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.
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
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.
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
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.
- 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.
- Railway track
-
Function Description RailwayTrack getTrack(int index) Returns the track with a given index connected to the switch.
index — the index of the trackList<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 trackvoid 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 trackboolean 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 trackboolean trackStarts(RailwayTrack track) Returns true if a given track starts at the switch, and false if it ends there.
track — the trackRailwayTrack 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 approachedRailwayTrack 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 approachedvoid 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 switchvoid 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 switchvoid 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 statusvoid 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?
-