Skip to main content

mincut

Function mincut 

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

Compute the global minimum cut of a (possibly weighted) graph.

Returns the minimum-capacity edge set whose removal maximally disconnects the graph, along with the resulting vertex partitions.

§Arguments

  • graph — input graph (directed or undirected).
  • capacity — optional per-edge capacity vector. None means unit capacities. When Some(c), c.len() must equal graph.ecount() and all entries must be finite non-negative.

§Returns

A Mincut containing:

  • value — total capacity of the cut (f64::INFINITY if vcount ≤ 1).
  • cut — edge IDs in the cut.
  • partition / partition2 — the two sides after cutting.

§Errors

Propagates errors from st_mincut (capacity validation, vertex out-of-range, etc.).

§Examples

use rust_igraph::{Graph, mincut};

// Undirected path: 0-1-2. Min cut = 1 edge.
let mut g = Graph::new(3, false).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
let mc = mincut(&g, None).unwrap();
assert!((mc.value - 1.0).abs() < 1e-12);
assert_eq!(mc.cut.len(), 1);
assert_eq!(mc.partition.len() + mc.partition2.len(), 3);