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

Similar documents
CMPSCI 611: Advanced Algorithms

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

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

1 Review for Lecture 2 MaxFlow

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

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

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

Algorithms: COMP3121/3821/9101/9801

Algorithms and Theory of Computation. Lecture 11: Network Flow

6.046 Recitation 11 Handout

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

Max Flow: Algorithms and Applications

Lecture 2: Network Flows 1

Algorithms: Lecture 12. Chalmers University of Technology

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

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

Internet Routing Example

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?

CS 1501 Recitation. Xiang Xiao

The maximum flow problem

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

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

Network Flows made simple

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

Algorithm Design and Analysis

The min cost flow problem Course notes for Optimization Spring 2007

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

Energy minimization via graph-cuts

Parallel Graph Algorithms (con4nued)

22 Max-Flow Algorithms

Parallel Graph Algorithms (con4nued)

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

Lecture 8 Network Optimization Algorithms

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

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

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

An example of LP problem: Political Elections

CSC 373: Algorithm Design and Analysis Lecture 12

Algorithm Design and Analysis

Maximum flow problem (part I)

Mathematics for Decision Making: An Introduction. Lecture 13

Two Applications of Maximum Flow

2.13 Maximum flow with a strictly positive initial feasible flow

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

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

Discrete Optimization 2010 Lecture 3 Maximum Flows

NP-Completeness I. Lecture Overview Introduction: Reduction and Expressiveness

7.5 Bipartite Matching

Maximum flow problem

Review Questions, Final Exam

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

Exposition of the Dinitz algorithm

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

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

5 Flows and cuts in digraphs

Lecture 21 November 11, 2014

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

Network Flow Problems Luis Goddyn, Math 408

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

CMPSCI 311: Introduction to Algorithms Second Midterm Exam

Lesson 3: Using Linear Combinations to Solve a System of Equations

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

CSE 202 Homework 4 Matthias Springer, A

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

Midterm Exam 2 Solutions

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

The augmented form of this LP is the following linear system of equations:

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Matroids and Greedy Algorithms Date: 10/31/16

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

NP-Completeness. Algorithmique Fall semester 2011/12

Maximum Flows & Minimum Cuts

Symmetric chain decompositions of partially ordered sets

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

Maximum skew-symmetric flows and matchings

University of Washington March 21, 2013 Department of Computer Science and Engineering CSEP 521, Winter Exam Solution, Monday, March 18, 2013

Capacity Releasing Diffusion for Speed and Locality

Solutions to Review Questions, Exam 1

Part III: A Simplex pivot

Soviet Rail Network, 1955

1 Matchings in Non-Bipartite Graphs

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

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

2. A vertex in G is central if its greatest distance from any other vertex is as small as possible. This distance is the radius of G.

Design and Analysis of Algorithms

Bulletin of the Transilvania University of Braşov Vol 8(57), No Series III: Mathematics, Informatics, Physics,

Algorithms. Algorithms 6.4 MAXIMUM FLOW

6.854 Advanced Algorithms

Lecture 13: Spectral Graph Theory

Review Questions, Final Exam

SOLUTIONS OF 2012 MATH OLYMPICS LEVEL II T 3 T 3 1 T 4 T 4 1

The Max Flow Problem

2007 Winton. Empirical Distributions

Design and Analysis of Algorithms

Lecture 13 Spectral Graph Algorithms

Chemical Reaction Optimization for Max Flow Problem

2 Systems of Linear Equations

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

Section 1.5. Solution Sets of Linear Systems

CS261: A Second Course in Algorithms Lecture #8: Linear Programming Duality (Part 1)

Transcription:

CSE 36: Data Structures Network Flow James Fogarty Autumn 007

Network Flows Given a weighted, directed graph G=(V,E) Treat the edge weights as capacities How much can we flow through the graph? A 1 B 7 F 11 H 9 10 3 C 13 1 5 G 6 11 6 D E 0 I

Network flow: definitions Define special source s and sink t vertices Define a flow as a function on edges: Capacity: f(v,w) <= c(v,w) Conservation: f ( u, v) = 0 for all u v V except source, sink Value of a flow: f f ( s, v) = v Saturated edge: when f(v,w) = c(v,w) 3

Network flow: definitions Capacity: you can t overload an edge Conservation: Flow entering any vertex must equal flow leaving that vertex We want to maximize the value of a flow, subject to the above constraints

Network Flows Given a weighted, directed graph G=(V,E) Treat the edge weights as capacities How much can we flow through the graph? s 1 B 7 F 11 H 9 10 3 C 13 1 5 G 6 11 6 D E 0 t 5

A Good Idea that Doesn t Work Start flow at 0 While there s room for more flow, push more flow across the network! While there s some path from s to t, none of whose edges are saturated Push more flow along the path until some edge is saturated Called an augmenting path 6

How do we know there s still room? Construct a residual graph: Same vertices Edge weights are the leftover capacity on the edges If there is a path s t at all, then there is still room 7

Example (1) Initial graph no flow B C 3 1 A D E F Flow / Capacity 8

Example () Include the residual capacities 0/3 3 B 0/ 0/1 C 0/ A 0/ 1 D 0/ 0/ E 0/ F Flow / Capacity Residual Capacity 9

Example (3) Augment along ABFD by 1 unit (which saturates BF) 1/3 B 0/ 1/1 C 0/ A 0/ 0 D 1/ 0/ E 0/ F 3 Flow / Capacity Residual Capacity 10

Example () Augment along ABEFD (which saturates BE and EF) 3/3 0 B 0/ 1/1 C 0/ A 0 / 0 D 3/ 0/ E / 0 F 1 Flow / Capacity Residual Capacity 11

Now what? There s more capacity in the network but there s no more augmenting paths 1

Network flow: definitions Define special source s and sink t vertices Define a flow as a function on edges: Capacity: f(v,w) <= c(v,w) Skew symmetry: f(v,w) = -f(w,v) Conservation: f ( u, v) = 0 for all u v V except source, sink Value of a flow: f f ( s, v) = v Saturated edge: when f(v,w) = c(v,w) 13

Network flow: definitions Capacity: you can t overload an edge Skew symmetry: sending f from u v implies you re sending -f, or you could return f from v u Conservation: Flow entering any vertex must equal flow leaving that vertex We want to maximize the value of a flow, subject to the above constraints 1

Main idea: Ford-Fulkerson method Start flow at 0 While there s room for more flow, push more flow across the network! While there s some path from s to t, none of whose edges are saturated Push more flow along the path until some edge is saturated Called an augmenting path 15

How do we know there s still room? Construct a residual graph: Same vertices Edge weights are the leftover capacity on the edges Add extra edges for backwards-capacity too! If there is a path s t at all, then there is still room 16

Example (5) Add the backwards edges, to show we can undo some flow A 3 3/3 0 B 0 / 0/ 1/1 0 1 C 0/ D 3/ 0/ Flow / Capacity Residual Capacity Backwards flow E / 0 F 1 3 17

Example (6) Augment along AEBCD (which saturates AE and EB, and empties BE) 3 B / 0 C A 3/3 0 0/ 1/1 0 1 / D 0 3/ / Flow / Capacity Residual Capacity Backwards flow E / 0 F 1 3 18

Example (7) Final, maximum flow B / C 3/3 / A 0/ 1/1 D 3/ / Flow / Capacity Residual Capacity Backwards flow E / F 19

How should we pick paths? Two very good heuristics (Edmonds-Karp): Pick the largest-capacity path available Otherwise, you ll just come back to it later so may as well pick it up now Pick the shortest augmenting path available For a good example why 0

Don t Mess this One Up B 0/000 0/000 A 0/1 D 0/000 C 0/000 Augment along ABCD, then ACBD, then ABCD, then ACBD Should just augment along ACD, and ABD, and be finished 1

Running time? Each augmenting path can t get shorter and it can t always stay the same length So we have at most O(E) augmenting paths to compute for each possible length, and there are only O(V) possible lengths. Each path takes O(E) time to compute Total time = O(E V)

Network Flows What about multiple turkey farms? s 1 B 7 F 11 H 9 10 3 C 13 1 5 G 6 11 6 s E 0 t 3

Network Flows Create a single source, with infinite capacity edges connected to sources Same idea for multiple sinks s 1 B 7 F 11 H s! 9 10 3 C 13 1 5 G 6 11 6 s E 0 t

One more definition on flows We can talk about the flow from a set of vertices to another set, instead of just from one vertex to another: f ( X, Y ) = f ( x, y) x X y Y Should be clear that f(x,x) = 0 So the only thing that counts is flow between the two sets 5

Network cuts Intuitively, a cut separates a graph into two disconnected pieces Formally, a cut is a pair of sets (S, T), such that V = S T S T = {} and S and T are connected subgraphs of G 6

Minimum cuts If we cut G into (S, T), where S contains the source s and T contains the sink t, Of all the cuts (S, T) we could find, what is the smallest (max) flow f(s, T) we will find? 7

Min Cut - Example (8) S T B C 3 1 A D E F Capacity of cut = 5 8

Coincidence? NO! Max-flow always equals Min-cut Why? If there is a cut with capacity equal to the flow, then we have a maxflow: We can t have a flow that s bigger than the capacity cutting the graph! So any cut puts a bound on the maxflow, and if we have an equality, then we must have a maximum flow. If we have a maxflow, then there are no augmenting paths left Or else we could augment the flow along that path, which would yield a higher total flow. If there are no augmenting paths, we have a cut of capacity equal to the maxflow Pick a cut (S,T) where S contains all vertices reachable in the residual graph from s, and T is everything else. Then every edge from S to T must be saturated (or else there would be a path in the residual graph). So c(s,t) = f(s,t) = f(s,t) = f and we re done. 9

GraphCut http://www.cc.gatech.edu/cpl/projects/graphcuttextures/ 30