A summary of the learning of the two graphs

Source: Internet
Author: User

The nature of the dichotomy: in the graph G, there must be at least two points. If there is a loop, then the loop must be an even-edged loop.

match : In graph theory, a match is a set of edges, where any two edges have no public vertices.
maximum match: A match with the largest number of matched edges in all matches of a graph, called the maximum match of this graph
Maximum matches: the number of matching edges that match the maximum
Perfect Match : if one of the graphs has a match, all vertices are matching points, then it is a perfect match.
minimum Point coverage : Select a minimum point so that at least one end of any edge is selected
maximum independent number : Select the most points so that any selected two points are not connected
Minimum path coverage : For a DAG (directed acyclic graph), select the minimum path,
Makes each vertex belong to and belong to only one path. The path length can be 0 (that is, a single point).
theorem 1: maximum number of matches = minimum point coverage (this is the Konig theorem)
theorem 2: The maximum independent set of two graphs = vertex number-two graph maximum match
theorem 3: Minimum path coverage = number of vertices-maximum number of matches

The nature of the augmented path in a binary diagram:
(1) There is an odd number of edges.
(2) The starting point is in the left half of the dichotomy, ending at the right half.
(3) The point on the path must be one in the left half, and one in the right half, alternating. (In fact, the nature of the binary chart determines this point, because the two points of the same side of the point is not connected to the side, do not forget oh.) )
(4) There are no duplicate points on the entire path.
(5) The starting and ending points are not currently paired, and all the other points are well-matched. (1, Figure 2, [1,5] and [2,6] in Figure 1 are two pairs already paired with the point, and the beginning 3 and end of 4 are not currently matched with other points. )
(6) All the odd-number edges on the path are not in the original match, and all of the even-odd bars appear in the original match. (1, Figure 2 shows that the original match is [1,5] and [2,6], the two side of the edge in Figure 2 given in the augmented path of the edge is the 2nd and 4th edge. The 1th, 3, and 5 edges of the augmented path do not appear in the match shown in Figure 1. )
(7) Finally, the most important one, adding all the odd bars on the augmented path to the original match, and removing all the odd bars in the augmented path from the original match (this operation is called the inverse of the augmented path), the new match number increases by 1 compared to the original match number. (2 shows that the new match is all blue edges, and all red edges are removed from the original match.) The new match number is 3. )

Learning materials: http://blog.csdn.net/xuguangsoft/article/details/7861988

The key is to build a map: Set up a A, a, two sets, there is no relationship within the collection is a one-way relationship
multiple matches : Multiple matches of a one-to-many binary graph. The implementation of the multi-matching algorithm of the binary graph is similar to the Hungarian algorithm, for the element XI in the set X, to find an element that is connected to Yi, check whether the two conditions of the Hungarian algorithm are established, if Yi is not matched, it will
Xi,yi matches. Otherwise, if the element that matches the Yi has reached the upper limit, select an element in all the elements that match Yi, and check to see if an augmented path can be found, and if so, make a position and let Xi and Yi match.
MATCH[I][J] indicates that the XI point in the X collection is connected to J points in the Y set (one-to-many)

    1. Hungarian algorithm templates
//Two graph matching (DFS implementation of Hungarian algorithm)//Initialize: g[][] Division of vertices on both sides//Build g[i][j] means that the i->j has a forward edge, which is the right side to the left .the//g is initialized to 0 without a side connection .//un is the number of vertices to match to the left, and VN is the number of vertices matching the right//Call: Res=hungary (); Output maximum number of matches//Pros: Suitable for dense graphs, DFS find augmented road, simple and easy to understand//Complexity of Time: O (VE)//vertex numbering starting from 0Const intmaxn=510;intUN,VN;Number of//u,vintG[MAXN][MAXN];intLINKER[MAXN];BOOLUSED[MAXN];BOOLDfsintU//Find the augmented path from the left{intV for(v=0; v<vn;v++)//This vertex number starts from 0 and needs to be modified starting from 1      if(G[u][v]&&!used[v]) {used[v]=true;if(linker[v]==-1|| DFS (Linker[v])) {linker[v]=u;//Find augmented road, reverse              return true; }      }return false;}intHungary () {intres=0;intUmemset(linker,-1,sizeof(linker)); for(u=0; u<un;u++) {memset(Used,0,sizeof(used));if(Dfs (U)) res++; }returnRes;}

2 Hopcroft-carp algorithm Template

This algorithm is smaller than the time complexity of the Hungarian algorithm, and the big data can be matched with the binary graph (Hopcroft-carp algorithm).  Initialize: g[][] adjacency matrix call: Res=maxmatch (); Nx,ny to initialize!!! Time Complex O (v^0.5E) suitable for binary matching with large dataConst intmaxn= the;Const intinf=1<< -;intG[maxn][maxn],mx[maxn],my[maxn],nx,ny;intDx[maxn],dy[maxn],dis;BOOLVST[MAXN];BOOLSEARCHP () { Queue<int>Q; Dis=inf;memset(dx,-1,sizeof(DX));memset(dy,-1,sizeof(DY)); for(intI=0; i<nx;i++)if(mx[i]==-1) {Q.push (i); dx[i]=0; } while(! Q.empty ()) {intU=q.front (); Q.pop ();if(Dx[u]>dis) Break; for(intv=0; v<ny;v++)if(g[u][v]&&dy[v]==-1) {dy[v]=dx[u]+1;if(my[v]==-1) Dis=dy[v];Else{dx[my[v]]=dy[v]+1;                Q.push (My[v]); }            }    }returnDis!=inf;}BOOLDFS (intu) { for(intv=0; v<ny;v++)if(!vst[v]&&g[u][v]&&dy[v]==dx[u]+1) {vst[v]=1;if(my[v]!=-1&&dy[v]==dis)Continue;if(my[v]==-1||               DFS (My[v])) {my[v]=u; Mx[u]=v;return 1; }       }return 0;}intMaxmatch () {intres=0;memset(mx,-1,sizeof(Mx));memset(my,-1,sizeof(My)); while(SEARCHP ()) {memset(VST,0,sizeof(VST)); for(intI=0; i<nx;i++)if(mx[i]==-1&&dfs (i)) res++; }returnRes;}

Some types of topics:
1. Maximum Match
2. Minimum path coverage
3. Minimum point coverage
4. Maximum independent set
5. Row-and-column matching parity, staining, shrinking,
6. Path Output Solution output
7. Building the details of the reverse map, the maximum complete sub-map,
8. One-to-many matching, many-to-many matching
9. Two-point answer + match
10. Two the application of the character of the graph

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

A summary of the learning of the two graphs

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.