The maximum weights of binary graphs match km algorithm

Source: Internet
Author: User

The essence of this algorithm is to constantly find the augmented road;

Km the correctness of the algorithm is based on the following theorem:
If the sub-graph (i,j) consisting of all the edges (a[i]+b[j]=w[i,j) in the binary graph (called Equal sub-graph) has a complete match, then this complete match is the maximum weight matching of the binary graph.

This theorem is obvious. Because for any one of the binary graphs, if it is contained in an equal sub-graph, then its Benquan and equals the top label of all vertices, and if it has an edge that is not included in the equal sub-graph, then its Benquan and is smaller than the top of all vertices and. So the complete match of the equal sub-graph must be the maximal right match of the binary graph.

(1) Feasible point mark: Each point has a label, note Lx[i] is x square point I, Ly[j] is the y Square point J label. If there are lx[i]+ly[j]>=w on any side of the diagram (I, J, W), then this set of points is feasible . In particular, for lx[i]+ly[j]=w edges (i, J, W), known as feasible edges ;


(2) km The core idea of the algorithm is to modify certain points of the label (but to meet the point is always feasible), and continuously increase the total number of viable edges in the graph, until there is only a viable edge of the complete match, this match must be the best (because the definition of the target of the feasible point, any one of the diagram exactly matches The sum of its edge weights is not greater than that of all points, and the sum of exactly matched Benquan consisting of the feasible edges equals the number of all points, so this match is the best. Initially, the initial label for each point is calculated: Lx[i]=max{e.w|e.x=i} (that is, the initial label for each X-square point is the weight of the most weighted edge associated with the X-square point), ly[j]=0 (i.e. the initial label for each y-square point is 0). This initial point is obviously feasible, and there is at least one feasible edge in the edge associated with any X-square point ;


(3) Then, start Dfs augmentation from each x-square point. The process of Dfs augmentation and the maximum matching Hungary algorithm is basically the same, just to pay attention to two points: first, only to find the feasible side, the second is to search the process of the X-square point all down (can be done with VST), in order to make the subsequent changes;


(4) The result of augmentation has two kinds: if the success (find the augmented orbit), then the point augmentation completed, into the next point of augmentation. If you fail (no augmented orbit is found), you need to change the label of some points to increase the number of viable edges in the graph. By subtracting a constant d from all the X-square points in the augmented orbit (that is, traversing through the augmented process), all the labels of the Y-square points in the augmented orbit are all prefixed with a constant d, for any one of the graphs (I, J, W) (I is the X-square point, J is the Y-square point):


<1>i and J are in the augmented orbit: at this point (I, J) the value of the (Lx[i]+ly[j]) is unchanged, that is, the feasibility of this side of the same (the original feasible edge is still, it is not now still not);
<2>i in the augmented orbit while J is absent: The value of this edge (I, J) (Lx[i]+ly[j]) is reduced by D, i.e. the edge is not a viable edge (otherwise J will be traversed), and now it may be;
<3>j in the augmented orbit and I not: The value of the Edge (I, J) (Lx[i]+ly[j]) is increased by D, that is, the original edge is not a viable edge (if this edge is a viable edge, then the traversal to J will be executed immediately after the DFS (i), at which I will be traversed), and is still not;
Neither <4>i nor J are in the augmented orbit: at this point the (Lx[i]+ly[j]) value of the Edge (I, j) is not changed, that is, the feasibility of this edge is constant.
In this way, the original viable edges in the diagram are still viable after this step of the modification, and the previously infeasible edges may now become viable edges. So how much should the value of D take? Obviously, the entire point mark can not lose the feasibility, that is, for the above <2> side, its lx[i]+ly[j]>=w this property can not be changed, so take All <2> class Edge (LX[I]+LY[J]-W) minimum value as a D value. On the one hand, the feasibility of point marking can be ensured, on the other hand, after this step, at least one feasible edge will be added to the figure.


(5) After the modification, continue to the X-side point Dfs augmentation, if it fails, continue to modify until successful;

The above is the basic idea of the KM algorithm. But the simple implementation method, the time complexity of O (N4)-Need to find O (n) Secondary augmentation path, each augmentation needs to modify the O (N) sub-index, each time the top is modified to enumerate the edges to find D value, the complexity of O (N2). In fact, the complexity of the KM algorithm can be achieved O (N3). We give each y vertex a "slack" function slack, which is initialized to infinity each time we start looking for an augmented path. While looking for an augmented path, when checking for edges (i,j), if it is not in the equal sub-graph, let slack[j] be the smaller value of the original value and Lx[i]+ly[j]-w[i,j]. This way, when you modify the top label, take all the minimum values in the slack value of the y vertices that are not in the interleaved tree as the D value. However, it is important to note that all slack values are subtracted from D when the top label is modified.

Recommended:

Http://www.cppblog.com/MatoNo1/archive/2012/04/26/151724.html

http://blog.csdn.net/liguanxing/article/details/5665646

The maximum weights of binary graphs match km algorithm

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.