Given G = (V, E) and a matching M of G, a vertex v is exposed if no edge of M is incident with v. A path in G is an alternating path, if its edges are alternately not in M and in M (or in M and not in M). An augmenting path P is an alternating path that starts and ends at two distinct exposed vertices. Note that the number of unmatched edges in an augmenting path is greater by one than the number of matched edges, and hence the total number of edges in an augmenting path is odd. A matching augmentation along an augmenting path P is the operation of replacing M with a new matching
By Berge's lemma, matching M is maximum if and only if there is no M-augmenting path in G.67 Hence, either a matching is maximum, or it can be augmented. Thus, starting from an initial matching, we can compute a maximum matching by augmenting the current matching with augmenting paths as long as we can find them, and return whenever no augmenting paths are left. We can formalize the algorithm as follows:
We still have to describe how augmenting paths can be found efficiently. The subroutine to find them uses blossoms and contractions.
Given G = (V, E) and a matching M of G, a blossom B is a cycle in G consisting of 2k + 1 edges of which exactly k belong to M, and where one of the vertices v of the cycle (the base) is such that there exists an alternating path of even length (the stem) from v to an exposed vertex w.
Finding Blossoms:
Define the contracted graph G' as the graph obtained from G by contracting every edge of B, and define the contracted matching M' as the matching of G' corresponding to M.
G' has an M'-augmenting path if and only if G has an M-augmenting path, and that any M'-augmenting path P' in G' can be lifted to an M-augmenting path in G by undoing the contraction by B so that the segment of P' (if any) traversing through vB is replaced by an appropriate segment traversing through B.8 In more detail:
Thus blossoms can be contracted and search performed in the contracted graphs. This reduction is at the heart of Edmonds' algorithm.
The search for an augmenting path uses an auxiliary data structure consisting of a forest F whose individual trees correspond to specific portions of the graph G. In fact, the forest F is the same that would be used to find maximum matchings in bipartite graphs (without need for shrinking blossoms). In each iteration the algorithm either (1) finds an augmenting path, (2) finds a blossom and recurses onto the corresponding contracted graph, or (3) concludes there are no augmenting paths. The auxiliary structure is built by an incremental procedure discussed next.9
The construction procedure considers vertices v and edges e in G and incrementally updates F as appropriate. If v is in a tree T of the forest, we let root(v) denote the root of T. If both u and v are in the same tree T in F, we let distance(u,v) denote the length of the unique path from u to v in T.
The following four figures illustrate the execution of the algorithm. Dashed lines indicate edges that are currently not present in the forest. First, the algorithm processes an out-of-forest edge that causes the expansion of the current forest (lines B10 – B12).
Next, it detects a blossom and contracts the graph (lines B20 – B21).
Finally, it locates an augmenting path P′ in the contracted graph (line B22) and lifts it to the original graph (line B23). Note that the ability of the algorithm to contract blossoms is crucial here; the algorithm cannot find P in the original graph directly because only out-of-forest edges between vertices at even distances from the roots are considered on line B17 of the algorithm.
The forest F constructed by the find_augmenting_path() function is an alternating forest.10
Each iteration of the loop starting at line B09 either adds to a tree T in F (line B10) or finds an augmenting path (line B17) or finds a blossom (line B20). It is easy to see that the running time is O ( | E | | V | 2 ) {\displaystyle O(|E||V|^{2})} .
When G is bipartite, there are no odd cycles in G. In that case, blossoms will never be found and one can simply remove lines B20 – B24 of the algorithm. The algorithm thus reduces to the standard algorithm to construct maximum cardinality matchings in bipartite graphs11 where we repeatedly search for an augmenting path by a simple graph traversal: this is for instance the case of the Ford–Fulkerson algorithm.
The matching problem can be generalized by assigning weights to edges in G and asking for a set M that produces a matching of maximum (minimum) total weight: this is the maximum weight matching problem. This problem can be solved by a combinatorial algorithm that uses the unweighted Edmonds's algorithm as a subroutine.12 Kolmogorov provides an efficient C++ implementation of this.13
Edmonds, Jack (1991), "A glimpse of heaven", in J.K. Lenstra; A.H.G. Rinnooy Kan; A. Schrijver (eds.), History of Mathematical Programming --- A Collection of Personal Reminiscences, CWI, Amsterdam and North-Holland, Amsterdam, pp. 32–54 ↩
Edmonds, Jack (1965). "Paths, trees, and flowers". Can. J. Math. 17: 449–467. doi:10.4153/CJM-1965-045-4. https://doi.org/10.4153%2FCJM-1965-045-4 ↩
Micali, Silvio; Vazirani, Vijay (1980). An O(V1/2E) algorithm for finding maximum matching in general graphs. 21st Annual Symposium on Foundations of Computer Science. IEEE Computer Society Press, New York. pp. 17–27. ↩
Edmonds, Jack (1965). "Maximum matching and a polyhedron with 0,1-vertices". Journal of Research of the National Bureau of Standards Section B. 69: 125–130. doi:10.6028/jres.069B.013. https://doi.org/10.6028%2Fjres.069B.013 ↩
Schrijver, Alexander (2003). Combinatorial Optimization: Polyhedra and Efficiency. Algorithms and Combinatorics. Berlin Heidelberg: Springer-Verlag. ISBN 9783540443896. 9783540443896 ↩
Lovász, László; Plummer, Michael (1986). Matching Theory. Akadémiai Kiadó. ISBN 963-05-4168-8. 963-05-4168-8 ↩
Karp, Richard, "Edmonds's Non-Bipartite Matching Algorithm", Course Notes. U. C. Berkeley (PDF), archived from the original (PDF) on 2008-12-30 https://web.archive.org/web/20081230183603/http://www.cs.berkeley.edu/~karp/greatalgo/lecture05.pdf ↩
Tarjan, Robert, "Sketchy Notes on Edmonds' Incredible Shrinking Blossom Algorithm for General Matching", Course Notes, Department of Computer Science, Princeton University (PDF) http://www.cs.dartmouth.edu/~ac/Teach/CS105-Winter05/Handouts/tarjan-blossom.pdf ↩
Kenyon, Claire; Lovász, László, "Algorithmic Discrete Mathematics", Technical Report CS-TR-251-90, Department of Computer Science, Princeton University /wiki/L%C3%A1szl%C3%B3_Lov%C3%A1sz ↩
Kolmogorov, Vladimir (2009), "Blossom V: A new implementation of a minimum cost perfect matching algorithm", Mathematical Programming Computation, 1 (1): 43–67, doi:10.1007/s12532-009-0002-8 http://pub.ist.ac.at/~vnk/papers/BLOSSOM5.html ↩