Lecture 2: Network Flows 1

Similar documents
1 Review for Lecture 2 MaxFlow

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

CMPSCI 611: Advanced Algorithms

Algorithms: COMP3121/3821/9101/9801

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

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

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

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

6.046 Recitation 11 Handout

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)}

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

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

CS 1501 Recitation. Xiang Xiao

Algorithms and Theory of Computation. Lecture 11: Network Flow

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

The min cost flow problem Course notes for Optimization Spring 2007

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

Internet Routing Example

Exposition of the Dinitz algorithm

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

Discrete Optimization 2010 Lecture 3 Maximum Flows

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

Two Applications of Maximum Flow

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

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

Mathematics for Decision Making: An Introduction. Lecture 13

Algorithms: Lecture 12. Chalmers University of Technology

Algorithm Design and Analysis

Algorithm Design and Analysis

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

Maximum flow problem CE 377K. February 26, 2015

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

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

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

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

Flows. Chapter Circulations

Max Flow: Algorithms and Applications

The maximum flow problem

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

Review Questions, Final Exam

CSC 373: Algorithm Design and Analysis Lecture 12

Maximum flow problem

Energy minimization via graph-cuts

Maximum flow problem (part I)

p 3 p 2 p 4 q 2 q 7 q 1 q 3 q 6 q 5

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

1 Matchings in Non-Bipartite Graphs

22 Max-Flow Algorithms

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

Network Flows made simple

Parallel Graph Algorithms (con4nued)

CSC Design and Analysis of Algorithms. LP Shader Electronics Example

CSE 421 Introduction to Algorithms Final Exam Winter 2005

Lecture 21 November 11, 2014

Parallel Graph Algorithms (con4nued)

Lecture 3. 1 Polynomial-time algorithms for the maximum flow problem

Basics on the Graphcut Algorithm. Application for the Computation of the Mode of the Ising Model

Lecture 8 Network Optimization Algorithms

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

Lecture 4: An FPTAS for Knapsack, and K-Center

Standard Diraphs the (unique) digraph with no vertices or edges. (modulo n) for every 1 i n A digraph whose underlying graph is a complete graph.

DISTRIBUTIVE LATTICES ON GRAPH ORIENTATIONS

Breadth First Search, Dijkstra s Algorithm for Shortest Paths

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

Breadth-First Search of Graphs

Introduction 1.1 PROBLEM FORMULATION

arxiv: v5 [cs.ds] 3 Jul 2015

5 Flows and cuts in digraphs

1 The Arthur-Merlin Story

(1,3) (3,4) (2,2) (1,2) (2,4) t

5. Partitions and Relations Ch.22 of PJE.

7.5 Bipartite Matching

The partial inverse minimum cut problem with L 1 -norm is strongly NP-hard. Elisabeth Gassner

Graphs and Network Flows IE411. Lecture 15. Dr. Ted Ralphs

Lecture 2: Just married

Math 5490 Network Flows

Two-Commodity Multiroute Maximum Flow Problem

CS 4407 Algorithms Lecture: Shortest Path Algorithms

An example of LP problem: Political Elections

The Max Flow Problem

Algorithms. Algorithms 6.4 MAXIMUM FLOW

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

1 Ordinary Load Balancing

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

CSC2420: Algorithm Design, Analysis and Theory Fall 2017

9. Submodular function optimization

2.13 Maximum flow with a strictly positive initial feasible flow

Fundamental Algorithms 11

On disconnected cuts and separators

Lecture 13 Spectral Graph Algorithms

USA Mathematical Talent Search Round 2 Solutions Year 27 Academic Year

CS 6820 Fall 2014 Lectures, October 3-20, 2014

Design and Analysis of Algorithms

1 The Local-to-Global Lemma

Functions If (x, y 1 ), (x, y 2 ) S, then y 1 = y 2

Network Flow Problems Luis Goddyn, Math 408

Midterm Exam 2 Solutions

ORIE 633 Network Flows October 4, Lecture 10

Algorithms. Algorithms 6.4 MAXIMUM FLOW

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

Transcription:

Comp 260: Advanced Algorithms Tufts University, Spring 2011 Lecture by: Prof. Cowen Scribe: Saeed Majidi Lecture 2: Network Flows 1 A wide variety of problems, including the matching problems discussed in the previous lectures, can be described and analyzed in terms of Flow Networks. In this lecture, we introduce the basic forms and laws governing Flow Networks, and develop several theorems useful for their analysis. 1 Definitions 1.1 Flow Networks A flow network G = (V, E) is a directed graph such that: G contains a source node s and a sink node t every vertex v V is on some path between s and t every edge (u, v) E has a capacity c(u, v) 0 nodes have no storage capacity Figure 1 shows an example of a flow network. 1.2 Flows A flow f in a network G is a function that assigns real numbers to edges such that following constraints are satisfied: capacity constraint: (u, v) E, f(u, v) c(u, v) 1 These lecture notes are adopted in part from a set of lecture nots scribed by Jared Hunter and Daniel Vukelich in 200. 1

()# (*# "# $ *+#! (+#,#.# /# ' (-# % & (,#,# Figure 1: A flow network G = (V, E) with edge capacities specified. skew symmetry: (u, v) E, f(u, v) = f(v, u) flow conservation: u, v / {s, t}, f(u, v) = 0 Since c(u, v) is defined for each pair of nodes for which (u, v) E, we can think of the capacity constraint as merely stating that no flow between two directly connected nodes can possibly exceed the capacity of the edge that exists between them. The skew symmetry constraint follows from the fact that flow networks are directed graphs. Another definition would be u, v V, f(v, u) = f(u, v), for only flows directed contrary to the underlying path direction will ever be labeled with negative values. The flow conservation constraint applies to all nodes except source s and sink t, because the output potential of a source and input potential of a sink are both. For all other nodes, however, the total outbound flow must always equal the total inbound flow (nodes have no storage capacity), and semantics imposed by the skew symmetry constraint force the sum of all flows to zero. 2

()*+# ()*,# "# $ *+),-#! -)*-# -).# -)(# 0)0# ' **)*/# % & **)*.#.).# Figure 2: A flow f in flow network of Figure 1 with value f = 20. 1.3 Values of Flows and Related Properties The value of a flow f is defined as the total of all flows outward from the source s which is equal to the total of flows inward to the sink t (by flow conservation constraint): f = v V f(s, v) = u V f(u, t) (1) For sets of nodes X, Y V following properties hold: and if X Y = : f(x, Y ) = x X f(x, y) (2) y Y f(x, X) = 0 (3) f(x, Y ) = f(y, X) () f(x Y, Z) = f(x, Z) + f(y, Z) (5) f(z, X Y ) = f(z, X) + f(z, Y ) (6) 3

The total flow between two sets of nodes is the sum of the flows from any member of the first set to a member of the second set. When the sets are identical, total net flow is zero by the flow conservation constraint. When the sets are not identical, the total net flows from each set to the other have equal absolute value and opposing sign. When the two sets are disjoint, the total net flow from their union to any third set Z V is the sum of their individual net flows to that subset, and vice versa. 1. Residual Networks Instead of viewing a flow network in terms of capacities in use, it can be useful to view it in terms of capacities remaining (unused capacities). This representation is called a residual network. Given a network G = (V, E) and a flow f in G, the residual network is G f (V, E f ) where: E f = {(u, v) where c f (u, v) > 0} c f (u, v) = c(u, v) f(u, v) So if there is no remaining capacity along an edge in the flow network, that edge should not appear in our chosen representation of G f, an effect illustrated in Figure 3. We can also draw residual networks with a complete set of back edges, whose values maintain the residual network s compliance with the flow conservation constraint. For simplicity, these edges (call them E b ) are shown separately in Figure, these edges are called backward edges. The G f is really defined by (V, E f E b ). It s important to note that the values of the backward edges are not always simply the values of the forward flows in G. In cases where a network specifies forward edges (i, j) and (j, i) (as our network does between nodes A and C, for example), the values of the residual edges may be calculated. Given flows x ij and x ji, and unused capacities u ij and u ji respectively: residual edge r ij = (u ij x ij ) + x ji, for forward edges residual edge r ji = (u ji x ji ) + x ij, for backward edges

(# )# "# $ *#!,-# *#.# ' +# % & )# Figure 3: The forward edges of residual network resulting from the flow in Figure 2. (# (# "# $ )*#!,# ' ))# % & ))# +# Figure : The backward edges of residual network resulting from the flow in Figure 2. 5

(#!.# )# "# $.#,-# *#.# (# *#,/# ' +#,,# )# % &,,# *# Figure 5: The residual network G f resulting from the flow f in Figure 2 with augmenting path p shaded. 1..1 Augmenting Paths If G f contains a path p from s to t, p is an augmenting path with respect to the f in G that formed G f : f f + c(p) c(p) = min{c f (u, v) for (u, v) p} Figure 5 shows the residual network G f resulting from flow f in Figure 2. The shaded edges demonstrate an augmenting path p. 1.5 Cuts A cut of G(V, E) is a partition of V into S, T. s S, and t T S T = V, and S T = 6

The capacity of a cut (S, T ) is: c(s, T ) = u S,v T c(u, v) (7) Claim 1.5.1 While the capacities of different cuts may be different, the total value of flow across a cut boundary is always constant. ()*+#! %/# ()*,# "# $ *+),-# %*# %,# -).# -)*-# -)(# 0)0# ' **)*/# % & **)*.#.).# Figure 6: Three cuts of a flow network. We will not prove the claim here, but will try to bolster its intuitiveness with an example. Figure 6 shows cuts of our familiar flow network. We will calculate the capacity and flow across each cut separately. S 1 = {s}, T 1 = {A, B, C, D, t} c(s 1, T 1 ) = c(s, A) + c(s, C) = 16 + 13 = 29 f(s 1, T 1 ) = f(s, A) + f(s, C) = 9 + 11 = 20 S 2 = {s, A, B, C, D}, T 2 = {t} c(s 2, T 2 ) = c(b, t) + c(d, t) = 20 + = 2 f(s 2, T 2 ) = f(b, t) + f(d, t) = 16 + = 20 S 3 = {A, s, B, D}, T 3 = {C, t} c(s 3, T 3 ) = c(a, C) + c(s, C) + c(b, C) + c(b, t) + c(d, t) c(s 3, T 3 ) = + 13 + 9 + 20 + = 50 f(s 3, T 3 ) = f(s, C)+f(B, t)+f(d, t) f(c, D) = 11+16+ 11 = 20 7

2 The Max-Flow Problem Given (G, s, t), the Max-Flow problem is that of finding a maximal-capacity flow in G from source s to sink t. We call the value of this maximal flow f. 2.1 The Max-Flow Min-Cut Theorem The Max-Flow Min-Cut theorem states that f, the value of the maximum flow, is equal to the minimum cut capacity out of all possible cuts of G. Theorem 2.1.1 (Maxflow/Mincut Theorem) Given a network, G, and a flow, f, the following are equivalent: 1. f is a maximum flow in G 2. the residual network G f contains no augmenting paths 3. we can find some cut (S, T ) for which f = c(s, T ) Proof. 1 2. If G f contained an augmenting path then we could improve f, in which case f would not be maximum and f would not be a maximum flow. 2 3. 1. assume G f has no augmenting path 2. let S = {v V such that v is reachable from s in G f } 3. let T = V S. notice s S, but t / S. t is not reachable in G f because there are no augmenting paths 5. u S, v T : f(u, v) = c(u, v) (a) assume f(u, v) c(u, v) (maybe we can improve f(u, v)) 8

6. (b) if (u, v) E (the edges of G f ), then v S (c) but v / S, so f = f(s, T ) = u f(u, v) = c(u, v) = c(s, T ) v u S v T 3 1. 1. assume f = c(s, T ) 2. but f f c(s, T ) 3. so f = c(s, T ) f = f 2.2 The Ford-Fulkerson Algorithm The Ford-Fulkerson algorithm initializes a zero (null) flow in the network and then repeatedly augments the initial (null) flow with any path that augments it. FF (G, s, t): 1. Initialize flow f to 0 2. while there exists an augmenting path p in G f do augment f along p 3. return f The first few iterations of the Ford-Fulkerson algorithm are shown in Figure 7. In the figure, (a) shows the initial network, and (b) is the residual network induced by choosing the augmenting path along the top of the graph. Within (b), the next augmenting path is shown in bold lines, and (c) shows the original network augmented with this path. Finally, (d) shows the residual network corresponding to (c), from which we may select a subsequent augmenting path. The algorithm terminates when there are no more augmenting paths. 9

12/12 12 12/16 12/20 8 10 9 7 12 10 9 7 12 13 13 1 (a) 12/12 1 (b) 12 16/16 12/20 16 8 /10 9 7 6 8 9 7 12 13 / 13 /1 10 (c) (d) Figure 7: Flows in G and its residual network. Claim 2.2.1 The Ford-Fulkerson algorithm always terminates and always returns a maximum flow. 2.2.1 Time Complexity of Ford-Fulkerson Algorithm Initialization of f and the construction of G f are both O( E ), as is the process of finding an augmenting path. The while loop is executed at most f times, since the augmenting path increases flow by at least one unit each iteration. It is therefore easily seen that worst case bounds are O( f E ). Now, consider the flow in Figure 8. In (a), a flow of 1 unit follows the path of dotted lines and, (b) shows the resulting residual network. Now, suppose the next augmenting path is that highlighted in (b); once again, an increase in flow of 1 unit will result, and this alternating pattern can continue f times, exhibiting the worst case performance. For improved performance, we next sketch the Edmonds-Karp algorithm. 10

1/1,000,000 1,000,000 999,999 1,000,000 1 1/1 1 1 1,000,000 1/1,000,000 1,000,000 999,999 (a) (b) Figure 8: Worst case flow in Ford-Fulkerson 2.3 The Edmonds-Karp Algortihm Instead of choosing any augmenting path each time through the while loop, we might instead choose, among augmenting paths to choose, a path that optimizes some criteria. The Edmonds-Karp algorithm always chooses a path with the minimum number of comprising edges. It makes a new network from residual network where edge weights are replace by 1 and then employs a breadth-first search to choose the shortest augmenting path from s to t. That shortest augmenting path corresponds to an augmented path in the residual network with the fewest number of edges. Referring to Figure 8, choosing path with the fewest number of edges(namely the paths of two edges of 1,000,000 along the top and bottom of the graph) would have readily achieved the 2,000,000 capacity maximum flow by avoiding the extra edge of capacity 1 (the bottleneck). Moreover, maximum flow would then have been realized in two iterations of the while loop instead of 2,000,000 by Ford-Fulkerson! 2.3.1 Time Complexity of Edmonds-Karp Algorithm Lemma 2.3.1 If the E-K algorithm is run on a flow network with source s and sink t, then for all verticie v V {s, t}, the shortest path distance can only increase in the residual network. 11

Proof (by contradiction). Let f be the flow before the first augmentation that decreases some shortest path distance and let f be the flow just afterwards. Let v be the closest vertex to s in f s residual network: d f (s, v) d f (s, v) Let p = s u v be the shortest path from s to v in G f such that (u, v) E f and d f (s, u) = d f (s, v) 1. We choose v to be the closest vertex to s with distance decreasing. So d f (s, v) d f (s, u). Claim 2.3.2 (u, v) / E f : edge (u, v) has been disappeared from E f Proof. (u, v) E f d f (s, v) d f (s, u) + 1 d f (s, v) + 1 = d f (s, u) + 1 How can we have (u, v) / E f but (u, v) E f? It must be that we increased the flow from v to u. Since E-C algorithm always augments flow along shortest path, the shortest path from s to u in G f has (v, u) as its last edge: d f (s, v) = d f (s, u) 1 d f (s, u) = d f (s, v) 2 but we assumed d f (s, v) d f (s, v) and it is a contradiction. Theorem 2.3.3 Edmonds-Karp algorithm will go for at most O( V E ) iterations Proof. Say edge (u, v) in a residual network G f is a critical on augmenting path p if the residual capacity of p is the residual capacity of (u, v). That is if c f (p) = c f (u, v), at least one edge on every augmenting path is critical. We will show an edge can become critical at most V /2 1 times. 12

Let u, v be vertices in V connected by an edge in E. We claim that from the time (u, v) is critical to the next time it becomes critical again, its distance to s must increase by 2. Let f be the flow when its first critical: d f (s, v) = d f (s, u) + 1 (since augmenting paths are shortest paths). Then (u, v) disappears from residual network can not appear again until (u, v) appears on an augmenting path. For some flow f : d f (s, u) = d f (s, v) + 1 d f (s, u) + 1 = d f (s, u) + 2 13