pub fn fast_greedy_modularity(graph: &Graph) -> IgraphResult<FastGreedyResult>Expand description
Run fast greedy modularity community detection on graph (unweighted).
§Errors
IgraphError::Unsupportedifgraph.is_directed().IgraphError::InvalidArgumentif the graph has multi-edges.
§Examples
use rust_igraph::{Graph, fast_greedy_modularity};
// Two K5 cliques joined by a single bridge edge (0,5).
let mut g = Graph::with_vertices(10);
for &(u, v) in &[
(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4),
(2, 3), (2, 4), (3, 4),
(5, 6), (5, 7), (5, 8), (5, 9), (6, 7), (6, 8), (6, 9),
(7, 8), (7, 9), (8, 9),
(0, 5),
] {
g.add_edge(u, v).unwrap();
}
let r = fast_greedy_modularity(&g).unwrap();
assert_eq!(r.nb_clusters, 2);
assert!((r.modularity.iter().copied().fold(f64::NEG_INFINITY, f64::max) - 0.452_381).abs() < 1e-5);