SLIDE 1
Flow networks
How much flow can we push through from s to t ? (Numbers are capacities.) 5 3 4 2 5 1 7 2
SLIDE 2 Flow networks
5 3 4 2 5 1 7 2 Def: A flow network is a directed graph G=(V,E) where edges have capacities c:E->R+. There are two specified vertices s (source) and t (sink). A flow f:E->R must satisfy:
- Capacity constraint: for every edge e: f(e) · c(e)
- Flow conservation:
for every v in V-{s,t}: e out of v f(e) = e into v f(e) The value of the flow is: e out of s f(e) - e into s f(e) s t
SLIDE 3
Maximum flow problem
Input: a flow network G=(V,E), with capacities c, the source s and sink t Output: a maximum-value flow Algorithm ? t 5 3 4 2 5 1 7 2 s
SLIDE 4 Maximum flow problem – Ford-Fulkerson
5 3 4 2 5 1 2 7 Ford-Fulkerson ( G=(V,E), c, s, t )
- 1. Initialize flow f to 0
- 2. While exists augmenting path p do
3. Augment flow f along p
“Def”: Given a flow f, an augmenting path is a path s=v1, v2, …, vk=t such that f(vi,vi+1) < c(vi,vi+1) for i=1,…,k-1 s t
SLIDE 5 Maximum flow problem – Ford-Fulkerson
5 3 4 2 5 1 2 7 Ford-Fulkerson ( G=(V,E), c, s, t )
- 1. Initialize flow f to 0
- 2. While exists augmenting path p do
3. Augment flow f along p
“Def”: Given a flow f, an augmenting path is a path s=v1, v2, …, vk=t such that f(vi,vi+1) < c(vi,vi+1) for i=1,…,k-1 How to find augmenting paths ? s t
SLIDE 6 Maximum flow problem – Ford-Fulkerson
5 3 4 2 5 1 2 7 Ford-Fulkerson ( G=(V,E), c, s, t )
- 1. Initialize flow f to 0
- 2. While exists augmenting path p do
3. Augment flow f along p
“Def”: Given is G=(V,E), c, f. The residual graph has edges weighted by the residual capacities, i.e. cf(e) = c(e)-f(e) s t
SLIDE 7 Maximum flow problem – Ford-Fulkerson
5 3 4 2 5 1 2 7 Ford-Fulkerson ( G=(V,E), c, s, t )
- 1. Initialize flow f to 0
- 2. While exists augmenting path p do
3. Augment flow f along p
“Def”: Given is G=(V,E), c, f. The residual graph has edges weighted by the residual capacities, i.e. cf(e) = c(e)-f(e) Idea: Find an s-t path in the residual graph! s t
SLIDE 8 Maximum flow problem – Ford-Fulkerson
1 1000 Ford-Fulkerson ( G=(V,E), c, s, t )
- 1. Initialize flow f to 0
- 2. While exists augmenting path p do
3. Augment flow f along p
Consider this input: s t 1000 1000 1000
SLIDE 9 Maximum flow problem – Ford-Fulkerson
1 1000 Ford-Fulkerson ( G=(V,E), c, s, t )
- 1. Initialize flow f to 0
- 2. While exists augmenting path p do
3. Augment flow f along p
Consider this input: Need to refine the definition
residual graph. s t 1000 1000 1000
SLIDE 10 Maximum flow problem – Ford-Fulkerson
1 1000 Refined def: Given is G=(V,E), c, f. The residual graph Gf=(V,E’) contains the following edges:
if e 2 E and f(e) < c(e) then include e in E’ with weight cf(e) = c(e)-f(e),
if e=(u,v) 2 E with f(e)>0 then include (v,u) in E’ with weight cf(v,u) = f(u,v). s t 1000 1000 1000
SLIDE 11 Maximum flow problem – Ford-Fulkerson
Ford-Fulkerson ( G=(V,E), c, s, t )
- 1. For every edge e let f(e)=0
- 2. Construct the residual graph Gf
- 3. While exists s-t path in Gf do
4. Let p be an s-t path in Gf 5. Let d=mine in p cf(e) 6. For every e on p do 7. If e is a forward edge then 8. f(e)+=d 9. else 10. f(reverse(e))-=d 11. Update Gf (construct new Gf) 12.Return f
SLIDE 12 Maximum flow problem – Ford-Fulkerson
Ford-Fulkerson ( G=(V,E), c, s, t )
- 1. For every edge e let f(e)=0
- 2. Construct the residual graph Gf
- 3. While exists s-t path in Gf do
4. Let p be an s-t path in Gf 5. Let d=mine in p cf(e) 6. For every e on p do 7. If e is a forward edge then 8. f(e)+=d 9. else 10. f(reverse(e))-=d 11. Update Gf (construct new Gf) 12.Return f Running time:
SLIDE 13
Maximum flow problem – Ford-Fulkerson
1 1000 Consider this input: s t 1000 1000 1000
SLIDE 14 Maximum flow problem – Ford-Fulkerson
5 3 4 2 5 1 7 7 Ford-Fulkerson ( G=(V,E), c, s, t )
- 1. Initialize flow f to 0
- 2. While exists augmenting path p do
3. Augment flow f along p
Lemma: Ford-Fulkerson works. s t
SLIDE 15
Maximum flow problem – Ford-Fulkerson
5 3 4 2 5 1 7 7 Lemma: Ford-Fulkerson works. Def: Given G=(V,E), c. An s-t cut of G is a subset of vertices S s.t. s 2 S and t 2 SC. Its value is e out of S c(e) s t
SLIDE 16 Maximum flow problem – Ford-Fulkerson
5 3 4 2 5 1 7 7 Lemma: Ford-Fulkerson works. The Max-flow min-cut theorem: Let min-cut(G) be the minimal value
f is a maximum flow iff value(f)=min-cut(G) s t
SLIDE 17 Improving Ford-Fulkerson
5 3 4 2 5 1 7 7 Ford-Fulkerson ( G=(V,E), c, s, t )
- 1. Initialize flow f to 0
- 2. While exists augmenting path p do
3. Augment flow f along p
Can find better paths to reduce the running time? s t
SLIDE 18 5 3 4 2 5 1 7 2 Can find better paths to reduce the running time?
- many ways, will discuss two:
- Scaling paths
- BFS
s t
Improving Ford-Fulkerson
Ford-Fulkerson ( G=(V,E), c, s, t )
- 1. Initialize flow f to 0
- 2. While exists augmenting path p do
3. Augment flow f along p
SLIDE 19 5 3 4 2 5 1 7 2 Can find better paths to reduce the running time?
- many ways, will discuss two:
- Scaling paths
s t
Improving Ford-Fulkerson
Ford-Fulkerson ( G=(V,E), c, s, t )
- 1. Initialize flow f to 0
- 2. While exists augmenting path p do
3. Augment flow f along p
SLIDE 20 5 3 4 2 5 1 7 2 Edmonds-Karp ( G=(V,E), c, s, t )
- 1. Initialize flow f to 0
- 2. While exists augm. path p (check with BFS) do
3. Augment flow f along p
Can find better paths to reduce the running time?
- many ways, will discuss two:
- Scaling paths
- BFS
Thm: Edmonds-Karp takes O(|V||E|) iterations. Running time of Edmonds-Karp: s t
Improving Ford-Fulkerson
SLIDE 21
- multiple sources, multiple sinks
Applications of Network Flows
s1 t1 t2 t3 t4 s2 s3
SLIDE 22
Applications of Network Flows
5 3 4 2 5 1 7 7 s t
SLIDE 23
- maximum number of edge-disjoint s-t paths
Applications of Network Flows
s t
SLIDE 24
- maximum bipartite matching
Applications of Network Flows
SLIDE 25
- maximum bipartite matching
Applications of Network Flows
SLIDE 26
- maximum weighted (perfect) bipartite matching
Applications of Network Flows
7 5 2 3 8 4 4 1 6 3
SLIDE 27 Consider the Diet problem:
- n food items, m nutrients
- for every nutrient: the daily quota bj
- for each item: cost per pound ci
- for every item and nutrient: how much of the nutrient in a
pound of item: ai,j
Introduction to Linear Programming
SLIDE 28 A linear program looks like this:
Introduction to Linear Programming
Find x1, x2, …, xm which
c1x1 + c2x2 + … + cmxm
- and satisfy these constraints:
a1,1x1 + a1,2x2 + … + a1,mxm · b1 a2,1x1 + a2,2x2 + … + a2,mxm · b2 … an,1x1 + an,2x2 + … + an,mxm · bn
SLIDE 29
A linear program in compressed form: Given a vector c in Rm, a vector b in Rn and a matrix A in Rn x m, find a vector x in Rm which satisfies xAT · b and maximizes cxT. Thm: Exists a polynomial-time algorithm solving linear programs. Caveat: Sometimes need integer programs (no algorithm for integer programs is likely to exist) !
Introduction to Linear Programming