aryagraph.algorithms.community.girvan_newman#

aryagraph.algorithms.community.girvan_newman(g: Any, most_valuable_edge: Callable[[Any], tuple[Hashable, Hashable]] | None = None) → Iterator[list[set]][source]#

Divisive communities (Girvan & Newman 2002): yield a finer partition at each split.

Works on an undirected copy without self-loops, repeatedly deleting the edge of highest betweenness (first in edge order on ties, as networkx) until the number of components grows, then yielding the components. most_valuable_edge(graph) -> (u, v) replaces the betweenness rule. Each split costs O(n·m) per removed edge, so this suits small graphs.

>>> from itertools import islice
>>> first_split = next(girvan_newman(g))