+ All Categories
Home > Documents > CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus...

CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus...

Date post: 23-Jun-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
69
CS 4102: Algorithms Lecture 22: Network Flow David Wu Fall 2019
Transcript
Page 1: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

CS 4102: AlgorithmsLecture 22: Network Flow

David WuFall 2019

Page 2: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Review: All-Pairs Shortest Path

2

Thus far: single-source shortest path algorithms (Dijkstra, Bellman-Ford)

All-pairs shortest-paths: find shortest path between every pair of nodes

10

2

11

95

8

3

7

3

1

8

12

9

Page 3: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Review: All-Pairs Shortest Path

Naรฏvely: Run single-source shortest paths algorithm for each node ๐‘  (to compute shortest path from ๐‘  to every other node in the graph)

โ€ข If edge weights are all non-negative, can use Dijkstra (running time ๐‘‚ ๐‘‰ ๐ธ log ๐‘‰

โ€ข If edge weights can be negative, can use Bellman-Ford (running time ๐‘‚ ๐‘‰ ( ๐ธ

When ๐ธ = ฮฉ ๐‘‰ ( , both of these algorithms are ๐‘‚ ๐‘‰ + log ๐‘‰ or ๐‘‚ ๐‘‰ ,

3

Page 4: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Floyd-Warshall All-Pairs Shortest Paths

4

Finds all-pairs shortest paths in ฮ˜( ๐‘‰ +) using dynamic programmingAlso works if graph has negative-weight edges

Same observation as before: Every subpath of a shortest path is itself a shortest path (optimal substructure)โ€ข Namely if shortest path from ๐‘– to ๐‘— goes through ๐‘˜, then the ๐‘– โ†’ ๐‘˜ and ๐‘˜ โ†’ ๐‘— subpaths must themselves be a shortest path

Two possibilities for node ๐‘˜:

Shortest path from ๐‘– to ๐‘— includes ๐‘˜

Shortest path from ๐‘– to ๐‘— excludes ๐‘˜OR

Short(๐‘–, ๐‘—, ๐‘˜ โˆ’ 1)

Short(๐‘–, ๐‘˜, ๐‘˜ โˆ’ 1) + Short(๐‘˜, ๐‘—, ๐‘˜ โˆ’ 1)

๐‘–๐‘—

๐‘˜

๐‘–

๐‘—๐‘˜

Short ๐‘–, ๐‘—, ๐‘˜ = weight of shortest path from ๐‘– โ†’ ๐‘— using nodes 1,โ€ฆ , ๐‘˜ as intermediate hops

Page 5: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Floyd-Warshall All-Pairs Shortest Paths

5

Finds all-pairs shortest paths in ฮ˜( ๐‘‰ +) using dynamic programmingAlso works if graph has negative-weight edges

Same observation as before: Every subpath of a shortest path is itself a shortest path (optimal substructure)โ€ข Namely if shortest path from ๐‘– to ๐‘— goes through ๐‘˜, then the ๐‘– โ†’ ๐‘˜ and ๐‘˜ โ†’ ๐‘— subpaths must themselves be a shortest path

Short(๐‘–, ๐‘—, ๐‘˜ โˆ’ 1)Short(๐‘–, ๐‘˜, ๐‘˜ โˆ’ 1) + Short(๐‘˜, ๐‘—, ๐‘˜ โˆ’ 1)Short ๐‘–, ๐‘—, ๐‘˜ = min

Short ๐‘–, ๐‘—, ๐‘˜ = weight of shortest path from ๐‘– โ†’ ๐‘— using nodes 1,โ€ฆ , ๐‘˜ as intermediate hops

Page 6: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Floyd-Warshall All-Pairs Shortest Paths

6

allocate short[n][n][n] (initialized to โˆž)for (i, j) in E:

short[i][j][0] = w[i][j]

for i = 1,...,n:

short[i][i][0] = 0

for k = 1,...,n:

for i = 1,...,n:

for j = 1,...,n:

short[i][j][k] = min(short[i][k][k-1] + short[k][j][k-1], short[i][j][k-1])

๐’Œ = ๐ŸŽ: shortest path cannot use any intermediate nodes (must be direct path)

๐’Œ = ๐ŸŽ: shortest path from node to itself is always 0

Short(๐‘–, ๐‘—, ๐‘˜ โˆ’ 1)Short(๐‘–, ๐‘˜, ๐‘˜ โˆ’ 1) + Short(๐‘˜, ๐‘—, ๐‘˜ โˆ’ 1)Short ๐‘–, ๐‘—, ๐‘˜ = min

Page 7: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Floyd-Warshall All-Pairs Shortest Paths

7

allocate short[n][n] (initialized to โˆž)for (i, j) in E:

short[i][j] = w[i][j]

for i = 1,...,n:

short[i][i] = 0

for k = 1,...,n:

for i = 1,...,n:

for j = 1,...,n:

short[i][j] = min(short[i][k] + short[k][j], short[i][j])

๐’Œ = ๐ŸŽ: shortest path cannot use any intermediate nodes (must be direct path)

๐’Œ = ๐ŸŽ: shortest path from node to itself is always 0

Observation: short[i][j][k] only depends on values for short[][][k โ€“ 1], so we can just use a single two-dimensional array

Short(๐‘–, ๐‘—, ๐‘˜ โˆ’ 1)Short(๐‘–, ๐‘˜, ๐‘˜ โˆ’ 1) + Short(๐‘˜, ๐‘—, ๐‘˜ โˆ’ 1)Short ๐‘–, ๐‘—, ๐‘˜ = min

In this case, the initialization step is constructing the adjacency matrix of the graph

(this step is not needed if graph already represented in this form!)

Page 8: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Floyd-Warshall All-Pairs Shortest Paths

8

allocate short[n][n] (initialized to โˆž)for (i, j) in E:

short[i][j] = w[i][j]

for i = 1,...,n:

short[i][i] = 0

for k = 1,...,n:

for i = 1,...,n:

for j = 1,...,n:

short[i][j] = min(short[i][k] + short[k][j], short[i][j])

๐’Œ = ๐ŸŽ: shortest path cannot use any intermediate nodes (must be direct path)

๐’Œ = ๐ŸŽ: shortest path from node to itself is always 0

Very simple implementation!

Running time: ๐‘‚ ๐‘›+ = ๐‘‚ ๐‘‰ +

Short(๐‘–, ๐‘—, ๐‘˜ โˆ’ 1)Short(๐‘–, ๐‘˜, ๐‘˜ โˆ’ 1) + Short(๐‘˜, ๐‘—, ๐‘˜ โˆ’ 1)Short ๐‘–, ๐‘—, ๐‘˜ = min

Page 9: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Todayโ€™s Keywords

GraphsNetwork flowFord-FulkersonEdmonds-KarpMax-Flow Min-Cut Theorem

9

CLRS Readings: Chapter 25, 26

Page 10: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Homework

HW7 due today, 11pmโ€ข Graph algorithmsโ€ข Written (use LaTeX!) โ€“ Submit both zip and pdf (two separate attachments)!

HW10B due today, 11pmโ€ข No late submissions allowed (no exceptions)

HW8 out today, due Thursday, November 21, 11pmโ€ข Programming assignment (Python or Java)โ€ข Graph algorithms

10

Page 11: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Network Flow

11Railway map of Western USSR, 1955

Question: What is the maximum throughput of the

railroad network?

Page 12: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Flow Networks

Graph ๐บ = (๐‘‰, ๐ธ)Source node ๐‘  โˆˆ ๐‘‰Sink node ๐‘ก โˆˆ ๐‘‰Edge capacities ๐‘ ๐‘’ โˆˆ โ„K

Max flow intuition: If ๐‘  is a faucet, ๐‘ก is a drain, and ๐‘  connects to ๐‘ก through a network of pipes ๐ธ with capacities ๐‘(๐‘’), what is the maximum amount of water which can flow from the faucet to the drain?

12

3

3

3

2

๐‘ ๐‘ก

1

2

1 3 2

2

3

Page 13: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Assignment of values ๐‘“ ๐‘’ to edgesโ€ข โ€œAmount of water going through that pipeโ€

Capacity constraintโ€ข ๐‘“ ๐‘’ โ‰ค ๐‘(๐‘’)โ€ข โ€œFlow cannot exceed capacityโ€

Flow constraintโ€ข โˆ€๐‘ฃ โˆˆ ๐‘‰ โˆ’ {๐‘ , ๐‘ก}, inRlow ๐‘ฃ = outRlow(๐‘ฃ)โ€ข inRlow ๐‘ฃ = โˆ‘VโˆˆW ๐‘“(๐‘ฅ, ๐‘ฃ)โ€ข outRlow ๐‘ฃ = โˆ‘VโˆˆW ๐‘“(๐‘ฃ, ๐‘ฅ)โ€ข Water going in must match water coming out

Flow of ๐บ: |๐‘“| = outRlow ๐‘  โˆ’ inRlow(๐‘ )โ€ข Net outflow of ๐‘ 

13

flow / capacity

3 in this example

Network Flow

1/3

1/3

2/3

2/2

๐‘ ๐‘ก

0/1

2/2

1/1

2/31/2

1/2

2/3

Page 14: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Maximum Flow Problem

Of all valid flows through the graph, find the one that maximizes:

๐‘“ = outRlow ๐‘  โˆ’ inRlow(๐‘ )

14

3

3

3

2

๐‘ ๐‘ก

1

2

1

32

2

30/3

2/3

2/3

2/2

๐‘ ๐‘ก

0/1

2/2

0/1

0/30/2

2/2

2/3

Page 15: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Greedy Approach

15

30

20

๐‘  ๐‘ก

10 20

10

Greedy choice: saturate highest capacity path first

Page 16: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Greedy Approach

16

30

20

๐‘  ๐‘ก

10 20

10

Greedy choice: saturate highest capacity path first

Page 17: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Greedy Approach

17

20/30

20/20

๐‘  ๐‘ก

10 20/20

10

Greedy choice: saturate highest capacity path first

Flow: 20

Page 18: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Greedy Approach

18

10/30

20/20

๐‘  ๐‘ก

10/10 20/20

10/10

Greedy choice: saturate highest capacity path first

Maximum Flow: 30

Observe: highest capacity path is not saturated in optimal solution

Page 19: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Residual Graphs

19

1/3

1/3

2/3

2/2

๐‘ ๐‘ก

0/1

2/2

1/1

2/31/2

1/2

2/3

Flow ๐‘“ in ๐บ

Given a flow ๐‘“ in graph ๐บ, the residual graph ๐บZ models additional flow that is possibleโ€ข Forward edge for each edge in ๐บ with weight set to remaining capacity ๐‘ ๐‘’ โˆ’ ๐‘“(๐‘’)

โ€ข Models additional flow that can be sent along the edge

Residual graph ๐บZ

๐‘ ๐‘ก

21

1

112

11

Page 20: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Residual Graphs

20

1/3

1/3

2/3

2/2

๐‘ ๐‘ก

0/1

2/2

1/1

2/31/2

1/2

2/3

Flow ๐‘“ in ๐บ Residual graph ๐บZ

๐‘ ๐‘ก

21

1

112

11

1

21

2

1

2

212

1

Given a flow ๐‘“ in graph ๐บ, the residual graph ๐บZ models additional flow that is possibleโ€ข Forward edge for each edge in ๐บ with weight set to remaining capacity ๐‘ ๐‘’ โˆ’ ๐‘“(๐‘’)

โ€ข Models additional flow that can be sent along the edgeโ€ข Backward edge by flipping each edge ๐‘’ in ๐บ with weight set to flow ๐‘“(๐‘’)

โ€ข Models amount of flow that can be removed from the edge

Page 21: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Residual Graphs

21

1/3

1/3

2/3

2/2

๐‘ ๐‘ก

0/1

2/2

1/1

2/31/2

1/2

2/3

Flow ๐‘“ in ๐บ

Consider a path from ๐‘  โ†’ ๐‘ก in ๐บZ using only edges with positive (non-zero) weightConsider the minimum-weight edge ๐‘’ along the path: we can increase the flow by ๐‘ค(๐‘’)โ€ข Send ๐‘ค(๐‘’) flow along all forward edges (these have at least ๐‘ค(๐‘’) capacity)

Residual graph ๐บZ

๐‘ ๐‘ก

21

1

112

11

1

21

2

1

2

212

1

Page 22: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Residual Graphs

22

1/3

1/3

2/3

2/2

๐‘ ๐‘ก

0/1

2/2

1/1

2/31/2

1/2

2/3

Flow ๐‘“ in ๐บ

Consider a path from ๐‘  โ†’ ๐‘ก in ๐บZ using only edges with positive (non-zero) weightConsider the minimum-weight edge ๐‘’ along the path: we can increase the flow by ๐‘ค(๐‘’)โ€ข Send ๐‘ค(๐‘’)flow along all forward edges (these have at least ๐‘ค(๐‘’) capacity)โ€ข Remove ๐‘ค(๐‘’)flow along all backward edges (these contain at least ๐‘ค(๐‘’) units of flow)

Residual graph ๐บZ

๐‘ ๐‘ก

21

1

112

11

1

21

2

1

2

212

1

Page 23: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Residual Graphs

23

0/3

2/3

2/3

2/2

๐‘ ๐‘ก

0/1

2/2

0/1

2/31/2

1/2

3/3

Flow ๐‘“ in ๐บ Residual graph ๐บZ

๐‘ ๐‘ก

21

1

112

11

1

21

2

1

2

212

1

Observe: Flow has increased by ๐‘ค(๐‘’)

Consider a path from ๐‘  โ†’ ๐‘ก in ๐บZ using only edges with positive (non-zero) weightConsider the minimum-weight edge ๐‘’ along the path: we can increase the flow by ๐‘ค(๐‘’)โ€ข Send ๐‘ค(๐‘’)flow along all forward edges (these have at least ๐‘ค(๐‘’) capacity)โ€ข Remove ๐‘ค(๐‘’)flow along all backward edges (these contain at least ๐‘ค(๐‘’) units of flow)

Page 24: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Residual Graphs

24

Consider a path from ๐‘  โ†’ ๐‘ก in ๐บZ using only edges with positive (non-zero) weightConsider the minimum-weight edge ๐‘’ along the path: we can increase the flow by ๐‘ค(๐‘’)โ€ข Send ๐‘ค(๐‘’) flow along all forward edges (these have at least ๐‘ค(๐‘’) capacity)โ€ข Remove ๐‘ค(๐‘’) flow along all backward edges (these contain at least ๐‘ค(๐‘’) units of flow)

Residual graph ๐บZ

๐‘ ๐‘ก

21

1

112

11

1

21

2

1

2

212

1

Observe: Flow has increased by ๐‘ค(๐‘’)

Why does this respect flow constraints?โ€ข Incoming edge to a node always

corresponds to increased flow to the node (more incoming flow from forward edge or less outgoing flow from backward edge)

โ€ข Outgoing edge to a node always corresponds to decreased flow to the node

Page 25: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Residual Graphs

25

Consider a path from ๐‘  โ†’ ๐‘ก in ๐บZ using only edges with positive (non-zero) weightConsider the minimum-weight edge ๐‘’ along the path: we can increase the flow by ๐‘ค(๐‘’)โ€ข Send ๐‘ค(๐‘’) flow along all forward edges (these have at least ๐‘ค(๐‘’) capacity)โ€ข Remove ๐‘ค(๐‘’) flow along all backward edges (these contain at least ๐‘ค(๐‘’) units of flow)

Residual graph ๐บZ

๐‘ ๐‘ก

21

1

112

11

1

21

2

1

2

212

1

Observe: Flow has increased by ๐‘ค(๐‘’)

Why does this respect flow constraints?โ€ข Incoming edge to a node always

corresponds to increased flow to the node (more incoming flow from forward edge or less outgoing flow from backward edge)

โ€ข Outgoing edge to a node always corresponds to decreased flow to the node

Capacity constraints satisfied by construction of the residual network

Page 26: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Algorithm

Define an augmenting path to be an ๐‘  โ†’ ๐‘ก path in the residual graph ๐บZ (using edges of non-zero weight)

Ford-Fulkerson max-flow algorithm:โ€ข Initialize ๐‘“ ๐‘’ = 0 for all ๐‘’ โˆˆ ๐ธโ€ข Construct the residual network ๐บZโ€ข While there is an augmenting path ๐‘ in ๐บZ:

โ€ข Let ๐‘ = min]โˆˆ^

๐‘Z(๐‘’) (๐‘Z(๐‘’) is the weight of edge ๐‘’ in the residual network ๐บZ)โ€ข Add ๐‘ units of flow to ๐บ based on the augmenting path ๐‘โ€ข Update the residual network ๐บZ for the updated flow

26

Ford-Fulkerson approach: take any augmenting path(will revisit this later)

Page 27: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Example

27

0/3

0/3

0/3

0/2

๐‘ ๐‘ก

0/1

0/2

0/1

0/30/2

0/2

0/3

Initially: ๐‘“ ๐‘’ = 0 for all ๐‘’ โˆˆ ๐ธ

3

3

3

๐‘ ๐‘ก

1

2

1

32

2

Residual graph ๐บZ

3

2

Page 28: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Example

28

0/3

0/3

0/3

0/2

๐‘ ๐‘ก

0/1

0/2

0/1

0/30/2

0/2

0/33

3

๐‘ ๐‘ก

1

2

1

32

2

Residual graph ๐บZ

Increase flow by 1 unit

33

2

Page 29: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Example

29

0/3

1/3

1/3

0/2

๐‘ ๐‘ก

0/1

1/2

1/1

0/30/2

1/2

0/33

3

๐‘ ๐‘ก

1

2

1

32

2

Residual graph ๐บZ

Increase flow by 1 unit

33

2

Page 30: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Example

30

0/3

1/3

1/3

0/2

๐‘ ๐‘ก

0/1

1/2

1/1

0/30/2

1/2

0/32

2

๐‘ ๐‘ก

1

1

32

1

11

1

1

1

Residual graph ๐บZ

33

2

Page 31: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Example

31

0/3

1/3

1/3

0/2

๐‘ ๐‘ก

0/1

1/2

1/1

0/30/2

1/2

0/32

2

๐‘ ๐‘ก

1

1

32

1

11

1

1

1

Residual graph ๐บZ

Increase flow by 1 unit

33

2

Page 32: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Example

32

0/3

2/3

1/3

0/2

๐‘ ๐‘ก

0/1

2/2

1/1

0/30/2

1/2

1/32

2

๐‘ ๐‘ก

1

1

32

1

11

1

1

1

Residual graph ๐บZ

Increase flow by 1 unit

33

2

Page 33: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Example

33

0/3

2/3

1/3

0/2

๐‘ ๐‘ก

0/1

2/2

1/1

0/30/2

1/2

1/31

2

๐‘ ๐‘ก

1

32

1

221

1

1

2 1

Residual graph ๐บZ

Increase flow by 1 unit

3

2

Page 34: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Example

34

0/3

2/3

1/3

0/2

๐‘ ๐‘ก

0/1

2/2

1/1

0/30/2

1/2

1/3

Residual graph ๐บZ

1

2

๐‘ ๐‘ก

1

32

1

221

1

1

2 13

2

Page 35: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Example

35

0/3

2/3

1/3

1/2

๐‘ ๐‘ก

0/1

2/2

0/1

0/30/2

1/2

2/3

Residual graph ๐บZ

1

2

๐‘ ๐‘ก

1

32

1

221

1

1

2 1

Increase flow by 1 unit

3

2

Page 36: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Example

36

0/3

2/3

1/3

1/2

๐‘ ๐‘ก

0/1

2/2

0/1

0/30/2

1/2

2/3

Residual graph ๐บZ

1

2

๐‘ ๐‘ก

1

32

1

121

1

1

2 2

Increase flow by 1 unit

3

11

Page 37: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Example

37

0/3

2/3

1/3

1/2

๐‘ ๐‘ก

0/1

2/2

0/1

0/30/2

1/2

2/3

Residual graph ๐บZ

1

2

๐‘ ๐‘ก

1

32

1

121

1

1

2 23

11

Page 38: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Example

38

0/3

2/3

2/3

2/2

๐‘ ๐‘ก

0/1

2/2

0/1

0/30/2

2/2

2/3

Residual graph ๐บZ

1

2

๐‘ ๐‘ก

1

32

1

121

1

1

2 2

Increase flow by 1 unit

3

11

Page 39: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Example

39

0/3

2/3

2/3

2/2

๐‘ ๐‘ก

0/1

2/2

0/1

0/30/2

2/2

2/3

Residual graph ๐บZ

No more augmenting paths

1

1

๐‘ ๐‘ก

1

3212

1

2

2

2 23

2

Maximum flow: 4

Page 40: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Running Time

Define an augmenting path to be an ๐‘  โ†’ ๐‘ก path in the residual graph ๐บZ (using edges of non-zero weight)

Ford-Fulkerson max-flow algorithm:โ€ข Initialize ๐‘“ ๐‘’ = 0 for all ๐‘’ โˆˆ ๐ธโ€ข Construct the residual network ๐บZโ€ข While there is an augmenting path ๐‘ in ๐บZ:

โ€ข Let ๐‘ = min]โˆˆ^

๐‘Z(๐‘’) (๐‘Z(๐‘’) is the weight of edge ๐‘’ in the residual network ๐บZ)โ€ข Add ๐‘ units of flow to ๐บ based on the augmenting path ๐‘โ€ข Update the residual network ๐บZ for the updated flow

40

Initialization: ๐‘‚ ๐ธ

Page 41: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Running Time

Define an augmenting path to be an ๐‘  โ†’ ๐‘ก path in the residual graph ๐บZ (using edges of non-zero weight)

Ford-Fulkerson max-flow algorithm:โ€ข Initialize ๐‘“ ๐‘’ = 0 for all ๐‘’ โˆˆ ๐ธโ€ข Construct the residual network ๐บZโ€ข While there is an augmenting path ๐‘ in ๐บZ:

โ€ข Let ๐‘ = min]โˆˆ^

๐‘Z(๐‘’) (๐‘Z(๐‘’) is the weight of edge ๐‘’ in the residual network ๐บZ)โ€ข Add ๐‘ units of flow to ๐บ based on the augmenting path ๐‘โ€ข Update the residual network ๐บZ for the updated flow

41

Initialization: ๐‘‚ ๐ธConstruct residual network: ๐‘‚ ๐ธ

Page 42: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Running Time

Define an augmenting path to be an ๐‘  โ†’ ๐‘ก path in the residual graph ๐บZ (using edges of non-zero weight)

Ford-Fulkerson max-flow algorithm:โ€ข Initialize ๐‘“ ๐‘’ = 0 for all ๐‘’ โˆˆ ๐ธโ€ข Construct the residual network ๐บZโ€ข While there is an augmenting path ๐‘ in ๐บZ:

โ€ข Let ๐‘ = min]โˆˆ^

๐‘Z(๐‘’) (๐‘Z(๐‘’) is the weight of edge ๐‘’ in the residual network ๐บZ)โ€ข Add ๐‘ units of flow to ๐บ based on the augmenting path ๐‘โ€ข Update the residual network ๐บZ for the updated flow

42

Initialization: ๐‘‚ ๐ธConstruct residual network: ๐‘‚ ๐ธFinding augmenting path in residual network: ๐‘‚ ๐ธ using BFS/DFS

We only care about nodes reachable from the source ๐‘  (so the number of nodes

that are โ€œrelevantโ€ is at most ๐ธ )

Page 43: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Running Time

Define an augmenting path to be an ๐‘  โ†’ ๐‘ก path in the residual graph ๐บZ (using edges of non-zero weight)

Ford-Fulkerson max-flow algorithm:โ€ข Initialize ๐‘“ ๐‘’ = 0 for all ๐‘’ โˆˆ ๐ธโ€ข Construct the residual network ๐บZโ€ข While there is an augmenting path ๐‘ in ๐บZ:

โ€ข Let ๐‘ = min]โˆˆ^

๐‘Z(๐‘’) (๐‘Z(๐‘’) is the weight of edge ๐‘’ in the residual network ๐บZ)โ€ข Add ๐‘ units of flow to ๐บ based on the augmenting path ๐‘โ€ข Update the residual network ๐บZ for the updated flow

43

Initialization: ๐‘‚ ๐ธConstruct residual network: ๐‘‚ ๐ธFinding augmenting path in residual network: ๐‘‚ ๐ธ using BFS/DFS

How many iterations are needed?โ€ข For integer-valued capacities, min-weight of each augmenting path is 1, so

number of iterations is bounded by ๐‘“โˆ— , where ๐‘“โˆ— is max-flow in ๐บโ€ข For rational-valued capacities, can scale to make capacities integerโ€ข For irrational-valued capacities, algorithm may never terminate!

โ€ข Extra credit: Construct a graph where this happens

Page 44: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Ford-Fulkerson Running Time

Define an augmenting path to be an ๐‘  โ†’ ๐‘ก path in the residual graph ๐บZ (using edges of non-zero weight)

Ford-Fulkerson max-flow algorithm:โ€ข Initialize ๐‘“ ๐‘’ = 0 for all ๐‘’ โˆˆ ๐ธโ€ข Construct the residual network ๐บZโ€ข While there is an augmenting path ๐‘ in ๐บZ:

โ€ข Let ๐‘ = min]โˆˆ^

๐‘Z(๐‘’) (๐‘Z(๐‘’) is the weight of edge ๐‘’ in the residual network ๐บZ)โ€ข Add ๐‘ units of flow to ๐บ based on the augmenting path ๐‘โ€ข Update the residual network ๐บZ for the updated flow

44

Initialization: ๐‘‚ ๐ธConstruct residual network: ๐‘‚ ๐ธFinding augmenting path in residual network: ๐‘‚ ๐ธ using BFS/DFS

For graphs with integer capacities, running time of Ford-Fulkerson is

๐‘‚ ๐‘“โˆ— โ‹… ๐ธHighly undesirable if ๐‘“โˆ— โ‰ซ |๐ธ| (e.g., graph is small, but capacities are โ‰ˆ 2+()

As described, algorithm is not polynomial-time!

Page 45: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Worst-Case Ford-Fulkerson

45

0/1

0/100

๐‘  ๐‘ก

0/100 0/100

0/100

1

100

๐‘  ๐‘ก

100 100

100

Page 46: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Worst-Case Ford-Fulkerson

46

0/1

0/100

๐‘  ๐‘ก

0/100 0/100

0/100

1

100

๐‘  ๐‘ก

100 100

100

Increase flow by 1 unit

Page 47: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Worst-Case Ford-Fulkerson

47

1/1

1/100

๐‘  ๐‘ก

0/100 1/100

0/100

1

100

๐‘  ๐‘ก

100 100

100

Increase flow by 1 unit

Page 48: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Worst-Case Ford-Fulkerson

48

1/1

1/100

๐‘  ๐‘ก

0/100 1/100

0/100

1

99

๐‘  ๐‘ก

100 99

100

11

Page 49: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Worst-Case Ford-Fulkerson

49

1/1

1/100

๐‘  ๐‘ก

0/100 1/100

0/100

1

99

๐‘  ๐‘ก

100 99

100

11

Increase flow by 1 unit

Page 50: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Worst-Case Ford-Fulkerson

50

0/1

1/100

๐‘  ๐‘ก

1/100 1/100

1/100

1

99

๐‘  ๐‘ก

100 99

100

11

Increase flow by 1 unit

Page 51: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Worst-Case Ford-Fulkerson

51

0/1

1/100

๐‘  ๐‘ก

1/100 1/100

1/100

1

99

๐‘  ๐‘ก

99 99

99

11

1

1

Page 52: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Worst-Case Ford-Fulkerson

52

0/1

1/100

๐‘  ๐‘ก

1/100 1/100

1/100

1

99

๐‘  ๐‘ก

99 99

99

11

1

1

Observation: each iteration increases flow by 1 unitTotal number of iterations: ๐‘“โˆ— = 200

Page 53: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Can We Avoid this?

Edmonds-Karp Algorithm: choose augmenting path with fewest hopsRunning time: ฮ˜ min ๐ธ ๐‘“โˆ— , ๐‘‰ ๐ธ ( = ๐‘‚ ๐‘‰ ๐ธ (

53

Ford-Fulkerson max-flow algorithm:โ€ข Initialize ๐‘“ ๐‘’ = 0 for all ๐‘’ โˆˆ ๐ธโ€ข Construct the residual network ๐บZโ€ข While there is an augmenting path in ๐บZ, let ๐‘ be the path with fewest hops:โ€ข Let ๐‘ = min

]โˆˆ^๐‘Z(๐‘’) (๐‘Z(๐‘’) is the weight of edge ๐‘’ in the residual network ๐บZ)

โ€ข Add ๐‘ units of flow to ๐บ based on the augmenting path ๐‘โ€ข Update the residual network ๐บZ for the updated flow

How to find this? Use breadth-first search (BFS)!

Edmonds-Karp = Ford-Fulkerson using BFS to find augmenting path

Proof: See CLRS (Chapter 26.2)

Page 54: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Correctness of Ford-Fulkerson

Consider cuts which separate ๐‘  and ๐‘กโ€ข Let ๐‘  โˆˆ ๐‘†, ๐‘ก โˆˆ ๐‘‡, such that ๐‘‰ = ๐‘† โˆช ๐‘‡

Cost ๐‘†, ๐‘‡ of cut ๐‘†, ๐‘‡ : sum of the capacities of edges from ๐‘† to ๐‘‡

54

3

3

3

2

๐‘ ๐‘ก

1

2

1

32

2

3

๐‘† ๐‘‡๐‘†, ๐‘‡ = 5

Page 55: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Max-Flow / Min-CutClaim: Maximum flow in a flow network ๐บ always upper-bounded by the cost any cut that separates ๐‘  and ๐‘กProof: โ€œConservation of flowโ€

โ€ข All flow from ๐‘  must eventually get to ๐‘กโ€ข To get from ๐‘  to ๐‘ก, all flow must cross the cut somewhere

Conclusion: Max-flow in ๐บ is at most the cost of the min-cut in ๐บโ€ข max

Z๐‘“ โ‰ค min

j,k๐‘†, ๐‘‡

55

3

3

3

2

๐‘ ๐‘ก

1

2

1

32

2

3

๐‘† ๐‘‡

Page 56: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Max-Flow Min-Cut Theorem

Let ๐‘“ be a flow in a graph ๐บ

56

๐‘“ is a maximum flow in ๐บ

there are no augmenting paths in the

residual graph ๐บZ

there exists a cut (๐‘†, ๐‘‡) of ๐บ where

๐‘“ = โ€–๐‘†, ๐‘‡โ€–

Statements are equivalent!

Implications:โ€ข Correctness of Ford-Fulkerson: Ford-Fulkerson terminates when there are no more

augmenting paths in the residual graph ๐บZ, which means that ๐‘“ is a maximum flowโ€ข Max-flow min-cut duality: the maximum flow in a network coincides with the minimum cut

of the graph (maxZ

๐‘“ = minj,k

๐‘†, ๐‘‡ )

โ€ข Finding either the minimum cut or the maximum flow yields solution to the otherโ€ข Special case of more general principle (duality in linear programming)

Page 57: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Max-Flow Min-Cut Duality Example

57

0/3

2/3

2/3

2/2

๐‘ ๐‘ก

0/1

2/2

0/1

0/30/2

2/2

2/31

1

๐‘ ๐‘ก

1

3212

1

2

2

2 23

2

Flow graph Residual graph

no more augmenting paths

Max flow: 4

๐‘†

๐‘‡

Page 58: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Max-Flow Min-Cut Duality Example

58

0/3

2/3

2/3

2/2

๐‘ ๐‘ก

0/1

2/2

0/1

0/30/2

2/2

2/31

1

๐‘ ๐‘ก

1

3212

1

2

2

2 23

2

Flow graph Residual graph

no more augmenting paths๐‘†

๐‘‡

Max flow: 4Min cut: 4

When there are no more augmenting paths in the graph, there is a cut whose cost matches the flow

Page 59: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Max-Flow Min-Cut Theorem Proof

Let ๐‘“ be a flow in a graph ๐บ

59

๐‘“ is a maximum flow in ๐บ

there are no augmenting paths in the

residual graph ๐บZ

there exists a cut (๐‘†, ๐‘‡) of ๐บ where

๐‘“ = โ€–๐‘†, ๐‘‡โ€–

Proof:โ€ข Suppose ๐‘“ is a max flow in ๐บ and there is an augmenting path in ๐บZโ€ข If there is an augmenting path in ๐บZ, then we can send additional units of flow though

the network along the augmenting pathโ€ข This contradicts optimality of ๐‘“

Page 60: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Max-Flow Min-Cut Theorem Proof

Let ๐‘“ be a flow in a graph ๐บ

60

๐‘“ is a maximum flow in ๐บ

there are no augmenting paths in the

residual graph ๐บZ

there exists a cut (๐‘†, ๐‘‡) of ๐บ where

๐‘“ = โ€–๐‘†, ๐‘‡โ€–

Proof:โ€ข Take any flow ๐‘“mโ€ข Consider the cut ๐‘†, ๐‘‡ of ๐บ; then, ๐‘“m โ‰ค ๐‘†, ๐‘‡ = ๐‘“โ€ข Thus, ๐‘“m โ‰ค ๐‘“ , so ๐‘“ must be a maximum flow

Page 61: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Max-Flow Min-Cut Theorem Proof

Let ๐‘“ be a flow in a graph ๐บ

61

๐‘“ is a maximum flow in ๐บ

there are no augmenting paths in the

residual graph ๐บZ

there exists a cut (๐‘†, ๐‘‡) of ๐บ where

๐‘“ = โ€–๐‘†, ๐‘‡โ€–

Page 62: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Max-Flow Min-Cut Theorem Proof

62

0/3

2/3

2/3

2/2

๐‘ ๐‘ก

0/1

2/2

0/1

0/30/2

2/2

2/31

1

๐‘ ๐‘ก

1

3212

1

2

2

2 23

2

no more augmenting paths๐‘†

๐‘‡Flow graph Residual graph

No augmenting paths means there is no path from ๐‘  to ๐‘ก in ๐บZโ€ข Let ๐‘† be set of nodes reachable from ๐‘  in ๐บZโ€ข Let ๐‘‡ = ๐‘‰ โˆ’ ๐‘†

Page 63: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Max-Flow Min-Cut Theorem Proof

63

0/3

2/3

2/3

2/2

๐‘ ๐‘ก

0/1

2/2

0/1

0/30/2

2/2

2/31

1

๐‘ ๐‘ก

1

3212

1

2

2

2 23

2

no more augmenting paths๐‘†

๐‘‡Claim: ๐‘†, ๐‘‡ = ๐‘“โ€ข Total flow ๐‘“ is amount of outgoing flow from ๐‘† to ๐‘‡ minus the amount of incoming flow from ๐‘‡ to ๐‘†

Page 64: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Max-Flow Min-Cut Theorem Proof

64

0/3

2/3

2/3

2/2

๐‘ 

๐‘ข๐‘ฃ

๐‘ก

0/1

2/2

0/1

0/30/2

2/2

2/31

1

๐‘ 

๐‘ข๐‘ฃ

๐‘ก

1

3212

1

2

2

2 23

2

no more augmenting paths๐‘†

๐‘‡Claim: ๐‘†, ๐‘‡ = ๐‘“โ€ข Total flow ๐‘“ is amount of outgoing flow from ๐‘† to ๐‘‡ minus the amount of incoming flow from ๐‘‡ to ๐‘†โ€ข Outgoing flow: Consider edge ๐‘ข, ๐‘ฃ where ๐‘ข โˆˆ ๐‘† and ๐‘ฃ โˆˆ ๐‘‡

โ€ข Then, ๐‘“ ๐‘ข, ๐‘ฃ = ๐‘ ๐‘ข, ๐‘ฃ . Otherwise, there is a forward edge ๐‘ข, ๐‘ฃ with positive weight in ๐บZ and ๐‘ฃ โˆˆ ๐‘†

Page 65: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Max-Flow Min-Cut Theorem Proof

65

0/3

2/3

2/3

2/2

๐‘ 

๐‘ฅ

๐‘ฆ

๐‘ก

0/1

2/2

0/1

0/30/2

2/2

2/31

1

๐‘ 

๐‘ฅ

๐‘ฆ

๐‘ก

1

3212

1

2

2

2 23

2

no more augmenting paths๐‘†

๐‘‡Claim: ๐‘†, ๐‘‡ = ๐‘“โ€ข Total flow ๐‘“ is amount of outgoing flow from ๐‘† to ๐‘‡ minus the amount of incoming flow from ๐‘‡ to ๐‘†โ€ข Outgoing flow: Consider edge ๐‘ข, ๐‘ฃ where ๐‘ข โˆˆ ๐‘† and ๐‘ฃ โˆˆ ๐‘‡

โ€ข Then, ๐‘“ ๐‘ข, ๐‘ฃ = ๐‘ ๐‘ข, ๐‘ฃ . Otherwise, there is a forward edge ๐‘ข, ๐‘ฃ with positive weight in ๐บZ and ๐‘ฃ โˆˆ ๐‘†โ€ข Incoming flow: Consider edge ๐‘ฆ, ๐‘ฅ where ๐‘ฆ โˆˆ ๐‘‡ and ๐‘ฅ โˆˆ ๐‘†

โ€ข Then, ๐‘“ ๐‘ฆ, ๐‘ฅ = 0. Otherwise, there is a backward edge ๐‘ฅ, ๐‘ฆ with positive weight in ๐บZ and ๐‘ฆ โˆˆ ๐‘†

Page 66: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Max-Flow Min-Cut Theorem Proof

66

0/3

2/3

2/3

2/2

๐‘ ๐‘ก

0/1

2/2

0/1

0/30/2

2/2

2/3๐‘†

๐‘‡Claim: ๐‘†, ๐‘‡ = ๐‘“โ€ข Total flow ๐‘“ is amount of outgoing flow from ๐‘† to ๐‘‡ minus the amount of incoming flow from ๐‘‡ to ๐‘†โ€ข Outgoing flow: Consider edge ๐‘ข, ๐‘ฃ where ๐‘ข โˆˆ ๐‘† and ๐‘ฃ โˆˆ ๐‘‡

โ€ข Then, ๐‘“ ๐‘ข, ๐‘ฃ = ๐‘ ๐‘ข, ๐‘ฃ . Otherwise, there is a forward edge ๐‘ข, ๐‘ฃ with positive weight in ๐บZ and ๐‘ฃ โˆˆ ๐‘†โ€ข Incoming flow: Consider edge ๐‘ฆ, ๐‘ฅ where ๐‘ฆ โˆˆ ๐‘‡ and ๐‘ฅ โˆˆ ๐‘†

โ€ข Then, ๐‘“ ๐‘ฆ, ๐‘ฅ = 0. Otherwise, there is a backward edge ๐‘ฅ, ๐‘ฆ with positive weight in ๐บZ and ๐‘ฆ โˆˆ ๐‘†

๐‘“ = pqโˆˆj,rโˆˆk

๐‘“ ๐‘ข, ๐‘ฃ โˆ’ psโˆˆk,Vโˆˆj

๐‘“ ๐‘ฆ, ๐‘ฅ

= ๐‘†, ๐‘‡

= pqโˆˆj,rโˆˆk

๐‘ ๐‘ข, ๐‘ฃ

Page 67: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Max-Flow Min-Cut Theorem

Let ๐‘“ be a flow in a graph ๐บ

67

๐‘“ is a maximum flow in ๐บ

there are no augmenting paths in the

residual graph ๐บZ

there exists a cut (๐‘†, ๐‘‡) of ๐บ where

๐‘“ = โ€–๐‘†, ๐‘‡โ€–

Statements are equivalent!

Implications:โ€ข Correctness of Ford-Fulkerson: Ford-Fulkerson terminates when there are no more

augmenting paths in the residual graph ๐บZ, which means that ๐‘“ is a maximum flowโ€ข Max-flow min-cut duality: the maximum flow in a network coincides with the minimum cut

of the graph (maxZ

๐‘“ = minj,k

๐‘†, ๐‘‡ )

Page 68: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Other Max Flow Algorithms

Ford-Fulkersonโ€ข ฮ˜ ๐ธ ๐‘“โˆ—

Edmonds-Karp (Ford-Fulkerson using BFS to choose augmenting path)โ€ข ฮ˜( ๐ธ ( ๐‘‰ )

Push-Relabel (Tarjan)โ€ข ฮ˜( ๐ธ ๐‘‰ ()

Faster Push-Relabel (also Tarjan)โ€ข ฮ˜( ๐‘‰ +)

68

Page 69: CS 4102: Algorithmsjh2jf/courses/fall2019/cs...Review: All-Pairs Shortest Path 2 Thus far:single-sourceshortest path algorithms (Dijkstra, Bellman-Ford) All-pairs shortest-paths: find

Minimum-Cost Maximum-Flow Problem

Not all paths are created equal!

69

3

3

3

2

๐‘ ๐‘ก

1

2

1

32

2

3

2 5

211

3 4

7

1 2

1

A cost is associated with each unit of flow sent along an edgeGoal: Maximize flow while minimizing cost

Much harder problem!Can solve using linear programming


Recommended