objectives
play

Objectives Network Flow Max flow Min cut March 29, 2019 CSCI211 - PDF document

3/29/19 Objectives Network Flow Max flow Min cut March 29, 2019 CSCI211 - Sprenkle 1 Motivating Flow Network Problems Modeling transportation networks Edges: carry traffic Nodes: pass traffic between edges Can represent


  1. 3/29/19 Objectives • Network Flow Ø Max flow Ø Min cut March 29, 2019 CSCI211 - Sprenkle 1 Motivating Flow Network Problems • Modeling transportation networks Ø Edges: carry traffic Ø Nodes: pass traffic between edges • Can represent many different types of problems Ø Instead of looking at all possibilities, formulate as a flow problem March 29, 2019 CSCI211 - Sprenkle 2 1

  2. 3/29/19 Flow Network • G = (V, E) = directed graph, no parallel edges • Two distinguished nodes: s = source, t = sink • c(e) = capacity of edge e, > 0 2 9 5 10 15 15 10 4 source 5 sink s 3 8 6 10 t 4 15 6 10 15 capacity 30 4 7 March 29, 2019 CSCI211 - Sprenkle 3 Flows: Definitions Flow can’t exceed • An s-t flow is a function that satisfies capacity Ø Capacity condition : For each e ∈ E: 0 ≤ f(e) ≤ c(e) Ø Conservation condition : For each v ∈ V – {s, t}: Flow in == Flow out ∑ e into y f(e) = ∑ e out of y f(e) 0 2 9 5 4 0 0 10 15 15 0 10 4 4 0 4 4 source 5 sink s 3 8 6 10 t 0 0 4 15 0 6 0 capacity 10 15 15 flow 0 0 30 4 7 March 29, 2019 CSCI211 - Sprenkle 4 2

  3. 3/29/19 Flows: Definitions • The value of a flow f is v(f) = ∑ e out of s f(e) 0 2 5 9 4 0 0 10 15 15 0 10 4 4 0 4 4 s 3 6 t 5 8 10 0 0 15 0 4 0 6 capacity 10 15 flow 0 0 Value = 4 4 7 30 March 29, 2019 CSCI211 - Sprenkle 5 Maximum Flow Problem • Make network most efficient Ø Use most of available capacity Goal : Find s-t flow of maximum value 9 2 9 5 10 9 1 10 15 15 0 10 4 0 4 9 8 s 5 3 8 6 t 10 4 10 4 0 15 0 6 capacity 10 15 flow 14 14 Value = 28 4 30 7 March 29, 2019 CSCI211 - Sprenkle 6 3

  4. 3/29/19 Towards a Max Flow Algorithm • Greedy algorithm Ø Start all edges e Î E at f(e) = 0 Ø Find an s-t path P with the most capacity: f(e) < c(e) Ø Augment flow along path P Ø Repeat until you get stuck 1 0 0 20 10 s t 30 0 20 10 Flow value = 0 0 0 2 March 29, 2019 CSCI211 - Sprenkle 7 Towards a Max Flow Algorithm • Greedy algorithm Ø Start all edges e Î E at f(e) = 0 Ø Find an s-t path P with the most capacity: f(e) < c(e) Ø Augment flow along path P Ø Repeat until you get stuck 1 X 20 0 0 Is this optimal? 20 10 X s t 30 0 20 20 10 X Flow value = 20 0 0 20 2 March 29, 2019 CSCI211 - Sprenkle 8 4

  5. 3/29/19 Towards a Max Flow Algorithm • Greedy algorithm Ø Start all edges e Î E at f(e) = 0 Ø Find an s-t path P with the most capacity: f(e) < c(e) Ø Augment flow along path P Ø Repeat until you get stuck locally optimality does not Þ global optimality 1 1 20 0 20 10 20 10 20 10 s t s t 30 20 30 10 greedy = 20 10 20 10 20 0 20 10 20 opt = 30 2 2 March 29, 2019 CSCI211 - Sprenkle 9 Towards a solution… RESIDUAL GRAPHS March 29, 2019 CSCI211 - Sprenkle 10 5

  6. 3/29/19 Towards a Residual Graph • Original edge: e = (u, v) Î E capacity u v Ø Flow f(e), capacity c(e) 17 6 flow March 29, 2019 CSCI211 - Sprenkle 11 Towards a Residual Graph • Original edge: e = (u, v) Î E capacity u v Ø Flow f(e), capacity c(e) 17 6 • Residual edge flow Ø e = (u, v) w/ capacity c(e) - f(e) residual capacity Ø e R = (v, u) with capacity f(e) u v 11 • To undo flow 6 residual capacity March 29, 2019 CSCI211 - Sprenkle 12 6

  7. 3/29/19 Residual Graph: G f • Original edge: e = (u, v) Î E capacity u v Ø Flow f(e), capacity c(e) 17 6 • Residual edge flow Ø e = (u, v) w/ capacity c(e) - f(e) residual capacity Ø e R = (v, u) with capacity f(e) u v 11 • To undo flow 6 • Residual graph: G f = (V, E f ) residual capacity Ø Residual edges with positive residual capacity Ø E f = {e : f(e) < c(e)} È {e R : f(e) > 0} Backward edges Forward edges March 29, 2019 CSCI211 - Sprenkle 13 Applying Residual Graph • Used to find the maximum flow Ø Use similar idea to greedy algorithm • Residual path: simple s-t path in G f Ø Also known as augmenting path March 29, 2019 CSCI211 - Sprenkle 14 7

  8. 3/29/19 Augmenting Path Algorithm c=capacity Ford Ford-Fulkerson(G, s, t, c): Fulkerson(G, s, t, c): foreach foreach e Î E f(e) = 0 # initially no flow G f = residual graph while while there exists augmenting path P f = Augment(f, c, P) # change the flow update G f # build a new residual graph return f return Augment(f, c, P): Augment(f, c, P): b = bottleneck(P) # edge on P with least capacity foreach foreach e Î P if if (e Î E) f(e) = f(e) + b # forward edge, é flow else else f(e R ) = f(e) - b # forward edge, ê flow return f return March 29, 2019 CSCI211 - Sprenkle 15 Ford-Fulkerson Algorithm 0 flow 2 4 4 capacity G: 0 0 0 6 0 8 10 10 2 0 0 0 0 10 s 3 5 10 t 9 Flow value = 0 March 29, 2019 CSCI211 - Sprenkle 16 8

  9. 3/29/19 Ford-Fulkerson Algorithm 0 flow 2 4 4 capacity G: 0 0 0 6 0 8 10 10 2 0 0 0 0 10 s 3 5 10 t 9 Flow value = 0 What does the residual graph look like? March 29, 2019 CSCI211 - Sprenkle 17 Ford-Fulkerson Algorithm 0 flow 2 4 4 capacity G: 0 0 0 6 0 8 10 10 2 0 0 0 0 10 s 3 5 10 t 9 Flow value = 0 2 4 G f : s 3 5 t March 29, 2019 CSCI211 - Sprenkle 18 9

  10. 3/29/19 Ford-Fulkerson Algorithm 0 flow 2 4 4 capacity G: 0 0 0 6 0 8 10 10 2 0 0 0 0 10 s 3 5 10 t 9 Flow value = 0 Bottleneck 2 4 4 residual capacity G f : 8 6 10 10 2 10 s 3 5 10 t 9 March 29, 2019 CSCI211 - Sprenkle 19 Ford-Fulkerson Algorithm 0 2 4 4 G: 10 X 0 8 8 6 0 8 10 10 2 X 0 2 10 X 0 8 X 0 2 10 s 3 5 10 t 9 Flow value = 8 2 4 4 G f : 8 8 6 10 2 2 10 s 3 5 2 t 9 8 March 29, 2019 CSCI211 - Sprenkle 20 10

  11. 3/29/19 Ford-Fulkerson Algorithm 0 2 4 4 G: X 6 0 10 8 6 0 8 X 10 10 2 2 6 6 X 0 10 2 8 X 10 s 3 5 10 t 9 Flow value = 10 2 4 4 G f : 8 6 10 10 2 10 s 3 5 10 t 7 2 March 29, 2019 CSCI211 - Sprenkle 21 Ford-Fulkerson Algorithm 2 X 0 2 4 4 G: X 8 6 10 8 6 6 8 10 10 2 2 X 0 8 X 6 10 8 10 s 3 5 10 t 9 Flow value = 16 2 4 4 G f : 6 8 6 10 4 2 4 s 3 5 10 t 1 6 8 March 29, 2019 CSCI211 - Sprenkle 22 11

  12. 3/29/19 Ford-Fulkerson Algorithm 2 3 X 2 4 4 G: X 8 9 10 8 7 X 6 6 8 10 10 2 0 X 8 9 10 8 9 X 10 s 3 5 10 t 9 Flow value = 18 2 2 2 4 G f : 8 8 6 10 2 2 2 s 3 5 10 t 1 8 8 March 29, 2019 CSCI211 - Sprenkle 23 Ford-Fulkerson Algorithm 3 2 4 4 G: 9 10 7 6 6 8 10 10 2 0 9 10 9 10 s 3 5 10 t 9 Flow value = 19 3 2 1 4 G f : 9 1 7 6 10 1 2 1 s 3 5 10 t 9 9 How do we know we’re done? March 29, 2019 CSCI211 - Sprenkle 24 12

  13. 3/29/19 Ford-Fulkerson Algorithm 3 2 4 4 G: 9 10 7 6 6 8 10 10 2 0 9 10 9 10 s 3 5 10 t 9 Flow value = 19 Cut capacity = 19 3 2 1 4 G f : 9 1 7 6 10 1 2 1 s 3 5 10 t 9 9 What is reachable from s March 29, 2019 CSCI211 - Sprenkle 25 Analyzing Augmenting Path Algorithm Ford Ford-Fulkerson(G Fulkerson(G, , s, , t, , c) foreach foreach e Î E E f(e f(e) ) = 0 0 # initially no flow # initially no flow G f = residual graph residual graph while while there exists augmenting path P there exists augmenting path P f = Augment(f Augment(f, , c, P) , P) # change the flow # change the flow update update G f # build a new residual graph # build a new residual graph return return f Augment(f Augment(f, , c, P) , P) b = = bottleneck(P bottleneck(P) ) # edge on P with least capacity # edge on P with least capacity foreach foreach e Î P if (e Î E) if E) f(e f(e) ) = f(e f(e) + ) + b # forward edge, # forward edge, é flow flow else else f(e f(e R ) ) = f(e f(e) ) - b # forward edge, # forward edge, ê flow flow return return f Why does alg work? What is happening at each iteration? March 29, 2019 What is the running time? CSCI211 - Sprenkle 26 Need more analysis … 13

  14. 3/29/19 MINIMUM CUTS March 29, 2019 CSCI211 - Sprenkle 27 Cuts • An s-t cut is a partition (A, B) of V with s Î A and t Î B • The capacity of a cut (A, B) is cap ( A , B ) = c ( e ) ∑ e out of A B What is the capacity 9 2 5 of this cut? 10 15 15 10 4 s 5 3 8 6 10 t A 15 4 6 10 15 Capacity = 9 + 15 + 8 + 30 = 62 30 4 7 March 29, 2019 CSCI211 - Sprenkle 28 14

  15. 3/29/19 Minimum Cut Problem • Find an s-t cut of minimum capacity Ø Puts upperbound on maximum flow Same graph, 2 9 5 different cut B 10 15 15 10 4 5 8 s 3 6 10 t 15 4 6 10 15 A Capacity = 10 + 8 + 10 = 28 30 4 7 March 29, 2019 CSCI211 - Sprenkle 29 Recall • The value of a flow f is v(f) = ∑ e out of s f(e) 0 2 5 9 4 0 0 10 15 15 0 10 4 4 0 4 4 s 3 6 t 5 8 10 0 0 15 0 4 0 6 capacity 10 15 flow 0 0 Value = 4 4 7 30 March 29, 2019 CSCI211 - Sprenkle 30 15

Recommend


More recommend