Returns the maximum cardinality matching of the bipartite graph
- G (NetworkX graph) – Undirected bipartite graph
- 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.
matches – The matching is returned as a dictionary,
matching, such that
matching[v] == wif node
vis matched to node
w. Unmatched nodes do not occur as a key in mate.
AmbiguousSolution : Exception – 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.
This function is implemented with David Eppstein’s version of the algorithm Hopcroft–Karp algorithm (see
hopcroft_karp_matching()), which originally appeared in the Python Algorithms and Data Structures library (PADS).
bipartite documentationfor further details on how bipartite graphs are handled in NetworkX.