Flow networks 2 5 How much flow can

  • Slides: 31
Download presentation
Flow networks 2 5 How much flow can we push through from s to

Flow networks 2 5 How much flow can we push through from s to t ? (Numbers are capacities. ) 1 4 7 3 5 2

Flow networks 2 5 How much flow can we push through from s to

Flow networks 2 5 How much flow can we push through from s to t ? (Numbers are capacities. ) 1 4 7 3 5 3

Flow networks 2 5 How much flow can we push through from s to

Flow networks 2 5 How much flow can we push through from s to t ? (Numbers are capacities. ) 1 4 7 3 5 4

Flow networks 2 5 How much flow can we push through from s to

Flow networks 2 5 How much flow can we push through from s to t ? (Numbers are capacities. ) 1 4 7 3 5 7

2 Flow networks 5 s 1 4 7 3 5 Def: t 2 A

2 Flow networks 5 s 1 4 7 3 5 Def: t 2 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)

Maximum flow problem 2 Input: a flow network G=(V, E), with capacities c, the

Maximum flow problem 2 Input: a flow network G=(V, E), with capacities c, the source s and sink t Output: a maximum-value flow Algorithm ? 5 s 1 4 7 3 5 t 2

Maximum flow problem – Ford-Fulkerson “Def”: 2 Given a flow f, an augmenting path

Maximum flow problem – Ford-Fulkerson “Def”: 2 Given a flow f, an augmenting path is a path s=v 1, v 2, …, vk=t such that s f(vi, vi+1) < c(vi, vi+1) for i=1, …, k-1 5 1 4 2 3 5 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 4. Return f t 7

Maximum flow problem – Ford-Fulkerson 2 “Def”: Given a flow f, an augmenting path

Maximum flow problem – Ford-Fulkerson 2 “Def”: Given a flow f, an augmenting path is a path s=v 1, v 2, …, vk=t such that s f(vi, vi+1) < c(vi, vi+1) for i=1, …, k-1 5 1 4 2 3 5 How to find augmenting paths ? 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 4. Return f t 7

Maximum flow problem – Ford-Fulkerson “Def”: Given is G=(V, E), c, f. The residual

Maximum flow problem – Ford-Fulkerson “Def”: Given is G=(V, E), c, f. The residual graph has edges s weighted by the residual capacities, i. e. cf(e) = c(e)-f(e) 2 5 1 4 2 3 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 4. Return f 5 t 7

Maximum flow problem – Ford-Fulkerson 2 “Def”: Given is G=(V, E), c, f. The

Maximum flow problem – Ford-Fulkerson 2 “Def”: Given is G=(V, E), c, f. The residual graph has edges s weighted by the residual capacities, i. e. cf(e) = c(e)-f(e) 5 1 4 2 3 Idea: Find an s-t path in the residual graph! 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 4. Return f 5 t 7

Maximum flow problem – Ford-Fulkerson Consider this input: 1000 s 1 1000 Ford-Fulkerson (

Maximum flow problem – Ford-Fulkerson Consider this input: 1000 s 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 4. Return f t 1000

Maximum flow problem – Ford-Fulkerson Consider this input: 1000 Need to refine the definition

Maximum flow problem – Ford-Fulkerson Consider this input: 1000 Need to refine the definition of augmenting paths and residual graph. s 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 4. Return f t 1000

Maximum flow problem – Ford-Fulkerson Refined def: Given is G=(V, E), c, f. The

Maximum flow problem – Ford-Fulkerson Refined def: Given is G=(V, E), c, f. The residual graph Gf=(V, E’) contains the following edges: • forward edge: if e 2 E and f(e) < c(e) then include e in E’ with weight cf(e) = c(e)-f(e), • backward edge: if e=(u, v) 2 E with f(e)>0 then include (v, u) in E’ with weight cf(v, u) = f(u, v). 1000 s 1 1000 t 1000

Maximum flow problem – Ford-Fulkerson ( G=(V, E), c, s, t ) 1. For

Maximum flow problem – 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

Maximum flow problem – Ford-Fulkerson ( G=(V, E), c, s, t ) 1. For

Maximum flow problem – 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:

Maximum flow problem – Ford-Fulkerson 1000 s 1 1000 t 1000

Maximum flow problem – Ford-Fulkerson 1000 s 1 1000 t 1000

Maximum flow problem – Ford-Fulkerson Lemma: 2 5 Ford-Fulkerson works. s 1 4 7

Maximum flow problem – Ford-Fulkerson Lemma: 2 5 Ford-Fulkerson works. s 1 4 7 3 5 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 4. Return f t 2

Maximum flow problem – Ford-Fulkerson 2 Lemma: 5 Ford-Fulkerson works. s Def: Given G=(V,

Maximum flow problem – Ford-Fulkerson 2 Lemma: 5 Ford-Fulkerson works. s 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) 1 4 7 3 5 t 2

Maximum flow problem – Ford-Fulkerson 2 Lemma: 5 Ford-Fulkerson works. s Let min-cut(G) be

Maximum flow problem – Ford-Fulkerson 2 Lemma: 5 Ford-Fulkerson works. s Let min-cut(G) be the minimal value of an s-t cut of G. Then: iff 4 7 3 The Max-flow min-cut theorem: f is a maximum flow 1 5 value(f)=min-cut(G) t 2

Improving Ford-Fulkerson Can find better paths to reduce the running time? 2 5 s

Improving Ford-Fulkerson Can find better paths to reduce the running time? 2 5 s 1 4 7 3 5 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 4. Return f t 2

Improving Ford-Fulkerson Can find better paths to reduce the running time? - many ways,

Improving Ford-Fulkerson Can find better paths to reduce the running time? - many ways, will discuss two: - Scaling paths 2 5 s 1 4 7 3 - BFS 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 4. Return f 5 t 2

Improving Ford-Fulkerson Can find better paths to reduce the running time? - many ways,

Improving Ford-Fulkerson Can find better paths to reduce the running time? - many ways, will discuss two: - Scaling paths 2 5 s 8 4 7 3 5 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 4. Return f t 2

Improving Ford-Fulkerson 2 Can find better paths to reduce the running time? - many

Improving Ford-Fulkerson 2 Can find better paths to reduce the running time? - many ways, will discuss two: - Scaling paths 5 s 1 4 7 3 - BFS 5 t 2 Thm: Edmonds-Karp takes O(|V||E|) iterations. Running time of Edmonds-Karp: 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 4. Return f

Applications of Network Flows • multiple sources, multiple sinks s 1 t 1 s

Applications of Network Flows • multiple sources, multiple sinks s 1 t 1 s 2 t 2 s 3 t 4

Applications of Network Flows • how to find minimum cut 2 5 s 1

Applications of Network Flows • how to find minimum cut 2 5 s 1 4 7 3 5 t 7

Applications of Network Flows • maximum number of edge-disjoint s-t paths s t

Applications of Network Flows • maximum number of edge-disjoint s-t paths s t

Applications of Network Flows • maximum bipartite matching

Applications of Network Flows • maximum bipartite matching

Applications of Network Flows • maximum weighted (perfect) bipartite matching 7 5 2 3

Applications of Network Flows • maximum weighted (perfect) bipartite matching 7 5 2 3 4 4 1 6 3 8

Introduction to Linear Programming Consider the Diet problem: - n food items, m nutrients

Introduction to Linear Programming 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 A linear program looks like this: Find x 1, x

Introduction to Linear Programming A linear program looks like this: Find x 1, x 2, …, xm which • maximize c 1 x 1 + c 2 x 2 + … + c m x m • and satisfy these constraints: a 1, 1 x 1 + a 1, 2 x 2 + … + a 1, mxm · b 1 a 2, 1 x 1 + a 2, 2 x 2 + … + a 2, mxm · b 2 … an, 1 x 1 + an, 2 x 2 + … + an, mxm · bn

Introduction to Linear Programming A linear program in compressed form: Given a vector c

Introduction to Linear Programming 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 x. AT · b and maximizes cx. T. Thm: Exists a polynomial-time algorithm solving linear programs. Caveat: Sometimes need integer programs (no algorithm for integer programs is likely to exist) !