pub struct Graph { /* private fields */ }Expand description
A network graph for spatial analysis
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn graph_type(&self) -> GraphType
pub fn graph_type(&self) -> GraphType
Get the graph type
Sourcepub fn add_node(&mut self, coordinate: Coordinate) -> NodeId
pub fn add_node(&mut self, coordinate: Coordinate) -> NodeId
Add a node to the graph
Sourcepub fn add_node_with_id(
&mut self,
id: NodeId,
coordinate: Coordinate,
) -> Result<NodeId>
pub fn add_node_with_id( &mut self, id: NodeId, coordinate: Coordinate, ) -> Result<NodeId>
Add a node with a specific ID (useful for graph reconstruction)
Sourcepub fn add_edge(
&mut self,
source: NodeId,
target: NodeId,
weight: f64,
) -> Result<EdgeId>
pub fn add_edge( &mut self, source: NodeId, target: NodeId, weight: f64, ) -> Result<EdgeId>
Add an edge to the graph
Sourcepub fn add_weighted_edge(
&mut self,
source: NodeId,
target: NodeId,
multi_weight: EdgeWeight,
) -> Result<EdgeId>
pub fn add_weighted_edge( &mut self, source: NodeId, target: NodeId, multi_weight: EdgeWeight, ) -> Result<EdgeId>
Add an edge with multi-criteria weight
Sourcepub fn remove_edge(&mut self, edge_id: EdgeId) -> Result<Edge>
pub fn remove_edge(&mut self, edge_id: EdgeId) -> Result<Edge>
Remove an edge from the graph
Sourcepub fn remove_node(&mut self, node_id: NodeId) -> Result<Node>
pub fn remove_node(&mut self, node_id: NodeId) -> Result<Node>
Remove a node and all its incident edges from the graph
Sourcepub fn get_node_mut(&mut self, id: NodeId) -> Option<&mut Node>
pub fn get_node_mut(&mut self, id: NodeId) -> Option<&mut Node>
Get a mutable reference to a node by ID
Sourcepub fn get_edge_mut(&mut self, id: EdgeId) -> Option<&mut Edge>
pub fn get_edge_mut(&mut self, id: EdgeId) -> Option<&mut Edge>
Get a mutable reference to an edge by ID
Sourcepub fn outgoing_edges(&self, node: NodeId) -> &[EdgeId]
pub fn outgoing_edges(&self, node: NodeId) -> &[EdgeId]
Get all outgoing edges from a node
Sourcepub fn incoming_edges(&self, node: NodeId) -> &[EdgeId]
pub fn incoming_edges(&self, node: NodeId) -> &[EdgeId]
Get all incoming edges to a node
Sourcepub fn neighbors(&self, node: NodeId) -> Vec<NodeId>
pub fn neighbors(&self, node: NodeId) -> Vec<NodeId>
Get all neighbors of a node (targets of outgoing edges)
Sourcepub fn neighbors_with_edges(&self, node: NodeId) -> Vec<(NodeId, EdgeId, f64)>
pub fn neighbors_with_edges(&self, node: NodeId) -> Vec<(NodeId, EdgeId, f64)>
Get all neighbors with the connecting edge information
Sourcepub fn find_edge(&self, source: NodeId, target: NodeId) -> Option<EdgeId>
pub fn find_edge(&self, source: NodeId, target: NodeId) -> Option<EdgeId>
Find an edge between two specific nodes
Sourcepub fn find_edges(&self, source: NodeId, target: NodeId) -> Vec<EdgeId>
pub fn find_edges(&self, source: NodeId, target: NodeId) -> Vec<EdgeId>
Find all edges between two specific nodes (multi-graph support)
Sourcepub fn nearest_node(&self, coord: &Coordinate) -> Option<NodeId>
pub fn nearest_node(&self, coord: &Coordinate) -> Option<NodeId>
Find the nearest node to a given coordinate
Sourcepub fn k_nearest_nodes(
&self,
coord: &Coordinate,
k: usize,
) -> Vec<(NodeId, f64)>
pub fn k_nearest_nodes( &self, coord: &Coordinate, k: usize, ) -> Vec<(NodeId, f64)>
Find the k nearest nodes to a given coordinate
Sourcepub fn out_degree(&self, node: NodeId) -> usize
pub fn out_degree(&self, node: NodeId) -> usize
Compute the out-degree of a node
Sourcepub fn metrics(&self) -> GraphMetrics
pub fn metrics(&self) -> GraphMetrics
Calculate graph metrics
Sourcepub fn subgraph(&self, node_ids: &[NodeId]) -> Result<Graph>
pub fn subgraph(&self, node_ids: &[NodeId]) -> Result<Graph>
Create a subgraph containing only the specified nodes and edges between them
Sourcepub fn reverse(&self) -> Graph
pub fn reverse(&self) -> Graph
Reverse all edge directions (only meaningful for directed graphs)
Sourcepub fn nodes_iter(&self) -> impl Iterator<Item = (&NodeId, &Node)>
pub fn nodes_iter(&self) -> impl Iterator<Item = (&NodeId, &Node)>
Access the nodes map directly (for iteration)
Sourcepub fn edges_iter(&self) -> impl Iterator<Item = (&EdgeId, &Edge)>
pub fn edges_iter(&self) -> impl Iterator<Item = (&EdgeId, &Edge)>
Access the edges map directly (for iteration)
Sourcepub fn sorted_node_ids(&self) -> Vec<NodeId>
pub fn sorted_node_ids(&self) -> Vec<NodeId>
Get sorted node IDs for deterministic iteration
Source§impl Graph
impl Graph
Sourcepub fn validate_detailed(&self) -> ValidationResult
pub fn validate_detailed(&self) -> ValidationResult
Detailed graph validation returning all issues
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if the graph is connected (weakly for directed graphs)
Sourcepub fn connected_components(&self) -> Vec<ConnectedComponent>
pub fn connected_components(&self) -> Vec<ConnectedComponent>
Find all connected components (weakly connected for directed graphs)
Sourcepub fn strongly_connected_components(&self) -> Vec<Vec<NodeId>>
pub fn strongly_connected_components(&self) -> Vec<Vec<NodeId>>
Find strongly connected components using Tarjan’s algorithm (directed graphs only)
Sourcepub fn remove_isolated_nodes(&mut self) -> Vec<NodeId>
pub fn remove_isolated_nodes(&mut self) -> Vec<NodeId>
Remove all isolated nodes (nodes with no edges)
Sourcepub fn remove_self_loops(&mut self) -> Vec<EdgeId>
pub fn remove_self_loops(&mut self) -> Vec<EdgeId>
Remove self-loops
Sourcepub fn remove_parallel_edges(&mut self) -> Vec<EdgeId>
pub fn remove_parallel_edges(&mut self) -> Vec<EdgeId>
Remove duplicate (parallel) edges, keeping the one with minimum weight
Sourcepub fn contract_degree2_nodes(&mut self) -> usize
pub fn contract_degree2_nodes(&mut self) -> usize
Contract degree-2 nodes (nodes with exactly one incoming and one outgoing edge)
Sourcepub fn snap_nodes(&mut self, tolerance: f64) -> usize
pub fn snap_nodes(&mut self, tolerance: f64) -> usize
Snap close nodes together within a tolerance
Sourcepub fn clean_topology(&mut self, tolerance: f64) -> TopologyCleanResult
pub fn clean_topology(&mut self, tolerance: f64) -> TopologyCleanResult
Clean topology by performing multiple operations