Skip to main content

all_simple_paths

Function all_simple_paths 

Source
pub fn all_simple_paths(
    graph: &Graph,
    from: u32,
    to: Option<&[u32]>,
    mode: SimplePathMode,
    min_len: i32,
    max_len: i32,
    max_results: i64,
) -> IgraphResult<Vec<Vec<u32>>>
Expand description

Enumerate all simple paths from from to vertices in to.

A path is simple if no vertex appears more than once. Returns paths as vertex sequences (including from and the final vertex).

Multi-edges and self-loops in the graph are ignored — the neighbor list is deduplicated before traversal.

§Parameters

  • to: target vertices. If None, all vertices are targets.
  • mode: direction of traversal for directed graphs. Ignored for undirected graphs.
  • min_len: minimum path length (number of edges). Paths shorter than this are not returned. Use 0 or negative for no lower bound.
  • max_len: maximum path length. Use a negative value for no upper bound.
  • max_results: maximum number of paths to return. Use a negative value for no limit.

§Examples

use rust_igraph::{Graph, create, all_simple_paths, SimplePathMode};

// Path graph: 0-1-2-3
let g = create(&[(0,1),(1,2),(2,3)], 4, false).unwrap();
let paths = all_simple_paths(&g, 0, None, SimplePathMode::Out, 0, -1, -1).unwrap();
// From 0: paths to 1 (len 1), to 2 (len 2), to 3 (len 3)
assert_eq!(paths.len(), 3);