Maximum flow: The preflowpush method of Goldberg and Tarjan 87 PowerPoint PPT Presentation

presentation player overlay
1 / 124
About This Presentation
Transcript and Presenter's Notes

Title: Maximum flow: The preflowpush method of Goldberg and Tarjan 87


1
Maximum flow The preflow/push method of Goldberg
and Tarjan (87)
2
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
3
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
4
Flows and s-t cuts
Let (X,X) be a cut such that s ?X, t ?X.
s
t
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 ? X
v ?X, w ? V
so
f ? cap(X,X) ?c(v,w)
The value of the maximum flow is smaller than the
minimum capacity of a cut.
5
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)
6
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) gt 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)
7
Example
1
3
4
1
3
3
3
1
1
3
3
1
1
2
2
1
1
2
2
2
1
3
3
3
3
4
1
The residual network
A flow
8
Basic theorem
(1) f is max flow ltgt (2) There is no
augmenting path in R ltgt (3) f cap(X,X) for
some X
Proof. (3) gt (1), (1) gt (2) obvious To prove
(2) gt(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)
9
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 Dinics
algorithm, that can be implemented in O(nmlog(n))
time
10
But well go for the preflow/push method
11
Distance labels
  • Defined with respect to residual capacities
  • d(t) 0
  • d(v) d(w) 1 if r(v,w) gt 0

12
Example (distance labels)
1
3
4
1
3
3
3
1
1
3
3
1
1
2
2
1
1
2
2
2
1
3
3
3
3
4
1
The residual network
A flow
13
Example (distance labels)
1
3
3
4
1
3
3
3
1
1
2
2
3
3
1
1
2
2
1
1
2
2
2
1
1
1
3
3
3
3
4
1
0
The residual network
A flow
14
Example (distance labels)
1
3
3
4
1
3
3
3
1
1
2
2
3
3
1
1
2
2
1
1
2
2
2
1
2
1
3
3
3
3
4
1
0
The residual network
A flow
15
Example (distance labels)
1
4
3
4
1
3
3
3
1
1
3
2
3
3
1
1
2
2
1
1
2
2
2
1
3
1
3
3
3
3
4
1
0
The residual network
A flow
16
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
v2
v1
t
d(v) d(v1) 1 d(v2) 2 ..... d(t) k k
17
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
(well also have e(t) 0, and e(s) 0)
18
Example (preflow)
2
0
2
2
3
1
3
2
s
t
0
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(
).
19
Initialization (preflow)
3
4
4
3
1
0
3
3
0
0
2
0
3
0
4
0
20
Initialization (distance labels)
6
3
4
4
3
3
4
1
1
0
0
3
3
0
0
3
3
2
0
2
0
0
3
0
3
4
0
4
0
Note s must be disconnected from t when d(s)
n, and the labeling is valid
21
Admissible arc in the residual graph
v
w
d(v) d(w) 1
22
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) mind(w) 1
r(v,w) gt 0 (relabel)
23
Example (preflow-push)
2
4
1
1
4
24
4
2
4
0
4
1
0
4
1
4
1
0
1
25
4
2
4
0
4
1
0
4
1
4
1
0
1
2
4
0
1
0
4
4
1
0
26
4
2
4
1
4
1
0
4
1
4
1
0
1
2
4
1
1
0
4
4
1
0
27
2
2
4
1
2
4
1
0
4
1
4
1
0
1
2
4
1
1
0
4
4
1
0
28
1
2
4
1
2
4
1
1
0
4
1
4
1
0
2
2
4
1
1
0
4
4
1
0
29
1
2
4
5
2
4
1
1
0
4
1
4
1
0
2
2
4
5
1
0
4
4
1
0
30
0
2
3
5
2
4
1
1
0
4
1
4
1
0
2
2
5
3
1
1
0
4
4
1
0
31
0
2
3
5
2
4
1
1
0
4
1
4
1
1
2
2
5
3
1
1
0
4
4
1
1
32
0
2
3
5
2
4
1
1
0
4
1
2
4
1
1
0
2
5
3
1
1
0
4
2
1
1
2
33
(No Transcript)
34
(No Transcript)
35
(No Transcript)
36
(No Transcript)
37
(No Transcript)
38
(No Transcript)
39
(No Transcript)
40
(No Transcript)
41
(No Transcript)
42
(No Transcript)
43
(No Transcript)
44
(No Transcript)
45
(No Transcript)
46
(No Transcript)
47
(No Transcript)
48
(No Transcript)
49
(No Transcript)
50
(No Transcript)
51
(No Transcript)
52
(No Transcript)
53
(No Transcript)
54
(No Transcript)
55
(No Transcript)
56
(No Transcript)
57
(No Transcript)
58
Correctness
Lemma 1 The source is reachable from every
active vertex in the residual network
Proof
Assume thats not the case
Which means that no flow enters S..
59
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.
60
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
61
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)
62
Complexity analysis
63
Another example
64
(No Transcript)
65
(No Transcript)
66
(No Transcript)
67
(No Transcript)
68
(No Transcript)
69
(No Transcript)
70
(No Transcript)
71
(No Transcript)
72
(No Transcript)
73
(No Transcript)
74
(No Transcript)
75
(No Transcript)
76
(No Transcript)
77
(No Transcript)
78
(No Transcript)
79
(No Transcript)
80
(No Transcript)
81
(No Transcript)
82
(No Transcript)
83
(No Transcript)
84
(No Transcript)
85
(No Transcript)
86
(No Transcript)
87
(No Transcript)
88
(No Transcript)
89
(No Transcript)
90
(No Transcript)
91
(No Transcript)
92
(No Transcript)
93
(No Transcript)
94
(No Transcript)
95
(No Transcript)
96
(No Transcript)
97
(No Transcript)
98
(No Transcript)
99
(No Transcript)
100
(No Transcript)
101
(No Transcript)
102
(No Transcript)
103
(No Transcript)
104
(No Transcript)
105
(No Transcript)
106
(No Transcript)
107
(No Transcript)
108
(No Transcript)
109
(No Transcript)
110
(No Transcript)
111
(No Transcript)
112
(No Transcript)
113
(No Transcript)
114
(No Transcript)
115
(No Transcript)
116
(No Transcript)
117
Well, lets do another example first
2
4
2
2
1
2
4
118
2
4
0
4
2
2
0
0
6
1
2
2
4
0
0
119
2
4
0
4
2
2
0
0
6
1
2
2
4
0
0
2
0
4
2
2
0
0
6
1
2
4
0
0
120
2
4
1
4
2
2
0
0
6
1
2
2
4
0
0
2
1
4
2
2
0
0
6
1
2
4
0
0
121
2
4
2
1
4
2
2
2
0
0
6
1
2
2
4
0
0
2
1
4
2
2
0
0
6
1
2
4
0
0
122
2
4
2
1
4
2
2
2
0
2
6
1
2
2
4
0
0
2
1
4
2
2
0
2
6
1
2
4
0
0
123
2
4
2
1
4
2
2
2
2
0
2
6
1
2
2
4
0
0
2
1
4
2
2
0
2
6
1
2
4
0
0
124
2
4
2
3
4
2
2
2
2
0
2
6
1
2
2
4
0
0
2
3
4
2
2
0
2
6
1
2
4
0
0
125
2
4
2
3
4
0
2
2
2
0
2
6
1
2
2
4
0
0
2
3
4
2
2
0
2
6
1
2
4
0
0
126
2
4
2
7
4
2
2
2
2
0
6
6
1
2
2
4
0
0
Skipping some steps
2
7
4
2
2
0
6
6
1
2
4
0
0
127
Complexity analysis
Observation d(v) increases when we relabel v !
Lemma d(v) 2n-1
Proof
d(v) d(v1) 1 d(v2) 2 ..... d(s) (n-1)
2n-1
128
Complexity analysis (cont)
Lemma The of relabelings is (2n-1)(n-2) lt 2n2
Proof
At most 2n-1 per each node other than s and t
129
Complexity analysis (cont)
Def Call a push saturating if mine(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

130
Nonsaturating pushes
Lemma The of nonsaturating pushes is at most
4n2m
Proof Let F Sv 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 lt
    (2n-1)(n-2)

131
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
132
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.
133
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
134
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)
135
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 hasnt
been relabeled then push/relabel(v). (If the
loop stops because v is relabeled then add v to
the end of Q)
136
Example (FIFO order)
2
4
2
2
1
2
4
137
2
4
0
4
2
2
0
0
6
1
2
2
4
0
0
138
4
2
4
0
4
z
2
2
2
0
0
6
1
2
2
y
w
x
4
0
0
u
v
Q z y
2
0
4
2
2
0
0
6
1
2
4
0
0
139
4
2
4
1
4
z
2
2
2
0
0
6
1
2
2
y
w
x
4
0
0
u
v
Q y z
2
1
4
2
2
0
0
6
1
2
4
0
0
140
4
2
4
1
4
z
2
2
2
0
2
6
1
2
2
y
w
x
4
0
0
u
v
Q z y
2
1
4
2
2
0
2
6
1
2
4
0
0
141
2
4
2
1
4
z
2
2
2
2
0
2
6
1
2
2
y
w
x
4
2
0
0
u
v
Q y u
2
1
4
2
2
0
2
6
1
2
4
0
0
142
2
2
4
2
1
4
z
2
2
2
2
0
2
6
1
2
2
y
w
x
4
2
0
0
u
v
Q u z
2
1
4
2
2
0
2
6
1
2
4
0
0
143
2
2
4
2
1
4
z
2
2
2
2
0
2
6
1
2
2
y
w
x
4
2
0
1
u
v
Q z u
2
1
4
2
2
0
2
6
1
2
4
0
1
144
2
4
2
3
4
z
2
2
2
2
0
2
6
1
2
2
y
w
x
4
0
1
u
v
Q u z
2
3
4
2
2
0
2
6
1
2
4
0
0
145
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)
146
4
2
4
0
4
z
2
2
2
0
0
6
1
2
2
y
w
x
4
0
0
u
v
Q z y
2
0
4
2
2
0
0
6
1
2
4
0
0
147
4
2
4
1
4
z
2
2
2
0
0
6
1
2
2
y
w
x
4
0
0
u
v
Q y z
2
1
4
2
2
0
0
6
1
2
4
0
0
148
4
End of pass 1
2
4
1
4
z
2
2
2
0
2
6
1
2
2
y
w
x
4
0
0
u
v
Q z y
2
1
4
2
2
0
2
6
1
2
4
0
0
149
4
2
4
1
4
z
2
2
2
0
2
6
1
2
2
y
w
x
4
0
0
u
v
Q z y
2
1
4
2
2
0
2
6
1
2
4
0
0
150
2
4
2
1
4
z
2
2
2
2
0
2
6
1
2
2
y
w
x
4
2
0
0
u
v
Q y u
2
1
4
2
2
0
2
6
1
2
4
0
0
151
2
End of pass 2
2
4
2
1
4
z
2
2
2
2
0
2
6
1
2
2
y
w
x
4
2
0
0
u
v
Q u z
2
1
4
2
2
0
2
6
1
2
4
0
0
152
2
2
4
2
1
4
z
2
2
2
2
0
2
6
1
2
2
y
w
x
4
2
0
0
u
v
Q u z
2
1
4
2
2
0
2
6
1
2
4
0
0
153
2
2
4
2
1
4
z
2
2
2
2
0
2
6
1
2
2
y
w
x
4
2
0
1
u
v
Q z u
2
1
4
2
2
0
2
6
1
2
4
0
1
154
End of pass 3
2
4
2
3
4
z
2
2
2
2
0
2
6
1
2
2
y
w
x
4
0
1
u
v
Q u z
2
3
4
2
2
0
2
6
1
2
4
0
0
155
Analysis
Note that we still have the O(n2m) bound
How many passes are there ?
Let F maxactive vd(v)
1) If the algorithm does not relabel during a
pass then F 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 F 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 F by at most O(n2)
? There are at most O(n2) passes of the first
kind
156
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
157
A faster implementation
Maintain a (dynamic) forest of some of the
admissible current edges
158
Reminder Admissible arc in the residual graph
v
w
d(v) d(w) 1
159
A faster implementation
Maintain a (dynamic) forest of some of the
admissible current edges
160
A faster implementation
Maintain a (dynamic) forest of some of the
admissible current edges
Active guys are among the roots
161
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 hasnt
been relabeled then Treepush/relabel(v). (If
the loop stops because v is relabeled then add v
to the end of Q)
162
A faster implementation
Q v.. ? discharge(v) ? Treepush/relabel(v)
v
w
163
Case 1 (v,w) is admissible
v
w
link(v,w,rf(v,w)), (v,c) findmin(v),
addcost(v,-c) Let (u,c) findmin(v) If
c0 cut(u) and repeat If e(v) gt 0 and v is not a
root then repeat
164
Case 2 (v,w) is not admissible
v
w
  • 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

165
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
166
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
Well see how to do those in O(log n) each so we
get running time of O(mnlog n)
167
Can we improve on that ?
Notice that we have not really used the fact that
Q is a queue, any list would do !
168
Idea Dont get the trees to grow too large
Case 1 (v,w) is admissible
v
We wont 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
c0 cut(u) and repeat If e(v) gt 0 and v is not a
root then repeat
169
If we are about to create a tree with at least k
vertices
v
w
170
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)
171
How do we recover ?
v
w
r
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
172
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.
173
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 kn2/m we get O(mnlog(n2/m))
Write a Comment
User Comments (0)
About PowerShow.com