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

Collection of named train routes built on top of a railway network. More...

#include <Route.hpp>

Public Member Functions

 RouteMap ()=default
 Creates an empty route map with no routes.
 RouteMap (const std::filesystem::path &p, const Network &network)
 Loads all routes from a routes.json file inside directory p.
 RouteMap (const std::string &path, const Network &network)
 Convenience overload accepting a std::string path.
 RouteMap (const char *path, const Network &network)
 Convenience overload accepting a C-string path.
 RouteMap (const RouteMap &other)=default
 RouteMap (RouteMap &&other) noexcept=default
RouteMap & operator= (const RouteMap &other)=default
RouteMap & operator= (RouteMap &&other) noexcept=default
 Move-assigns another RouteMap to this one.
 ~RouteMap ()=default
auto begin () const
 Read-only iterator to the first route entry.
auto end () const
 Read-only iterator past the last route entry.
auto cbegin () const
 Returns a const iterator to the beginning of the routes.
auto cend () const
 Read-only iterator past the last route entry (explicit const).
size_t size () const
 Counts the number of stored train routes.
bool empty () const
 Determines whether the map contains no routes.
const Route & get_route (const std::string &train_name) const
 Returns the route assigned to the given train.
double route_length (const std::string &train_name, const Network &network) const
 Returns the total length of the route assigned to the given train.
bool has_route (const std::string &train_name) const
 Checks whether a route for the given train is stored in this map.
std::vector< ConflictPair > get_parallel_overlaps (const std::string &train1, const std::string &train2, const Network &network) const
 Finds segments where both trains travel in the same direction over the same track section.
std::vector< ConflictPair > get_ttd_overlaps (const std::string &train1, const std::string &train2, const Network &network) const
 Finds segments where both trains share an unbreakable (TTD) track section.
std::vector< ConflictPair > get_reverse_overlaps (const std::string &train1, const std::string &train2, const Network &network) const
 Finds segments where the two trains travel in opposite directions over the same physical track.
std::vector< ConflictPair > get_crossing_overlaps (const std::string &train1, const std::string &train2, const Network &network) const
 Finds all segments where the two trains could potentially block each other, regardless of travel direction.
void add_empty_route (const std::string &train_name)
 Registers an empty route for the given train name.
void add_empty_route (const std::string &train_name, const TrainList &trains)
 Registers an empty route for a train, verifying it exists in the train list first.
void push_back_edge (const std::string &train_name, Network::EdgeInput const &new_edge, const Network &network)
 Appends an edge at the end of the given train's route.
void push_front_edge (const std::string &train_name, Network::EdgeInput const &new_edge, const Network &network)
 Prepends an edge at the beginning of the given train's route.
void remove_first_edge (const std::string &train_name)
 Removes the first edge from the given train's route.
void remove_last_edge (const std::string &train_name)
 Removes the last edge from the given train's route.
void remove_route (const std::string &train_name)
 Removes the entire route for the given train from the map.
void export_routes (const std::filesystem::path &p, const Network &network) const
 Writes all routes to a routes.json file inside directory p.
void export_routes (const std::string &path, const Network &network) const
 Writes all routes to routes.json in the specified directory.
void export_routes (const char *path, const Network &network) const
 Exports routes to a directory specified by a C-string path.
bool check_consistency (const TrainList &trains, const Network &network, bool every_train_must_have_route=true) const
 Checks whether all stored routes are valid with respect to the given train list and network.
void update_after_discretization (const std::vector< std::pair< size_t, cda_rail::index_vector > > &new_edges)
 Updates all routes after a network discretization step.

Static Public Member Functions

static RouteMap import_routes (const std::filesystem::path &p, const Network &network)
 Loads routes from a directory into a new RouteMap.
static RouteMap import_routes (const std::string &path, const Network &network)
 Static factory: convenience overload accepting a std::string path.
static RouteMap import_routes (const char *path, const Network &network)
 Loads train routes from a file at the given directory path.

Detailed Description

Collection of named train routes built on top of a railway network.

A RouteMap maps each train (identified by its name string) to its Route. It supports building routes edge by edge, querying pairwise track conflicts between two trains, and serialising the whole collection to or from a JSON file on disk.

Constructor & Destructor Documentation

◆ RouteMap() [1/6]

cda_rail::RouteMap::RouteMap ( )
default

Creates an empty route map with no routes.

◆ RouteMap() [2/6]

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

Loads all routes from a routes.json file inside directory p.

Every route entry in the file is validated against network as edges are added: successor constraints are enforced and referenced vertices must exist.

Parameters
pPath to the directory that contains routes.json.
networkNetwork used to resolve and validate each edge.
Exceptions
cda_rail::exceptions::ImportExceptionIf p does not exist or is not a directory.
cda_rail::exceptions::EdgeNotExistentExceptionIf the file references a vertex name that does not exist in network.
cda_rail::exceptions::ConsistencyExceptionIf any loaded edge is not a valid successor of the previous edge on that route.

◆ RouteMap() [3/6]

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

Convenience overload accepting a std::string path.

Parameters
pathPath string pointing to the directory with routes.json.
networkNetwork used to validate the loaded routes.
See also
RouteMap(const std::filesystem::path&, const Network&)

◆ RouteMap() [4/6]

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

Convenience overload accepting a C-string path.

Parameters
pathNull-terminated path string.
networkNetwork used to validate the loaded routes.
See also
RouteMap(const std::filesystem::path&, const Network&)

◆ RouteMap() [5/6]

cda_rail::RouteMap::RouteMap ( const RouteMap & other)
default

◆ RouteMap() [6/6]

cda_rail::RouteMap::RouteMap ( RouteMap && other)
defaultnoexcept

◆ ~RouteMap()

cda_rail::RouteMap::~RouteMap ( )
default

Member Function Documentation

◆ add_empty_route() [1/2]

void cda_rail::RouteMap::add_empty_route ( const std::string & train_name)

Registers an empty route for the given train name.

The route is initially empty (no edges). Edges can be added afterwards with push_back_edge or push_front_edge.

Parameters
train_nameName to associate the new route with.
Exceptions
cda_rail::exceptions::InvalidInputExceptionIf a route for train_name is already registered.

◆ add_empty_route() [2/2]

void cda_rail::RouteMap::add_empty_route ( const std::string & train_name,
const TrainList & trains )

Registers an empty route for a train, verifying it exists in the train list first.

Parameters
train_nameName of the train.
trainsTrain list that train_name must be part of.
Exceptions
cda_rail::exceptions::TrainNotExistentExceptionIf train_name is not present in trains.
cda_rail::exceptions::InvalidInputExceptionIf a route for train_name is already registered.

◆ begin()

auto cda_rail::RouteMap::begin ( ) const
inlinenodiscard

Read-only iterator to the first route entry.

◆ cbegin()

auto cda_rail::RouteMap::cbegin ( ) const
inlinenodiscard

Returns a const iterator to the beginning of the routes.

◆ cend()

auto cda_rail::RouteMap::cend ( ) const
inlinenodiscard

Read-only iterator past the last route entry (explicit const).

◆ check_consistency()

bool cda_rail::RouteMap::check_consistency ( const TrainList & trains,
const Network & network,
bool every_train_must_have_route = true ) const
nodiscard

Checks whether all stored routes are valid with respect to the given train list and network.

A RouteMap is considered consistent when:

  • (if every_train_must_have_route is true) every train in trains has a registered route, and
  • every registered route belongs to a known train and is internally connected (each consecutive edge pair satisfies the successor relation).
Parameters
trainsList of all known trains.
networkNetwork used for successor checks.
every_train_must_have_routeIf true (the default), returns false whenever the number of stored routes differs from the number of trains in trains.
Returns
true if all consistency conditions are met, otherwise false.

◆ empty()

bool cda_rail::RouteMap::empty ( ) const
inlinenodiscard

Determines whether the map contains no routes.

Returns
true if no routes are stored, false otherwise.

◆ end()

auto cda_rail::RouteMap::end ( ) const
inlinenodiscard

Read-only iterator past the last route entry.

◆ export_routes() [1/3]

void cda_rail::RouteMap::export_routes ( const char * path,
const Network & network ) const
inline

Exports routes to a directory specified by a C-string path.

Parameters
pathNull-terminated destination directory path.
networkNetwork used to look up vertex names.

◆ export_routes() [2/3]

void cda_rail::RouteMap::export_routes ( const std::filesystem::path & p,
const Network & network ) const

Writes all routes to a routes.json file inside directory p.

Each route is stored as an ordered list of [source_vertex_name, target_vertex_name] pairs. The directory is created if it does not yet exist.

Parameters
pDestination directory for the output file.
networkNetwork used to look up vertex names for each edge.
Exceptions
cda_rail::exceptions::ExportExceptionIf the directory cannot be created.

◆ export_routes() [3/3]

void cda_rail::RouteMap::export_routes ( const std::string & path,
const Network & network ) const
inline

Writes all routes to routes.json in the specified directory.

Parameters
pathDestination directory as a string.
networkNetwork used to look up vertex names.

◆ get_crossing_overlaps()

std::vector< cda_rail::ConflictPair > cda_rail::RouteMap::get_crossing_overlaps ( const std::string & train1,
const std::string & train2,
const Network & network ) const
nodiscard

Finds all segments where the two trains could potentially block each other, regardless of travel direction.

Combines the results of get_ttd_overlaps and get_reverse_overlaps, sorts the merged list by start position on train1's route, and then merges consecutive intervals that overlap on both routes into a single ConflictPair. Use this function when you need a complete conflict picture for scheduling or safety checks.

Parameters
train1Name of the first train.
train2Name of the second train.
networkNetwork used for all sub-queries.
Returns
Sorted, de-duplicated list of conflict segments.
Precondition
Routes for both trains must exist in this map.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf either train has no registered route.

◆ get_parallel_overlaps()

std::vector< cda_rail::ConflictPair > cda_rail::RouteMap::get_parallel_overlaps ( const std::string & train1,
const std::string & train2,
const Network & network ) const
nodiscard

Finds segments where both trains travel in the same direction over the same track section.

Two trains are in a parallel overlap whenever consecutive edges on their respective routes are identical (same edge ids in the same order). Each returned ConflictPair represents one maximal such shared segment and gives the start/end positions (in metres from each route's beginning) and the set of underlying track ids.

Parameters
train1Name of the first train.
train2Name of the second train.
networkNetwork used to look up edge lengths and track ids.
Returns
List of parallel conflict segments; empty if the routes do not share any edges in the same direction.
Precondition
Routes for both trains must exist in this map.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf either train has no registered route.

◆ get_reverse_overlaps()

std::vector< cda_rail::ConflictPair > cda_rail::RouteMap::get_reverse_overlaps ( const std::string & train1,
const std::string & train2,
const Network & network ) const
nodiscard

Finds segments where the two trains travel in opposite directions over the same physical track.

A reverse overlap occurs when an edge on train1's route has a reverse counterpart (same physical track, opposite direction) on train2's route. Each returned ConflictPair covers the maximal consecutive stretch where this head-on situation persists. Positions are measured from each route's own start; note that for train2 the interval is traversed in reverse, so pos2.first < pos2.second still holds but the edges are visited in decreasing order.

Parameters
train1Name of the first train.
train2Name of the second train.
networkNetwork used to find reverse edge pairs and read edge lengths.
Returns
List of reverse conflict segments; empty if no head-on overlap exists.
Precondition
Routes for both trains must exist in this map.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf either train has no registered route.

◆ get_route()

const cda_rail::Route & cda_rail::RouteMap::get_route ( const std::string & train_name) const
nodiscard

Returns the route assigned to the given train.

Parameters
train_nameName of the train whose route is requested.
Returns
Const reference to the train's Route.
Precondition
A route for train_name must exist in this map.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf no route for train_name has been registered.

◆ get_ttd_overlaps()

std::vector< cda_rail::ConflictPair > cda_rail::RouteMap::get_ttd_overlaps ( const std::string & train1,
const std::string & train2,
const Network & network ) const
nodiscard

Finds segments where both trains share an unbreakable (TTD) track section.

A TTD overlap occurs when both routes use at least one edge that belongs to the same unbreakable section (a section where no VSS border may be placed). Each returned ConflictPair covers the full extent of that section on both routes and includes the involved track ids. Only non-breakable edges on train1's route trigger a check.

Parameters
train1Name of the first train.
train2Name of the second train.
networkNetwork used to identify unbreakable sections and edge lengths.
Returns
List of TTD conflict segments; empty if no unbreakable section is shared by both routes.
Precondition
Routes for both trains must exist in this map.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf either train has no registered route.

◆ has_route()

bool cda_rail::RouteMap::has_route ( const std::string & train_name) const
inlinenodiscard

Checks whether a route for the given train is stored in this map.

Parameters
train_nameName of the train to look up.
Returns
true if a route for train_name exists, otherwise false.

◆ import_routes() [1/3]

RouteMap cda_rail::RouteMap::import_routes ( const char * path,
const Network & network )
inlinestaticnodiscard

Loads train routes from a file at the given directory path.

Parameters
pathDirectory path containing routes.json.
networkNetwork used to validate referenced edges during loading.
Returns
RouteMap containing the loaded routes.
Exceptions
ImportExceptionif the directory does not exist or is not a directory.
EdgeNotExistentExceptionif the routes file references an unknown vertex or edge.
ConsistencyExceptionif any route contains invalid successor relations between consecutive edges.

◆ import_routes() [2/3]

RouteMap cda_rail::RouteMap::import_routes ( const std::filesystem::path & p,
const Network & network )
inlinestaticnodiscard

Loads routes from a directory into a new RouteMap.

Parameters
pDirectory containing routes.json.
networkNetwork used to validate the loaded routes.
Returns
RouteMap containing all routes loaded from the file.
See also
RouteMap(const std::filesystem::path&, const Network&)

◆ import_routes() [3/3]

RouteMap cda_rail::RouteMap::import_routes ( const std::string & path,
const Network & network )
inlinestaticnodiscard

Static factory: convenience overload accepting a std::string path.

Parameters
pathDirectory path as a string.
networkNetwork used to validate the loaded routes.
See also
RouteMap(const std::string&, const Network&)

◆ operator=() [1/2]

RouteMap & cda_rail::RouteMap::operator= ( const RouteMap & other)
default

◆ operator=() [2/2]

RouteMap & cda_rail::RouteMap::operator= ( RouteMap && other)
defaultnoexcept

Move-assigns another RouteMap to this one.

Parameters
otherThe RouteMap to move from.
Returns
Reference to this RouteMap.

◆ push_back_edge()

void cda_rail::RouteMap::push_back_edge ( const std::string & train_name,
Network::EdgeInput const & new_edge,
const Network & network )

Appends an edge at the end of the given train's route.

Parameters
train_nameName of the train whose route is extended.
new_edgeEdge to append.
networkNetwork used to resolve and validate new_edge.
Precondition
A route for train_name must exist in this map.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf no route for train_name has been registered or if new_edge is not a valid successor of the current last edge.
cda_rail::exceptions::EdgeNotExistentExceptionIf new_edge does not exist in network.

◆ push_front_edge()

void cda_rail::RouteMap::push_front_edge ( const std::string & train_name,
Network::EdgeInput const & new_edge,
const Network & network )

Prepends an edge at the beginning of the given train's route.

Parameters
train_nameName of the train whose route is extended.
new_edgeEdge to prepend.
networkNetwork used to resolve and validate new_edge.
Precondition
A route for train_name must exist in this map.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf no route for train_name has been registered or if new_edge is not a valid predecessor of the current first edge.
cda_rail::exceptions::EdgeNotExistentExceptionIf new_edge does not exist in network.

◆ remove_first_edge()

void cda_rail::RouteMap::remove_first_edge ( const std::string & train_name)

Removes the first edge from the given train's route.

Parameters
train_nameName of the train whose route is shortened.
Precondition
A non-empty route for train_name must exist in this map.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf no route for train_name has been registered or if the route is empty.

◆ remove_last_edge()

void cda_rail::RouteMap::remove_last_edge ( const std::string & train_name)

Removes the last edge from the given train's route.

Parameters
train_nameName of the train whose route is shortened.
Precondition
A non-empty route for train_name must exist in this map.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf no route for train_name has been registered or if the route is empty.

◆ remove_route()

void cda_rail::RouteMap::remove_route ( const std::string & train_name)

Removes the entire route for the given train from the map.

Parameters
train_nameName of the train whose route should be deleted.
Precondition
A route for train_name must exist in this map.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf no route for train_name has been registered.

◆ route_length()

double cda_rail::RouteMap::route_length ( const std::string & train_name,
const Network & network ) const
nodiscard

Returns the total length of the route assigned to the given train.

Parameters
train_nameName of the train.
networkNetwork used to read edge lengths.
Returns
Sum of all route edge lengths in metres.
Precondition
A route for train_name must exist in this map.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf no route for train_name has been registered.
cda_rail::exceptions::EdgeNotExistentExceptionIf the route references an edge that does not exist in network.

◆ size()

size_t cda_rail::RouteMap::size ( ) const
inlinenodiscard

Counts the number of stored train routes.

Returns
size_t The number of stored train routes.

◆ update_after_discretization()

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

Updates all routes after a network discretization step.

For each (old_edge, replacement_edges) pair in new_edges, every occurrence of old_edge in every stored route is replaced by the corresponding sequence of replacement edges, preserving travel order. Routes that do not contain any edge from new_edges are unchanged.

Parameters
new_edgesMapping from each replaced edge id to the ordered list of edges that take its place.

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