Flow Networks zichun@comp.nus.edu.sg Formalization Basic Results Min-cut Ford-Fulkerson Edmunds-Karp Bipartite Matching Flow Network • Directed Graph G = (V, E) • Each edge π’, π£ ∈ πΈ has a capacity – π π’, π£ ≥ 0 • π’, π£ ∉ πΈ ⇒ π π’, π£ = 0 Properties of Flow ππππ€ ππ πΊ β π βΆ π × π → π Capacity Constraint ∀π’, π£ ∈ π (π π’, π£ ≤ π π’, π£ ) Skew Symmetry ∀π’, π£ ∈ π (π π’, π£ = −π π£, π’ ) Flow Conservation ∀π’ ∈ π − {π , π‘} ( π’∈π π π’, π£ = 0) Maximum Flow • πππ₯πΉπππ€ πΊ = π, πΈ , π ∈ π, π‘ ∈ π – ∀π£ ∈ π ∃ πππ‘β π π → π π£ → π π‘ – Returns Maximum Flow of G Value of Flow π = π π , π£ π£∈π Motivating Problem v1 16 10 s 12 4 v3 9 14 t 7 13 v2 20 v4 4 Motivating Problem 10 8/13 1/4 v2 4/9 11/14 v3 7/7 v1 11/16 s 12/12 v4 t 4/4 10 8/13 π = 1/4 v2 11/14 π π , π£ = π£∈π = 19 4/9 v3 7/7 v1 11/16 s 12/12 v4 π π£, π‘ π£∈π t 4/4 Multiple Sources / Sinks v1 16 s1 s2 13 4 12 10 4 v2 v3 9 14 7 v4 20 t1 4 4 t2 Multiple Sources / Sinks v1 16 ∞ s1 S ∞ s2 13 4 12 10 4 v2 v3 9 14 7 v4 20 t1 ∞ t 4 4 t2 ∞ Implicit Summation Notation π πΏ, π = π(π, π) π∈πΏ π∈π Key Equalities Let G = (V, E) be a flow network, and let f be a flow in G. Then 1. ∀π ⊂ π π π, π = 0 2. ∀π, π ⊂ π π π, π = −π(π, π) 3. ∀π, π, π ⊂ π π∩π =∅⇒ π π ∪ π, π = π π, π + π π, π ^ π π, π ∪ π = π π, π + π(π, π) Capacity Constraint ∀π’, π£ ∈ π π π’, π£ ≤ π π’, π£ Skew Symmetry ∀π’, π£ ∈ π π π’, π£ = −π π£, π’ ∀π, π ⊂ π π π, π = −π(π, π) Flow Conservation ∀π’ ∈ π − π , π‘ π’∈π π π’, π£ = 0 ∀π ⊂ π π π, π = 0 Homomorphism ∀π, π, π ⊂ π π∩π =∅⇒ π π ∪ π, π = π π, π + π π, π ^ π π, π ∪ π = π π, π + π(π, π) Flow Value Prove π = π π, π‘ π = π π , π = π π, π − π π − π , π = −π π − π , π = π π, π − π = π π, π‘ + π π, π − π − π‘ = π(π, π‘) Definition Homomorphism Flow Conservation Skew Symmetry Homomorphism Flow Conservation Ford-Fulkerson flow=0 while(∃ (augmenting path p)) { augment flow f along p } return flow Residual network Induced network from G=(V, E) and flow f ππ π’, π£ = π π’, π£ − π(π’, π£) 10 8/13 v2 5 3 4/9 11/14 0 v1 11 s 1/4 4 v2 4/4 v4 5 15 5 8 5 t v3 12 11 v3 7/7 v1 11/16 s 12/12 11 3 t 0 7 0 v4 4 Augmenting Path A path of non-zero weight from s to t in Gf 10 8/13 v2 5 3 4/9 11/14 0 v1 11 s 1/4 4 v2 4/4 v4 5 15 5 8 5 t v3 12 11 v3 7/7 v1 11/16 s 12/12 11 3 t 0 7 0 v4 4 10 8/13 v2 5 3 4/9 11/14 0 v1 11 s 1/4 4 v2 4/4 v4 5 15 5 8 5 t v3 12 11 v3 7/7 v1 11/16 s 12/12 11 3 t 0 7 0 v4 4 10 8/13 v2 5 3 5 0 12 11 8 v2 4/9 11/14 v1 11 s 1/4 v3 7/7 v1 11/16 s 12/12 t 4/4 v4 v3 5 15 5 4 11 3 t 0 7 0 v4 4 10 13/13 v2 5 3 0/9 11/14 0 v1 11 s 1/4 0 v2 4/4 v4 0 20 9 13 0 t v3 12 11 v3 7/7 v1 11/16 s 12/12 11 3 t 0 7 0 v4 4 S-T Cut • A cut C=(S, T) of a flow network G=(V, E) is a partition of V into S and T = V – S – π ∈ π, π‘ ∈ π • Net flow across πΆ: π π, π • Capacity of cut: c π, π 10 8/13 1/4 v2 4/9 11/14 v3 7/7 v1 11/16 s 12/12 v4 t 4/4 f(S, T) = 12 – 4 + 11 = 19 c(S, T) = 12 + 14 = 26 Let f be a flow in a flow network G with source s and sink t, and let (S, T) be a cut of G. Then the net flow across (S, T) is f(S, T) = |f| π π, π = π π, π − π π, π = π π, π = π π , π + π π − π , π = π π , π = |π| Homomorphism Flow Conservation Homomorphism Flow Conservation Definition The value of any flow f in a flow network G is bounded by the capacity of any cut of G π = π π, π = π(π, π) π∈πΊ π∈π» ≤ π π, π π∈πΏ π∈π = π(π, π) Min-Cut Max-Flow 1. f is a maximum flow in G 2. The residual network Gf contains no augmenting path 3. |f|= c(S, T) for some cut (S, T) of G 1 ⇒ (2) 1. Premise: f is a max-flow in G 2. Assume Gf has augmenting path p 3. We can augment Gf with p to get a flow f’ > f – Contradicts [1] • Hence Gf has no augmenting paths 2 ⇒ (3) 1. Premise: Gf has no augmenting paths 2. Let 1. π = π£ ∈ π: ∃ πππ‘β ππππ π π‘π π£ ππ πΊπ 2. T = V-S 3. (S, T) is a cut 1. π ∈ π, π‘ ∈ π β΅ ~∃πππ‘β ππππ π π‘π π‘ ππ¦ 1 4. ∀π’ ∈ π, π£ ∈ π(π π’, π£ = π π’, π£ ) 1. Otherwise π → π’ → π£ ⇒ π£ ∈ π 5. π = π π, π = π(π, π) 3 ⇒ (1) The value of any flow f in a flow network G is bounded by the capacity of any cut of G 1. π ≤ π π, π ππ¦ πΏππππ 2. πππππ π = π π, π , |f| is maximum Ford-Fulkerson flow=0 while(∃ (augmenting path p)) { augment flow f along p } return flow Termination: Gf has no augmenting path iff flow is maximum Run-time flow=0 while(∃ (augmenting path p)) { augment flow f along p } return flow O(E|f*|) where |f*| is the maximum flow v1 1,000,000 1,000,000 1 s 1,000,000 v2 t 1,000,000 v1 1,000,000 1,000,000 1 s 1,000,000 v2 t 1,000,000 v1 999,999 s 1,000,000 1,000,000 1 1 1 v2 t 1,000,000 v1 999,999 s 1,000,000 1,000,000 1 1 1 v2 t 1,000,000 v1 999,999 s 999,999 1 1 1 1 1 999,999 v2 t 1,000,000 v1 999,999 s 999,999 1 1 1 1 1 999,999 v2 t 1,000,000 Edmunds Karp flow=0 while(∃ (augmenting path p)) { find augmenting path by BFS augment flow f along p } return flow Run-time: O(VE2) v1 11 5 s 3 12 11 8 5 0 v2 v3 5 15 5 4 11 3 t 0 7 0 v4 4 Critical Edge Lemma: Edges can be critical at most v1 11 5 s 3 12 11 8 5 0 v2 v3 5 15 5 4 11 3 t 0 7 0 v4 4 Critical Edge π 2 times πΏπ π’, π£ β π βπππ‘ππ π‘ − πππ‘β πππππ‘β ππππ π’ → π£ v1 11 5 s 3 12 11 8 5 0 v2 v3 5 15 5 4 11 3 t 0 7 0 v4 4 πΏπ π’, π£ β π βπππ‘ππ π‘ − πππ‘β πππππ‘β ππππ π’ → π£ 1. Assume (u, v) is a critical edge 2. Augmenting-paths are shortest path [by EK] 3. πΏπ π , π£ = πΏπ π , π’ + 1 [from 1] 4. After flow-augmentation, cf(u,v) = 0 • (u, v) cannot be critical path until another augmenting path containing (v, u). • Let the flow at this point be f’ 5. πΏπ′ π , π’ = πΏπ′ π , π£ + 1 ≥ πΏπ π , π£ + 1 = πΏπ π , π’ + 2 6. i.e, each time (u, v) is augmenting-path, path length increases by 2 7. (u, v) can be critical edge at most π 2 times Lemma: Edges can be critical at most π 2 times Since there are O(E) edges, the number of augmenting path is bounded by O(VE) [by Lemma]. Run-time: O(VE2) Bipartite Matching Bipartite Matching Bipartite Matching ≤ MaxFlow s t Bipartite Matching ≤ MaxFlow s t