Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis...

21
Preflow-Push Algorithm An s-t preflow obeys the following constraints: Capacity constraints: 0 f(e) c(e) e f (v) = A labeling h assigns nonnegative integers to vertices. h(t) = 0, h(s) = n, h(u) 0 for all other vertices u in V. A labeling h is compatible with an s-t preflow f if: h(t) = 0, h(s) = n. for all edges (v,w) in E f , h(v) h(w) + 1. f ( u, v ) uV f (v, w) w V 0

Transcript of Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis...

Page 1: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

Preflow-Push Algorithm

An s-t preflow obeys the following constraints: •  Capacity constraints: 0 f(e) c(e) •  ef(v) =

A labeling h assigns nonnegative integers to vertices. h(t) = 0, h(s) = n, h(u) 0 for all other vertices u in V.

A labeling h is compatible with an s-t preflow f if: •  h(t) = 0, h(s) = n. •  for all edges (v,w) in Ef, h(v) h(w) + 1.

f (u,v)∀u∈V∑ − f (v,w)

∀w∈V∑ ≥ 0

Page 2: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

Initial preflow f assigns f(e) = c(e) for each edge leaving s, and f(e) = 0 for all other edges.

Initial labeling h assigns h(t) = 0, h(s) = n.

Initial preflow f and labeling h are compatible.

Lemma 1. There is no s-t path in Gf if s-t preflow f is compatible with labeling h.

Lemma 2. If s-t flow f is compatible with labeling h, then f is a flow of maximum value.

2

Page 3: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

3 Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-3

Page 4: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

4 Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-4

Algorithm 7.4, page 360

Page 5: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

5 Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-5

Algorithm 7.5, page 360

Page 6: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

Lemma 3. Throughout the preflow-push algorithm, the preflow f and the labeling h are compatible.

Pf. When push operation is performed from vertex u to vertex v, the edge (v,u) can appear in Gf.

h(v) h(u) + 1. Why?

When relabel operation is performed on vertex u, h(u) < h(v) for all edges (u,v) in Ef. Why?

For any edge (v,u) in Ef, h(v) h(u) + 1 after the relabel operation. Why?

6

Page 7: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

7 Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-7

Algorithm 7.6, page 360

Page 8: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

Preflow-Push Algorithm Analysis

Lemma 4. If vertex v has excess preflow ef(v) then there is a path from v to s in Gf.

Pf. Let all vertices w such that there is a path in Gf from w to s be in set A. The remaining vertices are put in set B.

There can be no positive flow f(e) on any edge (u,v) in Gf going out of set A. Why?

Consider the sum of all excess in vertices in set B.

0 = .

There can be no positive flow into B. This implies that each excess in B is 0. Why?

8

e fv∈B∑ (v)

infv∈B∑ (v) −

outf (v)

Page 9: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

Preflow-Push Algorithm Analysis

Number of relabel operations:

Any vertex v in V can have label h(v) at most 2n – 1. Why?

Consider a vertex v with excess. v’s can be changed only by a relabel operation. This there is a path in Gf from v to s. This implies that the label of v can be at most 2n – 1.

Thus the total number of relabel operations is at most 2n2.

9

Page 10: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

Number of saturating pushes: (A push is saturating is it saturates the edge)

When a push occurs along edge (u,v), the edge dissappears from Gf.

It can reappear only after a push along edge (v,u).

But the label of vertex v must have increased by at least 2 for that to happen. Why?

Thus vertex v can participate at most (2n – 1)/2 times in push along edge (u,v).

Therefore there are at most 2mn saturating pushes.

10

Page 11: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

11 Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-11

Page 12: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

Number of nonsaturating pushes:

Let be the sum of the heights of all vertices with excess.

A nonsaturating push decreases by at least 1. Why?

A relabel operation increases by at most 1. There are at most 2n2 relabel operations.

Each saturating push increases by at most 2n – 1. Why? There are at most 2nm saturating pushes.

Thus increases by at most 4mn2.

Since is nonnegative, and decreases by at least for each nonsaturating push, there are at most 4mn2 nonsaturating pushes.

12

φ( f ,h) = h(v)v:e f >0∑

φ( f ,h)

φ( f ,h)

φ( f ,h)

φ( f ,h)

φ( f ,h)

Page 13: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

Implementation

Data Structure:

All vertices with excess can be placed in a list.

Choosing a vertex on this list, as well as updating the list (when a vertex with excess no longer has excess, or a new vertex with excess has to be added) can be done in O(1) time. Why?

In the Ford-Fulkerson Algorithm, choosing the right augmenting path lead to a better algorithm.

Similarly, in the Preflow-Push Algorithm, can choosing the right vertex with excess lead to a better algorithm?

Choose the vertex with maximum height.

13

Page 14: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

Choosing vertex with maximum height

Algorithm: At each stage, a vertex with excess at maximum height is chosen for a

push operation. What is an upper bound on the number of nonsaturating push

operations?

The maximum number of relabel operations is 2n2. Therefore the total increase in height is at most 2n2. Therefore the number of times the maximum height H changes is at

most 4n2. Each vertex can have at most one nonsaturating push operation at a

given H. Why? Therefore the maximum number of nonsaturating push operations at a

given H is at most n. Therefore the maximum number of nonsaturating push operations in

total is at most 4n3.

14

Page 15: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

Data Structure:

Maintain a (doubly-linked) list of all heights. For a given height, maintain a list of all vertices with excess.

Maintain an adjacency list representation of the graph, with both forward edges (as in the original graph G) and backward edges (which can arise in the residual graph).

For each forward (backward) edge, maintain a pointer to the backward (forward) edge. Also keep the flow value f, as well as the capacity of the edge.

The above data structure and the initial flow and labeling can be constructed in O(m) time.

15

Page 16: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

A pointer to the list with maximum height can be maintained. This can be used to choose a vertex with excess at maximum height. Once a vertex v is chosen, how is an edge for push chosen?

For each vertex, all the edges adjacent on it are maintained in some arbitrary order in a list. For each such list, a pointer current(v) points to the current edge considered for push.

When a vertex with excess (at maximum height) is chosen for push, the edge pointed to by current(v) is chosen for push.

After nonsaturating push, current(v) points to the same edge. After saturating push, current(v) points to the next edge in the list.

If we come to the end of the list, then current(v) is reset to the start of the list.

16

Page 17: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

Algorithm:

Choose a vertex v at maximum height. Choose edge pointed to by current(v) to push flow. Update current(v) by advancing if push saturating.

Continue with vertex v if push saturating. If push nonsaturating, choose another vertex at maximum height H (if

possible) or go to height H-1 to choose another vertex. If no other vertex at H, then there is a vertex with excess flow at H-1.

Why?

Relabel v if push saturating, and current(v) advances to end of list. After relabeling v, reset current(v) to start of list.

17

Page 18: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

Lemma 5. After current(v) is advanced from edge (v,w) to next edge in list, push cannot be applied to edge (v,w) until v gets relabeled.

Pf. If a push occurred on edge (v,w), then current(v) stays with edge (v,w)

if push is nonsaturating. It will be used again if v gets relabeled.

If the push was saturating, then the edge dissappears, and reappears only after v gets relabeled. Why?

If no push occurred, and current(v) advances to the next edge in list, then edge (v,w) not present in Gf. Either (v,w) is saturated (and v has to be relabeled to reappear), or h(v) h(w). Againv has to get relabeled for edge to reappear in Gf.

18

Page 19: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

Running time

Analysis:

Each time a vertex gets relabeled, current(v) reset to start of list. Total number of times a vertex can get relabeled is at most 2n. Total number of times current(v) gets advanced is 2ndv (where dv is the

number edges adjacent to v). Total number of times current gets advanced (for all vertices) is at

most 2n = O(mn).

Total number of nonsaturating push operations is O(n3).

Therefore total running time is O(n3 ).

19

vdv∈V∑

Page 20: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

20 Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-20

Page 21: Preflow-Push Algorithm - Simon Fraser University · 2008-09-19 · Preflow-Push Algorithm Analysis Lemma 4. If vertex v has excess preflow e f(v) then there is a path from v to s

21 Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-21