approx_minimum_maximal_matching

approx_minimum_maximal_matching#

graph_tool.structure.approx_minimum_maximal_matching(g)[git][source]#

Return a maximal matching, which approximates the minimum maximal matching within a factor two.

Parameters:
gGraph

Graph to be used. Edge directions are ignored.

Returns:
matchingEdgePropertyMap

Boolean edge property map marking the edges of the matching.

See also

maximum_cardinality_matching

Maximum matching

approx_minimum_edge_dominating_set

Approximate minimum edge dominating set

Notes

A matching is a set of edges no two of which share an endpoint, and it is maximal if no other edge can be added to it, i.e. if every edge shares an endpoint with an edge of the matching. A minimum maximal matching is a maximal matching with the fewest edges. Any maximal matching has at most twice as many edges as a minimum maximal matching (which is NP-hard to find), and the same holds for the minimum edge dominating set (see approx_minimum_edge_dominating_set()) [yannakakis-edge-1980]. A maximum matching (see maximum_cardinality_matching()) is used, which is maximal.

References

[yannakakis-edge-1980]

Mihalis Yannakakis and Fanica Gavril, “Edge dominating sets in graphs”, SIAM Journal on Applied Mathematics 38, 364-372 (1980), DOI: 10.1137/0138030 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["karate"]
>>> print(gt.approx_minimum_maximal_matching(g).a.sum())
13

The matching can be highlighted in a drawing of the network:

>>> m = gt.approx_minimum_maximal_matching(g)
>>> ecolor = g.new_ep("string", vals=np.where(m.a, "#e41a1c", "#999999"))
>>> ewidth = g.new_ep("double", vals=np.where(m.a, 2.5, 1))
>>> gt.graph_draw(g, g.vp.pos, vertex_fill_color="#cccccc",
...               edge_color=ecolor, edge_pen_width=ewidth,
...               output="approx_minimum_maximal_matching-karate.pdf")
<...>
../_images/approx_minimum_maximal_matching-karate.png

Maximal matching of Zachary’s karate club network, with its edges shown in red.#