MTCT
Design Automation and Optimization for ETCS Railway Networks
Loading...
Searching...
No Matches
cda_rail::simulator::GreedySimulator Class Reference

Simulates the trains of a moving block instance greedily. More...

#include <GreedySimulator.hpp>

Inheritance diagram for cda_rail::simulator::GreedySimulator:
cda_rail::simulator::GeneralSimulator

Classes

struct  PositionBound
 How far along its route a train may be at most at a given time. More...
class  FirstComeFirstServed

Public Types

using PositionBoundFunction
 The PositionBound of train tr at time t, or std::nullopt if the train is not restricted.

Public Member Functions

 GreedySimulator (cda_rail::instances::GeneralPerformanceOptimizationInstance const &instance, std::vector< cda_rail::index_set > ttd_sections)
 Constructs a greedy simulator from an instance and TTD sections.
 GreedySimulator (cda_rail::instances::GeneralPerformanceOptimizationInstance const &instance, std::vector< cda_rail::index_set > ttd_sections, std::vector< cda_rail::index_vector > train_edges, std::vector< cda_rail::index_vector > ttd_orders, std::vector< cda_rail::index_vector > vertex_orders, std::vector< std::vector< double > > stop_positions)
 Constructs a greedy simulator with explicit state vectors.
 GreedySimulator (GreedySimulator const &)=default
 Copy constructor.
 GreedySimulator (GreedySimulator &&) noexcept=default
 Move constructor.
GreedySimulator & operator= (GreedySimulator const &)=default
 Copy assignment operator.
GreedySimulator & operator= (GreedySimulator &&) noexcept=default
 Move assignment operator.
 ~GreedySimulator () override=default
 Virtual destructor.
instances::GeneralPerformanceOptimizationInstance const * get_instance () const override
 Retrieves the typed performance optimization instance.
void set_position_bound (PositionBoundFunction bound, index_set trains_with_feasible_bound={})
 Restricts the trains to the positions given by bound.
SimulatorResults simulate (double dt, bool late_entry_possible, bool limit_speed_by_leaving_edges, bool save_trajectories, bool block_vertices_after_disappearing) const override
 Runs the greedy simulation in time steps of length dt.
std::optional< SimulatorState > first_come_first_served_state (double dt, bool late_entry_possible, bool limit_speed_by_leaving_edges) const override
 Decides every open order first come, first served, see GeneralSimulator::first_come_first_served_state.
SimulatorResults simulate (double dt=6.0, bool late_entry_possible=false, bool limit_speed_by_leaving_edges=true, bool save_trajectories=false) const
 Simulates with default values, in particular a time step of 6 seconds and blocking the last vertex of a partial route.
Public Member Functions inherited from cda_rail::simulator::GeneralSimulator
 GeneralSimulator (instances::GeneralProblemInstanceWithScheduleAndRoutes &instance, std::vector< cda_rail::index_set > ttd_sections)
 Constructs a simulator from a mutable instance reference.
 GeneralSimulator (instances::GeneralProblemInstanceWithScheduleAndRoutes &instance, std::vector< cda_rail::index_set > ttd_sections, std::vector< cda_rail::index_vector > train_edges, std::vector< cda_rail::index_vector > ttd_orders, std::vector< cda_rail::index_vector > vertex_orders, std::vector< std::vector< double > > stop_positions)
 Constructs a simulator from explicit state vectors.
virtual ~GeneralSimulator ()=default
 Virtual destructor.
 GeneralSimulator (GeneralSimulator const &)=default
 Copy constructor.
 GeneralSimulator (GeneralSimulator &&)=default
 Move constructor.
GeneralSimulator & operator= (GeneralSimulator const &)=default
 Copy assignment operator.
GeneralSimulator & operator= (GeneralSimulator &&)=default
 Move assignment operator.
const std::vector< cda_rail::index_set > & get_ttd_sections () const
 Retrieves the TTD sections considered by the simulator.
const std::vector< cda_rail::index_vector > & get_train_edges () const
 Accesses the edge sequences for all trains.
const cda_rail::index_vector & get_train_edges_of_tr (size_t train_id) const
 Returns the current edge sequence for one train.
const std::vector< cda_rail::index_vector > & get_ttd_orders () const
 Retrieves the ordering vectors for all TTD sections.
const cda_rail::index_vector & get_ttd_orders_of_ttd (size_t ttd_index) const
 Returns the train order for one TTD section.
std::optional< size_t > get_ttd (Network::EdgeInput const &edge) const
 Returns the TTD section containing an edge, if any.
const std::vector< cda_rail::index_vector > & get_vertex_orders () const
 Accesses the train ordering for each vertex.
const cda_rail::index_vector & get_vertex_orders_of_vertex (Network::VertexInput const &vertex) const
 Returns the train order stored for a vertex.
const std::vector< std::vector< double > > & get_stop_positions () const
 Accesses all trains' scheduled stop positions.
const std::vector< double > & get_stop_positions_of_tr (size_t train_id) const
 Returns the stop positions of one train.
double train_edge_length (size_t tr) const
 Returns the length of the current edge sequence of a train.
double get_edge_position (size_t train_id, size_t edge_id) const
 Returns the route position at which an edge ends, i.e., the position of its target vertex.
size_t get_edge_at_position (size_t train_id, double position) const
 Returns the edge that contains a route position.
bool is_route_end_valid_stop_pos (size_t tr, const cda_rail::index_vector &edges) const
 Checks whether a route end can serve as the next stop position.
bool is_current_pos_valid_stop_position (size_t tr) const
 Checks whether the train's current last edge is a valid stop position.
SimulatorState get_simulator_state () const
 The full simulator state.
void set_simulator_state (SimulatorState state)
 Replaces the full simulator state.
void set_train_edges (std::vector< cda_rail::index_vector > tr_edges)
 Replaces all train edge sequences.
void set_train_edges_of_tr (size_t train_id, cda_rail::index_vector edges)
 Replaces the edge sequence of one train.
void append_train_edge_to_tr (size_t train_id, cda_rail::Network::EdgeInput const &edge)
 Appends one edge to a train edge sequence.
void set_ttd_orders (std::vector< cda_rail::index_vector > orders)
 Replaces all TTD train orders.
void set_ttd_orders_of_ttd (size_t ttd_index, cda_rail::index_vector orders)
 Replaces the order stored for one TTD section.
void set_vertex_orders (std::vector< cda_rail::index_vector > orders)
 Replaces all vertex train orders.
void set_vertex_orders_of_vertex (cda_rail::Network::VertexInput const &vertex, cda_rail::index_vector orders)
 Replaces the train order stored for one vertex.
void set_stop_positions (std::vector< std::vector< double > > positions)
 Replaces all stop-position vectors.
void set_stop_positions_of_tr (size_t train_id, std::vector< double > positions)
 Replaces the stop positions of one train.
void append_stop_position_to_tr (size_t train_id, double position)
 Appends one stop position to a train.
void append_stop_edge_to_tr (size_t train_id, size_t edge)
 Appends a stop edge reference to a train.
void append_current_stop_position_of_tr (size_t train_id)
 Appends the current route-end position as a stop for a train.
bool is_final_state () const
 Checks whether the current simulator state is terminal.
SimulatorResults simulate (double dt=6.0, bool late_entry_possible=false, bool limit_speed_by_leaving_edges=true, bool save_trajectories=false) const
 Simulates with default values, in particular a time step of 6 seconds and blocking the last vertex of a partial route.
cda_rail::index_set trains_on_path (cda_rail::index_vector const &edges, bool also_reverse_path=false) const
 Returns the trains whose current routes contain a path.
cda_rail::index_set trains_on_path (cda_rail::index_vector const &edges, std::vector< cda_rail::index_vector > const &tr_edges, bool also_reverse_path=false) const
 Returns the trains from provided routes that contain a path.

Additional Inherited Members

Static Public Member Functions inherited from cda_rail::simulator::GeneralSimulator
static cda_rail::index_set trains_on_path (cda_rail::index_vector const &edges, std::vector< cda_rail::index_vector > const &tr_edges, Network const &network, bool also_reverse_path=false)
 Returns the trains from provided routes that contain a path.
Protected Member Functions inherited from cda_rail::simulator::GeneralSimulator
 GeneralSimulator (std::shared_ptr< const cda_rail::instances::GeneralProblemInstanceWithScheduleAndRoutes > instance, std::vector< cda_rail::index_set > ttd_sections)
 Constructs a simulator from shared instance data.
 GeneralSimulator (std::shared_ptr< const cda_rail::instances::GeneralProblemInstanceWithScheduleAndRoutes > instance, std::vector< cda_rail::index_set > ttd_sections, std::vector< cda_rail::index_vector > train_edges, std::vector< cda_rail::index_vector > ttd_orders, std::vector< cda_rail::index_vector > vertex_orders, std::vector< std::vector< double > > stop_positions)
 Constructs a simulator from shared instance data and explicit state.
double tr_braking_distance (size_t tr, double v) const
 Computes braking distance for a train at a given speed.
std::vector< double > edge_milestones (size_t tr) const
 Returns cumulative edge milestones for a train route.
bool is_on_route (size_t tr, size_t edge_id) const
 Checks whether an edge is on a train's current route.
std::vector< std::unordered_set< size_t > > tr_on_edges () const
 Returns, for each edge, the trains currently using it.

Detailed Description

Simulates the trains of a moving block instance greedily.

Every train drives as fast as the moving block separation, its own dynamics, and the orders of the state allow, so that the simulated trajectories are the best ones for the given routing, ordering, and stopping decisions. The simulation advances in time steps of the given length until every train has left the network, or until nothing moves any more, see CYCLE_LIMIT.

As in the moving block MILP, a train leaves the network once its rear has passed its exit vertex, which is when its scheduled exit time and speed apply. Until then, it occupies its last edge, beyond whose end the route continues at the edge's speed limit. A train only waits within the network, i.e., at the latest with its front at the exit vertex, unless it is kept behind a solution, see set_position_bound.

Member Typedef Documentation

◆ PositionBoundFunction

Initial value:
std::function<std::optional<PositionBound>(size_t tr, double t)>

The PositionBound of train tr at time t, or std::nullopt if the train is not restricted.

Constructor & Destructor Documentation

◆ GreedySimulator() [1/4]

cda_rail::simulator::GreedySimulator::GreedySimulator ( cda_rail::instances::GeneralPerformanceOptimizationInstance const & instance,
std::vector< cda_rail::index_set > ttd_sections )
explicit

Constructs a greedy simulator from an instance and TTD sections.

Parameters
instancePerformance optimization instance.
ttd_sectionsTTD sections used by the simulator.

◆ GreedySimulator() [2/4]

cda_rail::simulator::GreedySimulator::GreedySimulator ( cda_rail::instances::GeneralPerformanceOptimizationInstance const & instance,
std::vector< cda_rail::index_set > ttd_sections,
std::vector< cda_rail::index_vector > train_edges,
std::vector< cda_rail::index_vector > ttd_orders,
std::vector< cda_rail::index_vector > vertex_orders,
std::vector< std::vector< double > > stop_positions )
explicit

Constructs a greedy simulator with explicit state vectors.

Parameters
instancePerformance optimization instance.
ttd_sectionsTTD sections used by the simulator.
train_edgesPer-train edge sequences.
ttd_ordersPer-TTD train orders.
vertex_ordersPer-vertex train orders.
stop_positionsPer-train stop positions.

◆ GreedySimulator() [3/4]

cda_rail::simulator::GreedySimulator::GreedySimulator ( GreedySimulator const & )
default

Copy constructor.

◆ GreedySimulator() [4/4]

cda_rail::simulator::GreedySimulator::GreedySimulator ( GreedySimulator && )
defaultnoexcept

Move constructor.

◆ ~GreedySimulator()

cda_rail::simulator::GreedySimulator::~GreedySimulator ( )
overridedefault

Virtual destructor.

Member Function Documentation

◆ first_come_first_served_state()

std::optional< cda_rail::simulator::SimulatorState > cda_rail::simulator::GreedySimulator::first_come_first_served_state ( double dt,
bool late_entry_possible,
bool limit_speed_by_leaving_edges ) const
nodiscardoverridevirtual

Decides every open order first come, first served, see GeneralSimulator::first_come_first_served_state.

A train gets to a TTD section, or to its exit vertex, once its moving authority would extend into the section, respectively up to the end of its route, i.e., once the order is checked for it, and to its entry vertex once it is due to enter. Trains getting somewhere within the same time step get there in the order in which the simulation handles them, entering ones by their entry times.

Two trains that use a stretch of track in opposite directions would block each other if each one entered it from its end. Hence, the stretch, namely every TTD section and vertex from the one at which a train gets to the shared track up to the one at which it leaves it, is given to the train that gets to it first: this train gets to all of them at once. If the other train got to one of them before, or the given state lets it pass one of them before this train, the other train came first and gets to the others before. Since a train of the given state that has not gotten somewhere yet is no obstacle, a stretch of which each train holds one end by the given state still goes to the train getting to it first.

If a train misses its entry time that way, it passes before the train that kept it from entering last, at every TTD section and vertex at which the given state leaves their order open, and the orders are decided anew. Since every such retry adds a train to an order of the given state, there are only finitely many.

Reimplemented from cda_rail::simulator::GeneralSimulator.

◆ get_instance()

instances::GeneralPerformanceOptimizationInstance const * cda_rail::simulator::GreedySimulator::get_instance ( ) const
inlinenodiscardoverridevirtual

Retrieves the typed performance optimization instance.

Returns
Const pointer to the GeneralPerformanceOptimizationInstance for this simulator.

Reimplemented from cda_rail::simulator::GeneralSimulator.

◆ operator=() [1/2]

GreedySimulator & cda_rail::simulator::GreedySimulator::operator= ( GreedySimulator && )
defaultnoexcept

Move assignment operator.

◆ operator=() [2/2]

GreedySimulator & cda_rail::simulator::GreedySimulator::operator= ( GreedySimulator const & )
default

Copy assignment operator.

◆ set_position_bound()

void cda_rail::simulator::GreedySimulator::set_position_bound ( PositionBoundFunction bound,
index_set trains_with_feasible_bound = {} )
inline

Restricts the trains to the positions given by bound.

After every time step, a train's braking point must not exceed the bound at the end of that step, and neither must its front. If this is not even possible by braking fully, the train brakes fully until it is behind the bound again. A train only enters the network once its braking point at the entry is within the bound. This replays the speed decisions of a given solution, whose trains are hence not overtaken. As long as a train is restricted, it may wait without the simulation being considered deadlocked.

A train whose bound follows its dynamics, i.e., never asks it to brake harder than it can, can always stay behind the bound. It hence leaves no earlier than the train of that solution, so that its exit time is not enforced by apply_exit_time, and it may leave the network as slowly as the train of the solution. Any other train might not be able to stop at its exit vertex in time when following its bound, which apply_exit_time foresees. No train is counted as leaving before its exit time.

Parameters
boundThe bound, see PositionBoundFunction.
trains_with_feasible_boundThe trains whose bound follows their dynamics.

◆ simulate() [1/2]

cda_rail::simulator::SimulatorResults cda_rail::simulator::GreedySimulator::simulate ( double dt,
bool late_entry_possible,
bool limit_speed_by_leaving_edges,
bool save_trajectories,
bool block_vertices_after_disappearing ) const
nodiscardoverridevirtual

Runs the greedy simulation in time steps of length dt.

Parameters
dtSimulation time step in seconds.
late_entry_possibleWhether trains may enter later than scheduled.
limit_speed_by_leaving_edgesWhether leaving edges constrain speed.
save_trajectoriesWhether to retain detailed trajectories.
block_vertices_after_disappearingWhether trains block their last vertex after disappearing on a partial route.
Returns
Simulation results.

Implements cda_rail::simulator::GeneralSimulator.

◆ simulate() [2/2]

SimulatorResults cda_rail::simulator::GeneralSimulator::simulate ( double dt = 6.0,
bool late_entry_possible = false,
bool limit_speed_by_leaving_edges = true,
bool save_trajectories = false ) const
inlinenodiscard

Simulates with default values, in particular a time step of 6 seconds and blocking the last vertex of a partial route.


The documentation for this class was generated from the following files: