dsatur_vertex_coloring

dsatur_vertex_coloring#

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

Return a vertex coloring obtained with the DSatur heuristic.

Parameters:
gGraph

Graph to be used. Edge directions are ignored.

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, numbered from zero.

See also

sequential_vertex_coloring

Greedy coloring in a given order

equitable_vertex_coloring

Coloring with color classes of nearly equal size

Notes

The coloring is proper, i.e. adjacent vertices receive different colors, and DSatur seeks one with few colors. The DSatur algorithm [brelaz-new-1979] colors next the uncolored vertex with the largest number of distinct colors among its neighbors (its saturation), with ties broken by the number of uncolored neighbors, and gives it the smallest color not used by its neighbors. It is exact for bipartite graphs and usually needs fewer colors than the static orders of sequential_vertex_coloring(). The time is \(O((V + E)\log V)\).

References

[brelaz-new-1979]

Daniel Brélaz, “New methods to color the vertices of a graph”, Communications of the ACM 22, 251-256 (1979), DOI: 10.1145/359094.359101 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["football"]
>>> c = gt.dsatur_vertex_coloring(g)
>>> print(c.a.max() + 1)
9

The coloring can be shown in a drawing of the network:

>>> palette = np.array(["#9bbedc", "#f28c8e", "#a6d7a4", "#cba6d1",
...                     "#ffbf7f", "#ffff99", "#d2aa93", "#fbc0df",
...                     "#cccccc"])
>>> vcolor = g.new_vp("string", vals=palette[c.a])
>>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=vcolor,
...               edge_color="#999999",
...               output="dsatur_vertex_coloring-football.pdf")
<...>
../_images/dsatur_vertex_coloring-football.png

Vertex coloring with nine colors of the network of American college football games obtained with DSatur.#