|
MTCT
Design Automation and Optimization for ETCS Railway Networks
|
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. | |
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.
|
default |
Creates an empty route map with no routes.
| 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.
| p | Path to the directory that contains routes.json. |
| network | Network used to resolve and validate each edge. |
| cda_rail::exceptions::ImportException | If p does not exist or is not a directory. |
| cda_rail::exceptions::EdgeNotExistentException | If the file references a vertex name that does not exist in network. |
| cda_rail::exceptions::ConsistencyException | If any loaded edge is not a valid successor of the previous edge on that route. |
|
inline |
Convenience overload accepting a std::string path.
| path | Path string pointing to the directory with routes.json. |
| network | Network used to validate the loaded routes. |
|
inline |
Convenience overload accepting a C-string path.
| path | Null-terminated path string. |
| network | Network used to validate the loaded routes. |
|
default |
|
defaultnoexcept |
|
default |
| 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.
| train_name | Name to associate the new route with. |
| cda_rail::exceptions::InvalidInputException | If a route for train_name is already registered. |
| 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.
| train_name | Name of the train. |
| trains | Train list that train_name must be part of. |
| cda_rail::exceptions::TrainNotExistentException | If train_name is not present in trains. |
| cda_rail::exceptions::InvalidInputException | If a route for train_name is already registered. |
|
inlinenodiscard |
Read-only iterator to the first route entry.
|
inlinenodiscard |
Returns a const iterator to the beginning of the routes.
|
inlinenodiscard |
Read-only iterator past the last route entry (explicit const).
|
nodiscard |
Checks whether all stored routes are valid with respect to the given train list and network.
A RouteMap is considered consistent when:
every_train_must_have_route is true) every train in trains has a registered route, and| trains | List of all known trains. |
| network | Network used for successor checks. |
| every_train_must_have_route | If true (the default), returns false whenever the number of stored routes differs from the number of trains in trains. |
|
inlinenodiscard |
Determines whether the map contains no routes.
|
inlinenodiscard |
Read-only iterator past the last route entry.
|
inline |
Exports routes to a directory specified by a C-string path.
| path | Null-terminated destination directory path. |
| network | Network used to look up vertex names. |
| 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.
| p | Destination directory for the output file. |
| network | Network used to look up vertex names for each edge. |
| cda_rail::exceptions::ExportException | If the directory cannot be created. |
|
inline |
Writes all routes to routes.json in the specified directory.
| path | Destination directory as a string. |
| network | Network used to look up vertex names. |
|
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.
| train1 | Name of the first train. |
| train2 | Name of the second train. |
| network | Network used for all sub-queries. |
| cda_rail::exceptions::ConsistencyException | If either train has no registered route. |
|
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.
| train1 | Name of the first train. |
| train2 | Name of the second train. |
| network | Network used to look up edge lengths and track ids. |
| cda_rail::exceptions::ConsistencyException | If either train has no registered route. |
|
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.
| train1 | Name of the first train. |
| train2 | Name of the second train. |
| network | Network used to find reverse edge pairs and read edge lengths. |
| cda_rail::exceptions::ConsistencyException | If either train has no registered route. |
|
nodiscard |
Returns the route assigned to the given train.
| train_name | Name of the train whose route is requested. |
train_name must exist in this map. | cda_rail::exceptions::ConsistencyException | If no route for train_name has been registered. |
|
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.
| train1 | Name of the first train. |
| train2 | Name of the second train. |
| network | Network used to identify unbreakable sections and edge lengths. |
| cda_rail::exceptions::ConsistencyException | If either train has no registered route. |
|
inlinenodiscard |
Checks whether a route for the given train is stored in this map.
| train_name | Name of the train to look up. |
train_name exists, otherwise false.
|
inlinestaticnodiscard |
Loads train routes from a file at the given directory path.
| path | Directory path containing routes.json. |
| network | Network used to validate referenced edges during loading. |
| ImportException | if the directory does not exist or is not a directory. |
| EdgeNotExistentException | if the routes file references an unknown vertex or edge. |
| ConsistencyException | if any route contains invalid successor relations between consecutive edges. |
|
inlinestaticnodiscard |
|
inlinestaticnodiscard |
Static factory: convenience overload accepting a std::string path.
| path | Directory path as a string. |
| network | Network used to validate the loaded routes. |
| 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.
| train_name | Name of the train whose route is extended. |
| new_edge | Edge to append. |
| network | Network used to resolve and validate new_edge. |
train_name must exist in this map. | cda_rail::exceptions::ConsistencyException | If 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::EdgeNotExistentException | If new_edge does not exist in network. |
| 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.
| train_name | Name of the train whose route is extended. |
| new_edge | Edge to prepend. |
| network | Network used to resolve and validate new_edge. |
train_name must exist in this map. | cda_rail::exceptions::ConsistencyException | If 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::EdgeNotExistentException | If new_edge does not exist in network. |
| void cda_rail::RouteMap::remove_first_edge | ( | const std::string & | train_name | ) |
Removes the first edge from the given train's route.
| train_name | Name of the train whose route is shortened. |
train_name must exist in this map. | cda_rail::exceptions::ConsistencyException | If no route for train_name has been registered or if the route is empty. |
| void cda_rail::RouteMap::remove_last_edge | ( | const std::string & | train_name | ) |
Removes the last edge from the given train's route.
| train_name | Name of the train whose route is shortened. |
train_name must exist in this map. | cda_rail::exceptions::ConsistencyException | If no route for train_name has been registered or if the route is empty. |
| void cda_rail::RouteMap::remove_route | ( | const std::string & | train_name | ) |
Removes the entire route for the given train from the map.
| train_name | Name of the train whose route should be deleted. |
train_name must exist in this map. | cda_rail::exceptions::ConsistencyException | If no route for train_name has been registered. |
|
nodiscard |
Returns the total length of the route assigned to the given train.
| train_name | Name of the train. |
| network | Network used to read edge lengths. |
train_name must exist in this map. | cda_rail::exceptions::ConsistencyException | If no route for train_name has been registered. |
| cda_rail::exceptions::EdgeNotExistentException | If the route references an edge that does not exist in network. |
|
inlinenodiscard |
Counts the number of stored train routes.
| 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.
| new_edges | Mapping from each replaced edge id to the ordered list of edges that take its place. |