Ask Your Question

Revision history [back]

You can ask for a maximal matching and see if its size correspond to half the size of the bipartite graph:

You can get a maximal matching as follows:

sage: n = 10
sage: G = graphs.RandomBipartite(n,n,0.5)
sage: G.matching()
[((0, 1), (1, 0), None),
 ((0, 6), (1, 7), None),
 ((0, 4), (1, 4), None),
 ((0, 7), (1, 8), None),
 ((0, 9), (1, 9), None),
 ((0, 0), (1, 2), None),
 ((0, 5), (1, 6), None),
 ((0, 3), (1, 1), None),
 ((0, 8), (1, 5), None),
 ((0, 2), (1, 3), None)]

You can check that a maximal matching is complete as follows:

sage: len(G.matching()) == n
True

or as follows:

sage: G.matching(value_only=True) == n
True