Skip to main content

maximum_cut

Function maximum_cut 

Source
pub fn maximum_cut(graph: &Graph) -> IgraphResult<MaxCutResult>
Expand description

Compute an approximate maximum cut using a greedy heuristic.

Processes vertices in order. Each vertex is assigned to the side (S or V\S) that maximizes the number of edges crossing the cut. The result is guaranteed to have a cut value of at least |E|/2.

Self-loops never cross a cut (both endpoints are the same vertex).

ยงExamples

use rust_igraph::{Graph, maximum_cut, cut_value};

// Complete graph K4: max cut is 4 (partition {0,2} vs {1,3})
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(0, 3).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(1, 3).unwrap();
g.add_edge(2, 3).unwrap();
let result = maximum_cut(&g).unwrap();
assert!(result.cut_value >= 3); // at least |E|/2 = 3
assert_eq!(result.cut_value, cut_value(&g, &result.partition).unwrap());