Question about the (weight) Matching of bipartite graphs

Source: Internet
Author: User

// ********************************* The following is a reprinted *** ****************************************

Bipartite Graph Matching Algorithm Summary

Hungarian algorithm for maximum matching of bipartite graphs

A bipartite graph is such a graph. Its vertices can be classified into two sets X and Y. All edges are associated with two vertices. Exactly one belongs to set X, and the other belongs to set Y.

Maximum matching: the matching with the largest number of edges in the graph is called the maximum matching of the graph.

Perfect match: If all vertices are on the matching edge, the maximum match is perfect.

Minimum coverage: The minimum coverage requires that each edge be associated with at least one of the points with the minimum number of vertices (x set or y set. It can be proved that the least point (that is, the number of overwrites) = the maximum number of matches

Minimum path coverage:

Overwrite all nodes in directed acyclic graph G with a small number of non-Intersecting simple paths. To solve this problem, you can create a bipartite graph model. Split all vertex I into two: I in the x node set and I in the Y node set. If edge I-> J exists, edge I-> J is introduced in the bipartite graph ', if the maximum matching value of a bipartite graph is m, the result is n-M.

Maximum Independent Set Problem:

Select M points in graph G of N points so that there is no edge between them. Calculate the maximum m value.

If graph G meets the condition of a bipartite graph, you can use Bipartite Graph Matching. Maximum number of independent set points = N-Maximum number of matching

I. Hungary Algorithm

Set G = (V, {r}) to an undirected graph. For example, vertex set V can be divided into two subsets, and the two vertices attached to each edge in the graph belong to two different subsets. The graph G is a binary graph.

Given a bipartite graph G, In a subgraph m of G, any two edges in the edge set {e} of m are not attached to the same vertex. M is a matching.

Selecting the largest subset of the number of edges is called the maximal matching problem)

If in a match, each vertex in the graph is associated with an edge in the graph, it is called a full match or a complete match.

The maximum match is widely used in practice. An obvious Algorithm for Finding the maximum match is to first find all the matches, and then keep the most matching numbers. However, the complexity of this algorithm is an exponential function of the number of edges. Therefore, we need to find a more efficient algorithm.

The Hungary algorithm is an effective algorithm for maximum matching. It uses the augmented path definition (also known as the augmented track or staggered track ): if P is a path connecting two unmatched vertices in graph G, and the edges belonging to m and not belonging to M (that is, the edges that have been matched and to be matched) Alternate on P, P is an augmented path relative to M.

The following three conclusions can be drawn from the definition of the augmented path:

1. The path length of P must be an odd number. The first side and the last side do not belong to M.

2. P after the inverse operation (that is, the edge in the non-M is changed to the edge in the m, and the edge in the original m is removed), a larger matching m' can be obtained '.

3. m is the maximum matching of G if and only if there is no augmented path relative to M.

Then we can obtain the Hungary algorithm for maximum matching:

(1) Set M to null

(2) Find an augmented path P, and obtain a larger matching m' instead of m through reverse operations.

(3) Repeat (2) the operation until the augmented path is not found.

Ii. KM algorithm:

Optimal Bipartite Graph Matching: each edge of a bipartite graph has a weight (non-negative). A complete matching scheme is required to maximize the weight of all matching edges, perform optimal and complete matching. (In particular, when the right of all edges is 1, it is the biggest complete match problem)

You can use the exhaustive method to solve the optimal matching problem in a bipartite graph. However, the efficiency of the exhaustive solution is n !, Therefore, we need better algorithms.

Let us first describe a theorem: Let M be a complete match with weighted completely bipartite graph G, A feasible top mark is given for each vertex (the feasible mark of X vertex I is represented by lx [I], and the feasible mark of Y vertex J is represented by Ly [J ), if all edges (I, j) in g have lx [I] + ly [J]> = W [I, j] (W [I, j] indicates the edge weight. For all edges (I, j) in m, LX [I] + ly [J] = W [I, j] is true, then M is an optimal matching of graph G.

Kuhn-munkras algorithm (I .e. km algorithm) process:

(1) initialize the value of the feasible top mark

(2) Search for complete matching using the Hungary Algorithm

(3) If a complete match is not found, modify the value of the feasible top mark.

(4) Repeat (2) (3) until a complete match of an equal subgraph is found.

The KM algorithm mainly controls how to modify the feasible top-level strategy so that a perfect match can be achieved, first, you can set any feasible top mark (for example, the feasible top mark of each x node is set to the maximum right of all the arcs it sets, and the feasible top mark of Y node is set to 0 ), then, find the augmented path in the same subgraph, and find the augmented path. If no augmented path is found, consider all the x nodes (marked as s sets) in the current Hungarian tree and all the y nodes (marked as t sets) in the current Hungarian tree ), evaluate the test taker's knowledge about the arc of all segments in S and not t sets, and take Delta = min {L (xi) + L (YJ)-W (XI, YJ ), | XI in S, YJ in not t }. Obviously, when we reduce L (xi) in all s sets by Delta, at least one edge that belongs to (s, not t) must enter an equal subgraph, in this way, we can continue to expand the Hungary tree. To ensure that the edges belonging to (S, T) do not exit the equal subgraph, we add Delta to the feasible top mark of all vertices in the T set. Then the Hungary tree continues to expand. If the y node of the newly added Hungary tree is not covered, find the augmented path, otherwise, add the corresponding x matching point of the node to the Hungary tree and try to increase the value.

Complexity Analysis: because at least one element is added to the Hungary tree after the above adjustment without expanding the matching, you can find an increasing path by executing at most N times, you can find up to N augmented paths. Therefore, you can perform n ^ 2 times to modify the top mark, and scan all the arcs for each modification, in this way, the complexity of modifying the top mark is O (n ^ 2), and the total complexity is O (n ^ 4.

For each element YJ of not t, define the relaxation variable slack (YJ) = min {L (xi) + L (YJ)-W (XI, YJ ), | XI in S}, it is obvious that Delta = min {slack (YJ), | YJ in not t} each time, O (N ^ 2) is used after each expansion) the calculation of the time is a bit of the initial slack, because the top increment of each arc is the same when the Hungarian tree is grown, therefore, it takes a constant time to modify each slack (note that slack needs to be modified after the top mark is modified and the x node corresponding to the Y node is added to the Hungary tree ). In this way, the time for modifying all slack values is O (n). After each enhancement, the maximum number of top labels can be modified. Then, the total time for modifying the top labels is reduced to O (N ^ 2 ), the total time complexity of n times of augmented expansion is reduced to O (N ^ 3 ). In fact, after this implementation, most of the data can be about twice faster than the O (N ^ 4) algorithm.

Using the Hungarian and KM algorithms for bipartite graph matching, we can solve most of the problems related to bipartite graphs. They provide effective algorithms for maximum matching and optimal matching, in specific programming, we only need to pay more attention to optimization, so that we can come up with an effective way to solve such problems, so as to effectively and reasonably solve such practical problems.

Another statement:

KM algorithm (transfer)

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 subgraphs (called equal subgraphs) that meet the conditions of a [I] + B [J] = W [I, j] edge (I, j) if there is a complete match, 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 contains an equal subgraph, its edge weight is equal to the top mark and sum of all vertices. If its edge does not contain an equal subgraph, the edge weight is smaller than the top sum 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. In this case, we get an interleaved tree with all its leaf nodes being 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:
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.
The two ends are not the edges (I, j) in the staggered tree, And neither a [I] nor B [J] are 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.
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.
The X end is in the staggered tree, and the Y end is not in the edge (I, j) of the staggered tree. The value of a [I] + B [J] is reduced. That is to say, it originally does not belong to an equal subgraph, And now it may have entered an equal subgraph, thus expanding the equal subgraph.
The problem now is to evaluate the value of D. To ensure that a [I] + B [J]> = W [I, j] is always valid, and at least one edge enters 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 }.
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 it is not in the same subgraph, the slack [J] is converted into a smaller value of the original value and a [I] + B [J]-W [I, j. In this way, the minimum value of the slack value of all y vertices not in the staggered tree can be used as the D value when the top mark is modified. Note that after the top mark is modified, all slack values must be subtracted from D.

Original article: http://www.360doc.com/content/11/0718/14/3701281_134273282.shtml

// ******************************** The above is reprinted *** **************************************** ***

 

Another article in Baidu Library is also well written.

Http://wenku.baidu.com/view/def03654312b3169a451a434.html

 

Note that S is emphasized in the article. t sets are a series of points involved in an unsuccessful augmented process. These points appear in an extended attempt, due to various reasons, the edge set of the equivalent subgraph can be modified to meet the conditions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.