pub fn traversegraph<T, S>(
graph: &S,
start: usize,
directed: bool,
order: &str,
return_predecessors: bool,
) -> SparseResult<(Vec<usize>, Option<Array1<isize>>)>Expand description
Perform graph traversal from a starting vertex
§Arguments
graph- The graph as a sparse matrixstart- Starting vertexdirected- Whether the graph is directedorder- Traversal order (BFS or DFS)return_predecessors- Whether to return predecessor information
§Returns
A tuple containing:
- Traversal order as a vector of vertex indices
- Optional predecessor array
§Examples
use scirs2_sparse::csgraph::traversegraph;
use scirs2_sparse::csr_array::CsrArray;
// Create a simple graph
let rows = vec![0, 1, 1, 2];
let cols = vec![1, 0, 2, 1];
let data = vec![1.0, 1.0, 1.0, 1.0];
let graph = CsrArray::from_triplets(&rows, &cols, &data, (3, 3), false).unwrap();
// Perform BFS from vertex 0
let (order, _) = traversegraph(&graph, 0, false, "bfs", false).unwrap();