edge_coloring

Contents

edge_coloring#

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

Return a proper edge coloring of a simple undirected graph.

Parameters:
gGraph

Simple undirected graph to be used.

colorEdgePropertyMap (optional, default: None)

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

Returns:
colorEdgePropertyMap

The color of every edge, numbered from zero.

See also

sequential_vertex_coloring

Vertex coloring

maximum_cardinality_matching

Maximum matching

graph_tool.generation.line_graph

Line graph of a graph

Notes

In a proper edge coloring, the edges incident on the same vertex have distinct colors. The coloring uses at most \(\Delta + 1\) colors, where \(\Delta\) is the largest degree, as guaranteed by Vizing’s theorem, and is found with the algorithm of Misra and Gries [misra-constructive-1992], in time \(O(VE)\).

References

[misra-constructive-1992]

Jayadev Misra and David Gries, “A constructive proof of Vizing’s theorem”, Information Processing Letters 41, 131-133 (1992), DOI: 10.1016/0020-0190(92)90041-S [sci-hub, @tor]

Examples

>>> g = gt.collection.data["karate"]
>>> c = gt.edge_coloring(g)
>>> print(c.fa.max() + 1, g.get_total_degrees(g.get_vertices()).max())
17 17

The Petersen graph has maximum degree three, and its edges are colored with four colors:

>>> g = gt.collection.petersen_graph()
>>> c = gt.edge_coloring(g)
>>> print(c.fa.max() + 1)
4
>>> a = np.pi / 2 + 2 * np.pi * np.arange(5) / 5
>>> pos = g.new_vp("vector<double>",
...                vals=list(zip(np.cos(a), -np.sin(a))) +
...                     list(zip(.5 * np.cos(a), -.5 * np.sin(a))))
>>> palette = np.array(["#e41a1c", "#377eb8", "#4daf4a", "#984ea3"])
>>> ecolor = g.new_ep("string", vals=palette[c.a])
>>> gt.graph_draw(g, pos, vertex_fill_color="#cccccc", edge_color=ecolor,
...               vertex_size=30, edge_pen_width=3,
...               output="edge_coloring-petersen.pdf")
<...>
../_images/edge_coloring-petersen.png

Proper edge coloring of the Petersen graph with four colors.#