AnyLogic
Expand
Font size

Switch

The Switch  object represents a two-way railroad switch that connects several tracks. Different switch types define different number of connected tracks and different rules of train movement along these tracks. AnyLogic supports three switch types.

All-to-all

All-to-all slip: movement rules

This is the default type of switch in AnyLogic. It supports the connection of an unlimited number of tracks and the following train movement:

  • direct movement along all the tracks
  • change of direction along all the obtuse angles
If all-to-all type of switch connects only three tracks: 0, 1, and 2, then, depending on its state, the switch will direct the trains coming from track 0 (face point movement) to either track 1 or track 2. The trains coming from track 1 or 2 (trailing point movement) will always proceed to track 0 regardless of the state of the switch and will always force the switch to the corresponding state. The movement from track 1 to track 2 and vice versa is not supported in this case.

Single slip

Single slip: movement rules

This type of switch supports the connection of 4 tracks and the following train movement:

  • direct movement along all the tracks
  • change of direction along the obtuse angle only from / to the switching track (e.g., track 1 to track 3 and vice versa as displayed in the image above). You can define any of the tracks connected to the single slip switch as the switching track in the properties of the Switch element.
Single slip switch can only be applied when the four connecting tracks form 2 acute angles opposite each other (measuring less than 90°). If this condition is not satisfied, an error will occur at model run.

Double slip

Double slip: movement rules

This type of switch supports the connection of 4 tracks and the following train movements:

  • direct movement along all the tracks
  • change of direction along all the obtuse angles
Double slip switch can only be applied when the four connecting tracks form 2 acute angles opposite each other (measuring less than 90°). If this condition is not satisfied, an error will occur at model run.

You can toggle the switch state by clicking within the circle, or via its API.

You do not need to use functions of switches too often: the Rail Library object TrainMoveTo is capable of setting up the switch states automatically when the train moves along a defined route.

The switch is animated in the shape of a circle. The state of the switch is shown with a thin line that crosses the circle marking the direction of movement through the switch.

Properties

General

Name — The name of the switch. The name is used to identify and access the switch from code and flowchart blocks properties.

Ignore — If selected, the switch is excluded from the model.

Visible on upper agent — If selected, the switch is also visible on the upper agent where this agent lives.

Lock — If selected, the switch is locked. Locked shapes do not react to mouse clicks — it is impossible to select them in the graphical editor until you unlock them. It is frequently needed when you want to prevent editing this shape while drawing other shapes over it.

Visible — Here you specify whether the shape is visible on animation at model runtime, or not. Using the control, choose yes or no.

Type — Here you can select the type switch to specify the rules of train movement across this switch. You can choose between All-to-all, Single slip, and Double slip.

Switching track — [Visible only if the Single slip option is selected in the Type parameter] Here you can select the track which will support change of direction for the train movement.

Advanced

Show in — This shape cannot be displayed in 3D.

Functions

Railway track
Function Description
RailwayTrack getTrack(int index) Returns the track with a given index connected to the switch.

index — the index of the track
List<RailwayTrack> getTracks() Returns all tracks connected to the switch.
List<RailwayTrack> getAvailableTracks(RailwayTrack source) Finds all the tracks which the train can move to if it approaches the switch from the given source track.

source — source track
void connectTracks(RailwayTrack source, RailwayTrack target) The switch is set to the state (one of the states, if there are several) which allows the movement from the given source track to the given target track.

source — source track
target — target track
boolean stateExists(RailwayTrack source, RailwayTrack target) Checks whether there is a state in which the train can move from the given source track to the given target track. If the state exists, the function returns true; otherwise — false.

source — source track
target — target track
boolean trackStarts(RailwayTrack track) Returns true if a given track starts at the switch, and false if it ends there.

track — the track
RailwayTrack nextTrack(RailwayTrack source) Returns the next track, given the switch is approached from a given track. If the current switch state does not allow movement from the source track, then the function returns the next track in the next feasible state (for the source track) without changing the state.

source — the track from which the switch is being approached
RailwayTrack currentStateNextTrack(RailwayTrack source) Based on the current state of the switch returns the next track, given the switch is approached from the given track.

source — the track from which the switch is being approached
void toggle() Makes the toggle assume its next state.
int getToggleCount() Returns the number of toggles for the switch: both toggles that occur during the automatic routing and those initiated manually during the model run.
boolean trackStarts(RailwayTrack track) Tests if movement from the given track through the switch is a trailing point movement or face point. Will signal error if the track is not connected to the switch. Returns true if trailing point, false if facing point.

track — the track from which the train approaches the switch
Location
Function Description
RailwayNetwork getRailYard() Returns the railway network this switch belongs to, or null if this switch is not a part of a railway network.
double getX() Returns the X-coordinate of the switch.
double getY() Returns the Y-coordinate of the switch.
double getZ() Returns the Z-coordinate of the switch.
Dimensions
Function Description
double getRadius() Returns the radius of the switch.
void setRadius(double radius) Sets the radius of the switch.

radius — the radius of the switch
Level
Function Description
Level getLevel() Returns the level on which this switch is located.
Appearance
Function Description
Paint getColor() Returns the color (or texture) of the switch.
Color getSelectionColor() Returns the color of the line animating the current switch position at model runtime.
void setColor(Paint color) Sets the color (or texture) of the switch.

color — the color (or texture) of the switch
void setSelectionColor(Color color) Sets the color of the line animating the current switch position at model runtime.

color — the color the current switch position is highlighted with
Visibility
Function Description
boolean isVisible() Returns true if the switch is visible; returns false otherwise.
void setVisible(boolean v) Sets the visibility of the switch.

v — visibility. If v is true — the switch is set to be visible, if it is false — not visible.
Removal
Function Description
void remove() Removes the switch from the presentation. If the switch is not a part of presentation, the function does nothing.
Removal from the presentation does not necessarily mean removing from the model logic, since logical networks and routes may have been created before the removal and survive it.
Creating a switch programmatically
Function Description
void setTracks(RailwayTrack... tracks) This function is used to set the tracks connected to the switch when you build the railway yard programmatically from scratch. You can pass as many tracks as you need as arguments here.

tracks — tracks that are connected to the switch
void setAllToAllType() Sets the type of the created switch to All-to-all. This function can only be used if you are creating the switch programmatically.
void setSingleSlipType(RailwayTrack track) Sets the type of the created switch to Single slip and assigns the switching track status to the given track. This function can only be used if you are creating the switch programmatically.

track — track that will be assigned the switching track status
void setDoubleSlipType() Sets the type of the created switch to Double slip. This function can only be used if you are creating the switch programmatically.
How can we improve this article?