Hi JPF. I'm having trouble with a question given to us by our lecturer. The question is as follows

In a toy train circuit (figure of eight) trains can enter via section 5 or section 14, do a figure of eight circuit and then leave via the same section that they entered.

A train joining the circuit must first make sure the section ahead and the section immediately to the right/left of them is free (e.g. A train entering via section 14 must ensure the section 14 and section 13, are not occupied by another train at that time. To avoid train crashes only one train at any time can be in any of the available sections. The crossover protocol at the junction (i.e. section 0) in the centre of the figure of eight is that the first train to get access to the junction is allowed to proceed across it.

the reason it cuts off around the await section is because I am rather a beginner in using java and despite being a final year student have managed to get along doing modules that are not heavily focused on coding; but also I couldn't find much on java await statements by googling.

Any advice/nudges in the right direction would be appreciated.
Thanks

March 4th, 2014, 11:05 AM

Norm

Re: Use of await statement in problem

Quote:

java await statements

I don't recognize that.

Are you asking about the Object class's wait() method?

March 4th, 2014, 11:14 AM

hcoyle545

Re: Use of await statement in problem

see thats what i'm unsure of. Our lecturer provided some code that he said would work straight out of the box for java, it was as follows:

My understanding is that the wait statement is just to ensure that there is enough room on the track for another train to enter.

thanks for having a look at my thread too

March 4th, 2014, 11:45 AM

Norm

Re: Use of await statement in problem

That does not look like java code. What language is it?

March 4th, 2014, 02:22 PM

Flying216

Re: Use of await statement in problem

I agree with Norm, that doesn't look much like java.

Is the wait command absolutely necessary? This seems like a problem about determining when the trains are to enter through the station if they are all traveling at a constant "velocity" (Sections per iteration). A wait function seems to be for a time base instead of an iterative base. There are a few controlling variables for the solution: How many sections does each train take up? How long is the figure 8 track? Most importantly, what is the distance of each station from the junction within the figure 8?

This problem could be solved without programming it; I'd say watch/imagine a train going through the track and observe how many iterations after departing from the starting station which pass before the train enters the junction. This allows you to see the walls - moments where a collision is possible - created by any train leaving the station.

I really like this problem, could you post the picture that goes along with it?

March 5th, 2014, 10:21 AM

hcoyle545

1 Attachment(s)

Re: Use of await statement in problem

heres the picture attached... ive since found that the code I posted was psuedocode. and the aim is to make psuedocode in that same format as mentioned above for this track.

The psuedocode I posted earlier is from a different question (just to serve as an example)

Here's the question for the above image

"A toy train circuit (figure of eight) is show below. Trains can enter via section 5 or section 14, do a figure of eight circuit and then leave via the same section that they entered. The route they take is indicated in figure 1.

A train joining the circuit must first make sure the section ahead and the section immediately to the right/left of them is free (e.g. A train entering via section 14 must ensure the section 14 and section 13, are not occupied by another train at that time. To avoid train crashes only one train at any time can be in any of the available sections. The crossover protocol at the junction (i.e. section 0) in the centre of the figure of eight is that the first train to get access to the junction is allowed to proceed across it.

Assuming that shared memory is available
(a) Design a solution using the await statement, that adhers to the above
behaviour protocol and hence allows trains to enter, travel around and leave safely. (25%)
(b) translate the design in part(a) into a semaphore based design. (25%)
"

At the minute Im working on changing the psuedocode so that it applies to the question above

March 5th, 2014, 10:28 AM

Norm

Re: Use of await statement in problem

Quote:

Design a solution using the await statement

There is no await statement in java. Where have you heard about an await statement?

March 5th, 2014, 10:33 AM

hcoyle545

Re: Use of await statement in problem

Quote:

Originally Posted by Norm

There is no await statement in java. Where have you heard about an await statement?

First time I've heard is from this question which is what's confusing. But this is just psuedocode now, it signifies waiting until a slot on the track is empty before another train can enter.

March 6th, 2014, 08:53 AM

Flying216

Re: Use of await statement in problem

Oh I see, its one of those exercises. I would start with creating objects and passing variables between them which act within the constraints. Maybe you could clear this up, is semaphore design trying to determine the memory allocation for operating this track?

The first task of identifying the objects has already been done: TrackSegments, Trains, and Stations.
It seems there are two different reference points for deciding how to draft the "sight" of the program. Junctions, being the point of conflict, could be created to control the trains, but seeing this exercise I am pretty sure you are supposed to focus on passing variables from TrackSegments to the Trains.