is_maximal_matching#

is_maximal_matching(G, matching)[source]#

Return True if matching is a maximal matching of G

A maximal matching in a graph is a matching in which adding any edge would cause the set to no longer be a valid matching.

Parameters:
GNetworkX graph
matchingdict 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:
bool

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

Examples

>>> G = nx.Graph([(1, 2), (1, 3), (2, 3), (3, 4), (3, 5)])
>>> nx.is_maximal_matching(G, {(1, 2), (3, 4)})
True