Presentation is loading. Please wait.

Presentation is loading. Please wait.

Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf.

Similar presentations


Presentation on theme: "Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf."— Presentation transcript:

1 www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University pursuant to Part VB of the Copyright Act 1968 (the Act). The material in this communication may be subject to copyright under the Act. Any further reproduction or communication of this material by you may be the subject of copyright protection under the Act. Do not remove this notice.

2 www.monash.edu.au FIT2004 Algorithms & Data Structures L15: Flow Problems Prepared by: Bernd Meyer April 2007

3 www.monash.edu.au 3 Maximum Flow and Minimum Cut Max flow and min cut. –MaxFlow: determine the maximum possible flow from a source node a to a sink node b in some capacity-limited transport network –Min cut is dual to max flow. –Fundamental problems in combinatorial optimization. Many other problems reduce to max flow –scheduling (airlines, trains etc.) –transportation problems –matching problems –network routing –etc.

4 www.monash.edu.au 4 single commodity transport network. directed graph G = (V, E), no parallel edges. s = source, t = sink. c(e) = capacity of edge e. Flow Networks s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 15 4 4 capacity source sink

5 www.monash.edu.au 5 An s-t cut is a partition (A, B) of V with s  A and t  B. Its capacity is: Cuts Capacity = 10 + 5 + 15 = 30 s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 15 4 4 A

6 www.monash.edu.au 6 An s-t cut is a partition (A, B) of V with s  A and t  B. Its capacity is: Cuts s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 15 4 4 A Capacity = 9 + 15 + 8 + 30 = 62

7 www.monash.edu.au 7 Find an s-t cut of minimum capacity. Minimum Cut Problem s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 15 4 4 A Capacity = 10 + 8 + 10 = 28

8 www.monash.edu.au 8 An s-t flow is a function that satisfies: –(capacity) For each e  E: –(conservation) For each v  V – {s, t}: The value of a flow f is: Flows Value = 4 4 0 0 0 0 0 0 4 4 0 0 0 0 capacity flow s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 15 4 4 0 4

9 www.monash.edu.au 9 An s-t flow is a function that satisfies: –(capacity) For each e  E: –(conservation) For each v  V – {s, t}: The value of a flow f is: Flows Value = 24 10 6 6 11 1 10 3 8 8 0 0 0 11 capacity flow s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 15 4 4 0 4

10 www.monash.edu.au 10 Find s-t flow of maximum value. Maximum Flow Problem 10 9 9 14 4 10 4 8 9 1 0 0 0 14 capacity flow s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 15 4 4 0 Value = 28

11 www.monash.edu.au 11 Flow value lemma. Let f be any flow, let (A, B) be any s-t cut. The net flow across the cut is equal to the amount leaving s. Flows and Cuts 10 6 6 11 1 10 3 8 8 0 0 0 11 s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 15 4 4 0 Value = 24 4 A

12 www.monash.edu.au 12 Flow value lemma. Let f be any flow, let (A, B) be any s-t cut. The net flow across the cut is equal to the amount leaving s. Flows and Cuts 10 6 6 11 1 10 3 8 8 0 0 0 11 s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 15 4 4 0 Value = 24 4 A

13 www.monash.edu.au 13 Flow value lemma. Let f be any flow, let (A, B) be any s-t cut. The net flow across the cut is equal to the amount leaving s. Flows and Cuts 10 6 6 11 1 10 3 8 8 0 0 0 11 s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 15 4 4 0 Value = 24 4 A

14 www.monash.edu.au 14 Flows and Cuts Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then by flow conservation, all terms except v = s are 0 if for an edge e both ends are in A, the sum terms cancel if e “points into” A, the sign in negative if e “points out of” A, the sign is positive

15 www.monash.edu.au 15 Flows and Cuts Weak duality. Let f be any flow, and let (A, B) be any s-t cut. The value of the flow is at most the capacity of the cut. Cut capacity = 30  Flow value  30 s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 15 4 4 Capacity = 30 A

16 www.monash.edu.au 16 Weak duality: v(f)  cap(A, B). Flows and Cuts s t A B 7 6 8 4

17 www.monash.edu.au 17 Certificate of Optimality Corollary. Let f be any flow, let (A, B) be any cut. If v(f) = cap(A, B), then f is a max flow and (A, B) is a min cut. Value of flow = 28 Cut capacity = 28  Flow value  28 10 9 9 14 4 10 4 8 9 1 0 0 0 14 s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 15 4 4 0 A

18 www.monash.edu.au 18 Towards a Max Flow Algorithm Greedy algorithm. –Start with f(e) = 0 for all edge e  E. –Find an s-t path P where each edge has f(e) < c(e). –Augment flow along path P. –Repeat until you get stuck. s 1 2 t 10 00 00 0 20 30 Flow value = 0

19 www.monash.edu.au 19 Towards a Max Flow Algorithm Greedy algorithm. –Start with f(e) = 0 for all edge e  E. –Find an s-t path P where each edge has f(e) < c(e). –Augment flow along path P. –Repeat until you get stuck. s 1 2 t 10 200 0 30 Flow value = 20

20 www.monash.edu.au 20 Towards a Max Flow Algorithm greedy = 20 s 1 2 t 2010 20 30 200 0 opt = 30 s 1 2 t 2010 20 30 2010 20 This is only a local optimum!

21 www.monash.edu.au 21 Residual Graph Original edge: e = (u, v)  E. –Flow f(e), capacity c(e). Residual edge. –"Undo" flow sent. –e = (u, v) and e R = (v, u). –Residual capacity: Residual graph: G f = (V, E f ). –Residual edges with positive residual capacity. –E f = {e : f(e) 0}. uv 17 6 capacity uv 11 residual capacity 6 flow

22 www.monash.edu.au 22 Example 1 123 4 5 6 0/2 0/3 0/1 0/5 0/30/4 Augmenting path: 1→2 →3 →6 flow/capacity

23 www.monash.edu.au 23 123 4 5 6 2/2 0/3 0/1 2/5 0/30/4 Augmenting path: 1 →4 →3←2 →5 →6 Example 1 (cont.)

24 www.monash.edu.au 24 123 4 5 6 22 3 1 3 34 Augmenting path: 1 →4 →3←2 →5 →6 Example 1 (cont., Residual Graph) 2

25 www.monash.edu.au 25 123 4 5 6 2/2 1/3 1/1 1/5 1/31/4 max flow value = 3 Example 1 (maximum flow)

26 www.monash.edu.au 26 Augmenting Path Algorithm Augment(f, P) { b  bottleneck(P) foreach e  P { if (e  E) f(e)  f(e) + b else f(e R )  f(e) - b } return f } Ford-Fulkerson(G, s, t) { foreach e  E f(e)  0 G f  residual graph while (there exists augmenting path P) { f  Augment(f, P) update G f } return f } forward edge reverse edge

27 www.monash.edu.au 27 Max-Flow Min-Cut Theorem Augmenting path theorem. Flow f is a max flow iff there are no augmenting paths. Max-flow min-cut theorem. [Ford-Fulkerson 1956] The value of the max flow is equal to the value of the min cut.

28 www.monash.edu.au 28 Max-Flow Min-Cut Theorem Proof strategy. We prove both simultaneously by showing the TFAE: (i)There exists a cut (A, B) such that v(f) = cap(A, B). (ii)Flow f is a max flow. (iii)There is no augmenting path relative to f. (i)  (ii) This was the corollary to weak duality lemma. (ii)  (iii) We show contrapositive. –Let f be a flow. If there exists an augmenting path, then we can improve f by sending flow along path.

29 www.monash.edu.au 29 Proof of Max-Flow Min-Cut Theorem (iii)  (i) –Let f be a flow with no augmenting paths. –Let A be set of vertices reachable from s in residual graph. –By definition of A, s  A. –By definition of f, t  A. original network s t A B

30 www.monash.edu.au 30 Running Time Assumption. All capacities are integers between 1 and C. Invariant. Every flow value f(e) and every residual capacities c f (e) remains an integer throughout the algorithm. WHY? Theorem. The algorithm terminates in at most v(f*)  mC iterations. –Each augmentation increase value by at least 1. Corollary. If the maximum flow is F=v(f*), Ford-Fulkerson runs in O(m F) time. –Finding a path costs O(m+n)=O(m) because G is connected (DFS, BFS)

31 www.monash.edu.au 31 Running Time Integrality theorem. If all capacities are integers, then there exists a max flow f for which every flow value f(e) is an integer. Pf. Since algorithm terminates, theorem follows from invariant.

32 www.monash.edu.au 32 Ford-Fulkerson: Exponential Number of Augmentations Q. Is generic Ford-Fulkerson algorithm polynomial in input size? (m, n, and log C) A. No. If max capacity is C, then algorithm can take C iterations. s 1 2 t C C 00 00 0 C C 1 s 1 2 t C C 1 00 00 0 X 1 C C X X X 1 1 1 X X 1 1 X X X 1 0 1

33 www.monash.edu.au 33 Choosing Good Augmenting Paths Use care when selecting augmenting paths. –Some choices lead to exponential algorithms. –Clever choices lead to polynomial algorithms. Goal: –Can find augmenting paths efficiently. –Few iterations. Choose augmenting paths with: [Edmonds-Karp 1972, Dinitz 1970] –Max bottleneck capacity but can we find this cheaply? –Sufficiently large bottleneck capacity. –Shortest augmenting path (fewest edges)

34 www.monash.edu.au 34 Capacity Scaling Intuition. Choosing path with highest bottleneck capacity increases flow by max possible amount. –Don't worry about finding exact highest bottleneck path. –Maintain scaling parameter . –Let G f (  ) be the subgraph of the residual graph consisting of only arcs with capacity at least . 110 s 4 2 t 1 170 102 122 GfGf 110 s 4 2 t 170 102 122 G f (100)

35 www.monash.edu.au 35 Capacity Scaling Scaling-Max-Flow(G, s, t, c) { foreach e  E f(e)  0   smallest power of 2 greater than or equal to C G f  residual graph while (   1) { G f (  )   -residual graph while (there exists augmenting path P in G f (  )) { f  augment(f, P) update G f (  ) }    / 2 } return f }

36 www.monash.edu.au 36 Capacity Scaling: Correctness Assumption. All edge capacities are integers between 1 and C. Integrality invariant. All flow and residual capacity values are integral. Correctness. If the algorithm terminates, then f is a max flow. –By integrality invariant, when  = 1  G f (  ) = G f. –Upon termination of  = 1 phase, there are no augmenting paths.

37 www.monash.edu.au 37 Capacity Scaling: Running Time The scaling max-flow algorithm finds a max flow in O(m log C) augmentations. It can be implemented to run in O(m 2 log C) time.

38 www.monash.edu.au 38 Capacity Scaling: Running Time 1.The outer while loop repeats 1 +  log 2 C  times. –Initially C   < 2C.  decreases by a factor of 2 each iteration. 2.Let f be the flow at the end of a  -scaling phase. Then the value of the maximum flow is at most v(f) + m . 3.There are at most 2m augmentations per scaling phase. –Let f be the flow at the end of the previous scaling phase. –From (2) we have v(f*)  v(f) + m (2  ). –Each augmentation in a  -phase increases v(f) by at least .

39 www.monash.edu.au 39 Capacity Scaling: Running Time (2) Let f be the flow at the end of a  -scaling phase. Then value of the maximum flow is at most v(f) + m . –We show that at the end of a  -phase, there exists a cut (A, B) such that cap(A, B)  v(f) + m . –Choose A to be the set of nodes reachable from s in G f (  ). –By definition of A, s  A. –By definition of f, t  A. original network s t A B


Download ppt "Www.monash.edu.au 1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf."

Similar presentations


Ads by Google