networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersRaisesReturnsBackRef
equitable_color(G, num_colors)

Attempts to color a graph using r colors, where no neighbors of a node can have same color as the node itself and the number of nodes with each color differ by at most 1.

Parameters

G : networkX graph

The nodes of this graph will be colored.

num_colors : number of colors to use

This number must be at least one more than the maximum degree of nodes in the graph.

Raises

NetworkXAlgorithmError

If the maximum degree of the graph G is greater than num_colors .

Returns

A dictionary with keys representing nodes and values representing
corresponding coloring.

Provides equitable (r + 1)-coloring for nodes of G in O(r * n^2) time if deg(G) <= r. The algorithm is described in .

Examples

>>> G = nx.cycle_graph(4)
... d = nx.coloring.equitable_color(G, num_colors=3)
... nx.algorithms.coloring.equitable_coloring.is_equitable(G, d) True
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.coloring.equitable_coloring.equitable_color

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/coloring/equitable_coloring.py#396
type: <class 'function'>
Commit: