has_path

Function has_path 

Source
pub fn has_path<T, S>(
    graph: &S,
    source: usize,
    target: usize,
    directed: bool,
) -> SparseResult<bool>
where T: Float + Debug + Copy + 'static, S: SparseArray<T>,
Expand description

Check if there is a path between two vertices

§Arguments

  • graph - The graph as a sparse matrix
  • source - Source vertex
  • target - Target vertex
  • directed - Whether the graph is directed

§Returns

True if there is a path from source to target, false otherwise

§Examples

use scirs2_sparse::csgraph::has_path;
use scirs2_sparse::csr_array::CsrArray;

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();

assert!(has_path(&graph, 0, 2, false).unwrap());