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

#include <GeneralSimulator.hpp>

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

Public Member Functions

 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.
virtual instances::GeneralProblemInstanceWithScheduleAndRoutes const * get_instance () const
 Provides access to the problem instance for this simulator.
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.
virtual SimulatorResults simulate (double dt, bool late_entry_possible, bool limit_speed_by_leaving_edges, bool save_trajectories, bool block_vertices_after_disappearing) const =0
 Simulates train movements given the current routing, ordering, and stopping configuration.
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.

Static Public Member Functions

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

 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

This abstract class defines the interface for a general simulator to simulate train trajectories given all routing, ordering, and stopping information. It can, e.g., be used within search algorithms like A* for objective evaluation. This abstract class defines all necessary functions to be implemented and provides some general helper functions.

Constructor & Destructor Documentation

◆ GeneralSimulator() [1/6]

cda_rail::simulator::GeneralSimulator::GeneralSimulator ( std::shared_ptr< const cda_rail::instances::GeneralProblemInstanceWithScheduleAndRoutes > instance,
std::vector< cda_rail::index_set > ttd_sections )
protected

Constructs a simulator from shared instance data.

Parameters
instanceShared problem instance.
ttd_sectionsTTD sections used by the simulator.

◆ GeneralSimulator() [2/6]

cda_rail::simulator::GeneralSimulator::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 )
protected

Constructs a simulator from shared instance data and explicit state.

Parameters
instanceShared problem 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.

◆ GeneralSimulator() [3/6]

cda_rail::simulator::GeneralSimulator::GeneralSimulator ( instances::GeneralProblemInstanceWithScheduleAndRoutes & instance,
std::vector< cda_rail::index_set > ttd_sections )

Constructs a simulator from a mutable instance reference.

Parameters
instanceProblem instance.
ttd_sectionsTTD sections used by the simulator.

◆ GeneralSimulator() [4/6]

cda_rail::simulator::GeneralSimulator::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.

Parameters
instanceProblem 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.

◆ ~GeneralSimulator()

virtual cda_rail::simulator::GeneralSimulator::~GeneralSimulator ( )
virtualdefault

Virtual destructor.

Ensures proper cleanup when derived class instances are deleted through base class pointers.

◆ GeneralSimulator() [5/6]

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

Copy constructor.

◆ GeneralSimulator() [6/6]

cda_rail::simulator::GeneralSimulator::GeneralSimulator ( GeneralSimulator && )
default

Move constructor.

Member Function Documentation

◆ append_current_stop_position_of_tr()

void cda_rail::simulator::GeneralSimulator::append_current_stop_position_of_tr ( size_t train_id)

Appends the current route-end position as a stop for a train.

◆ append_stop_edge_to_tr()

void cda_rail::simulator::GeneralSimulator::append_stop_edge_to_tr ( size_t train_id,
size_t edge )

Appends a stop edge reference to a train.

◆ append_stop_position_to_tr()

void cda_rail::simulator::GeneralSimulator::append_stop_position_to_tr ( size_t train_id,
double position )

Appends one stop position to a train.

◆ append_train_edge_to_tr()

void cda_rail::simulator::GeneralSimulator::append_train_edge_to_tr ( size_t train_id,
cda_rail::Network::EdgeInput const & edge )

Appends one edge to a train edge sequence.

◆ edge_milestones()

std::vector< double > cda_rail::simulator::GeneralSimulator::edge_milestones ( size_t tr) const
nodiscardprotected

Returns cumulative edge milestones for a train route.

Parameters
trTrain index.
Returns
Edge milestone positions in metres.

◆ first_come_first_served_state()

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

Decides every order that the current state leaves open first come, first served.

The routes and stops are taken as they are, and the trains of every order of the state keep their relative order. Every train that is not yet in the order of a TTD section, entry or exit vertex of its route is inserted into that order once it gets there in the simulation, i.e., once it needs it for its moving authority: behind the trains that got there before it, and hence ahead of the trains of the state that have not gotten there yet.

Parameters
dtSee simulate.
late_entry_possibleSee simulate.
limit_speed_by_leaving_edgesSee simulate.
Returns
The state with the realized orders, or std::nullopt if the trains do not all reach the ends of their routes that way.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf the simulator does not support this.

Reimplemented in cda_rail::simulator::GreedySimulator.

◆ get_edge_at_position()

size_t cda_rail::simulator::GeneralSimulator::get_edge_at_position ( size_t train_id,
double position ) const
nodiscard

Returns the edge that contains a route position.

Parameters
train_idTrain index.
positionPosition on the train route.
Returns
Edge index containing position.

◆ get_edge_position()

double cda_rail::simulator::GeneralSimulator::get_edge_position ( size_t train_id,
size_t edge_id ) const
nodiscard

Returns the route position at which an edge ends, i.e., the position of its target vertex.

Parameters
train_idTrain index.
edge_idEdge index on the route.
Returns
Position of the edge end in metres.

◆ get_instance()

virtual instances::GeneralProblemInstanceWithScheduleAndRoutes const * cda_rail::simulator::GeneralSimulator::get_instance ( ) const
inlinenodiscardvirtual

Provides access to the problem instance for this simulator.

Returns
Const pointer to the problem instance.

Reimplemented in cda_rail::simulator::EventSimulator, and cda_rail::simulator::GreedySimulator.

◆ get_simulator_state()

SimulatorState cda_rail::simulator::GeneralSimulator::get_simulator_state ( ) const
inlinenodiscard

The full simulator state.

◆ get_stop_positions()

const std::vector< std::vector< double > > & cda_rail::simulator::GeneralSimulator::get_stop_positions ( ) const
inlinenodiscard

Accesses all trains' scheduled stop positions.

Returns
Const reference to a vector where each element is a vector of stop positions for the corresponding train.

◆ get_stop_positions_of_tr()

const std::vector< double > & cda_rail::simulator::GeneralSimulator::get_stop_positions_of_tr ( size_t train_id) const
nodiscard

Returns the stop positions of one train.

Parameters
train_idTrain index.
Returns
Stop-position vector for the specified train.

◆ get_train_edges()

const std::vector< cda_rail::index_vector > & cda_rail::simulator::GeneralSimulator::get_train_edges ( ) const
inlinenodiscard

Accesses the edge sequences for all trains.

Returns
The per-train edge sequences.

◆ get_train_edges_of_tr()

const cda_rail::index_vector & cda_rail::simulator::GeneralSimulator::get_train_edges_of_tr ( size_t train_id) const
nodiscard

Returns the current edge sequence for one train.

Parameters
train_idTrain index.
Returns
Edge sequence for the specified train.

◆ get_ttd()

std::optional< size_t > cda_rail::simulator::GeneralSimulator::get_ttd ( Network::EdgeInput const & edge) const
nodiscard

Returns the TTD section containing an edge, if any.

Parameters
edgeEdge descriptor.
Returns
TTD section index, or std::nullopt if the edge is not in any configured TTD section.

◆ get_ttd_orders()

const std::vector< cda_rail::index_vector > & cda_rail::simulator::GeneralSimulator::get_ttd_orders ( ) const
inlinenodiscard

Retrieves the ordering vectors for all TTD sections.

Returns
const std::vector<index_vector>& The per-TTD ordering vectors.

◆ get_ttd_orders_of_ttd()

const cda_rail::index_vector & cda_rail::simulator::GeneralSimulator::get_ttd_orders_of_ttd ( size_t ttd_index) const
nodiscard

Returns the train order for one TTD section.

Parameters
ttd_indexTTD section index.
Returns
Train order assigned to the specified TTD.

◆ get_ttd_sections()

const std::vector< cda_rail::index_set > & cda_rail::simulator::GeneralSimulator::get_ttd_sections ( ) const
inlinenodiscard

Retrieves the TTD sections considered by the simulator.

Returns
const std::vector<cda_rail::index_set>& Vector of TTD section identifier sets.

◆ get_vertex_orders()

const std::vector< cda_rail::index_vector > & cda_rail::simulator::GeneralSimulator::get_vertex_orders ( ) const
inlinenodiscard

Accesses the train ordering for each vertex.

Returns
const std::vector<cda_rail::index_vector>& The ordering vectors per vertex.

◆ get_vertex_orders_of_vertex()

const cda_rail::index_vector & cda_rail::simulator::GeneralSimulator::get_vertex_orders_of_vertex ( Network::VertexInput const & vertex) const
nodiscard

Returns the train order stored for a vertex.

Parameters
vertexVertex descriptor.
Returns
Train order assigned to the specified vertex.

◆ is_current_pos_valid_stop_position()

bool cda_rail::simulator::GeneralSimulator::is_current_pos_valid_stop_position ( size_t tr) const
inlinenodiscard

Checks whether the train's current last edge is a valid stop position.

Parameters
trTrain ID.
Returns
true if the position is valid for stopping, false otherwise.

This function checks if the current last edge can be used as a stop for a specific train. A stop is possible, if the train length back from the target vertex is fully within the next station.

Parameters
trThe id of the train to check.
Returns
: A boolean indicating whether the current position is a valid stop position.

◆ is_final_state()

bool cda_rail::simulator::GeneralSimulator::is_final_state ( ) const
nodiscard

Checks whether the current simulator state is terminal.

Returns
true if no further state extension is needed.

◆ is_on_route()

bool cda_rail::simulator::GeneralSimulator::is_on_route ( size_t tr,
size_t edge_id ) const
nodiscardprotected

Checks whether an edge is on a train's current route.

Parameters
trTrain index.
edge_idEdge index.
Returns
true if the edge is on the route.

◆ is_route_end_valid_stop_pos()

bool cda_rail::simulator::GeneralSimulator::is_route_end_valid_stop_pos ( size_t tr,
const cda_rail::index_vector & edges ) const
inlinenodiscard

Checks whether a route end can serve as the next stop position.

Parameters
trTrain index.
edgesCurrent route edges.
Returns
true if the route end is a valid stop position.

◆ operator=() [1/2]

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

Move assignment operator.

◆ operator=() [2/2]

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

Copy assignment operator.

◆ set_simulator_state()

void cda_rail::simulator::GeneralSimulator::set_simulator_state ( SimulatorState state)

Replaces the full simulator state.

◆ set_stop_positions()

void cda_rail::simulator::GeneralSimulator::set_stop_positions ( std::vector< std::vector< double > > positions)

Replaces all stop-position vectors.

◆ set_stop_positions_of_tr()

void cda_rail::simulator::GeneralSimulator::set_stop_positions_of_tr ( size_t train_id,
std::vector< double > positions )

Replaces the stop positions of one train.

◆ set_train_edges()

void cda_rail::simulator::GeneralSimulator::set_train_edges ( std::vector< cda_rail::index_vector > tr_edges)

Replaces all train edge sequences.

◆ set_train_edges_of_tr()

void cda_rail::simulator::GeneralSimulator::set_train_edges_of_tr ( size_t train_id,
cda_rail::index_vector edges )

Replaces the edge sequence of one train.

◆ set_ttd_orders()

void cda_rail::simulator::GeneralSimulator::set_ttd_orders ( std::vector< cda_rail::index_vector > orders)

Replaces all TTD train orders.

◆ set_ttd_orders_of_ttd()

void cda_rail::simulator::GeneralSimulator::set_ttd_orders_of_ttd ( size_t ttd_index,
cda_rail::index_vector orders )

Replaces the order stored for one TTD section.

◆ set_vertex_orders()

void cda_rail::simulator::GeneralSimulator::set_vertex_orders ( std::vector< cda_rail::index_vector > orders)

Replaces all vertex train orders.

◆ set_vertex_orders_of_vertex()

void cda_rail::simulator::GeneralSimulator::set_vertex_orders_of_vertex ( cda_rail::Network::VertexInput const & vertex,
cda_rail::index_vector orders )

Replaces the train order stored for one vertex.

◆ simulate() [1/2]

virtual SimulatorResults cda_rail::simulator::GeneralSimulator::simulate ( double dt,
bool late_entry_possible,
bool limit_speed_by_leaving_edges,
bool save_trajectories,
bool block_vertices_after_disappearing ) const
nodiscardpure virtual

Simulates train movements given the current routing, ordering, and stopping configuration.

For partial routes, it is assumed that trains instantaneously stop at their route end, where they disappear.

Parameters
dtTime step of the greedy simulator in seconds. The event-based simulator uses it as the minimal time after which a train following another one 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
SimulatorResults containing the simulation outcome, including train exit times, stop timestamps, vertex headways, and—when enabled—train trajectories over time.

Implemented in cda_rail::simulator::EventSimulator, and cda_rail::simulator::GreedySimulator.

◆ 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.

◆ tr_braking_distance()

double cda_rail::simulator::GeneralSimulator::tr_braking_distance ( size_t tr,
double v ) const
nodiscardprotected

Computes braking distance for a train at a given speed.

Parameters
trTrain index.
vSpeed.
Returns
Braking distance in metres.

◆ tr_on_edges()

std::vector< std::unordered_set< size_t > > cda_rail::simulator::GeneralSimulator::tr_on_edges ( ) const
nodiscardprotected

Returns, for each edge, the trains currently using it.

Returns
Edge-indexed sets of train indices.

◆ train_edge_length()

double cda_rail::simulator::GeneralSimulator::train_edge_length ( size_t tr) const
nodiscard

Returns the length of the current edge sequence of a train.

Parameters
trTrain index.
Returns
Route length of the current train edge sequence.

◆ trains_on_path() [1/3]

cda_rail::index_set cda_rail::simulator::GeneralSimulator::trains_on_path ( cda_rail::index_vector const & edges,
bool also_reverse_path = false ) const
inlinenodiscard

Returns the trains whose current routes contain a path.

Parameters
edgesPath edges to test.
also_reverse_pathWhether to also test the reverse path.
Returns
Set of train indices using the path.

◆ trains_on_path() [2/3]

cda_rail::index_set cda_rail::simulator::GeneralSimulator::trains_on_path ( cda_rail::index_vector const & edges,
std::vector< cda_rail::index_vector > const & tr_edges,
bool also_reverse_path = false ) const
inlinenodiscard

Returns the trains from provided routes that contain a path.

Parameters
edgesPath edges to test.
tr_edgesPer-train edge sequences.
also_reverse_pathWhether to also test the reverse path.
Returns
Set of train indices using the path.

◆ trains_on_path() [3/3]

cda_rail::index_set cda_rail::simulator::GeneralSimulator::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 )
staticnodiscard

Returns the trains from provided routes that contain a path.

Parameters
edgesPath edges to test.
tr_edgesPer-train edge sequences.
networkNetwork used for reverse-path lookup.
also_reverse_pathWhether to also test the reverse path.
Returns
Set of train indices using the path.

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