Maximum Flow - Computer Science and Engineeringweb.cse.ohio-state.edu/~lai.1/6331/6-maximum...

65
Maximum Flow Reading: CLRS Chapter 26. CSE 6331 Algorithms Steve Lai

Transcript of Maximum Flow - Computer Science and Engineeringweb.cse.ohio-state.edu/~lai.1/6331/6-maximum...

Maximum Flow

Reading: CLRS Chapter 26.

CSE 6331 Algorithms

Steve Lai

A flow network ( , ) is a directed graph with

a source node ,

a sink node ,

a capacity function .

Each edge ( , ) has a nonnegative capacity ( , ) 0.

Flow Network

G V E

s V

t V

c

u v E c u v

• If ( , ) , assume ( , ) 0.

Also, assume that every node is on some path from to .

This implies ( ) ( ).

A maxflow may only go through such nodes.

u v E c u v

v s t

O V E O E

2

Let ( , ) be a flow network with capacity function ,

source node , and sink node .

A flow is a real-valued function : satisfying

Capacity constraint: , , ( , ) ( , ).

Flow

G V E c

s t

f V V

u v V f u v c u v

Skew symmetry: , , ( , ) ( , ).

Flow conservation: { , },

( , ) ( , ) 0

value of a The is ( , ) ( , ).

The is

flo

to

w

maxflow problem find a f

v V

v V

u v V f u v f v u

u V s t

f u V f u v

f f s f vf V s

low of maximum value. 3

If no edge between and , then ( , ) ( , ) 0.

Flow conservation implies: { , },

Total positive flow into Total positive flow out of .

For , , define

Some Properties of Flows

u v f u v f v u

u V s t

u u

X Y V

• ( , ) ( , ).

( , ) 0.

( , ) ( , ).

( , ) ( , ) ( , ), if .

( , ) ( , ) ( , ), if .

x X y Y

f X Y f x y

f X X

f X Y f Y X

f X Y Z f X Z f Y Z X Y

f Z X Y f Z X f Z Y X Y

4

Let ( , ) be a flow network and a flow.

Residual capacity of ( , ) is

( , ) ( , ) ( , ).

Residual network induced by is ( , ), where

Residual networks and augmenting paths

f

f f

G V E f

u v

c u v c u v f u v

f G V E

( , ) : ( , ) 0 .

Augmenting path: a simple path from to in .

Residual capacity of :

( ) min ( , ) : ( , ) is in .

f f

f

f f

E u v V V c u v

p s t G

p

c p c u v u v p

5

Example

6

s

a

c

b

d

t

12/12

11/147/710

1/4

s

a

c

b

d

t

12

3

711 3

11

(a) Flow network and flow (b) Residual network and

augmenting path p with

s

a

c

b

d

t

12/12

11/14

7/710

1/4

( ) 4fc p

s

a

c

b

d

t

12

3

711 3

11

(c) Augmented flow (d) No augmenting path

Let ( , ) be a flow network with a capacity function ,

source , and Assusink .

i.e.,

me has no parallel edge

if ( , ) then (

s

, ) .

,

Flow: an alternative defini (CLRS, 3rd ed.)tion

G V E c

s t

u v

G

E v u E

A flow is a real-valued function : , satisfying

Capacity constraint: 0

Flow conservatio

, , ( , ) ( , ).

: { , },

( , ) ( , ) i.e. ,

n

v V v V

f V V R

u v V f u v c u v

u V s t

f v u f u v f V u f u

when ( , ) , ( , ) 0

,

The value of a flow is , , .

Note: .

V

f f s V f

u v E f u v

V s

7

If no edge between and , then ( , ) ( , ) 0.

Flow conservation implies: { , },

Total positi

Some of these properties do not hold any more

(when using the second definition of flows)

u v f u v f v u

u V s t

ve flow into Total positive flow out of .

For , , define ( , ) ( , ).

( , ) 0.

( , ) ( , ).

( , ) ( , ) ( , ), if .

( , ) ( , ) ( , ), if .

x X y Y

u u

X Y V f X Y f x y

f X X

f X Y f Y X

f X Y Z f X Z f Y Z X Y

f Z X Y f Z X f Z Y X Y

8

Let ( , ) be a flow network and a f

Residual cap

low.

of ( , ) is

( , ) ( , ) if ( , )

( , ) ( , ) if

acity

Residual networks and augmenting paths

(using the second definition of flows)

f

G V E f

u v

c u v f u v u v E

c u v f v u

( , )

0 otherwise

Residual network induced by is ( , ), where

( , ) : ( , ) 0 .

Augmenting path: a simple path from to in .

f f

f f

f

v u E

f G V E

E u v V V c u v

p s t G

9

Given a flow network ( , ) with source and sink ,

Initialize flow to 0

there exists an augmenting path

augment flow along

Ford-Fulkerson Method

G V E s t

f

p

f p

f

while do

do

return

10

each edge ( , ) ( )

( , ) 0

( , ) 0

there exists an augmenting path in residual network

( ) min ( , ) : ( , ) is on

Ford-Fulkerson , ,

f

f f

u v E G

f u v

f v u

p G

c p c u v u v p

G s t

for

do

while

do

each edge ( , ) is in

( , ) ( , ) ( )

( , ) ( , )

f

u v p

f u v f u v c p

f v u f u v

for

do

11

The running time depends on how the augmenting

path is determined.

If capacities are integers, the running time is ,

where is the value of the maxflow.

Each iteration can

Analysis

p

O E f

f

be done in time.

There are at most iterations.

If all capacities are integers, the flow

produced by the Ford-Fulkerson method has the prope

Integral

rt

y that

( , ) is an integ

ity Theore

er

m.

O E

f

f

f u v

for all , .u v V

12

Let be the residual network induced by flow .

Let be a flow in . Then is a flow in with

.

Skew symmetry:

( , ) ( , ) ( , )

Lemma 1.

Pro

(

of.

, ) ( , )

(

f

f

G f

f G f f G

f f f f

f f u v f u v f u v

f v u f v u

f f

, )

Capacity constraint:

( , ) ( , ) ( , )

( , ) ( , )

( , ) ( , ) ( , )

( , )

f

v u

f f u v f u v f u v

f u v c u v

f u v c u v f u v

c u v

13

Flow conservation: for all , ,

( , ) ( , ) ( , )

0 0 0

Finally,

( , )

( , ) ( , )

u V s t

f f u V f u V f u V

f f f f s V

f s V f s V

f f

14

If is an augmenting path in , then

augmenting along yields a flow

Lemma 2.

Corollary

in with value

( ) .

The produced by Ford-F 3 ulkerson is a flo .. w

f

f

p G

f p G

f c p f

f

15

A , of a flow network ( , ) is a partition of

of into and such that and .

If is a flow, ( , ) denotes the across

cut

net flo

the cut (w

capacit

, ).

The of ( , ) s

iy

Cuts

S T G V E

V S T V S s S t T

f f S T S T

S T

( , ) ( , ).

Example: ( , ) ( , ) ( , ) 12 14 26.

( , ) ( , ) ( , ) ( , ) 12 11 4 19.

u S v T

c S T c u v

c S T c a b c c d

f S T f a b f c d f c b

16

s

a

c

b

d

t

12/12

11/14

7/710

1/4

S T

Note that ( , ) 0 , .

( , ) ( , ) ( , )

( ,

Lemma 4. For any cut ( , ), ( , )

)

( , ) ( , )

( , )

( , ) ( , ).

.

Proof.

Corollary 5. ( , ).

Proof.

f u V u s t

f S T f S V f S S

f S V

S T f

f s V f S s V

f s V f

f f S T c S T

f S T

f c S T

17

The following conditions are equivalent:

1. is a maxflow in .

2. The residual network contains no augmenting paths.

3. ( , ) for some cut ( , )

Theorem.

in .

The Max-flow Min-cut Theorem.

f

f G

G

f c S T S T G //minimum cut//

Immediately follows from Corollary 5.

Immediately follows from Lemma 2. (If

contains an augmenting path , augmenting

Proof. (3) (1):

(1) (2):

along will

increase the flow.)

fG

p f p

18

(2) (3):

2. The residual network contains no augmenting paths.

3. ( , ) for some cut ( , ) in .

Suppose contains no augmenting path. Define

: there is a path from to in ,

.

( , )

f

f

f

G

f c S T S T G

G

S v s v G

T V S

S T

is a cut since and (no path from to in ).

For all , , we have , since otherwise

( , ) and would be in . So,

( , ) ( , )

( , ) .

By Lemma 4, ( ,

( ,

) ( , ).

)

f

f

f u v c u v

f S

s S t T s t G

u S v T

u v E v S

f f

T c S

S

T

S T c T

19

In the while loop of Ford-Fulkerson, find the augmenting

path with a breadth-first search, that is, the augmenting

path is a shortest path from to in the residual

ne

Edmonds-Karp Algorithm

p

s t

2

twork,

where "shortest" is in terms of number of edges.

Running time: (to be shown . )O VE•

20

In the execution of Edmonds-Karp algorithm, for all

, , ( ) is nondecreasing with each flow augmentation

where ( ) shortest distance (# edges) fr

Lem 6

o

m .

m

a

Analysis of the Edmonds-Karp Algorithm

f

f

v s t v

v

to in .

. By contradiction. Assume the lemma is not true.

Consider the first augmentation that decreases some ( ).

Let and be t beforehe flows just and the

Proof

L

e

a

t

ugmentation.after

f

f

s v G

f f

v

Let be a sho

be the verte

rtest

path fr

x s.t. ( ) ( ) and

om to in , and let ( , ) be the last edge of .

S

( ) is minimum

among those nodes with ( ) ( ).

o, ( , ) , ( ) 1

f

f

f

f

f f f

f p

s

v

v G u v p

u

v v

x x x

v E u

( ), an ( ) ( )d .f ff uv u 21

Case 1: . Then, ( ) 1 ( ), and then

( ) ( ) 1 ( ) 1 ( ) ( ),

a contradiction.

Case 2: Now, ( , ) , but ( , ) .

( ,

This means, the augmen

)

(

ting

, ) .

f f

f

f

f f

ff

f f

u v E

u

u v

v u u v v

u v E u vv EE

path contains edge ( , ).

As Edmonds-Karp always augments flow along shortest paths,

( , ) is the last edge of a shortest path from to in .

Therefore, ( ) ( ) 1 ( ) 1 ( ).

f

f f f f

v u

v u s u G

u v u v

As in case 1, this will lead to a contrdiction.

22

23

ssvu

f

f

G

G

( ) decreases for red nodes; does not decrease for green nodes.

: the red node closest to in .

: predecessor of on shortest path to in ; a green node.

f

f

v s G

u v s v G

st

ss st

augmentation

24

ss

vuf

f

G

G st

ss st

vu

( ) 1 ( )f fu v

( ) 1 ( )f fu v

If edge ( , ) exists in fu v G

25

ss

vuf

f

G

G st

ss st

vu

( ) 1 ( )f fu v

( ) 1 ( )f fu v

If edge ( , ) does not exist in fu v G

augmenting

path

2

If Edmonds-Karp Algorithm runs on , ,

then the total number of flow augmentations is

and hence the total running time is .

. An edge ( , ) in is on an augm

Theor

c entiriti

em 7.

Pro ngc lof af

G V E

O VE

O VE

u v G

path

if ( ) ( , ). Every augmenting path has a critical edge.

An edge ( , ) may become critical only if ( , ) or ( , ) .

So there are at most 2 edges that may become critical during

the algo

f f

p

c p c u v

u v u v E v u E

E

rithm's execution. We will show that each of these edges

may become critical at most 2 times, which will imply that

during the execution of the Edmonds-Karp algorithm there are

at most augmentati

V

O VE ons.26

an edge ( , ) can become critical at most 2 times.

When ( , ) becomes critical in a residual network ,

( ) ( ) 1. (1)

After flow augmentation along the augmenting path,

Claim:

(

f

f f

u v V

u v G

v u

aft

, ) disappears from the residual network.

It may reappear later on another augmenting path only

, which occurs only if edge ( , )

appears on an augmenting path i

er

( , ) decreas

n e

es

som

u v

v uf u v

, in which case,

( ) ( ) 1 ( ) 1 by Lemma 6

( ) 2 by (1).

f

f f f

f

G

u v v

u

27

Thus, if ( , ) becomes critical more than once, then for

each additional time ( , ) becomes critical, ( ) increases

by at least 2.

When ( , ) becomes critical for the last time, ( ) 2.

u v

u v u

u v u V

Thus, ( , ) can become critical no more than 2 times.

This proves the claim and the theorem.

u v V•

28

1 2

1 2

, : flow network with

sources: , , ,

sinks: , , ,

Networks with multiple sources and sinks

m

m

G V E

m s s s

n t t t

29

G

s1

s2

s1

t1

t2

t3

s t

, : undirected graph

Bipartite graph: if can be partitioned into and such

that all edges in go between and .

Theorem: is bipartite iff it has no cy

Maximum Bipartite Matching

G V E

V L R

E L R

G

• cles of odd length.

Matching: a set of edges such that every vertex in

is an endpoint of at most one edge in .

Maximum matching: a matching with the max cardinality.

A maximum matchin

M E

V M

• g of a bipartite graph can be found

using the Ford-Fulkerson method.

30

, : a graph

Edge-disjoint paths: two paths are edge-disjoint if they

do not share any edges.

Problem: Given a graph , and two

nodes , , find a

directed

maxi

Edge-Disjoint Paths

G V E

G V E

s t

mum number of edge-disjoint

paths from to .

Problem: Given an graph , and

two nodes , , find a maximum number of edge-disjoint

paths from

und

to

irec e

.

t d

s t

G V E

s t

s t

31

, : a graph

Node-disjoint paths: two paths from to are

node-disjoint if they do not share any intermediate nodes.

Problem: Given a di graph , andrect twed o

Node-Disjoint Paths

G V E

s t

G V E

undirec

nodes , , find a maximum number of node-disjoint

paths from to .

Problem: Given an graph , and two

nodes , , find a maximum number of node-disjoint

te

paths fro

d

m

s t

s t

G V E

s t

s

to .t

32

A fundamental problem in computer vision.

Given a digital image (a set of pixels), we want to partition

it into multiple segments.

In a simple case, we just want to divide

Image Segmentation

• the image into two

segments: the foreground and the background.

Represent the image by an undirected graph ( , ),

where is the set of pixels and there is an edge

between two pixels iff

G V E

V

there are neighbors.

33

34

Each pixel has a likelihood (goodness) 0 to belong to

the foreground and a likelihood 0 to belong to the

background.

Each edge ( , ) is associated with a separation

penalty

i

i

ij

i a

b

i j E

p

0, which is incurred if pixels and

are placed in different segments.

jip i j

35

Given a pixel graph ( , ), likelihood functions

, : and penalty function : , we want

to partition into two sets and and

( , )

Prob

maximize

le :

:

m

i i ij

i A i B

G V E

a b E p E

V A B

Q A B

a b p

minimize

( , ) , , in different segments

Or, equivalently,

( , ) ( , )

: ( , ) , , in different seg en

m ts

i i

i i ij

i V i V

i B i A

i j E i j

Q A B a b Q A B

a b p i j E i j

36

We can solve the image segmentation problem by converting

it to a flow network. Let ( , ) be the pixel graph.

Introduce two new vertices: a source and a sink .

Connect to each pixel

G V E

s t

s

• with capacity .

Connect from each pixel with capacity .

Replace each edge ( , ) with two directed edges ( , )

and ( , ) with capacities and .

Relationship between the

i

i

ij ji

i V a

t i V b

i j E i j

j i p p

1-1 correspondence

pixel graph , and

the constructed flow network , :

Segmentations of Cuts of

( , ) { }, { }

G V E

G V E

G G

Q A B c A s B t

37

38

Pixel graph ( , )G V E

i

ij

k

a

p

b

B A

( , ) { }, { }Q A B c A s B t

Generic Push-Relabel Algorithms for Maximum Flows

2Running time: O V E

Flow net ( , ), capacity function , source , sink .

A is a function : , satisfying

Capacity constraint: , , ( , ) ( , ).

Skew symmetry: , , (

preflow

, )

Preflows

G V E c s t

f V V

u v V f u v c u v

u v V f u v

( , ).

flow conservation: { },

( , ) 0

The quantity ( ) ( , ) is calle excess f

Rela

lowd the into

overflowing

.

Vertex is if ( , ) 0.

xed

f v u

u V s

f V u

e u f V u u

u t f V u

40

0 a function : , satisfying

( )

( ) 0

( ) ( ) 1 for every residual edge , .

a height function is

Height functio

defined relative to a preflow.Note:

Lemma: If

n:

( )

f

h V

h s V

h t

h u h v u v E

h u

( ) 1 then , .fh v u v E

41

Applicable when:

Act

is overflowing, ( , ) 0, and ( ) ( ) 1.

push ( , ) min ( ), ( , ) units of

flow

io

from to .

( , ) ( , ) ( , ).

n:

Operation Push( , )

f

f f

f

u c u v h u h v

u v e u c u v

u v

f u v f u v u v

u v

( , ) ( , ).

( ) ( ) ( , ).

( ) ( ) ( , ).

f

f

f v u f u v

e u e u u v

e v e v u v

42

The operation Push( , ) is called a from to .

edge ( , ) becomes saturated

(i.e., ( , ) 0) after the p

push

Saturating push:

Nonsaturating push

ush.

( , ) 0 after the push.

Lemm

:

a:

f

f

u v u v

u v

c u v

c u v

• After a nonsaturating push from to , vertex

is no longer overflowing.

After the push, either ( ) 0 orProof , 0.: ( )f

u v

u

e u c u v

43

{ , } is overflowing and

( ) ( ) for all edges ( , ) .

increase the

Applicable when:

Act height of .

( ) 1 min ( )

ion:

Note

: ( , ) .

s : ince

Operation Relabel( )

f

f

u s t

h u h v u v E

u

h u h v u v E

u

u

is overflowing, there is at least one edge

( , ) , so the above min is not over an empty set.

fu v E

44

Initial preflow: For all , ,

( , ) if

( , ) ( , ) if

0 otherwise

Corresponding excess flow function:

( , ) if ( , )

( ) ( , ) : ( , )

Initialize-Preflow( , , )

u v V

c u v u s

f u v c u v v s

c s v s v E

e v c s x s x E

G s t

if

0 otherwise

Initial height function:

if ( )

0 otherwise

v s

V u sh u

45

1. Initialize-Preflow( , , ) // initialize a preflow //

2. there is an applicable or operation

an applicable operation an

push relabel

sele ect d p

Generic-Push-Relabel Algorithm

G s t f

while

do rform it

For correctness, what do we need toQuest proion: ve?

46

If is an overflowing vertex, then either a

push or relabel operation can be appl

Lemma 1.

Lemm

ied to it.

Whenever a relabel operation is applied to a

ver

a

tex

2.

Correctness of Generic-Push-Relabel

u t

u

, its height ( ) increases by at least 1.

During the execution of the algorithm, is

always a height function.

During the execution of the algorithm,

Lemma 3.

Lemma is

always a pr

4.

eflow.

h u

h

f

47

Let be a preflow. If there is a height function

relative to , then there is no path from to in the

residual network .

. Otherwise, if there is a simple pat

Le

h

mma 5.

in Proof

from to

f

f

f

h f s t

G

p G

s , then

( ) ( ) length( ) 1

contradicting the fact that ( ) ( ) .

t

h s h t p V

h s h t V

48

the algorithm terminates, the preflow

it computes is a maximum flow.

. When the algorithm terminates:

is a preflow (by Lemma 4).

No vertex is overf

Theorem.

lowin

If/whe

g (by L

n

Pr

emm

a

oof

S

1).

f•

• o, is a flow

There is no augmenting

.

is a height function (by Lemma 3).

(by Lemma 5).

So, is a maxflow (by Max-flow M

pa

in-cut Theorem)

t

.

h in f

h

f

f

G

•49

Let be a preflow. Then, for any overflowing

vertex , there is a path from to i

Lemma 1.

Lemma 2

n .

At any time during the execution of the algorithm

( 2 1

. ,

)

Analysis of Generic-Push-Relabel

f

f

u u s G

h u V for any node .

When a vertex is relabeled, it is overflowing and

has a simple path to (which is still true after the relabel).

Since the path has at most 1 edges,

Proof.

Corollary

( ) 2 1.

u V

u

s

V h u V

2

The total number

of relabel opera

(bound on rela

tions is at mos

bel operat

t 2 1 2 2

ions).

.V V V

50

The total number

of saturating pushes is at most 2 .

Push( , ) may occur only if ( , ) or (

Lemma 3 (bou

, ) .

Between

nd on

two c

saturating p

onsecutive

ushes).

Proof.

saturati png ushes from to ,

V E

u v u v E v u E

u v

Reasons:

Between two saturating pushs from to ,

there must be a push from to .

At the 1st Push( , ) : sa

( )

y ( ) a .

At Push( , ) : (

) (

increases

) 1

by at least 2.

u v

v u

u v h u

v u h v h

h u

u a

1.

At the 2nd Push( , ) : ( ) ( ) 1 2 .

So, for each ( , ) or ( , ) , satulating Push( , )

may occur no more than times.

u v h u h v a

u v E v u E u v

V

51

2

( ) 0

Lemma 4 (bound on nonsaturating pushes).

Proof.

The number

of nonsaturating pushes is less than 4 .

Define ( ). Initially, 0.

Relabeling a vertex increases by less than 2 .

A s

a

e u

V V E

h u

u V

2 2

turating push from to increases by less than 2 .

Total amount of increase to is less than

2 2 2 4 .

A nonsaturating push from to deccreases by at least 1.

Thus, the total

u v V

V V V E V V E

u v

2

number of nonsaturating pushes is less than

4 .V V E52

2

3

Each relabel can be done in time and

each push can be done in 1 time.

The running time of the generic push-relabel

algori

Lemma 5.

Proof.

thm is .

Total time for rel ( )abels: .

Theo .

rem

O V

O

O

O V

V E

2

Total time for satulating pushes: .

Total time for nonsatulating pushes:

( )

( ) .

O VE

O V E

53

The Relabel-to-Front Algorithm

3Running time: O V

, , ,

An edge ( , ) is if

( , ) 0 and ( ) ( ) 1.

, , where is

the set of admissible edges. It is a subgrap

admissible

Admissible network:

h

Admissible edges and networks

f

f h f h f h

u v

c u v h u h v

G V E E

,

,

of .

The admissible network is acyclic.

The height function ( ) is decreasing alo

Lem

ng

any path in .

ma 1.

Proof.

f

f h

f h

G

G

h

G

55

,

If a vertex is overflowing and edge ( , )

is admissible, then Push(

When is Push( , ) applicable? Ho

, ) is applicable. The

o

w does it affect ?

L

peration does not create any new adm

e

issi

mma 2.

f h

u u v

u v

u v G

ble edges,

but it may cause ( , ) to become inadmissible.

The Push( , ) operation reduces ( , )

and increases ( , ). If ( , ) becomes 0,

( , ) becomes inadmissible. Since ( ) ( ) 1,

Proo

(

f. f

f f

u v

u v c u v

c v u c u v

u v h u h v

v

, ) cannot become admissible. u

56

,

If a vertex { , } is overflowing and there are

no admissible edges

When is Relabel( ) applicable?

leaving , then Relabel( ) is

applicable

How does it affect ?

.

Lemma 3.

f h

u

u

s t

G

u

u

After the relabel operat

Proof. Only the last claim needs a proof.

If, after the relabel, ( , ) is an admissible edge entering

v u

ion, there is at least

one admissible edge leaving u, but there are no

admissible edges entering u.

,

then ( ) ( ) 1. Before the relabel of ,

( ) ( ) 1 and thus ( , ) .

f

u

h v h u u

h v h u v u E

57

Same as the adjacency lists of the flow network ( , ),

except that the list of contains iff ( , )

or ( , ) .

( ) : the neighbor list of . It contains those vertice

Neighbor lists

G V E

u v u v E

v u E

N u u

s

for which there may be a residual edge ( , ).

( ) : pointing to the first element in ( ).

( ) : pointing to the vertex currently under

consideration in ( ). Initially,

v u v

head N u N u

current u

N u curre

( ) ( ) .

- ( ) :

nt u head N u

next neighbor

•58

Discharge( ) : push excess flow of thru admissible

edges leaving , relabeling as necessary.

Procedure Discharge( ) //after Discharge( )

all

( ), 0//

Discharging an overflowing vertex

u u

u u

u u e u

wh

( ) 0

( )

NIL

Relabel( )

( ) ( )

( , ) is admissible

Push( , )

e u

v current u

v

u

current u head N u

u v

u v

curren

ile do

if then

elseif then

else ( ) - ( )t u next neighbor v59

1 Initialize-Preflow( , , )

2 [ ] { , } in any order

3 Initialize ( ) for each [ ] { , }

4 ( )

5 NIL

6 Discharge( )

7 has been relabe

Algorithm Relabel-to-Front( , , )

G s t

L V G s t

current u u V G s t

u head L

u

u

u

G s t

while do

if led during Discharge( )

8 move to the front of

9 - ( )

u

u L

u next neighbor u

then

60

,

Lemma 4.

Relabel-to-Front performs push and relabel

operations only when they are applicable.

At each test in line 5 of Relabel-to-Front,

is a topological sort of { , } an

Lem

d n

ma

o

5.

vertex

be

f hL G s t

fore in the list has excess flow.

When Relabel-to-Front terminates, there

are no applicable push or relabel operations

(since by Lemma 5 there is no overflowing node).

Theore

Coroll

Relabm e

a

l

ry.

. F

-to-

u

ront is an implementation of

the generic push and relable algorithm.

61

,

, For iteration 1, it is

Proof of Lemma 5 (part 1)

true, since initially

. By induction, we show

is a topologic

.

Assume that is in topological order at the b

al sort of {

eginn

, }.

ing

f h

f h

E

L G s t

L

• of

an iteration.

During the iteration, we perform pushes and relables.

Pushes do not create any admissible edges (Lemma 2).

By Lemma 3, Relabel( ) may create admissible edges

lea

u

ving , but after the relabel there will be no

admissible edge entering . By moving to the front

of , remains in topological order.

u

u u

L L

62

Initially, it

Proof of Lemma

is true since

5 (part 2). By inductio

is at the front o

n, we show that

vertices before have no excess

f .

Assume the property holds at the beginning of an

flo

it

w.

u

u

L•

• eration.

Let be the vertex that will be the in the next iteration.

We will show that no vertex before has excess flow.

If is moved to front, it has no excess flow (since it has

been d

u u

u

u

vertices before received no

addi

ischarged), and it is the only vertex before .

If is not moved to front,

and thus still have no excess, and itself

now

ti

ha

onal flow

s no excess.

u

uu

u

63

3 The running time of Relabel-to-Front is .

Proof.

The running time

the total number of iterations (discharges)

the time spent on executing the discharges

Theo

We first det

em.

e

r O V

O

2

rmine the number of discharges:

There are at most ( ) relabels.

Preceding each relabel there may be ( ) calls to

Discharge. Similarly, ( ) discharges after the last

relabel

O V

O V

O V

3

.

Thus, the total number of calls to Discharge is ( ).O V

64

3

Now we determine the total time spent within Discharge.

Total time for moving the pointer : .

Preceding each Relabel( ), it takes

time to move ( ).

)

(

current

u O V

curren u

O V

t

2

3

3

3

There are at most ( ) relabels.

Total time for relabels: .

Total time for satulating pushes: .

Total time for nonsatulating pushes: .

Each discha

( )

( ) ( )

rge

( )

has

O V

O VE O V

O V

O V

at most 1 nonsatulating push.

65