Algorithms (2IL15) – Lecture 7

Slides:



Advertisements
Similar presentations
Maximum flow Main goals of the lecture:
Advertisements

COMP 482: Design and Analysis of Algorithms
Lecture 7. Network Flows We consider a network with directed edges. Every edge has a capacity. If there is an edge from i to j, there is an edge from.
Lecture 5: Network Flow Algorithms Max-Flow Min-Cut Single-Source Shortest-Path (SSSP) Job Sequencing.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.
MAXIMUM FLOW Max-Flow Min-Cut Theorem (Ford Fukerson’s Algorithm)
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Advanced Algorithm Design and Analysis (Lecture 8) SW5 fall 2004 Simonas Šaltenis E1-215b
Lectures on Network Flows
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 The Max Flow Problem. 2 Flow networks Flow networks are the problem instances of the max flow problem. A flow network is given by 1) a directed graph.
CS138A Network Flows Peter Schröder. CS138A Flow Networks Definitions a flow network G=(V,E) is a directed graph in which each edge (u,v)
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Lecture 4 Tuesday, 2/19/02 Graph Algorithms: Part 2 Network.
1 Maximum flow problems. 2 - Introduction of: network, max-flow problem capacity, flow - Ford-Fulkerson method pseudo code, residual networks, augmenting.
Maximum Flows Lecture 4: Jan 19. Network transmission Given a directed graph G A source node s A sink node t Goal: To send as much information from s.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2004 Lecture 5 Wednesday, 10/6/04 Graph Algorithms: Part 2.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Theory of Computing Lecture 13 MAS 714 Hartmut Klauck.
Single Source Shortest-Path: The General Case (with negative edges) Bellman-Ford algorithm. Iteratively relax all edges |V|-1 times Running time? O(VE).
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Finding Max Flow.
Max Flow – Min Cut Problem. Directed Graph Applications Shortest Path Problem (Shortest path from one point to another) Max Flow problems (Maximum material.
Maximum Flow Problem (Thanks to Jim Orlin & MIT OCW)
Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices.
Chapter 7 April 28 Network Flow.
15.082J and 6.855J March 4, 2003 Introduction to Maximum Flows.
Chapter 7 May 3 Ford-Fulkerson algorithm Step-by-step walk through of an example Worst-case number of augmentations Edmunds-Karp modification Time complexity.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
1 Network Flow CSC401 – Analysis of Algorithms Chapter 8 Network Flow Objectives: Flow networks –Flow –Cut Maximum flow –Augmenting path –Maximum flow.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
A directed graph G consists of a set V of vertices and a set E of arcs where each arc in E is associated with an ordered pair of vertices from V. V={0,
Maximum Flow Problem Definitions and notations The Ford-Fulkerson method.
Instructor Neelima Gupta Edited by Divya Gaur(39, MCS '09) Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09)
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
Network Flow What is a network? Flow network and flows
Maximum Flow Chapter 26.
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Maximum Flow Chapter 26.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Graph Algorithms Minimum Spanning Tree (Chap 23)
CS4234 Optimiz(s)ation Algorithms
Lectures on Network Flows
Algorithms and Networks Hans Bodlaender
Network flow problem [Adapted from M.Chandy].
Richard Anderson Lecture 23 Network Flow
CSCI 3160 Design and Analysis of Algorithms Tutorial 8
ADVANCED ALGORITHMS GRAPH ALGORITHMS (UNIT-2).
Max Flow – Min Cut Problem
Instructor: Shengyu Zhang
Edmonds-Karp Algorithm
Network Flows and Matching (Supplementary)
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Network Flow and Connectivity in Wireless Sensor Networks
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Flow Networks Topics Flow Networks Residual networks
Richard Anderson Lecture 23 Network Flow
Network Flows and Matching (Supplementary)
Max Flow Min Cut, Bipartite Matching Yin Tat Lee
Flow Networks General Characteristics Applications
Flow Networks and Bipartite Matching
EE5900 Advanced Embedded System For Smart Infrastructure
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Text Book: Introduction to algorithms By C L R S
Lecture 21 Network Flow, Part 1
Richard Anderson Lecture 22 Network Flow
Advanced Graph Homer Lee 2013/10/31.
Presentation transcript:

Algorithms (2IL15) – Lecture 7 MAXIMUM FLOW

optimization problems on graphs single-source shortest paths Part II of the course: optimization problems on graphs single-source shortest paths Find shortest path from source vertex to all other vertices all-pairs shortest paths Find shortest paths between all pairs of vertices maximum flow Find maximum flow from source vertex to target vertex maximum bipartite matching Find maximum number of disjoint pairs of vertices with edge between them 2 1 2.3 − 2 4 3 1 8 5 2 4

Single-Source Shortest Paths Bellman-Ford algorithm can handle negative edge weights, works even for negative-weight cycles running time Θ ( |V | ∙ |E| ) Dijkstra’s algorithm works only for non-negative edge weights running time Θ ( |V | log |V | + |E| ) All-Pairs Shortest Paths Dynamic-programming algorithms connection to matrix-multiplication improved version (repeated squaring) runs in Θ ( |V |3 log |V | ) time different subproblems give simple Θ ( |V |3)-time algorithm (Floyd-Warshall) Johnson’s algorithm: reweighting modify graph to make all edge-weights non-negative then run Dijkstra’s algorithm |V | times running time Θ ( |V |2 log |V | + |V | ∙ |E| )

The maximum-flow problem source sink How much flow we can push through the network? edges are directed and have a maximum capacity source is generating the flow, sink is consuming it all flow arriving at a node must also leave the node, except at sink

trick: insert node on edge 3 10 2 2 3 source s t sink 2 1 5 5 3 Flow network: directed graph G = ( V, E ), where each edge (u,v) in E has a capacity c(u,v ) ≥ 0 define c(u,v)=0 if (u,v) not in E there are two special nodes in V: the source s and the sink t if (u,v) in E then (v,u) not in E Assume that any node u can be reached from s and can reach t Note: G can have cycles trick: insert node on edge

2 / 3 4 / 10 2 / 2 2 / 2 3 / 3 source s t sink 2 / 2 1 / 1 1 / 5 1 / 5 0 / 3 flow = 1, capacity = 5 Flow: function f : V x V → R satisfying capacity constraint: 0 ≤ f (u,v) ≤ c(u,v ) for all nodes u,v ( Hence, f (u,v) = 0 if edge (u,v) does not exist. ) flow conservation: for all nodes u ≠ s, t we have flow in = flow out: ∑v in V f (v,u) = ∑v in V f (u,v) value of flow: |f | = ∑v in V f (s,v) − ∑v in V f (v,s)

Flow: function f : V x V → R satisfying capacity constraint: 0 ≤ f (u,v) ≤ c(u,v ) for all nodes u,v ( Hence, f (u,v) = 0 if edge (u,v) does not exist. ) flow conservation: for all nodes u ≠ s, t we have flow in = flow out: ∑v in V f (v,u) = ∑v in V f (u,v) value of flow: |f | = ∑v in V f (s,v) − ∑v in V f (v,s) Can there be flow if all outgoing edges from the source have zero flow? 2 3 5 s t 2 / 0 /

Idea for computing max flow incrementally start with zero flow repeat until stuck − find path from s to t along which we can increase the flow − increase flow along the path 0 / 3 0 / 2 0 / 2 0 / 3 0 / 2 source s t sink 0 / 6 0 / 1 0 / 5 0 / 5 0 / 3 Total flow: 0

Idea for computing max flow incrementally start with zero flow repeat until stuck − find path from s to t along which we can increase the flow − increase flow along the path 0 / 3 0 / 2 2 / 2 FULL 2 / 3 2 / 2 source s t sink FULL 0 / 6 0 / 1 0 / 5 0 / 5 0 / 3 Total flow: 0 + 2

Idea for computing max flow incrementally start with zero flow repeat until stuck − find path from s to t along which we can increase the flow − increase flow along the path 0 / 3 0 / 2 2 / 2 FULL 2 / 3 2 / 2 source s t sink FULL 0 / 6 0 / 1 0 / 5 0 / 5 0 / 3 Total flow: 0 + 2

Idea for computing max flow incrementally start with zero flow repeat until stuck − find path from s to t along which we can increase the flow − increase flow along the path 0 / 3 0 / 2 2 / 2 FULL 2 / 3 2 / 2 source s t sink FULL 5 / 6 0 / 1 5 / 5 FULL 5 / 5 FULL 0 / 3 Total flow: 0 + 2 + 5

Idea for computing max flow incrementally start with zero flow repeat until stuck − find path from s to t along which we can increase the flow − increase flow along the path stuck ! do we have max flow? we need to decrease flow along an edge no 0 / 3 0 / 2 2 / 2 FULL 2 / 3 2 / 2 source s t sink FULL 5 / 6 0 / 1 5 / 5 FULL 5 / 5 FULL 0 / 3 Total flow: 0 + 2 + 5

trick: decrease flow along edge = send flow along reverse edge Idea for computing max flow incrementally start with zero flow repeat until stuck − find path from s to t along which we can increase the flow − increase flow along the path trick: decrease flow along edge = send flow along reverse edge 0 / 3 0 / 2 2 / 2 FULL 2 / 3 2 / 2 source s t sink FULL 5 / 6 FULL 0 / 1 5 / 5 5 / 5 FULL 0 / 3 Total flow: 0 + 2 + 5

trick: decrease flow along edge = send flow along reverse edge Idea for computing max flow incrementally start with zero flow repeat until stuck − find path from s to t along which we can increase the flow − increase flow along the path trick: decrease flow along edge = send flow along reverse edge 1 / 3 1 / 2 2 / 2 FULL 1 / 3 1 2 / 2 source s t sink FULL 6 / 6 1 / 1 5 / 5 FULL 5 / 5 FULL 0 / 3 Total flow: 0 + 2 + 5 + 1

The Ford-Fulkerson method work with residual network Gf original edges reverse edges: sending flow along such an edge = decreasing flow along original edge Ford-Fulkerson-Method ( G, s, t ) Initialize flow: set f (u,v) = 0 for each pair (u,v) in V x V while there is an augmenting path p in the residual network Gf do increase flow by augmenting flow along p return f

G = (V,E) is flow network with source s and sink t f = flow on G residual capacity of pair of vertices u,v in G ( for the given flow f ) c (u,v) − f (u,v) if (u,v) in E // original edge cf (u,v) = f (v,u) if (v,u) in E // reverse edge 0 otherwise well defined because (u,v) and (v,u) cannot both be in E 2 / 2 cf = 0 2 / 3 cf = 1 s t 1 / 2 cf = 2 cf = 2 cf = 0 0 / 5 1 / 1 / 3 5

network Gf = (V, Ef ) where Ef = { (u,v) in V x V : cf (u,v) > 0 } Residual network of network G with given flow f network Gf = (V, Ef ) where Ef = { (u,v) in V x V : cf (u,v) > 0 } (u,v) in E : Ef can contain (u,v) and/or (v,u) (u,v) not in E and (v,u) not in E: (u,v) and (v,u) not in Ef either 1 / 2 / 2 3 5 s t 0 / cf = 1 cf = 0 cf = 2 residual network 1 s t 2 1 2 4 5 1 2 1 1

Let’s look at earlier example, where we had to decrease flow along some edge residual network 0 / 3 0 / 2 2 / 2 FULL 2 / 3 2 / 2 s t FULL 5 / 6 1 5 / 5 FULL 0 / 5 / 5 FULL 0 / 3 3 2 2 1 2 2 s t 1 1 5 5 5 3

flow in residual network Gf should satisfy residual capacity constraints for each vertex ≠ s,t: flow in = flow out We will only use flows along augmenting path p = simple s-to-t path in Gf 3 2 2 1 2 2 s t 1 1 5 5 5 3 residual capacity = 1 residual capacity cf (p) of p = amount of flow we can push along p = min { cf (u,v): (u,v) is an edge of p }

Augmenting flow f by flow along simple s-to-t path p in Gf for each edge (u,v) on the augmenting path p do if (u,v) in E then increase f (u,v) by cf (p) else decrease f (v,u) by cf (p) 3 s t 2 1 5 3 residual capacity = 1 2 / 2 3 5 6 1 s t 0 / 5 / 1 1 1 6 1

Lemma: Augmenting flow along simple s-to-t path p gives valid flow in G whose value is (old flow value) + residual capacity cf (p). Proof. Must show: new flow satisfies capacity constraint: 0 ≤ f (u,v) ≤ c(u,v) new flow satisfies: flow in = flow out new flow value = (old flow value) + residual capacity cf (p). s t 2 1 5 3 c (u,v) − f (u,v) if (u,v) in E cf (u,v) = f (v,u) if (v,u) in E 0 otherwise

Ford-Fulkerson ( G, s, t ) Initialize flow: set f (u,v) = 0 for each pair (u,v) in V x V Construct residual network Gf while there is an augmenting path p in the residual network Gf do // increase flow by augmenting flow along p cf (p) ← residual capacity of the path p for each edge (u,v) on the path p do if (u,v) in E then f (u,v) ← f (u,v) + cf (p) else f (v,u) ← f (v,u) − cf (p) Update the residual network Gf return f need algorithm to find path between two given vertices; for the moment we assume we just find any path

Properties of Ford-Fulkerson: Invariant: flow is valid Flow increases at each iteration Questions: Are we sure it always terminates? not guaranteed if capacities are irrational and augmenting paths are chosen in the “wrong” way How many iterations before we get stuck (no augmenting path) ? more next lecture Are we sure we have max flow when we get stuck ? want to prove: no augmenting path max flow

Cuts of flow network G = (V,E) cut (S,T) = partitioning of V into subsets S and T, with s in S and t in T flow f (S,T) across cut (S,T) = ∑u in S ∑v in T f(u,v) − ∑u in S ∑v in T f(v,u) = ( 2 + 2 + 3 + 1 ) − ( 1 + 1 ) = 6 capacity c(S,T) of cut (S,T) = max flow across the cut = ∑u in S ∑v in T c(u,v) = ( 2 + 3 + 3 + 5 ) = 13 2 / 3 4 / 10 2 / 2 2 / 2 3 / 3 s t 2 / 2 1 / 1 1 / 5 1 / 5 0 / 3

Lemma: Flow across any cut is the same, and equals the value of the flow. Proof. See book. flow across cut = 6 10 2 5 3 1 s t 2 / 3 / 4 / 1 / 0 /

Lemma: Flow across any cut is the same, and equals the value of the flow. Note: capacity of cuts is not necessarily the same minimum cut = cut whose capacity is minimum Corollary: Maximum flow cannot be more than capacity of minimum cut. Proof. Consider flow f of maximum value value of f = flow of f across any cut = flow of f across minimum cut ≤ capacity of minimum cut

Combine (iii) with corollary: maximum flow = capacity of minimum cut Corollary: Maximum flow cannot be more than capacity of minimum cut. Max-flow min-cut Theorem: Let f be a flow in a flow network G. Then the following conditions are equivalent: (i) f is a maximum flow in G (ii) residual network Gf contains no augmenting path (iii) there is a cut (S,T) with |f | = c(S,T) Combine (iii) with corollary: maximum flow = capacity of minimum cut

Max-flow min-cut Theorem: Let f be a flow in a flow network G Max-flow min-cut Theorem: Let f be a flow in a flow network G. Then the following conditions are equivalent: (i) f is maximum flow in G (ii) residual network Gf contains no augmenting path (iii) there is a cut (S,T) with |f | = c(S,T) Proof. (i) (ii): if there were an augmenting path, we could increase the flow.

Max-flow min-cut Theorem: Let f be a flow in a flow network G Max-flow min-cut Theorem: Let f be a flow in a flow network G. Then the following conditions are equivalent: (i) f is maximum flow in G (ii) residual network Gf contains no augmenting path (iii) there is a cut (S,T) with |f | = c(S,T) Proof. (ii) (iii): Define: S = set of all vertices that can be reached from s in Gf T = V − S Consider edge (u,v) from S to T: f (u,v) = c(u,v) otherwise (u,v) in Ef and v is reachable Consider edge (v,u) from T to S: f (v,u) = 0 otherwise (u,v) in Ef and v is reachable Hence, |f | = c(S,T)

Max-flow min-cut Theorem: Let f be a flow in a flow network G Max-flow min-cut Theorem: Let f be a flow in a flow network G. Then the following conditions are equivalent: (i) f is maximum flow in G (ii) residual network Gf contains no augmenting path (iii) there is a cut (S,T) with |f | = c(S,T) Proof. (iii) (i): follows from Corollary

more on flows next lecture Max-Flow Summary Flow network directed graph with source and sink, and capacities on the edges if (u,v) in E then we cannot have (v,u) in E Flow in a network must satisfy capacity constraints and “flow in = flow out” Ford-Fulkerson method iteratively increase flow using augmenting paths in residual graph Max flow = min cut more on flows next lecture