Maximum flow: The preflow/push method of Goldberg and Tarjan (87)

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

Min Cost Flow: Polynomial Algorithms. Overview Recap: Min Cost Flow, Residual Network Potential and Reduced Cost Polynomial Algorithms Approach Capacity.
§3 Shortest Path Algorithms Given a digraph G = ( V, E ), and a cost function c( e ) for e  E( G ). The length of a path P from source to destination.
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.
Breadth-First Search of Graphs Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
MAXIMUM FLOW Max-Flow Min-Cut Theorem (Ford Fukerson’s Algorithm)
CSE 326: Data Structures Network Flow and APSP Ben Lerner Summer 2007.
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
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.
Chapter 7 Maximum Flows: Polynomial Algorithms
1 Efficient implementation of Dinic’s algorithm for maximum flow.
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)
Global Price Updates Help A.V Goldberg and R. Kennedy Advanced Algorithms Seminar Instructor: Prof. Haim Kaplan Presented by: Orit Nissan-Messing.
A New Approach to the Maximum-Flow Problem Andrew V. Goldberg, Robert E. Tarjan Presented by Andrew Guillory.
CSE 589 Part III The computer is useless It can only answer questions. -- Pablo Picasso.
1 Maximum flow: The preflow/push method of Goldberg and Tarjan (87)
1 Efficient implementation of Dinic’s algorithm for maximum flow.
Maximum flow Algorithms and Networks. A&N: Maximum flow2 Today Maximum flow problem Variants Applications Briefly: Ford-Fulkerson; min cut max flow theorem.
Lecture 8. Why do we need residual networks? Residual networks allow one to reverse flows if necessary. If we have taken a bad path then residual networks.
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.
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.
1 Binomial heaps, Fibonacci heaps, and applications.
Advanced Algorithms Piyush Kumar (Lecture 5: Preflow Push) Welcome to COT5405.
15.082J and 6.855J and ESD.78J October 19, 2010 Max Flows 3 Preflow-Push Algorithms.
1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf.
Maximum Flow Algorithms —— ACM 黄宇翔. 目录 Max-flow min-cut theorem 12 Augmenting path algorithms 3 Push-relabel maximum flow algorithm.
Flow Algorithms Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms Week 9, Lecture 2.
1 WEEK 11 Graphs III Network Flow Problems A Simple Maximum-Flow Algorithm Izmir University of Economics.
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.
Outline Standard 2-way minimum graph cut problem. Applications to problems in computer vision Classical algorithms from the theory literature A new algorithm.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
Iterative Improvement for Domain-Specific Problems Lecturer: Jing Liu Homepage:
1 Maximum Flows CONTENTS Introduction to Maximum Flows (Section 6.1) Introduction to Minimum Cuts (Section 6.1) Applications of Maximum Flows (Section.
Binomial heaps, Fibonacci heaps, and applications
Lectures on Network Flows
Algorithms and Networks Hans Bodlaender
Richard Anderson Lecture 23 Network Flow
Edmunds-Karp Algorithm: Choosing Good Augmenting Paths
James B. Orlin Presented by Tal Kaminker
Maximum flow: The preflow/push method of Goldberg and Tarjan (87)
Algorithms and Networks
Instructor: Shengyu Zhang
Efficient implementation of Dinic’s algorithm for maximum flow
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
3.4 Push-Relabel(Preflow-Push) Maximum Flow Alg.
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 23 Network Flow
(Push-relabel algorithms)
Richard Anderson Lecture 21 Network Flow
Algorithms (2IL15) – Lecture 7
EE5900 Advanced Embedded System For Smart Infrastructure
and 6.855J March 6, 2003 Maximum Flows 2
Min Global Cut Animation
Lecture 21 Network Flow, Part 1
and 6.855J The Goldberg-Tarjan Preflow Push Algorithm for the Maximum Flow Problem Obtain a network, and use the same network to illustrate the.
and 6.855J The Goldberg-Tarjan Preflow Push Algorithm for the Maximum Flow Problem Obtain a network, and use the same network to illustrate the.
Richard Anderson Lecture 22 Network Flow
Binomial heaps, Fibonacci heaps, and applications
Advanced Graph Homer Lee 2013/10/31.
Max Flows 3 Preflow-Push Algorithms
Class 11 Max Flows Obtain a network, and use the same network to illustrate the shortest path problem for communication networks, the max flow.
Presentation transcript:

Maximum flow: The preflow/push method of Goldberg and Tarjan (87)

Definitions G=(V,E) is a directed graph capacity c(v,w) for every v,w V: If (v,w)  E then c(v,w) = 0 Two distinguished vertices s and t. s 4 3 1 a b 3 3 2 c d 4 3 t

Definitions (cont) A flow is a function on the edges which satisfies the following requirements f(v,w) = -f(w,v) skew symmetry f(v,w)  c(v,w) For every v except s and t wf(v,w) = 0 The value of the flow |f| = wf(s,w) The maxflow problem is to find f with maximum value

Flows and s-t cuts Let (X,X’) be a cut such that s X, t X’. Flow is the same across any cut: f(X,X’) = f(v,w) = f(v,w) - f(v,w) = |f| - 0 = |f| v X, w  X’ v X, w  V v X, w  X so |f|  cap(X,X’) = c(v,w) The value of the maximum flow is smaller than the minimum capacity of a cut.

More definitions The residual capacity of a flow is a function r on the edges such that r(v,w) = c(v,w) - f(v,w) a 2, 1 d Interpretation: We can push r(v,w) more flow from v to w by increasing f(v,w) and decreasing f(w,v)

More definitions (cont) We define the residual graph R on V such that there is an arc from v to w with capacity r(v,w) for every v and w such that r(v,w) > 0 An augmenting path p  R is a path from s to t in R r(p) = min r(v,w) (v,w)  p We can increase the flow by r(p)

Example 1 3 3 4 1 3 3 1 1 3 1 3 1 2 2 1 2 2 1 2 1 3 4 1 3 3 3 The residual network A flow

Basic theorem (1) f is max flow <==> (2) There is no augmenting path in R <==> (3) |f| = cap(X,X’) for some X Proof. (3) ==> (1), (1) ==> (2) obvious To prove (2) ==>(3) let X be all vertices reachable from s in R. By assumption t  X. So (X,X’) is an s-t cut. Since there is no edge from X to X’ in R |f| = f(X,X’) = f(v,w) = c(v,w) = cap(X,X’)

Augmenting path methods Repeat the following step: Find an augmenting path in R, increase the flow, update R Stop when s and t are disconnected in R. Need to be careful about how you choose those augmenting paths ! The best algorithm in this family is Dinic’s algorithm, that can be implemented in O(nmlog(n)) time

But we’ll go for the preflow/push method

Distance labels Defined with respect to residual capacities d(t) = 0 d(v) ≤ d(w) + 1 if r(v,w) > 0

Example (distance labels) 1 3 3 4 1 3 3 1 1 3 1 3 1 2 2 1 2 2 1 2 1 3 4 1 3 3 3 The residual network A flow

Example (distance labels) 1 3 3 3 4 1 3 3 1 1 2 2 3 1 3 1 2 2 1 2 2 1 2 1 1 1 4 1 3 3 3 3 The residual network A flow

Example (distance labels) 1 3 3 3 4 1 3 3 1 1 2 2 3 1 3 1 2 2 1 2 2 1 2 1 1 2 4 1 3 3 3 3 The residual network A flow

Example (distance labels) 1 4 3 3 4 1 3 3 1 1 2 3 3 1 3 1 2 2 1 2 2 1 2 1 1 3 4 1 3 3 3 3 The residual network A flow

Distance labels – basic lemma Lemma: d(v) is a lower bound on the length of the shortest path from v to the sink Proof: Let the s.p. to the sink be: v v1 v2 t d(v) ≤ d(v1) + 1 ≤ d(v2) + 2 ..... ≤ d(t) + k = k

Preflow (definition) A preflow is a function on the edges which satisfies the following requirements f(v,w) = -f(w,v) skew symmetry f(v,w)  c(v,w) For every v, except s and t, vf(v,w) ≥ 0 Let e(w) = vf(v,w) be the excess at the node v (we’ll also have e(t) ≥ 0, and e(s) ≤ 0)

Example (preflow) 2 2 2 3 1 3 2 s t 3 2 1 Nodes with positive excess are called active. The preflow push algorithm will try to push flow from active nodes towards the sink, relying on d( ).

Initialization (preflow) 3 4 2 1 3 3 4 4 3 4 1 3 3 2 4 3

Initialization (distance labels) 6 3 3 4 4 3 4 3 4 1 1 3 3 3 3 2 2 4 3 4 3 Note: s must be disconnected from t when d(s) = n, and the labeling is valid…

Admissible arc in the residual graph v w d(v) = d(w) + 1

The preflow push algorithm While there is an active node { pick an active node v and push/relabel(v) } Push/relabel(v) { If there is an admissible arc (v,w) then { push  = min {e(v) , r(v,w)} flow from v to w } else { d(v) := min{d(w) + 1 | r(v,w) > 0} (relabel) }

Example (preflow-push) 2 4 1 1 4

4 4 2 4 1 4 1 1 4 1

4 4 2 4 1 4 1 1 4 1 relabel 4 2 1 4 1 4

4 4 2 1 4 1 4 1 1 4 1 push 4 2 1 1 4 1 4

2 4 2 1 2 4 1 4 1 1 4 1 4 2 1 push 1 4 1 4

relabel 1 4 2 1 2 4 1 1 4 1 1 4 2 4 2 1 1 4 1 4

1 4 2 5 2 4 1 1 4 1 1 4 2 push 4 2 5 1 4 1 4

3 2 5 2 4 1 1 4 1 1 4 2 2 5 3 1 1 4 1 4 relabel

3 2 5 2 4 1 1 4 1 1 4 1 2 2 5 3 1 1 4 1 4 push 1

3 2 5 2 4 1 1 4 1 2 1 4 1 2 5 3 1 1 4 1 2 1 2

Correctness Lemma 1: The source is reachable from every active vertex in the residual network Proof: Assume that’s not the case: v s S Which means that no flow enters S..

Correctness (cont) Corollary: There is an outgoing arc incident with every active vertex so assuming distance labels are valid, we can always either push or relabel an active node.

Correctness (cont) Lemma 1: Distance labels remain valid at all times Proof: By induction on the number of pushing and relabeling operations. For relabel this is clear by the definition of relabel For push: w v d(v) = d(w) + 1 so even if we add (w,v) to the residual network then it is still a valid labeling

Correctness (cont) Corollary: So we can push-relabel as long as there is an active vertex Lemma: When (and if) the algorithm stops the preflow is a maximum flow Proof: It is a flow since there is no active vertex. It is maximum since the sink is not reachable from the source in the residual network. (d(s) = n, and the labeling is valid)

Complexity analysis

Well, lets do another example first 2 4 2 2 2 1 4

4 2 4 2 2 6 2 2 1 4

relabel 4 2 4 2 2 6 2 2 1 4 2 4 2 2 6 2 1 4

push 4 2 1 4 2 2 6 2 2 1 push 4 2 1 4 2 2 6 2 1 4

4 2 2 1 4 2 2 2 6 2 2 1 relabel 4 2 1 4 2 2 6 2 1 4

4 2 2 1 4 2 2 2 2 6 2 2 push 1 4 2 1 4 2 2 2 6 2 1 4

relabel 4 2 2 1 4 2 2 2 2 2 6 2 2 1 4 2 1 4 2 2 2 6 2 1 4

4 2 2 3 4 2 2 2 2 2 6 2 2 push 1 4 2 3 4 2 2 2 6 2 1 4

4 2 2 3 4 2 2 2 2 6 2 2 1 4 2 3 4 2 2 2 6 2 1 4

4 2 2 7 4 2 2 2 2 6 6 2 2 1 4 Skipping some steps… 2 7 4 2 2 6 6 2 1 4

Complexity analysis Observation: d(v) increases when we relabel v ! Lemma: d(v) ≤ 2n-1 Proof: v v1 v2 s d(v) ≤ d(v1) + 1 ≤ d(v2) + 2 ..... ≤ d(s) + (n-1) = 2n-1

Complexity analysis (cont) Lemma: The # of relabelings is (2n-1)(n-2) < 2n2 Proof: At most 2n-1 per each node other than s and t

Complexity analysis (cont) Def: Call a push saturating if min{e(v), r(v,w)} = r(v,w) Lemma: The # of saturating pushes is at most 2nm Proof: Before another saturating push on (v,w), we must push from w to v. d(w) must increase by at least 2 Since d(w) ≤ 2n-1, this can happen at most n times

Nonsaturating pushes Lemma: The # of nonsaturating pushes is at most 4n2m Proof: Let Φ = Σv active d(v) Decreases (by at least one) by every nonsaturating push Increases by at most 2n-1 by a saturating push : total increase (2n-1)2nm Increases by each relabeling: total increase < (2n-1)(n-2)

Implementation Maintain a list of active nodes, so finding an active node is easy Given an active node v, we need to decide if there is an admissible arc (v,w) to push on ? v All edges, not only those in R current edge

Current edge v current edge If the current edge (v,w) is admissible, push on it (updating the list of active vertices) Otherwise, advance the current edge pointer if you are on the last edge, relabel v and set the current edge to be the first one.

Is this implementation correct? Lemma: When we relabel v there is no admissible arc (v,w) Proof: After we scanned (v,w) either (v,w) dropped off the residual network or d(v) ≤ d(w) If d(v) ≤ d(w) then this must be the case now since v has not been relabeled. If (v,w) got back on the list of v since it was scanned then when that happened d(w) = d(v) + 1  d(v) ≤ d(w) and this must be the case now

Analysis Lemma: The total time spent at v between two relabelings of v is Δv plus O(1) per push out of v Summary: Since we relabel v at most (2n-1) times we get that the total work at v is O(nΔv) + O(1) per push out of v. Summing over all vertices we get that the total time is O(nm) + #of pushes  O(n2m)

Reducing the # of nonsaturating pushes Maintain the list of active vertices as a FIFO queue (Q) Discharge the first vertex of the queue: Discharge(v) { While v is active and hasn’t been relabeled then push/relabel(v). (If the loop stops because v is relabeled then add v to the end of Q) }

Example (FIFO order) 2 4 2 2 2 1 4

4 2 4 2 2 6 2 2 1 4

relabel 4 4 2 4 z 2 2 2 6 2 2 1 y w x 4 u v Q: z y 2 4 2 2 6 2 1 4

4 4 2 1 4 z 2 2 2 6 2 2 1 y w x 4 relabel u v Q: y z 2 1 4 2 2 6 2 1 4

4 push 4 2 1 4 z 2 2 2 2 6 push 2 2 1 y w x 4 u v Q: z y 2 1 4 2 2 2 6 2 1 4

4 2 2 1 4 z 2 2 2 2 2 6 2 2 push 1 y w x 4 2 u v Q: y u 2 1 4 2 2 2 6 2 1 4

2 4 2 2 1 4 z 2 2 2 2 2 6 2 2 1 y w x 4 2 u v Q: u z relabel 2 1 4 2 2 2 6 2 1 4

relabel 2 4 2 2 1 4 z 2 2 2 2 2 6 2 2 1 y w x 4 2 1 u v Q: z u 2 1 4 2 2 2 6 2 1 4 1

4 2 2 3 4 z 2 2 2 2 2 6 2 2 1 y w x 4 1 u v Q: u z 2 3 4 2 2 2 6 2 1 4

Passes Pass 1: Until you finish discharging all vertices initially in Q Pass i: Until you finish discharging all vertices added to Q in pass (i-1)

relabel 4 4 2 4 z 2 2 2 6 2 2 1 y w x 4 u v Q: z y 2 4 2 2 6 2 1 4

4 4 2 1 4 z 2 2 2 6 2 2 1 y w x 4 relabel u v Q: y z 2 1 4 2 2 6 2 1 4

End of pass 1 4 4 2 1 4 z 2 2 2 2 6 2 2 1 y w x 4 u v Q: z y 2 1 4 2 2 2 6 2 1 4

4 push 4 2 1 4 z 2 2 2 2 6 push 2 2 1 y w x 4 u v Q: z y 2 1 4 2 2 2 6 2 1 4

4 2 2 1 4 z 2 2 2 2 2 6 2 2 push 1 y w x 4 2 u v Q: y u 2 1 4 2 2 2 6 2 1 4

End of pass 2 2 4 2 2 1 4 z 2 2 2 2 2 6 2 2 1 y w x 4 2 u v Q: u z 2 1 4 2 2 2 6 2 1 4

2 4 2 2 1 4 z 2 2 2 2 2 6 2 2 1 y w x 4 2 u v Q: u z relabel 2 1 4 2 2 2 6 2 1 4

relabel 2 4 2 2 1 4 z 2 2 2 2 2 6 2 2 1 y w x 4 2 1 u v Q: z u 2 1 4 2 2 2 6 2 1 4 1

End of pass 3 4 2 2 3 4 z 2 2 2 2 2 6 2 2 1 y w x 4 1 u v Q: u z 2 3 4 2 2 2 6 2 1 4

Analysis Note that we still have the O(n2m) bound How many passes are there ? Let Φ = maxactive vd(v) 1) If the algorithm does not relabel during a pass then Φ decreases by at least 1 (each active node at the beginning of a pass moved its excess to a vertex with lower label) 2) If we relabel then Φ may increase by at most the maximum increase of a distance label There are at most O(n2) passes of the second kind. These passes increase Φ by at most O(n2)  There are at most O(n2) passes of the first kind

Analysis (Cont) So we have O(n2) passes In each pass we have at most one nonsaturating push per vertex  O(n3) nonsaturating pushes  O(n3) total running time

A faster implementation Maintain a (dynamic) forest of some of the admissible current edges

Reminder: Admissible arc in the residual graph v w d(v) = d(w) + 1

A faster implementation Maintain a (dynamic) forest of some of the admissible current edges

A faster implementation Maintain a (dynamic) forest of some of the admissible current edges Active guys are among the roots

At a high level the algorithm is almost the same While there is an active node in Q { Let v be the first in Q discharge(v) } discharge(v) { While v is active and hasn’t been relabeled then Treepush/relabel(v). (If the loop stops because v is relabeled then add v to the end of Q) }

A faster implementation Q: v…..  discharge(v)  Treepush/relabel(v) v w

Case 1: (v,w) is admissible link(v,w,rf(v,w)), (v,c) = findmin(v), addcost(v,-c) Let (u,c) = findmin(v) If c=0 cut(u) and repeat If e(v) > 0 and v is not a root then repeat

Case 2: (v,w) is not admissible If (v,w) is not the last edge then advance the current edge If (v,w) is the last edge we relabel v and perform cut(u) for every child u of v

Analysis O(1) work + tree operations in Treepush/relabel + O(1) work + tree operations per cut How many cuts do we do ? O(mn) How many times do we call Treepush/relabel ? O(mn) + # of times we add a vertex to Q

Analysis (Cont) How many times a vertex can become active ? We can charge each new active vertex to a link or a cut  A vertex becomes active O(mn) times Summary: we do O(mn) dynamic tree operations We’ll see how to do those in O(log n) each so we get running time of O(mnlog n)

Can we improve on that ? Notice that we have not really used the fact that Q is a queue, any list would do !

Idea: Don’t get the trees to grow too large Case 1: (v,w) is admissible v We won’t do the link if a too large tree is created (say larger than k) w link(v,w,rf(v,w)), (v,c) = findmin(v), addcost(v,-c) Let (u,c) = findmin(v) If c=0 cut(u) and repeat If e(v) > 0 and v is not a root then repeat

If we are about to create a tree with at least k vertices Push from v to w min{e(v),rf(v,w)} flow (w,c) = findmin(w), addcost(w,-c) Let (u,c) = findmin(w) If c=0 cut(u) and repeat If e(w) > 0 and w is not a root then repeat

What collapses in our analysis ? Note r may become active and we cannot charge it to a link or a cut ! v w r So we cannot say that the # of insertions into Q is O(mn)

How do we recover ? Either Tv or Tr is large ≥ k/2 May assume that the push from v is not saturating..(there are only O(nm) saturating ones) There cannot be another such push involving v as the pushing root and r as the “becoming active” node in a phase Either Tv or Tr is large ≥ k/2

Tv Tr v w r Charge it to the large tree if it existed at the beginning of the phase Charge it to the link or cut creating it if it did not exist at the beginning of the phase.

Each link is charged once, a cut is charged twice O(mn) such charges over all phases. At the beginning of a phase we have O(n/k) large trees, each charged once  O(n3/k) So we get O(mn + n3/k) dynamic tree operations each costs O(log k) For k=n2/m we get O(mnlog(n2/m))