Network Flow CSE 373 Data Structures
Sources and Sinks S T 4/7/2019 CSE 373 AU 2005 -- Network Flow
Flow Conservation 14 + 10 = 6 + 11 + 7 6 14 11 10 7 4/7/2019 CSE 373 AU 2005 -- Network Flow
Capacities/Saturation 7/9 T 7/10 7/7 7/11 flow / capacity 4/7/2019 CSE 373 AU 2005 -- Network Flow
Flow Cancellation 8 5 = 3 4/7/2019 CSE 373 AU 2005 -- Network Flow
Max Flow? A 0/12 B 0/20 0/16 0/4 S T 0/10 0/7 0/9 0/13 0/4 C D 0/14 4/7/2019 CSE 373 AU 2005 -- Network Flow
A Flow A 12/12 B 19/20 11/16 1/4 S T 0/10 7/7 0/9 12/13 4/4 C D 11/14 4/7/2019 CSE 373 AU 2005 -- Network Flow
A Flow saturated 12 + 7 = 19 + 0 A 12/12 B 19/20 11/16 1/4 S T 0/10 7/7 0/9 saturated 12/13 4/4 saturated C D 11/14 12 + 0 + 0 = 1 + 11 4/7/2019 CSE 373 AU 2005 -- Network Flow
Cuts 23/29 A 12/12 B 19/20 11/16 1/4 S T 0/10 7/7 0/9 12/13 4/4 C D 11/14 Remove edges until S is in one connected component, and T in the other 23/29 4/7/2019 CSE 373 AU 2005 -- Network Flow
Cuts 23/26 A 12/12 B 19/20 11/16 1/4 S T 0/10 7/7 0/9 12/13 4/4 C D 11/14 23/26 Only count forward edges 4/7/2019 CSE 373 AU 2005 -- Network Flow
Cuts 23/31 A 12/12 B 19/20 11/16 1/4 S T 0/10 7/7 0/9 12/13 4/4 C D 11/14 23/31 4/7/2019 CSE 373 AU 2005 -- Network Flow
Min Cut 23/23 A 12/12 B 19/20 11/16 1/4 S T 0/10 7/7 0/9 12/13 4/4 C D 11/14 23/23 4/7/2019 CSE 373 AU 2005 -- Network Flow
Max Flow = Min Cut 23 23 A 12/12 B 19/20 11/16 1/4 S T 0/10 7/7 0/9 12/13 4/4 C D 11/14 No more capacity along cut to take more flow 4/7/2019 CSE 373 AU 2005 -- Network Flow
Ford-Fulkerson Method Single source, single sink Several algorithms are implementations of this method Requires integer capacities for steady progress Fastest implementation computes max flow in O(V^3) time 4/7/2019 CSE 373 AU 2005 -- Network Flow
Ford-Fulkerson Method Initialize flow f to 0 While there exists an augmenting path p Augment flow f along p Return f 4/7/2019 CSE 373 AU 2005 -- Network Flow
An Augmenting Path How much can be sent along the path? A 0/12 B 0/20 0/16 0/4 S T 0/10 0/7 0/9 0/13 0/4 C D 0/14 How much can be sent along the path? 4/7/2019 CSE 373 AU 2005 -- Network Flow
An Augmenting Path Find a path with DFS or BFS. bottleneck A 12/12 B 12/20 12/16 0/4 S T 0/10 0/7 0/9 0/13 0/4 C D 0/14 Find a path with DFS or BFS. 4/7/2019 CSE 373 AU 2005 -- Network Flow
Another Augmenting Path 12/12 B 12/20 12/16 0/4 S T 0/10 0/7 0/9 0/13 0/4 C D 0/14 How much can be sent along the path? 4/7/2019 CSE 373 AU 2005 -- Network Flow
Another Augmenting Path 12/12 B bottleneck 12+4=16/20 12+4=16/16 0/4 S T 4/10 4/7 0/9 0/13 0/4 C D 4/14 How much can be sent along the path? 4/7/2019 CSE 373 AU 2005 -- Network Flow
Residual Graphs How much more flow can be sent? 4/12 A B 4/16 0/20 0/4 0/10 0/7 4/9 0/13 4/4 C D 4/14 12-4=8 A B 4 16-4=12 20 4 4 S T 10 4 7 9-4=5 13 4 4 C D 4/7/2019 CSE 373 AU 2005 -- Network Flow 14-4=10 How much more flow can be sent?
Residual Graphs S A C B D T 4/16 0/13 0/10 0/4 4/9 4/14 4/12 0/20 0/7 4/4 8 A B 4 12 20 4 4 S T 10 4 7 5 13 4 S A C B D T 4/16 4/13 0/10 0/4 0/9 4/14 4/12 4/20 0/7 4/4 4 C D 10 8 A B 4 12 16 4 4 4 S T 10 7 9 4 9 4 Can cancel out flow (BC) 4/7/2019 CSE 373 AU 2005 -- Network Flow 4 C D 10
Residual Graphs S A C B D T 4/16 0/13 0/10 0/4 4/9 4/14 4/12 0/20 0/7 4/4 8 A B 4 12 12 4 4 4 S T 10 7 9 4 9 4 12/12 4 A B C D 12/16 12/20 10 0/4 0/10 S T 0/7 0/9 A B 4/13 12 4/4 C D 4 8 4/14 12 12 4 S T 10 7 9 4 9 4 4/7/2019 CSE 373 AU 2005 -- Network Flow 4 C D 10
Residual Graphs S A C B D T 4/16 0/13 0/10 0/4 4/9 4/14 4/12 0/20 0/7 4/4 A B 12 4 8 12 12 4 S T 10 7 9 4 9 4 12/12 4 A B C D 12/16 10 19/20 0/4 0/10 S T 7/7 0/9 A B 11/13 12 4/4 C D 4 1 11/14 19 12 4 S T 10 7 9 11 2 4 4/7/2019 CSE 373 AU 2005 -- Network Flow 11 C D 3
Residual Graphs 12/12 A B 12/16 19/20 0/4 0/10 S T 7/7 0/9 11/13 4/4 C 11/14 A B 12 4 1 19 12 4 S T 10 7 9 11 2 4 11 C D 3 No more augmenting paths: Max Flow! Reachable vertices from source form one set, other vertices the other set. Edges in the middle are the cut. 4/7/2019 CSE 373 AU 2005 -- Network Flow
Linear Programming: Max Flow Variables: SA, SB, AB, AT, BT (amount of flow through the edge) Constraints: capacity 0 <= SA, SB, AB, AT, BT SA <= 16 SB <= 13 AB <= 10 AT <= 4 BT <= 20 flow conservation AS = AB + AT AB + SB = BT Objective: max ( SA + SB + AB + AT + BT ) A 0/4 0/16 S T 0/10 0/13 B 0/20 4/7/2019 CSE 373 AU 2005 -- Network Flow
Linear Programming: Min Cut Variables: SA, SB, AB, AT, BT (not cut = 0, cut = 1) AinS, BinS (not in S = 0, in S = 1) Constraints: 0 <= SA, SB, AB, AT, BT 1 <= SA + AinS (A in S or SA is cut) 1 <= SB + BinS (B in S or SB is cut) 0 <= AB - AinS + BinS (A in S but not B means AB is cut) 0 <= AT - AinS (A in S means AT is cut) 0 <= BT - BinS (B in S means BT is cut) Objective: min (16 SA + 4 AT + 10 AB + 13 SB + 20 BT) A 0/4 0/16 S T 0/10 0/13 B 0/20 4/7/2019 CSE 373 AU 2005 -- Network Flow