Now, let us simulate how the rail cars are classified and placed on different tracks according to their type.
Draw additional tracks
-
Draw more tracks as shown in the figure below. These will be the destination tracks. To create this rail topology, first draw several long tracks extending to the end of the hump yard. Then, add branch tracks.
- Name the destination tracks: trackN1, trackN2…trackN6.
-
Add six
Position on track elements on every destination track and name them stopLineN1...stopLineN6. This defines stop lines for each track. Cars rolling down by gravity onto their destination tracks will stop at these lines.
Define the flowchart logic
A train arriving at the hump yard may contain several cars of the same type in a row. These cars can be rolled onto their tracks all at once.
-
Create a
Function element that will calculate the number of successive cars of the same type in a train standing on the hump. Name it carsOfSameType and make sure to set the following parameters:
Returns value
Type: int
Arguments: train of the Train type
Function body:Agent firstCar = train.getFirst(); int n = 1; while( train.getCar(n).getClass() == firstCar.getClass() ) n++; return n;
- Create another
Function and name it departurePointOnTrack.
This function will determine the destination track for the rail cars in the classification bowl (the tracks where the cars of a particular type are sorted). This function takes a train as an argument and then checks the type of the first car in the train since trains usually consists of just a single car. We determine the type of the car with the help of the instanceof Java operator. This operator evaluates to true if the object is an instance of the specified class. Finally, the function returns the Position on track element that depends on the car type.
Make sure to set the following parameters:Returns value
Type: Other…: PositionOnTrack<?>
Arguments: train of the Train type
Function body:Agent car = train.getCar(0); if( car instanceof HopperCar ) return stopLineN1; if( car instanceof BoxCar ) return stopLineN2; if( car instanceof OpenCar ) return stopLineN3; if( car instanceof GondolaCar ) return stopLineN4; if( car instanceof TankCar ) return stopLineN5; return null;
-
Drag a
Variable element from the
Agent palette into the graphical editor. This variable will store the reference to the track where the required number of cars of the same type are ready to be taken by a locomotive from the yard.
-
Modify the
Variable element:
Name: trackReadyToDepart
Type: Other…: RailwayTrack
Modify the flowchart
-
The
TrainDecouple block decouples the train cars when the train is on the hump. A train may contain several cars of the same type in a row. These cars are rolled onto their tracks all at once. We determine the number of the cars to be rolled using the carsOfSameType function that we created in the previous step. The destination is defined by the departurePointOnTrack function, which we also created earlier.
Set the following parameters for theTrainDecouple block:
Number of cars to decouple: carsOfSameType(train)
New train:Train
-
There is a short delay before the train continues to decouple.
Set the following parameters for theDelay block:
Delay time: 5 seconds
-
Next, determine if the train has additional freight cars that need to be decoupled. This is done by the
SelectOutput block. We check if the train has more than one car. Remember that one car is the locomotive itself. If so, the train enters the
TrainDecouple block again. This cycle repeats until one locomotive remains, ready to depart from the yard.
Set the following parameters for theSelectOutput block:
Select True output: If condition is true
Condition: agent.size()>1 - Do not forget to connect the right port of the
SelectOutput block to the input port of the trainMoveTo4 block to move the train back to the hump.
Simulate how the locomotive leaves the yard
-
We use
TrainMoveTo again to simulate the movement of the train. Specify the name of the lower track (
trackN6) as the destination point.
Set the following parameters for theTrainMoveTo block:
Route is: Calculated automatically…
Target is: A given offset on a track
Railway track:trackN6
- Finally, the locomotive is removed from the model by the
TrainDispose block.
Simulate moving rail cars
Simulate how the rail cars roll onto their destination tracks (the tracks where the cars are sorted) by gravity.
-
As always, the movement is simulated with the
TrainMoveTo block. A train can consist of single cars or coupled cars of the same type in a block. The destination, or the stop line of the track corresponding to this rail car type, is returned by the departurePointOnTrack function that was defined earlier.
Set the following parameters for theTrainMoveTo block:
Route is: Calculated automatically…
Target is: A given position on track
Position on track: departurePointOnTrack(train)
Finish options: Decelerate and stop - If there are any other cars with the same destination track, they are assembled together with the rolled cars in the
TrainCouple block.
-
The cars continue to assemble until the required number of cars is on the track. At this point, a locomotive arrives at this point to take them away from the yard. The
SelectOutput block checks whether to stop the assembly. We specify that the train should be assembled until it has 8 cars.
Set the following parameters for theSelectOutput block:
Select True output: If condition is true
Condition: agent.size() < 8
Add a new flowchart branch
This will simulate how a train made up of 8 cars of the same type leaves the yard.
-
First, couple the cars with the locomotive using the
TrainCouple block. We will define the locomotive logic in the next step.
-
Then, the train leaves the yard. This is modeled with a regular
TrainMoveTo block.
Set the following parameters for theTrainMoveTo block:
Route is: not specified (train will follow switches)
Target is: not specified -
Finally, we remove the train from the model using the
TrainDispose block.
Add the locomotive logic to the flowchart
Simulate how locomotives take trains that are ready and combine them with from cars of the same type before leaving the yard.
-
First, let us add a
TrainSource block to model the arrival of the locomotive. The train consists of only one railcar: the locomotive itself. Select the manual train generation mode, as this block only creates trains when they are ready to depart from the yard. The locomotive should appear on the track defined by the trackReadyToDepart variable. We will calculate the value of the variable in the next step.
Set the following parameters for the TrainSource block:Name: newLoco
Arrivals defined by: Call of inject() function
# of cars (including loco): 1
Entry point defined as: offset on the track Railway track: trackReadyToDepart (Switch to the code field by clicking )
Offset from: Beginning of the track
Offset of 1st car: tracklength - 15 meters
New train:Train
New rail car:Locomotive
-
This block checks whether the required number of the cars of the same type are already on the yard track. Define the On exit (false) action. This action is executed when the required number of rail cars is reached. The line trackReadyToDepart = agent.getTrack( true ); stores the current track to the trackReadyToDepart variable.
The newLoco.inject(); line generates a new locomotive. Once created, the locomotive moves to the next block.
Set the following parameters in the Actions section of theSelectOutput block:
On exit (false):
trackReadyToDepart = agent.getTrack( true ); newLoco.inject();
-
This
TrainMoveTo block simulates how the locomotive moves to the cars that are ready to depart.
The movement direction is Backward (the locomotive moves in the direction opposite to the track direction, from right to left).Then, the locomotive couples with the cars, and the resulting train moves to the flowchart branch, simulating how the train leaves the yard.
Set the following parameters for theTrainMoveTo block:
Direction: Backward
Route is: not specified (train will follow switches)
Target is: not specified
Cruise speed: 10 meters per second
Finally, your flowchart should look like this:
Now run the model. You will see that the rail cars are classified by type. Once the required number of railcars of the same type reach the destination track, a locomotive will take them away from the yard.
Congratulations! You have completed the AnyLogic Hump Yard tutorial.
Demo model: Hump Yard Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files). Demo model: Hump YardOpen the model in your AnyLogic desktop installation.-
How can we improve this article?
-