Algorithms in a Nutshell

(Tina Meador) #1
Bipartite Matching | 239

Network Flow
Algorithms

Bipartite Matching


Matching problems exist in numerous forms. Consider the following scenario.
Five applicants have been interviewed for five job openings. The applicants have
listed the jobs for which they are qualified. The task is to match applicants to jobs
such that each job opening is assigned to exactly one qualified applicant. It may
be surprising to discover that we can use FORD-FULKERSONto solve the Bipartite
Matching problem. This technique is known in computer science as “problem
reduction.” We reduce the Bipartite Matching problem to a Maximum Flow
problem in a flow network by showing (a) how to map the Bipartite Matching
problem input into the input for a Maximum Flow problem, and (b) how to map
the output of the Maximum Flow problem into the output of the Bipartite
Matching problem.

Input/Output


Input

A Bipartite Matching problem consists of a set of 1≤i≤nelements,si∈S; a set of
1 ≤j≤mpartners,tj∈T; and a set of 1≤k≤pacceptable pairs,pk∈P, that associate an
elementsi∈Swith a partnertj∈T. The setsSandTare disjoint, which gives this
problem its name.

Output

A set of pairs (si,tj) selected from the original set of acceptable pairs,P. These pairs
represent a maximum number of pairs allowed by the matching. The algorithm
guarantees that no greater number of pairs is possible to be matched (although
there may be other arrangements that lead to the same number of pairs).

Solution


Instead of devising a new algorithm to solve this problem, we reduce a Bipartite
Matching problem instance into a Maximum Flow instance. In Bipartite
Matching, selecting the match (si,tj) for elementsi∈Swith partnertj∈Tprevents
eithersiortjfrom being selected again in another pairing. To produce this same
behavior in a flow network graphG=(V,E), constructG as follows:
V contains n+m+2 vertices
Each elementsimaps to a vertex numberedi. Each partnertjmaps to a vertex
numberedn+j. Create a new source vertexsrc(labeled 0) and a new target
vertextgt (labeledn+m+1).
E contains n+m+k edges
There arenedges connecting the newsrcvertex to the vertices mapped from
S. There aremedges connecting the newtgtvertex to the vertices mapped
fromT. For each of thekpairs,pk=(si,tj), add the edge (i,n+j). Set the flow
capacity for each of these edges to 1.

Algorithms in a Nutshell
Algorithms in a Nutshell By Gary Pollice, George T. Heineman, Stanley Selkow ISBN:
9780596516246 Publisher: O'Reilly Media, Inc.


Prepared for Ming Yi, Safari ID: [email protected]
Licensed by Ming Yi
Print Publication Date: 2008/10/21 User number: 594243
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use

Free download pdf