Struct transit_grid::graphs::TopologyGraph
source · pub struct TopologyGraph {
pub graph: StableDiGraph<TopoNode, TopoEdge, u32>,
/* private fields */
}
Expand description
Represents the topological graph of a transit network as a skew-symmetric graph.
A TopologyGraph
is a directed graph where each node in the topological graph
maps to a node in the physical graph. This is particularly useful for scenarios
such as rail switches where the directionality of edges matters.
Skew-Symmetric Model
The TopologyGraph
struct uses a skew-symmetric model based on the definition by Goldberg & Karzanov (1996).
In this model, let G = (V, E)
be the directed graph with a function σ
mapping vertices of G
to other vertices,
satisfying the following properties:
- For every vertex
v
,σ(v)
≠v
. - For every vertex
v
,σ(σ(v))
=v
. - For every edge
(u, v)
,(σ(v), σ(u))
must also be an edge.
In the context of TopologyGraph
,
- For each node
v
inV
, there are two nodes inV_t
, denoted asv_entry
andv_exit
. - For each edge
(u, v)
inE
, there are two directed edges inE_t
: one fromu_exit
tov_entry
and one fromv_exit
tou_entry
.
Mathematically,
V_t = {v_entry, v_exit | v ∈ V}
E_t = {(u_exit, v_entry), (v_exit, u_entry) | (u, v) ∈ E}
Bigroup Algebraic Structure (Additional Information)
According to Dr. R. Muthuraj and P. M. Sitharselvam, M. S. Muthuraman (2010), a set G
with two binary operations +
and *
is called a bigroup if there exist two proper subsets G1
and G2
of G
such that G = G1 ∪ G2
.
Fields§
§graph: StableDiGraph<TopoNode, TopoEdge, u32>
the inner graph
Implementations§
source§impl TopologyGraph
impl TopologyGraph
sourcepub fn index_to_id(&self, index: NodeIndex) -> Option<&NodeId>
pub fn index_to_id(&self, index: NodeIndex) -> Option<&NodeId>
Returns the NodeId
corresponding to a given NodeIndex
.
This method is useful when you have the index of a node in the graph and you want to retrieve its identifier.
Arguments
index
- TheNodeIndex
of the node.
Returns
NodeId
- The identifier of the node corresponding to the input index.
Panics
This function will panic if the NodeIndex
does not exist in the graph.
sourcepub fn id_to_index(&self, id: NodeId) -> Option<&(NodeIndex, NodeIndex)>
pub fn id_to_index(&self, id: NodeId) -> Option<&(NodeIndex, NodeIndex)>
Returns the NodeIndex
corresponding to a given NodeId
.
This method is useful when you have the identifier of a node and you want to retrieve its index in the graph.
As each NodeId
maps to two TopoNode
s in the graph, this function returns a tuple of NodeIndex
.
Arguments
id
- TheNodeId
of the node.
Returns
- A tuple of two
NodeIndex
values corresponding to the twoTopoNode
s for the inputNodeId
.
Panics
This function will panic if the NodeId
does not exist in the graph.
sourcepub fn add_edge(
&mut self,
edge_id: EdgeId,
from_node_id: NodeId,
to_node_id: NodeId
) -> (EdgeIndex, EdgeIndex)
pub fn add_edge( &mut self, edge_id: EdgeId, from_node_id: NodeId, to_node_id: NodeId ) -> (EdgeIndex, EdgeIndex)
sourcepub fn no_edges_in_direction(
&self,
topo_node_id: NodeIndex,
neighbors: Vec<NodeId>,
dir: Direction
) -> bool
pub fn no_edges_in_direction( &self, topo_node_id: NodeIndex, neighbors: Vec<NodeId>, dir: Direction ) -> bool
Checks if there are no edges in the specified direction leading to any of the nodes in the neighbors list.
Arguments
topo_node_id
- TheNodeIndex
of the node to check.neighbors
- A vector ofNodeId
that the node should not have edges towards in the given direction.dir
- The direction of the edges to check (Outgoing or Incoming).
Returns
bool
- True if none of the neighbors have an edge in the given direction to the node, otherwise false.
sourcepub fn find_node_index_with_edges(
&self,
node_id: NodeId,
neighbors: Vec<NodeId>,
dir: Direction
) -> Option<NodeIndex>
pub fn find_node_index_with_edges( &self, node_id: NodeId, neighbors: Vec<NodeId>, dir: Direction ) -> Option<NodeIndex>
Returns the NodeIndex
of the NodeId
that does not have any edge in the opposite direction leading to any node in neighbors
.
Arguments
node_id
- The ID of the node to check.neighbors
- A vector ofNodeId
s to check.dir
- TheDirection
in which to check the edges.
Returns
Option<NodeIndex>
- TheNodeIndex
of theNodeId
if it does not have any edge in the opposite direction leading to nodes inneighbors
, otherwiseNone
.
sourcepub fn get_other_toponode(&self, topo_node_id: NodeIndex) -> Option<NodeIndex>
pub fn get_other_toponode(&self, topo_node_id: NodeIndex) -> Option<NodeIndex>
sourcepub fn add_edge_with_accessibility(
&mut self,
edge_id: EdgeId,
from_node_id: NodeId,
to_node_id: NodeId,
accessability: Accessability
) -> (EdgeIndex, EdgeIndex)
pub fn add_edge_with_accessibility( &mut self, edge_id: EdgeId, from_node_id: NodeId, to_node_id: NodeId, accessability: Accessability ) -> (EdgeIndex, EdgeIndex)
Adds an edge with a certain accessibility into the graph.
Arguments
edge_id
- The identifier of the edge that should be added.from_node_id
- The identifier of the node where the edge should start.to_node_id
- The identifier of the node where the edge should end.accessability
- The type of accessability of the edge. This can be eitherReachableNodes
orUnreachableNodes
.
Returns
A tuple of EdgeIndex
values that were assigned to the newly created edges.
Panics
The function will panic if it’s unable to add an edge with the provided accessibility. This might occur if it cannot find nodes with the desired edge accessability or if the respective TopoNode
s for the given nodes cannot be found.
sourcepub fn has_incoming(&self, node: NodeIndex) -> bool
pub fn has_incoming(&self, node: NodeIndex) -> bool
sourcepub fn reverse_edge(&mut self, edge_index: EdgeIndex)
pub fn reverse_edge(&mut self, edge_index: EdgeIndex)
sourcepub fn find_edge_indices(
&self,
node1_id: NodeId,
node2_id: NodeId
) -> Option<(EdgeIndex, EdgeIndex)>
pub fn find_edge_indices( &self, node1_id: NodeId, node2_id: NodeId ) -> Option<(EdgeIndex, EdgeIndex)>
Returns the indices of edges between two nodes in all directions.
Arguments
node1_id
- The ID of the first node.node2_id
- The ID of the second node.
Returns
Option<(EdgeIndex, EdgeIndex)>
- The indices of the two edges between the nodes, if they exist.
Panics
This function will panic if the nodes do not exist in the graph.
sourcepub fn edge_is_in_neighbors_direction(&self, edge_index: EdgeIndex) -> bool
pub fn edge_is_in_neighbors_direction(&self, edge_index: EdgeIndex) -> bool
Checks if an edge is in the same direction as its neighboring edges.
Arguments
edge_index
- TheEdgeIndex
of the edge to check.
Returns
bool
-true
if the edge is in the same direction as its neighboring edges,false
otherwise.
Panics
This function will panic if the EdgeIndex
does not exist in the graph.
Trait Implementations§
source§impl Clone for TopologyGraph
impl Clone for TopologyGraph
source§fn clone(&self) -> TopologyGraph
fn clone(&self) -> TopologyGraph
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more