KM Algorithm Solving the Maximum Weight Assignment Problem of Bipartite Graph

Both the Hungarian algorithm and the KM algorithm can be used to solve the task allocation problem (also known as the assignment problem): Assuming there are n employees and n jobs, one person can only complete one task and the tasks that can be completed are different. Ask how to arrange employees to maximize efficiency.

Use the vernacular to describe the bipartite graph: the bipartite graph can be divided into two sets {employee} and {job}, the elements between the two sets can be connected, and the elements in the same set cannot be connected.

The bipartite graph matching problem as shown in the figure can be solved by the Hungarian algorithm.

Now let's think about another question: in the above figure, we assume that the work efficiency of A, B, and C is the same (that is, the time for A or B to complete work a is equal), which is only a minority in real life. So if employees A, B, and C have different efficiencies in completing different tasks, how should they get the optimal match?

The KM algorithm is used to solve the problem of the maximum weight distribution of the bipartite graph, and its steps are as follows:

① The vertex on the left is assigned the maximum weight, and the vertex on the right is assigned 0.

 ② match. The principle of matching is to match only the edges equal to the maximum efficiency. If the matching fails, the values ​​of all left vertices participating in the matching are -1, and the right vertices are +1 until the matching is completed.

According to this convention, we match A: connect Ac, the match is successful!

Next we match the B employees. But we found that only Bc is the edge that matches B with maximum efficiency, and c has already been matched with A. What should we do? The normal way of thinking is to see if A has any other matching sides, but unfortunately there is none. According to the principle of matching, the efficiency of A and B needs to be -1, and that of c+1. In this way, the efficiency of A is updated to 3, the efficiency of B is updated to 2, and the value of c becomes 1.

Through -1 and +1 operations, Ac and Bc are still sides that can be matched: 3+1=4, 2+1=3. In addition, it also brings us new choices: Aa and Ba.

In this way, B can find a job without changing A's job. The match is successful!

 Now let's match C. Since 5+1≠5, and c already matches A. So we find A to see if A has any other options. We found that A can match with c (3+1=4), and can also match with a (3+0=3). When I was trying to match Aa, I found that a has already been matched with B. So we find B and see if there are any other matching matches for B. But at this time, B said that his ability is limited, and he can't help it. He can only match with A. Then the nodes involved in this "dispute" are: A, B, C, a, c, which are handed over to the matching principle for "disposition".

(This step is a bit of a nesting doll, and it is not difficult to understand the principle.)

Update the values ​​as shown in the figure:

For now, B can match! (1+0=1)

The final match can be obtained by the negation operation of the Hungarian algorithm (explained below).

 

 This is the whole process of the KM algorithm. Every time a vertex is found with the maximum weight edge , it cooperates with the Hungarian algorithm to find the maximum match , so as to obtain a perfect match .

The Hungarian algorithm handles the "collision problem":

On the premise that Aa has been successfully matched, if B can only match a, then the Hungarian algorithm tells us that we can pass an augmented path , and we can match more points through the inversion operation.

The definition of an augmented path: starting from an unmatched vertex, passing through several matching vertices, and finally reaching an unmatched vertex in the opposite set, that is to say, this path combines two unmatched vertices in two different sets Connected by a series of matching vertices.

In this question, A can also match with c, resulting in an augmented path: B--a--A--c. After the inversion operation, the matching is updated to:

 From this round of operation, a matching edge is added to resolve the contradiction. This is the ingenuity of the inversion of the augmented path of the Hungarian algorithm!

 We can find the augmenting path when there is a conflict, so as to find the optimal match.

Reference article: Getting Started with KM Algorithm - logosG - 博客园

Guess you like

Origin blog.csdn.net/m0_64007201/article/details/127457750