1"""
2**************
3Graph Matching
4**************
5
6Given a graph G = (V,E), a matching M in G is a set of pairwise non-adjacent
7edges; that is, no two edges share a common vertex.
8
9`Wikipedia: Matching <https://en.wikipedia.org/wiki/Matching_(graph_theory)>`_
10"""
11
12import networkx as nx
13
14__all__ = ["min_maximal_matching"]
15
16
17@nx._dispatchable
18def min_maximal_matching(G):
19 r"""Returns the minimum maximal matching of G. That is, out of all maximal
20 matchings of the graph G, the smallest is returned.
21
22 Parameters
23 ----------
24 G : NetworkX graph
25 Undirected graph
26
27 Returns
28 -------
29 min_maximal_matching : set
30 Returns a set of edges such that no two edges share a common endpoint
31 and every edge not in the set shares some common endpoint in the set.
32 Cardinality will be 2*OPT in the worst case.
33
34 Notes
35 -----
36 The algorithm computes an approximate solution for the minimum maximal
37 cardinality matching problem. The solution is no more than 2 * OPT in size.
38 Runtime is $O(|E|)$.
39
40 References
41 ----------
42 .. [1] Vazirani, Vijay Approximation Algorithms (2001)
43 """
44 return nx.maximal_matching(G)