Skip to main content

cut_size

Function cut_size 

Source
pub fn cut_size(
    graph: &Graph,
    membership: &[u32],
    weights: Option<&[f64]>,
) -> IgraphResult<f64>
Expand description

Compute the cut size of a partition.

Counts the number of edges (or sum of edge weights) that cross between different clusters.

§Parameters

  • graph — The input graph.
  • membership — Cluster assignment for each vertex (membership[v] is the cluster id of vertex v). Length must equal vcount.
  • weights — Optional edge weights. If None, each edge has weight 1.

§Examples

use rust_igraph::{Graph, cut_size};

let g = Graph::from_edges(&[(0,1),(1,2),(2,3)], false, Some(4)).unwrap();
// Partition: {0,1} vs {2,3}
let membership = vec![0u32, 0, 1, 1];
let cs = cut_size(&g, &membership, None).unwrap();
assert!((cs - 1.0).abs() < 1e-10); // only edge 1-2 crosses