Note: Hungarian algorithm for maximum matching of bipartite graphs

Bipartite graph maximum matching problem

definition

FIG provided two simple \ (G = <A, B , E>, M \ subset E, \) if \ (M \) any two adjacent sides are not said to \ (M \) is \ ( G \) of matching . When \ (M \) has the most edges, \ (M \) is called the maximum match . When \ (| A | = | B | = n \) , the matching with the number of edges \ (n \) is called perfect matching .

Related concepts

Staggered path and augmented staggered path

Set \ (M \) is bipartite \ (G \) of a match, called \ (M \) in the side of the matching edges , \ (G \) does not belong to \ (M \) side is non- Matching edges , the vertices associated with matching edges are saturation points . The path composed of matching edges and non-matching edges alternately in \ (G \) is called the interlaced path , and the interlaced path whose starting point and focus are all unsaturated vertices is called the augmented interlaced path .

Lemma 1

Let \ (M \) be a match of bipartite graph \ (G \) , \ (P \) is an augmented staggered path about \ (M \) , then \ (M '= M \ bigoplus E (P ) \) (Symmetric difference from the original match) is a match, and \ (| M '| = | M | +1 \) , where \ (E (P) \) is the set of edges of \ (P \) .

Theorem 1

The matching of the bipartite graph is the maximum matching if and only if there is no augmented interleaved path about it.

Hungarian algorithm

Basic idea

(1). Starting from the initial match \ (M \) , find an augmented interlaced path about it \ (P \)

(2).令\(M\leftarrow M\bigoplus E(P)\)

(3). Check if there is an augmented staggered path \ (P \) about \ (M \) , if it does not exist, the algorithm ends. Otherwise, go to (2).

Implementation: Labeling

1. Set the current match to \ (M \) , add a label to each unsaturated point \ (A_i \) in \ (A \) \ (l (A_i) = 0 \) , \ (A_i \) is labeled But unchecked points.

2. For any labeled but unchecked vertex \ (A_i \) , label all adjacent but unlabeled vertices \ (B_j \) as \ (l (B_j) = A_i \) .

3. If \ (B_j \) is an unsaturated point, find an augmented staggered path, modify the match, and restart the labeling.

4. If \ (B_j \) is the saturation point, then set \ ((A_k, B_j) \ in M ​​\) , and make \ (l (A_k) = B_j \) , then \ (A_k \) becomes labeled unchecked Vertex, \ (A_i \) becomes the vertex whose label has been checked.

5. Repeat the algorithm until there are no unchecked vertices in \ (A \) .

Hungarian algorithm complexity analysis

Set up a bipartite graph \ (G = <A, B, E> \) . At each stage of the Hungarian algorithm, if you find the augmented staggered path \ (P \) , let \ (M \ leftarrow M \ bigoplus E (P) \) . For the initial state, \ (M = \ emptyset \) is \ ( G \) . When the calculation is terminated, there is no augmented interleaved path.

In addition to the final stage of the algorithm, each stage of the algorithm adds a matching edge, the total number of matching edges is \ (\ min \ {| A |, | B | \} \) , so there is at most \ (\ min \ {| A | , | B | \} + 1 \) stages, in each labeling stage, each edge is checked at most once, the length of the augmented interleaved path does not exceed \ (2 | M | +1 \) , so each stage It will be done in \ (O (| E |) \) . Therefore, the whole algorithm is aborted in the \ (O (\ min \ {| A |, | B | \} \ times E) \) step.

Guess you like

Origin www.cnblogs.com/allegro-vivace/p/12693264.html