Flow networks 2 5 1 How much flow can we push 4 7 through from - - PowerPoint PPT Presentation

flow networks
SMART_READER_LITE
LIVE PREVIEW

Flow networks 2 5 1 How much flow can we push 4 7 through from - - PowerPoint PPT Presentation

Flow networks 2 5 1 How much flow can we push 4 7 through from s to t ? 3 2 (Numbers are capacities.) 5 2 Flow networks 5 1 s 4 7 t 3 2 5 Def: A flow network is a directed graph G=(V,E) where edges have capacities c:E->R +


slide-1
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
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
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
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

  • 4. Return f

“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
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

  • 4. Return f

“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
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

  • 4. Return f

“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
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

  • 4. Return f

“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
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

  • 4. Return f

Consider this input: s t 1000 1000 1000

slide-9
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

  • 4. Return f

Consider this input: Need to refine the definition

  • f augmenting paths and

residual graph. s t 1000 1000 1000

slide-10
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:

  • 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). s t 1000 1000 1000

slide-11
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
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
SLIDE 13

Maximum flow problem – Ford-Fulkerson

1 1000 Consider this input: s t 1000 1000 1000

slide-14
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

  • 4. Return f

Lemma: Ford-Fulkerson works. s t

slide-15
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
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 an s-t cut of G. Then:

f is a maximum flow iff value(f)=min-cut(G) s t

slide-17
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

  • 4. Return f

Can find better paths to reduce the running time? s t

slide-18
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

  • 4. Return f
slide-19
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

  • 4. Return f
slide-20
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

  • 4. Return f

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
SLIDE 21
  • multiple sources, multiple sinks

Applications of Network Flows

s1 t1 t2 t3 t4 s2 s3

slide-22
SLIDE 22
  • how to find minimum cut

Applications of Network Flows

5 3 4 2 5 1 7 7 s t

slide-23
SLIDE 23
  • maximum number of edge-disjoint s-t paths

Applications of Network Flows

s t

slide-24
SLIDE 24
  • maximum bipartite matching

Applications of Network Flows

slide-25
SLIDE 25
  • maximum bipartite matching

Applications of Network Flows

slide-26
SLIDE 26
  • maximum weighted (perfect) bipartite matching

Applications of Network Flows

7 5 2 3 8 4 4 1 6 3

slide-27
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
SLIDE 28

A linear program looks like this:

Introduction to Linear Programming

Find x1, x2, …, xm which

  • maximize

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
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