Skip to main content

reachability_matrix

Function reachability_matrix 

Source
pub fn reachability_matrix(graph: &Graph) -> IgraphResult<Vec<Vec<bool>>>
Expand description

Dense reachability matrix of graph. result[i][j] is true iff vertex j is reachable from i in zero or more steps.

On directed graphs follows out-edges (matches upstream’s IGRAPH_OUT mode); on undirected graphs reachability is symmetric.

Counterpart of igraph_reachability(_, _, _, _, _, IGRAPH_OUT) (dense output; upstream returns a per-SCC bitset list).

§Examples

use rust_igraph::{Graph, reachability_matrix};

// Directed 0->1->2: 0 can reach all; 1 can reach 1, 2; 2 only 2.
let mut g = Graph::new(3, true).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
let m = reachability_matrix(&g).unwrap();
assert_eq!(m[0], vec![true, true, true]);
assert_eq!(m[1], vec![false, true, true]);
assert_eq!(m[2], vec![false, false, true]);