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

The trains of an instance together with what they are to do. More...

#include <Timetable.hpp>

Public Member Functions

 Timetable ()=default
 Creates an empty timetable.
 Timetable (StationList station_list, TrainList train_list, const std::vector< Schedule > &schedules)
 Constructs a timetable from explicit station, train, and schedule data.
 Timetable (const std::filesystem::path &p, const Network &network)
 Loads a timetable from a filesystem path.
 Timetable (const std::string &path, const Network &network)
 Constructs a timetable from a file path specified as a string.
 Timetable (char const *const path, Network const &network)
 Constructs a timetable from a C-string path.
 Timetable (const Timetable &other)
 Copy constructor that performs a deep copy.
Timetable & operator= (const Timetable &other)
 Copy assignment operator that performs a deep copy.
 Timetable (Timetable &&) noexcept=default
 Move constructor.
Timetable & operator= (Timetable &&) noexcept=default
 Move assignment operator.
constexpr auto begin () const
 Provides a read-only iterator to the first schedule.
constexpr auto end () const
 Provides the end iterator for iterating over schedules.
constexpr auto cbegin () const
 Read-only iterator to the first schedule (explicit const).
constexpr auto cend () const
 Returns a const iterator to one past the last schedule.
constexpr auto crbegin () const
 Const reverse iterator to the last schedule.
constexpr auto crend () const
 Read-only reverse iterator before the first schedule.
void export_timetable (const std::filesystem::path &p, const Network &network) const
 Exports the timetable to the given filesystem path.
void export_timetable (const std::string &path, const Network &network) const
 Writes the timetable to a file.
void export_timetable (char const *const path, Network const &network) const
 Exports the timetable to a file.
StationList const & get_station_list () const
 Provides access to the station list.
TrainList const & get_train_list () const
 Provides access to the train list.
Schedule const & get_schedule (size_t const trainIndex) const
 Retrieves the schedule for a given train.
Schedule const & get_schedule (std::string const &train_name) const
 Retrieves the schedule for a train by name.
double latest_exit_time () const
 Returns the latest scheduled exit time across all trains.
Train & editable_train (size_t const index)
 Provides mutable access to a train by index.
Train & editable_train (std::string const &name)
 Obtains a mutable reference to a train by name.
Schedule & editable_schedule (size_t const trainIndex)
 Provides mutable access to the schedule of a train.
Schedule & editable_schedule (std::string const &train_name)
 Provides mutable access to the schedule of a train by name.
std::vector< std::pair< size_t, std::vector< cda_rail::index_vector > > > get_stop_tracks (size_t const tr, std::string const &station_name, Network const &network, cda_rail::index_set const &edges_to_consider) const
 Retrieves available track segments for a train at a station.
void add_empty_station (const std::string &station_name)
 Adds a new station to the timetable with no scheduled stops.
void insert_stop (size_t train_index, std::string const &station_name, double service_time, double service_duration)
 Inserts a scheduled stop for a train identified by index.
void insert_stop (std::string const &train_name, std::string const &station_name, double const serviceTime, double const serviceDuration)
 Inserts a scheduled stop for a train identified by name.
void remove_stop (size_t train_index, std::string const &station_name, bool throw_exception_if_not_existent=true)
 Removes a stop from a train's schedule by train index.
void remove_stop (std::string const &train_name, std::string const &station_name, bool throw_exception_if_not_existent=true)
 Removes a stop from a train's schedule by station name.
void add_track_to_station (std::string const &station_name, Network::EdgeInput const &new_edge, Network const &network)
 Adds a new track to the specified station.
size_t add_train (std::string const &train_name, double length, double max_speed, double acceleration, double deceleration, bool tim, double entry_time, double initial_velocity, Network::VertexInput const &entry_vertex, double exit_time, double exit_velocity, Network::VertexInput const &exit_vertex, Network const &network)
 Adds a train to the timetable with specified entry/exit constraints.
size_t add_train (std::string const &train_name, double length, double max_speed, double acceleration, double deceleration, double entry_time, double initial_velocity, Network::VertexInput const &entry_vertex, double exit_time, double exit_velocity, Network::VertexInput const &exit_vertex, Network const &network)
 Adds a new train to the timetable.
bool check_consistency (Network const &network) const
 Checks whether timetable data is consistent with the network.
void update_after_discretization (std::vector< std::pair< size_t, cda_rail::index_set > > const &new_edges)
 Updates the timetable after network discretization.
void update_after_discretization (std::vector< std::pair< size_t, cda_rail::index_vector > > const &new_edges)
 Updates the timetable after discretization.
std::pair< size_t, size_t > time_index_interval (size_t train_index, double dt, bool tn_inclusive=true) const
 Returns the discrete time-index interval relevant for one train.
std::pair< size_t, size_t > time_index_interval (std::string const &train_name, double const dt, bool const tnInclusive=true) const
 Computes the time index interval for a train, identified by name.

Static Public Member Functions

static Timetable import_timetable (const std::string &path, const Network &network)
 Imports a timetable from a file.
static Timetable import_timetable (const std::filesystem::path &p, const Network &network)
 Imports a timetable from a file.
static Timetable import_timetable (char const *const path, const Network &network)
 Loads a timetable from a file.

Detailed Description

The trains of an instance together with what they are to do.

Holds the stations, the trains, and one schedule per train, where the schedule of a train is stored at the index the train has in the train list. The stops of a schedule refer to the stations of this timetable, which is why a timetable is deep copied.

Constructor & Destructor Documentation

◆ Timetable() [1/7]

cda_rail::Timetable::Timetable ( )
default

Creates an empty timetable.

◆ Timetable() [2/7]

cda_rail::Timetable::Timetable ( StationList station_list,
TrainList train_list,
const std::vector< Schedule > & schedules )

Constructs a timetable from explicit station, train, and schedule data.

Parameters
station_listStation list owned by the timetable.
train_listTrain list owned by the timetable.
schedulesSchedule vector indexed by train.

◆ Timetable() [3/7]

cda_rail::Timetable::Timetable ( const std::filesystem::path & p,
const Network & network )

Loads a timetable from a filesystem path.

Parameters
pPath to the timetable data.
networkNetwork used for validation and vertex resolution.

◆ Timetable() [4/7]

cda_rail::Timetable::Timetable ( const std::string & path,
const Network & network )
inline

Constructs a timetable from a file path specified as a string.

Parameters
pathPath to the timetable data.

◆ Timetable() [5/7]

cda_rail::Timetable::Timetable ( char const *const path,
Network const & network )
inline

Constructs a timetable from a C-string path.

Parameters
pathC-string path to the timetable file.
networkNetwork used for vertex validation.

◆ Timetable() [6/7]

cda_rail::Timetable::Timetable ( const Timetable & other)
inline

Copy constructor that performs a deep copy.

Creates new Station objects and updates all ScheduledStop references to point to the corresponding stations in the copied StationList.

Parameters
otherThe Timetable to copy from.

◆ Timetable() [7/7]

cda_rail::Timetable::Timetable ( Timetable && )
defaultnoexcept

Move constructor.

Member Function Documentation

◆ add_empty_station()

void cda_rail::Timetable::add_empty_station ( const std::string & station_name)
inline

Adds a new station to the timetable with no scheduled stops.

Parameters
station_nameName of the station to add.

◆ add_track_to_station()

void cda_rail::Timetable::add_track_to_station ( std::string const & station_name,
Network::EdgeInput const & new_edge,
Network const & network )
inline

Adds a new track to the specified station.

Parameters
station_nameName of the station.
new_edgeEdge input describing the new track.
networkNetwork context for validation and resolution.

◆ add_train() [1/2]

size_t cda_rail::Timetable::add_train ( std::string const & train_name,
double length,
double max_speed,
double acceleration,
double deceleration,
bool tim,
double entry_time,
double initial_velocity,
Network::VertexInput const & entry_vertex,
double exit_time,
double exit_velocity,
Network::VertexInput const & exit_vertex,
Network const & network )
inlinenodiscard

Adds a train to the timetable with specified entry/exit constraints.

Parameters
train_nameThe name identifier for the train.
lengthThe train's length.
max_speedThe train's maximum speed.
accelerationThe train's acceleration rate.
decelerationThe train's deceleration rate.
timWhether the train operates in time-independent movement mode.
entry_timeThe service start time at the entry vertex.
initial_velocityThe velocity at entry.
entry_vertexThe entry vertex specification.
exit_timeThe service end time at the exit vertex.
exit_velocityThe velocity at exit.
exit_vertexThe exit vertex specification.
Returns
size_t The index of the newly added train.

◆ add_train() [2/2]

size_t cda_rail::Timetable::add_train ( std::string const & train_name,
double length,
double max_speed,
double acceleration,
double deceleration,
double entry_time,
double initial_velocity,
Network::VertexInput const & entry_vertex,
double exit_time,
double exit_velocity,
Network::VertexInput const & exit_vertex,
Network const & network )
inlinenodiscard

Adds a new train to the timetable.

Parameters
train_nameName of the train.
lengthTrain length.
max_speedMaximum speed.
accelerationAcceleration rate.
decelerationDeceleration rate.
entry_timeScheduled entry time.
initial_velocityVelocity at entry.
entry_vertexEntry vertex; resolved against the network.
exit_timeScheduled exit time.
exit_velocityVelocity at exit.
exit_vertexExit vertex; resolved against the network.
networkNetwork to resolve vertex inputs against.
Returns
Index of the newly added train.

◆ begin()

auto cda_rail::Timetable::begin ( ) const
inlinenodiscardconstexpr

Provides a read-only iterator to the first schedule.

Returns
Const iterator to the beginning of the schedule list.

◆ cbegin()

auto cda_rail::Timetable::cbegin ( ) const
inlinenodiscardconstexpr

Read-only iterator to the first schedule (explicit const).

◆ cend()

auto cda_rail::Timetable::cend ( ) const
inlinenodiscardconstexpr

Returns a const iterator to one past the last schedule.

Returns
A const iterator to the position following the last schedule.

◆ check_consistency()

bool cda_rail::Timetable::check_consistency ( Network const & network) const
nodiscard

Checks whether timetable data is consistent with the network.

Verifies that entry and exit vertices exist and are terminal vertices, station tracks refer to valid network edges, scheduled stops are ordered by service time and use distinct stations, and each stop's service interval is contained in the train's entry/exit time window.

Parameters
networkThe network to which the timetable belongs.
Returns
True if the timetable is consistent with the network, false otherwise.

◆ crbegin()

auto cda_rail::Timetable::crbegin ( ) const
inlinenodiscardconstexpr

Const reverse iterator to the last schedule.

Returns
auto Const reverse iterator to the beginning of the reversed schedule sequence.

◆ crend()

auto cda_rail::Timetable::crend ( ) const
inlinenodiscardconstexpr

Read-only reverse iterator before the first schedule.

◆ editable_schedule() [1/2]

Schedule & cda_rail::Timetable::editable_schedule ( size_t const trainIndex)
inlinenodiscard

Provides mutable access to the schedule of a train.

Parameters
trainIndexThe index of the train.
Returns
Schedule& A mutable reference to the train's schedule.
Exceptions
exceptions::TrainNotExistentExceptionif the train does not exist.

◆ editable_schedule() [2/2]

Schedule & cda_rail::Timetable::editable_schedule ( std::string const & train_name)
inlinenodiscard

Provides mutable access to the schedule of a train by name.

Parameters
train_nameName of the train.
Returns
Schedule& A mutable reference to the train's schedule.
Exceptions
exceptions::TrainNotExistentExceptionif the train does not exist.

◆ editable_train() [1/2]

Train & cda_rail::Timetable::editable_train ( size_t const index)
inlinenodiscard

Provides mutable access to a train by index.

Returns
A mutable reference to the train at the given index.

◆ editable_train() [2/2]

Train & cda_rail::Timetable::editable_train ( std::string const & name)
inlinenodiscard

Obtains a mutable reference to a train by name.

Parameters
nameThe name of the train.
Returns
Train& A mutable reference to the Train with the given name.

◆ end()

auto cda_rail::Timetable::end ( ) const
inlinenodiscardconstexpr

Provides the end iterator for iterating over schedules.

Returns
A const iterator to the position past the last schedule.

◆ export_timetable() [1/3]

void cda_rail::Timetable::export_timetable ( char const *const path,
Network const & network ) const
inline

Exports the timetable to a file.

◆ export_timetable() [2/3]

void cda_rail::Timetable::export_timetable ( const std::filesystem::path & p,
const Network & network ) const

Exports the timetable to the given filesystem path.

Parameters
pOutput path.
networkNetwork context used during export.

◆ export_timetable() [3/3]

void cda_rail::Timetable::export_timetable ( const std::string & path,
const Network & network ) const
inline

Writes the timetable to a file.

Parameters
pathFile path where the timetable should be written.
networkNetwork context used for the export.

◆ get_schedule() [1/2]

Schedule const & cda_rail::Timetable::get_schedule ( size_t const trainIndex) const
inlinenodiscard

Retrieves the schedule for a given train.

Parameters
trainIndexThe index of the train.
Returns
const Schedule& The schedule for the specified train.
Exceptions
exceptions::TrainNotExistentExceptionif the train does not exist.

◆ get_schedule() [2/2]

Schedule const & cda_rail::Timetable::get_schedule ( std::string const & train_name) const
inlinenodiscard

Retrieves the schedule for a train by name.

Parameters
train_nameName of the train.
Returns
The Schedule for the specified train.
Exceptions
exceptions::TrainNotExistentExceptionif the train does not exist.

◆ get_station_list()

StationList const & cda_rail::Timetable::get_station_list ( ) const
inlinenodiscard

Provides access to the station list.

Returns
const StationList& Const reference to the station list.

◆ get_stop_tracks()

std::vector< std::pair< size_t, std::vector< cda_rail::index_vector > > > cda_rail::Timetable::get_stop_tracks ( size_t const tr,
std::string const & station_name,
Network const & network,
cda_rail::index_set const & edges_to_consider ) const
inlinenodiscard

Retrieves available track segments for a train at a station.

Parameters
trTrain index.
station_nameName of the station.
networkThe network containing track and vertex information.
edges_to_considerNetwork edges to filter available tracks.
Returns
Vector of pairs, each pairing a track identifier with index vectors indicating valid positioning ranges on that track for the specified train.

◆ get_train_list()

TrainList const & cda_rail::Timetable::get_train_list ( ) const
inlinenodiscard

Provides access to the train list.

Returns
const reference to the TrainList managed by this timetable.

◆ import_timetable() [1/3]

Timetable cda_rail::Timetable::import_timetable ( char const *const path,
const Network & network )
inlinestaticnodiscard

Loads a timetable from a file.

Parameters
pathFile path as a C-string.
networkNetwork used for validation.
Returns
Timetable loaded from the file.

◆ import_timetable() [2/3]

Timetable cda_rail::Timetable::import_timetable ( const std::filesystem::path & p,
const Network & network )
inlinestaticnodiscard

Imports a timetable from a file.

Parameters
pPath to the timetable file.
networkNetwork context for validating timetable data.
Returns
A Timetable loaded from the specified file.

◆ import_timetable() [3/3]

Timetable cda_rail::Timetable::import_timetable ( const std::string & path,
const Network & network )
inlinestaticnodiscard

Imports a timetable from a file.

Parameters
pathPath to the timetable file.
networkNetwork used for validation and context.
Returns
Timetable The imported timetable.

◆ insert_stop() [1/2]

void cda_rail::Timetable::insert_stop ( size_t train_index,
std::string const & station_name,
double service_time,
double service_duration )

Inserts a scheduled stop for a train identified by index.

Parameters
train_indexIndex of the train.
station_nameName of the station.
service_timeEarliest service start time.
service_durationMinimum service duration.

◆ insert_stop() [2/2]

void cda_rail::Timetable::insert_stop ( std::string const & train_name,
std::string const & station_name,
double const serviceTime,
double const serviceDuration )
inline

Inserts a scheduled stop for a train identified by name.

Parameters
train_nameName of the train.
station_nameName of the station.
serviceTimeEarliest service start time.
serviceDurationMinimum service duration.
Exceptions
cda_rail::exceptions::InvalidInputExceptionif the station already exists in the train's schedule.

◆ latest_exit_time()

double cda_rail::Timetable::latest_exit_time ( ) const
nodiscard

Returns the latest scheduled exit time across all trains.

Returns
Maximum exit time in the timetable, or 0 if no trains exist.

◆ operator=() [1/2]

Timetable & cda_rail::Timetable::operator= ( const Timetable & other)
inline

Copy assignment operator that performs a deep copy.

Parameters
otherThe Timetable to copy from.
Returns
Reference to this Timetable.

◆ operator=() [2/2]

Timetable & cda_rail::Timetable::operator= ( Timetable && )
defaultnoexcept

Move assignment operator.

◆ remove_stop() [1/2]

void cda_rail::Timetable::remove_stop ( size_t train_index,
std::string const & station_name,
bool throw_exception_if_not_existent = true )

Removes a stop from a train's schedule by train index.

Parameters
train_indexIndex of the train.
station_nameName of the station to remove.
throw_exception_if_not_existentIf true, throws when no matching stop exists.

◆ remove_stop() [2/2]

void cda_rail::Timetable::remove_stop ( std::string const & train_name,
std::string const & station_name,
bool throw_exception_if_not_existent = true )
inline

Removes a stop from a train's schedule by station name.

Parameters
train_nameName of the train.
station_nameName of the station to remove.
throw_exception_if_not_existentIf true, throws an exception if the station is not found in the schedule.
Exceptions
cda_rail::exceptions::InvalidInputExceptionIf throw_exception_if_not_existent is true and the station is not in the train's schedule.

◆ time_index_interval() [1/2]

std::pair< size_t, size_t > cda_rail::Timetable::time_index_interval ( size_t train_index,
double dt,
bool tn_inclusive = true ) const
nodiscard

Returns the discrete time-index interval relevant for one train.

Parameters
train_indexIndex of the train.
dtTime discretization step.
tn_inclusiveWhether the upper bound includes the final time index.
Returns
Pair (first_index, last_index).

◆ time_index_interval() [2/2]

std::pair< size_t, size_t > cda_rail::Timetable::time_index_interval ( std::string const & train_name,
double const dt,
bool const tnInclusive = true ) const
inlinenodiscard

Computes the time index interval for a train, identified by name.

Parameters
train_nameThe name of the train.
dtThe time discretization step.
tnInclusiveWhether to include the final time index. Defaults to true.
Returns
A pair (start_index, end_index) of discretized time indices for the train.

◆ update_after_discretization() [1/2]

void cda_rail::Timetable::update_after_discretization ( std::vector< std::pair< size_t, cda_rail::index_set > > const & new_edges)
inline

Updates the timetable after network discretization.

Parameters
new_edgesPairs of vertex IDs and their associated edge indices after discretization.

◆ update_after_discretization() [2/2]

void cda_rail::Timetable::update_after_discretization ( std::vector< std::pair< size_t, cda_rail::index_vector > > const & new_edges)
inline

Updates the timetable after discretization.

Parameters
new_edgesVector of pairs mapping edge identifiers to their discretized indices.

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