Lec18 NetworkFlow
Lec18 NetworkFlow
Network Flow
Flow network
• Abstraction for material flowing through the edges.
• E.g. traffic on highway, pipes carrying liquid, computer networks
• ! = ($, &), directed graph.
• Two distinguished nodes: (: source, ): sink.
• *(+): capacity of edge e. *(+) ≥ 0.
2 9 5
Source Sink absorbs
generates flow 10 15 15 flow and has
4 10
and has no no outgoing
incoming edges edges
source s 5 3 8 6 10 t sink
4 6 15 10
capacity 15
4 30 7
1
11/10/20
Flows
Def. An ! − # $%&' is a function that satisfies:
• For each ( ∈ *: 0 ≤ f (e) ≤ c(e) (capacity)
• For each , ∈ -– {!, #}: ∑ f (e) = ∑ f (e)
e in to v e out of v
(conservation)
€ v( f ) = ∑ f (e) .
Def. The value of a flow
€
$ is: e out of s
0
2 9 5
4 0 0
10€ 15 15 0 10
44
0 4 4
s 5 3 8 6 10 t
0 0
40 6 15 0 10
capacity 15
flow 0 0 Value = 4
4 30 7
Flows
?
2 9 5
10 0 6
10 44 15 15 0 10
3 8 8
s 5 3 8 6 10 t
1 ?
capacity 40 6 15 0 10
15
flow 11 11 Value = ?
4 30 7
2
11/10/20
9
2 9 5
10 1 9
10 15 15 0 10
4 0
4 8 9
s 5 3 8 6 10 t
4 10
capacity 40 6 15 0 10
15
flow 14 14 Value = 28
4 30 7
Ford-Fulkerson Algorithm
Basic Algorithm:
• Identify an ! − # path and augment the flow along that path
• How to find a path? BFS or DFS
• Bottleneck along path determines amount flow can be augmented
Ford-Fulkerson ( G=(V,E), c, s, t )
1. Initialize flow f to 0 Consider an augmenting path is a
2. While exists augmenting path p do path that you can still increase the
3. Augment flow f along p flow of it. So at each edge has
4. Return f $(&) < )(&).
3
11/10/20
Residual Graph
Original edge: ! = ($, &) ∈ ). capacity
• Flow +(!), capacity ,(!). u 17 v
Residual edge 6
• "Undo" flow sent. flow
Ford-Fulkerson Algorithm
Complete Algorithm: Ford-Fulkerson ( G=(V,E), c, s, t )
4
11/10/20
Analysis of Ford-Fulkerson
Does it terminate?
Assumption: Flow capacities are all integer values.
Invariant: Every flow value !(#) and every residual capacity
%! (#) remains an integer throughout the algorithm.
Theorem: Let C = ∑ c(e)
e out of s
Analysis of Ford-Fulkerson
What is the running time?
How much work for each iteration?
• Finding an ! − # path in the residual graph $%
• $% has at most 2' edges
• Use BFS/DFS: ((' + +) = ((') since assume $ is connected
• Augment flow along the path
• ((') to update each edge along the path (conservative)
• Update the residual graph
• ((') to update each edge (conservative)
• Total running time for Ford-Fulkerson is: (('.)
• NOTE – this is pseudo-polynomial (similar to Knapsack problem)
5
11/10/20
Analysis of Ford-Fulkerson
Does it generate the maximum flow?
Cuts
Def. A ! − # cut is a partition (%, ') of ) with ! ∈ % and # ∈ '.
Def. The capacity of a cut (%, ') is: cap( A, B) = ∑ c(e)
e out of A
2 9 5
10 € 15 15 10
4
s 5 3 8 6 10 t
A
4 6 15 10
15
Capacity = 10 + 5 + 15
4 30 7 = 30
6
11/10/20
Cuts
Def. A ! − # cut is a partition (%, ') of ) with ! ∈ % and # ∈ '.
Def. The capacity of a cut (%, ') is: cap( A, B) = ∑ c(e)
e out of A
2 9 5
€ 15 15
4
10 10
s 5 3 8 6 10 t
A 15
4 6 10
15
Capacity = 9 + 15 + 8 + 30
4 30 7 = 62
2 9 5
10 15 15 10
4
s 5 3 8 6 10 t
4 6 15 10
A 15
Capacity = 10 + 8 + 10
4 30 7 = 28
7
11/10/20
6
2 9 5
€ 10 0 6
10 15 15 0 10
44
3 8 8
s 5 3 8 6 10 t
A 1 10
40 6 15 0 10
15
11 11 Value = 24
4 30 7
6
2 9 5
€ 10 0 6
10 15 15 0 10
44
3 8 8
s 5 3 8 6 10 t
A 1 10
40 6 15 0 10
15
11 11 Value = 6 + 0 + 8 - 1 + 11
4 30 7 = 24
8
11/10/20
Pf. € v( f ) = ∑ f (e)
e out of s
= ∑ f (e) − ∑ f (e).
e out of A e in to A
9
11/10/20
Certificate of Optimality
Corollary: Let ! be any flow, and let (#, %) be any cut.
If '(!) = )*+(#, %), then ! is a max flow and (#, %) is a min cut.
Value of flow = ? 9
Cut capacity = ? 2 9 5
10 1 9
Þ 10
40 15 15 0 10
Max flow = ?
4 8 9
s 5 3 8 6 10 t
A 4 10
40 6 15 0 10
15
14 14
4 30 7
10
11/10/20
11
11/10/20
12
11/10/20
Capacity Scaling
Intuition: Choosing path with highest bottleneck capacity increases
flow by max possible amount.
• Maintain scaling parameter D.
• Let !" (D) be the subgraph of the residual graph consisting of only
edges with capacity at least D.
4 4
s 1 t s t
Gf 2 Gf (64) 2
Capacity Scaling
• Start with D = largest power of 2 that is smaller than #, the sum of
the capacities of all edges out of s.
• Discover all $ − & paths in '( (D).
• Divide D by 2 and repeat, until finding all paths with D = 1.
4 4
s 1 t s t
2 Gf (64) 2
Gf
13
11/10/20
Running Time
• The scaling max-flow algorithm finds a max flow in
(() log -) augmentations. It can be implemented to run in
(()2 log -) time.
• (reducing the dependency on flow capacity to log -)
Edmonds-Karp Algorithm
General Idea: For each iteration, the shortest augmentation path is chosen.
Running Time: Each edge can be a critical edge at most !/2 times, since all
shortest paths will be length ! − 1 or less. Every augmentation must
involve at least one critical edge. Thus the total number of augmentations
is &(!(), and the total running time of Edmonds-Karp is &(!(2).
Dependency on C has been completely removed.
14