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

Directed multigraph representing a railway network. More...

#include <RailwayNetwork.hpp>

Classes

struct  VertexInput
 Unified vertex descriptor accepted by all public API functions. More...
struct  EdgeInput
 Unified edge descriptor accepted by all public API functions. More...

Public Member Functions

 Network (std::string_view const networkName="UnnamedNetwork")
 Default-constructs an empty network.
 Network (std::string_view network_name, std::filesystem::path const &working_directory)
 Reads a network from disk and constructs the object.
 Network (std::string_view const networkName, std::string const &working_directory)
 Convenience overload accepting a std::string path.
 Network (std::string_view const networkName, char const *const workingDirectory)
 Convenience overload accepting a C-string path.
void export_network (std::filesystem::path const &working_directory) const
 Exports the network to disk.
void export_network (std::string const &working_directory) const
 Convenience overload of export_network accepting a std::string path.
void export_network (char const *const workingDirectory) const
 Convenience overload of export_network accepting a C-string path.
bool has_vertex (size_t index) const
 Checks whether a numeric vertex index is valid.
bool has_vertex (std::string_view const name) const
 Checks whether a vertex with the given name exists.
bool has_edge (size_t const index) const
 Checks whether a numeric edge index is valid.
bool has_edge (VertexInput const &source, VertexInput const &target) const
 Checks whether a directed edge between two vertices exists.
bool is_valid_successor (EdgeInput const &edge_in, EdgeInput const &edge_out) const
 Checks whether edge_out is a valid successor of edge_in.
bool is_adjustable (VertexInput const &vertex) const
 Checks whether a vertex is adjustable by certain algorithmic approaches.
bool is_consistent_for_transformation () const
 Checks network consistency required for edge-separation transformations.
bool has_reversal_free_successors () const
 Checks that no successor lets a train reverse its direction of travel.
size_t number_of_vertices () const
 Returns the total number of vertices in the network.
size_t number_of_edges () const
 Returns the total number of edges in the network.
std::string const & get_network_name () const
 Returns the network name.
std::vector< Vertex > const & get_vertices () const
 Returns a const reference to the underlying vertex container.
cda_rail::index_vector get_vertices_by_type (VertexType type) const
 Returns the indices of all vertices of the specified type, ordered by vertex index.
const std::vector< Edge > & get_edges () const
 Returns a const reference to the underlying edge container.
std::pair< size_t, double > get_old_edge (EdgeInput const &edge) const
 Returns the pre-discretization edge and position for an edge that may have been created by a transformation.
cda_rail::index_vector get_old_path (const cda_rail::index_vector &path) const
 Returns the path of the network before its transformations that corresponds to path.
void reset_old_edges ()
 Forgets from which edges earlier transformations derived the edges, so that get_old_edge and get_old_path refer to the network as it is now.
size_t get_vertex_index (std::string_view name) const
 Returns the index of the vertex with the given name.
size_t resolve_vertex_index (VertexInput const &vertex) const
 Resolves a vertex descriptor to its numeric vertex index.
const Vertex & get_vertex (VertexInput const &vertex) const
 Returns a const reference to the specified vertex.
size_t get_edge_index (VertexInput const &source, VertexInput const &target) const
 Returns the index of the directed edge from source to target.
size_t get_edge_index (EdgeInput const &edge_input) const
 Resolves an edge descriptor to its numeric edge index.
const Edge & get_edge (EdgeInput const &edge) const
 Returns a const reference to the specified edge.
std::string get_edge_name (EdgeInput const &edge) const
 Returns the canonical name of an edge formatted as "<source_name>-<target_name>".
cda_rail::index_set out_edges (VertexInput const &vertex) const
 Returns the set of edge indices of all edges leaving vertex.
cda_rail::index_set in_edges (VertexInput const &vertex) const
 Returns the set of edge indices of all edges entering vertex.
cda_rail::index_set neighboring_edges (VertexInput const &vertex) const
 Returns the set of edge indices of all edges incident to vertex (both in-edges and out-edges).
cda_rail::index_set get_predecessors (EdgeInput const &edge) const
 Returns all predecessor edges of edge.
cda_rail::index_set const & get_successors (EdgeInput const &edge) const
 Returns the set of valid successor edges for edge.
cda_rail::index_set edges_on_paths_between (VertexInput const &source, VertexInput const &target) const
 Returns all edges that lie on some path from source to target.
cda_rail::index_set neighbors (VertexInput const &vertex) const
 Returns the set of vertex indices adjacent to vertex via any incident edge.
std::optional< size_t > common_vertex (EdgeInput const &edge1, EdgeInput const &edge2) const
 Returns the common endpoint of two edges, if one exists.
std::optional< size_t > get_reverse_edge_index (EdgeInput const &edge) const
 Returns the index of the edge with reversed endpoints relative to edge.
std::optional< cda_rail::index_vector > get_reverse_path (cda_rail::index_vector const &edges) const
 Get reverse path.
std::optional< size_t > get_optional_reverse_edge_index (std::optional< size_t > const edgeIndex) const
 Wraps get_reverse_edge_index to propagate an optional input.
std::vector< std::pair< std::optional< size_t >, std::optional< size_t > > > combine_reverse_edges (const cda_rail::index_vector &edges_to_consider, bool sort=false) const
 Pairs each edge in edges_to_consider with its reverse edge, eliminating duplicate pairs.
size_t get_track_index (EdgeInput const &edge) const
 Returns the canonical track index for edge.
cda_rail::index_vector breakable_edges () const
 Returns the indices of all breakable edges, sorted by index.
cda_rail::index_vector relevant_breakable_edges () const
 Returns the indices of breakable edges, counting each bidirectional track only once.
std::vector< cda_rail::index_set > unbreakable_sections () const
 Returns all unbreakable sections of the network.
std::vector< cda_rail::index_set > no_border_vss_sections () const
 Returns all sections bounded by NoBorderVSS vertices.
cda_rail::index_set get_unbreakable_section_containing_edge (EdgeInput const &edge) const
 Returns the set of edge indices that form the unbreakable section containing edge.
bool is_on_same_unbreakable_section (EdgeInput const &edge1, EdgeInput const &edge2) const
 Checks whether two edges belong to the same unbreakable section.
cda_rail::index_set vertices_used_by_edges (const cda_rail::index_set &edges_tmp) const
 Returns all vertex indices that are endpoints of at least one edge in edges_tmp.
cda_rail::index_set edge_set_complement (const cda_rail::index_set &edge_indices) const
 Returns the set of all network edge indices not in edge_indices.
cda_rail::index_set edge_set_complement (const cda_rail::index_set &edge_indices, const cda_rail::index_set &edges_to_consider) const
 Returns edges_to_consider minus edge_indices.
double maximal_vertex_speed (VertexInput const &vertex, const cda_rail::index_set &edges_to_consider={}) const
 Returns the maximum speed achievable at vertex.
double minimal_neighboring_edge_length (VertexInput const &vertex, const cda_rail::index_set &edges_to_consider={}) const
 Returns the length of the shortest edge incident to vertex.
size_t max_vss_on_edge (EdgeInput const &edge) const
 Returns the maximum number of VSS borders that can be placed on edge.
size_t max_vss_on_edge (EdgeInput const &edge, const vss::SeparationFunction &sep_func) const
 Returns the maximum number of VSS borders that can be placed on edge if their positions are given by sep_func.
void set_network_name (std::string_view const networkName)
 Sets the network name.
void change_vertex_name (VertexInput const &vertex, std::string_view const newName)
 Renames a vertex.
void change_vertex_type (VertexInput const &vertex, VertexType const newType)
 Changes the type of a vertex.
void change_vertex_headway (VertexInput const &vertex, double const newHeadway)
 Updates the additional headway imposed on a vertex.
void change_edge_length (EdgeInput const &edge, double new_length)
 Changes the length of an edge.
void change_edge_max_speed (EdgeInput const &edge, double new_max_speed)
 Changes the maximum speed of an edge.
void change_edge_min_block_length (EdgeInput const &edge, double new_min_block_length)
 Changes the minimum block length of an edge.
void change_edge_min_stop_block_length (EdgeInput const &edge, double new_min_stop_block_length)
 Changes the minimum stop-block length of an edge.
void set_edge_breakable (EdgeInput const &edge)
 Marks an edge as breakable (VSS borders may be placed on it).
void set_edge_unbreakable (EdgeInput const &edge)
 Marks an edge as unbreakable (no VSS borders may be placed on it).
void change_edge_breakable_status (EdgeInput const &edge, bool const breakable)
 Sets the breakable flag of an edge.
size_t add_vertex (Vertex vertex)
 Adds a vertex to the network.
size_t add_vertex (std::string_view name, VertexType type, double headway=Vertex::HEADWAY_DEFAULT)
 Constructs a vertex and adds it to the network.
size_t add_vertex (std::string_view name, VertexType type, std::optional< double > const &headway)
 Constructs a vertex and adds it to the network.
size_t add_edge (VertexInput const &source, VertexInput const &target, double const length, double const maxSpeed, std::optional< bool > const &breakable={}, std::optional< double > const &min_block_length={}, std::optional< double > const &min_stop_block_length={})
 Adds a directed edge between two vertices.
std::pair< size_t, size_t > add_bidirectional_edge (VertexInput const &source, VertexInput const &target, double length, double max_speed, std::optional< bool > const &breakable={}, std::optional< double > const &min_block_length={}, std::optional< double > const &min_stop_block_length={})
 Adds a bidirectional edge between two vertices, i.e., it adds two edges, one in each direction.
void add_successor (EdgeInput const &edge_in, EdgeInput const &edge_out)
 Registers edge_out as a valid successor of edge_in.
void add_trivial_successors ()
 Lets trains pass straight through every vertex with exactly two neighbors.
void add_turnout_successors (VertexInput const &turnout, VertexInput const &toe, VertexInput const &branch_1, VertexInput const &branch_2)
 Registers the successors of a simple turnout.
void add_crossing_successors (VertexInput const &crossing, VertexInput const &track_1_a, VertexInput const &track_1_b, VertexInput const &track_2_a, VertexInput const &track_2_b)
 Registers the successors of a diamond crossing, where two tracks cross without being connected.
void add_double_slip_successors (VertexInput const &double_slip, VertexInput const &track_1_a, VertexInput const &track_1_b, VertexInput const &track_2_a, VertexInput const &track_2_b)
 Registers the successors of a double slip switch, i.e., a diamond crossing whose tracks are additionally connected on both sides.
std::pair< cda_rail::index_vector, cda_rail::index_vector > separate_edge (EdgeInput const &edge, const vss::SeparationFunction &sep_func=vss::UNIFORM)
 Separates a breakable edge (and its reverse, if present) into multiple sub-edges according to sep_func and the edge's min_block_length.
std::pair< cda_rail::index_vector, cda_rail::index_vector > separate_stop_edge (EdgeInput const &edge)
 Separates a breakable edge using min_stop_block_length with uniform separation.
std::vector< std::pair< size_t, cda_rail::index_vector > > separate_stop_edges (const cda_rail::index_set &stop_edges)
 Separates all edges in stop_edges whose length is at least twice their min_stop_block_length.
std::vector< std::pair< size_t, cda_rail::index_vector > > discretize (const vss::SeparationFunction &sep_func=vss::UNIFORM)
 Discretizes all relevant breakable edges, inserting new NoBorderVSS vertices so that VSS borders are only permitted at those vertex positions.
std::vector< std::pair< size_t, cda_rail::index_vector > > separate_edges_at_vss (const std::vector< std::vector< double > > &vss_positions)
 Splits the breakable edges at the given positions, which become VSS border vertices.
std::vector< cda_rail::index_vector > all_paths_of_length_starting_in_vertex (size_t v, double desired_len, std::optional< size_t > exit_node={}, const cda_rail::index_set &edges_to_consider={}, bool return_successors_if_zero=false) const
 Returns all edge paths of length at least desired_len starting at vertex v.
std::vector< cda_rail::index_vector > all_paths_of_length_starting_in_edge (size_t e, double desired_len, std::optional< size_t > exit_node={}, const cda_rail::index_set &edges_to_consider={}) const
 Returns all edge paths of length at least desired_len starting immediately after edge e (i.e., at the target of e).
std::vector< cda_rail::index_vector > all_paths_of_length_ending_in_vertex (size_t v, double desired_len, std::optional< size_t > exit_node={}, const cda_rail::index_set &edges_to_consider={}) const
 Returns all edge paths of length at least desired_len ending at vertex v (paths are listed from source side towards v).
std::vector< cda_rail::index_vector > all_paths_of_length_ending_in_edge (size_t const e, double const desiredLen, std::optional< size_t > exit_node={}, const cda_rail::index_set &edges_to_consider={}) const
 Returns all edge paths of length at least desiredLen ending at edge e.
std::vector< cda_rail::index_vector > all_paths_ending_at_ttd (EdgeInput const &edge, const std::vector< cda_rail::index_set > &ttd_sections, std::optional< size_t > exit_node={}, bool skip_irrelevant_ttds=false, bool zero_length_if_next_edge_is_ttd=false) const
 Returns all paths starting immediately after edge e_0 and ending upon entering a TTD section or reaching the exit vertex if specified.
double length_of_path (const cda_rail::index_vector &path) const
 Computes the total length of a path given as an ordered sequence of edge indices.
std::vector< std::vector< double > > all_edge_pairs_shortest_paths () const
 Computes the shortest-path distance matrix between all ordered edge pairs using the Floyd–Warshall algorithm.
std::optional< double > shortest_path_from_edge_to_edge (EdgeInput const &source_edge, EdgeInput const &target_edge, bool include_first_edge=false, bool use_minimal_time=false, double max_v=INF) const
 Returns the shortest distance from source_edge to target_edge.
std::optional< double > shortest_path_from_edge_to_vertex (EdgeInput const &source_edge, VertexInput const &target_vertex, bool include_first_edge=false, bool use_minimal_time=false, double max_v=INF) const
 Returns the shortest distance from source_edge to target_vertex.
std::vector< double > shortest_path_lengths_to_all_vertices (const cda_rail::index_set &source_edge_ids, bool include_first_edge=false, bool use_minimal_time=false, double max_v=INF) const
 Returns the shortest distance from any edge in source_edge_ids to every vertex of the network.
std::pair< std::optional< double >, cda_rail::index_vector > shortest_edge_to_edge_path (EdgeInput const &source_edge, EdgeInput const &target_edge, bool only_use_valid_successors=true, const cda_rail::index_set &edges_to_use={}, bool include_first_edge=false, bool use_minimal_time=false, double max_v=INF) const
 Returns the shortest path and its length from source_edge to target_edge.
std::pair< std::optional< double >, cda_rail::index_vector > shortest_edge_to_vertex_path (EdgeInput const &source_edge, VertexInput const &target_vertex, bool only_use_valid_successors=true, const cda_rail::index_set &edges_to_use={}, bool include_first_edge=false, bool use_minimal_time=false, double max_v=INF) const
 Returns the shortest path and its length from source_edge to target_vertex.
std::pair< std::optional< double >, cda_rail::index_vector > shortest_path_between_edge_sets (const cda_rail::index_set &source_edge_ids, const cda_rail::index_set &target_edge_ids, bool only_use_valid_successors=true, const cda_rail::index_set &edges_to_use={}, bool include_first_edge=false, bool use_minimal_time=false, double max_v=INF) const
 Returns the shortest path and distance from any edge in source_edge_ids to any edge in target_edge_ids.
std::pair< std::optional< double >, cda_rail::index_vector > shortest_path_between_edge_and_vertex_set (const cda_rail::index_set &source_edge_ids, const cda_rail::index_set &target_vertex_ids, bool only_use_valid_successors=true, const cda_rail::index_set &edges_to_use={}, bool include_first_edge=false, bool use_minimal_time=false, double max_v=INF) const
 Returns the shortest path and distance from any edge in source_edge_ids to any vertex in target_vertex_ids.
std::optional< double > shortest_path_length_between_edge_sets (const cda_rail::index_set &source_edge_ids, const cda_rail::index_set &target_ids, bool include_first_edge=false, bool use_minimal_time=false, double max_v=INF) const
 Returns the length of the shortest path from any edge in source_edge_ids to any edge in target_ids.
std::optional< double > shortest_path_length_between_edge_and_vertex_set (const cda_rail::index_set &source_edge_ids, const cda_rail::index_set &target_vertex_ids, bool include_first_edge=false, bool use_minimal_time=false, double max_v=INF) const
 Returns the length of the shortest path from any edge in source_edge_ids to any vertex in target_vertex_ids.
std::unordered_set< size_t > get_border_vertices_of_ttd (const cda_rail::index_set &ttd_section) const
 Returns the border vertices of a given TTD section.
bool has_ttd_path (VertexInput const &source_vertex, VertexInput const &target_vertex, const cda_rail::index_set &ttd_section) const
 Checks if a TTD can be traversed from a given source to target.
bool has_ttd_path_not_using_border_vertex (VertexInput const &border_vertex, const cda_rail::index_set &ttd_section) const
 Checks if a TTD can be traversed without using a given border vertex.
void throw_if_not_valid_successor (EdgeInput const &edge_in, EdgeInput const &edge_out) const
 Checks that edge_out may be used directly after edge_in.

Static Public Member Functions

static Network import_network (std::string_view const networkName, std::filesystem::path const &working_directory)
 Loads a network from disk and returns it by value.
static Network import_network (std::string_view const networkName, std::string const &working_directory)
 Convenience overload of import_network accepting a std::string path.
static Network import_network (std::string_view const networkName, char const *const workingDirectory)
 Convenience overload of import_network accepting a C-string path.
static std::vector< std::pair< size_t, size_t > > get_intersecting_ttd (const cda_rail::index_vector &edges, const std::vector< cda_rail::index_set > &ttd)
 For each TTD section that intersects edges, returns the TTD index together with the position of the first (entering) edge within edges.
static std::optional< size_t > get_ttd_of_edge (size_t e_0, const std::vector< cda_rail::index_set > &ttd_sections)
 Returns the index of the TTD section that contains a given edge.

Detailed Description

Directed multigraph representing a railway network.

Stores vertices, directed edges, and the edge-successor relation that encodes which continuations are physically possible at each junction. The class also provides import/export, graph queries, network transformations (edge discretization), and shortest-path algorithms.

Constructor & Destructor Documentation

◆ Network() [1/4]

cda_rail::Network::Network ( std::string_view const networkName = "UnnamedNetwork")
inlineexplicit

Default-constructs an empty network.

Parameters
networkNameName of the network, used for export folder naming; defaults to "UnnamedNetwork".
Exceptions
cda_rail::exceptions::InvalidInputExceptionIf networkName is not a valid folder name.

◆ Network() [2/4]

cda_rail::Network::Network ( std::string_view network_name,
std::filesystem::path const & working_directory )
explicit

Reads a network from disk and constructs the object.

The graph (tracks.graphml) and the successor map (successors_cpp.json) are read from working_directory/networks/networkName/.

Parameters
network_nameName of the network subfolder; defaults to "UnnamedNetwork".
working_directoryRoot working directory.
Exceptions
cda_rail::exceptions::ImportExceptionIf the expected directory does not exist or the files cannot be parsed.

◆ Network() [3/4]

cda_rail::Network::Network ( std::string_view const networkName,
std::string const & working_directory )
inlineexplicit

Convenience overload accepting a std::string path.

Parameters
networkNameName of the network subfolder.
working_directoryRoot working directory as a string.
Exceptions
cda_rail::exceptions::ImportExceptionIf the network cannot be loaded.

◆ Network() [4/4]

cda_rail::Network::Network ( std::string_view const networkName,
char const *const workingDirectory )
inlineexplicit

Convenience overload accepting a C-string path.

Parameters
networkNameName of the network subfolder.
workingDirectoryRoot working directory as a C-string.
Exceptions
cda_rail::exceptions::ImportExceptionIf the network cannot be loaded.

Member Function Documentation

◆ add_bidirectional_edge()

std::pair< size_t, size_t > cda_rail::Network::add_bidirectional_edge ( VertexInput const & source,
VertexInput const & target,
double length,
double max_speed,
std::optional< bool > const & breakable = {},
std::optional< double > const & min_block_length = {},
std::optional< double > const & min_stop_block_length = {} )

Adds a bidirectional edge between two vertices, i.e., it adds two edges, one in each direction.

Parameters
sourceSource vertex descriptor.
targetTarget vertex descriptor.
lengthEdge length in metres.
max_speedMaximum speed in m/s.
breakableWhether VSS borders may be placed on this edge; std::nullopt uses Edge::BREAKABLE_DEFAULT.
min_block_lengthMinimum block length in metres; std::nullopt uses Edge::MIN_BLOCK_LENGTH_DEFAULT.
min_stop_block_lengthMinimum stop-block length in metres; std::nullopt uses Edge::MIN_STOP_BLOCK_LENGTH_DEFAULT.
Returns
A pair of indices of the newly added edges, with the first being the forward edge and the second being the reverse edge.
Exceptions
cda_rail::exceptions::InvalidInputExceptionIf source equals target or the edge already exists.
cda_rail::exceptions::VertexNotExistentExceptionIf either vertex does not exist.

◆ add_crossing_successors()

void cda_rail::Network::add_crossing_successors ( VertexInput const & crossing,
VertexInput const & track_1_a,
VertexInput const & track_1_b,
VertexInput const & track_2_a,
VertexInput const & track_2_b )

Registers the successors of a diamond crossing, where two tracks cross without being connected.

Trains pass straight through crossing on the first track, i.e., between track_1_a and track_1_b, and on the second track, i.e., between track_2_a and track_2_b. Each successor is only registered if both of its edges exist.

Parameters
crossingVertex descriptor of the crossing.
track_1_aNeighbor of crossing on one side of the first track.
track_1_bNeighbor of crossing on the other side of the first track.
track_2_aNeighbor of crossing on one side of the second track.
track_2_bNeighbor of crossing on the other side of the second track.
Exceptions
cda_rail::exceptions::InvalidInputExceptionIf the four tracks are not exactly the neighbors of crossing.

◆ add_double_slip_successors()

void cda_rail::Network::add_double_slip_successors ( VertexInput const & double_slip,
VertexInput const & track_1_a,
VertexInput const & track_1_b,
VertexInput const & track_2_a,
VertexInput const & track_2_b )

Registers the successors of a double slip switch, i.e., a diamond crossing whose tracks are additionally connected on both sides.

track_1_a and track_2_a lie on the same side of double_slip, and track_1_b and track_2_b on the other. Trains coming from either vertex of one side may continue to either vertex of the other side. Each successor is only registered if both of its edges exist.

Parameters
double_slipVertex descriptor of the double slip switch.
track_1_aNeighbor of double_slip on one side of the first track.
track_1_bNeighbor of double_slip on the other side of the first track.
track_2_aNeighbor of double_slip on one side of the second track, the same side as track_1_a.
track_2_bNeighbor of double_slip on the other side of the second track, the same side as track_1_b.
Exceptions
cda_rail::exceptions::InvalidInputExceptionIf the four tracks are not exactly the neighbors of double_slip.

◆ add_edge()

size_t cda_rail::Network::add_edge ( VertexInput const & source,
VertexInput const & target,
double const length,
double const maxSpeed,
std::optional< bool > const & breakable = {},
std::optional< double > const & min_block_length = {},
std::optional< double > const & min_stop_block_length = {} )
inline

Adds a directed edge between two vertices.

Parameters
sourceSource vertex descriptor.
targetTarget vertex descriptor.
lengthEdge length in metres.
maxSpeedMaximum speed in m/s.
breakableWhether VSS borders may be placed on this edge; std::nullopt uses Edge::BREAKABLE_DEFAULT.
min_block_lengthMinimum block length in metres; std::nullopt uses Edge::MIN_BLOCK_LENGTH_DEFAULT.
min_stop_block_lengthMinimum stop-block length in metres; std::nullopt uses Edge::MIN_STOP_BLOCK_LENGTH_DEFAULT.
Returns
Index of the newly added edge.
Exceptions
cda_rail::exceptions::InvalidInputExceptionIf source equals target or the edge already exists.
cda_rail::exceptions::VertexNotExistentExceptionIf either vertex does not exist.

◆ add_successor()

void cda_rail::Network::add_successor ( EdgeInput const & edge_in,
EdgeInput const & edge_out )
inline

Registers edge_out as a valid successor of edge_in.

The edges must be adjacent (target of edge_in == source of edge_out). If the relation already exists the call is a no-op.

Parameters
edge_inPredecessor edge descriptor.
edge_outSuccessor edge descriptor to register.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf either edge does not exist.
cda_rail::exceptions::ConsistencyExceptionIf the edges are not adjacent.

◆ add_trivial_successors()

void cda_rail::Network::add_trivial_successors ( )

Lets trains pass straight through every vertex with exactly two neighbors.

For a vertex v with neighbors u and w, (u, v) -> (v, w) and (w, v) -> (v, u) are registered, each only if both of its edges exist. An edge never becomes a successor of its reverse edge.

◆ add_turnout_successors()

void cda_rail::Network::add_turnout_successors ( VertexInput const & turnout,
VertexInput const & toe,
VertexInput const & branch_1,
VertexInput const & branch_2 )

Registers the successors of a simple turnout.

Trains coming from toe may continue to either branch, and trains coming from either branch continue to toe. A train can never move from one branch to the other. Each successor is only registered if both of its edges exist.

Parameters
turnoutVertex descriptor of the turnout.
toeNeighbor of turnout from which both branches can be reached.
branch_1Neighbor of turnout on the first branch.
branch_2Neighbor of turnout on the second branch.
Exceptions
cda_rail::exceptions::InvalidInputExceptionIf toe, branch_1 and branch_2 are not exactly the neighbors of turnout.

◆ add_vertex() [1/3]

size_t cda_rail::Network::add_vertex ( std::string_view name,
VertexType type,
double headway = Vertex::HEADWAY_DEFAULT )
inline

Constructs a vertex and adds it to the network.

Parameters
nameName of the vertex.
typeType of the vertex.
headwayAdditional minimal headway at the vertex in s.
Returns
Index of the newly added vertex.
Exceptions
cda_rail::exceptions::InvalidInputExceptionIf a vertex with the same name already exists.

◆ add_vertex() [2/3]

size_t cda_rail::Network::add_vertex ( std::string_view name,
VertexType type,
std::optional< double > const & headway )
inline

Constructs a vertex and adds it to the network.

Parameters
nameName of the vertex.
typeType of the vertex.
headwayAdditional minimal headway at the vertex in s; std::nullopt uses Vertex::HEADWAY_DEFAULT.
Returns
Index of the newly added vertex.
Exceptions
cda_rail::exceptions::InvalidInputExceptionIf a vertex with the same name already exists.

◆ add_vertex() [3/3]

size_t cda_rail::Network::add_vertex ( Vertex vertex)

Adds a vertex to the network.

Parameters
vertexVertex object to add.
Returns
Index of the newly added vertex.
Exceptions
cda_rail::exceptions::InvalidInputExceptionIf a vertex with the same name already exists.

◆ all_edge_pairs_shortest_paths()

std::vector< std::vector< double > > cda_rail::Network::all_edge_pairs_shortest_paths ( ) const
nodiscard

Computes the shortest-path distance matrix between all ordered edge pairs using the Floyd–Warshall algorithm.

Entry [u][v] stores the shortest distance from the target of edge u to the target of edge v using only valid successors. Entries where no path exists are set to INF.

Returns
n x n distance matrix, where n is the number of edges.

◆ all_paths_ending_at_ttd()

std::vector< cda_rail::index_vector > cda_rail::Network::all_paths_ending_at_ttd ( EdgeInput const & edge,
const std::vector< cda_rail::index_set > & ttd_sections,
std::optional< size_t > exit_node = {},
bool skip_irrelevant_ttds = false,
bool zero_length_if_next_edge_is_ttd = false ) const
inlinenodiscard

Returns all paths starting immediately after edge e_0 and ending upon entering a TTD section or reaching the exit vertex if specified.

Parameters
edgeStarting edge (paths begin with a valid successor of this edge).
ttd_sectionsVector of TTD sections (each a set of edge indices).
exit_nodeOptional vertex at which paths may terminate.
skip_irrelevant_ttdsIf true, TTD sections are traversed if there if every path through TTD contains the entry node as entry or exit. In this case it is not possible for another train to traverse the TTD while a train waits at the specified entry node. Hence, the train can safely traverse through the TTD since it will never have to wait.
zero_length_if_next_edge_is_ttdIf true, a path of length zero is returned if the first edge after e_0 is already part of a (new) TTD section. This reflects that a train could also wait before entering a TTD. If false, the train is forced to move at least one edge.
Returns
Vector of edge-index vectors, each representing one such path.

◆ all_paths_of_length_ending_in_edge()

std::vector< cda_rail::index_vector > cda_rail::Network::all_paths_of_length_ending_in_edge ( size_t const e,
double const desiredLen,
std::optional< size_t > exit_node = {},
const cda_rail::index_set & edges_to_consider = {} ) const
inlinenodiscard

Returns all edge paths of length at least desiredLen ending at edge e.

Parameters
eTerminal edge index.
desiredLenMinimum path length in metres.
exit_nodeOptional additional vertex constraint.
edges_to_considerIf non-empty, only these edges are used.
Returns
Vector of edge-index vectors, each representing one path.

◆ all_paths_of_length_ending_in_vertex()

std::vector< cda_rail::index_vector > cda_rail::Network::all_paths_of_length_ending_in_vertex ( size_t v,
double desired_len,
std::optional< size_t > exit_node = {},
const cda_rail::index_set & edges_to_consider = {} ) const
inlinenodiscard

Returns all edge paths of length at least desired_len ending at vertex v (paths are listed from source side towards v).

Parameters
vTerminal vertex index.
desired_lenMinimum path length in metres.
exit_nodeOptional additional vertex constraint.
edges_to_considerIf non-empty, only these edges are used.
Returns
Vector of edge-index vectors, each representing one path.

◆ all_paths_of_length_starting_in_edge()

std::vector< cda_rail::index_vector > cda_rail::Network::all_paths_of_length_starting_in_edge ( size_t e,
double desired_len,
std::optional< size_t > exit_node = {},
const cda_rail::index_set & edges_to_consider = {} ) const
inlinenodiscard

Returns all edge paths of length at least desired_len starting immediately after edge e (i.e., at the target of e).

Parameters
eStarting edge index.
desired_lenMinimum path length in metres.
exit_nodeOptional vertex at which a path may terminate early.
edges_to_considerIf non-empty, only these edges are used.
Returns
Vector of edge-index vectors, each representing one path.

◆ all_paths_of_length_starting_in_vertex()

std::vector< cda_rail::index_vector > cda_rail::Network::all_paths_of_length_starting_in_vertex ( size_t v,
double desired_len,
std::optional< size_t > exit_node = {},
const cda_rail::index_set & edges_to_consider = {},
bool return_successors_if_zero = false ) const
inlinenodiscard

Returns all edge paths of length at least desired_len starting at vertex v.

A path is included if its total length is at least desired_len, but removing the last edge would make it too short.

Parameters
vStarting vertex index.
desired_lenMinimum path length in metres.
exit_nodeIf set, a path may terminate at this vertex even before reaching desired_len.
edges_to_considerIf non-empty, only these edges are used.
return_successors_if_zeroIf true and desired_len is 0, single-edge paths for each outgoing edge are returned.
Returns
Vector of edge-index vectors, each representing one path.

◆ breakable_edges()

cda_rail::index_vector cda_rail::Network::breakable_edges ( ) const
nodiscard

Returns the indices of all breakable edges, sorted by index.

Returns
Vector of breakable edge indices in ascending order.

◆ change_edge_breakable_status()

void cda_rail::Network::change_edge_breakable_status ( EdgeInput const & edge,
bool const breakable )
inline

Sets the breakable flag of an edge.

Parameters
edgeEdge descriptor.
breakableNew breakable status.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ change_edge_length()

void cda_rail::Network::change_edge_length ( EdgeInput const & edge,
double new_length )
inline

Changes the length of an edge.

Parameters
edgeEdge descriptor.
new_lengthNew length in metres.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ change_edge_max_speed()

void cda_rail::Network::change_edge_max_speed ( EdgeInput const & edge,
double new_max_speed )
inline

Changes the maximum speed of an edge.

Parameters
edgeEdge descriptor.
new_max_speedNew maximum speed in m/s.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ change_edge_min_block_length()

void cda_rail::Network::change_edge_min_block_length ( EdgeInput const & edge,
double new_min_block_length )
inline

Changes the minimum block length of an edge.

Parameters
edgeEdge descriptor.
new_min_block_lengthNew minimum block length in metres.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ change_edge_min_stop_block_length()

void cda_rail::Network::change_edge_min_stop_block_length ( EdgeInput const & edge,
double new_min_stop_block_length )
inline

Changes the minimum stop-block length of an edge.

Parameters
edgeEdge descriptor.
new_min_stop_block_lengthNew minimum stop-block length in metres.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ change_vertex_headway()

void cda_rail::Network::change_vertex_headway ( VertexInput const & vertex,
double const newHeadway )
inline

Updates the additional headway imposed on a vertex.

Parameters
vertexVertex descriptor.
newHeadwayNew headway value in seconds.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf the vertex does not exist.

◆ change_vertex_name()

void cda_rail::Network::change_vertex_name ( VertexInput const & vertex,
std::string_view const newName )
inline

Renames a vertex.

Parameters
vertexVertex descriptor.
newNameNew name for the vertex.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf the vertex does not exist.
cda_rail::exceptions::InvalidInputExceptionIf a vertex with newName already exists.

◆ change_vertex_type()

void cda_rail::Network::change_vertex_type ( VertexInput const & vertex,
VertexType const newType )
inline

Changes the type of a vertex.

Parameters
vertexVertex descriptor.
newTypeNew vertex type.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf the vertex does not exist.

◆ combine_reverse_edges()

std::vector< std::pair< std::optional< size_t >, std::optional< size_t > > > cda_rail::Network::combine_reverse_edges ( const cda_rail::index_vector & edges_to_consider,
bool sort = false ) const
nodiscard

Pairs each edge in edges_to_consider with its reverse edge, eliminating duplicate pairs.

Each bidirectional track produces exactly one pair (e, rev_e) where the smaller index comes first. Edges without a reverse in edges_to_consider are paired with std::nullopt as the second element.

If the output is sorted, it is ensured that the first element edges are successors of each other, hence, the inner-pair order might be off. In this case it is also required that edges_to_consider includes every possible reverse edge if existent.

Parameters
edges_to_considerOrdered vector of edge indices to process. All indices must refer to existing edges.
sortIf true, the returned pairs are reordered so that consecutive pairs share a vertex (valid only when edges_to_consider forms a simple path).
Returns
Vector of {forward_edge, optional_reverse_edge} pairs.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf any edge in edges_to_consider does not exist.

◆ common_vertex()

std::optional< size_t > cda_rail::Network::common_vertex ( EdgeInput const & edge1,
EdgeInput const & edge2 ) const
inlinenodiscard

Returns the common endpoint of two edges, if one exists.

Parameters
edge1First edge descriptor.
edge2Second edge descriptor.
Returns
Index of the shared vertex, or std::nullopt if the edges share no endpoint.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf the edges share more than one vertex.

◆ discretize()

std::vector< std::pair< size_t, cda_rail::index_vector > > cda_rail::Network::discretize ( const vss::SeparationFunction & sep_func = vss::UNIFORM)

Discretizes all relevant breakable edges, inserting new NoBorderVSS vertices so that VSS borders are only permitted at those vertex positions.

Parameters
sep_funcSeparation function that controls the placement of the new vertices; defaults to uniform separation.
Returns
Vector of pairs {original_edge_index, new_edge_indices} for every separated direction.

◆ edge_set_complement() [1/2]

cda_rail::index_set cda_rail::Network::edge_set_complement ( const cda_rail::index_set & edge_indices) const
nodiscard

Returns the set of all network edge indices not in edge_indices.

Parameters
edge_indicesSet of edge indices to exclude.
Returns
Complement set with respect to all edges in the network.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf any index in edge_indices is invalid.

◆ edge_set_complement() [2/2]

cda_rail::index_set cda_rail::Network::edge_set_complement ( const cda_rail::index_set & edge_indices,
const cda_rail::index_set & edges_to_consider ) const
nodiscard

Returns edges_to_consider minus edge_indices.

Parameters
edge_indicesSet of edge indices to exclude.
edges_to_considerSet of edge indices to restrict to.
Returns
Set edges_to_consider \ edge_indices.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf any index in either argument set is invalid.

◆ edges_on_paths_between()

cda_rail::index_set cda_rail::Network::edges_on_paths_between ( VertexInput const & source,
VertexInput const & target ) const
inlinenodiscard

Returns all edges that lie on some path from source to target.

A path starts with an edge leaving source, ends with an edge entering target, and only follows valid successors. A train entering the network at source and leaving it at target can use no other edge.

Parameters
sourceVertex descriptor of the first vertex.
targetVertex descriptor of the last vertex.
Returns
Set of edge indices.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf a vertex does not exist.

◆ export_network() [1/3]

void cda_rail::Network::export_network ( char const *const workingDirectory) const
inline

Convenience overload of export_network accepting a C-string path.

Parameters
workingDirectoryRoot working directory as a C-string.
Exceptions
cda_rail::exceptions::ExportExceptionIf the output directory cannot be created.

◆ export_network() [2/3]

void cda_rail::Network::export_network ( std::filesystem::path const & working_directory) const

Exports the network to disk.

Writes tracks.graphml and successors_cpp.json to working_directory/networks/<networkName>/.

Parameters
working_directoryRoot working directory.
Exceptions
cda_rail::exceptions::ExportExceptionIf the output directory cannot be created.

◆ export_network() [3/3]

void cda_rail::Network::export_network ( std::string const & working_directory) const
inline

Convenience overload of export_network accepting a std::string path.

Parameters
working_directoryRoot working directory as a string.
Exceptions
cda_rail::exceptions::ExportExceptionIf the output directory cannot be created.

◆ get_border_vertices_of_ttd()

std::unordered_set< size_t > cda_rail::Network::get_border_vertices_of_ttd ( const cda_rail::index_set & ttd_section) const
nodiscard

Returns the border vertices of a given TTD section.

A border vertex is a vertex with only one neighbor within the TTD.

Parameters
ttd_sectionEdges within the TTD section
Returns
All border vertices

◆ get_edge()

const Edge & cda_rail::Network::get_edge ( EdgeInput const & edge) const
inlinenodiscard

Returns a const reference to the specified edge.

Parameters
edgeEdge descriptor (index, vertex-pair, or Edge object).
Returns
Const reference to the Edge.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ get_edge_index() [1/2]

size_t cda_rail::Network::get_edge_index ( EdgeInput const & edge_input) const
inlinenodiscard

Resolves an edge descriptor to its numeric edge index.

Parameters
edge_inputEdge descriptor.
Returns
Numeric edge index.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.
cda_rail::exceptions::ConsistencyExceptionIf an Edge object conflicts with the stored edge data.

◆ get_edge_index() [2/2]

size_t cda_rail::Network::get_edge_index ( VertexInput const & source,
VertexInput const & target ) const
inlinenodiscard

Returns the index of the directed edge from source to target.

Parameters
sourceSource vertex descriptor.
targetTarget vertex descriptor.
Returns
Numeric edge index.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf either vertex does not exist.
cda_rail::exceptions::EdgeNotExistentExceptionIf no such directed edge exists.

◆ get_edge_name()

std::string cda_rail::Network::get_edge_name ( EdgeInput const & edge) const
inlinenodiscard

Returns the canonical name of an edge formatted as "<source_name>-<target_name>".

Parameters
edgeEdge descriptor.
Returns
Edge name string.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ get_edges()

const std::vector< Edge > & cda_rail::Network::get_edges ( ) const
inlinenodiscard

Returns a const reference to the underlying edge container.

Returns
Const reference to the vector of all Edge objects, indexed by edge index.

◆ get_intersecting_ttd()

std::vector< std::pair< size_t, size_t > > cda_rail::Network::get_intersecting_ttd ( const cda_rail::index_vector & edges,
const std::vector< cda_rail::index_set > & ttd )
staticnodiscard

For each TTD section that intersects edges, returns the TTD index together with the position of the first (entering) edge within edges.

Parameters
edgesOrdered vector of edge indices representing a path.
ttdVector of TTD sections (each a set of edge indices).
Returns
Vector of pairs {ttd_index, position_of_first_intersecting_edge} where the position is an index into edges.

◆ get_network_name()

std::string const & cda_rail::Network::get_network_name ( ) const
inlinenodiscard

Returns the network name.

Returns
Const reference to the network name string; guaranteed to be a valid directory name on all operating systems.

◆ get_old_edge()

std::pair< size_t, double > cda_rail::Network::get_old_edge ( EdgeInput const & edge) const
inlinenodiscard

Returns the pre-discretization edge and position for an edge that may have been created by a transformation.

If edge has not been produced by any transformation, returns {edge_index, 0.0}.

Parameters
edgeEdge descriptor.
Returns
Pair {original_edge_index, offset_from_source_in_metres}.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ get_old_path()

cda_rail::index_vector cda_rail::Network::get_old_path ( const cda_rail::index_vector & path) const
nodiscard

Returns the path of the network before its transformations that corresponds to path.

Consecutive edges into which one edge was separated, see get_old_edge, are replaced by that edge, so that a route of the transformed network becomes the same route of the original network.

Parameters
pathEdge indices of a path of this network.
Returns
Edge indices of the original network.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf an edge does not exist.

◆ get_optional_reverse_edge_index()

std::optional< size_t > cda_rail::Network::get_optional_reverse_edge_index ( std::optional< size_t > const edgeIndex) const
inlinenodiscard

Wraps get_reverse_edge_index to propagate an optional input.

If edgeIndex has no value, std::nullopt is returned immediately without any look-up.

Parameters
edgeIndexOptional numeric edge index to query.
Returns
Index of the reverse edge, or std::nullopt.

◆ get_predecessors()

cda_rail::index_set cda_rail::Network::get_predecessors ( EdgeInput const & edge) const
inlinenodiscard

Returns all predecessor edges of edge.

An edge e' is a predecessor of edge if edge is a valid successor of e'.

Parameters
edgeEdge descriptor.
Returns
Set of predecessor edge indices.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ get_reverse_edge_index()

std::optional< size_t > cda_rail::Network::get_reverse_edge_index ( EdgeInput const & edge) const
inlinenodiscard

Returns the index of the edge with reversed endpoints relative to edge.

Parameters
edgeEdge descriptor.
Returns
Index of the reverse edge, or std::nullopt if no such edge exists.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf edge does not exist.

◆ get_reverse_path()

std::optional< cda_rail::index_vector > cda_rail::Network::get_reverse_path ( cda_rail::index_vector const & edges) const
nodiscard

Get reverse path.

Parameters
edgesVector of edge indices.
Returns
Vector of reverse indices in revers order, if all reverse edges exist.

◆ get_successors()

cda_rail::index_set const & cda_rail::Network::get_successors ( EdgeInput const & edge) const
inlinenodiscard

Returns the set of valid successor edges for edge.

Parameters
edgeEdge descriptor.
Returns
Const reference to the set of successor edge indices.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ get_track_index()

size_t cda_rail::Network::get_track_index ( EdgeInput const & edge) const
inlinenodiscard

Returns the canonical track index for edge.

For a bidirectional track the canonical index is the smaller of the two directed edge indices.

Parameters
edgeEdge descriptor.
Returns
Canonical track index.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ get_ttd_of_edge()

std::optional< size_t > cda_rail::Network::get_ttd_of_edge ( size_t e_0,
const std::vector< cda_rail::index_set > & ttd_sections )
staticnodiscard

Returns the index of the TTD section that contains a given edge.

Parameters
e_0Edge index to look up.
ttd_sectionsCollection of TTD sections.
Returns
Index of the containing TTD section, or std::nullopt if none contains e_0.

◆ get_unbreakable_section_containing_edge()

cda_rail::index_set cda_rail::Network::get_unbreakable_section_containing_edge ( EdgeInput const & edge) const
inlinenodiscard

Returns the set of edge indices that form the unbreakable section containing edge.

If edge is breakable the returned set is empty.

Parameters
edgeEdge descriptor.
Returns
Set of edge indices in the same unbreakable section as edge.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ get_vertex()

const Vertex & cda_rail::Network::get_vertex ( VertexInput const & vertex) const
inlinenodiscard

Returns a const reference to the specified vertex.

Parameters
vertexVertex descriptor (index, name, or Vertex object).
Returns
Const reference to the Vertex.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf the vertex does not exist.

◆ get_vertex_index()

size_t cda_rail::Network::get_vertex_index ( std::string_view name) const
nodiscard

Returns the index of the vertex with the given name.

Parameters
nameVertex name.
Returns
Numeric vertex index.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf no vertex with name exists.

◆ get_vertices()

std::vector< Vertex > const & cda_rail::Network::get_vertices ( ) const
inlinenodiscard

Returns a const reference to the underlying vertex container.

Returns
Const reference to the vector of all Vertex objects, indexed by vertex index.

◆ get_vertices_by_type()

cda_rail::index_vector cda_rail::Network::get_vertices_by_type ( VertexType type) const
nodiscard

Returns the indices of all vertices of the specified type, ordered by vertex index.

Parameters
typeVertex type to filter by.
Returns
Vector of vertex indices whose type equals type.

◆ has_edge() [1/2]

bool cda_rail::Network::has_edge ( size_t const index) const
inlinenodiscard

Checks whether a numeric edge index is valid.

Parameters
indexCandidate edge index.
Returns
true if index refers to an existing edge.

◆ has_edge() [2/2]

bool cda_rail::Network::has_edge ( VertexInput const & source,
VertexInput const & target ) const
inlinenodiscard

Checks whether a directed edge between two vertices exists.

Parameters
sourceSource vertex descriptor.
targetTarget vertex descriptor.
Returns
true if such a directed edge exists.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf either vertex does not exist.

◆ has_reversal_free_successors()

bool cda_rail::Network::has_reversal_free_successors ( ) const
nodiscard

Checks that no successor lets a train reverse its direction of travel.

A train passing a vertex comes from one side of it and leaves to the other, e.g., from the toe of a switch to one of its two branches or back. Hence, the neighbors of every vertex must split into two sides such that every successor pair connects a neighbor on one side with a neighbor on the other. A successor turning back onto the reverse edge (U-turn) violates this, and so does one from one branch of a switch to the other (zig-zag) if the switch can also be passed from its toe.

Returns
true if the successors of every vertex admit such a split.

◆ has_ttd_path()

bool cda_rail::Network::has_ttd_path ( VertexInput const & source_vertex,
VertexInput const & target_vertex,
const cda_rail::index_set & ttd_section ) const
inlinenodiscard

Checks if a TTD can be traversed from a given source to target.

Parameters
source_vertexSource vertex
target_vertexDestination/Target vertex
ttd_sectionEdges within the TTD section
Returns
True if there is a path from source to target only using edges within the TTD section

◆ has_ttd_path_not_using_border_vertex()

bool cda_rail::Network::has_ttd_path_not_using_border_vertex ( VertexInput const & border_vertex,
const cda_rail::index_set & ttd_section ) const
inlinenodiscard

Checks if a TTD can be traversed without using a given border vertex.

Parameters
border_vertexBorder vertex of the TTD section
ttd_sectionEdges within the TTD section
Returns
True if there is another path through the TTD that does neither begin nor end at the specified border vertex.

◆ has_vertex() [1/2]

bool cda_rail::Network::has_vertex ( size_t index) const
inlinenodiscard

Checks whether a numeric vertex index is valid.

Parameters
indexCandidate vertex index.
Returns
true if index refers to an existing vertex.

◆ has_vertex() [2/2]

bool cda_rail::Network::has_vertex ( std::string_view const name) const
inlinenodiscard

Checks whether a vertex with the given name exists.

Parameters
nameVertex name to look up.
Returns
true if such a vertex exists in the network.

◆ import_network() [1/3]

Network cda_rail::Network::import_network ( std::string_view const networkName,
char const *const workingDirectory )
inlinestaticnodiscard

Convenience overload of import_network accepting a C-string path.

Parameters
networkNameName of the network subfolder.
workingDirectoryRoot working directory as a C-string.
Returns
Newly constructed Network object.
Exceptions
cda_rail::exceptions::ImportExceptionIf the network cannot be loaded.

◆ import_network() [2/3]

Network cda_rail::Network::import_network ( std::string_view const networkName,
std::filesystem::path const & working_directory )
inlinestaticnodiscard

Loads a network from disk and returns it by value.

Parameters
networkNameName of the network subfolder; defaults to "UnnamedNetwork".
working_directoryRoot working directory.
Returns
Newly constructed Network object.
Exceptions
cda_rail::exceptions::ImportExceptionIf the network cannot be loaded.

◆ import_network() [3/3]

Network cda_rail::Network::import_network ( std::string_view const networkName,
std::string const & working_directory )
inlinestaticnodiscard

Convenience overload of import_network accepting a std::string path.

Parameters
networkNameName of the network subfolder.
working_directoryRoot working directory as a string.
Returns
Newly constructed Network object.
Exceptions
cda_rail::exceptions::ImportExceptionIf the network cannot be loaded.

◆ in_edges()

cda_rail::index_set cda_rail::Network::in_edges ( VertexInput const & vertex) const
inlinenodiscard

Returns the set of edge indices of all edges entering vertex.

Parameters
vertexVertex descriptor.
Returns
Set of incoming edge indices.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf the vertex does not exist.

◆ is_adjustable()

bool cda_rail::Network::is_adjustable ( VertexInput const & vertex) const
inlinenodiscard

Checks whether a vertex is adjustable by certain algorithmic approaches.

A vertex is adjustable if and only if it is of type NoBorder and has exactly two neighboring vertices.

Parameters
vertexVertex descriptor.
Returns
true if the vertex satisfies the adjustability criterion.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf the vertex does not exist.

◆ is_consistent_for_transformation()

bool cda_rail::Network::is_consistent_for_transformation ( ) const
nodiscard

Checks network consistency required for edge-separation transformations.

The following conditions must all hold:

  • Every breakable edge has a strictly positive min_block_length.
  • No breakable edge is incident to a NoBorder vertex.
  • For every bidirectional edge pair, both directions share the same breakable flag and length.
  • Every NoBorderVSS vertex has at most two neighbors, none of type NoBorder.
Returns
true if all consistency conditions are satisfied.

◆ is_on_same_unbreakable_section()

bool cda_rail::Network::is_on_same_unbreakable_section ( EdgeInput const & edge1,
EdgeInput const & edge2 ) const
inlinenodiscard

Checks whether two edges belong to the same unbreakable section.

Parameters
edge1First edge descriptor.
edge2Second edge descriptor.
Returns
true if both edges lie in the same unbreakable section.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf either edge does not exist.

◆ is_valid_successor()

bool cda_rail::Network::is_valid_successor ( EdgeInput const & edge_in,
EdgeInput const & edge_out ) const
inlinenodiscard

Checks whether edge_out is a valid successor of edge_in.

A valid successor must satisfy two conditions:

  • The source of edge_out equals the target of edge_in (adjacency).
  • The pair is registered in the successor map (e.g. physically possible at a junction).
Parameters
edge_inPredecessor edge.
edge_outCandidate successor edge.
Returns
true if edge_out is a valid successor of edge_in.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf either edge does not exist.

◆ length_of_path()

double cda_rail::Network::length_of_path ( const cda_rail::index_vector & path) const
nodiscard

Computes the total length of a path given as an ordered sequence of edge indices.

Parameters
pathOrdered vector of edge indices forming the path.
Returns
Sum of the lengths of all edges in path, in metres.

◆ max_vss_on_edge() [1/2]

size_t cda_rail::Network::max_vss_on_edge ( EdgeInput const & edge) const
inlinenodiscard

Returns the maximum number of VSS borders that can be placed on edge.

Every block has at least the edge's min_block_length, including the blocks towards both ends of the edge, since these end at a border as well. Uniformly separated blocks allow the most borders, hence the value equals floor(length / min_block_length) - 1. Returns 0 for non-breakable edges, when min_block_length is zero, and when the edge is too short for two blocks, in particular when min_block_length exceeds its length.

Parameters
edgeEdge descriptor.
Returns
Maximum number of VSS borders.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ max_vss_on_edge() [2/2]

size_t cda_rail::Network::max_vss_on_edge ( EdgeInput const & edge,
const vss::SeparationFunction & sep_func ) const
inlinenodiscard

Returns the maximum number of VSS borders that can be placed on edge if their positions are given by sep_func.

As above, every block has at least the edge's min_block_length. A separation function with blocks of different lengths allows fewer borders than a uniform one.

Parameters
edgeEdge descriptor.
sep_funcSeparation function placing the borders.
Returns
Maximum number of VSS borders.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ maximal_vertex_speed()

double cda_rail::Network::maximal_vertex_speed ( VertexInput const & vertex,
const cda_rail::index_set & edges_to_consider = {} ) const
inlinenodiscard

Returns the maximum speed achievable at vertex.

If the vertex has exactly one neighbor the speed of the single incident edge is returned. Otherwise the second-highest speed over distinct neighboring vertices is returned, reflecting the maximum speed at which a train can traverse the vertex without reversing.

Parameters
vertexVertex descriptor.
edges_to_considerSubset of incident edges to consider; if empty, all incident edges are used.
Returns
Maximum speed in m/s, or 0 if no relevant edges exist.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf the vertex does not exist.

◆ minimal_neighboring_edge_length()

double cda_rail::Network::minimal_neighboring_edge_length ( VertexInput const & vertex,
const cda_rail::index_set & edges_to_consider = {} ) const
inlinenodiscard

Returns the length of the shortest edge incident to vertex.

Parameters
vertexVertex descriptor.
edges_to_considerSubset of incident edges to consider; if empty, all incident edges are used.
Returns
Minimum incident edge length in metres, or std::numeric_limits<double>::infinity() if there are no relevant edges.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf the vertex does not exist.

◆ neighboring_edges()

cda_rail::index_set cda_rail::Network::neighboring_edges ( VertexInput const & vertex) const
inlinenodiscard

Returns the set of edge indices of all edges incident to vertex (both in-edges and out-edges).

Parameters
vertexVertex descriptor.
Returns
Set of all incident edge indices.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf the vertex does not exist.

◆ neighbors()

cda_rail::index_set cda_rail::Network::neighbors ( VertexInput const & vertex) const
inlinenodiscard

Returns the set of vertex indices adjacent to vertex via any incident edge.

Parameters
vertexVertex descriptor.
Returns
Set of neighboring vertex indices.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf the vertex does not exist.

◆ no_border_vss_sections()

std::vector< cda_rail::index_set > cda_rail::Network::no_border_vss_sections ( ) const
nodiscard

Returns all sections bounded by NoBorderVSS vertices.

These sections typically result from a prior edge-separation transformation and can be altered by a subsequent VSS-placement algorithm.

Returns
Vector of index sets, each representing one NoBorderVSS section.

◆ number_of_edges()

size_t cda_rail::Network::number_of_edges ( ) const
inlinenodiscard

Returns the total number of edges in the network.

Returns
Number of directed edges.

◆ number_of_vertices()

size_t cda_rail::Network::number_of_vertices ( ) const
inlinenodiscard

Returns the total number of vertices in the network.

Returns
Number of vertices.

◆ out_edges()

cda_rail::index_set cda_rail::Network::out_edges ( VertexInput const & vertex) const
inlinenodiscard

Returns the set of edge indices of all edges leaving vertex.

Parameters
vertexVertex descriptor.
Returns
Set of outgoing edge indices.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf the vertex does not exist.

◆ relevant_breakable_edges()

cda_rail::index_vector cda_rail::Network::relevant_breakable_edges ( ) const
nodiscard

Returns the indices of breakable edges, counting each bidirectional track only once.

For a bidirectional breakable track only the edge with the smaller index is included.

Returns
Vector of relevant breakable edge indices in ascending order.

◆ reset_old_edges()

void cda_rail::Network::reset_old_edges ( )
inline

Forgets from which edges earlier transformations derived the edges, so that get_old_edge and get_old_path refer to the network as it is now.

◆ resolve_vertex_index()

size_t cda_rail::Network::resolve_vertex_index ( VertexInput const & vertex) const
inlinenodiscard

Resolves a vertex descriptor to its numeric vertex index.

Parameters
vertexVertex descriptor.
Returns
Numeric vertex index.
Exceptions
cda_rail::exceptions::VertexNotExistentExceptionIf the vertex does not exist.
cda_rail::exceptions::ConsistencyExceptionIf a Vertex object conflicts with the stored vertex data.

◆ separate_edge()

std::pair< cda_rail::index_vector, cda_rail::index_vector > cda_rail::Network::separate_edge ( EdgeInput const & edge,
const vss::SeparationFunction & sep_func = vss::UNIFORM )
inline

Separates a breakable edge (and its reverse, if present) into multiple sub-edges according to sep_func and the edge's min_block_length.

Parameters
edgeEdge descriptor of the edge to separate.
sep_funcSeparation function that positions the new VSS-border vertices; defaults to uniform separation.
Returns
Pair {forward_new_edges, reverse_new_edges} where each vector contains the indices of the new sub-edges ordered from source to target.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf the network fails is_consistent_for_transformation() or the edge is not breakable.

◆ separate_edges_at_vss()

std::vector< std::pair< size_t, cda_rail::index_vector > > cda_rail::Network::separate_edges_at_vss ( const std::vector< std::vector< double > > & vss_positions)

Splits the breakable edges at the given positions, which become VSS border vertices.

Every resulting sub-edge is unbreakable. A reverse edge is split at the same borders, hence, it is enough to specify them for one direction.

Parameters
vss_positionsFor every edge, the distances of its borders from its source vertex, strictly between 0 and its length.
Returns
Vector of pairs {original_edge_index, new_edge_indices} for every separated direction.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf the network fails is_consistent_for_transformation().
cda_rail::exceptions::InvalidInputExceptionIf vss_positions does not have one entry per edge.

◆ separate_stop_edge()

std::pair< cda_rail::index_vector, cda_rail::index_vector > cda_rail::Network::separate_stop_edge ( EdgeInput const & edge)
inline

Separates a breakable edge using min_stop_block_length with uniform separation.

Parameters
edgeEdge descriptor of the edge to separate.
Returns
Pair {forward_new_edges, reverse_new_edges}.
Exceptions
cda_rail::exceptions::ConsistencyExceptionIf the network fails is_consistent_for_transformation() or the edge is not breakable.

◆ separate_stop_edges()

std::vector< std::pair< size_t, cda_rail::index_vector > > cda_rail::Network::separate_stop_edges ( const cda_rail::index_set & stop_edges)

Separates all edges in stop_edges whose length is at least twice their min_stop_block_length.

Parameters
stop_edgesVector of edge indices to process.
Returns
Vector of pairs {last_new_edge_index, all_new_edge_indices} for each separated direction; edges that are too short are skipped.

◆ set_edge_breakable()

void cda_rail::Network::set_edge_breakable ( EdgeInput const & edge)
inline

Marks an edge as breakable (VSS borders may be placed on it).

Parameters
edgeEdge descriptor.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ set_edge_unbreakable()

void cda_rail::Network::set_edge_unbreakable ( EdgeInput const & edge)
inline

Marks an edge as unbreakable (no VSS borders may be placed on it).

Parameters
edgeEdge descriptor.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the edge does not exist.

◆ set_network_name()

void cda_rail::Network::set_network_name ( std::string_view const networkName)
inline

Sets the network name.

Parameters
networkNameNew name; must be a valid directory name on all operating systems.
Exceptions
cda_rail::exceptions::InvalidInputExceptionIf networkName is not a valid directory name.

◆ shortest_edge_to_edge_path()

std::pair< std::optional< double >, cda_rail::index_vector > cda_rail::Network::shortest_edge_to_edge_path ( EdgeInput const & source_edge,
EdgeInput const & target_edge,
bool only_use_valid_successors = true,
const cda_rail::index_set & edges_to_use = {},
bool include_first_edge = false,
bool use_minimal_time = false,
double max_v = INF ) const
inlinenodiscard

Returns the shortest path and its length from source_edge to target_edge.

Parameters
source_edgeStarting edge descriptor.
target_edgeDestination edge descriptor.
only_use_valid_successorsIf true, only registered successors are followed.
edges_to_useIf non-empty, restricts traversable edges.
include_first_edgeIf true, includes source_edge length.
use_minimal_timeIf true, measures in travel time.
max_vMaximum train speed in m/s.
Returns
Pair of {optional distance, path as edge-index vector}.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf either edge does not exist.

◆ shortest_edge_to_vertex_path()

std::pair< std::optional< double >, cda_rail::index_vector > cda_rail::Network::shortest_edge_to_vertex_path ( EdgeInput const & source_edge,
VertexInput const & target_vertex,
bool only_use_valid_successors = true,
const cda_rail::index_set & edges_to_use = {},
bool include_first_edge = false,
bool use_minimal_time = false,
double max_v = INF ) const
inlinenodiscard

Returns the shortest path and its length from source_edge to target_vertex.

Parameters
source_edgeStarting edge descriptor.
target_vertexDestination vertex descriptor.
only_use_valid_successorsIf true, only registered successors are followed.
edges_to_useIf non-empty, restricts traversable edges.
include_first_edgeIf true, includes source edge length.
use_minimal_timeIf true, measures in travel time.
max_vMaximum train speed in m/s.
Returns
Pair of {optional distance, path as edge-index vector}.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the source edge does not exist.
cda_rail::exceptions::VertexNotExistentExceptionIf the target vertex does not exist.

◆ shortest_path_between_edge_and_vertex_set()

std::pair< std::optional< double >, cda_rail::index_vector > cda_rail::Network::shortest_path_between_edge_and_vertex_set ( const cda_rail::index_set & source_edge_ids,
const cda_rail::index_set & target_vertex_ids,
bool only_use_valid_successors = true,
const cda_rail::index_set & edges_to_use = {},
bool include_first_edge = false,
bool use_minimal_time = false,
double max_v = INF ) const
inlinenodiscard

Returns the shortest path and distance from any edge in source_edge_ids to any vertex in target_vertex_ids.

Parameters
source_edge_idsSet of starting edge indices.
target_vertex_idsSet of destination vertex indices.
only_use_valid_successorsIf true, only registered successors are followed.
edges_to_useIf non-empty, restricts traversable edges.
include_first_edgeIf true, includes source edge length.
use_minimal_timeIf true, measures in travel time.
max_vMaximum train speed in m/s.
Returns
Pair of {optional distance, path as edge-index vector}.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the source edge does not exist.
cda_rail::exceptions::VertexNotExistentExceptionIf the target vertex does not exist.

◆ shortest_path_between_edge_sets()

std::pair< std::optional< double >, cda_rail::index_vector > cda_rail::Network::shortest_path_between_edge_sets ( const cda_rail::index_set & source_edge_ids,
const cda_rail::index_set & target_edge_ids,
bool only_use_valid_successors = true,
const cda_rail::index_set & edges_to_use = {},
bool include_first_edge = false,
bool use_minimal_time = false,
double max_v = INF ) const
inlinenodiscard

Returns the shortest path and distance from any edge in source_edge_ids to any edge in target_edge_ids.

Parameters
source_edge_idsSet of starting edge indices.
target_edge_idsSet of destination edge indices.
only_use_valid_successorsIf true, only registered successors are followed.
edges_to_useIf non-empty, restricts traversable edges.
include_first_edgeIf true, includes source edge length.
use_minimal_timeIf true, measures in travel time.
max_vMaximum train speed in m/s.
Returns
Pair of {optional distance, path as edge-index vector}.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf either edge does not exist.

◆ shortest_path_from_edge_to_edge()

std::optional< double > cda_rail::Network::shortest_path_from_edge_to_edge ( EdgeInput const & source_edge,
EdgeInput const & target_edge,
bool include_first_edge = false,
bool use_minimal_time = false,
double max_v = INF ) const
inlinenodiscard

Returns the shortest distance from source_edge to target_edge.

The distance is measured from the target of source_edge to the target of target_edge using only valid successors.

Parameters
source_edgeStarting edge descriptor.
target_edgeDestination edge descriptor.
include_first_edgeIf true, the length of source_edge is included in the distance.
use_minimal_timeIf true, distances are measured in travel time.
max_vMaximum train speed in m/s.
Returns
Shortest distance, or std::nullopt if unreachable.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf either edge does not exist.

◆ shortest_path_from_edge_to_vertex()

std::optional< double > cda_rail::Network::shortest_path_from_edge_to_vertex ( EdgeInput const & source_edge,
VertexInput const & target_vertex,
bool include_first_edge = false,
bool use_minimal_time = false,
double max_v = INF ) const
inlinenodiscard

Returns the shortest distance from source_edge to target_vertex.

The distance is measured from the target of source_edge to target_vertex using only valid successors.

Parameters
source_edgeStarting edge descriptor.
target_vertexDestination vertex descriptor.
include_first_edgeIf true, the length of source_edge is included.
use_minimal_timeIf true, distances are measured in travel time.
max_vMaximum train speed in m/s.
Returns
Shortest distance, or std::nullopt if unreachable.
Exceptions
cda_rail::exceptions::EdgeNotExistentExceptionIf the source edge does not exist.
cda_rail::exceptions::VertexNotExistentExceptionIf the target vertex does not exist.

◆ shortest_path_length_between_edge_and_vertex_set()

std::optional< double > cda_rail::Network::shortest_path_length_between_edge_and_vertex_set ( const cda_rail::index_set & source_edge_ids,
const cda_rail::index_set & target_vertex_ids,
bool include_first_edge = false,
bool use_minimal_time = false,
double max_v = INF ) const
inlinenodiscard

Returns the length of the shortest path from any edge in source_edge_ids to any vertex in target_vertex_ids.

Parameters
source_edge_idsSet of starting edge indices.
target_vertex_idsSet of destination vertex indices.
include_first_edgeIf true, includes source edge length.
use_minimal_timeIf true, measures in travel time.
max_vMaximum train speed in m/s.
Returns
Shortest distance, or std::nullopt if unreachable.

◆ shortest_path_length_between_edge_sets()

std::optional< double > cda_rail::Network::shortest_path_length_between_edge_sets ( const cda_rail::index_set & source_edge_ids,
const cda_rail::index_set & target_ids,
bool include_first_edge = false,
bool use_minimal_time = false,
double max_v = INF ) const
inlinenodiscard

Returns the length of the shortest path from any edge in source_edge_ids to any edge in target_ids.

Parameters
source_edge_idsSet of starting edge indices.
target_idsSet of destination edge indices.
include_first_edgeIf true, includes source edge length.
use_minimal_timeIf true, measures in travel time.
max_vMaximum train speed in m/s.
Returns
Shortest distance, or std::nullopt if unreachable.

◆ shortest_path_lengths_to_all_vertices()

std::vector< double > cda_rail::Network::shortest_path_lengths_to_all_vertices ( const cda_rail::index_set & source_edge_ids,
bool include_first_edge = false,
bool use_minimal_time = false,
double max_v = INF ) const
nodiscard

Returns the shortest distance from any edge in source_edge_ids to every vertex of the network.

Entry [v] is the distance to vertex v, measured as in shortest_path_length_between_edge_and_vertex_set, and INF if v is unreachable. The source vertices themselves are not treated specially: a vertex only gets a finite value if it is the target of some reachable edge.

Parameters
source_edge_idsSet of starting edge indices.
include_first_edgeIf true, includes source edge lengths.
use_minimal_timeIf true, measures in travel time.
max_vMaximum train speed in m/s.
Returns
Vector of size number_of_vertices().
Exceptions
cda_rail::exceptions::InvalidInputExceptionIf source_edge_ids is empty or use_minimal_time is true with non-positive max_v.
cda_rail::exceptions::EdgeNotExistentExceptionIf a source edge does not exist.

◆ throw_if_not_valid_successor()

void cda_rail::Network::throw_if_not_valid_successor ( EdgeInput const & edge_in,
EdgeInput const & edge_out ) const
inline

Checks that edge_out may be used directly after edge_in.

Parameters
edge_inEdge descriptor of the incoming edge.
edge_outEdge descriptor of the outgoing edge.
Exceptions
cda_rail::exceptions::InvalidInputExceptionIf edge_out is not a successor of edge_in.

◆ unbreakable_sections()

std::vector< cda_rail::index_set > cda_rail::Network::unbreakable_sections ( ) const
nodiscard

Returns all unbreakable sections of the network.

Each section is represented as a set of edge indices. The method covers:

  • Single-edge sections between two TTD/VSS vertices.
  • Multi-edge sections passing through one or more NoBorder vertices.
Returns
Vector of index sets, each representing one unbreakable section.

◆ vertices_used_by_edges()

cda_rail::index_set cda_rail::Network::vertices_used_by_edges ( const cda_rail::index_set & edges_tmp) const
nodiscard

Returns all vertex indices that are endpoints of at least one edge in edges_tmp.

Parameters
edges_tmpSet of edge indices to inspect.
Returns
Set of vertex indices referenced as source or target by any edge in edges_tmp.

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