pub fn louvain_weighted(
graph: &Graph,
weights: &[f64],
) -> IgraphResult<LouvainResult>Expand description
Run Louvain with per-edge weights (γ = 1, deterministic seed 0).
§Errors
IgraphError::Unsupportedifgraphis directed.IgraphError::InvalidArgumentifweights.len() != ecountor any weight is negative or NaN.
§Examples
use rust_igraph::{Graph, louvain_weighted};
// Two K3s + bridge. Heavy intra-clique weights vs a thin bridge:
// Louvain splits the two triangles.
let mut g = Graph::with_vertices(6);
for &(u, v) in &[(0, 1), (0, 2), (1, 2), (3, 4), (3, 5), (4, 5), (2, 3)] {
g.add_edge(u, v).unwrap();
}
let weights = vec![10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 0.01];
let r = louvain_weighted(&g, &weights).unwrap();
assert_eq!(r.membership[0], r.membership[1]);
assert_ne!(r.membership[0], r.membership[3]);