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

Simulates the trains of a moving block instance event by event. More...

#include <EventSimulator.hpp>

Inheritance diagram for cda_rail::simulator::EventSimulator:
cda_rail::simulator::GeneralSimulator

Classes

class  Run

Public Member Functions

 EventSimulator (cda_rail::instances::GeneralPerformanceOptimizationInstance const &instance, std::vector< cda_rail::index_set > ttd_sections)
 Constructs an event-based simulator from an instance and TTD sections.
 EventSimulator (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 an event-based simulator with explicit state vectors.
 EventSimulator (EventSimulator const &)=default
 Copy constructor.
 EventSimulator (EventSimulator &&)=default
 Move constructor.
EventSimulator & operator= (EventSimulator const &)=default
 Copy assignment operator.
EventSimulator & operator= (EventSimulator &&)=default
 Move assignment operator.
 ~EventSimulator () override=default
 Virtual destructor.
instances::GeneralPerformanceOptimizationInstance const * get_instance () const override
 Retrieves the typed performance optimization instance.
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 event-based simulation.
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.
virtual std::optional< SimulatorState > first_come_first_served_state (double dt, bool late_entry_possible, bool limit_speed_by_leaving_edges) const
 Decides every order that the current state leaves open first come, first served.
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 event by event.

The trains drive by the same rules as in the GreedySimulator. Instead of advancing all trains in time steps of a fixed length, however, a train plans its fastest movement up to the end of its movement authority and is only simulated again once something relevant to it happens, e.g., once it has reached a stop or once the train it waits for has passed. Trains that wait for another train are woken up by that train.

Hence, the trajectories are exact, apart from one approximation: if a train's movement authority ends at the rear of the train ahead, it plans as if that rear stayed where it is. It is simulated again once it starts to brake, but at the earliest after dt seconds, see simulate.

The simulator is based on Sebastian Ludwig's bachelor's thesis "Event-Based Simulation of Modern Railway Networks", Technical University of Munich, 2026.

Constructor & Destructor Documentation

◆ EventSimulator() [1/4]

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

Constructs an event-based simulator from an instance and TTD sections.

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

◆ EventSimulator() [2/4]

cda_rail::simulator::EventSimulator::EventSimulator ( 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 an event-based 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.

◆ EventSimulator() [3/4]

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

Copy constructor.

◆ EventSimulator() [4/4]

cda_rail::simulator::EventSimulator::EventSimulator ( EventSimulator && )
default

Move constructor.

◆ ~EventSimulator()

cda_rail::simulator::EventSimulator::~EventSimulator ( )
overridedefault

Virtual destructor.

Member Function Documentation

◆ get_instance()

instances::GeneralPerformanceOptimizationInstance const * cda_rail::simulator::EventSimulator::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]

EventSimulator & cda_rail::simulator::EventSimulator::operator= ( EventSimulator && )
default

Move assignment operator.

◆ operator=() [2/2]

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

Copy assignment operator.

◆ simulate() [1/2]

cda_rail::simulator::SimulatorResults cda_rail::simulator::EventSimulator::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 event-based simulation.

Parameters
dtMinimal time in seconds after which a train whose movement authority ends at the rear of another train is simulated again.
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: