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

3.2.1. Augmenting path algorithm

  • Upload
    imaran

  • View
    87

  • Download
    1

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Page 1: 3.2.1. Augmenting path algorithm

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 matchingInput: 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

3.2.1. Augmenting path algorithm

Algorithm (Augmenting path algorithm)Input An X,Y-bigraph G, a (partial matching) M, andthe set U of M-unsaturated vertices of XIdea Explore augmenting paths to all possible vertices, marking explored vertices and their predecessors, and tracking reached vertices SµX and TµYInitialization 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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 5u

v

w(M)=12

w(u,v)=12

Page 20: 3.2.1. Augmenting path algorithm

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=0Iteration 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

Hungarian Algorithm Example

0 0 0 0 06 4 1 6 2 37 5 0 3 7 68 2 3 4 5 86 3 4 6 3 48 4 6 5 8 6

uv

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

0 0 0 0 06 2 5 0 4 37 2 7 4 0 18 6 5 4 3 06 3 2 0 3 28 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

Hungarian Algorithm Example

0 0 1 1 05 4 1 6 2 36 5 0 3 7 68 2 3 4 5 85 3 4 6 3 47 4 6 5 8 6

uv

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

0 0 1 1 05 1 4 0 4 26 1 6 4 0 08 6 5 5 4 05 2 1 0 3 17 3 1 3 0 1

uv excess matrix

T Tx1 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

Hungarian Algorithm Example

0 0 2 2 14 4 1 6 2 35 5 0 3 7 67 2 3 4 5 84 3 4 6 3 46 4 6 5 8 6

uv

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

0 0 2 2 14 0 3 0 4 25 0 5 4 0 07 5 4 5 4 04 1 0 0 3 16 2 0 3 0 1

uv excess matrix

T Tx1 x2 x3 x4 x5

y1 y2 y3 y4 y5

T

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

equality subgraph