Objectives Network Flow Max flow Min cut March 29, 2019 CSCI211 - - PDF document

objectives
SMART_READER_LITE
LIVE PREVIEW

Objectives Network Flow Max flow Min cut March 29, 2019 CSCI211 - - PDF document

3/29/19 Objectives Network Flow Max flow Min cut March 29, 2019 CSCI211 - Sprenkle 1 Motivating Flow Network Problems Modeling transportation networks Edges: carry traffic Nodes: pass traffic between edges Can represent


slide-1
SLIDE 1

3/29/19 1

Objectives

  • Network Flow

Ø Max flow Ø Min cut

March 29, 2019 1 CSCI211 - Sprenkle

Motivating Flow Network Problems

  • Modeling transportation networks

Ø Edges: carry traffic Ø Nodes: pass traffic between edges

  • Can represent many different types of problems

Ø Instead of looking at all possibilities, formulate as a flow problem

March 29, 2019 CSCI211 - Sprenkle 2

slide-2
SLIDE 2

3/29/19 2

Flow Network

  • G = (V, E) = directed graph, no parallel edges
  • Two distinguished nodes: s = source, t = sink
  • c(e) = capacity of edge e, > 0

March 29, 2019 CSCI211 - Sprenkle 3 s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4

capacity

source sink

Flows: Definitions

  • An s-t flow is a function that satisfies

Ø Capacity condition: For each e ∈ E: 0 ≤ f(e) ≤ c(e) Ø Conservation condition: For each v ∈ V – {s, t}: ∑e into y f(e) = ∑e out of y f(e)

March 29, 2019 CSCI211 - Sprenkle 4

Flow can’t exceed capacity Flow in == Flow out

4 4 4

capacity flow

4

15

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

slide-3
SLIDE 3

3/29/19 3

Flows: Definitions

  • The value of a flow f is v(f) = ∑e out of s f(e)

March 29, 2019 CSCI211 - Sprenkle 5

4 4 4

Value = 4

capacity flow

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

Maximum Flow Problem

  • Make network most efficient

Ø Use most of available capacity

March 29, 2019 CSCI211 - Sprenkle 6 10

9

9 14 4 10 4 8 9 1 14

capacity flow

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

Value = 28

Goal: Find s-t flow of maximum value

slide-4
SLIDE 4

3/29/19 4

Towards a Max Flow Algorithm

  • Greedy algorithm

Ø Start all edges e Î E at f(e) = 0 Ø Find an s-t path P with the most capacity: f(e) < c(e) Ø Augment flow along path P Ø Repeat until you get stuck

March 29, 2019 CSCI211 - Sprenkle 7

s 1 2 t 10 10 20 20 30

Flow value = 0

Towards a Max Flow Algorithm

  • Greedy algorithm

Ø Start all edges e Î E at f(e) = 0 Ø Find an s-t path P with the most capacity: f(e) < c(e) Ø Augment flow along path P Ø Repeat until you get stuck

March 29, 2019 CSCI211 - Sprenkle 8

s 1 2 t 10 10 20 20 30

X X X

20 20 20

Is this optimal?

Flow value = 20

slide-5
SLIDE 5

3/29/19 5

Towards a Max Flow Algorithm

  • Greedy algorithm

Ø Start all edges e Î E at f(e) = 0 Ø Find an s-t path P with the most capacity: f(e) < c(e) Ø Augment flow along path P Ø Repeat until you get stuck

March 29, 2019 CSCI211 - Sprenkle 9

greedy = 20

s 1 2 t

20 10 10 20 30 20 20 20

  • pt = 30

s 1 2 t

20 10 10 20 30 20 10 10 10 20

locally optimality does not Þ global optimality

RESIDUAL GRAPHS

Towards a solution…

March 29, 2019 CSCI211 - Sprenkle 10

slide-6
SLIDE 6

3/29/19 6

Towards a Residual Graph

  • Original edge: e = (u, v) Î E

Ø Flow f(e), capacity c(e)

March 29, 2019 CSCI211 - Sprenkle 11

u v 17 6 capacity

flow

Towards a Residual Graph

  • Original edge: e = (u, v) Î E

Ø Flow f(e), capacity c(e)

  • Residual edge

Ø e = (u, v) w/ capacity c(e) - f(e) Ø eR = (v, u) with capacity f(e)

  • To undo flow

March 29, 2019 CSCI211 - Sprenkle 12

u v 11 residual capacity 6 residual capacity u v 17 6 capacity

flow

slide-7
SLIDE 7

3/29/19 7

Residual Graph: Gf

  • Original edge: e = (u, v) Î E

Ø Flow f(e), capacity c(e)

  • Residual edge

Ø e = (u, v) w/ capacity c(e) - f(e) Ø eR = (v, u) with capacity f(e)

  • To undo flow
  • Residual graph: Gf = (V, Ef)

Ø Residual edges with positive residual capacity Ø Ef = {e : f(e) < c(e)} È {eR : f(e) > 0}

March 29, 2019 CSCI211 - Sprenkle 13

u v 11 residual capacity 6 residual capacity

Forward edges Backward edges

u v 17 6 capacity

flow

Applying Residual Graph

  • Used to find the maximum flow

Ø Use similar idea to greedy algorithm

  • Residual path: simple s-t path in Gf

Ø Also known as augmenting path

March 29, 2019 CSCI211 - Sprenkle 14

slide-8
SLIDE 8

3/29/19 8

Augmenting Path Algorithm

March 29, 2019 CSCI211 - Sprenkle 15

Ford Ford-Fulkerson(G, s, t, c): Fulkerson(G, s, t, c): foreach foreach e Î E f(e) = 0 # initially no flow Gf = residual graph while while there exists augmenting path P f = Augment(f, c, P) # change the flow update Gf # build a new residual graph return return f Augment(f, c, P): Augment(f, c, P): b = bottleneck(P) # edge on P with least capacity foreach foreach e Î P if if (e Î E) f(e) = f(e) + b # forward edge, é flow else else f(eR) = f(e) - b # forward edge, ê flow return return f

c=capacity

Ford-Fulkerson Algorithm

March 29, 2019 CSCI211 - Sprenkle 16 s 2 3 4 5 t

10 10 9 8 4 10 10 6 2

G: Flow value = 0 flow capacity

slide-9
SLIDE 9

3/29/19 9

Ford-Fulkerson Algorithm

March 29, 2019 CSCI211 - Sprenkle 17 s 2 3 4 5 t

10 10 9 8 4 10 10 6 2

G: Flow value = 0 flow

What does the residual graph look like?

capacity

Ford-Fulkerson Algorithm

March 29, 2019 CSCI211 - Sprenkle 18 s 2 3 4 5 t

10 10 9 8 4 10 10 6 2

G: Flow value = 0 flow

s 2 3 4 5 t

Gf: capacity

slide-10
SLIDE 10

3/29/19 10

Ford-Fulkerson Algorithm

March 29, 2019 CSCI211 - Sprenkle 19 s 2 3 4 5 t

10 10 9 8 4 10 10 6 2

G: Flow value = 0 flow

s 2 3 4 5 t

10 9 4 10 6 2

Gf:

10 8 10

residual capacity

Bottleneck

capacity

Ford-Fulkerson Algorithm

March 29, 2019 CSCI211 - Sprenkle 20 s 2 3 4 5 t

10 10 9 8 4 10 10 6 2 8 8 8

G:

s 2 3 4 5 t

10 4 10 6

Gf:

8 8 8 9 2 2 2 10 2 10 X X X 2 X

Flow value = 8

slide-11
SLIDE 11

3/29/19 11

Ford-Fulkerson Algorithm

March 29, 2019 CSCI211 - Sprenkle 21 s 2 3 4 5 t

10 10 9 8 4 10 10 6 2 10 2 10 8 2

G:

s 2 3 4 5 t

4 2

Gf:

10 8 10 2 10 7 10 6 X 6 6 6 X X 8 X

Flow value = 10

Ford-Fulkerson Algorithm

March 29, 2019 CSCI211 - Sprenkle 22 s 2 3 4 5 t

10 10 9 8 4 10 10 6 2 10 6 6 8 10 8 2

G:

s 2 3 4 5 t

1 6

Gf:

10 8 10 8 6 6 6 4 4 4 2 X 8 2 8 X X X

Flow value = 16

slide-12
SLIDE 12

3/29/19 12

Ford-Fulkerson Algorithm

March 29, 2019 CSCI211 - Sprenkle 23 s 2 3 4 5 t

10 10 9 8 4 10 10 6 2 10 2 8 8 8 10 8

G:

s 2 3 4 5 t

6 2

Gf:

10 10 8 6 8 8 2 2 1 2 8 2 X 9 7 9 X X 9 X X 3

Flow value = 18

Ford-Fulkerson Algorithm

March 29, 2019 CSCI211 - Sprenkle 24 s 2 3 4 5 t

10 10 9 8 4 10 10 6 2 10 3 9 9 9 10 7

G:

s 2 3 4 5 t

1 9 1 1 6 2

Gf:

10 7 10 6 9 9 3 1

Flow value = 19

How do we know we’re done?

slide-13
SLIDE 13

3/29/19 13

Ford-Fulkerson Algorithm

March 29, 2019 CSCI211 - Sprenkle 25 s 2 3 4 5 t

10 10 9 8 4 10 10 6 2 10 3 9 9 9 10 7

G:

s 2 3 4 5 t

1 9 1 1 6 2

Gf:

10 7 10 6 9 9 3 1

What is reachable from s Flow value = 19

Cut capacity = 19

Analyzing Augmenting Path Algorithm

March 29, 2019 CSCI211 - Sprenkle 26

Ford Ford-Fulkerson(G Fulkerson(G, , s, , t, , c) foreach foreach e Î E E f(e f(e) ) = 0 0 # initially no flow # initially no flow Gf = residual graph residual graph while while there exists augmenting path P there exists augmenting path P f = Augment(f Augment(f, , c, P) , P) # change the flow # change the flow update update Gf # build a new residual graph # build a new residual graph return return f Augment(f Augment(f, , c, P) , P) b = = bottleneck(P bottleneck(P) ) # edge on P with least capacity # edge on P with least capacity foreach foreach e Î P if if (e Î E) E) f(e f(e) ) = f(e f(e) + ) + b # forward edge, # forward edge, é flow flow else else f(e f(eR) ) = f(e f(e) ) - b # forward edge, # forward edge, ê flow flow return return f

Why does alg work? What is happening at each iteration? What is the running time?

Need more analysis …

slide-14
SLIDE 14

3/29/19 14

MINIMUM CUTS

March 29, 2019 CSCI211 - Sprenkle 27

Cuts

  • 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

March 29, 2019 CSCI211 - Sprenkle 28

s 2 3 4 5 6 7 t

15 5 30 15 10 8 15 9 6 10 10 10 15 4 4

A cap(A, B) = c(e)

e out of A

Capacity = 9 + 15 + 8 + 30 = 62

B

What is the capacity

  • f this cut?
slide-15
SLIDE 15

3/29/19 15

Minimum Cut Problem

  • Find an s-t cut of minimum capacity

Ø Puts upperbound on maximum flow

March 29, 2019 CSCI211 - Sprenkle 29

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

A

Capacity = 10 + 8 + 10 = 28

B

Same graph, different cut

Recall

  • The value of a flow f is v(f) = ∑e out of s f(e)

March 29, 2019 CSCI211 - Sprenkle 30

4 4 4

Value = 4

capacity flow

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

slide-16
SLIDE 16

3/29/19 16

Flow Value Lemma

  • Let f be any flow, and let (A, B) be any s-t cut.

Then, the value of the flow is = fout(A) – fin(A).

March 29, 2019 CSCI211 - Sprenkle 31

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

Value = 24 f (e)

e out of A

∑ − f (e)

e in to A

∑ = v( f )

4

A B

What is the value

  • f this flow?

Flow Value Lemma

March 29, 2019 CSCI211 - Sprenkle 32

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

Value = 6 + 0 + 8 - 1 + 11 = 24

4 11

A B

  • Let f be any flow, and let (A, B) be any s-t cut.

Then, the value of the flow is = fout(A) – fin(A).

f (e)

e out of A

∑ − f (e)

e in to A

∑ = v( f )

slide-17
SLIDE 17

3/29/19 17

CSCI211 - Sprenkle

Possibilities for edge e:

  • Both ends in A (0)
  • Points out from A (+), Points in to A (-)

Flow Value Lemma (FVL)

  • Let f be any flow, and let (A, B) be any s-t cut.
  • Then
  • Pf.

March 29, 2019 33

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

A B

Weak Duality

  • Let f be any flow and let (A, B) be any s-t cut.

➜Then the value of the flow is at most the

cut’s capacity

March 29, 2019 CSCI211 - Sprenkle 34

Cut capacity = 30 Þ Flow value £ 30

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

Capacity = 30

A

slide-18
SLIDE 18

3/29/19 18

Weak Duality

  • Let f be any flow. Then, for any s-t cut (A, B)

v(f) £ cap(A, B).

  • Pf.

March 29, 2019 CSCI211 - Sprenkle 35

v( f ) = f (e)

e out of A

∑ − f (e)

e in to A

∑ ≤ f (e)

e out of A

∑ ≤ c(e)

e out of A

∑ = cap(A, B)

s t

A B

7 6 8 4

By FVL

Certificate of Optimality

  • Corollary. Let f be any flow, and

let (A, B) be any cut. If v(f) = cap(A, B), then f is a max flow and (A, B) is a min cut.

March 29, 2019 CSCI211 - Sprenkle 36

Value of flow = 28 Cut capacity = 28 Þ Flow value £ 28

10 9 9 14 4 10 4 8 9 1 14 s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4 0

A B

slide-19
SLIDE 19

3/29/19 19

Recall: Residual Graph Gf

  • Original edge: e = (u, v) Î E

Ø Flow f(e), capacity c(e)

  • Residual edge

Ø e = (u, v) w/ capacity c(e) - f(e) Ø eR = (v, u) with capacity f(e)

  • To undo flow
  • Residual graph: Gf = (V, Ef)

Ø Residual edges with positive residual capacity Ø Ef = {e : f(e) < c(e)} È {eR : f(e) > 0}

March 29, 2019 CSCI211 - Sprenkle 37

u v 11 residual capacity 6 residual capacity

Forward edges Backward edges

u v 17 6 capacity

flow

Recall: Augmenting Path Algorithm

March 29, 2019 CSCI211 - Sprenkle 38

Ford Ford-Fulkerson(G Fulkerson(G, , s, , t, , c) foreach foreach e Î E E f(e f(e) ) = 0 0 # initially no flow # initially no flow Gf = residual graph residual graph while while there exists augmenting path P there exists augmenting path P f = Augment(f Augment(f, , c, P) , P) # change the flow # change the flow update update Gf # build a new residual graph # build a new residual graph return return f Augment(f Augment(f, , c, P) , P) b = = bottleneck(P bottleneck(P) ) # edge on P with least capacity # edge on P with least capacity foreach foreach e Î P if if (e Î E) E) f(e f(e) ) = f(e f(e) + ) + b # forward edge, # forward edge, é flow flow else else f(e f(eR) ) = f(e f(e) ) - b # forward edge, # forward edge, ê flow flow return return f

slide-20
SLIDE 20

3/29/19 20

Intuition Behind Correctness of F-F Algorithm

  • Let A be set of vertices reachable from s in

residual graph at end of F-F alg execution

  • By definition of A, s Î A
  • By definition of the F-F algorithm’s resulting

flow, t Ï A

March 29, 2019 CSCI211 - Sprenkle 39

Ford-Fulkerson Algorithm

March 29, 2019 CSCI211 - Sprenkle 40 s 2 3 4 5 t

10 10 9 8 4 10 10 6 2 10 3 9 9 9 10 7

G:

s 2 3 4 5 t

1 9 1 1 6 2

Gf:

10 7 10 6 9 9 3 1 Flow value = 19 Cut capacity = 19

A

  • What do we know about the flow out of A?
  • What do we know about the flow into A?

A: nodes reachable from s

A

slide-21
SLIDE 21

3/29/19 21

Ford-Fulkerson Algorithm

March 29, 2019 CSCI211 - Sprenkle 41 s 2 3 4 5 t

10 10 9 8 4 10 10 6 2 10 3 9 9 9 10 7

G:

s 2 3 4 5 t

1 9 1 1 6 2

Gf:

10 7 10 6 9 9 3 1 Flow value = 19 Cut capacity = 19

  • What do we know about the flow out of A?
  • What do we know about the flow into A?

A

  • All edges out of A are completely saturated
  • All edges into A are completely unused

A

Max-Flow Min-Cut Theorem

  • Proof strategy. Prove both simultaneously by

showing the following are equivalent:

(i) There exists a cut (A, B) such that v(f) = cap(A, B). (ii) Flow f is a max flow. (iii) There is no augmenting path relative to f.

42 March 29, 2019 CSCI211 - Sprenkle

Max-flow min-cut theorem. [Ford-Fulkerson 1956] The value of the max flow is equal to the value of the min cut. Augmenting path theorem. Flow f is a max flow iff there are no augmenting paths.

See formal proof in book

slide-22
SLIDE 22

3/29/19 22

Analyzing Augmenting Path Algorithm

March 29, 2019 CSCI211 - Sprenkle 43

Ford Ford-Fulkerson(G Fulkerson(G, , s, , t, , c) foreach foreach e Î E E f(e f(e) ) = 0 0 # initially no flow # initially no flow Gf = residual graph residual graph while while there exists augmenting path P there exists augmenting path P f = Augment(f Augment(f, , c, P) , P) # change the flow # change the flow update update Gf # build a new residual graph # build a new residual graph return return f Augment(f Augment(f, , c, P) , P) b = = bottleneck(P bottleneck(P) ) # edge on P with least capacity # edge on P with least capacity foreach foreach e Î P if if (e Î E) E) f(e f(e) ) = f(e f(e) + ) + b # forward edge, # forward edge, é flow flow else else f(e f(eR) ) = f(e f(e) ) - b # forward edge, # forward edge, ê flow flow return return f

Analyzing Augmenting Path Algorithm

March 29, 2019 CSCI211 - Sprenkle 44

Ford Ford-Fulkerson(G Fulkerson(G, , s, , t, , c) foreach foreach e Î E E f(e f(e) ) = 0 0 # initially no flow # initially no flow Gf = residual graph residual graph while while there exists augmenting path P there exists augmenting path P f = Augment(f Augment(f, , c, P) , P) # change the flow # change the flow update update Gf # build a new residual graph # build a new residual graph return return f Augment(f Augment(f, , c, P) , P) b = = bottleneck(P bottleneck(P) ) # edge on P with least capacity # edge on P with least capacity foreach foreach e Î P if if (e Î E) E) f(e f(e) ) = f(e f(e) + ) + b # forward edge, # forward edge, é flow flow else else f(e f(eR) ) = f(e f(e) ) - b # forward edge, # forward edge, ê flow flow return return f

O(m) O(m) O(m) O(m) O(n) O(n) O(1) O(1)

Total: O(n) à O(m), since n ≤ 2m Total: O(Fm)

Find path: O(m); Iterations: O(F) iterations, where F = max flow

slide-23
SLIDE 23

3/29/19 23

Running Time

  • Assumption. All capacities are integers between 1 and F.
  • Invariant. Every flow value f(e) and every residual capacity’s

cf(e) remains an integer throughout algorithm.

  • Theorem. Algorithm terminates in at most v(f*) £ nF iterations.
  • Pf. Each augmentation increases value by at least 1.
  • Corollary. If F = 1, Ford-Fulkerson runs in O(mn) time.
  • Integrality theorem. If all capacities are integers, then there

exists a max flow f for which every flow value f(e) is an integer.

  • Pf. Since algorithm terminates, theorem follows from

invariant.

45 March 29, 2019 CSCI211 - Sprenkle

Looking Ahead

  • PS 9 (last one!) due Friday

Ø See course schedule page for starter code

  • Wiki due Monday – Network flows focus

March 29, 2019 CSCI211 - Sprenkle 46