Today Flow review Augmenting paths Ford-Fulkerson Algorithm Intro - - PowerPoint PPT Presentation

today
SMART_READER_LITE
LIVE PREVIEW

Today Flow review Augmenting paths Ford-Fulkerson Algorithm Intro - - PowerPoint PPT Presentation

Today Flow review Augmenting paths Ford-Fulkerson Algorithm Intro to cuts (reason: prove correctness) Flow Networks s = source, t = sink. c(e) = capacity of edge e Capacity condition: 0 f(e) c(e) Conservation condition: for v V


slide-1
SLIDE 1

Today

Flow review Augmenting paths Ford-Fulkerson Algorithm Intro to cuts (reason: prove correctness)

slide-2
SLIDE 2

s = source, t = sink. c(e) = capacity of edge e Capacity condition: 0 ≤ f(e) ≤ c(e) Conservation condition: for v ∈ V – {s, t}: ∑ f(e) = ∑ f(e)

Flow Networks

e into v e out of v

s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4 source sink flow = 4 4 4 4

slide-3
SLIDE 3

The value of a flow f is: v(f) = ∑ f(e)

Flows

e out of s

s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4 source sink flow = 4 4 4 4

value = 4

slide-4
SLIDE 4

The value of a flow f is: v(f) = ∑ f(e)

Flows

e out of s

s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4 source sink flow = 10 9 4 10 9 1 6 1 10 9 6

value = 24

slide-5
SLIDE 5

Find s-t flow of maximum value.

Maximum Flow Problem

s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4 source sink flow = 10 1 10 5 13 9 8 3 13 9 9

value = 28

slide-6
SLIDE 6

Towards a Max-Flow Algorithm

Key idea: repeatedly choose paths and “augment” the amount of flow on those paths as much as possible until capacities are met

slide-7
SLIDE 7

Towards a Max Flow Algorithm

Problem: possible to get stuck at a flow that is not maximum, no more paths with excess capacity

s 1 2 t 10 10 20 20 30

Flow value = 0

× × ×

20 20 20

×

20

slide-8
SLIDE 8

Residual Graph

Original edge: e = (u, v) ∈ E. Flow f(e), capacity c(e). Create two residual edges Forward edge e = (u, v) with capacity c(e) - f(e) Backward/reverse edge e’ = (v, u) with capacity f(e) Residual graph: Gf = (V , Ef ). Ef = edges with positive residual capacity Ef = {e : f(e) < c(e)} ∪ {e’ : f(e) > 0}

u v 17 6 u v 11

residual capacity

6

slide-9
SLIDE 9

Augmenting Path

Definition: an s-t path P in Gf is an augmenting path Idea: use an augmenting path to augment flow in G Increase flow on forward edges Decrease flow on backward edges Definition: let bottleneck(P, f) be the minimum residual capacity (i.e., capacity in Gf) of any edge in P

Example on board

slide-10
SLIDE 10

Augmenting Path

Augment(f, P) { b = bottleneck(P, f) foreach e = (u,v) ∈ P { if e is a forward edge

f(e) = f(e) + b

else let e’ = (v, u) f(e’) = f(e’) - b } return f } / / edge on P with least residual capacity

Use path P in Gf to to update flow f

/ / forward edge: increase flow / / backward edge: decrease flow

slide-11
SLIDE 11

Augmenting Path

Claim: Let f be a flow and let f’ = Augment(f, P). Then f’ is a flow. Proof idea: verify capacity and conservation conditions 1) Capacity: by design of residual graph 2) Conservation: check that net change at each node is zero Proof sketch on board

slide-12
SLIDE 12

Ford-Fulkerson Algorithm

Ford-Fulkerson(G, s, t) { foreach e ∈ E f(e) = 0 // initially, no flow Gf = copy of G // residual graph = original graph while (there exists an s-t path P in Gf) { f = Augment(f, P) // change the flow update Gf // build a new residual graph } return f }

Repeat: find an augmenting path, and augment!

slide-13
SLIDE 13

Example

s 2 3 4 5 t

10 10 9 8 4 10 10 6 2 G:

Flow value = 0

slide-14
SLIDE 14

Example

s 2 3 4 5 t

10 10 9 8 4 10 10 6 2

G Flow value = 0

s 2 3 4 5 t

10 9 4 10 6 2

Gf

10 8 10

× × ×

8 8 8

× 8

slide-15
SLIDE 15

Example

s 2 3 4 5 t

10 10 9 8 4 10 10 6 2

8 8

G Flow value = 8

s 2 3 4 5 t

10 4 10 6

Gf

8

8 8 8 9 2 2 2

× × ×

10 10 2

× 2 × 10

slide-16
SLIDE 16

Example

s 2 3 4 5 t

10 10 9 8 4 10 10 6 2

10 2 10 2

G Flow value = 10

s 2 3 4 5 t

4

Gf

8

8 10 10 2 2 10 10 6 7

× × × ×

6 8 6 6

× 16

slide-17
SLIDE 17

Example

s 2 3 4 5 t

10 10 9 8 4 10 10 6 2

10 10 2

G Flow value = 16

s 2 3 4 5 t

Gf

8

8 10 10 8 6 1

6 8 6 6

6 6 4 2 4 4

×8 × × 2 × 8 × 18

slide-18
SLIDE 18

Example

s 2 3 4 5 t

10 10 9 8 4 10 10 6 2

10 10

G Flow value = 18

s 2 3 4 5 t

Gf

8

10 10 8 6

8 6

8 8 2

8 2 8

2 8 1 2 2 2

× 9 × 9 × 7 × 3 × 9 × 19

slide-19
SLIDE 19

max flow = 19

Example

s 2 3 4 5 t

10 10 9 8 4 10 10 6 2

10 10

G

s 2 3 4 5 t

Gf

10 10 9 6

6

9 9 2 3 7 1 1 1

9 9 7 3 9

1

slide-20
SLIDE 20

Termination

  • Assumption. All capacities are positive integers.
  • Invariant. Every flow value f(e) and every residual

capacity cf (e) remains an integer throughout the algorithm.

  • Theorem. Let OPT = value of max flow. The algorithm

terminates in at most OPT iterations, with OPT ≤ C, the total capacity of the edges leaving the source. Proof?

slide-21
SLIDE 21

Running Time?

There are at most C augment operations. How long does it take for each? Find a residual path Compute bottleneck capacity Update flow Update residual graph

O(m+n) O(m) O(m) O(m) Total running time: O(C(m+n))

slide-22
SLIDE 22

B A

An s-t cut is a partition (A, B) of V with s ∈ A and t ∈ B. The capacity of a cut (A, B) is c(A,B) = Σ c(e)

Cuts

e out of A

s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4 source sink

capacity of cut = 30

slide-23
SLIDE 23

B A

Cuts

s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4 source sink

capacity of cut = 9 + 15 + 8 + 30 = 62 (Capacity is sum of weights on edges leaving A.)

slide-24
SLIDE 24

B A

Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then, the net flow sent across the cut is equal to the amount leaving s.

Flows and Cuts

s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4 source sink 10 9 4 10 9 1 6 1 10 9 6

value = 24 ∑ f(e) - ∑ f(e) = v(f)

e out of a e into a

slide-25
SLIDE 25

B A

Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then, the net flow sent across the cut is equal to the amount leaving s.

Flows and Cuts

s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4 source sink 10 9 4 10 9 1 6 1 10 9 6

value = 24 ∑ f(e) - ∑ f(e) = v(f)

e out of a e into a

slide-26
SLIDE 26

B A

Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then, the net flow sent across the cut is equal to the amount leaving s.

Flows and Cuts

s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4 source sink 10 9 4 10 9 1 6 1 10 9 6

value = 24 ∑ f(e) - ∑ f(e) = v(f)

e out of a e into a

slide-27
SLIDE 27

Flows and Cuts

Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then ∑ f(e) - ∑ f(e) = v(f). Proof: v(f) = ∑ f(e) by definition = ∑ ( ∑ f(e) - ∑ f(e) ) = ∑ f(e) - ∑ f(e)

by flow conservation, all terms except v = s are 0

e out of A e into A e out of s e out of v v ∈ A e out of A e into A e into v

if both endpoints of e are in A, there will be canceling terms for that edge

slide-28
SLIDE 28

Max-Flow Min-Cut

There is a deep connection between flows and cuts in networks Next time, we will prove that Ford-Fulkerson is correct by proving the Max-Flow Min-Cut Theorem