KM algorithmic explanation [go]

Source: Internet
Author: User
Tags benchmark

Read Catalogue

    • Binary Chart Blog Recommendation
    • Hungarian algorithm steps
    • Hungary algorithm Blog recommended
    • KM algorithm steps
    • KM introduction of the algorithm benchmark (aka Top mark)
    • KM process details
    • KM Algorithm blog recommendations

0. Two-minute chartThe concept of the dichotomy graphThe two-part graph, also known as two-part graph, is a special model in graph theory. set g= (V, E) is a graph without direction. If the vertex set V can be divided into two disjoint subsets X and Y, and the two vertices connected by each edge of the graph are one in X and the other in Y, then figure G is a two-point figure. It is possible to get a matching relationship between driver and order on the line as a two-part graph. the determination of the dichotomy graphthe sufficient and necessary condition for the two-point graph of the graph G is that G has at least two vertices and that all of its loops are of an even length. Judging the undirected graph is not a binary graph, you can use the depth-first traversal algorithm (aka cross-staining method). The following focuses on the definition and principle of the cross-staining methodfirst, remove a vertex for staining, and there are three cases of points adjacent to the node:1. If the node is not dyed, it will dye its opposite color, push into the queue,2. If the section Dianran and vice versa, ignore it,3. If the section Dianran and is the same as the parent node, the proof is not a binary diagram, return back to topBinary Chart Blog recommendationThe code can refer to the blog: graph theory Introduction ——— Depth-first search implementation of two-part graph determinationCross Staining Blog recommendation: Cross-staining method to determine the two-part mapalso enclosed are the properties of the binary Chart blog: Some properties of the binary graphs 1.KM Algorithm PreliminaryKm the full name of the algorithm is Kuhn-munkras, which was put forward by the two men in 1957, interestingly, the Hungarian algorithm was proposed in 1965. Augmented Pathaugmented path definition:if P is a path in Figure G that connects two unmatched vertices, and an edge of M and an edge that does not belong to M (that is, matched and matched edges) alternately appear on p, then p is an augmented path relative to M(for example, there is a, B set, a point in the augmented route a leads to a point in B, and this point in B leads to a point in a ...). Alternately)The augmented path has the following characteristics:1 An odd number of edges2. Beginning at x-side of the dichotomy, end point on the Y side of the binary graph3. The point on the path must be one on the X side, one on the Y side, and interlaced. 4. There are no duplicate points on the entire path5. The starting and ending points are not currently paired, and the other points have been shown in the matching sub-graph6. All the odd edges on the path are not currently on the edge of the current matching sub-graph, and all the even-odd bars have entered the current matching sub-graph. An odd edge is one edge more than an even edge7. So when we add all of the odd-number edges to the matching sub-graph and delete the strip edges, the number of matches increases by 1. For example, the blue is the current matching sub-graph, red indicates an unmatched path, there is only edge x0y0, and the augmented path is found through X1: X1y0->y0x0->x0y2

There are two ways to find the augmented path, one is deep search, the other is wide search. For example, looking for an augmented path from X2
    • If it is deep search, X2 find y0 match, but found Y0 has been X1 match, so go deep to x1, to X1 find new matching node, the results found that X1 No other matching node, so matching failed, x2 then find y1, found Y1 can match, so found a new augmented path.
    • If it is wide search, X1 find y0 node, because can not immediately get a legitimate match, so it as a candidate into the queue, and then find Y1, because Y1 has been matched, so the match successfully returned.
Relatively speaking, the deep search to be easy to understand, its stack can be maintained by the recursive process, while the wide search will need to maintain a queue, and on the way over the route to do their own marking, to achieve a more troublesome. Hungarian AlgorithmThe Hungarian algorithm, which is used to find the maximum match of the binary graph. What is the maximum match? Assuming that each edge has a value, there must be a match of the maximum weight. back to topHungarian algorithm stepsThe algorithm chooses the side of the binary graph according to certain rules to join the matching sub-graph, and its basic mode is:1. Initialize matching sub-graph is empty2.While Find augmented path3.Do Adding an augmented path to the matching sub-diagram back to topHungary Algorithm Blog recommendedkm Depth-first traversal algorithm, which is accompanied by a guide to the blog: Interesting Writing algorithm series – Hungarian algorithmMaximum Matching explanation blog: Hungarian algorithm (two-part chart)km algorithmkm algorithm, which is used to find the best match of binary graph matching. What is the best match? Is that the complete match with the weight of the weighted binary graph is called the best match. So what is a complete match? Each vertex in x matches a vertex in Y, or each vertex in the Y section matches a vertex in X, the match is a complete match. back to topkm algorithm stepsthe algorithm steps are as follows:1. Use the adjacency matrix (or any other method) to store the diagram, note: If you only want to match the maximum weights without requiring an exact match, set the weights of each unconnected edge to 0. 2. Use the greedy algorithm to initialize the benchmark. 3. Use the Hungarian algorithm to find a complete match. 4. If not found, add some edges by modifying the benchmark. 5. Repeat the 3,4 steps until the exact match is complete. back to topkm introduction of the algorithm benchmark (aka Top mark)binary graph Best match or binary graph matching, so with the Hungarian algorithm is similar to the idea. The binary graph is a special network flow, the best match is the maximum (small) cost maximum flow, so the FF algorithm (full name Ford-fulkerson algorithm) can also be achieved.
    • So we can combine this Hungarian algorithm with the FF algorithm. This is the idea of the KM algorithm: try to find the largest side of the edge, if you can not change a larger.
      • FF algorithm inside, we are looking for the longest (short) way to carry out the flow, so the binary map matching inside we also follow the FF algorithm to find the maximum edge to connect edge!
      • But what happens when you encounter a point that's been matched two times? Then use the Hungarian algorithm to change the match!
    • So, according to the idea of km algorithm, we start with the Benquan value of the largest connection.
    • So the question is, how do we get the computer to know which side of the weight is the most appropriate for that point? Maybe we can record the other end of the edge in some way, but it also involves changing the edges and recording the sum of the edge weights, and this method of recording the endpoint seems a bit cumbersome.
      • The KM used a very ingenious approach (and the essence of the KM algorithm idea): Add a benchmark (top mark)
Add a benchmark (top) process:
    • We add benchmark CX and CY to each point on the left of the XI and the right of each point Yi. Where we want to meet Cx+cy>=w[x][y] (w[x][y) is the Point XI, Yi between the Benquan value)
    • For the initial initialization, we do the following for each point: Cx=max (W[x][y]); cy=0;
to add a two-part chart before the top label:                to add a binary chart after the top label:  back to topkm process details
    • Initialize the value of the feasible top (set the initial value of the lx,ly)
    • Searching for complete matching of equal sub-graphs with Hungarian algorithm
    • Modify the value of the feasible top if no augmented path is found
    • Repeat (2) (3) until you find a complete match for the equal sub-graph
using the example, the Hungarian algorithm for the edge operation, the maximum edge is connected. So the original judge whether there are side conditions w[x][y]==0 replaced with Cx+cy==w[x][y]
  • So we even have the ad, forming a new dichotomy (we're calling it a two-molecule diagram.)
  • Then embarrassed, the computer next to the B-point BD, but D Point has been and a point connected, how to do???
    • According to the Hungarian algorithm, we do is to connect a point with other points, but at this time the sub-map "does not exist" and the other side of a point, how to do???
      • To do this, we need to add these sides! Obviously, we add edge, naturally add not in the sub-image edge of the largest edge, that is, and the sub-image of the edge of the lowest weight difference.
        • So we once again introduced a variable d,d=min{cx[i]+cy[j]-w[i][j]}, in which, in this topic cx[i] refers to the benchmark of a, cy[j] is the benchmark for points other than point D (i.e. connected points).
          • Subsequently, for the side ad that originally existed in the sub-graph, we subtract the benchmark of a cx[i] minus the d,d cy[d] plus d.
            • This ensures that the original ad edge is retained in the sub-graph, and that the edge AE that is not the maximum weight of the sub-graph connected to point A is added to the sub-graph.
            • Because the computer determines whether an edge is in the sub-diagram, the condition is that its ends of the vertices of the benchmark meet Cx+cy==w[x][y]
              • For the original side, we subtract d from the left end of the benchmark, plus d for the right end of the benchmark, so the final result remains the same, still w[x][y].
              • For the edges we want to add, we subtract d from the left endpoint, i.e. cx[i]=cx[i]-d, for the convenience of indicating that we treat the changed cx[i] as cz[i], i.e. cz[i]=cx[i]-d;
                • Because Cz[i]=cx[i]-d;d=cx[i]+cy[j]-w[i][j];
                • The D generation into the left type can be cz[i]=cx[i]-(cx[i]+cy[j]-w[i][j]);
                • The cz[i]+cy[j]=w[i][j of simplicity];
                • Meet the requirements! The new edge is added.
    • Repeat the above process. (a combination of the Hungarian algorithm and the FF algorithm)
back to topkm algorithm blog recommendationsthe top label content is very good: km algorithmrelaxation content is better: the best perfect match--km algorithm for binary graphsthe Hungarian algorithm and the FF algorithm are combined to get the KM algorithm is very detailed: the best matching--km algorithm for binary graph matchingBest Explanation Blog Recommendation: My understanding of the KM algorithm

KM algorithmic explanation [go]

Related Article

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.