RailSettings

RailSettings is a detached block that offers the lower-level interface for the rail yard management based on Java functions and callback technique. You can use those callbacks, for example, to collect statistics on the rail car movement throughout the whole rail yard.

Please note that RailSettings will not automatically detect track crossings (i.e. places where two tracks cross each other without a switch) and it is the user’s responsibility to make sure there are no train collisions in such places, whereas collisions at switches are detected automatically and errors are signaled.

Parameters

Car type
The type of the rail cars created by this object. Is optional, but if you use a custom class for rail cars, specifying it here enables you to directly access its custom fields in dynamic parameters like On enter yard. [Note that in the descriptions below RC refers to the class specified by the user in the Rail car class field. If the user does not change the default value, RC means RailCar.]
Referred below as:  RC
New rail car [dynamic]
[Obsolete since AnyLogic version 6.5.1. Use TrainSource to create trains] The expression that is used by RailSettings to create a rail car when the function addTrain() is called. Should evaluate to an object of type RailCar or its subclass.
Local variable: int n - the position of the car in the train, starting from 0
Actions
On enter yard [code]
Code that is executed each time a new car is added to the rail yard.
Local variables: RC car - the car
             RailwayNetwork railYard - the rail network defining the railyard that this railcar enters.
                          RailwayTrack track - the track where the car enters the yard
On exit yard [code]
Code that is executed each time a car exits the rail yard.
Local variables: RC car - the car
             RailwayNetwork railYard - the rail network defining the railyard that this railcar exits.
                          RailwayTrack track - the track from which the car exits the yard
Call onAtSwitch for 1st car only
If selected (true), the On at switch code is called only for a first car/locomotive in a train (or for a car moving alone), otherwise it is called for every car approaching a switch (this is the default behavior).
Syntax: boolean callAtSwitchForFirstCarOnly
Default value: false
On at switch [code]
Code that is executed each time a car approaches a switch. The switch state can still be changed in this code.
Local variables: RC car - the car
             RailwayNetwork railYard - the rail network defining the railyard
                          RailwayTrack track - the track from which the car approaches the switch
                          RailwaySwitch sw - the switch 
On enter track [code]
The user’s code that is executed each time a car enters a new track (and has already registered there).
Local variables: RC car - the car
             RailwayNetwork railYard - the rail network defining the railyard
                          RailwayTrack track - the track being entered
                          RailwaySwitch sw - the switch via which the car is entering the track
On exit track [code]
The user’s code that is executed each time a car fully exits a track.
Local variables: RC car - the car
             RailwayNetwork railYard - the rail network defining the railyard
                          RailwayTrack track - the track being exited
                          RailwaySwitch sw - the switch via which the car is exiting the track
On car hit car [code]
The user’s code that is executed each time a car hits another car. Is NOT called for the car that is being hit.
Local variables: RC car - the car
                          boolean frontside - the side of the car that hits another car (true if front side)
                          RC other - another car
                          RailwayTrack track - the track where this is happening
             RailwayNetwork railYard - the rail network defining the railyard
On at callback [code]
The user’s code that is executed each time a car reaches a specific point where it was requested to “call back” by the function callbackAt of the RailCar.
Local variables: RC car - the car
             RailwayNetwork railYard - the rail network defining the railyard
                          RailwayTrack track - the track
                          double offset - the point on the track
                         Object info - arbitrary information that was passed to this callback code, or null
On car clicked [code]
The user’s code that is executed each time a car is clicked by the user.
Local variables: RC car - the car
             RailwayNetwork railYard - the rail network defining the railyard

Functions

int getNCars() - Returns the number of railcars in this rail yard.

List<Agent> getCars() - Returns the railcars in this rail yard.

Agent getCar( int index ) - Returns the railcar in this rail yard with the given index, or null if there is no such car.

RailwayTrack[] getShortestPath( RailwayTrack sourceTrack, RailwayTrack targetTrack, boolean forwardOnTrack, double targetOffset, RailwayTrack[] avoidTracks ) - Returns shortest path from sourceTrack to targetTrack, or null if path was not found.
Parameters: sourceTrack - source track.
          targetTrack - target track.
          forwardOnTrack - if true, the train will go in forward on track.
          targetOffset - offset on the target track.
          avoidTracks  - list of tracks the route should not contain.

Switch[] getRouteSwitches( Track[] route ) - Returns all switches for the specified route.

void addCar( RC car, RailwayTrack track, double frontoffset, boolean orientation ) - [Obsolete since AnyLogic version 6.5.1. Use TrainSource to create cars and trains] Adds an (already constructed) rail car to the rail yard model, and puts it on the specified track at a given position with a given orientation. Both sides of the car must be on the same track. If the car intersects with another car that is already on the track, the error is signaled.
Parameters: car - the car to add
                    track - the track where the car is initially put
                    frontoffset - the offset of the front side of the car from the start of the track
                    orientation - if true, the car orientation (rear to front) is the same as the track orientation (start to end)

void addTrain( int n, RailwayTrack track, double frontoffset, boolean orientation)[Obsolete since AnyLogic version 6.5.1. Use TrainSource to create cars and trains] Creates a train with a given number of cars and puts it on the specified track at a given position with a given orientation. A customizable function newCar is used to create cars. All cars must fully be on the same track. If the train intersects with other cars that are already on the track, the error is signaled.

Parameters: n - the number of cars in the train
       track - the track where the train is put
       frontoffset - the offset of the front side of the first car from the start of the track
       orientation - if true, the train orientation (rear to front) is the same as the track orientation (start to end)