3.2.1. augmenting path algorithm two theorems to recall: theorem 3.1.10 (berge). a matching m in a...

23
3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M- augmenting path. Theorem 3.1.16 (König,Egerváry) If G is bipartite, then a maximum matching and a minimum vertex cover of G have the same size (’(G)=(G)). Augmenting path algorithm for maximum bipartite matching Input: X,Y-bigraph. Output: M,Q with |M|=|Q| Use modified breadth-first search to find augmenting paths. Initialize with empty matching and iteratively increase by 1. 1

Upload: ralph-goodman

Post on 15-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

3.2.1. Augmenting path algorithm

Two theorems to recall:

Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting path.

Theorem 3.1.16 (König,Egerváry) If G is bipartite, then a maximum matching and a minimum vertex cover of G have the same size (’(G)=(G)).

Augmenting path algorithm for maximum bipartite matching

Input: X,Y-bigraph. Output: M,Q with |M|=|Q|

Use modified breadth-first search to find augmenting paths.

Initialize with empty matching and iteratively increase by 1.

Produce a vertex cover of same size to certify the output.

1

Page 2: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

3.2.1. Augmenting path algorithm

Algorithm (Augmenting path algorithm)

Input An X,Y-bigraph G, a (partial matching) M, and

the set U of M-unsaturated vertices of X

Idea Explore augmenting paths to all possible vertices, marking explored vertices and their predecessors, and tracking reached vertices SµX and TµY

Initialization S=U and T=;Iteration If S is all marked, stop and output M and Q=T[(X-S).

Otherwise, explore from an unmarked x2S.

For any edge xy2E(G)-M: (1) mark y and put y in T. (2) For any edge yw2M, mark w and put w in S.

Stop if an unsaturated y is found; report an M-augmenting path.

Otherwise continue exploring in this fashion.

2

Page 3: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Augmenting path algorithm example

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

Iteration 1 Input: M=; S=U=X, T=;, x=x1

3

SSS S S

Page 4: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Augmenting path algorithm example

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

Iteration 1: y1 unsaturated. Halt and augment M.

4

T

SSS S S

Page 5: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Augmenting path algorithm example

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

5

Iteration 2 Input: M={x1y1} S={x2, x3, x4, x5}, T=;, x=x2

SSS S

Page 6: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Augmenting path algorithm example

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

6

Iteration 2: From x2, explore y1 and its matched neighbors

T

SSS S S

Page 7: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Augmenting path algorithm example

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

7

Iteration 2: From x1, explore y2 and its matched neighbors.y2 is unsaturated: halt and augment M.

T

SSS S S

T

Page 8: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Augmenting path algorithm example

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

8

Iteration 3 Input: M={x1y2, x2y1} S={x3, x4, x5}, T=;, x=x3

SS S

Page 9: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Augmenting path algorithm example

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

9

Iteration 3: From x3, explore y3 and its matched neighbors.y3 unsaturated, so terminate and report augmenting path.

SS S

T

Page 10: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Augmenting path algorithm example

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

10

Iteration 4 Input: M={x1y2, x2y1, x3y3} S={x4, x5}, T=;, x=x4

S S

Page 11: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Augmenting path algorithm example

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

11

Iteration 4: From x4, explore y2,y3 and their (distinct) matched neighbors.

SSS

T T

S

Page 12: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Augmenting path algorithm example

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

12

Iteration 4: From x1, and x3, explore to find y1 via non-matching edges. Explore back up to x2 via a matching edge.

SSS

T T

S

T

S

Page 13: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Augmenting path algorithm example

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

13

Iteration 4 (continued): x5 is still unexplored. Explore from x5 to find unsaturated vertex y4. Terminate and report an M-augmenting path.

SSS S

T TT

S

T

Page 14: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Augmenting path algorithm example

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

14

Iteration 5 Input: M={x1y2,x2y1,x3y3,x5y4} S={x4}, T=;, x=x4

S

Page 15: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Augmenting path algorithm example

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

15

Iteration 5: From x4, explore y2,y3 and their (distinct) matched neighbors.

SSS

T T

Page 16: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Augmenting path algorithm example

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

16

Iteration 5: From x1, and x3, explore to find y1 via non-matching edges. Explore back up to x2 via a matching edge.

SSS S

T TT

Page 17: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Augmenting path algorithm example

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

17

Termination: No vertex of S is unexplored.Output: maximum matching M={x1y2,x2y1,x3y3,x5y4}Minimum vertex cover Q=T[(X-S) ={x5,y1,y2,y3}.

SSS S

T TT

Q

QQQ

Page 18: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Maximum Weighted Transversal

0 0 0 0 0

6 4 4 4 3 6

4 1 1 4 3 4

5 1 4 5 3 5

9 5 6 4 7 9

8 5 3 6 8 3

Transversal: A set M of n entries of an n£n, matrix, no two in the same column or row. Its weight is the sum of the entries.Cover: A pair of vectors (u,v)=(u1,…,un;v1,…,vn) such that every entry wi,j of the matrix satisfies wi,j · ui+vj.

u

v

w(M)=23

w(u,v)=32

Page 19: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

3.2.7. Maximum Transversal = Minimum Cover

3.2.7. Lemma. (Duality of weighted matching and weighted cover problems) For a perfect matching M and a weighted cover (u,v) in a weighted bipartite graph G, c(u,v)¸w(M). Also, c(u,v)=w(M) iff M consists of edges xiyj such that ui+vj=wi,j. In this case, M and (u,v) are optimal.

0 1 2

4 4 4 4

2 1 1 4

3 1 4 5

u

v

w(M)=12

w(u,v)=12

Page 20: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

3.2.9. Hungarian Algorithm (Maximum Weighted Matching/Minimum Weighted Cover)

Algorithm (Hungarian Algorithm)

Input An n£n matrix of nonnegative edge weights of Kn,n

Idea Iteratively adjust the cover (u,v) until the equality subgraph Gu,v has a perfect matching

Initialization Any cover (u,v), such as ui=maxi wi,j and vj=0

Iteration Find a maximum matching M in Gu,v. If M is a perfect matching, stop and output M and (u,v) as a maximum weight matching and minimum weight cover.

Otherwise:

Let = smallest excess in Gu,v of an edge from X-R to Y-T.

Replace uià ui- for all xi2 X-R.

Replace vjà vj+ for all yj2 Y-T.

Form the new equality subgraph Gu,v and repeat.

20

Page 21: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Hungarian Algorithm Example

0 0 0 0 06 4 1 6 2 3

7 5 0 3 7 6

8 2 3 4 5 8

6 3 4 6 3 4

8 4 6 5 8 6

uv

w(M)=21 w(u,v)=35

0 0 0 0 0

6 2 5 0 4 3

7 2 7 4 0 1

8 6 5 4 3 0

6 3 2 0 3 2

8 4 2 3 0 2

uv excess matrix

T T

R

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

T T

R

Equality subgraphvertex cover: Q=R[T

Add =1 to T, subtract from X-R.

Page 22: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Hungarian Algorithm Example

0 0 1 1 05 4 1 6 2 3

6 5 0 3 7 6

8 2 3 4 5 8

5 3 4 6 3 4

7 4 6 5 8 6

uv

w(M)=21 w(u,v)=33

0 0 1 1 0

5 1 4 0 4 2

6 1 6 4 0 0

8 6 5 5 4 0

5 2 1 0 3 1

7 3 1 3 0 1

uv excess matrix

T T

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

T T T

Equality subgraphvertex cover: Q=R[T

T

Add =1 to T, subtract from X-R.

Page 23: 3.2.1. Augmenting path algorithm Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting

Hungarian Algorithm Example

0 0 2 2 14 4 1 6 2 3

5 5 0 3 7 6

7 2 3 4 5 8

4 3 4 6 3 4

6 4 6 5 8 6

uv

w(M)=31 w(u,v)=31

0 0 2 2 1

4 0 3 0 4 2

5 0 5 4 0 0

7 5 4 5 4 0

4 1 0 0 3 1

6 2 0 3 0 1

uv excess matrix

T T

x1 x2 x3 x4 x5

y1 y2 y3 y4 y5

T

Matching weight=cover weight.Halt and output M, and (u,v).

equality subgraph