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
vinV, there are two nodes inV_t, denoted asv_entryandv_exit. - For each edge
(u, v)inE, there are two directed edges inE_t: one fromu_exittov_entryand one fromv_exittou_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- TheNodeIndexof 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 TopoNodes in the graph, this function returns a tuple of NodeIndex.
Arguments
id- TheNodeIdof the node.
Returns
- A tuple of two
NodeIndexvalues corresponding to the twoTopoNodes 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- TheNodeIndexof the node to check.neighbors- A vector ofNodeIdthat 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 ofNodeIds to check.dir- TheDirectionin which to check the edges.
Returns
Option<NodeIndex>- TheNodeIndexof theNodeIdif 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 eitherReachableNodesorUnreachableNodes.
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 TopoNodes 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- TheEdgeIndexof the edge to check.
Returns
bool-trueif the edge is in the same direction as its neighboring edges,falseotherwise.
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