Title: Maximum Bipartite Matching
1Maximum Bipartite Matching
- In a graph G, if no M-augmenting path exists,
then M is a maximum matching in G. - Idea Iteratively seek augmenting paths to
enlarge the current matching till no M-augmenting
path can be found.
- Question How to show the current matching has
maximum size?
- Answer Find a vertex cover with the same size
as the current matching.
2Algorithm 3.2.1
- Input An X,Y-bigraph G, a matching M in G, and
the set U of M-unsaturated vertices in X. - Output Output an M-augmenting path or a vertex
cover of size M.
We can get maximum matching in X,Y-bigraph by
repeatedly apply Algorithm 3.2.1 to X,Y-bigraph.
U
X
Y
3Algorithm 3.2.1
- Exploring M-alternating paths from U, letting S?X
and T?Y be the sets of vertices reached. - If no M-alternating paths are explored, report
T?(X-S) as a minimum cover and M as a maximum
matching.
S
X-S
U
X
Y
T
4Algorithm 3.2.1
S
X
Y
5Algorithm 3.2.1
- 3. Explore alternating path from an unmark x?S
and mark x. - 3.2. For each xy?E(G), include y in T and include
w in S, where yw?M.
S
x
x
x
x
x
x
U
X
w
w
w
y
y
y
Y
T
6Algorithm 3.2.1
3.1 If there exists unsaturated y?N(x) such that
xy?M, then stop and report an M-augmenting path
from U to y.
S
X
Y
T
7Algorithm 3.2.1
2. If S has no unmarked vertex, stop and report
T?(X-S) as a minimum cover and M as a maximum
matching.
X-S
S
x
x
x
x
x
x
U
X
w
w
w
y
y
y
Y
T
8Algorithm 3.2.1
- 1. SU and T?.
- 2. If S has no unmarked vertex, stop and report
T?(X-S) as a minimum cover and M as a maximum
matching. - 3. Explore alternating path from an unmark x?S.
- 3.1. If there exists unsaturated y?N(x) such
that xy?M, then stop and report an M-augmenting
path from U to y. - 3.2. For each xy?E(G), include y in T and
include w in S, where yw?M. Mark x and Goto Step
2.
9Theorem 3.2.2
- Repeatedly applying Algorithm 3.2.1 to a
bipartite graph produces a matching and a vertex
cover of equal size - 1. Let QT?(X-S) and M be the matching when
algorithm 3.2.1 stops at step 2. - 2. Q is a vertex cover.
? No edge joins S to Y-T.
S
X-S
X
Y
T
Y-T
10Theorem 3.2.2
- 3. Each y?T is M-saturated.
4. Each vertex of X-S is M-saturated.
5. No edge in M joins T to X-S.
3.4.5. ? M has at least TX-S edges.
? Q is a minimum vertex cover and M is a maximum
matching.
S
X-S
X
Y
T
Y-T
11Maximum Weighted Bipartite Matching
- A farming company owns n farms and n processing
plants. The profit that results from sending the
output of farm i to plant j is wi,j. - The company wants to select edges forming a
matching to maximize total profit.
v1
v2
v3
u1
u2
u3
u1
u2
v3
v2
v1
u3
Edge weight Wi,j
w(M)65819
12Minimum Weighted Cover
- The government will pay ui if the company agrees
not to use farm i and vj if it agrees not to use
plant j. The government must offer amounts such
that uivjgtwi,j for all i, j. Otherwise, the
company makes more by using edge xiyj than taking
the government payments for those vertices. - The government wants to minimize ?ui?vj.
v1
v2
v3
c(u)
4
5
7
u1
u2
u3
c(v)
0
2
1
Edge weight Wi,j
c(u,v)19
13Lemma 3.2.7 Duality of minimum c(u,v) and
maximum w(M)
- For a perfect matching M and weighted cover (u,v)
in a weighted bipartite graph G, (1)
c(u,v)gtw(M), and (2) c(u,v) w(M) iff M consists
of edges xiyj such that uivjwi,j. In (2), M and
(u,v) are optimal. - (1) c(u,v)gtw(M) since uivjgtwi,j for all i, j.
- (2) Trivial.
c(u)
4
5
7
u1
u2
u3
v3
v2
v1
c(v)
0
2
1
w(M)65819
c(u,v)19
14Equality Subgraph
- Equality Subgraph The equality subgraph Gu,v for
a weighted cover (u,v) is the spanning subgraph
of Kn,n whose edges are the pairs xiyj such that
uivjwi,j. In the cover, the excess for i,j is
uivj-wi,j.
Kn,n
v1
v2
v3
c(u)
4
5
7
u1
u2
u3
u1
u2
u3
v3
v2
v1
c(v)
0
2
1
Edge weight Wi,j
15Algorithm 3.2.9
- Input A matrix of weights on the edges of Kn,n
with bipartition X,Y. - Output A maximum weighted matching.
- Idea Iteratively adjust the cover (u,v) until
the equality subgraph Gu,v has a perfect matching.
16Algorithm 3.2.9
- Initialization Let (u,v) be a cover, such that
uimaxj wi,j and vj0.
? u1 max 4, 1, 6, 2, 3 6, v1 0 u2
max 5, 0, 3, 7, 6 7, v2 0 u3 max 2,
3, 4, 5, 8 8, v3 0 u4 max 3, 4, 6, 3,
4 6, v4 0 u5 max 4, 6, 5, 8, 6 8,
v5 0
A matrix of weight
0 0 0 0 0
4 1 6 2 3 5 0 3 7 6 2 3 4 5 8 3 4 6
3 4 4 6 5 8 6
6 7 8 6 8
17Algorithm 3.2.9
0 0 0 0 0
4 1 6 2 3 5 0 3 7 6 2 3 4 5 8 3 4 6
3 4 4 6 5 8 6
60-4 60-1 60-6 60-2 60-3 70-5 70-0
70-3 70-7 70-6 80-2 80-3 80-4 80-5
80-8 60-3 60-4 60-6 60-3 60-4 80-4
80-6 80-5 80-8 80-6
excess matrix
6 7 8 6 8
R
2 5 0 4 3 2 7 4 0 1 6 5 4 3 0 3 2 0
3 2 4 2 3 0 2
X
R
Y
T T
T T
18Algorithm 3.2.9
- How to adjust the cover (u,v) such that the
equality subgraph Gu,v has a perfect matching? - Add any edge incident to a vertex in QR?T into
Gu,v does not work. - Decrease the excess for each edge not incident to
a vertex in QR?T. - No edge has a negative excess after adjusting the
cover (u,v).
19Algorithm 3.2.9
0 0 0 0 0
R
2 5 0 4 3 2 7 4 0 1 6 5 4 3 0 3 2 0
3 2 4 2 3 0 2
6 7 8 6 8
min
X
e
R
Y
T T T
T T
T T
e
0 0 11 11 01
min
0 0 0 0 0
1 1
0 3 0 4 2 0 5 4 0
0 5 4 5 4 0 1 0 0 3
1 2 0 3 0 1
5-1 6-1 8-1 5-1 7-1
6-1 7-1 8 6-1 8-1
1 4 0 4 2 1 6 4 0
0 6 5 5 4 0 2 1 0 3
1 5 1 3 0 1
TTT
20Algorithm 3.2.9
- 1. Find a maximum matching M in Gu,v. If M is
perfect matching, stop and report M as a maximum
weighted matching. - 2. Let Q be a vertex cover of size M in Gu,v.
Let RX?Q and TY?Q. Leteminuivj- wi,j
xi?X-R, yj?Y-T. - 3. Decreases ui byefor xi ?X-R, and increases vj
byefor yj ?Y. - 4. Form the new equality graph and Goto Step 1.
21Theorem 3.2.11
- Algorithm 3.2.9 finds a maximum weight matching
and a minimum cost cover - Let (u,v) be the current cover and suppose that
the equality subgraph has no perfect matching.
Let (u,v) be the new lists of numbers assigned
to the vertices. - Show (u,v) is a cover by discuss 3 cases 1)
edge from X-R to T or from R to Y-T, 2) edges
from R to T, and 3) edge from X-R to Y-T.
22Theorem 3.2.11
- Case 1 uivj uivj for edges xiyj from X-R to
T or from R to Y-T. ? (u,v) is a cover
0 0 0 0 0
0 0 01 01 0
2 5 0 4 3 2 7 4 0 1 6 5 4 3 0 3 2 0
3 2 4 2 3 0 2
6 7 8 6 8
6-1 7-1 8 6-1 8-1
1 4 0 4 2 1 6 4 0
0 6 5 5 4 0 2 1 0 3
1 5 1 3 0 1
R
R
T T
T T
23Theorem 3.2.11
- Case 2 uivj uivje for edges xiyj from R to
T. ? (u,v) is a cover -
0 0 0 0 0
0 0 01 01 0
2 5 0 4 3 2 7 4 0 1 6 5 4 3 0 3 2 0
3 2 4 2 3 0 2
6 7 8 6 8
6-1 7-1 8 6-1 8-1
1 4 0 4 2 1 6 4 0
0 6 5 5 4 0 2 1 0 3
1 5 1 3 0 1
R
R
T T
T T
24Theorem 3.2.11
- Case 3 uivj uivj-e for edges xiyj from X-R
to Y-T. ? (u,v) is a cover since eminuivj-
wi,j xi?X-R, yj?Y-T.
0 0 0 0 0
0 0 01 01 0
2 5 0 4 3 2 7 4 0 1 6 5 4 3 0 3 2 0
3 2 4 2 3 0 2
6 7 8 6 8
6-1 7-1 8 6-1 8-1
1 4 0 4 2 1 6 4 0
0 6 5 5 4 0 2 1 0 3
1 5 1 3 0 1
R
R
T T
T T
25Theorem 3.2.11
- 2. It terminates only when the equality subgraph
has a perfect matching. ? equal value for the
current matching and cover. - 3. We need to show Algorithm 3.2.9 always
terminate. It suffices to show at each iteration
the cost of the cover is reduced at least e
because the cost starts at some value and is
bounded below by the weight of a perfect
matching.
26Theorem 3.2.11
- M is not a perfect matching. ? QMltX. ?
RTltX-RR.
? TltX-R.
-e
X-R
R
X
Y
T
e