networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersRaisesReturns
kernighan_lin_bisection(G, partition=None, max_iter=10, weight='weight', seed=None)

This algorithm partitions a network into two sets by iteratively swapping pairs of nodes to reduce the edge cut between the two sets. The pairs are chosen according to a modified form of Kernighan-Lin, which moves node individually, alternating between sides to keep the bisection balanced.

Parameters

G : graph
partition : tuple

Pair of iterables containing an initial partition. If not specified, a random balanced partition is used.

max_iter : int

Maximum number of times to attempt swaps to find an improvemement before giving up.

weight : key

Edge data key to use as weight. If None, the weights are all set to one.

seed : integer, random_state, or None (default)

Indicator of random number generation state. See Randomness<randomness> . Only used if partition is None

Raises

NetworkXError

If partition is not a valid partition of the nodes of the graph.

Returns

partition : tuple

A pair of sets of nodes representing the bipartition.

Partition a graph into two blocks using the Kernighan–Lin algorithm.

Examples

See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/community/kernighan_lin.py#42
type: <class 'function'>
Commit: