Skip to main content

louvain_with_options

Function louvain_with_options 

Source
pub fn louvain_with_options(
    graph: &Graph,
    weights: Option<&[f64]>,
    resolution: f64,
    seed: u64,
) -> IgraphResult<LouvainResult>
Expand description

Run Louvain with the full set of options.

  • weights: per-edge weights or None for unit weights. Must be non-negative and not NaN.
  • resolution: γ ≥ 0. Lower values produce fewer, larger communities; higher values produce more, smaller communities. γ = 1 recovers the classical Newman-Girvan modularity.
  • seed: PRNG seed for the node-order shuffle. Same seed produces the same partition on the same graph.

§Errors

§Examples

use rust_igraph::{Graph, louvain_with_options};

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();
}
// Determinism: same seed reproduces the same partition bit-for-bit.
let a = louvain_with_options(&g, None, 1.0, 42).unwrap();
let b = louvain_with_options(&g, None, 1.0, 42).unwrap();
assert_eq!(a.membership, b.membership);