FordFulkerson Recap Residual Flow Network G 3 3

  • Slides: 39
Download presentation
Ford-Fulkerson Recap

Ford-Fulkerson Recap

Residual Flow Network G 3) ( 3 s Gf v 2( 5 (3) 2(

Residual Flow Network G 3) ( 3 s Gf v 2( 5 (3) 2( 0) v 0) w t 3 (3) c(e) (f(e)) s t w

Residual Flow Network G 3) ( 3 s Gf v 2( 5 (3) 2(

Residual Flow Network G 3) ( 3 s Gf v 2( 5 (3) 2( 0) v 0) w t s 3 (3) Forward edge. capacity: c(e)-f(e) 3 2 t w Backward edge. capacity: f(e)

Residual Flow Network G 3) ( 3 s Gf v 2( 5 (3) 2(

Residual Flow Network G 3) ( 3 s Gf v 2( 5 (3) 2( 0) v 0) w t 3 (3) s 3 2 w t

Residual Flow Network G 3) ( 3 s Gf v 2( 0) 5 (3)

Residual Flow Network G 3) ( 3 s Gf v 2( 0) 5 (3) 2( 0) w t 3 (3) s v 3 0 3 2 w t

Residual Flow Network G 3) ( 3 s Gf v 2( 0) 5 (3)

Residual Flow Network G 3) ( 3 s Gf v 2( 0) 5 (3) 2( 0) w t 3 (3) s 3 0 v 3 0 2 2 0 w 2 t 3 0

Residual Flow Network G 3) ( 3 s Gf v 2( 5 (3) 2(

Residual Flow Network G 3) ( 3 s Gf v 2( 5 (3) 2( 0) w v 3 0) t 3 (3) s 3 2 2 Delete all edges with residual capacity 0! w 2 3 t

Gf G v 6 (4) 2 u v u 4 v 6 (6) saturated

Gf G v 6 (4) 2 u v u 4 v 6 (6) saturated u v u 6 empty v 6 (0) u 6 v u

Gf G 6 (4) v 2 u 3 (2) v 4 2 1 u

Gf G 6 (4) v 2 u 3 (2) v 4 2 1 u

Ford-Fulkerson Algorithm • Start: f(e)=0 for all edges e • Compute Gf. • Iterate:

Ford-Fulkerson Algorithm • Start: f(e)=0 for all edges e • Compute Gf. • Iterate: While Gf contains an s-t path: – Let P be any simple s-t path in Gf. Ø improve flow – Let Δ(P)=mine the Pcf(e). – For each edge e=(u, v)Gon P: Ø re-compute f • If e is a forward edge, increase f(e) by Δ • Otherwise, let e'=(v, u) be the edge of G corresponding to e. Reduce f(e’) by Δ. – Recompute Gf.

Ford-Fulkerson Algorithm • Start: f(e)=0 for all edges e • Compute Gf. • While

Ford-Fulkerson Algorithm • Start: f(e)=0 for all edges e • Compute Gf. • While Gf contains an s-t path: – Let P be any simple s-t path in Gf. – Let Δ(P)=mine Pcf(e). – For each edge e=(u, v) on P: Flow • If e is. Update: a forward edge, push increase Δ(P) f(e) by Δflow units • Otherwise, let e'=(v, u) be the edge of G corresponding to e. Reduce f(e’) by Δ. along P – Recompute Gf.

Ford-Fulkerson Algorithm • Start: f(e)=0 for all edges e • Compute Gf. • While

Ford-Fulkerson Algorithm • Start: f(e)=0 for all edges e • Compute Gf. • While Gf contains an s-t path: – Let P be any simple s-t path in Gf. – Let Δ(P)=mine Pcf(e). – For each edge e=(u, v) on P: • If e is a forward edge, increase f(e) by Δ • Otherwise, let e'=(v, u) be the edge of G corresponding to e. Reduce f(e’) by Δ. – Recompute Gf.

We Saw: The flow is always feasible and integral The algorithm terminates Correctness proof:

We Saw: The flow is always feasible and integral The algorithm terminates Correctness proof: optimality is Each iteration takes O(m) time missing Flow value increases by at least 1 in each iteration. • Number of iterations at most sum of capacities. Running time: want faster • •

Is the Flow Optimal? 3) ( 3 s v 2( 2) 5 (1) 2(2

Is the Flow Optimal? 3) ( 3 s v 2( 2) 5 (1) 2(2 ) w t 3 ) 3 (

Is the Flow Optimal? 1 s v 10 0 1 10 0 w t

Is the Flow Optimal? 1 s v 10 0 1 10 0 w t 1 1 (1) s 10 0 v (2) 1 (1) (2) w t 1 ) 1 (

Is the Flow Optimal? 1 s v 10 0 1 10 0 w t

Is the Flow Optimal? 1 s v 10 0 1 10 0 w t 1 1 (1) s 10 0 v (2) 1 (1) (2) w t 1 ) 1 (

Ford-Fulkerson Algorithm • Start: f(e)=0 for all edges e • Compute Gf. • While

Ford-Fulkerson Algorithm • Start: f(e)=0 for all edges e • Compute Gf. • While Gf contains an s-t path: – Let P be any simple s-t path in Gf. – Let Δ(P)=mine Pcf(e). – For each edge e=(u, v) on P: • If e is a forward edge, increase f(e) by Δ • Otherwise, let e'=(v, u) be the edge of G corresponding to e. Reduce f(e’) by Δ. – Recompute Gf.

Ford-Fulkerson Algorithm • Start: f(e)=0 for all edges e • Compute Gf. • While

Ford-Fulkerson Algorithm • Start: f(e)=0 for all edges e • Compute Gf. • While Gf contains an s-t path: – Let P be any simple s-t path in Gf. – Let Δ(P)=mine Pcf(e). – For each edge e=(u, v) on P: • If e is a forward edge, increase f(e) by Δ • Otherwise, let e'=(v, u) be the edge of G corresponding to e. Reduce f(e’) by Δ. – Recompute Gf.

Edmonds-Karp Algorithm • Start: with f(e)=0 for all edges e • Compute Gf. •

Edmonds-Karp Algorithm • Start: with f(e)=0 for all edges e • Compute Gf. • While Gf contains an s-t path: – Let P be the shortest simple s-t path in Gf. – Let Δ(P)=mine Pcf(e). – For each edge e=(u, v) on P: • If e is a forward edge, increase f(e) by Δ • Otherwise, let e'=(v, u) be the edge of G corresponding to e. Reduce f(e’) by Δ. – Recompute Gf.

Changes to Gf Gf s P t

Changes to Gf Gf s P t

Changes to Gf Gf’ s P t Claim: • Only edges of P may

Changes to Gf Gf’ s P t Claim: • Only edges of P may disappear • At least one of them has to disappear • The only new edges are anti-parallel to edges of P

Claim: distance from s to t in the residual graph never decreases

Claim: distance from s to t in the residual graph never decreases

Claim: distance from s to t in the residual graph never decreases

Claim: distance from s to t in the residual graph never decreases

BFS from s in Gf t s d+1 d is length of augmenting path

BFS from s in Gf t s d+1 d is length of augmenting path

BFS from s in Gf shortcut edge forward-looking edges t s d+1

BFS from s in Gf shortcut edge forward-looking edges t s d+1

BFS from s inbackward-looking Gf edges t s d+1

BFS from s inbackward-looking Gf edges t s d+1

BFS from s in Gf sideways-looking edges t s d+1

BFS from s in Gf sideways-looking edges t s d+1

BFS from s in Gf t s d+1

BFS from s in Gf t s d+1

BFS from s in Gf t s d+1

BFS from s in Gf t s d+1

BFS from s in Gf We do not create shortcut edges! t s d+1

BFS from s in Gf We do not create shortcut edges! t s d+1 The s-t distance cannot decrease!

Claim: a phase has no more than m iterations.

Claim: a phase has no more than m iterations.

BFS from s in Gf at the Start of the Phase t s d+1

BFS from s in Gf at the Start of the Phase t s d+1

BFS from s in Gf at the Start of the Phase t s d+1

BFS from s in Gf at the Start of the Phase t s d+1

BFS from s in Gf at the Start of the Phase t s d+1

BFS from s in Gf at the Start of the Phase t s d+1

BFS from s in Gf at the Start of the Phase t s d+1

BFS from s in Gf at the Start of the Phase t s d+1

BFS from s in Gf at the Start of the Phase t s d+1

BFS from s in Gf at the Start of the Phase t s d+1

BFS from s in Gf at the Start of the Phase t s d+1

BFS from s in Gf at the Start of the Phase t s d+1

BFS from s in Gf at the Start of the Phase t s d+1

BFS from s in Gf at the Start of the Phase t s d+1

BFS from s in Gf at the Start of the Phase • We never

BFS from s in Gf at the Start of the Phase • We never create shortcut edges • As long as augmenting path length is d, it has to visit every layer in turn Induction s Conclusion: at most m iterations to a phase! t We do not create new forward-looking edges in a phase. d+1 At least one forward-looking edge deleted in each iteration