pub struct IndexedGraph<C> { /* private fields */ }Expand description
A directed graph stored as dense usize indices with weighted adjacency lists.
Implementations§
Source§impl<C> IndexedGraph<C>
impl<C> IndexedGraph<C>
Sourcepub const fn from_adjacency(adjacency: Vec<Vec<(usize, C)>>) -> Self
pub const fn from_adjacency(adjacency: Vec<Vec<(usize, C)>>) -> Self
Build a directed indexed graph from an adjacency list.
Sourcepub const fn node_count(&self) -> usize
pub const fn node_count(&self) -> usize
Return the number of nodes in the graph.
Sourcepub fn successors(&self, node: usize) -> &[(usize, C)]
pub fn successors(&self, node: usize) -> &[(usize, C)]
Return the adjacency list for node.
Sourcepub fn astar<FH, FS>(
&self,
start: usize,
heuristic: FH,
success: FS,
) -> Option<(Vec<usize>, C)>
pub fn astar<FH, FS>( &self, start: usize, heuristic: FH, success: FS, ) -> Option<(Vec<usize>, C)>
Run A* from start to a node satisfying success.
Sourcepub fn astar_bag<FH, FS>(
&self,
start: usize,
heuristic: FH,
success: FS,
) -> Option<(impl Iterator<Item = Vec<usize>>, C)>
pub fn astar_bag<FH, FS>( &self, start: usize, heuristic: FH, success: FS, ) -> Option<(impl Iterator<Item = Vec<usize>>, C)>
Run A* and return all shortest paths as an iterator.
Sourcepub fn astar_bag_collect<FH, FS>(
&self,
start: usize,
heuristic: FH,
success: FS,
) -> Option<(Vec<Vec<usize>>, C)>
pub fn astar_bag_collect<FH, FS>( &self, start: usize, heuristic: FH, success: FS, ) -> Option<(Vec<Vec<usize>>, C)>
Run A* and collect all shortest paths into a vector.
Sourcepub fn bfs<FS>(&self, start: usize, success: FS) -> Option<Vec<usize>>
pub fn bfs<FS>(&self, start: usize, success: FS) -> Option<Vec<usize>>
Run BFS from start to a node satisfying success.
Sourcepub fn bfs_loop(&self, start: usize) -> Option<Vec<usize>>
pub fn bfs_loop(&self, start: usize) -> Option<Vec<usize>>
Run BFS and return the shortest loop starting and ending at start.
Sourcepub fn bfs_bidirectional(&self, start: usize, end: usize) -> Option<Vec<usize>>
pub fn bfs_bidirectional(&self, start: usize, end: usize) -> Option<Vec<usize>>
Run bidirectional BFS from start to end.
Sourcepub fn bfs_reach(&self, start: usize) -> impl Iterator<Item = usize> + '_
pub fn bfs_reach(&self, start: usize) -> impl Iterator<Item = usize> + '_
Iterate over nodes reachable from start using BFS order.
Sourcepub fn dfs<FS>(&self, start: usize, success: FS) -> Option<Vec<usize>>
pub fn dfs<FS>(&self, start: usize, success: FS) -> Option<Vec<usize>>
Run DFS from start to a node satisfying success.
Sourcepub fn dfs_reach(&self, start: usize) -> impl Iterator<Item = usize> + '_
pub fn dfs_reach(&self, start: usize) -> impl Iterator<Item = usize> + '_
Iterate over nodes reachable from start using DFS order.
Sourcepub fn iddfs<FS>(&self, start: usize, success: FS) -> Option<Vec<usize>>
pub fn iddfs<FS>(&self, start: usize, success: FS) -> Option<Vec<usize>>
Run IDDFS from start to a node satisfying success.
Sourcepub fn idastar<FH, FS>(
&self,
start: usize,
heuristic: FH,
success: FS,
) -> Option<(Vec<usize>, C)>
pub fn idastar<FH, FS>( &self, start: usize, heuristic: FH, success: FS, ) -> Option<(Vec<usize>, C)>
Run IDA* from start to a node satisfying success.
Sourcepub fn dijkstra<FS>(&self, start: usize, success: FS) -> Option<(Vec<usize>, C)>
pub fn dijkstra<FS>(&self, start: usize, success: FS) -> Option<(Vec<usize>, C)>
Run Dijkstra from start to a node satisfying success.
Sourcepub fn dijkstra_all(&self, start: usize) -> Vec<Option<(usize, C)>>
pub fn dijkstra_all(&self, start: usize) -> Vec<Option<(usize, C)>>
Compute shortest paths to all reachable nodes from start.
Sourcepub fn dijkstra_partial<FS>(
&self,
start: usize,
stop: FS,
) -> (Vec<Option<(usize, C)>>, Option<usize>)
pub fn dijkstra_partial<FS>( &self, start: usize, stop: FS, ) -> (Vec<Option<(usize, C)>>, Option<usize>)
Compute shortest paths until stop returns true.
Sourcepub fn dijkstra_reach(
&self,
start: usize,
) -> impl Iterator<Item = (usize, Option<usize>, C)> + '_
pub fn dijkstra_reach( &self, start: usize, ) -> impl Iterator<Item = (usize, Option<usize>, C)> + '_
Iterate over nodes reached by Dijkstra, yielding the node, parent, and total cost.
Sourcepub fn bmssp<FS>(&self, start: usize, success: FS) -> Option<(Vec<usize>, C)>
pub fn bmssp<FS>(&self, start: usize, success: FS) -> Option<(Vec<usize>, C)>
Run the BMSSP-based SSSP algorithm from start.
Sourcepub fn bmssp_all(&self, start: usize) -> Vec<Option<(usize, C)>>
pub fn bmssp_all(&self, start: usize) -> Vec<Option<(usize, C)>>
Compute BMSSP parents and costs for all reachable nodes from start.
Sourcepub fn fringe<FH, FS>(
&self,
start: usize,
heuristic: FH,
success: FS,
) -> Option<(Vec<usize>, C)>
pub fn fringe<FH, FS>( &self, start: usize, heuristic: FH, success: FS, ) -> Option<(Vec<usize>, C)>
Run Fringe search from start to a node satisfying success.
Sourcepub fn strongly_connected_components(&self) -> Vec<Vec<usize>>
pub fn strongly_connected_components(&self) -> Vec<Vec<usize>>
Compute strongly connected components for all nodes.
Sourcepub fn strongly_connected_components_from(
&self,
start: usize,
) -> Vec<Vec<usize>>
pub fn strongly_connected_components_from( &self, start: usize, ) -> Vec<Vec<usize>>
Compute strongly connected components reachable from start.
Sourcepub fn strongly_connected_component(&self, node: usize) -> Vec<usize>
pub fn strongly_connected_component(&self, node: usize) -> Vec<usize>
Compute the strongly connected component containing node.
Sourcepub fn count_paths<FS>(&self, start: usize, success: FS) -> usize
pub fn count_paths<FS>(&self, start: usize, success: FS) -> usize
Count the number of paths from start to nodes satisfying success.
Source§impl<C: Copy> IndexedGraph<C>
impl<C: Copy> IndexedGraph<C>
Sourcepub fn from_adjacency_matrix(
matrix: &[Vec<Option<C>>],
) -> Result<Self, IndexedInputError>
pub fn from_adjacency_matrix( matrix: &[Vec<Option<C>>], ) -> Result<Self, IndexedInputError>
Build a directed indexed graph from a square adjacency matrix.
Every Some(weight) cell becomes a directed edge from the row index to the
column index. None cells produce no edge.
§Errors
Returns IndexedInputError::RaggedMatrix if rows have different lengths and
IndexedInputError::NonSquareAdjacencyMatrix if the matrix is not square.
§Example
use pathfinding_indexed::IndexedGraph;
let graph = IndexedGraph::from_adjacency_matrix(&[
vec![None, Some(3), None],
vec![None, None, Some(2)],
vec![Some(1), None, None],
])
.unwrap();
assert_eq!(graph.successors(0), &[(1, 3)]);
assert_eq!(graph.successors(1), &[(2, 2)]);
assert_eq!(graph.successors(2), &[(0, 1)]);Trait Implementations§
Source§impl<C: Clone> Clone for IndexedGraph<C>
impl<C: Clone> Clone for IndexedGraph<C>
Source§fn clone(&self) -> IndexedGraph<C>
fn clone(&self) -> IndexedGraph<C>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more