Skip to main content

mincut_value

Function mincut_value 

Source
pub fn mincut_value(
    graph: &Graph,
    capacity: Option<&[f64]>,
) -> IgraphResult<f64>
Expand description

Global minimum-cut value of a (possibly weighted) graph.

Returns the minimum total capacity of an edge set whose removal disconnects some pair of distinct vertices. For undirected input, equivalent to the global min-cut over weak components; for directed input, over strongly connected components.

Mirrors igraph_mincut_value (references/igraph/src/flow/flow.c:1692).

§Arguments

  • graph — input graph (directed or undirected).
  • capacity — optional per-edge capacity vector. None means every edge has unit capacity (in which case the result equals edge_connectivity(graph, true) as f64). When Some(c), c.len() must equal graph.ecount() and each entry must be a finite non-negative number — these checks are delegated to max_flow_value.

§Returns

  • f64::INFINITY if vcount() ≤ 1 (no pair to separate).
  • 0.0 if the graph is not strongly connected (directed) or not connected (undirected).
  • Otherwise the minimum value of max_flow_value(graph, 0, v, capacity) (plus max_flow_value(graph, v, 0, capacity) for directed) over v ∈ 1..vcount().

§Errors

Propagates errors from max_flow_value — chiefly IgraphError::InvalidArgument for bad capacity input (length mismatch, NaN, negative).

§Examples

use rust_igraph::{Graph, mincut_value};

// Undirected ring on 5 vertices, unit caps — global min cut = 2.
let mut g = Graph::new(5, false).unwrap();
for (u, v) in [(0u32, 1u32), (1, 2), (2, 3), (3, 4), (4, 0)] {
    g.add_edge(u, v).unwrap();
}
assert!((mincut_value(&g, None).unwrap() - 2.0).abs() < 1e-12);

// Same ring, weighted: each edge weight 0.5 → min cut = 1.0.
let caps = vec![0.5_f64; 5];
let mc = mincut_value(&g, Some(&caps)).unwrap();
assert!((mc - 1.0).abs() < 1e-12);