equitable_vertex_coloring

equitable_vertex_coloring#

graph_tool.structure.equitable_vertex_coloring(g, k=None, color=None)[git][source]#

Return an equitable vertex coloring with k colors.

Parameters:
gGraph

Graph to be used. Edge directions are ignored.

kint (optional, default: None)

Number of colors, which must be larger than the maximum degree \(\Delta\). If not given, \(k = \Delta + 1\) is used.

colorVertexPropertyMap (optional, default: None)

If given, the colors are stored in this property map, which must be of type int32_t.

Returns:
colorVertexPropertyMap

The color of every vertex, from \(0\) to \(k-1\).

See also

sequential_vertex_coloring

Greedy coloring in a given order

dsatur_vertex_coloring

Coloring with the DSatur heuristic

Notes

A coloring is equitable if adjacent vertices have different colors and the numbers of vertices with each color differ by at most one. The Hajnal–Szemerédi theorem guarantees that one exists for every \(k > \Delta\), and the algorithm of Kierstead, Kostochka, Mydlarz and Szemerédi [kierstead-fast-2010] finds it. The edges are added one at a time to an equitable coloring of the empty graph, and whenever an edge joins two vertices of the same color, the coloring is repaired by moving vertices between color classes. Self-loops and parallel edges are ignored, and a ValueError is raised if \(k \le \Delta\).

The time is \(O(kV^2)\) and the memory \(O(kV)\).

References

[kierstead-fast-2010]

Henry A. Kierstead, Alexandr V. Kostochka, Marcelo Mydlarz and Endre Szemerédi, “A fast algorithm for equitable coloring”, Combinatorica 30, 217-224 (2010), DOI: 10.1007/s00493-010-2483-5 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["football"]
>>> c = gt.equitable_vertex_coloring(g)
>>> print(c.a.max() + 1, np.bincount(c.a))
13 [9 9 9 9 9 9 9 9 9 9 9 8 8]

A square lattice has maximum degree \(\Delta = 4\), and hence is colored equitably with five colors, as shown in the figure below:

>>> g = gt.lattice([8, 8])
>>> c = gt.equitable_vertex_coloring(g)
>>> print(np.bincount(c.a))
[13 13 13 13 12]
>>> pos = g.new_vp("vector<double>",
...                vals=[(v % 8, v // 8) for v in g.get_vertices()])
>>> cmap = matplotlib.colors.ListedColormap(["#9bbedc", "#f28c8e",
...                                          "#a6d7a4", "#cba7d1",
...                                          "#ffbf80"])
>>> gt.graph_draw(g, pos, vertex_fill_color=c, vcmap=cmap,
...               output="equitable_vertex_coloring-lattice.pdf")
<...>
../_images/equitable_vertex_coloring-lattice.png

Equitable coloring of a \(8\times 8\) square lattice with five colors, which are used by 13, 13, 13, 13, and 12 vertices.#