Maximum Bipartite Matching

Preview:

DESCRIPTION

Maximum Bipartite Matching. M-augmenting path: A path that alternates between edges in M and edges not in M and has endpoints unsaturated by M. Theorem 3.10: A matching M is a maximum matching in G iff G has no M-augmenting path. We can enlarge M if M-augmenting path exists. X. Y. The Idea. - PowerPoint PPT Presentation

Citation preview

Maximum Bipartite Matching• M-augmenting path: A path that alternates

between edges in M and edges not in M and has endpoints unsaturated by M.

• Theorem 3.10: A matching M is a maximum matching in G iff G has no M-augmenting path.

• We can enlarge M if M-augmenting path exists.

X

Y

The Idea

• Iteratively seek augmenting paths to enlarge the current matching till no M-augmenting path can be found.

How to seek M-augmenting path?

• Let U be the set of M-unsaturated vertices in X. One endpoint of an M-augmenting path is in U.

• If node x is in U and xyE(G) for some unsaturated node y, then an M-augmenting path is found.

• Let SX be the set of vertices reached by exploring M-alternating paths from U. If node x is in S and xyE(G) for some unsaturated node y, then an M-augmenting path is found.

X

Y

How to seek M-augmenting path?

X

Y

U

T

S

x

y

w w

yy

w

x x xx

Algorithm 3.2.1

1. S=U 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 xS.

3.1. If there exists unsaturated yN(x) such that xyM, then stop and report an M-augmenting path from U to y.

3.2. For each xyE(G), include y in T and include w in S, where ywM. Mark x and Goto Step 2.

Theorem 3.2.2

• Repeatedly applying Algorithm 3.2.1 to a bipartite graph produces a matching and a vertex cover of equal size

How to show the current matching M has maximum size?

• Theorem 3.1.16: If G is a bipartite graph, then the maximum size of a matching in G equals to the minimum size of a vertex cover in G

• Find a vertex cover with the same size as the current matching– It goes to show T(X-S) is a vertex over with the

same size as the current matching M.

T(X-S) is a vertex cover

• No edge joins S to Y-T.

T

X

Y

S X-S

Y-T

|M|= |T|+|X-S|• |M|<= |T|+|X-S|

– T(X-S) is a vertex cover• |M| >= |T|+|X-S| edges.

– Each yT is M-saturated.– Each vertex of X-S is M-saturated.– No edge in M joins T to X-S.

T

X

Y

S X-S

Y-T

Maximum 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.

Edge weight Wi,j

842

635

364u1

u2

u3

v1 v2 v3

u1 u2 u3

v3v2v1

w(M)=6+5+8=19

Minimum 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 ui+vj>=wi,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.

Edge weight Wi,j

842

635

364u1

u2

u3

v1 v2 v3

u1 u2 u3

v3v2v1

4 5 7

0 2 1c(v)

c(u)

c(u,v)=19

Lemma 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)>=w(M)

(2) c(u,v) =w(M) iff M consists of edges xiyj such that ui+vj=wi,j.

In (2), M and c(u,v) are optimal.

u1 u2 u3

v3v2v1

w(M)=6+5+8=19

u1 u2 u3

v3v2v1

4 5 7

0 2 1c(v)

c(u)

c(u,v)=19

since ui+vj>=wi,j for all i, j.

Equality 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 ui+vj=wi,j.

• In the cover, the excess for i,j is ui+vj-wi,j.

Edge weight Wi,j

842

635

364u1

u2

u3

v1 v2 v3

u1 u2 u3

v3v2v1

4 5 7

0 2 1c(v)

c(u)

Kn,n

Algorithm 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.

Algorithm 3.2.9

• Initialization: Let (u,v) be a cover, such that ui=maxj wi,j and vj=0.

4 1 6 2 35 0 3 7 62 3 4 5 83 4 6 3 44 6 5 8 6

67868

0 0 0 0 0

Algorithm 3.2.9

0 0 0 0 0

67868

4 1 6 2 35 0 3 7 62 3 4 5 83 4 6 3 44 6 5 8 6

T T

R

2 5 0 4 32 7 4 0 16 5 4 3 03 2 0 3 24 2 3 0 2

excessmatrix

X

YT T

R

6+0-4 6+0-1 6+0-6 6+0-2

6+0-3

7+0-5 7+0-0 7+0-3 7+0-7

7+0-6

8+0-2 8+0-3 8+0-4 8+0-5

8+0-8

6+0-3 6+0-4 6+0-6 6+0-3

6+0-4

8+0-4 8+0-6 8+0-5 8+0-8

8+0-6

Algorithm 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 Q=RT into Gu,v does not work.

– Decrease the excess for each edge not incident to a vertex in Q=RT.

– No edge has a negative excess after adjusting the cover (u,v).

Algorithm 3.2.9

ε

T T

R

2 5 0 4 32 7 4 0 16 5 4 3 03 2 0 3 24 2 3 0 2

min

X

YT T

R

TTT

0 0 0 0 0

6-17-18

6-18-1

1 4 0 4 21 6 4 0 06 5 5 4 02 1 0 3 15 1 3 0 1

εmin

67868

0 0 0 0 0

0 0 1+1 1+1 0+1

5-16-18-15-17-1

0 3 0 4 20 5 4 0 05 4 5 4 01 0 0 3 12 0 3 0 1

T T T

+1 +1

Algorithm 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 R=XQ and T=YQ. Let ε=min{ui+vj- wi,j : xiX-R, yjY-T}.

3. Decreases ui by ε for xi X-R, and increases vj by ε for yj T.

4. Form the new equality graph and Goto Step 1.

Theorem 3.2.11

• Algorithm 3.2.9 finds a maximum weight matching and a minimum cost cover

1. 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.

2. 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.

Theorem 3.2.11

Case 1: ui’+vj’= ui+vj for edges xiyj from X-R to T or from R to Y-T.

(u’,v’) is a cover

T T

R

2 5 0 4 32 7 4 0 16 5 4 3 03 2 0 3 24 2 3 0 2

0 0 0 0 0

67868

0 0 0+1 0+1 0

6-17-18

6-18-1

1 4 0 4 21 6 4 0 06 5 5 4 02 1 0 3 15 1 3 0 1

R

T T

Theorem 3.2.11

Case 2: ui’+vj’= ui+vj+ε for edges xiyj from R to T.

(u’,v’) is a cover

T T

R

2 5 0 4 32 7 4 0 16 5 4 3 03 2 0 3 24 2 3 0 2

0 0 0 0 0

67868

0 0 0+1 0+1 0

6-17-18

6-18-1

1 4 0 4 21 6 4 0 06 5 5 4 02 1 0 3 15 1 3 0 1

R

T T

Theorem 3.2.11

Case 3: ui’+vj’= ui+vj-ε for edges xiyj from X-R to Y-T.

(u’,v’) is a cover

T T

R

2 5 0 4 32 7 4 0 16 5 4 3 03 2 0 3 24 2 3 0 2

0 0 0 0 0

67868

0 0 0+1 0+1 0

6-17-18

6-18-1

1 4 0 4 21 6 4 0 06 5 5 4 02 1 0 3 15 1 3 0 1

R

T T

since ε=min{ui+vj- wi,j : xiX-R, yjY-T}.

Theorem 3.2.11

3. It terminates only when the equality subgraph has a perfect matching. equal value for the current matching and cover.

4. We need to show Algorithm 3.2.9 always terminate.

5. It suffices to show at each iteration the cost of the cover is reduced at least ε because the cost starts at some value and is bounded below by the weight of a perfect matching.

Theorem 3.2.11

M is not a perfect matching. |Q|=|M|<|X|. |R|+|T|<|X-R|+|R|.

X-R R

T

X

Y

|T|<|X-R|.

Recommended