Skip to main content

vertex_disjoint_paths

Function vertex_disjoint_paths 

Source
pub fn vertex_disjoint_paths(
    graph: &Graph,
    source: VertexId,
    target: VertexId,
) -> IgraphResult<i64>
Expand description

Maximum number of pairwise internally vertex-disjoint paths from source to target.

Counterpart of igraph_vertex_disjoint_paths in references/igraph/src/flow/flow.c:2374. By Menger’s theorem (1927) on internal-vertex cuts, this equals the s-t vertex connectivity (under the Ignore convention) plus the count of direct source → target edges. See st_vertex_connectivity for the connectivity-flavoured spelling.

§Arguments

  • graph — input graph (directed or undirected).
  • source — source vertex id (0 ≤ source < vcount()).
  • target — sink vertex id (0 ≤ target < vcount(), target != source).

§Returns

The maximum number of internally vertex-disjoint source → target paths as i64, plus the count of direct source → target edges. Returns 0 when no path exists at all.

§Errors

Same as st_vertex_connectivity:

  • IgraphError::VertexOutOfRange if source or target is outside [0, vcount()).
  • IgraphError::InvalidArgument if source == target (igraph C returns IGRAPH_UNIMPLEMENTED for this case; we use InvalidArgument for parity with the rest of our flow module), or if vcount() < 2.
  • IgraphError::Internal if the sum vc + direct_count overflows i64 (unreachable in practice — both summands are bounded above by ecount() ≤ u32::MAX).

§Examples

use rust_igraph::{Graph, vertex_disjoint_paths};

// Two parallel directed paths 0→1→3 and 0→2→3 → 2 vertex-disjoint paths.
let mut g = Graph::new(4, true).unwrap();
for (s, t) in [(0u32, 1u32), (1, 3), (0, 2), (2, 3)] {
    g.add_edge(s, t).unwrap();
}
assert_eq!(vertex_disjoint_paths(&g, 0, 3).unwrap(), 2);