approx_minimum_vertex_cover

approx_minimum_vertex_cover#

graph_tool.structure.approx_minimum_vertex_cover(g, weight=None, cover=None)[git][source]#

Return an approximate minimum (weighted) vertex cover.

Parameters:
gGraph

Graph to be used.

weightVertexPropertyMap (optional, default: None)

Positive vertex weights. If not given, every vertex has unit weight.

coverVertexPropertyMap (optional, default: None)

If provided, the vertices of the cover will be marked in this property map.

Returns:
coverVertexPropertyMap

Boolean vertex property map marking the vertices of the cover.

See also

bipartite_vertex_cover

Exact minimum vertex cover of a bipartite graph

maximal_independent_vertex_set

Complement of a vertex cover

minimum_edge_cover

Edge counterpart

approx_minimum_dominating_set

Approximate minimum dominating set

Notes

A vertex cover contains at least one endpoint of every edge. Finding one of minimum weight is NP-hard, and the local-ratio algorithm of Bar-Yehuda and Even [bar-yehuda-linear-1981] is used, whose total weight is at most twice the minimum: for every edge, the residual weights of both endpoints are lowered by the smaller of them, and the vertices whose residual weight reaches zero form the cover. The algorithm runs in time \(O(V + E)\).

References

[bar-yehuda-linear-1981]

Reuven Bar-Yehuda and Shimon Even, “A linear-time approximation algorithm for the weighted vertex cover problem”, Journal of Algorithms 2, 198-203 (1981), DOI: 10.1016/0196-6774(81)90020-1 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["karate"]
>>> c = gt.approx_minimum_vertex_cover(g)
>>> print(c.fa.sum())
22

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

>>> vcolor = g.new_vp("string", vals=np.where(c.a, "#f28c8e", "#cccccc"))
>>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=vcolor,
...               edge_color="#999999",
...               output="approx_minimum_vertex_cover-karate.pdf")
<...>
../_images/approx_minimum_vertex_cover-karate.png

Approximate minimum vertex cover of Zachary’s karate club network, with its vertices shown in red.#