nick mckeown spring 2012 maximum matching algorithms ee384x packet switch architectures

18
Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Upload: bruce-thomas

Post on 18-Dec-2015

215 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Nick McKeown

Spring 2012

Maximum Matching Algorithms

EE384xPacket Switch Architectures

Page 2: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Network Flows

Sources

Sinkt

a c

b d

10

10

10

1

1

1

10

10

• Let G = [V,E] be a directed graph with capacity cap(v,w) on edge [v,w].• A flow is an (integer) function, f, that is chosen for each edge so that• We wish to maximize the flow allocation.

( , ), .( ) capf vv ww

Page 3: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

A maximum network flow exampleBy inspection

Sources

Sinkt

a c

b d

10

10

10

1

1

1

10

10

Step 1:

Sources

Sinkt

a c

b d

10, 10

10

10, 10

1

1

1

10

10, 10

Flow is of size 10

Page 4: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

A maximum network flow example

Sources

Sinkt

a c

b d

10, 10

10, 1

10, 10

1

1

1, 1 10, 1

10, 10

Step 2:

Flow is of size 10+1 = 11

Sources

Sinkt

a c

b d

10, 10

10, 2

10, 9

1,1

1,1

1, 1 10, 2

10, 10

Maximum flow:

Flow is of size 10+2 = 12

Not obvious

Page 5: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Ford-Fulkerson augmenting paths

1. Set f(v,w) = -f(w,v) on all edges.2. Define a Residual Graph, R, in which res(v,w) =

cap(v,w) – f(v,w)3. Find paths from s to t for which there is positive

residue.4. Increase the flow along the paths to augment

them by the minimum residue along the path.5. Keep augmenting paths until there are no more

to augment.

Page 6: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Example of Residual Graph

s t

a c

b d

10, 10

10

10, 10

1

1

1

10

10, 10

Flow is of size 10

t

a c

b d

10

10

10

1

1

1

10

10

s

res(v,w) = cap(v,w) – f(v,w) Residual Graph, R

Augmenting path

Page 7: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Example of Residual Graph

s t

a c

b d

10, 10

10, 1

10, 10

1

1

1, 1 10, 1

10, 10

Step 2:

Flow is of size 10+1 = 11

s t

a c

b d

10

1

10

1

1

1

1

10

Residual Graph

9 9

Page 8: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Example of Residual Graph

s t

a c

b d

10, 10

10, 2

10, 9

1, 1

1, 1

1, 1 10, 2

10, 10

Step 3:

Flow is of size 10+2 = 12

s t

a c

b d

10

2

9

1

1

1

2

10

Residual Graph

8 8

1

Page 9: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Complexity of network flow

• In general, it is possible to find a solution by considering at most |V|.|E| paths, by picking shortest augmenting path first.

• There are many variations, such as picking most augmenting path first.

Page 10: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Finding a maximum size match

Q: How do we find the maximum size (weight) match?

A

B

C

D

E

F

1

2

3

4

5

6

Page 11: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Network flows and bipartite matching

Finding a maximum size bipartite matching is equivalent to solving a network flow problem with capacities and flows of size 1.

A 1

Sources

Sinkt

B

C

D

E

F

2

3

4

5

6

Page 12: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Network flows and bipartite matchingFord-Fulkerson method

A 1

s t

B

C

D

E

F

2

3

4

5

6

Residual Graph for first three paths:

Page 13: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Network flows and bipartite matching

A 1

s t

B

C

D

E

F

2

3

4

5

6

Residual Graph for next two paths:

Page 14: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Network flows and bipartite matching

A 1

s t

B

C

D

E

F

2

3

4

5

6

Residual Graph for augmenting path:

Page 15: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Network flows and bipartite matching

A 1

s t

B

C

D

E

F

2

3

4

5

6

Residual Graph for last augmenting path:

Note that the path augments the match: no input and outputis removed from the match during the augmenting step.

Page 16: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Network flows and bipartite matching

A 1

s t

B

C

D

E

F

2

3

4

5

6

Maximum flow graph:

Page 17: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Network flows and bipartite matching

A 1

B

C

D

E

F

2

3

4

5

6

Maximum Size Matching:

Page 18: Nick McKeown Spring 2012 Maximum Matching Algorithms EE384x Packet Switch Architectures

Complexity of Maximum Matchings

• Maximum Size Matchings:– Algorithm by Dinic O(N5/2)

• Maximum Weight Matchings– Algorithm by Kuhn O(N3)

• In general:– Hard to implement in hardware– Slooooow.