Algorithms and Theory of Computation. Lecture 11: Network Flow

Similar documents
Agenda. Soviet Rail Network, We ve done Greedy Method Divide and Conquer Dynamic Programming

Running Time. Assumption. All capacities are integers between 1 and C.

Algorithm Design and Analysis

Algorithm Design and Analysis

Algorithm Design and Analysis

Soviet Rail Network, 1955

Algorithms: Lecture 12. Chalmers University of Technology

directed weighted graphs as flow networks the Ford-Fulkerson algorithm termination and running time

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

10 Max-Flow Min-Cut Flows and Capacitated Graphs 10 MAX-FLOW MIN-CUT

Algorithms. Algorithms 6.4 MAXIMUM FLOW

Algorithms: COMP3121/3821/9101/9801

Chapter 7. Network Flow. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

7.5 Bipartite Matching

CMPSCI 611: Advanced Algorithms

The max flow problem. Ford-Fulkerson method. A cut. Lemma Corollary Max Flow Min Cut Theorem. Max Flow Min Cut Theorem

Lecture 21 November 11, 2014

Flow Network. The following figure shows an example of a flow network:

Chapter 7. Network Flow. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Algorithms. Algorithms 6.4 MIN CUT / MAX FLOW

CSC 373: Algorithm Design and Analysis Lecture 12

Maximum flow problem

Algorithms. Algorithms 6.4 MAXIMUM FLOW

22 Max-Flow Algorithms

Algorithm Design and Analysis

Maximum Flow. Jie Wang. University of Massachusetts Lowell Department of Computer Science. J. Wang (UMass Lowell) Maximum Flow 1 / 27

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

6.046 Recitation 11 Handout

Flows and Cuts. 1 Concepts. CS 787: Advanced Algorithms. Instructor: Dieter van Melkebeek

Two Applications of Maximum Flow

Network Flows made simple

1 Review for Lecture 2 MaxFlow

Part V. Matchings. Matching. 19 Augmenting Paths for Matchings. 18 Bipartite Matching via Flows

Internet Routing Example

CSC2420: Algorithm Design, Analysis and Theory Spring (or Winter for pessimists) 2017

Lecture 2: Network Flows 1

Algorithms 6.4 MAXIMUM FLOW. overview Ford-Fulkerson algorithm analysis Java implementation applications

Problem set 1. (c) Is the Ford-Fulkerson algorithm guaranteed to produce an acyclic maximum flow?

Chapter 7. Network Flow. CS 350: Winter 2018

Preliminaries. Graphs. E : set of edges (arcs) (Undirected) Graph : (i, j) = (j, i) (edges) V = {1, 2, 3, 4, 5}, E = {(1, 3), (3, 2), (2, 4)}

Max Flow: Algorithms and Applications

Chapter 10. Maximum flow

We say that a flow is feasible for G (or just feasible if the graph and capacity function in question are obvious) if

Mathematics for Decision Making: An Introduction. Lecture 13

Today. Flow review. Augmenting paths. Ford-Fulkerson Algorithm. Intro to cuts (reason: prove correctness)

Types of Networks. Internet Telephone Cell Highways Rail Electrical Power Water Sewer Gas

CSCE423/823. Introduction. Flow Networks. Ford-Fulkerson Method. Edmonds-Karp Algorithm. Maximum Bipartite Matching 2/35 CSCE423/823.

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

CS 138b Computer Algorithm Homework #14. Ling Li, February 23, Construct the level graph

CSC2420: Algorithm Design, Analysis and Theory Fall 2017

Lecture 1. 1 Overview. 2 Maximum Flow. COMPSCI 532: Design and Analysis of Algorithms August 26, 2015

Maximum Integer Flows in Directed Planar Graphs with Multiple Sources and Sinks and Vertex Capacities

Friday, September 21, Flows

Maximum flow problem (part I)

Maximum Flow. Reading: CLRS Chapter 26. CSE 6331 Algorithms Steve Lai

Energy minimization via graph-cuts

Lecture 8 Network Optimization Algorithms

Dantzig s pivoting rule for shortest paths, deterministic MDPs, and minimum cost to time ratio cycles

Graph Algorithms -2: Flow Networks. N. H. N. D. de Silva Dept. of Computer Science & Eng University of Moratuwa

Algorithms and Theory of Computation. Lecture 22: NP-Completeness (2)

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

Exposition of the Dinitz algorithm

CSE 326: Data Structures Network Flow. James Fogarty Autumn 2007

GRAPH ALGORITHMS Week 7 (13 Nov - 18 Nov 2017)

u = 50 u = 30 Generalized Maximum Flow Problem s u = 00 2 u = 00 u = 50 4 = 3=4 u = 00 t capacity u = 20 3 u = 20 = =2 5 u = 00 gain/loss factor Max o

. CS711008Z Algorithm Design and Analysis. Lecture 10. Algorithm design technique: Network flow and its applications 1. Dongbo Bu

Chapter 7. Network Flow. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

ORIE 633 Network Flows October 4, Lecture 10

CS675: Convex and Combinatorial Optimization Fall 2014 Combinatorial Problems as Linear Programs. Instructor: Shaddin Dughmi

III. Linear Programming

Algorithms and Theory of Computation. Lecture 13: Linear Programming (2)

Network Flows. CTU FEE Department of control engineering. March 28, 2017

Parallel Graph Algorithms (con4nued)

Multicommodity Flows and Column Generation

CS 1501 Recitation. Xiang Xiao

The Budget-Constrained Maximum Flow Problem

Breadth-First Search of Graphs

Parallel Graph Algorithms (con4nued)

An example of LP problem: Political Elections

The Simplest and Smallest Network on Which the Ford-Fulkerson Maximum Flow Procedure May Fail to Terminate

Week 4. (1) 0 f ij u ij.

Combinatorial Optimization

Algorithm Design and Analysis

The Maximum Flow Problem

Maximum Flows & Minimum Cuts

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

The min cost flow problem Course notes for Optimization Spring 2007

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

Algorithms and Theory of Computation. Lecture 9: Dynamic Programming

1 Matchings in Non-Bipartite Graphs

Maximum Skew-Symmetric Flows. September Abstract

CSE 202 Homework 4 Matthias Springer, A

The min cost flow problem Course notes for Search and Optimization Spring 2004

Discrete Optimization 2010 Lecture 3 Maximum Flows

Computing Maximum Flow with Augmenting Electrical Flows

FRACTIONAL PACKING OF T-JOINS. 1. Introduction

Maximum flow problem CE 377K. February 26, 2015

Design and Analysis of Algorithms

A FAST MAX FLOW ALGORITHM

CS 170 DISCUSSION 10 MAXIMUM FLOW. Raymond Chan raychan3.github.io/cs170/fa17.html UC Berkeley Fall 17

Transcription:

Algorithms and Theory of Computation Lecture 11: Network Flow Xiaohui Bei MAS 714 September 18, 2018 Nanyang Technological University MAS 714 September 18, 2018 1 / 26

Flow Network A flow network is a directed graph G = (V, E) with a source s V and a sink t V, and a nonnegative integer capacity c(e) for each edge e E. no parallel edges, no edge enters s, no edge leaves t abstraction for material flowing through the edges a 9 d 10 4 15 15 10 s 5 b 8 e 10 t 15 4 6 15 10 c 16 f Nanyang Technological University MAS 714 September 18, 2018 2 / 26

Flow in Flow Networks A s-t flow (flow) f : E R is a function that satisfies: e E : 0 f(e) c(e) [capacity] v V {s, t} : e into v f(e) = e out of v f(e) [flow conservation] The value of a flow f is: val(f) = e out of s f(e). Max-Flow Problem Find a flow of maximum value. a 8/9 d 10/10 0/4 2/15 0/15 8/10 s 5/5 b 8/8 e 10/10 t 13/15 0/4 3/6 0/15 10/10 c 13/16 Nanyang Technological University MAS 714 September 18, 2018 3 / 26 f val(f) = 28

Cut in flow networks A s-t cut (cut) is a partition (A, B) of the vertices with s A and t B. The capacity of a cut is the sum of the capacities of edges from A to B. Min-Cut Problem Find a cut of minimum capacity. a 9 d 10 4 15 15 10 s 5 b 8 e 10 t 15 4 6 15 10 c 16 f Nanyang Technological University MAS 714 September 18, 2018 4 / 26

Application The Max Flow problem models the situation where commodities need to be transported through a network with limited capacities bipartite matching disjoint paths airline scheduling image segmentation project selection baseball elimination etc. Nanyang Technological University MAS 714 September 18, 2018 5 / 26

Application: Matching Given an undirect graph G = (V, E), a subset of edges M E is a matching if each vertex appears in at most one edge in M. Bipartite Matching Given a bipartite graph G = (L R, E), find a max cardinality matching. 1 2 3 4 5 6 7 8 Nanyang Technological University MAS 714 September 18, 2018 6 / 26

Bipartite Matching: Max-Flow Formulation Create a directed graph G = {L R {s, t}, E }. Direct all edges from L to R, and assign infinite capacity. Add sources s, and unit capacity edges from s to each vertex in L. Add sink t, and unit capacity edges from each vertex in R to t. Theorem The max cardinality of a matching in G = the value of max flow in G. 1 5 s 1 1 1 1 2 3 Nanyang Technological University MAS 714 September 18, 2018 7 / 26 6 7 1 1 1 1 t

Towards a max-flow algorithm First try: greedy algorithm start with f(e) = 0 for all edges e E find an s t path P where each edge has f(e) < c(e) augment flow along path P repeat until stuck a 0/4 3/4 c 10/10 8/10 2/2 0/2 0/8 8/8 7/8 0/6 6/6 0/10 6/10 9/10 s b 0/10 6/10 9/10 0/9 2/9 8/9 9/9 10/10 8/10 val(f) = 0 val(f) = 0 + 8 = 8 val(f) = 8 + 2 = 10 val(f) = 10 + 6 = 16 val(f) = 16 optimal val(f) = 19 d t Nanyang Technological University MAS 714 September 18, 2018 8 / 26

Residual Graph Residual edge undo flow sent Original edge: e = (u, v) E flow f(e) e = (u, v) and e R = (v, u) residual capacity: capacity c(e) { c(e) f(e) if e E c f (e) = f(e) if e R E u 6/17 v 6 u 11 v Residual Graph: G f = (V, E f ) residual edges with positive residual capacity E f = {e : f(e) < c(e)} {e R : f(e) > 0} key property: f + f is a flow in G iff f is a flow in G f Nanyang Technological University MAS 714 September 18, 2018 9 / 26

Augmenting Path An augmenting path is a simple s t path P in the residual graph G f. The bottleneck capacity of an augmenting P is the minimum residual capacity of any edge in P. Key Property Let f be a flow and let P be an augmenting path in G f. Then f is a flow and val(f ) = val(f) + bottleneck(g f, P) Algorithm: Augment(f, c, P): b = bottleneck capacity of path P; foreach edge e P do if e E then f(e) = f(e) + b; else f(e R ) = f(e R ) b; return f Nanyang Technological University MAS 714 September 18, 2018 10 / 26

Ford-Fulkerson Algorithm Ford-Fulkerson augmenting path algorithm start with f(e) = 0 for all edges e E find an augmenting path P in the residual graph G f augment flow along path P repeat until stuck Algorithm: Ford-Fulkerson(G, s, t, c): foreach edge e E do f(e) = 0; G f = residual graph; while there exists an augmenting path P in G f do f = Augment(f, c, P); Update G f ; return f Nanyang Technological University MAS 714 September 18, 2018 11 / 26

Demo a 4 c 10 2 8 6 10 s 10 b 9 d 10 t Nanyang Technological University MAS 714 September 18, 2018 12 / 26

net flow across cut = 5 + 10 + 10 = 25 net flow across cut = 10 + 5 + 10 = 25 net flow across cut Nanyang Technological University MAS 714 September 18, 2018 13 / 26 Relationship between Flows and Cuts Flow Value Lemma Let f be any flow and let (A, B) be any cut. Then the net flow across (A, B) equals the value of f, that is, f(e) f(e) = val(f). e out of A e into A a 5/9 d 10/10 0/4 5/15 0/15 5/10 s 5/5 b 5/8 e 10/10 t 10/15 0/4 0/6 0/15 10/10 c 10/16 f

Relationship between Flows and Cuts Flow Value Lemma Let f be any flow and let (A, B) be any cut. Then the net flow across (A, B) equals the value of f, that is, f(e) f(e) = val(f). e out of A e into A Proof. val(f) = f(e) e out of s = v A = ( e out of v f(e) e out of A e into A f(e) ) f(e) e into v f(e) by flow conservation Nanyang Technological University MAS 714 September 18, 2018 14 / 26

Weak Duality Weak Duality Let f be any flow and (A, B) be any cut. Then val(f) cap(a, B). Proof. val(f) = f(e) f(e) e out of A e out of A e out of A = cap(a, B) f(e) c(e) e into A Nanyang Technological University MAS 714 September 18, 2018 15 / 26

Max-Flow Min-Cut Theorem Augmenting Path Theorem A flow f is a max-flow iff there are no augmenting paths. Max-Flow Min-Cut Theorem Value of max-flow = capacity of min-cut. Proof: show the following three conditions are equivalent for any flow f 1 There exists a cut (A, B) such that cap(a, B) = val(f). 2 f is a max-flow. 3 There is no augmenting path with respect to f. Nanyang Technological University MAS 714 September 18, 2018 16 / 26

Max-Flow Min-Cut Theorem Proof. [(1) = (2)] : Trivial by weak duality. [(2) = (3)] : Assume by contradiction that there is an augmenting path with respect to f. Can improve flow f by sending flow along this path. Thus f is not a max-flow. Nanyang Technological University MAS 714 September 18, 2018 17 / 26

Max-Flow Min-Cut Theorem Proof. [(3) = (1)] : Let f be a flow with no augmenting paths. Let A be the set of vertices reachable from s in the residual graph G f. By the definition of cut A, s A. By the definition of flow f, t / A. val(f) = f(e) f(e) = e out of A e out of A = cap(a, B) c(e) e into A Nanyang Technological University MAS 714 September 18, 2018 18 / 26

Back to Ford-Fulkerson Algorithm: Ford-Fulkerson(G, s, t, c): foreach edge e E do f(e) = 0; G f = residual graph; while there exists an augmenting path P in G f do f = Augment(f, c, P); Update G f ; return f Theorem The Ford-Fulkerson algorithm computes a maximum flow of the network. Directly from the augmenting path theorem. Nanyang Technological University MAS 714 September 18, 2018 19 / 26

Running Time Analysis Assumption. Capacities are integers between 1 and C. Integrality invariant. Throughout the algorithm, the flow values f(e) and the residual capacities c f (e) are integers. Theorem The algorithm terminates in at most val(f ) nc iterations. Proof. Each augmentation increases the value by at least 1. Corollary The running time of Ford-Fulkerson is O(mnC). Nanyang Technological University MAS 714 September 18, 2018 20 / 26

Bad Case for Ford-Fulkerson Is generic Ford-Fulkerson algorithm polynomial time in input size? No. Input size is polynomial in m, n, log C. s C a 1 C t Augmenting Path: s a b t s b a t s a b t C b C s b a t... Requires 2C iterations. Nanyang Technological University MAS 714 September 18, 2018 21 / 26

Choosing Good Augmenting Paths Goal. Choose augmenting paths so that: Can find augmenting paths efficiently. Algorithm takes few iterations. Choosing augmenting paths with max bottleneck capacity sufficiently large bottleneck capacity fewest number of edges Nanyang Technological University MAS 714 September 18, 2018 22 / 26

Capacity-scaling algorithm Intuition. Choose augmenting path with (almost) highest bottleneck capacity: it increases flow by max possible amount in given iteration. Detail of the algorithm is omitted. Theorem The scaling algorithm finds a max flow in O(m log C) augmentations. It can be implemented to run in O(m 2 log C) time. Nanyang Technological University MAS 714 September 18, 2018 23 / 26

Shortest Augmenting Paths Lemma 1. Throughout the algorithm, length of the shortest path never decreases. Lemma 2. After at most m shortest path augmentations, the length of the shortest augmenting path strictly increases. O(m + n) time to find shortest augmenting path via BFS. O(m) augmentations for paths of exactly k edges. O(mn) augmentations. Theorem The shortest augmenting path algorithm runs in O(m 2 n) time. Nanyang Technological University MAS 714 September 18, 2018 24 / 26

Choosing Good Augmenting Paths: Summary Assumption. Integer capacities between 1 and C. method augmentations running time augmenting path nc O(mnC) fattest augmenting path m log (mc) O(m 2 log n log (mc)) capacity scaling m log C O(m 2 log C) improved capacity scaling m log C O(mn log C) shortest augmenting path mn O(m 2 n) improved shortest augmenting mn O(mn 2 ) path dynamic trees mn O(mn log n) Nanyang Technological University MAS 714 September 18, 2018 25 / 26

Max-Flow Algorithms: Theory year method worst case discovered by 1951 simplex O(m 3 C) Dantzig 1955 augmenting path O(m 2 C) Ford-Fulkerson 1970 shortest augmenting path O(m 3 ) Dinic, Edmonds-Karp 1970 fattest augmenting path O(m 2 log m log (mc)) Dinic, Edmonds-Karp 1977 blocking flow O(m 5/2 ) Cherkasky 1978 blocking flow O(m 7/3 ) Galil 1983 dynamic trees O(m 2 log m) Sleator-Tarjan 1985 capacity scaling O(m 2 log C) Gabow 1997 length function O(m 3/2 log m log C) Goldberg-Rao 2012 compact network O(m 2 / log m) Orlin?? O(m)? Nanyang Technological University MAS 714 September 18, 2018 26 / 26