pub fn build_topology_graph(
netelements: &[Netelement],
netrelations: &[NetRelation],
) -> Result<(DiGraph<NetelementSide, f64>, HashMap<NetelementSide, NodeIndex>), ProjectionError>Expand description
Build a directed graph representing the railway network topology
Creates a petgraph DiGraph where:
- Nodes are NetelementSide (each netelement has 2 nodes: start and end)
- Edges represent navigability:
- Internal edges: start→end and end→start within each netelement
- External edges: connections between netelements via netrelations
§Graph Structure Example
For netelement “NE_A”:
- Node: NE_A position 0 (start)
- Node: NE_A position 1 (end)
- Internal edges: start→end (forward), end→start (backward)
For netrelation connecting NE_A(end) to NE_B(start) with forward navigability:
- External edge: NE_A position 1 → NE_B position 0
§Parameters
netelements: All track segments in the networknetrelations: Navigability connections between segments
§Returns
A DiGraph where edges represent valid navigation paths, and a mapping from NetelementSide to NodeIndex for efficient lookups.
§Examples
use tp_lib_core::path::build_topology_graph;
use tp_lib_core::models::{Netelement, NetRelation};
let netelements = vec![/* ... */];
let netrelations = vec![/* ... */];
let (graph, node_map) = build_topology_graph(&netelements, &netrelations)?;
// Use graph for path finding algorithms