the max-flow problem defined on a capacitated directed graph g=(v,e,c). the capacities are...

53

Post on 21-Dec-2015

213 views

Category:

Documents


1 download

TRANSCRIPT

The max-flow problemThe max-flow problem

Defined on a capacitated directed graph G=(V,E,c).The capacities are non-negative.

1

1

1

1

1

1

2

G

s t

1 1

The flow function defined on the directed edges and fulfill:

- capacity constraint (flow capacities)eE : 0f(e)c(e)

- flow conservation (flow into a node= flow from a node)vV\{s,t}: (v,u)Ef(v,u) - (u,v)Ef(u,v)

The purpose is to find the maximum flow from the source to the sink.

1/1

G

s t

1/1

0/2

1/1

1/1

1/1

1/1

sourcesource sinksink

0/1 0/1

0),(:},{\),(

uvftsVv

Euv

),(),(:),( vucuvfEuv

f

),(),(),( vufuvfuvf

),(),(:),( uvfuvfEuv

),(),(

uvfEuv

The net flow from v is defined as .

Alternative definition for a flow functionAlternative definition for a flow function

Add the opposite edge if not exist with capacity 0 and define:

satisfies the following three constraints:

- capacity constraint. :

- flow conservation: .

- anti-symmetry: .

),( usfVu

The value of the flow is defined as .

First representation0),(&

),(),(

vuf

uvcuvf

),(),( uvcuvf ),(),( uvfuvc

),(),(),( vufuvfuvc

Edge is called saturated if

Residual capacity(Additional flow)

Second representation f

f

Ford&Fulkerson AlgorithmFord&Fulkerson Algorithm

Define Gf=(V,Ef) – the residual network.

Ef - the unsaturated edges with capacity cf(u,v)=c(u,v)-f(u,v)>0.

The idea is to make iterations of finding a flow augmenting path p from s to t in the residual network Gf, and updating Gf along p, until it can’t be done.

Ford&Fulkerson(G,s,t) 1. initalize flow f to 0 2. while there exists an augmenting path p (should find it first) 3. do augment flow f along p 4. return f

When no augmenting path exists, the current flow is maximum (Ford & Fulkerson Theorem).

Ford&Fulkerson AlgorithmFord&Fulkerson Algorithm

Ford&Fulkerson(G,s,t) 1. for each edge (u,v) Ef

2. do f(u,v)0 3. f(v,u)0 4. while there exists a path p from s to t in the residual network Gf

5. do cf(P) = min ePcf(e)>0

6. for each edge (u,v) in p do 7. f(u,v) f(u,v) - cf(P)

8. f(v,u) -f(u,v)

Comments:Comments: NoticeNotice that it is not certain that E = Ef,

as sending flow on (u,v) might close (u,v) (it is saturated),and may open a new edge (v,u) in the residual network.

For example: An edge (u,v) with flow 5 is equivalent, in a sense,to an opposite direction edge (v,u) with capacity equal to 5.

1

1 1

1s t1

0/1

s t

0/1

0/1

0/1

0/1

Ford&Fulkerson Algorithm Ford&Fulkerson Algorithm ExampleExample

GGGGGGffGGff

1

1 1

1s t1

0/1

s t

0/1

0/1

0/1

0/1

Ford&Fulkerson Algorithm Ford&Fulkerson Algorithm ExampleExample

GGGGGGffGGff

1

1 1

1s t1

0/1

s t

1/1

1/1

1/1

0/1

Ford&Fulkerson Algorithm Ford&Fulkerson Algorithm ExampleExample

GGGGGGffGGff

1

1 1

1s t1

0/1

s t

1/1

1/1

1/1

0/1

Ford&Fulkerson Algorithm Ford&Fulkerson Algorithm ExampleExample

GGGGGGffGGff

1

1 1

1s t1

Ford&Fulkerson Algorithm Ford&Fulkerson Algorithm ExampleExample

GGffGGff

0/1

s t

1/1

1/1

1/1

0/1

GGGG

1

1 1

1s t1

1/1

s t

1/1

0/1

1/1

1/1

Ford&Fulkerson Algorithm Ford&Fulkerson Algorithm ExampleExample

GGGGGGffGGff

1

1 1

1s t1

1/1

s t

1/1

0/1

1/1

1/1

Ford&Fulkerson Algorithm Ford&Fulkerson Algorithm ExampleExample

GGGGGGffGGff

Disadvantage of the algorithm:Disadvantage of the algorithm:

- Is finite only for integer capacities.- Finding an augmenting path is expensive. The time cost is O(|E|)=O(|V|2) for each iteration. (The bottleneck of the algorithm )

DA structure - DA structure - PHASEPHASE structure in generalstructure in general::

- At the beginning of phase, the extended BFS builds a layered network structure, of length l using the residual network Gf.

-A phase contains iterations, changing the flow using shortest augmenting paths of a fixed length l.

-The layered network is maintained during the phase as the union of all shortest augmenting paths of length l.

-When the layered network vanishes, there is no augmenting path of length l.

Therefore, at the next phase the length of the layered network > l .

),(ˆ tsL

DA structure - DA structure - ITERATION ITERATION structure in generalstructure in general ::

- Finding an augmenting path p at the layered network structure that was already built, in short time – O(l).

- Change the flow along the augmenting path p – O(l).

- Maintain the layered network using dead-end vertex removing. There is no need of building layered network from scratch. So at the next iteration, augmenting path finding will cost O(l) as well.

Layered network data structure for accelerating iterationsLayered network data structure for accelerating iterations

The bottleneck of the Ford&Fulkerson algorithm is the finding an augmenting path,with the time cost O(|E|)=O(|V|2), for each one. We use layered network data structure for accelerating iterations.

How layered network data structure is built?How layered network data structure is built?

- Run a special version of BFS from the source node at Gf. This version is called extended BFS. It adds allall edges from previous layer and not only the firstonly the first edge found.

This layered network is called L(s). This is the union of all the shortest paths from s. (Can be prove easily)

GGGGs t

BFS from BFS from ss in in GGBFS from BFS from ss in in GGs t

s t L(s)L(s) – extended BFSextended BFS from fromss in in GG

L(s)L(s) – extended BFSextended BFS from from ss in in GG

Extended BFS - DefinitionsExtended BFS - Definitions

dist(v,u) - distance between v and u . dist(v) = dist(s,v) .

Vi – the i layer: dist(v)=i vVi

Ei – edges from Vi-1 to Vi .

L(s) = (Vi , Ei) – the union of all shortest paths from s in the graph.

Running regularregular BFS time = Running extendedextended BFS time = O(|E|).

s t s ts t

GGGG BFS from BFS from ss in in GGBFS from BFS from ss in in GG L(s)L(s) – extended BFSextended BFS L(s)L(s) – extended BFSextended BFS

)(sLs t

Building network data structure – next stepBuilding network data structure – next step

Goal: Reduce the layered network so we will able continuancly to find an augmenting path in a short time.

How can it be done:Prune into ,That is the union of all the shortest paths from s to tt .This can be done using a BFS from t on L(s), in the opposite edge direction.

)(sL ),(ˆ tsL

)(sLs t

in thein the opposite edge directionopposite edge direction

Building network data structure – next stepBuilding network data structure – next step

Goal: Reduce the layered network so we will able continuancly to find an augmenting path in a short time.

How can it be done:Prune into ,That is the union of all the shortest paths from s to tt .This can be done using a BFS from t on L(s), in the opposite edge direction.

)(sL ),(ˆ tsL

s t )(sLBFS from BFS from tt in with the in with the opposite edge directionopposite edge direction

Building network data structure – next stepBuilding network data structure – next step

Goal: Reduce the layered network so we will able continuancly to find an augmenting path in a short time.

How can it be done:Prune into ,That is the union of all the shortest paths from s to tt .This can be done using a BFS from t on L(s), in the opposite edge direction.

)(sL ),(ˆ tsL

)(sL

),(ˆ tsL

s t

Building network data structure – next stepBuilding network data structure – next step

Prune into ,That is the union of all the shortest paths from s to tt .This can be done using a BFS from t on L(s), in the opposite edge direction.

s t

)(sL ),(ˆ tsL

Proof that network is the union of all the shortest paths from Proof that network is the union of all the shortest paths from ss to to tt

Proof that any shortest path from s to t is at .- For any shortest path from s to t, its i vertex is at distance i from s, While t is at distance l-i from it.

Proof that any path from s to t at at is at length of the shortest path from s to t. - For any vertex v in there is a path from s to t of length i and a path from v to t of length l-i.

- Their concatenation is a the shortest path going via v.

),(ˆ tsL

s t

GGGG

i=2 l-i=3-2=1

),(ˆ tsL

s t

i=2 l-i=3-2=1

),(ˆ tsL

),(ˆ tsL

Augmenting path finding and flow improvingAugmenting path finding and flow improving

- Just walk from s over . After l steps t is reached. This is the current augmenting path.

- Improve the flow with this augmenting path, and put the saturated edges into a list called sat.

- Update capacities in the sub layered network along the augmenting path.

- Remove saturated edges.

),(ˆ tsL

),(ˆ tsL

),(ˆ tsL

0s t

1

1

1

10

1

),(ˆ tsL

s t

1

1

1

1

1

),(ˆ tsL

1s t

1

2

1

11

1

Layered network maintenance – Cleaning dead ends.Layered network maintenance – Cleaning dead ends.- motivation (why should we do it)- motivation (why should we do it)

- After an edge removing we might have vertexes with no incoming edges. This kind of vertexes is called dead-ends vertex.

- We have to remove them, so the next augmenting path finding won’t got stuck and will work in short time – O(l) (l increased by one)

),(ˆ tsL

s t

Layered network maintenance – Cleaning dead ends. Layered network maintenance – Cleaning dead ends. - how should it be done.- how should it be done.

- Initialize two queues Ql and Qr by the list of saturated edges sat that were removed.

- Define two procedure RightPass and LeftPass:

-The graph cleaning consists of a loop of RightPass and LeftPass. It might remove all the edges of the graph. Then it reports on its vanishing.

),(ˆ tsL

s t

),(ˆ tsL

s tRightPass

Layered network maintenance – Cleaning dead ends. Layered network maintenance – Cleaning dead ends. - comments and additional information.- comments and additional information.

- No path from s to t could be removed. Any element that was removed is absent in all path from s to t

- The cleaned layered network, if not vanished, has some useful properties as the original layered network:

- Next augmenting path of length l can be fount at O(l). - The next founded path is truly augmenting path, it means that all its edges are not saturated by the current flow.

Algorithm AnalysisAlgorithm Analysis

Constructing of the layered network using two BFS, at the beginning of a phase costs O(|E|).

Algorithm AnalysisAlgorithm Analysis

Augmenting path finding using walk from s over the layered network costs O(l)=O(|V|) every time thanks to the cleaning maintenance .

Algorithm AnalysisAlgorithm Analysis

The path length at the iteration number l is l, so flow updating costs O(l)=O(|V|) as well.

Algorithm AnalysisAlgorithm Analysis

Remove edge = O(1);Checking edges’ two end vertices = O(1);Checking if the list is empty = O(1);

Algorithm AnalysisAlgorithm Analysis

In practice a single iteration might cost Omega(|E|+|V|) because we should remove every edge and vertex from the graph.Omega(|E|+|V|)= O (|E|) because the network is connected

Remove edge = O(1);Checking edges’ two end vertices = O(1);Checking if the list is empty = O(1);

Algorithm AnalysisAlgorithm Analysis

s

In practice a single iteration might cost Omega(|E|+|V|) because we should remove every edge and vertex from the graph.Omega(|E|+|V|)= O (|E|) because the network is connected

Algorithm AnalysisAlgorithm Analysis

- The cost of a Phase is:Constructing of the layered network = O(|E|).Maintenance of the layered network = O(|E|).

- The cost of a Iterations is:Path finding and capacity updating = O(l)=O(|V|).

====================================================

- The cost of DA is: O( [total number of iterations] x |V| + [number of phases] x |E| ).

- The cost of FF is: O( [number of iterations] x |E| ).

Next, we should evaluate the number of phases at DA algorithm.

Proposition:Proposition:After any iteration in the phase of DA with the layered network of length l, the updatedlayered network is the union of all augmenting paths of length l, while there is noshorter augmenting path.

Conclusion:Conclusion:The length of the layered network grows strictly from phase to phase.

After any iteration, if the layered network hasn’t vanished we get two kinds of paths:““Old path”: Old path”: consists of existed edges.““New path”:New path”: consists of at least one added edge, which was added

when the edge opposite direction was added.

s t s t

New pathAugmenting path

Proof that anProof that an “old” path “old” path P’P’ is at least is at least ll long long

d(v) – distance of v from s at the beginning of a phase

- Flow on (v,u) is increased only if d(u)=d(v)+1.- Flow on (u,v) is decreased only if d(v)=d(u)-1– and they are called “new edges”.- The removed edge from gf can’t be restored during the same phase.

-P is an “old” path of length l. If it is assumed that P contained in at the beginning of a phase and after some iteration in Gf, then no edges were saturated. P contained in current layered none edges were saturated P in Gf.

There is no augmenting old path of length shorter then l.

Proof that “new” path P’ is at least l+2 longProof that “new” path P’ is at least l+2 longAssume P’ has k new edges. P’ new k>0. d(node) increases by exactly 1 on new edges.d(node) decreases by at most 1 on old edges.d(t)=l and P’ has k new edges so P’ has to have at least l+k old edgesThe length of P’ is at least l+2k ≥ l +2.

Thus, after any iteration of the phase, there is no augmenting path of length less than l,If there are paths of length l they are contained in

At the end of a phase, since does not contain paths of length l, then also Gf does not contain paths of length at most l, by the above proposition.

The length of the layered network grows from phase to phase.

s t s t New path

Augmenting path

+1+1

+1

-1

+1

Algorithm AnalysisAlgorithm Analysis

- At most |E| edges are being removed during a phase There are at most |E| iterationsduring a phase

Algorithm AnalysisAlgorithm Analysis

Constructing of the layered network = O(|E|)

Path finding and capacity updating =O(l)=O(|V|).It is done at most |E| times furing a phase.

Maintenance of the layered network = O(|E|).

So phase costs O(|E|+|E||V|+|E|)=O(|E||V|)

Algorithm AnalysisAlgorithm Analysis

- Distance(s,t)|V|-1 There are at most |V|-1 phases in DA

Algorithm AnalysisAlgorithm Analysis

DA running time is O(|E||V||V|) = O(|V|2|E|)

The version of Shimon Even and Alon ItaiThe version of Shimon Even and Alon Itai

- Using the L(s) graph that has been built using BFS until the i level instead of using both L(s) and .

- Canceled Cleaning procedure. Instead of removing the dead ends, use the “burn their bridges behind them principle”: When a dead end is found, go backward and, in addition, remove that edge from L(s).

- Scan graph L(s) using DFS with backtracking when needed, until vertex t is found or the graph is vanished.

The version of Shimon Even and Alon Itai - AnalysisThe version of Shimon Even and Alon Itai - Analysis

- The running time of a phase is counted as intervals between events of two types: *** Finding an augmenting path. *** Arrivals at a dead end.

How much events are there?- At most |E| such events because each one of them causes the removing of an edge.

What is the time cost between two events?- At most l forward steps between edge removing- costs O(l). Besides forward steps there are backward steps, but a backward step cause an edge removing so the cost of both are O(l). If we found the path for t vertax we have to remove the saturated edges along the founded path – costs O(l). However, the total cost of between two events - O(l).

- This version of DA running time is O( l ·|E|) =O(|V||E|) per phase.

The implementation of DA by CherkasskyThe implementation of DA by Cherkassky

Further progress of Max-Flow FindingFurther progress of Max-Flow Finding

- Edmons’ and Karp’s version of Ford&Fulkerson- (|V||E|2)=O(|V|5)(which is higher then O(|V||E|2)=O(|V|5) of DA).

- Karzanov’s Algorithm- O(|V|3)

- Cherkassky –

- Galil –

- Galil and Naaman -

- Sleator and Tarjan –

- Goldberg and Rao - Where U is the maximal capacity.

Unless U is very big number, this time bound is better then O(|V||E|)

)|||(| 2 EVO

)|||(| 3/23/5 EVO

|)|log|||(| 2 VVEO

|)|log|||(| VVEO

|))|/|log(|||log||}||,|(min{| 23/22/1 EVUEVEO