Maximum binary match

Source: Internet
Author: User

Maximum binary matchingIt is common in real life and often occurs in task allocation. For example, there are five employees and four different tasks, and different employees can complete different or identical tasks. That is to say, some employees only do this task, some employees do that task, and some employees do some tasks.The diagram is as follows:: Employees on the left, tasks on the right, and connections on the left.

Our problem is to reasonably arrange employees and complete the most tasks as much as possible. The Shadow part is the best allocation method. In the previous article, we introduced the biggest stream problem,Here we can turn the maximum binary matching problem into the maximum stream problem.. As shown in:

The maximum traffic limit for each edge is 1. Therefore, the maximum number of tasks required to be completed is equivalent to the maximum flow of the transformed network. The maximum flow problem has been mentioned earlier.

The specific program implementation is as follows:

# Include
 
  
# Define N 11 // Number of vertices /*******************************: find the augmented path input from the Source Vertex s to the sink vertex t from the residual network: residual network matrix, record the matrix output of the previous vertex: 0 indicates that no path is found, 1 indicates that the path \ ********************************* is found \********************************** * *******************/int search (int dist1 [N] [N], int vertex [N]) {int queue [20] = {-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 }; // initialization,-1 as the flag int flag [N] = {0}; // It indicates whether the vertex has been accessed int front = 0; // queue header pointer int rear = 0; // queue end pointer int te Mp = 0; int I; queue [rear] = 0; // flag [0] = 1; rear ++; while (queue [front]! =-1) // The queue is not empty {temp = queue [front]; // the element of the queue header for (I = 0; I
  
   
0) // change the residual graph dist1 [j] [I] = dist1 [I] [j]; dist1 [I] [j] = dist1 [I] [j]-min; dist [I] [j] = dist [I] [j] + min-dist [j] [I]; // change the original stream network if (dist [I] [j] <0) {dist [j] [I] =-dist [I] [j]; dist [I] [j] = 0;} j = I; I = vertex [I];} printf ("original stream network matrix: \ n "); for (int I = 0; I
   
    

The maximum flow of the program is 3, which is consistent with the preceding diagram. However, we find that the results are different from those in the diagram. This indicates that the maximum binary matching can have different solutions and there are different allocation schemes.


Note: If a program error occurs, the development platform version may be different. click the following link: Description

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.