Bipartite Graph Matching Algorithm Summary

Source: Internet
Author: User

Recently I am studying the bipartite graph algorithms. The following content is based on my understanding. Welcome to discuss it.

What is a bipartite graph:

A bipartite graph, also known as a binary graph, is a special model in graph theory. Set G = (V, E) to an undirected graph. If vertex v can be divided into two subsets (a, B) that do not overlap with each other, and each edge (I, j) in the graph) the two associated vertex I and j belong to these two different vertex sets (I in a, J in B) respectively. Then, graph G is called a bipartite graph.

Maximum matching of a bipartite graph:

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

The maximum stream or Hungary algorithm can be used to obtain the maximum matching of a bipartite graph.

 
In the algorithm for finding the maximum binary matching for the maximum flow, the capacity of all edges is 1, and two additional nodes are added: S, T, and s are connected to the vertex in the set, t is connected to the vertices in the B set and the maximum stream algorithm can be run once. The following describes Hungary algorithms.

First, the algorithm code of Hungary is given. Take hdu1150 as an example.
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1150

# Include <iostream> # include <cstring> # include <cstdio> using namespace STD; int map [105] [105]; // map [I] [J] = 1; indicates that I in set a and Set B have access tags that are connected to int vis [105]; // access tags in Set B. Int link1 [105], n, m, K; // link1 [I] indicates the elements in the set matched by B set I. If link1 [I] =-1, it indicates that I does not match bool can (int I) at present. // find the matching {Int J; For (j = 0; j <m; j ++) of a set I) {If (! Vis [J] & map [I] [J]) // although J scans from 0-m, it is impossible to repeatedly access it, the VIS array is still necessary, the reason is that the following can (link1 [J]) {// can (link1 [J]) cannot be found after the VIS array is available. Vis [J] = 1; if (link1 [J] =-1 | can (link1 [J]) // If J does not match in B or the element in a that matches J has another match {link1 [J] = I; return true ;}} return false ;} int main () {While (scanf ("% d", & N), n! = 0) {scanf ("% d", & M, & K); int I; int Z; memset (MAP, 0, sizeof (MAP )); for (I = 0; I <K; I ++) {int T1, T2; scanf ("% d", & Z, & T1, & T2); If (T1> 0 & T2> 0) map [T1] [T2] = 1;} int S = 0; memset (link1,-1, sizeof (link1); for (I = 0; I <n; I ++) {memset (VIS, 0, sizeof (VIS); If (CAN (I )) s ++;} printf ("% d \ n", S );}}

Problems of graphs that the Hungarian algorithm can solve: (Bipartite Graph)
1. The minimum number of vertices in the graph = the maximum number of matching items in the graph;
2. The maximum vertex independence set of the graph = the number of graph vertices-the maximum number of matching graphs;
3. Minimum path overwrite of the graph = number of vertices of the source image-Maximum number of matching of the two graphs formed after the source image is split;

The proof of 1 can be proved by the reverse proof method. If the maximum number of matching M (the minimum number of points) cannot cover all edges, an extra edges e exists. Adding e can lead to a larger M. Conflict.

Minimum path coverage:

A nodeDirected Acyclic GraphIn, path overwrite is to find some paths in the graph to overwrite all vertices in the graph, and any vertex has only one path associated with it; (If each path in these paths is taken from its starting point to its end point, it can pass through each vertex in the graph once and only once ).

 
Relationship between path overwrite and bipartite graph (Must be a directed graph without loops): Minimum path overwrite = | A |-Maximum number of matching records after splitting

Split the I node in a into a 'I' in B, then I-> J in the finite edge
Number of knots corresponding to the I-> J 'source image-the maximum number of matching points between A and B is the minimum path overwrite.

Proof according to your own understanding: first, we will look at each point as a path, namely, p-> P
N paths are required to overwrite all vertices. In AB matching, if I-> j 'is used, the source image has I-> J. In this way, this edge is selected but the number of paths is-1, because a point in the AB match matches an edge, a point in the source image also corresponds to an edge, that is, path coverage is satisfied .. Therefore, the number of knots in the source image-the maximum number of matching points between A and B is the minimum path overwrite.

 



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.