CSC373 Week 5: Network Flow (contd) Nisarg Shah 373F19 - Nisarg Shah & Karan Singh 1
Recap • Some more DP ➢ Edit distance (aka sequence alignment) ➢ Traveling salesman problem (TSP) • Start of network flow ➢ Problem statement ➢ Ford-Fulkerson algorithm ➢ Running time ➢ Correctness using max-flow, min-cut 373F19 - Nisarg Shah & Karan Singh 2
This Lecture • Network flow in polynomial time ➢ Edmonds-Karp algorithm (shortest augmenting path) • Applications of network flow ➢ Bipartite matching & Hall’s theorem ➢ Edge-disjoint paths & Menger’s theorem ➢ Multiple sources/sinks ➢ Circulation networks ➢ Lower bounds on flows ➢ Survey design ➢ Image segmentation 373F19 - Nisarg Shah & Karan Singh 3
Ford-Fulkerson Recap • Define the residual graph 𝐻 𝑔 of flow 𝑔 ➢ 𝐻 𝑔 has the same vertices as 𝐻 ➢ For each edge e = (𝑣, 𝑤) in 𝐻 , 𝐻 𝑔 has at most two edges o Forward edge 𝑓 = (𝑣, 𝑤) with capacity 𝑑 𝑓 − 𝑔 𝑓 • We can send this much additional flow on 𝑓 o Reverse edge 𝑓 𝑠𝑓𝑤 = (𝑤, 𝑣) with capacity 𝑔(𝑓) • The maximum “reverse” flow we can send is the maximum amount by which we can reduce flow on 𝑓 , which is 𝑔(𝑓) o We only add each edge if its capacity > 0 373F19 - Nisarg Shah & Karan Singh 4
Ford-Fulkerson Recap • Example! Flow 𝑔 Residual graph 𝐻 𝑔 u u 20/20 0/10 𝟑𝟏 𝟐𝟏 20/30 𝟐𝟏 𝟑𝟏 s t s t 0/10 20/20 𝟐𝟏 𝟑𝟏 v v 373F19 - Nisarg Shah & Karan Singh 5
Ford-Fulkerson Recap MaxFlow( 𝐻 ): // initialize: Set 𝑔 𝑓 = 0 for all 𝑓 in 𝐻 // while there is an 𝑡 - 𝑢 path in 𝐻 𝑔 : While 𝑄 = FindPath (s, t, Residual( 𝐻, 𝑔 ))!=None: 𝑔 = Augment (𝑔, 𝑄) UpdateResidual( 𝐻 , 𝑔 ) EndWhile Return 𝑔 373F19 - Nisarg Shah & Karan Singh 6
Ford-Fulkerson Recap • Running time: ➢ #Augmentations: o At every step, flow and capacities remain integers o For path 𝑄 in 𝐻 𝑔 , bottleneck 𝑄, 𝑔 > 0 implies bottleneck 𝑄, 𝑔 ≥ 1 o Each augmentation increases flow by at least 1 o At most 𝐷 = σ 𝑓 leaving 𝑡 𝑑(𝑓) augmentations ➢ Time for an augmentation: o 𝐻 𝑔 has 𝑜 vertices and at most 2𝑛 edges o Finding an 𝑡 - 𝑢 path in 𝐻 𝑔 takes 𝑃(𝑛 + 𝑜) time ➢ Total time: 𝑃( 𝑛 + 𝑜 ⋅ 𝐷) 373F19 - Nisarg Shah & Karan Singh 7
Edmonds-Karp Algorithm • At every step, find the shortest path from 𝑡 to 𝑢 in 𝐻 𝑔 , and augment. Minimum number of edges MaxFlow( 𝐻 ): // initialize: Set 𝑔 𝑓 = 0 for all 𝑓 in 𝐻 // Find shortest 𝑡 - 𝑢 path in 𝐻 𝑔 & augment: While 𝑄 = BFS(s, t, Residual( 𝐻, 𝑔 ))!=None: 𝑔 = Augment (𝑔, 𝑄) UpdateResidual( 𝐻 , 𝑔 ) EndWhile Return 𝑔 373F19 - Nisarg Shah & Karan Singh 8
Edmonds-Karp Proof Overview • Overview ➢ Lemma 1: The length of the shortest 𝑡 → 𝑢 path in 𝐻 𝑔 never decreases. o (Proof ahead) ➢ Lemma 2: After at most 𝑛 augmentations, the length of the shortest 𝑡 → 𝑢 path in 𝐻 𝑔 must strictly increase. o (Proof ahead) ➢ Theorem: The algorithm takes 𝑃(𝑛 2 𝑜) time. o Proof: • Length of shortest 𝑡 → 𝑢 path in 𝐻 𝑔 can go from 0 to 𝑜 − 1 • Using Lemma 2, there can be at most 𝑛 ⋅ 𝑜 augmentations • Each takes 𝑃(𝑛) time using BFS. ∎ 373F19 - Nisarg Shah & Karan Singh 9
Level Graph • Level graph 𝑀 𝐻 of a directed graph 𝐻 = (𝑊, 𝐹) : ➢ Level: ℓ(𝑤) = length of shortest 𝑡 → 𝑤 path ➢ Level graph 𝑀 𝐻 = (𝑊, 𝐹 𝑀 ) is a subgraph of 𝐻 where we only retain edges 𝑣, 𝑤 ∈ 𝐹 where ℓ 𝑤 = ℓ 𝑣 + 1 o Intuition: Keep only the edges useful for shortest paths 373F19 - Nisarg Shah & Karan Singh 10
Level Graph • Level graph 𝑀 𝐻 of a directed graph 𝐻 = (𝑊, 𝐹) : ➢ Level: ℓ(𝑤) = length of shortest 𝑡 → 𝑤 path ➢ Level graph 𝑀 𝐻 = (𝑊, 𝐹 𝑀 ) is a subgraph of 𝐻 where we only retain edges 𝑣, 𝑤 ∈ 𝐹 where ℓ 𝑤 = ℓ 𝑣 + 1 o Intuition: Keep only the edges useful for shortest paths • Property: 𝑄 is a shortest 𝑡 → 𝑤 path in 𝐻 if and only if 𝑄 is an 𝑡 → 𝑤 path in 𝑀 𝐻 . 373F19 - Nisarg Shah & Karan Singh 11
Edmonds-Karp Proof • Lemma 1: ➢ Length of the shortest 𝑡 → 𝑢 path in 𝐻 𝑔 never decreases. • Proof: ➢ Let 𝑔 and 𝑔′ be flows before and after an augmentation step, and 𝐻 𝑔 and 𝐻 𝑔 ′ be their residual graphs. Residual graph 𝐻 𝑔 Residual graph 𝐻 𝑔 ′ 373F19 - Nisarg Shah & Karan Singh 12
Edmonds-Karp Proof • Lemma 1: ➢ Length of the shortest 𝑡 → 𝑢 path in 𝐻 𝑔 never decreases. • Proof: ➢ Let 𝑔 and 𝑔′ be flows before and after an augmentation step, and 𝐻 𝑔 and 𝐻 𝑔 ′ be their residual graphs. ➢ Augmentation happens along a path in 𝑀 𝐻 𝑔 ➢ For each edge on the path, we either remove it, add an opposite direction edge, or both. ➢ Opposite direction edges can’t help reduce the length of the shortest 𝑡 → 𝑢 path (exercise!). ➢ QED! 373F19 - Nisarg Shah & Karan Singh 13
Edmonds-Karp Proof • Lemma 2: ➢ After at most 𝑛 augmentations, the length of the shortest 𝑡 → 𝑢 path in 𝐻 𝑔 must strictly increase. • Proof: ➢ In each augmentation step, we remove at least one edge from 𝑀 𝐻 𝑔 o Because we make the flow on at least one edge on the shortest path equal to its capacity ➢ No new edges are added in 𝑀 𝐻 𝑔 unless the length of the shortest 𝑡 → 𝑢 path strictly increases ➢ This cannot happen more than 𝑛 times! ∎ 373F19 - Nisarg Shah & Karan Singh 14
Edmonds-Karp Proof Overview • Overview ➢ Lemma 1: The length of the shortest 𝑡 → 𝑢 path in 𝐻 𝑔 never decreases. ➢ Lemma 2: After at most 𝑛 augmentations, the length of the shortest 𝑡 → 𝑢 path in 𝐻 𝑔 must strictly increase. ➢ Theorem: The algorithm takes 𝑃(𝑛 2 𝑜) time. 373F19 - Nisarg Shah & Karan Singh 15
Edmonds-Karp Proof Overview • Note: ➢ Some graphs require Ω(𝑛𝑜) augmentation steps ➢ But we may be able to reduce the time to run each augmentation step • Two algorithms use this idea to reduce run time ➢ Dinitz’s algorithm [1970] ⇒ 𝑃(𝑛𝑜 2 ) ➢ Sleator – Tarjan algorithm [1983] ⇒ 𝑃(𝑛 𝑜 log 𝑜) o Using the dynamic trees data structure 373F19 - Nisarg Shah & Karan Singh 16
Network Flow Applications 373F19 - Nisarg Shah & Karan Singh 17
Rail network connecting Soviet Union with Eastern European countries ( Tolstoǐ 1930s) 373F19 - Nisarg Shah & Karan Singh 18
Rail network connecting Soviet Union with Eastern European countries ( Tolstoǐ 1930s) Min-cut 373F19 - Nisarg Shah & Karan Singh 19
Integrality Theorem • Before we look at applications, we need the following special property of the max-flow computed by Ford-Fulkerson and its variants • Observation: ➢ If edge capacities are integers, then the max-flow computed by Ford-Fulkerson and its variants are also integral (i.e. the flow on each edge is an integer). ➢ Easy to check that each augmentation step preserves integral flow 373F19 - Nisarg Shah & Karan Singh 20
Bipartite Matching • Problem ➢ Given a bipartite graph 𝐻 = (𝑉 ∪ 𝑊, 𝐹) , find a maximum cardinality matching • We do not know any efficient greedy or dynamic programming algorithm for this problem. • But it can be reduced to max-flow. 373F19 - Nisarg Shah & Karan Singh 21
Bipartite Matching 𝑉 𝑊 𝑉 𝑊 • Create a directed flow graph where we… ➢ Add a source node 𝑡 and target node 𝑢 ➢ Add edges, all of capacity 1 : o 𝑡 → 𝑣 for each 𝑣 ∈ 𝑉 , 𝑤 → 𝑢 for each 𝑤 ∈ 𝑊 o 𝑣 → 𝑤 for each 𝑣, 𝑤 ∈ 𝐹 373F19 - Nisarg Shah & Karan Singh 22
Bipartite Matching • Observation ➢ There is a 1-1 correspondence between matchings of size 𝑙 in the original graph and flows with value 𝑙 in the corresponding flow network. • Proof: (matching ⇒ integral flow) ➢ Take a matching 𝑁 = 𝑣 1 , 𝑤 1 , … , 𝑣 𝑙 , 𝑤 𝑙 of size 𝑙 ➢ Construct the corresponding unique flow 𝑔 𝑁 where… o Edges 𝑡 → 𝑣 𝑗 , 𝑣 𝑗 → 𝑤 𝑗 , and 𝑤 𝑗 → 𝑢 have flow 1, for all 𝑗 = 1, … , 𝑙 o The rest of the edges have flow 0 ➢ This flow has value 𝑙 373F19 - Nisarg Shah & Karan Singh 23
Bipartite Matching • Observation ➢ There is a 1-1 correspondence between matchings of size 𝑙 in the original graph and flows with value 𝑙 in the corresponding flow network. • Proof: (integral flow ⇒ matching) ➢ Take any flow 𝑔 with value 𝑙 ➢ The corresponding unique matching 𝑁 𝑔 = set of edges from 𝑉 to 𝑊 with a flow of 1 o Since flow of 𝑙 comes out of 𝑡 , unit flow must go to 𝑙 distinct vertices in 𝑉 o From each such vertex in 𝑉 , unit flow goes to a distinct vertex in 𝑊 o Uses integrality theorem 373F19 - Nisarg Shah & Karan Singh 24
Recommend
More recommend