pub fn shortest_path<T, S>(
graph: &S,
from_vertex: Option<usize>,
to_vertex: Option<usize>,
method: &str,
directed: bool,
returnpredecessors: bool,
) -> SparseResult<(Array2<T>, Option<Array2<isize>>)>
Expand description
Compute shortest paths in a graph
§Arguments
graph
- The graph as a sparse matrixfrom_vertex
- Source vertex (None for all pairs)to_vertex
- Target vertex (None for all destinations)method
- Algorithm to usedirected
- Whether the graph is directedreturnpredecessors
- Whether to return predecessor information
§Returns
A tuple containing:
- Distance matrix/array
- Optional predecessor matrix/array
§Examples
use scirs2_sparse::csgraph::shortest_path;
use scirs2_sparse::csr_array::CsrArray;
// Create a simple graph
let rows = vec![0, 0, 1, 2];
let cols = vec![1, 2, 2, 0];
let data = vec![1.0, 4.0, 2.0, 3.0];
let graph = CsrArray::from_triplets(&rows, &cols, &data, (3, 3), false).unwrap();
// Find shortest paths from vertex 0
let (distances_) = shortest_path(
&graph, Some(0), None, "dijkstra", true, false
).unwrap();