Maximum Flow Problem flow capacity Source s actual flow 3/ 4 2/ 2 1/ 1 a b 2/3 d 2/ 2 1/2 c e 1. Actual flow capacity 2. The source node can produce flow as much as possible 3. For every node other than s and t, flow out flow in The target node’s flow-in is called the flow of the graph f 1/ 2 Target (sink) 7/13/2017 A node may have different ways to dispatch its flow-out . g 2/ 3 t What is the maximum flow of the graph? ACM-ICPC 1 What makes the maximum flow problem more difficult than the shortest path problem? Source s 3/ 4 The shortest path of t is based on the shortest path of g. 2/ 2 1/ 1 a once a node’s shortest path from s is determined, we will never have to revise the decision b 2/3 d 2/ 2 1/2 c e The maximum flow to t is not based on the maximum flows to f and g. f g 1/ 2 Target 7/13/2017 2/ 3 t ACM-ICPC 2 local optimum does not imply global optimum Source Source s s 4/5 5/5 2/2 0/1 a b 3/3 1/4 3/3 c Source 2/3 d a 0/3 c s 2/2 5/5 1/1 b 4/4 3/3 0/3 d a 1/3 c 2/2 1/1 b 3/4 1/3 3/3 d Target Target sc max flow = 6 7/13/2017 2/2 sd max flow = 7 ACM-ICPC Target 5/5 t st max flow = 7 3 A naïve approach: adding all possible paths together Source Source s s 2/3 a 1 2 1 2 c d 2/ 2 3 Target a b 4 2/ 3 t Source s 2/ 2 1 2/ 2 d c 1 b 1/ 4 1 d c 2/3 Target t Residual Graph 7/13/2017 a b 4 1 1/1 ACM-ICPC 1/1 Target t Residual Graph 4 Source Source s s 3/3 a 1 b a 3 1 d Target b 2/2 c d 2/ 2 3/3 t Target t Not always work. We are just lucky Residual Graph 7/13/2017 1 1/4 3 c 2/2 ACM-ICPC 5 We may have a wrong choice: Source Source s 3/3 2 2 1 a b 3/4 3 2 Target 2 b 1 3 2 d c 3/3 t 1 a d c 7/13/2017 s 2 So, we keep a path for changing decision: ACM-ICPC Target t 6 Keep a path for changing decision: Source Source s 3/3 s 2 2 3 1 a b 3/4 3 1 a 2 b 1 3 2 3 d c 2 Target d c 3/3 2 t Target 3 t Augmented Graph 7/13/2017 ACM-ICPC 7 Find another path in the augmented graph No more path from s to t Source s s 2/2 3 a b 2/3 2/ 2 3 t Augmented Graph 7/13/2017 3 b a 2 1 b 2 1 2 1 2 d c 2 1 a 2/2 2/3 Target 3 1 1 s 1 2 d c 2 3 1 3 2 1 d c 2 t 3 t new Augmented Graph ACM-ICPC 8 Add flows together Source 3 + s = s 3 2 a b 3 a b 2 2 d 2 a b 2 2 c s 2 1 d c d c 3 3 2 Target 2 t Target t Target t Maximum Flow 7/13/2017 ACM-ICPC 9 An algorithm for finding the maximum flow of graphs Input: G = (V, E), and s,t V Let Gmax = (, ), Gaug = G 1. Find a path p from s to t in Gaug 2. If no such p exists, output Gmax and stop the program 3. Add p into Gmax and update Gaug 4. Repeat 1, 2, and, if possible, 3 Complexity: 7/13/2017 O(f |E|) ACM-ICPC 10 Claim: This algorithm always terminates with a maximum flow of the input graph The proof is somewhat difficult and beyond the scope of 279. Input: G = (V, E), and s,t V Let Gmax = (, ), Gaug = G 1. 2. 3. 4. I say: No, it is not difficult and every one here should know. Find a path p from s to t in Gaug If no such p exists, output Gmax and stop the program Add p into Gmax and update Gaug Repeat 1, 2, and 3 if possible • Since any given graph has a finite maximum flow, and every path from s to t, if any, provides a positive flow, the program therefore cannot run forever. • By contradiction, suppose the algorithm terminates with a flow in Gmax. that is not maximum. Then, there must be a flow not included in Gmax. But, if this is the case, there must be a path from s to t to carries this flow, and hence the program should not terminate at this moment. A contradiction. 7/13/2017 ACM-ICPC 11 An inefficient situation Source s 1/1000 1/1000 1/1 a b 1/ 1 1/1000 1/ 1000 t Target 7/13/2017 ACM-ICPC 12 An inefficient situation Source s 2/ 1/1000 2/ 1/ 1000 1/ 1 a b 2/ 1/1000 2/ 1/ 1000 t Target 7/13/2017 ACM-ICPC 13 Solution Source s 1000/ 1000 Always chose the maximum next edge 1000 a b 1000/ 1000 1/ 1000 t Target 7/13/2017 ACM-ICPC 14
© Copyright 2025 Paperzz