Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

45
Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin

Transcript of Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Page 1: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Max Flows 2: The Excess Scaling Algorithm

and Variants.

James Orlin

Page 2: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Algorithmic ideas from the previous lecture

• Augmenting path algorithm• an improvement algorithm that is guaranteed to be

optimal

• Max-Flow Min-Cut: • using a variation of LP duality to establish optimality

and distance from optimality.

• Scaling• Solving a sequence of problems that converges to the

original problem.• Efficient when reoptimizing can be done quickly.

• Simple data structures• keeping track of distance labels and current arcs sped

up the algorithm2

Page 3: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Algorithmic Ideas in this lecture

• Preflows: • A relaxation of flows that leads to improved

algorithms.

• A new scaling algorithm

• Potential function analysis• a method of establishing a faster running time

by using “global” information about the algorithm.

3

Page 4: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

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)

4

Page 5: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

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. (2011)

O(nm / log n) O. (2011) 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).

Remark 2: The improvements by O. (2011) are very involved.

5

Page 6: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

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. (2011)

Further improvements if log Umax/Umin = O(n1/3)

Remark: The improvement by O. (2011) is very simple

6

Page 7: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

7

Preflows

At each intermediate stages we permit more flow arriving at nodes than leaving (except for s)

A preflow is a function x: A → R s.t. 0 ≤ x ≤ u and such that

e(i) = ∑j N∈ xji - ∑j N∈ xij ≥ 0,

for all i ∈ N – {s, t}.

i.e., e(i) = excess at i = net excess flow into node i.

The excess is required to be nonnegative.

Page 8: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

8

A Feasible Preflow

The excess e(j) at each node j ≠ s, t is the flow in minus the flow out.

s

3

4

2 5

t

3

3

3

2

2

2

2

1

2

1

0

0

Note: total excess = flow out of s minus flow into t.

In preflow push algorithms, we typically send flow in only one arc at a time.

Page 9: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

9

Converting a preflow into a flow

Any preflow can be converted into a flow that preserves the flow into t.

s

5

t

3 2

2

1

3

3

2

1

43 2

0

0

Run flow decomposition and then keep only the paths from s to t.

Path Flow

s-3-t 2

s-3 1

s-4-t 2

s-4-2 1

Path Flow

s-2 1

s-2-5-t 2

12

2

2

2

12

Page 10: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Distances

We will maintain distance labels.

Next: how to maintain distance labels efficiently.

10

Page 11: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

11

Exact Distance Labels

Distance labels d( ) are exact for G(x) if for all j with a path to t, d(j) is the length of the shortest path from j to t.

i t

P = the shortest path from i to t in G(x)

d( ) 01234 34

Lemma. Suppose all distance labels are exact. Then, an arc (i, j) is admissible if and only if it is on a shortest path from i to t.

An arc is (i, j) is admissible if d(i) = d(j) + 1.

Page 12: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Maintaining Exact Distance Labels

At each iteration, CurrentArc(i) is the first admissible arc in A(i). The current arcs form a tree (or forest), whose arcs are directed into node t.

12

1

2 3

4

5

6

7

8

t

7

6

5

4

3

2

1

0

Suppose CurrentArc(i) = (i, j). Arc (i, j) may become inadmissible if

1. (i, j) is saturated or

2. the distance label of j is increased.

We will update CurrentArc(i) if it is inadmissible. We will update d(i) if there is no admissible arc out of i.

Page 13: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

An update of CurrentArc

Example 1. Suppose that flow is sent in (7, 2) and the arc is saturated.

13

1

2 3

4

5

6

7

8

t

7

6

5

4

3

2

1

0

7

8

4

6

2 3

Tail Head Res. Cap

7 2 07 3 17 4 47 6 27 8 0

Then (7, 3) becomes admissible.

Page 14: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Example 2: there is a cascading effect

Example 2. Suppose now that (3, 8) is saturated.

14

1

2

4

5

6

7

8

t

7

6

5

4

3

2

1

0

Tail Head Res. Cap

3 5 6

3 7 2

3 8 0

Node 3 increases its distance label to 4. (3, 5) is admissible. (7, 3) is inadmissible and node 7 is updated next.

3

Page 15: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Example 3: a gap is created

Example 3. Suppose now that (5, 2) is saturated.

15

1

2

4

5

6 7

8

t

7

6

5

4

3

2

1

0

Tail Head Res. Cap 5 2 0

5 3 3

5 4 6

Node 5 increases its distance label to 5. But now there is no node with distance label 3.

3

Page 16: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Example 3: continued

16

1

2

4 5 6 7

8

t

37

6

5

4

3

2

1

0

When a gap is created, all nodes with distance level above the gap have their distance level set to ∞.

Page 17: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

17

Time for updating distance labels

Lemma.

1. The arc list of each node i is scanned at most once between updates of d(i).

2. The arc list is scanned once if d(i) needs to be updated.

3. d(i) is updated at most n-1 times for each i.

Conclusion. Each arc is scanned O(n) times. The total running time for updating CurrentArc and d( ) is O(nm).

Page 18: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

On the order in which things are done

Typically, the generic preflow push algorithm is presented before the excess scaling algorithm.

But not here.

18

Page 19: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Scaling Algorithms

19

Generic Scaling Algorithm

Δ := 2K for some selected value K

determine a Δ-optimal solution x

while Δ > 1 do

y := ImproveApprox(x, Δ)

x := y

Δ := Δ/2

1. Define a concept called Δ-optimal, where Δ is some positive integer, and where a 1-optimal solution is optimal for the original problem.

2. Develop a subroutine that efficiently determines Δ0-optimum solution where

Δ0 is some (possibly large) power of 2

3. Develop a subroutine Improve-Approx that transforms a Δ-optimal solution into a Δ/2-optimal solution.

Page 20: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Initialize

20

s

5

7

d(s) := ∞

e(5) = us5

e(7) = us7

1. Determine exact distance labels for each node.

2. For each arc (s, j), send usj units of flow from s to j. This results in an excess e(j) = usj.

3. d(s) := ∞;

4. Choose Δ0 to be the minimum power of 2 that is greater than max (usj : j N}.∈

Page 21: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

21

Excess- Scaling Preliminaries

A preflow x is called Δ-optimal if1. 0 ≤ e(i) < Δ for all i with 1 ≤ d(i) < ∞.2. the distance labels are exact3. d(s) = ∞; that is, there is no path from s to t in G(x).

Subroutine ImproveApprox(x,Δ): takes a flow that is Δ-maximum and outputs a flow that is Δ/2-maximum.

ImproveApprox terminates when e(i) < Δ/2 for all i with 1 ≤ d(i) < ∞.

After initialization, the flow is Δ0-optimal.

Page 22: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Push-Relabel(i)

22

INPUT: a node i with e(i) ≥ Δ/2.

Push-Relabel(i)

begin

while e(i) > 0 do

if there is an admissible arc (i, j) then send min {e(i), Δ - e(j) – 1, rij) units of flow in (i, j)

else replace d(i) by 1 + min{d(j) : rij > 0}

update r, e, CurrentArc, and d( );

end

Page 23: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Examples of Push-Relabel

23

7

4

6

3

Δ = 64 level

k+2

k+1

k

k-1

Case 1. e(7) = 62 r73 = 40 e(3) = 10

62

10

40

22

52

0

Case 2. e(7) = 62 r73 = 40 e(3) = 30

62

30

40

29

63

7

62

30

0

Case 3. e(7) = 62 r73 = 0

Page 24: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

24

Excess Scaling Algorithm

Procedure Improve-Approx(r, Δ)

begin

while there is a Δ/2-active node do

begin

let i = argmin (d(i) : i is Δ/2-active}

Push-Relabel(i)

end

end;

Page 25: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

25

Pushing in the 64-scaling phase

0

5

4

3

2

1

t

4 5

s2 s

s

5

7

9

8

7

6

9

6

3 8

5

j 32 ≤ e(j) < 64 “large excess”

i e(i) < 32

4

7

5

62

0 25

2 40

For each admissible arc (i,j), j is not large excess.

Choose a large excess node i at minimum distance level.

Page 26: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

26

Pushing in the 64-scaling phase.

4

7

5

62

0 28

2 40

Rule: push as before, except that no node excess can exceed Δ-1.

Push 2 units in (7,4). Then push 35 units in (7,5)4

7

5

25

2 63

2 5

35

Send min{e(i), rij, Δ-e(j)-1} units of flow in (i,j)

Any non-saturating push has at least Δ/2 units of flow

j 32 ≤ e(j) < 64 “large excess”

i e(i) < 32

Page 27: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Bounding the number of pushes

Each arc (i, j) has at most one saturating push in between relabels of i. It may have several non-saturating pushes.

We will show that the number of non-saturating pushes per scaling phase is O(n2).

We will use a potential function argument.

We will define a potential function Φ.• Each non-saturating push will decrease Φ by .5.

We will bound this number by bounding the total increase in Φ over all iterations.

27

Page 28: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Elevators movements

28

10

9

8

7

6

5

4

3

2

1

0

An elevator is in a building that is n stories high. It can go up multiple floors at a time, but it can only go down one floor at a time.

In m movements of the elevator, how many floors can it travel upwards?

Note: it can travel n floors in a single move.

Page 29: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

UP ≤ DOWN + n.

29

10

9

8

7

6

5

4

3

2

1

0

It can go up at most n floors more than it goes down.

It can go down at most m floors in m moves.

In m moves, it can travel at most 2m + n floors.

If m > n, it travels at most 3m floors, or fewer than 3 floors per move on average.

Page 30: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Finding a min-distance Δ/2-active node.

30

10

9

8

7

6

5

4

3

2

1

0

For each distance level store a doubly linked list of Δ/2-active nodes.

After pushing flow from a node i, the next push is from a node with d(j) ≥ d(i) – 1.

Start with distance level d(i) – 1 and seek the first distance level with a Δ/2-active node.

Number of steps in m pushes is at most 2m + n. ∅

{i}

{j, j’}

Δ/2-active nodes at level k

Page 31: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Next: Bounding the number of pushes

We will create a potential function Φ.

We will use the up and down argument to bound the amount of decrease in Φ over all iterations.

This will bound the number of pushes.

31

Page 32: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

32

A potential function for excess-scaling

0

5

4

3

2

1

t

4 5

s2 s

s

5

7

9

8

7

6

9

6

3 8

5

Φ = ∑j∈N e(j) d(j) / Δ

node 2 3 4 5 6 7 8 9

e(j) 4 0 1 0 5 35 55 40

e(j)d(j) 8 0 1 0 20 70 165 120

Φ = 384 / 64 = 6

The potential is the “gravitational potential” measured in units of Δ

Page 33: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

33

Increases in the potential function

0

5

4

3

2

1

t

4 5

s2 s

s

5

7

9

8

7

6

9

6

3 8

5

Relabels:

Φ increases by at most k if d(j) increases by k.

Φ increases by O(n2) over all relabels.

Φ = ∑j∈N e(j) d(j) / Δ

Start of scaling phase.

Φ doubles when Δ is replaced by Δ/2.

Φ increases by O(n2 log U) over all scaling phases.

Page 34: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

34

Decreases in the potential function

0

5

4

3

2

1

t

4 5

s2 s

s

5

7

9

8

7

6

9

6

3 8

5

Push:

Φ decreases by δ/Δ if δ units of flow are sent in (i, j)

Φ decreases by at least ½ in any large push

Φ = ∑j∈N e(j) d(j) / Δ

Conclusion: number of large pushes is at most 2n2 plus the total increase in Φ. This is O(n2 log U) large pushes.

Page 35: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Summary of Excess Scaling Algorithm

• Converts Δ-optimal flows into Δ/2-optimal flows

• O(nm) running time (excluding time for large pushes)

• O(n2) time for large pushes per scaling phase.

• O(nm + n2 log U) time overall.

35

Page 36: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

On the analysis of the potential function

Note: the potential function Φ increased O(n2) because of relabels, and increased O(n2 log U) when Δ was replaced by Δ/2.

Speeding up the algorithm:

• If we can reduce the total flow at the end of the algorithm to O(nΔ/K) for some K, then the potential increase would be O( (n2 log U)/K).

• We will show how to do this for K = log½ U.

• Another bottleneck appears; so one cannot make K any larger.

36

Page 37: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

General Algorithmic Rule

37

Single bottleneck rule

If the bottleneck in an algorithm

is caused by one “thing”, then

try to speed up the “thing.”

Page 38: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Excess Scaling with Waves

Carry out a sequence of “waves” during a scaling phase.

Rules for the wave.

1. Select the lowest level Δ/2-active node, if one exists. Else, select the highest level node i with 1 < e(i) < Δ/2. Push flow from the selected node.

2. If a node has no admissible arcs, then delete it from G(x) for the rest of the wave (and add it back after the wave).

3. The wave ends when there are no nodes with positive excess remaining.

4. After the wave, update the distance labels and the CurrentArc( ).

38

Page 39: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Excess Scaling with Waves

39

Procedure Improve-Approx(r, Δ)

begin

while the total excess is greater than nΔ / log½ U do

perform a wave

update distance labels and current arcs

end;

Page 40: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Examples of Pushes During a Wave

40

Δ = 64

level

k

k-1

There are no Δ/2-active nodes.Node 7 is the highest level node with excess.Arcs (7, 3) and (7, 4) are admissible.

30

20

20

7

3 4 5

15

30

8

20

7

3 4 5

15

30

10

6

7

3 4 5

4

10

40

0

7

3 4 5

15

0

28

0

7

3 4 15

5

20

16

0

7

3 4 9

0

Case 1. Send 20 units in arc (7, 3). Node 3 becomes Δ/2-active.

Case 2. Send 20 units in arc (7, 3). Send 10 units in arc (7, 4). Delete node 7 from LIST.

Case 3. Send 6 units in arc (7, 3). Send 4 units in arc (7, 4). Delete node 7 from LIST.

Example 1

Example 2 Example 3

Page 41: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

4 55

t

Waves during the Δ-scaling Phase

1. No node is ever Δ-active during the Δ-scaling phase.

2. At the end of the wave, each active node j (that is, e(j) > 0) will increase its distance label. (There is no path from j to t of admissible arcs).

41

0

4

3

2

1

2

6

37

1

An arc may become inadmissible when it is saturated. This can cause a “cascading effect of deletions.

e.g., suppose (1, 5) is saturated.

suppose (2, 4) is saturated.

Page 42: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Waves during the Δ-scaling Phase

3. There is at most one non-saturating push from a node with e(i) < Δ/2.

42

4 55

t0

4

3

2

1

2

6

37

1

If no nodes are Δ/2 active, then the highest level active node will never receive any more flow during the wave.

4. If the Δ-scaling phase does not end after a wave, there were at least n/log½ U distance increases.

If e(6) := 0, then e(6) = 0 for the rest of the wave.

At the end of the wave, each node with excess will be relabeled.

If the Δ-scaling phase didn’t end, then the total excess is at least nΔ/log½ U.

Page 43: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

Putting it all together

1. There are O(log U + n log½ U ) waves. Each wave leads to O(n) small non-saturating pushes.

2. Total run time because of the waves is O(n2 log½ U ), if log U < n2

43

3. Each non-saturating push from a Δ/2-active node decreases Φ by at least .5

4. Φ increases byO(n2 / log½ U ) following a scaling phase. It increases by O(n2 log½ U ) in total.

5. Conclusion: Number of non-saturating pushes is O(n2 log½ U ).

Page 44: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

summary of techniques

• Preflows: A relaxation of flows that leads to improved algorithms. It is quite common to solve problems by solving relaxations.

• Potential function analysis• a method of establishing a faster running time by using

“global” information about the algorithm.• surprisingly useful in analyzing data structures and

algorithms

• Excess scaling

• Excess scaling with waves. (If there is a single bottleneck operation or a single cause of the bottleneck, sometimes the running time can be improved by combining two approaches.)

44

Page 45: Max Flows 2: The Excess Scaling Algorithm and Variants. James Orlin.

45

Research notes on preflow push

Pushing from the active node with the largest distance label leads to O(n2 m.5) nonsaturating pushes.

A very efficient data structure called dynamic trees reduces the running time to O(nm log n2/m). Goldberg-Tarjan (1986)

The “excess scaling technique” of Ahuja and Orlin (1989)reduced the running time to O(nm + n2 log U).

Ahuja, Orlin, and Tarjan (1989): further very small improvements.

Goldberg and Rao (1998). An even more efficient algorithm for max flows.

Orlin [2011] max flows in O(nm) time and sometimes less.