Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

networkx.algorithms.matching.is_matching

is_matching(G, matching)[source]

Decides whether the given set or dictionary represents a valid matching in G.

A matching in a graph is a set of edges in which no two distinct edges share a common endpoint.

Parameters:
  • G (NetworkX graph)
  • matching (dict or set) – A dictionary or set representing a matching. If a dictionary, it must have matching[u] == v and matching[v] == u for each edge (u, v) in the matching. If a set, it must have elements of the form (u, v), where (u, v) is an edge in the matching.
Returns:

Whether the given set or dictionary represents a valid matching in the graph.

Return type:

bool