Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.

Slides:



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

1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
1 Review of some graph algorithms Graph G(V,E) (Chapter 22) –Directed, undirected –Representation Adjacency-list, adjacency-matrix Breadth-first search.
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)
The Maximum Network Flow Problem. CSE Network Flows.
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 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)
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.
1 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method Maximum bipartite matching.
1 Optimization Spring 2007 (Third Quarter). 2 Some practical remarks Homepage: Exam: Written, 3 hours. There.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 4 Tuesday, 10/2/01 Graph Algorithms: Part 2 Network.
The max flow problem
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.
Flows sourcesink s t Flows sourcesink edge-weights = capacities.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2006 Lecture 5 Wednesday, 10/4/06 Graph Algorithms: Part 2.
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.
Maximum Flow Maximum Flow Problem The Ford-Fulkerson method
Assignment 4. (Due on Dec 2. 2:30 p.m.) This time, Prof. Yao and I can explain the questions, but we will NOT tell you how to solve the problems. Question.
Flow Networks Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut.
Maximum Flow Chapter 26.
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).
1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf.
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.
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows.
Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices.
CS223 Advanced Data Structures and Algorithms 1 Maximum Flow Neil Tang 3/30/2010.
Chapter 7 April 28 Network Flow.
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.
Fall 2003Maximum Flow1 w s v u t z 3/33/3 1/91/9 1/11/1 3/33/3 4/74/7 4/64/6 3/53/5 1/11/1 3/53/5 2/22/2 
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
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)
The Maximum Network Flow Problem
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
The Maximum Network Flow Problem
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
Lecture 22 Network Flow, Part 2
Instructor: Shengyu Zhang
Network Flows and Matching (Supplementary)
Lecture 10 Network flow Max-flow and Min-cut Ford-Fulkerson method
Flow Networks Topics Flow Networks Residual networks
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 21 Network Flow
Network Flows and Matching (Supplementary)
Flow Networks and Bipartite Matching
Algorithms (2IL15) – Lecture 7
EE5900 Advanced Embedded System For Smart Infrastructure
Lecture 21 Network Flow, Part 1
Richard Anderson Lecture 22 Network Flow
Lecture 22 Network Flow, Part 2
Advanced Graph Homer Lee 2013/10/31.
Presentation transcript:

Theory of Computing Lecture 12 MAS 714 Hartmut Klauck

Network Flows A flow network is a directed graph G=(V,E) with nonegative edge weights C(u,v), called capacities – nonedges have capacity 0 There is a source s and a sink t We assume that for all v there is a path from s to v and from v to t A flow in G is a mapping f from V £ V to the reals: – For all u,v: f(u,v) · C(u,v) [capacity constraint] – For all u,v: f(u,v) = -f(v,u) [skew symmetry] – For all u  s,t:  v f(u,v)=0 [flow conservation] The value of a flow f is |f|=  v f(s,v) The Max Flow problem consists of finding the maximum value of any flow for G,C,s,t

Motivation The Max Flow problem models the situation where commodities need to be transported through a network with limited capacities Application to other problems

Application: Matching For simplicity we consider the bipartite matching problem G=(L [ R,E) is a bipartite graph A matching is a set M µ E, in which no two edges share a vertex A perfect matching (assuming |L|=|R|) has |L| edges Edges have weights W(u,v) A maximum matching is a matching with the maximum total edge weight

Flow network for bipartite matching G=(L [ R,E) is a bipartite graph (unweighted) Add two extra vertices s, t – connect s to all vertices of L, weight 1 – keep the edges in E (directed from L to R), weight 1 – connect all vertices in R to t, weight 1 Then the maximum flow in the new graph is equal to the maximum matching – We will prove this later, it is obvious that a matching leads to a flow but not the other way around

Back to flows: remarks Having several sources and sinks can be modeled by using extra edges Nonadjacent u,v have C(u,v)=0 Notation: For vertex sets X,Y denote f(X,Y)=  x 2 X, y 2 Y f(x,y) Similarly define C(X,Y) C(u,v)  C(v,u) is possible!

An observation N=(G,C,s,t) is a flow network, f a flow. Then – For all X µ V: f(X,X)=0 – For all X,Y µ V: f(X,Y)=-f(Y,X) – For all X,Y,Z with X Å Y= ; : f(X [ Y,Z)=f(X,Z)+f(Y,Z)

The Ford Fulkerson Method To start set f(u,v)=0 for all pairs u,v We will look for augmenting paths. i.e., paths in G along which we can increase f Repeat until there is no augmenting path

Augmenting paths Setting C(u,v)=0 for nonedges allows us to assume that the graph is complete Consider simple paths from s to t Definition: If C(u,v)-f(u,v)>0 for all edges on the path then the path is augmenting – Note: C(u,v)=0 and f(u,v)<0 possible Definition: capacity C(p) of a path p is the minimum capacity of any edge on the path

Residual Network Given: flow network G,C,s,t, and flow f „Remove“ f, to get the residual network Formally: Set C f (u,v)=C(u,v)-f(u,v) G with capacities C f is a new flow network Note: C f (u,v)>C(u,v) is possible

Residual Network Lemma: N=(G,C,s,t) flow network, f flow N f =(G,C f,s,t) the residual network f‘ a flow in N f f+f‘ defined by (f+f‘)(u,v)=f(u,v)+f‘(u,v) Then f+f‘ is a flow in N with value |f+f‘|=|f|+|f‘|

Proof: (f+f‘)(u,v)=f(u,v)+f‘(u,v) Statement about |f+f‘| trivial Have to check that f+f‘ is really a flow – Skew Symmetry: (f+f‘)(u,v)=f(u,v)+f‘(u,v) =-f(v,u)-f‘(v,u)=-(f+f‘)(v,u) – Capacity: (f+f‘)(u,v)=f(u,v)+f‘(u,v) · f(u,v)+C f (u,v) = f(u,v)+C(u,v)-f(u,v)=C(u,v) – Flow conservation:  v (f+f‘)(u,v)=  v f(u,v)+  v f‘(u,v) =0+0=0

Augmenting Paths Flow network N and flow f Find the residual network N f For a path p from s to t the residual capacity is C f (p)=min{C f (u,v): (u,v) on p} Search an augmenting path, – i.e. path s to t with C f (p)>0 Idea: remove edges with capacity 0, perform BFS from s until t is found

Augmenting Paths Let p be an augmenting path Set f p (u,v)= C f (p) if (u,v) on p -C f (p), if (v,u) on p 0 otherwise Claim: then f p is a flow in the residual network And f+f p is a flow with value |f|+|f p | in N Proof by checking flow conditions

Ford Fulkerson 1.Input: flow network N=(G,C,s,t) 2.Set f(u,v)=0 for all pairs u,v 3.While there is an augmenting path p in N f : 1.Compute C f (p) 2.For all edges u,v on p: 1.set f(u,v):=f(u,v)+C f (p) 2.set f(v,u):=-f(u,v) 4.Output f

Running time Computing augmenting paths takes time O(m+n) What is the number of iterations? Depending on the choice of paths (and the capacities) FF need not terminate at all! Running time can be  (|f| m) where f is the max flow and capacities are integers – For integer weights no more than O(|f|) iterations are needed (augmenting paths add flow 1 at least) – Example that  (|f|) iterations can happen

Running time Network where 2M iterations can happen:

Improving the running time Improvement, choose the augmenting paths with BFS Claim: – If in each iteration an augmenting path in N f is chosen by BFS then running time is O(nm 2 ) – Choosing paths by BFS means choosing augmenting paths with the smallest number of edges Proof: Later Edmonds-Karp algorithm

Correctness of Ford Fulkerson Tool: the Max-flow Min-cut Theorem This will imply that a flow is maximum iff there is no augmenting path Hence the output of Ford Fulkerson is correct The theorem is an example of duality/min- max theorems

Min Cuts s-t Min Cut problem: input is a flow network An s-t cut is a partition of V into L,R with s 2 L and t 2 R The capacity of the cut is C(L,R)=  u,v C(u,v), where u 2 L and v 2 R The output is an s-t cut of minimum capacity

Max-Flow Min-Cut Theorem Theorem – N=(G,C,s,t) flow network, f a flow – The following statements are equivalent: 1.f is a maximum flow 2.N f has no augmenting path 3.|f|=C(L,R) for some s-t cut L,R

Proof Lemma – Let f be a flow and L,R an s-t cut – Then f(L,R)=|f| Proof: f(L-{s},V)=0 by flow conservation f(L,R)=f(L,V)-f(L,L) [from earlier observation] =f(L,V) =f({s},V)+f(L-{s},V) =f({s},V) =|f|

Proof Lemma |f| · C(L,R) for every flow f and every s-t cut L,R Proof |f|= f(L,R) · C(L,R) Hence the maximum value of |f| is upper bounded by C(L,R) for any s-t cut L,R

Proof of the theorem 1 to 2: – Assume f is max but N f has an augmenting path p, so f+f p is larger, contradiction 2 to 3: – Assume N f has no augmenting path – |f| · C(L,R) by the Lemma – Construct a cut: L: vertices reachable from s in N f R=V-L – f(L,R)=|f| – All edges in G from L to R satisfy: f(u,v)=C(u,v), otherwise they would be edges in N f Hence |f|=f(L,R)=C(L,R) 3 to 1: – |f| · C(L,R). IF |f|=C(L,R), then f must be maximum flow

Correctness of Ford-Fulkerson This proves that Ford Fulkerson computes a maximum flow

Duality The value of related maximization and minimization problems coincides Similar example: Linear Programming Useful to prove bounds: – To show that there is no larger flow than f it is enough to point out a cut with small capacity

Running Time We assume that augmenting paths are found by BFS Then: – Number of iterations is at most O(mn) Ford-Fulkerson finds maximum flows in time O(m 2 n)

Number of iterations Lemma: – Let N be a flow network – For all v  s,t: The distance from s to v (number of edges) increases monotonically when changing N to a residual network

Proof Assume the distance  (s,v) decreases in an iteration f is the flow before the iteration, f‘ afterwards  (s,v) is the distance in N f ;  (s,v) in N f ‘ v has min.  (s,v) among all v with  (s,v)<  (s,v) (*) p: path s ! u ! v shortest path in N f ‘ –  (s,u) =  (s,v)-1 –  (s,u) ·  (s,u) (*) – (u,v) is no edge in N f Assume (u,v) 2 N f  (s,v) ·  (s,u)+1 ·  (s,u)+1 =  (s,v) contradiction

Proof (u,v) edge in N f‘ but no edge in N f In the iteration the flow from v to u is increased There is an augmenting path path in N f with edge (v,u) I.e., a shortest path from s to u with edge (v,u) at the end exists in N f Hence: –  (s,v) =  (s,u)-1 ·  (s,u)-1 =  (s,v)-2 But we assumed  (s,v)<  (s,v)

Number of iterations Theorem: – There are at most mn iterations Proof: – Edges in N f are critical, if the capacity of the augmenting path p is the capacity of (u,v) in N f – Critical edges are removed, i.e. are not in N f' – Every augmenting path has at least 1 critical edge – Claim: an edge can be critical at most n/2-1 times – Since at most 2m edges are used there can be at most nm iterations

Proof of the claim (u,v) critical in N f for the first time:  (s,v)=  (s,u)+1 (u,v) vanishes in the iteration (u,v) can only reappear if the flow from u to v is reduced Then (v,u) is on an augmenting path; f‘ the flow at this time  (s,u)=  (s,v)+1  (s,v) ·  (s,v) Hence:   (s,u)=  (s,v)+1  ¸  (s,v)+1  =  (s,u)+2 Distance s to u increases by 2, before (u,v) can be critical Distance is integer between 0 and n-1 (u,v) can be critical at most n/2-1 times.

Conclusion The Edmonds-Karp implementation of the Ford-Fulkerson approach computes maximum flows in time O(m 2 n)