Maximum flow Algorithms and Networks. A&N: Maximum flow2 Today Maximum flow problem Variants Applications Briefly: Ford-Fulkerson; min cut max flow theorem.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Max Flow Problem Given network N=(V,A), two nodes s,t of V, and capacities on the arcs: uij is the capacity on arc (i,j). Find non-negative flow fij for.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
Chapter 6 Maximum Flow Problems Flows and Cuts Augmenting Path Algorithm.
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.
Chapter 10: Iterative Improvement The Maximum Flow Problem The Design and Analysis of Algorithms.
1 Maximum Flow 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 
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 Maximum Flow Networks Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘capacity’ u ij. Goal: Determine the maximum amount.
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
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.
A New Approach to the Maximum-Flow Problem Andrew V. Goldberg, Robert E. Tarjan Presented by Andrew Guillory.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 4 Tuesday, 10/2/01 Graph Algorithms: Part 2 Network.
Flows sourcesink s t Flows sourcesink edge-weights = capacities.
1 Maximum flow: The preflow/push method of Goldberg and Tarjan (87)
3/3/ Alperovich Alexander. Motivation  Find a maximal flow over a directed graph  Source and sink vertices are given 3/3/
A New Approach to the Maximum-Flow Problem Andrew V. Goldberg, Robert E. Tarjan Presented by Andrew Guillory.
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.
1 The Min Cost Flow Problem. 2 The Min Cost Flow problem We want to talk about multi-source, multi-sink flows than just “flows from s to t”. We want to.
MAX FLOW CS302, Spring 2013 David Kauchak. Admin.
Advanced Algorithms Piyush Kumar (Lecture 5: Preflow Push) Welcome to COT5405.
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.
Maximum Flow. p2. Maximum Flow A flow network G=(V, E) is a DIRECTED graph where each has a nonnegative capacity u.
Max Flow – Min Cut Problem. Directed Graph Applications Shortest Path Problem (Shortest path from one point to another) Max Flow problems (Maximum material.
Flow Algorithms Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms Week 9, Lecture 2.
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.
Chapter 7 April 28 Network Flow.
15.082J and 6.855J March 4, 2003 Introduction to Maximum Flows.
and 6.855J March 6, 2003 Maximum Flows 2. 2 Network Reliability u Communication Network u What is the maximum number of arc disjoint paths from.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
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)
1 Maximum Flows CONTENTS Introduction to Maximum Flows (Section 6.1) Introduction to Minimum Cuts (Section 6.1) Applications of Maximum Flows (Section.
The Maximum Network Flow Problem
Minimum Cost Flow Algorithms and Networks. Algorithms and Networks: Minimum Cost Flow2 This lecture The minimum cost flow problem: statement and applications.
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
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.
Lectures on Network Flows
Algorithms and Networks Hans Bodlaender
Algorithms and Networks
Maximum flow: The preflow/push method of Goldberg and Tarjan (87)
Algorithms and Networks
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
Network Flow and Connectivity in Wireless Sensor Networks
3.4 Push-Relabel(Preflow-Push) Maximum Flow Alg.
(Push-relabel algorithms)
Richard Anderson Lecture 21 Network Flow
Algorithms (2IL15) – Lecture 7
and 6.855J March 6, 2003 Maximum Flows 2
Algorithms and Networks
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
Lecture 21 Network Flow, Part 1
Maximum flow: The preflow/push method of Goldberg and Tarjan (87)
Piyush Kumar (Lecture 3: Preflow Push)
Max Flows 3 Preflow-Push Algorithms
Presentation transcript:

Maximum flow Algorithms and Networks

A&N: Maximum flow2 Today Maximum flow problem Variants Applications Briefly: Ford-Fulkerson; min cut max flow theorem Preflow push algorithm Lift to front algorithm

1 The problem

A&N: Maximum flow4 Problem Directed graph G=(V,E) Source s  V, sink t  V. Capacity c(e)  Z + for each e. Flow: function f: E  N such that –For all e: f(e)  c(e) –For all v, except s and t: flow into v equals flow out of v Flow value: flow out of s Question: find flow from s to t with maximum value Variants in notation, e.g.: Write f(u,v) = -f(v,u) Variants in notation, e.g.: Write f(u,v) = -f(v,u)

A&N: Maximum flow5 Maximum flow Ford-Fulkerson method –Possibly (not likely) exponential time –Edmonds-Karp version: O(nm 2 ): augment over shortest path from s to t Max Flow Min Cut Theorem Improved algorithms: Preflow push; scaling Applications Variants of the maximum flow problem Algoritmiek

1 Variants: Multiple sources and sinks Lower bounds

A&N: Maximum flow7 Variant Multiple sources, multiple sinks Possible maximum flow out of certain sources or into some sinks Models logistic questions G s1s1 sksk t1t1 trtr s t

A&N: Maximum flow8 Lower bounds on flow Edges with minimum and maximum capacity –For all e: l(e)  f(e)  c(e) l(e) c(e)

A&N: Maximum flow9 Flow with Lower Bounds Look for maximum flow with for each e: l(e)  f(e)  c(e) Problem solved in two phases –First, find admissible flow –Then, augment it to a maximum flow Admissible flow: any flow f, with –Flow conservation if v  {s,t}, flow into v equals flow out of v –Lower and upper capacity constraints fulfilled: for each e: l(e)  f(e)  c(e) Transshipment

A&N: Maximum flow10 Finding admissible flow 1 First, we transform the question to: find an admissible circulation Finding admissible circulation is transformed to: finding maximum flow in network with new source and new sink Translated back

A&N: Maximum flow11 Circulations Given: digraph G, lower bounds l, upper capacity bounds d A circulation fulfills: –For all v: flow into v equals flow out of v –For all (u,v): l(u,v)  f(u,v)  c(u,v) Existence of circulation: first step for finding admissible flow

A&N: Maximum flow12 Circulation vs. Flow Model flow network with circulation network: add an arc (t,s) with large capacity (e.g., sum over all c(s,v) ), and ask for a circulation with f(t,s) as large as possible st st f (t,s) = value( f ) G G

A&N: Maximum flow13 Finding admissible flow Find admissible circulation in network with arc (t,s) –Construction: see previous sheet Remove the arc (t,s) and we have an admissible flow

A&N: Maximum flow14 Finding admissible circulation Is transformed to: finding a maximum flow in a new network –New source –New sink –Each arc is replaced by three arcs

A&N: Maximum flow15 Finding admissible circulation S’ T’ ab 0 c(e)-l(e) ab l(e) c(e) l(e) Do this for each edge New source New sink

A&N: Maximum flow16 Finding admissible flow/circulation Find maximum flow from S’ to T’ If all edges from S’ (and hence all edges to T’) use full capacity, we have admissible flow: –f’(u,v) = f(u,v) + l(u,v) for all (u,v) in G

A&N: Maximum flow17 From admissible flow to maximum flow Take admissible flow f (in original G) Compute a maximum flow f’ from s to t in G f –Here c f (u,v) = c(u,v) – f(u,v) – l(u,v) f + f’ is a maximum flow from s to t that fulfills upper and lower capacity constraints Any flow algorithm can be used

3 Applications

A&N: Maximum flow19 Applications Logistics (transportation of goods) Matching Matrix rounding problem …

A&N: Maximum flow20 Matrix rounding problem p * q matrix of real numbers D = {d ij }, with row sums a i and column sums b j. Consistent rounding: round every d ij up or down to integer, such that every row sum and column sum equals rounded sum of original matrix Can be modeled as flow problem with lower and upper bounds on flow through edges

A&N: Maximum flow21 t Row 1 Row p Col 1 Col q [ 16,17] Row sum rounded down, Sum rounded up Column sum rounded down, Sum rounded up [  b ij ,  b ij  s

4 Reminder: Ford-Fulkerson and the min-cut max flow theorem

A&N: Maximum flow23 Ford-Fulkerson Residual network G f Start with 0 flow Repeat –Compute residual network –Find path P from s to t in residual network –Augment flow across P Until no such path P exists

A&N: Maximum flow24 Max flow min cut theorem s-t-cut: partition vertices in sets S, T such that s in S, t in T. Look to edges (v,w) with v in S, w in T. Capacity of cut: sum of capacities of edges from S to T Flow across cut Theorem: minimum capacity of s-t-cut equals maximum flow from s to t.

5 The preflow push algorithm

A&N: Maximum flow26 Preflow push Simple implementation: O(n 2 m) Better implementation: O(n 3 ) Algorithm maintains preflow: some flow out of s which doesn’t reach t Vertices have height Flow is pushed to lower vertex Vertices sometimes are lifted

A&N: Maximum flow27 Preflow Function f: V * V  R –Skew symmetry: f(u,v) = - f(v,u) –Capacity constraints: f(u,v)  c(u,v) –Notation: f(V,u) –For all u, except s: f(V,u)  0 (excess flow) –u is overflowing when f(V,u) > 0. –Maintain: e(u) = f(V,u).

A&N: Maximum flow28 Height function h: V  N: –h(s) = n –h(t) = 0 –For all (u,v)  E f (residual network): h(u)  h(v)+1

A&N: Maximum flow29 Initialize Set height function h –h(s) = n –h(t) = 0 –h(v) = 0 for all v except s for each edge (s,u) do –f(s,u) = c(s,u); f(u,s) = – c(s,u) –e[u] = c(s,u); Do not change Initial preflow

A&N: Maximum flow30 Basic operation 1: Push Suppose e(u) > 0, c f (u,v)>0, and h[u]= h[v]+1 Push as much flow across (u,v) as possible r = min {e[u], c f (u,v)} f(u,v) = f(u,v) + r; f(v,u) = – f(u,v); e[u] = e[u] – r; e[v] = e[v] + r.

A&N: Maximum flow31 Basic operation 2: Lift When no push can be done from overflowing vertex (except s,t) Suppose e[u]>0, and for all (u,v)  E f : h[u]  h[v], u  s, u  t Set h[u] = 1 + min {h[v] | (u,v)  E f }

A&N: Maximum flow32 Preflow push algorithm Initialize while push or lift operation possible do –Select an applicable push or lift operation and perform it To do: correctness proof and time analysis

A&N: Maximum flow33 Lemmas / Invariants If there is an overflowing vertex (except t), then a lift or push operation is possible The height of a vertex never decreases When a lift operation is done, the height increases by at least one. h remains a height function during the algorithm

A&N: Maximum flow34 Another invariant and the correctness There is no path in G f from s to t –Proof: the height drops by at most one across each of the at most n-1 edges of such a path When the algorithm terminates, the preflow is a maximum flow from s to t –f is a flow, as no vertex except t has excess –As G f has no path from s to t, f is a maximum flow

A&N: Maximum flow35 Time analysis 1: Lemma If u overflows then there is a simple path from u to s in G f Intuition: flow must arrive from s to u: reverse of such flow gives the path Formal proof skipped

A&N: Maximum flow36 Number of lifts For all u: h[u] < 2n –h[s] remains n. When vertex is lifted, it has excess, hence path to s, with at most n – 1 edges, each allowing a step in height of at most one up. Each vertex is lifted less than 2n times Number of lift operations is less than 2n 2

A&N: Maximum flow37 Counting pushes Saturating pushes and not saturating pushes –Saturating: sends c f (u,v) across (u,v) –Non-saturating: sends e[u] < c f (u,v) Number of saturating pushes –After saturating push across (u,v), edge (u,v) disappears from G f. –Before next push across (u,v), it must be created by push across (v,u) –Push across (v,u) means that a lift of v must happen –At most 2n lifts per vertex: O(n) sat. pushes across edge –O(nm) saturating pushes

A&N: Maximum flow38 Non-saturating pushes Look at Initially  = 0.  increases by lifts in total at most 2n 2  increases by saturating pushes at most by 2n per push, in total O(n 2 m)  decreases at least one by a non-saturating push across (u,v) –After push, u does not overflow –v may overflow after push –h(u) > h(v) At most O(n 2 m) pushes

A&N: Maximum flow39 Algorithm Implement –O(n) per lift operation –O(1) per push O(n 2 m) time

6 Preflow-push fastened: The lift-to-front algorithm

A&N: Maximum flow41 Lift-to-front algorithm Variant of preflow push using O(n 3 ) time Vertices are discharged: –Push from edges while possible –If still excess flow, lift, and repeat until no excess flow Order in which vertices are discharge: –list, –discharged vertex placed at top of list –Go from left to right through list, until end, then start anew

A&N: Maximum flow42 Definition and Lemma Edge (u,v) is admissible –c f (u,v) > 0, i.e., (u,v)  E f –h(u) = h(v)+1 The network formed by the admissible edges is acyclic. –If there is a cycle, we get a contradiction by looking at the heights If (u,v) is admissible and e[u] > 0, we can do a push across it. Such a push does not create an admissible edge, but (u,v) can become not admissible.

A&N: Maximum flow43 Discharge procedure Vertices have adjacency list N[u]. Pointer current[u] gives spot in adjacency list. Discharge(u) –While e[u] > 0 do v = current[u]; if v = NIL then {Lift(u); current[u] = head(N[u]);} elseif c f (u,v) > 0 and h[u] = h[v]+1 then Push(u,v); else current[u] = next-neighbor[v];

A&N: Maximum flow44 Discharge indeed discharges If u is overflowing, then we can do either a lift to u, or a push out of u Pushes and Lifts are done when Preflow push algorithm conditions are met.

A&N: Maximum flow45 Lift-to-front algorithm Maintain linked list L of all vertices except s, t. Lift-to-front(G,s,t) –Initialize preflow and L –for all v do current[v] = head[N(v)]; –u is head of L –while u not NIL do oldheight = h[u]; Discharge(u); if h[u] > oldheight then move u to front of list L u = next[u];

A&N: Maximum flow46 Remarks Note how we go through L. Often we start again at almost the start of L… We end when the entire list is done. For correctness: why do we know that no vertex has excess when we are at the end of L?

A&N: Maximum flow47 A definition: Topological sort A directed acyclic graph is a directed graph without cycles. It has a topological sort: –An ordering of the vertices  : V  {1, 2, …, n} (bijective function), such that for all edges (v,w)  E:  (v) <  (w)

A&N: Maximum flow48 L is a topological sort of the network of admissible edges If (u,v) is an admissible edge, then u is before v in the list L. –Initially true: no admissible edges –A push does not create admissible edges –After a lift of u, we place u at the start of L Edges (u,v) will be properly ordered Edges (v,u) will be destroyed

A&N: Maximum flow49 Lift-to-front algorithm correctly computes a flow The algorithm maintains a preflow. Invariant of the algorithm: all vertices before the vertex u in consideration have no excess flow. –Initially true. –Remains true when u is put at start of L. –Any push pushes flow towards the end of L. L is topological sort of network of admissible edges. When algorithm terminates, no vertex in L has excess flow.

A&N: Maximum flow50 Time analysis - I O(n 2 ) lift operations. (As in preflow push.) O(nm) saturating pushes. Phase of algorithm: steps between two times that a vertex is placed at start of L, (and before first such and last such event.) O(n 2 ) phases; each handling O(n) vertices. All work except discharges: O(n 3 ).

A&N: Maximum flow51 Time of discharging Lifts in discharging: O(n) each, O(n 3 ) total Going to next vertex in adjacency list –O(degree(u)) work between two lifts of u –O(nm) in total Saturating pushes: O(nm) Non-saturating pushes: only once per discharge, so O(n 3 ) in total. Conclusion: O(n 3 ) time for the Lift to front algorithm Conclusion: O(n 3 ) time for the Lift to front algorithm

7 Conclusions

A&N: Maximum flow53 Many other flow algorithms Push-relabel (variant of preflow push) O(nm log (n 2 /m)) Scaling (exercise)

A&N: Maximum flow54 A useful theorem Let f be a circulation. Then f is a nonnegative linear combination of cycles in G. –Proof. Ignore lower bounds. Find a cycle c, with minimum flow on c r, and use induction with f – r * c. If f is integer, `integer scalared’ linear combination. Corollary: a flow is the linear combination of cycles and paths from s to t. –Look at the circulation by adding an edge from t to s and giving it flow value(f).

A&N: Maximum flow55 Next Minimum cost flow