The KM algorithm converts the question of finding the maximum weight matching to the question of finding a complete match by giving each vertex a label (called the top mark.
Set vertex XI to a [I], vertex Yi to B [I], and edge weight between vertex XI and YJ to W [I, j].
A [I] + B [J]> = W [I, j] is always valid for any edge (I, j) during Algorithm Execution. The correctness of the KM algorithm is based on the following theorem:
If all the sub-graphs that meet the requirements of a [I] + B [J] = W [I, j] (I, j) are calledEqual subgraph (concept is important)) If there is a complete match, then this complete match is the maximum weight match of the Bipartite Graph.
This theorem is clear. For any matching of a bipartite graph, if it is contained in an equal subgraph, its edge weight is equal to the top mark of all vertices (obviously this is the largest ); if some of its edges do not contain an equal subgraph, its edge weight is smaller than the sum of the top labels of all vertices. Therefore, the full match of an equal subgraph must be the maximum weight match of a bipartite graph.
In the initial stage, to make a [I] + B [J]> = W [I, j] Always stand, make a [I] the maximum weight of all edges associated with vertex XI. B [J] = 0. If the current equality subgraph does not have a complete match, modify the top mark as follows to expand the equality subgraph until the equality subgraph has a complete match.
We fail to find the complete matching of the current equi-th subgraph because we cannot find an staggered path starting from an X vertex. Then we gotStaggered tree (concept is important)All of its leaf nodes are X vertices. Now, we can reduce all the top labels of X vertices in the staggered tree to a certain value D, and all the top labels of Y vertices Add the same value D. Then we will find that:
1. The value of the edge (I, j) and a [I] + B [J] In the staggered tree does not change. That is to say, it originally belongs to an equal subgraph and still belongs to an equal subgraph.
2. The two ends are not in the edge (I, j) of the staggered tree, And neither a [I] nor B [J] is changed. That is to say, it originally belongs to (or does not belong to) equal subgraph, And now it still belongs to (or does not belong to) equal subgraph. (Meaning, for the entire graph, if it does not belong to an equal subgraph, it does not belong to an equal subgraph. If it belongs to an equal subgraph, it also belongs to an equal subgraph because it remains unchanged)
3. The X end is not in the staggered tree, and the Y end is in the edge (I, j) of the staggered tree. The value of a [I] + B [J] increases. It does not belong to an equal subgraph and does not belong to an equal subgraph. D should be equal to min {A [I] + B [J]-W [I, j] | Xi is in the staggered tree, Yi is not in the staggered tree }.
A simple example:
K5 is known, and the weight matrix of 5 is
Y1 Y2 Y3 Y4 Y5
X1 3 5 5 4 1
X2 2 2 0 2 2
X3 2 4 4 1 0
X4 0 1 1 0 0
X5 1 2 1 3 3
Initialization: the top part of K5 and 5 is divided into x = {Xi}, y = {Yi}, I = 1, 2, 4, 5.
(1) take the feasible top Mark L (V) as L (yi) = 0, I =, 5; L (X1) = max, 1} = 5, L (X2) = max {, 2} = 2, L (X3) = max (, 0} = 4, L (X4) = max {, 0} = 1, L (X5) = max {, 3} = 3.
(2) See Figure 7.12.
In this figure, lift (G-x2) = 3, which is known by the Tutte theorem that there is no complete match. You need to modify the top mark.
Tutte theorem: A graph G has a complete match. The necessary condition is that for any point set in the graph U, after removing U, the number of connected components (recorded as O (G-U) with an odd number of vertices does not exceed the number of vertices in U.
When u = {X2} in an equal subgraph is removed, there are three connected components {y1}, {x1, X3, X4, Y2, Y3}, {X5, Y4, y5}, are an odd number of vertices, so O (G-x2) = 3, larger than the number of vertices in u 1. Therefore, the equality subgraph does not have a complete match.
(3) Search for the staggered tree. For X4, the staggered tree has: x1-y2-x4 and x1-y2-x3-y3-x4. D is the X set (, 4) in the staggered tree and the Y set (, 5) that is not in the staggered tree) to the minimum value of LX [I] + ly [J]-map [I] [J. The value is 1. then, the top labels of x1, x2, X3, X4, and X5 are changed to 4, 2, 3, 0, 3, Y1, Y2, Y3, Y4, and Y5 respectively to 0, 1, 1, 0, 0.
After modification, it is found that the edges that can enter an equal subgraph are (x1, Y4), (X4, Y1), (X4, Y4), (X4, Y5)
Then we continue to look for the staggered tree based on the previous step. We can find that the staggered tree has many situations:
1. x4-y4
2. x4-y5
3. x4-y1-x2-y4
4. x4-y2-x1-y4
In this way, we find the complete match:
1. x1-y2, x2-y1, x3-y3, x4-y4.
2. x1-y2, x2-y1, x3-y3, x4-y5.
3. x1-y2, x2-y4, x3-y3, x4-y1, x5-y5.
4. x1-y4, x2-y1, x3-y3, x4-y2.
The maximum values are:
1.5 + 2 + 4 + 0 + 3 = 14
2.5 + 2 + 4 + 0 + 3 = 14
3.5 + 2 + 4 + 0 + 3 = 14
4.4 + 2 + 4 + 1 + 3 = 14
(4) use the modified top Mark L to get GL and a complete match 7.13 (fourth case) above it ). The rough line in the figure provides an optimal match. The maximum weight is 4 + 2 + 4 + 1 + 3 = 14.
The above is the basic idea of the KM algorithm. However, in a simple implementation method, the time complexity is O (n4). You need to find the O (n) Increment path, and you need to modify the O (n) Increment path at most, each time you modify the top tag, the complexity is O (n2) because the enumeration edge is required to evaluate the D value ).
In fact, the complexity of the KM algorithm can be O (N3. Each y vertex is given a "relaxation amount" function slack, Which is initialized to an infinite number every time the augmented path is searched. When you check the edge (I, j) in the process of searching for the augmented path, if itNot equal subgraph, The slack [J] is changed to a smaller value of the original value and a [I] + B [J]-W [I, j. In this way, allY vertex not in the staggered treeThe minimum value of the slack value is the D value. Note that after the top mark is modified, all slack values must be subtracted from D. (The reason behind else is that Lx [I] becomes D and slack [J] = min {lx [I] + ly [J]-W [I] [J]} Is that slack [J] (j does not belong to T) d)