Class TrainRoute

java.lang.Object
com.amalgamasimulation.trains.TrainRoute

public class TrainRoute extends Object
Route for a 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 Details

    • TrainRoute

      public TrainRoute(List<AgentGraphPath<RailNode,RailArc>> paths, TrainsEnvironment trainsEnvironment)
      Creates a new TrainRoute consisting 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 of AgentGraphPaths that form the route
      trainsEnvironment - the TrainsEnvironment associated 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 - the Train for which the calculation should be performed
      beginTime - the earliest time at which movement can begin
      trainVelocity - the velocity of the train, used for timing along the route
      sourceSelfPath - path that represents the projection of a long agent onto the graph before movement
      considerBookedTracks - a BiPredicate to determine which booked tracks should be treated as occupied; the first argument is a RailTrack, the second is the booker object
      considerTrainsPredicate - a Predicate that determines which non-moving trains should be considered as obstacles; only trains for which this predicate returns true are considered
      prohibitedArcs - a set of RailArcs 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 - the Train for which the calculation should be performed
      beginTime - the earliest time at which movement can begin
      trainVelocity - the velocity of the train, used for timing along the route
      sourceSelfPath - path that represents the projection of a long agent onto the graph before movement
      considerBookedTracks - whether booked tracks should be considered as obstacles
      considerTrainsPredicate - 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 - the Train for which the calculation should be performed
      beginTime - the earliest time at which movement can begin
      trainVelocity - the velocity of the train, used for timing along the route
      sourceSelfPath - path that represents the projection of a long agent onto the graph before movement
      considerBookedTracks - a BiPredicate to determine which booked tracks should be treated as occupied; the first argument is a RailTrack, the second is the booker object
      considerTrainsPredicate - a Predicate that determines which non-moving trains should be considered as obstacles; only trains for which this predicate returns true are considered
      prohibitedArcs - a set of RailArcs 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 specified Train to 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 - the Train for which the calculation should be performed
      beginTime - the earliest time at which movement can begin
      trainVelocity - the velocity of the train, used for timing along the route
      sourceSelfPath - 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 specified Train to 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 - the Train for which the calculation should be performed
      beginTime - the earliest time at which movement can begin
      trainVelocity - the velocity of the train, used for timing along the route
      sourceSelfPath - path that represents the projection of a long agent onto the graph before movement
      considerBookedTracks - whether booked tracks should be considered as obstacles
      considerTrainsPredicate - whether non-moving trains should be considered as obstacles predicate returns true are 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 specified Train to 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 - the Train for which the calculation should be performed
      beginTime - the earliest time at which movement can begin
      trainVelocity - the velocity of the train, used for timing along the route
      sourceSelfPath - path that represents the projection of a long agent onto the graph before movement
      considerBookedTracks - a BiPredicate to determine which booked tracks should be treated as occupied; the first argument is a RailTrack, the second is the booker object
      considerTrainsPredicate - a Predicate that determines which non-moving trains should be considered as obstacles; only trains for which this predicate returns true are considered
      prohibitedArcs - a set of RailArcs 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 specified Train movement.

      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 route
      trainVelocity - the velocity of the train
      sourceSelfPath - 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

      public List<AgentGraphPath<RailNode,RailArc>> getPaths()
      Returns the list of AgentGraphPaths representing the paths in this route.
      Returns:
      the list of AgentGraphPaths
    • getTracks

      public List<RailTrack> getTracks()
      Returns an unmodifiable view of all RailTracks in this route.
      Returns:
      an unmodifiable list of RailTracks
    • getSourcePosition

      public GeometricGraphPosition<RailNode,RailArc> getSourcePosition()
      Returns the source position of this route.
      Returns:
      source position of this route
    • getDestPosition

      public GeometricGraphPosition<RailNode,RailArc> getDestPosition()
      Returns the dest position of this route.
      Returns:
      dest position of this route
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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