AnyLogic 9
Expand
Font size

Phase 2. Defining logic

To define the model logic

  1. Add the following blocks to the flowchart:  TrainSource,  TrainMoveTo,  TrainDecouple,  TrainCouple,  TrainDispose. We will use these blocks from the AnyLogic Rail Library to define the train logic.
  2. Start the flowchart with the train-generating  TrainSource block, then add the  TrainMoveTo block and place it near the first block so that they connect automatically. Continue adding other blocks to the flowchart as shown in the figure below.

  3. Specify the properties for the  TrainSource and  TrainMoveTo blocks.
    We will start by by telling the trains to appear at the  stopLineEntrytrack point every 15 minutes.

     TrainSource:
    Interarrival time: 15 minutes
    # of cars (including loco): 11
    Position on track:  stopLineEntry
    Once generated, each train will head to the  stopLineArrival track point where it will decelerate and stop.
     TrainMoveTo
    Route is: Calculated automatically from current to target track
    Target is: A given position on track
    Position on track:  stopLineArrival
    Finish options: Decelerate and stop
  4. We have also added a  TrainDecouple block which is used to detach a given number of cars from the incoming train. In the block’s properties, you can see that it decouples one car from the train by default, namely the first car (which in our case is a locomotive). A locomotive leaves the block through its bottom port outDecoupled.
  5. The  TrainCouple block will be used to couple a locomotive with rail cars into a train.

Below is the description of the Rail Library blocks we use.

Rail Library block Description
TrainSource Creates trains, performs the initial setup, and inserts them into the railway network. Starts any rail process flowchart. Supports several types of arrival schedules.
TrainDispose Removes trains from the model.
TrainMoveTo Controls the movement of trains. Can calculate routes and set switch states as the train goes along the route. Supports acceleration and deceleration.
TrainCouple Couples two “touching” trains into a single train.
TrainDecouple Decouples cars from the incoming train and creates a new train from those cars.
TrainEnter Takes the train agent and places it on the railway track.
TrainExit Removes the train from the railway network and returns the train agent to the regular process flow.
RailSettings Defines the advanced settings for the railway network.

To modify the flowchart

Add more  TrainMoveTo blocks and connect them as shown on the picture by following the steps below to determine the behavior of the train on the rail yard. This will include the locomotive decoupling and returning to use the lead track to recouple with the cars and move them to the hump.

Start with connecting a  TrainMoveTo block to the outDecoupled port (the one at the bottom) of the  TrainDecouple block, as we will only be defining the logic for the detached locomotive.

  1. Add another  TrainMoveTo block into the flowchart (trainMoveTo1). Define the parameters of the new block to move the locomotive to  stopLineHump and stop it there.
    Route is: Calculated automatically from current to target track
    Target is: A given position on track
    Position on track:  stopLineHump
    Finish options: Decelerate and stop
  2. Add two more  TrainMoveTo blocks (trainMoveTo2, trainMoveTo3) by holding down Ctrl (macOS: Cmd) and dragging the one you just edited.
  3. Modify the parameters of the trainMoveTo2 block. At this point, the locomotive is on its own and we need it to push the rail cars to the hump, meaning it should go back to the  stopLineEntry and then couple with the end of the train. The locomotive will move backwards, skipping the  trackArrival track that the rail cars are on:
    Direction: Backward
    Route should not contain:  trackArrival
    Position on track:  stopLineEntry
  4. Note the number of connections leading from the trainMoveTo3 block to  TrainCouple block. The bottom port in the  TrainMoveTo block, as compared to the out port on the right, is used for a train that collides with another train. In our case, the collision corresponds to the coupling of the locomotive arriving at the  stopLineArrival track position with the rail cars which we have previously detached from this locomotive.
  5. Now modify the parameters of the trainMoveTo3 block to move the locomotive from its current position to the  stopLineArrival track position:
    Position on track:  stopLineArrival

    Now that we have moved the locomotive to the back of the train consisting of rail cars, we need to add another  TrainMoveTo block by Ctrl-dragging (macOS: Cmd-dragging) the trainMoveTo1 block. It will simulate the locomotive pushing the rail cars to the hump area, represented in our model by the  stopLineHump element.

  6. Modify the parameters of the trainMoveTo4:
    Position on track:  stopLineHump
    Cruise speed (0 for no change): 5 meters per second

  7. Add a  Delay block from the  Process Modeling palette to simulate a time delay and define its parameters:
    Delay time: 15 seconds

We have completed Phase 2. You can run the model to see how trains appear and move along our track.

To run the model

  1. Click on the toolbar.
    After starting the model, you will see the model window. It displays the presentation of the top-level agent type (by default, it’s  Main).
    Observe the process dynamics. If needed, adjust the execution speed to your needs using  slow down and  speed up controls.
    If you see the The car being created must fully be on one track error, it means that there is not enough space for the whole train to fit in on the railway track before the  stopLineEntry  element. In this case, you need to increase the length of the  trackEntry railway track and move the  stopLineEntry further from the track’s start point.

    The train stops at the stop line and the locomotive uses the lead track to couple with the train end.

You can see that the locomotive moves the rail cars to the hump and stops for decoupling and classification.

Demo model: Hump Yard - Phase 2 Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files). Demo model: Hump Yard - Phase 2Open the model in your AnyLogic desktop installation.
How can we improve this article?