MF 6614
MF 6614
Acme Routing Company wants to route traffic over the internet from
San Fransisco to New York. It owns some wires that go between San
Francisco, Houston, Chicago and New York. The table below describes
how many kilobytes can be routed on each wire in a second. Figure out
a set of routes that maximizes the amount of traffic that goes from San
Francisco to New York.
Cities Maximum number of kbytes per second
S.F. - Chicago 3
S.F. - Houston 6
Houston - Chicago 2
Chicago - New York 7
Houston - New York 5
One commodity, one source, one sink
Maximum Flows
v∈V v∈V
v∈V v∈V
Example
a b
5
4
2
s 1
t
1
3 3
2
c d
Solutions
2/ 2
a b
2/ 5 2/
4
1/
2
0/ 1
s t
1/ 1
3/ 3 3/ 3
2/ 2
c d
Internet Advertising
Availability Queries
Given:
• Forecasts on ad impressions for each publisher’s slot
• A reservation request
An advertiser wants:
• 50 placements on sports slots
• 50 placements on afternoon slots
Publisher is offering
• 40 placements on slots that are sports and non-afternoon
• 40 placements on slots that are sports and afternoon
• 40 placements on slots that are non-sports and afternoon
reservations ad placements
sports and 40
afternoon
50 Sports
sports and
40
non−afternoon
50 Afternoon
non−sports and 40
afternoon
Example is a max flow problem
reservations ad placements
sports and 40
afternoon
50 Sports
sports and
40
non−afternoon
50 Afternoon
non−sports and 40
afternoon
reservations ad placements
sports and 40
inf afternoon
50 Sports
inf
sports and
source 40
non−afternoon
inf sink
50 Afternoon
inf
non−sports and 40
afternoon
Algorithm: Ford Fulkerson
Ford-Fulkerson-Method (G, s, t)
1 initialize flow f to 0
2 while there exists an augmenting path p
3 augment flow f along p
4 return f
For this to work, we need a notion of a residual graph
Residual Graph
v1 12/12 v3 v1 12 v3
15/ 5
11 /16 20 5
11 15
4
1/4
7/7
s t s t
7
1
3
9
5
4/
5
8/1
3
v2 v4 4/4 8 v2
3
v4
4
11/14 11
(a) (b)
v1 12/12 v3 v1 12 v3
6 19/ 5 1
1 20
11/
11 19
1/4
7/7
s t s t
7
1
3
1
9
9
12/
13
v2 v4 4/4 12
v2
3
v4
4
11/14 11
(c) (d)
Updating a Flow
4
1/4
s 7/7 t s t
7
1
3
9
5
4/
5
8/1
3
v2 v4 4/4 8 v2
3
v4
4
11/14 11
(a) (b)
v1 12/12 v3 v1 12 v3
19/ 1
11 /16 20 5
11 19
1/4
7/7
s t s t
7
1
3
1
9
9
12/
13
v2 v4 4/4 12
v2
3
v4
4
11/14 11
(c) (d)
s - t Cuts
An s - t cut satsfies
•s∈S , t∈T
• S∪T =V , S∩T =∅
2/ 2
a b
2/ 5 2/
4
1/
2
0/ 1
s t
1/ 1
3/ 3 3/ 3
2/ 2
c d
u∈S,v∈T
u∈S,v∈T u∈T,v∈S
Properties of cuts and flows
u∈S,v∈T
u∈S,v∈T u∈T,v∈S
• For all cuts (S, T ) and all feasible flows f , f (S, T ) ≤ c(S, T ) (weak
duality).
• For all pairs of cuts (S1, T1) and (S2, T2) , and all feasible flows f ,
f (S1, T1) = f (S2, T2) .
Examples of cuts
v1 12/12 v3
6 15/
/ 1 20
11
1/4
7/7
s t
9
4/
8/1
3
v2 v4 4/4
11/14
S T
Max-flow min-cut theorem
F ord − F ulkerson(G, s, t)
1 for each edge (u, v) ∈ E(G)
2 f (u, v) = 0
3 while there exists a path p from s to t in the residual network Gf
4 cf (p) = min{cf (u, v) : (u, v) is in p}
5 for each edge (u, v) in p
6 if (u, v) ∈ E
7 f (u, v) = f (u, v) + cf (p)
8 else f (v, u) = f (v, u) − cf (p)
Algorithm
v1 12 v3 v1 4/12 v3
16 20 6 20
4/1
(a) s t s t
7
9
4/
9
13 13
v2 v4 4 v2 v4 4/4
14 4/14
8 8/12
v1 v3 v1 v3
12 20 6 4/2
4 4/1 0
4
4
4/4
(b) s t s t
7
4
9
4/
5
13 10 4/1
v2 v4
4 3
v2 v4 4/4
4 4/14
4 8/12
v1 v3 16 v1 v3
12 6 8/2
8 8/1 0
4 4
4
(c) s t s t
7
4
9
5
4/1
4
v2
10
v4
4 3
v2 v4 4/4
4 4/14
Algorithm continued
4 8/12
v1 v3 12 v1 v3
8 15/
8 6 20
8/1
8 8
7/7
(d) s t
4
7
9 s t
9
10 11/
4
v2 v4
4 13
v2 4/4
v4
4 11/14
4 12/12
v1 v3 v1 v3 19/
8 5 6
8 2/1 20
1
8 15
7/7
(e) s t
4
4
7 s t
11
9
9
11/
2
v2
3
v4
4 13
v2 4/4
v4
11 11/14
v1 12 v3
4 1
12 19
(f) s t
4
11
9
2 3 4
v2 v4
11
Analysis
1
,9 99 , 999 ,999
1,0
00, 00
1,0
00, 999 999
0
000 00, 000 1 1 1
v 1,0 v v
Algorithm
• Run Ford-Fulkerson, but always choose the shortest augmenting path
in the residual graph.
• Breadth-first search implements this algorithm.
Idea for Analysis
Intuition
• Augment along shortest path in residual graph.
• Short paths get “saturated” and disappear.
• Future augmenting paths are along longer paths
• Eventually algorithm terminates because no more paths exist (remem-
ber that no augmenting path can have length greater than V.
Proof:
• Let δ be shortest path distances before an augmentation.
0
• Let δ be shortest path distances after an augmentation.
0
• Suppose, f.p.o.c. that for some v , δ (v) < δ(v) , and v is the minimum
0
vertex with this property (w.r.t δ )
Before
5 4 3 2 1 0
v t
After
4 3 2 1 0
v w t
Before
5 4 3 2 1 0
v t
After
4 3 2 1 0
v w t
0
• (v, w) ∈ Gf but not in Gf . (why?)
• We must have sent flow on (w, v) in the augmenting path
• δ(w) = 6
0
• δ (w) < δ(w) , which contradicts v being the minimum vertex whose
label decreased.
Solution We need to find some other event that happens on every aug-
menting path and then relate this event to increasing distances.
• 0 ≤ δ(v) ≤ V
• δ(v) never decreases.
• Each δ(v) increases at most V times.
• Total number of times some δ(v) increases is at most V 2 .
• We need to tie this to an augmenting path.
• Problem: A particular augmenting path may not increase any δ(v) .
(How can this happen?)
Solution We need to find some other event that happens on every aug-
menting path and then relate this event to increasing distances.
Edge Saturation
• If an augmeting path send cf (v, w) units of flow on edge (v, w) then
we call the push saturating.
• Every augmenting path saturates at least one edge. (Why?)
Analysis Continued
Edge Saturation
• If an augmeting path send cf (v, w) units of flow on edge (v, w) then
we call the push saturating.
• Every augmenting path saturates at least one edge.
5 4
v w
saturate (v,w)
v w
5 6
v w
saturate (w,v)
v w
7 6
v w
saturate (v,w)
Ideas
• Maintain variables d(v) which are “distances”, estimates (lower bounds)
on the distance to the sink (or source) in the residual graph
• Push flow over one edge at a time, pushing from a higher distance vertex
to a lower distance vertex.
• Allow excess flow to accumulate at a vertex.
• Maintain a preflow rather than a flow.
Capacity constraint: For all u, v ∈ V , we require 0 ≤ f (u, v) ≤ c(u, v) .
Relaxed Flow conservation: For all u ∈ V − {s, t} , we require
f (v, u) ≥ f (u, v) .
X X
v∈V v∈V
Define excess
e(u) = f (v, u) − f (u, v) (3)
X X
v∈V v∈V
Example
Comparison with augmenting paths
• Augmenting paths
– Always maintains a flow (feasibility)
– Works towards optimality (maximum flow)
• Push/relabel
– Always maintains a preflow and works towards a flow
– Maintains a superoptimal preflow and moves towards feasibility.
Basic Operations
Relabel When a vertex has all its outgoing residual edges pointing uphill,
we relabel it.
Relabel(u)
1 // Applies when: u is active and for all v ∈ V such that (u, v) ∈ Ef ,
we have d(u) ≤ d(v).
2 // Action: Increase the label of u.
3 d(u) = 1 + min{d(v) : (u, v) ∈ Ef }
Generic Push Relabel Algorithm
• At any point, any active vertex either has a path to the source or the
sink in the residual graph.
• There is never an s − t path in Gf .
• Let δ(v) be the minimum of distance to sink and V plus distance to
soure in Gf .
• If v is active then d(v) ≤ δ(v) . (inductive proof, similar to shortest
augmenting path, new short paths are not created).
• d(v) ≤ d(w) + 1 for any (v, w) ∈ Gf .
• If e(v) > 0 then either
– v has an outgoing admissible edge
– v can be relabeled (and the label will increase)
• If e(v) = 0 for all v ∈ V − {s, t} , then f is a maximum flow.
Relabel(u)
1 // Applies when: u is active and for all v ∈ V such that (u, v) ∈ Ef ,
we have d(u) ≤ d(v).
2 // Action: Increase the label of u.
3 d(u) = 1 + min{d(v) : (u, v) ∈ Ef }
Relabel(u)
1 // Applies when: u is active and for all v ∈ V such that (u, v) ∈ Ef ,
we have d(u) ≤ d(v).
2 // Action: Increase the label of u.
3 d(u) = 1 + min{d(v) : (u, v) ∈ Ef }
Number of relabels
• Vertex labels are at most 2V , so each vertex is relabelled at most 2V
times.
• Total time spent relabelling = V degree(v) = O(EV )
P
v
Pushes
P ush(u, v)
1 // Applies when: u is active, cf (u, v) > 0, and d(u) = d(v) + 1.
2 // Action: Push ∆(u, v) = min(e(u), cf (u, v)) units of flow from u to v.
3 ∆(u, v) = min(e(u), cf (u, v))
4 if (u, v) ∈ E
5 f (u, v) = f (u, v) + ∆(u, v)
6 else f (v, u) = f (v, u) − ∆(u, v)
7 e(u) = e(u) − ∆(u, v)
8 e(v) = e(v) + ∆(u, v)
Easy part
• Time per push = O(1) .
• Bookkeeping (can be amortized against other operations with reason-
able data structures and rules for choosing push/relabel operations).
• w has to be relabelled
• A push on (w, v) must occur
• v has to be relabelled.
Conclusion
• Between any two saturating pushes on (v, w) , v must be relabelled.
• v can be relabelled at most 2V times.
• There are at most 2V saturating pushes on (v, w) .
• The total number of saturating pushes is O(V E) .
Non-saturating pushes
Issue After a non-saturating push, the graph does not change, nothing
need be relabelled and another non-saturating push can occur on the edge
before anything significant happnes.
Φ= d(v)
X
v:e(v)>0
Analysis
Φ= d(v)
X
v:e(v)>0
• After initialiazation Φ ≤ 2V 2.
• At termination Φ = 0 .
• Let R be total increase in Φ due to relabellings.
• Let S be total increase in Φ due to saturating pushes.
• Each non-saturating push decreases Φ by at least 1. (Why?).
Putting these facts together
Φ= d(v)
X
v:e(v)>0
Relabellings
Saturating Pushes
• A saturating push leaves excess at v . It adds excess to w .
– If w already had excess, then Φ is unchanged.
– If w did not have excess, then Φ increases by d(w) , which is at
most 2V .
• There are at most O(EV ) saturating pushes, therefore total increase
due to saturating pushes is O(EV 2) .
Putting it Together