Class TrainRoute
Train, consisting of consecutive AgentGraphPaths
that represent sections for movement and maneuvers.
If there are multiple paths, then after completing one path, the train turns
around and starts moving along the next one.- Author:
- Andrey Korotin
-
Constructor Summary
ConstructorsConstructorDescriptionTrainRoute(List<AgentGraphPath<RailNode, RailArc>> paths, TrainsEnvironment trainsEnvironment) Creates a newTrainRouteconsisting of the given consecutive paths. -
Method Summary
Modifier and TypeMethodDescriptionvoidbookIntervals(Object booker, double startMovementTime, double trainVelocity, GeometricGraphPath<RailNode, RailArc> sourceSelfPath) Books time intervals along this route for the specifiedTrainmovement.Returns the dest position of this route.doublegetEndMovementTime(Train train, double beginTime, double trainVelocity, GeometricGraphPath<RailNode, RailArc> sourceSelfPath, boolean considerBookedTracks, boolean considerTrainsPredicate) Returns the earliest possible end time for movement along this route, taking into account other trains standing on the tracks and booked tracks.doublegetEndMovementTime(Train train, double beginTime, double trainVelocity, GeometricGraphPath<RailNode, RailArc> sourceSelfPath, BiPredicate<RailTrack, Object> considerBookedTracks, Predicate<Train> considerTrainsPredicate, Set<RailArc> prohibitedArcs) Returns the earliest possible end time for movement along this route, taking into account other trains standing on the tracks and booked tracks.doubleReturns the length of this route, i.e.getPaths()Returns the list ofAgentGraphPaths representing the paths in this route.Returns the source position of this route.doublegetStartMovementTime(Train train, double beginTime, double trainVelocity, GeometricGraphPath<RailNode, RailArc> sourceSelfPath, BiPredicate<RailTrack, Object> considerBookedTracks, Predicate<Train> considerTrainsPredicate, Set<RailArc> prohibitedArcs) Returns the earliest possible start time for movement along this route, taking into account other trains standing on the tracks and booked tracks.Returns an unmodifiable view of allRailTracks in this route.booleanisAvailableFor(Train train, double beginTime, double trainVelocity, GeometricGraphPath<RailNode, RailArc> sourceSelfPath) Checks whether this route is available for the specifiedTrainto start moving.booleanisAvailableFor(Train train, double beginTime, double trainVelocity, GeometricGraphPath<RailNode, RailArc> sourceSelfPath, boolean considerBookedTracks, boolean considerTrainsPredicate) Checks whether this route is available for the specifiedTrainto start moving.booleanisAvailableFor(Train train, double beginTime, double trainVelocity, GeometricGraphPath<RailNode, RailArc> sourceSelfPath, BiPredicate<RailTrack, Object> considerBookedTracks, Predicate<Train> considerTrainsPredicate, Set<RailArc> prohibitedArcs) Checks whether this route is available for the specifiedTrainto start moving.toString()
-
Constructor Details
-
TrainRoute
public TrainRoute(List<AgentGraphPath<RailNode, RailArc>> paths, TrainsEnvironment trainsEnvironment) Creates a newTrainRouteconsisting of the given consecutive paths.Each path represents a segment for movement or maneuvers. If multiple paths are provided, the train will complete one path, turn around, and then proceed along the next path.
The constructor also collects all unique
RailTracks used in the paths.- Parameters:
paths- the list ofAgentGraphPaths that form the routetrainsEnvironment- theTrainsEnvironmentassociated with this route
-
-
Method Details
-
getStartMovementTime
public double getStartMovementTime(Train train, double beginTime, double trainVelocity, GeometricGraphPath<RailNode, RailArc> sourceSelfPath, BiPredicate<RailTrack, Object> considerBookedTracks, Predicate<Train> considerTrainsPredicate, Set<RailArc> prohibitedArcs) Returns the earliest possible start time for movement along this route, taking into account other trains standing on the tracks and booked tracks. Returns Double.POSITIVE_INFINITY if movement cannot be started.- Parameters:
train- theTrainfor which the calculation should be performedbeginTime- the earliest time at which movement can begintrainVelocity- the velocity of the train, used for timing along the routesourceSelfPath- path that represents the projection of a long agent onto the graph before movementconsiderBookedTracks- aBiPredicateto determine which booked tracks should be treated as occupied; the first argument is aRailTrack, the second is the booker objectconsiderTrainsPredicate- aPredicatethat determines which non-moving trains should be considered as obstacles; only trains for which this predicate returnstrueare consideredprohibitedArcs- a set ofRailArcs that are forbidden for the moving- Returns:
- the earliest possible start time for movement along this route, taking into account other trains standing on the tracks and booked tracks. Returns Double.POSITIVE_INFINITY if movement cannot be started.
-
getEndMovementTime
public double getEndMovementTime(Train train, double beginTime, double trainVelocity, GeometricGraphPath<RailNode, RailArc> sourceSelfPath, boolean considerBookedTracks, boolean considerTrainsPredicate) Returns the earliest possible end time for movement along this route, taking into account other trains standing on the tracks and booked tracks. Returns Double.POSITIVE_INFINITY if movement cannot be started.- Parameters:
train- theTrainfor which the calculation should be performedbeginTime- the earliest time at which movement can begintrainVelocity- the velocity of the train, used for timing along the routesourceSelfPath- path that represents the projection of a long agent onto the graph before movementconsiderBookedTracks- whether booked tracks should be considered as obstaclesconsiderTrainsPredicate- whether non-moving trains should be considered as obstacles- Returns:
- the earliest possible end time for movement along this route, taking into account other trains standing on the tracks and booked tracks. Returns Double.POSITIVE_INFINITY if movement cannot be started.
-
getEndMovementTime
public double getEndMovementTime(Train train, double beginTime, double trainVelocity, GeometricGraphPath<RailNode, RailArc> sourceSelfPath, BiPredicate<RailTrack, Object> considerBookedTracks, Predicate<Train> considerTrainsPredicate, Set<RailArc> prohibitedArcs) Returns the earliest possible end time for movement along this route, taking into account other trains standing on the tracks and booked tracks. Returns Double.POSITIVE_INFINITY if movement cannot be started.- Parameters:
train- theTrainfor which the calculation should be performedbeginTime- the earliest time at which movement can begintrainVelocity- the velocity of the train, used for timing along the routesourceSelfPath- path that represents the projection of a long agent onto the graph before movementconsiderBookedTracks- aBiPredicateto determine which booked tracks should be treated as occupied; the first argument is aRailTrack, the second is the booker objectconsiderTrainsPredicate- aPredicatethat determines which non-moving trains should be considered as obstacles; only trains for which this predicate returnstrueare consideredprohibitedArcs- a set ofRailArcs that are forbidden for the moving- Returns:
- the earliest possible end time for movement along this route, taking into account other trains standing on the tracks and booked tracks. Returns Double.POSITIVE_INFINITY if movement cannot be started.
-
isAvailableFor
public boolean isAvailableFor(Train train, double beginTime, double trainVelocity, GeometricGraphPath<RailNode, RailArc> sourceSelfPath) Checks whether this route is available for the specifiedTrainto start moving.The availability is determined based on other trains on the tracks and booked tracks. If the earliest possible start time for movement is finite, the route is considered available.
This method calculates the availability of the route, taking into account other non-moving trains and booked tracks.
- Parameters:
train- theTrainfor which the calculation should be performedbeginTime- the earliest time at which movement can begintrainVelocity- the velocity of the train, used for timing along the routesourceSelfPath- path that represents the projection of a long agent onto the graph before movement- Returns:
- true if the route is available for the train to start moving; false otherwise
-
isAvailableFor
public boolean isAvailableFor(Train train, double beginTime, double trainVelocity, GeometricGraphPath<RailNode, RailArc> sourceSelfPath, boolean considerBookedTracks, boolean considerTrainsPredicate) Checks whether this route is available for the specifiedTrainto start moving.The availability is determined based on other trains on the tracks and booked tracks. If the earliest possible start time for movement is finite, the route is considered available.
- Parameters:
train- theTrainfor which the calculation should be performedbeginTime- the earliest time at which movement can begintrainVelocity- the velocity of the train, used for timing along the routesourceSelfPath- path that represents the projection of a long agent onto the graph before movementconsiderBookedTracks- whether booked tracks should be considered as obstaclesconsiderTrainsPredicate- whether non-moving trains should be considered as obstacles predicate returnstrueare considered- Returns:
- true if the route is available for the train to start moving; false otherwise
-
isAvailableFor
public boolean isAvailableFor(Train train, double beginTime, double trainVelocity, GeometricGraphPath<RailNode, RailArc> sourceSelfPath, BiPredicate<RailTrack, Object> considerBookedTracks, Predicate<Train> considerTrainsPredicate, Set<RailArc> prohibitedArcs) Checks whether this route is available for the specifiedTrainto start moving.The availability is determined based on other trains on the tracks, booked tracks, and prohibited arcs. If the earliest possible start time for movement is finite, the route is considered available.
- Parameters:
train- theTrainfor which the calculation should be performedbeginTime- the earliest time at which movement can begintrainVelocity- the velocity of the train, used for timing along the routesourceSelfPath- path that represents the projection of a long agent onto the graph before movementconsiderBookedTracks- aBiPredicateto determine which booked tracks should be treated as occupied; the first argument is aRailTrack, the second is the booker objectconsiderTrainsPredicate- aPredicatethat determines which non-moving trains should be considered as obstacles; only trains for which this predicate returnstrueare consideredprohibitedArcs- a set ofRailArcs that are forbidden for the moving- Returns:
- true if the route is available for the train to start moving; false otherwise
-
bookIntervals
public void bookIntervals(Object booker, double startMovementTime, double trainVelocity, GeometricGraphPath<RailNode, RailArc> sourceSelfPath) Books time intervals along this route for the specifiedTrainmovement.The booking considers the train's length, velocity, and the given source path segment. It also accounts for the end movement arcs and ensures that the source path aligns with the start of the route. If necessary, the source path is reversed to match the route's direction.
After booking the self path, this method books all consecutive paths in the route, considering any required reversion gaps between paths.
- Parameters:
booker- the object representing the entity booking the intervals (e.g., a train)startMovementTime- the time at which the train starts moving along the routetrainVelocity- the velocity of the trainsourceSelfPath- path that represents the projection of a long agent onto the graph before movement- Throws:
RuntimeException- if the source self path does not align with the start of the booking route
-
getPaths
Returns the list ofAgentGraphPaths representing the paths in this route.- Returns:
- the list of
AgentGraphPaths
-
getTracks
Returns an unmodifiable view of allRailTracks in this route.- Returns:
- an unmodifiable list of
RailTracks
-
getSourcePosition
Returns the source position of this route.- Returns:
- source position of this route
-
getDestPosition
Returns the dest position of this route.- Returns:
- dest position of this route
-
toString
-
getLength
public double getLength()Returns the length of this route, i.e. the length of trajectory of this route. Length of an empty route is zero- Returns:
- length of this route
-