networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersRaisesReturns
to_vertex_cover(G, matching, top_nodes=None)

Notes

This function is implemented using the procedure guaranteed by :None:None:`Konig's theorem <https://en.wikipedia.org/wiki/K%C3%B6nig%27s_theorem_%28graph_theory%29>`, which proves an equivalence between a maximum matching and a minimum vertex cover in bipartite graphs.

Since a minimum vertex cover is the complement of a maximum independent set for any graph, one can compute the maximum independent set of a bipartite graph this way:

>>> G = nx.complete_bipartite_graph(2, 3)
>>> matching = nx.bipartite.maximum_matching(G)
>>> vertex_cover = nx.bipartite.to_vertex_cover(G, matching)
>>> independent_set = set(G) - vertex_cover
>>> print(list(independent_set))
[2, 3, 4]

See bipartite documentation <networkx.algorithms.bipartite> for further details on how bipartite graphs are handled in NetworkX.

Parameters

G : NetworkX graph

Undirected bipartite graph

matching : dictionary

A dictionary whose keys are vertices in G and whose values are the distinct neighbors comprising the maximum matching for G, as returned by, for example, maximum_matching . The dictionary must represent the maximum matching.

top_nodes : container

Container with all nodes in one bipartite node set. If not supplied it will be computed. But if more than one solution exists an exception will be raised.

Raises

AmbiguousSolution

Raised if the input bipartite graph is disconnected and no container with all nodes in one bipartite set is provided. When determining the nodes in each bipartite set more than one valid solution is possible if the input graph is disconnected.

Returns

vertex_cover : :class:`set`

The minimum vertex cover in G.

Returns the minimum vertex cover corresponding to the given maximum matching of the bipartite graph G.

Examples

See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/bipartite/matching.py#415
type: <class 'function'>
Commit: