bipartite_vertex_cover#
- graph_tool.structure.bipartite_vertex_cover(g, partition=None)[git][source]#
Return a minimum vertex cover of a bipartite graph.
- Parameters:
- g
Graph Bipartite graph. Edge directions are ignored.
- partition
VertexPropertyMap(optional, default:None) Boolean partition of the vertices. If not given, it is computed with
is_bipartite().
- g
- Returns:
- cover
VertexPropertyMap Boolean vertex property map marking the vertices of the cover.
- cover
See also
approx_minimum_vertex_coverApproximate minimum vertex cover
maximum_cardinality_matchingMaximum matching, as large as the cover
is_bipartiteTest for bipartite graphs
Notes
By König’s theorem [konig-grafok-1931], the size of a minimum vertex cover of a bipartite graph equals that of a maximum matching. From a maximum matching (see
maximum_cardinality_matching()), the vertices \(Z\) reachable from the unmatched vertices of the first side \(L\) by alternating paths (whose edges alternate between unmatched and matched ones) are found, and the cover is \((L \setminus Z) \cup (R \cap Z)\), where \(R\) is the second side. The time is dominated by the matching. Minimum vertex covers of general graphs are NP-hard; an approximation is given byapprox_minimum_vertex_cover().References
[konig-grafok-1931]Dénes Kőnig, “Gráfok és mátrixok”, Matematikai és Fizikai Lapok 38, 116-119 (1931).
Examples
>>> g = gt.Graph([(0, 3), (0, 4), (1, 3), (2, 4), (2, 5)], directed=False) >>> c = gt.bipartite_vertex_cover(g) >>> print(c.a.sum(), gt.maximum_cardinality_matching(g, edges=True).a.sum()) 3 3