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:
- g
Graph Graph to be used.
- weight
VertexPropertyMap(optional, default:None) Positive vertex weights. If not given, every vertex has unit weight.
- cover
VertexPropertyMap(optional, default:None) If provided, the vertices of the cover will be marked in this property map.
- g
- Returns:
- cover
VertexPropertyMap Boolean vertex property map marking the vertices of the cover.
- cover
See also
bipartite_vertex_coverExact minimum vertex cover of a bipartite graph
maximal_independent_vertex_setComplement of a vertex cover
minimum_edge_coverEdge counterpart
approx_minimum_dominating_setApproximate 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") <...>
Approximate minimum vertex cover of Zachary’s karate club network, with its vertices shown in red.#