AnyLogic
Expand
Font size

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.

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 block. 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.

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.
New rail car
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 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 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 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
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
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
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
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
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

Statistics
Function Description
int getNCars() Returns the number of railcars in this rail yard.
List<Agent> getCars() Returns the railcars in this rail yard.
Accessing cars and switches
Function Description
Agent getCar(int index) Returns the railcar in this rail yard with the given index, or null if there is no such car.
Switch[] getRouteSwitches(Track[] route) Returns all switches for the specified route.
Route
Function Description
RailwayTrack[] getShortestPath(RailwayTrack sourceTrack, RailwayTrack targetTrack, boolean forwardOnTrack,double targetOffset, RailwayTrack[] avoidTracks) Returns the shortest path from sourceTrack to targetTrack, or null if the path was not found.

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
RailwayTrack[] getShortestUnblockedPath(RailwayTrack sourceTrack, RailwayTrack targetTrack,boolean forwardOnTrack, double targetOffset, RailwayTrack[] avoidTracks) Returns the shortest path from sourceTrack to targetTrack, taking into account the blocked tracks. If the path was not found, returns null.

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
RailwayTrack[] getShortestAvailablePath( Agent train,RailwayTrack sourceTrack, RailwayTrack targetTrack, boolean forwardOnTrack,double targetOffset, RailwayTrack[] avoidTracks) Returns the shortest path from sourceTrack to targetTrack, taking into account the blocked and reserved tracks. If the path was not found, returns null.

train — train that requires the shortest available path
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
Adding cars and trains
Function Description
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. If the car intersects with another car that is already on the track, the error is signaled.

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. If the train intersects with other cars that are already on the track, the error is signaled.

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)
How can we improve this article?