Lecture 16: Floyd-Fulkerson Tim LaRock larock.t@northeastern.edu - - PowerPoint PPT Presentation

lecture 16 floyd fulkerson
SMART_READER_LITE
LIVE PREVIEW

Lecture 16: Floyd-Fulkerson Tim LaRock larock.t@northeastern.edu - - PowerPoint PPT Presentation

Lecture 16: Floyd-Fulkerson Tim LaRock larock.t@northeastern.edu bit.ly/cs3000syllabus Business Homework 5 released this morning, due next Tuesday the 9 th at 11:59PM Boston time Midterm 2 next Wednesday night through Friday night Question on


slide-1
SLIDE 1

Lecture 16: Floyd-Fulkerson

Tim LaRock larock.t@northeastern.edu bit.ly/cs3000syllabus

slide-2
SLIDE 2

Business

Homework 5 released this morning, due next Tuesday the 9th at 11:59PM Boston time Midterm 2 next Wednesday night through Friday night Question on grades

slide-3
SLIDE 3
  • For any s-t flow ! and any s-t cut (#, %) '() ! ≤ +(, #, %
  • If ! is a flow, (#, %) is a cut, and '()(!) = +(,(#, %), then

! is a max flow and (#, %) is a min cut

≤ . !(/)

  • 1 3456 7→9

≤ . + /

  • 1 3456 7→9

= +(,(#, %) '() ! = . !(/)

  • 1 3456 7→9

− . !(/)

  • 1 3456 9→7

(by non-negativity) (definition of capacity)

Last time: Weak MaxFlow-MinCut Duality

slide-4
SLIDE 4

Augmenting Paths

  • Given a network ; = (<, =, >, ?, + /

) and a flow !, an augmenting path @ is an > → ? path such that !(/) < +(/) for every edge / ∈ @

s 1 2 t 10 10 10 10 20 20 30

slide-5
SLIDE 5

Augmenting Paths

  • Given a network ; = (<, =, >, ?, + /

) and a flow !, an augmenting path @ is an > → ? path such that !(/) < +(/) for every edge / ∈ @

s 1 2 t 10 10 10 10 10 10 20 20 30

Adding uniform flow

  • n an augmenting

path results in a new valid s-t flow!

slide-6
SLIDE 6

Greedy Max Flow

  • Start with ! / = 0 for all edges / ∈ =
  • Find an augmenting path @
  • Repeat until you get stuck

s 1 2 t 10 10 20 20 30

slide-7
SLIDE 7

Does Greedy Work?

  • Greedy gets stuck before finding a max flow
  • How can we get from our solution to the max flow?

s 1 2 t 10 10 20 20 20 20 20 30 s 1 2 t 10 10 20 10 10 20 10 20 20 30

greedy

  • ptimal
slide-8
SLIDE 8

Residual Graphs

  • Original edge: / = D, ' ∈ =.
  • Flow !(/), capacity +(/)
  • Residual edge
  • Allows “undoing” flow
  • / = D, ' and /E = ', D .
  • Residual capacity
  • Residual graph ;3 = <, =

3

  • Edges with positive residual capacity.
  • =! = / ∶ ! / < + /

∪ /H ∶ + / > 0 .

u v

!(/) +(/)

u v

+ / − !(/) !(/) /E /

slide-9
SLIDE 9

Augmenting Paths in Residual Graphs

  • Let ;3 be a residual graph
  • Let @ be an augmenting path in the residual graph
  • Fact: !’ = Augment(;3, @) is a valid flow

Augment(Gf, P) b ¬ the minimum capacity of an edge in P for e Î P if e Î E: f(e) ¬ f(e) + b else: f(e) ¬ f(e) - b return f

slide-10
SLIDE 10

Augmenting Paths in Residual Graphs

  • Let ;3 be a residual graph
  • Let @ be an augmenting path in the residual graph
  • Fact: !’ = Augment(;3, @) is a valid flow

Augment(Gf, P) b ¬ the minimum capacity of an edge in P for e Î P if e Î E: f(e) ¬ f(e) + b else: f(e) ¬ f(e) - b return f Note: This is the same process as the recurrence in Erickson 10.3!

slide-11
SLIDE 11

Ford-Fulkerson Algorithm

Augment(Gf, P) b ¬ the minimum capacity of an edge in P for e Î P if e Î E: f(e) ¬ f(e) + b else: f(e) ¬ f(e) - b return f FordFulkerson(G,s,t,{c(e)}) for e Î E: f(e) ¬ 0 Gf is the residual graph while (there is an s-t path P in Gf) f ¬ Augment(Gf,P) update Gf return f

slide-12
SLIDE 12

Ford-Fulkerson Algorithm

  • Start with ! / = 0 for all edges / ∈ =
  • Find an augmenting path @ in the residual graph
  • Repeat until you get stuck

s 1 2 t 10 10 20 20 30 s 1 2 t

slide-13
SLIDE 13

Ford-Fulkerson Algorithm

  • Start with ! / = 0 for all edges / ∈ =
  • Find an augmenting path @ in the residual graph
  • Repeat until you get stuck

s 1 2 t 10 10 20 20 30 s 1 2 t 10 10 20 20 30

/ ∈ = /E ∉ =

slide-14
SLIDE 14

Ford-Fulkerson Algorithm

  • Start with ! / = 0 for all edges / ∈ =
  • Find an augmenting path @ in the residual graph
  • Repeat until you get stuck

s 1 2 t 10 10 20 20 30 s 1 2 t 10 10 20 20 30

/ ∈ = /E ∉ =

slide-15
SLIDE 15

Ford-Fulkerson Algorithm

  • Start with ! / = 0 for all edges / ∈ =
  • Find an augmenting path @ in the residual graph
  • Repeat until you get stuck

s 1 2 t 10 10 20 20 30 s 1 2 t 10 10 20 20 20 20 20 30

/ ∈ = /E ∉ =

slide-16
SLIDE 16

Ford-Fulkerson Algorithm

  • Start with ! / = 0 for all edges / ∈ =
  • Find an augmenting path @ in the residual graph
  • Repeat until you get stuck

s 1 2 t 10 10 20 20 20 20 20 30 s 1 2 t 10 10 20

/ ∈ = /E ∉ =

10 20 20

slide-17
SLIDE 17

Ford-Fulkerson Algorithm

  • Start with ! / = 0 for all edges / ∈ =
  • Find an augmenting path @ in the residual graph
  • Repeat until you get stuck

s 1 2 t 10 10 20 20 20 20 20 30 s 1 2 t 10 10 20

/ ∈ = /E ∉ =

10 20 20

slide-18
SLIDE 18

Ford-Fulkerson Algorithm

  • Start with ! / = 0 for all edges / ∈ =
  • Find an augmenting path @ in the residual graph
  • Repeat until you get stuck

s 1 2 t 10 10 20 10 10 20 10 20 20 30 s 1 2 t 10 10 20

/ ∈ = /E ∉ =

10 20 20

slide-19
SLIDE 19

Ford-Fulkerson Algorithm

  • Start with ! / = 0 for all edges / ∈ =
  • Find an augmenting path @ in the residual graph
  • Repeat until you get stuck

s t 10 10 s 1 2 t 10 10 20 10 10 20 10 20 20 30 1 2 10 20 20 20

slide-20
SLIDE 20

Running Time of Ford-Fulkerson

  • For integer capacities, ≤ '() !∗ augmentation steps
  • Can perform each augmentation step in U V time
  • find augmenting path in U V
  • augment the flow along path in U W
  • update the residual graph along the path in U W
  • For integer capacities, FF runs in U V ⋅ '() !∗

time

  • U VW time if all capacities are +1 = 1
  • U VWZ[\] time for any integer capacities ≤ Z[\]
  • We can speed FF up by choosing smarter augmenting paths
  • Fattest path: Choose the augmenting path with max capacity
  • Use modified BFS/MST or similar to find max capacity path
  • ≤ V ln '∗ augmenting paths
  • U(V_ ln W ln '∗) total running time
  • Shortest augmenting paths (“shortest augmenting path”)
  • U(V_W) time
slide-21
SLIDE 21

Correctness of Ford-Fulkerson

  • Theorem: ! is a maximum s-t flow if and only if there is no

augmenting s-t path in ;3

  • Strong MaxFlow-MinCut Duality: The value of the max s-t

flow equals the capacity of the min s-t cut

  • We’ll prove that the following are equivalent for all !

1. There exists a cut (#, %) such that '() ! = +(,(#, %) 2. Flow ! is a maximum flow 3. There is no augmenting path in ;3

slide-22
SLIDE 22

Optimality of Ford-Fulkerson

  • Theorem: the following are equivalent for all !

1. There exists a cut (#, %) such that '() ! = +(,(#, %) 2. Flow ! is a maximum flow 3. There is no augmenting path in ;3

slide-23
SLIDE 23

Optimality of Ford-Fulkerson

  • (3 → 1) If there is no augmenting path in ;3, then there is a

cut (#, %) such that '()(!) = +(,(#, %)

slide-24
SLIDE 24

Optimality of Ford-Fulkerson

  • (3 → 1) If there is no augmenting path in ;3, then there is a

cut (#, %) such that '()(!) = +(,(#, %)

  • Sanity check: Is there such a cut in our example?

s t 10 10 s 1 2 t 10 10 20 10 10 20 10 20 20 30 1 2 10 20 20 20

slide-25
SLIDE 25

Optimality of Ford-Fulkerson

  • (3 → 1) If there is no augmenting path in ;3, then there is a

cut (#, %) such that '()(!) = +(,(#, %)

  • Let # be the set of nodes reachable from > in ;3
  • Let % be all other nodes
  • Key observation: no edges in ;3 go from # to %

s t 10 10 s 1 2 t 10 10 20 10 10 20 10 20 20 30 1 2 10 20 20 20

slide-26
SLIDE 26

Optimality of Ford-Fulkerson

  • (3 → 1) If there is no augmenting path in ;3, then there is a

cut (#, %) such that '()(!) = +(,(#, %)

  • Let # be the set of nodes reachable from > in ;3
  • Let % be all other nodes
  • Key observation: no edges in ;3 go from # to %
  • If / is # → %, then ! / = + /
  • If / is % → #, then ! / = 0
  • riginal network

s t

A B

slide-27
SLIDE 27

Optimality of Ford-Fulkerson

  • (3 → 1) If there is no augmenting path in ;3, then there is a

cut (#, %) such that '()(!) = +(,(#, %)

  • Let # be the set of nodes reachable from > in ;3
  • Let % be all other nodes
  • Key observation: no edges in ;3 go from # to %
  • If / is # → %, then ! / = + /
  • If / is % → #, then ! / = 0
  • riginal network

s t

A B

'() ! = . ! / − . !(/)

  • 1:9→7
  • 1:7→9

= . ! /

  • 1:7→9

= . + /

  • 1:7→9

= +(,(#, %)

slide-28
SLIDE 28

Optimality of Ford-Fulkerson

  • (3 → 1) If there is no augmenting path in ;3, then there is a

cut (#, %) such that '()(!) = +(,(#, %)

  • Let # be the set of nodes reachable from > in ;3
  • Let % be all other nodes
  • Key observation: no edges in ;3 go from # to %
  • If / is # → %, then ! / = + /
  • If / is % → #, then ! / = 0
  • riginal network

s t

A B

'() ! = . ! / − . !(/)

  • 1:9→7
  • 1:7→9

= . ! /

  • 1:7→9

= . + /

  • 1:7→9

= +(,(#, %)

slide-29
SLIDE 29

Optimality of Ford-Fulkerson

  • (3 → 1) If there is no augmenting path in ;3, then there is a

cut (#, %) such that '()(!) = +(,(#, %)

  • Let # be the set of nodes reachable from > in ;3
  • Let % be all other nodes
  • Key observation: no edges in ;3 go from # to %
  • If / is # → %, then ! / = + /
  • If / is % → #, then ! / = 0
  • riginal network

s t

A B

= . + /

  • 1:7→9

= +(,(#, %)

No augmenting path in ;3 implies that we have a maximum cut!

= . ! /

  • 1:7→9

'() ! = . ! / − . !(/)

  • 1:9→7
  • 1:7→9
slide-30
SLIDE 30

Summary

  • The Ford-Fulkerson Algorithm solves maximum s-t flow
  • Running time U V ⋅ '() !∗

in networks with integer capacities

  • Strong MaxFlow-MinCut Duality: max flow = min cut
  • The value of the maximum s-t flow equals the capacity of the

minimum s-t cut

  • If !∗ is a maximum s-t flow, then the set of nodes reachable from s

in ;3∗ gives a minimum cut

  • Given a max-flow, can find a min-cut in time U W + V
  • Every graph with integer capacities has an integer

maximum flow

  • Ford-Fulkerson will return an integer maximum flow
slide-31
SLIDE 31

Applications of Network Flow

slide-32
SLIDE 32

Applications of Network Flow

  • Algorithms for maximum flow can be used to solve:
  • Bipartite Matching
  • Disjoint Paths
  • Survey Design
  • Matrix Rounding
  • Auction Design
  • Fair Division
  • Project Selection
  • Baseball Elimination
  • Airline Scheduling
slide-33
SLIDE 33

Applications of Network Flow

  • Algorithms for maximum flow can be used to solve:
  • Bipartite Matching
  • Disjoint Paths
  • Survey Design
  • Matrix Rounding
  • Auction Design
  • Fair Division
  • Project Selection
  • Baseball Elimination
  • Airline Scheduling

In general: If a problem can be solved in polynomial time, maximum flow can be used to solve it!

slide-34
SLIDE 34

Reduction

  • Definition: a reduction is an efficient algorithm

that solves problem A using calls to function that solves problem B.

slide-35
SLIDE 35

Mechanics of Reductions

  • What exactly is a problem?
  • A set of legal inputs b
  • Ex: An array of numbers #[1. . W]
  • A set e(f) of legal outputs for each f ∈ b
  • Ex: The array # in sorted order
  • Example: integer maximum flow
  • Input: ; = (<, =, >, ?, +1 ) where +1 is an integer for

every / ∈ =

  • Output: A maximum flow {! / } for ; where !(/) is an

integer for every / ∈ = such that 0 ≤ ! / ≤ +1

slide-36
SLIDE 36

Mechanics of Reductions

  • What exactly is a problem?
  • A set of legal inputs b
  • Ex: An array of numbers #[1. . W]
  • A set e(f) of legal outputs for each f ∈ b
  • Ex: The array # in sorted order
  • Example: integer maximum flow
  • Input: ; = (<, =, >, ?, +1 ) where +1 is an integer for

every / ∈ =

  • Output: A maximum flow {! / } for ; where !(/) is an

integer for every / ∈ = such that 0 ≤ ! / ≤ +1

slide-37
SLIDE 37

Mechanics of Reductions

SolveA

Output y in B(x) for Problem B Input x for Problem B Input u for Problem A Output v in A(u) for Problem A

In the simplest case, we just call SolveA a single time. In fact we may use SolveA as a subroutine to a more complex reduction.

slide-38
SLIDE 38

When is a Reduction Correct?

SolveA

Output y in B(x) for Problem B Input x for Problem B Input u for Problem A Output v in A(u) for Problem A

Then for every valid input i, if ' is a valid output in # D , then j is a valid

  • utput in %(i).

Assume that for valid input D, SolveA returns a valid output ' in #(D).

slide-39
SLIDE 39

What is the Running Time?

SolveA

Output y in B(x) for Problem B Input x for Problem B Input u for Problem A Output v in A(u) for Problem A

1 2 3

Running time: + +

1 2 3

slide-40
SLIDE 40

Example: Minimum Cut

SolveA

Output y in B(x) for Problem B Input x for Problem B Input u for Problem A Output v in A(u) for Problem A

A = MaxFlow B = MinCut

Input i for B: ; = (<, =, >, ?, +1 ) Input D for A: ; = (<, =, >, ?, +1 ) Output ' ∈ #(D): ; = (<, =, >, ?, +1 ) Output j ∈ %(i): ; = (<, =, >, ?, +1 )

  • 1. Take !, compute the residual graph ;3
  • 2. Find the nodes reachable from > in ;3
  • 3. Output these nodes
slide-41
SLIDE 41

Example: Median

SolveA

Output y in B(x) for Problem B Input x for Problem B Input u for Problem A Output v in A(u) for Problem A

Input i for B: Array of length W, # 1. . W Input D for A: Same array Output ' ∈ #(D): Sorted version of #[1. . W] Output y ∈ %(i): #[ l

_ ]

A = MergeSort B = Median

slide-42
SLIDE 42

Wrap-up

Next time we will see examples of using reductions to solve problems Suggested Reading:

  • Reductions on Wikipedia: https://en.wikipedia.org/wiki/Reduction_(complexity)
  • (very optional for now) Erickson Chapter 12
  • He talks about reductions starting in 12.5
  • The first 4 sections will be more relevant for the last week of classes

Work on homework 5!