def is_maximal_matching(G, matching):
 if isinstance(matching, dict):
  matching = matching_dict_to_set(matching)
 if (not is_matching(G, matching)):
  return False
 all_edges = set(map(frozenset, G.edges()))
 matched_edges = set(map(frozenset, matching))
 unmatched_edges = (all_edges - matched_edges)
 return all(((not is_matching(G, (matching | {e}))) for e in unmatched_edges))

def is_maximal_matching ( G , matching ) : if isinstance ( matching , dict ) : matching = matching_dict_to_set ( matching ) if ( not is_matching ( G , matching ) ) : return False all_edges = set ( map ( frozenset , G . edges ( ) ) ) matched_edges = set ( map ( frozenset , matching ) ) unmatched_edges = ( all_edges - matched_edges ) return all ( ( ( not is_matching ( G , ( matching | { e } ) ) ) for e in unmatched_edges ) )
decides whether the given set or dictionary represents a valid maximal matching in g .