Max flows in O(nm) time, and sometimes less.
by James B. OrlinMIT Sloan School
2
The Maximum Flow Problem Directed Graph G = (N, A).
– Source s– Sink t– Capacities uij on arc (i,j). Let U = max {usj : j N}. ∈– Maximize the flow out of s, subject to – Flow out of i = Flow into i, for i ≠ s or t.
A Network with Arc Capacities
s
1
t
2
4
1
2
3
1
A maximum Flow
s
1
t
2
3/4
1/1
2/2
2/3
1/1
3
Max-Flow Min-Cut
• An s-t cut is a partition of the node set into two parts S and T, with s S and t T.∈ ∈
• The capacity of a cut with respect to capacity vector u is
A max flow and minimum cut
s
1
t
2
3/4
1/1
2/2
2/3
1/1
Max-Flow Min-Cut (1956)
The maximum flow value is
the minimum capacity of an
s-t cut.
4
Running times for max flow algorithms
O(nm2) Edmonds and Karp (1972)
O(n2m) Dinic (1970)
O(n3) Karzanov (1974)Malhotra, Kumar &
Maheshwari (1977)
O(n2 m½ ) Cherkasky (1977)
O(nm log2 n) Galil and Naaman (1980)
O(nm log n) Sleator and Tarjan (1983)
O(nm log n2/m) Goldberg and Tarjan (1988)
5
More Improvements in running time
O(nm+ n2+ε ) King Rao and Tarjan (1992)
O(nm logα n ) King Rao and Tarjan (1994)
α = m/(n log n)
O(n3 / log n ) Cheriyan, Hagerup, and Mehlhorn (1996)
O(nm) O. (2012)
O(nm / log n) O. (2012) if m = O(n) and under some other conditions.
Remark 1: The max flow problem is solvable in O(nm / log n) steps when m = Ω(n2) and when m = O(n).
6
Weakly polynomial running times
O(nm log U) Gabow (1985)
O(nm + n2 log U) Ahuja and Orlin (1989)
O(nm + n2 log½ U) Ahuja, Orlin, and Tarjan (1989)
O(m3/2 log n log U) Goldberg and Rao (1998)
O(n2/3 m log(n2/m) log U) Goldberg and Rao (1998)
O(n2/3 m log U) O. (2012)
Further improvements if log Umax/Umin = O(n1/3- ε)
7
On Network Flow Algorithms
All are improvement algorithms, they start with a non-optimal solution and find an improved solution.
Augmenting Path Algorithms:• intermediate solutions are feasible flows• improvements are made by sending flow along a path
Preflow-Push Algorithms• intermediate solutions can violate flow conservation• “improvements” are made by sending flow along a single edge
8
The Goldberg-Rao Δ-scaling phase as a black boxassume that m < n1.06
run O( log n) scaling phases of the original GR algorithm
Δ-scaling phase
INPUT: A flow x and an s-t cut (S, T). Δ = u(S, T) – v(x) Δ is an upper bound on how much more flow can be sent.
OUTPUT: A flow x’ and an s-t cut (S’, T’) such that u(S’, T’) – v(x’) ≤ Δ/n.
RUNNING TIME: O(m3/2 log2 n).
Leads to an (O(m3/2 log n log U) time algorithm for max flows.
9
The Residual Network
s
1
2
t
8/10 7/8
1/1
6/105/6
s
1
2
t
2 1
141
8
5 6
7
i jx /uijij
i j
u - x
xij
ijij
We let rij denote the residual capacity of arc (i,j)The Residual Network G(x)
10
We will ignore arcs directed into s or out of t
s
1
2
t
8/10 7/8
1/1
6/105/6
s
1
2
t
2 1
141
8
5 6
7
The Residual Network G(x)
11
Δ-abundant arcs and pathsAn arc (i, j) is called Δ-abundant at the Δ scaling phase if rij ≥ 2Δ.
Lemma. If an arc is Δ-abundant at some scaling phase, it is Δ-abundant at all subsequent phases.
Proof. The change in flow in any arc (i, j) in the Δ-scaling phase is at most Δ. If xij ≥ 2Δ at the beginning of the phase, then If xij ≥ Δ at the end of the phase, and If xij ≥ nΔ’ at the next phase.
We write i ⇒ j if there is a Δ-abundant path from i to j.Otherwise, we write i ⤃ j
We maintain a list of all pairs i, j of nodes such that i ⇒ j. • O(nm) time over all iterations• Italiano [1986]. Dynamic transitive closure.
12
Contraction of arcs
If arcs (i, j) and (j, i) are both Δ-abundant at the Δ scaling phase, then we will contract arcs (i, j) and (j, i) and expand them at the end of the algorithm. (Contraction is well known.)
1 2
34
56
≥ 2 Δ
≥ 2 Δ
1 2
34
55-6
At time of contraction,flow into 5 (resp., 6) = flow out 5 (resp., 6).
After contraction, the flow into (5, 6) changes by at most Δ over all remaining iterations.
13
More contraction of arcs
If arc (s, j) is Δ-abundant at the Δ scaling phase, then we will contract (s, j). If (j, t) is Δ-abundant, then we will contract (j, t).
1 2
34
ts
≥ 2 Δ
≥ 2 Δ
1
2
3
4
3-ts-1
We also can contract Δ abundant cycles.
14
Compaction of nodes• Compaction. New Procedure.
• Determine nodes that are compactible all arcs incident to compactible nodes are Δ-abundant. Compactible nodes are eliminated.
• There is an arc (i, j) in the compacted graph if there is an abundant path from i to j in the original graph.
1 2
34
65
≥ 2 Δ ≥ 2 Δ
≥ 2 Δ
≥ 2 Δ
≥ 2 Δ
Before compaction
1 2
34
After compaction
15
Small, medium, and abundant arcs
We say that arc (i, j) is Δ-small if rij ≤ Δ/2n3
We say that arc (i, j) is Δ-medium if Δ/2n3 < rij ≤ 2Δ
We say that arc (i, j) is Δ-abundant if rij > 2Δ
5
1
2
3
4s t
6
7
We partition the arcs of the contracted graph into three groups.
From here on, we ignore the Δ-small arcs.
16
Δ-Critical Arcs and Nodes
We say that arc (i,j) is critical if it is Δ–medium and j ⤃ i. We say that node i is critical if is incident to a critical arc.
5
1
2
3
4s t
6
7
critical node
critical arc medium non-critical arc
Each arc is critical for O(1) scaling phases.
17
Δ-Fertile and Δ-Compactible Nodes
fertile node
We say that a non-critical node i is Δ-compactible ifLet MNC be the set of medium non-critical arcs.
We say that a non-critical node i is Δ-Fertile if
5
1
2
3
4s t
6
7
3
5
4
2 2
compactible node
18
The compacted network.
Eliminate all Δ-compactible nodes. The nodes of the compacted network are N* = Δ-critical and Δ-fertile nodes.
If i, j N* and if i∈ ⇒ j , then there is a Δ-abundant arc in A*.
Use flow decomposition for other arcs in MNC.
5
1
2
3
4s t
6
7
3
5
4
2 2
5
1
2
3
s t
7
3
4
2
19
5
1
2
3
4s t
6
7
3
5
4
2 2
5
1
2
3
s t
7
3
4
2
Lemma 1. Any flow in G* of value v* > Δ/2 can be transformed into a flow in G with value at least v* (1 – α).
Let α = 1 – 1/(4n)G = network before compaction.G* = compacted network.
Lemma 2. Any s-t cut (S*, T*) in G* with capacity C < Δ/2 can be transformed into an s-t cut (S, T) in G with capacity < C(1 + α).
20
On the number of nodes in compacted networks
5
1
2
3
s t
7
3
4
2
Lemma 3. Each arc with finite capacity is critical for O(1) scaling phases.
Corollary. The number of critical nodes is O(m’) over all phases.
Lemma 4. Each fertile node is contracted within O(1) scaling phases. The number of fertile nodes in all scaling phases is O(n).
It is invariant if MNC does not change. After O(1) scaling iterations the left hand side exceeds 4mΔ and so one of the arcs (i, j) must be abundant, and would be contracted.
Proof. Consider the LHS of
21
On solving flows on compacted networks.Let G* = (N*, A*) be the compacted network, with c = |N*|. Thus |A*| < c2.
If c > m9/16, we will solve the approximate max flow problem on G in O(m3/2 log2 n) time.
If c ≤ m9/16, we will solve the approximate max flow problem on G in O(c8/3 log n) time.
Time to create all compacted networks is O(nm).
Total number of nodes in compacted networks is O(n + m’)
22
Range of c Running time per scaling phase
Running time/c
c > m9/16 O(m3/2 log2 n) O(m15/16 log2 n)
c ≤ m9/16 O(c8/3 log n) O(m15/16 log2 n)
Running time for the max flow problem
Time for flows in all phases: O(m15/16 m’ log2 n).
For ε < 1/16 and for m’ < n1+ε, time is O(nm).
Time to create the networks. O(nm). (See note below)
Total running time. O(nm).
A special approach is needed if c is smaller than nε .
23
Time for solving the flow problems
Time for flows: O(m15/16 m’ log2 n ) = O(n m15/16 log2 n).
Time for creating the compacted networks can be sped up to O(nm/log n).
Total running time is O(nm / log n).
If m = O(n), the running time is O(n2 / log n)
When m’ = O(n), running time is O(nm / log n) That is, the number of arcs with finite capacity is O(n).
24
On speeding up the creation of G*
Time for creating a compacted networkG* = (N*, A*) with |N*| = c.
Time for determining all abundant paths between nodes of N*• O(c m) time using search algorithms• O(c m / log n) time using “bit packing”
Time for creating all of the compacted networks• O(nm/log n).
Time for uncompacting the networks• O(nm/log n)• A number of technical details.
25
Further improvements if Umax/Umin is “small”.Umax = max {uij : uij < ∞}; Umin = min {uij : uij > 0}
After 2K phases, there are no small or medium capacity arcs.
Running time for flow subroutines: O(nm15/16).
Running time for creating compacted networks: O(nm/log n)
How large can K be so that the running time is O(nm/log n)?
If m is large, can one speed up the time to create compacted network.
26
How large can K be?
Suppose that m = nγ. The running time for the first 2K phases is less O(nm/log n) if
1. m < n4/3 and K < n2– γ/2 – ε or
2. m ≥ n4/3 and K < n1/3 – ε.
27
A speedup if Umax/Umin is small and m is large.
Suppose that m ≥ n4/3 and K < n1/3 – ε.
Running time for first 2K phases is O(n1-ε/2 m).
One can use fast matrix multiplication for computing the arcs of the compacted graph.
O(n2.376) Coppersmith and Winograd [1990]
O(n2.3727) Williams [2011]
Let ω = 2.3727
28
Running times if Umax/Umin is smallRange
of c time for flows time for fast
transitive closure Running time/c
c > nω/3
≈ n.7909O(n2/3 m log n) -- O(m log n /nw/3 -2/3)
= O(m / n.1242)
c = nω/3
≈ n.7909O(c3) O(nω) O(n2ω/3)
= O(n1.5818)
Running time = O(max {nm/ n.1242, n2.5818} )
29
Relies on contraction and compaction prior to using GR
If log (Umax/Umin) < n1/3- ε , then
Improvement in strongly polynomial time max flows