Dinitz's algorithm for finding a maximum flow in a network. - PowerPoint PPT Presentation

View by Category
About This Presentation
Title:

Dinitz's algorithm for finding a maximum flow in a network.

Description:

A flow f, is defined as a function on the directed edges satisfying the following: ... The goal is to find the maximum flow from the source to the sink. 5. DA ... – PowerPoint PPT presentation

Number of Views:1822
Avg rating:3.0/5.0
Date added: 30 June 2020
Slides: 85
Provided by: bobby87
Learn more at: http://www.cs.bgu.ac.il
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Dinitz's algorithm for finding a maximum flow in a network.


1
Dinitz's algorithm for finding a maximum flow
in a network.
  • Presented by
  • Ilan Kadar and Sivan Albagli

June 30, 2020
2
Content
  • Introduction
  • Ford and Fulkerson Algorithm
  • Original Dinitz algorithm

2
2
June 30, 2020
DA
3
IntroductionThe max flow problem definition
  • Capacitated directed graph G(V,E,c,s,t).
  • The capacities are non-negative.

2
1
3
3
June 30, 2020
DA
4
IntroductionThe max flow problem definition
  • A flow f, is defined as a function on the
    directed edges satisfying the following
  • Capacity constraint ?e?E 0?f(e)?c(e)
  • Flow conservation ?v?V\s,t ?(v,u)?Ef(v,u) -
    ?(u,v)?Ef(u,v)0

4
4
June 30, 2020
DA
5
IntroductionThe max flow problem definition
  • The goal is to find the maximum flow from the
    source to the sink.

Q How do we know that the flow is maximum?
5
5
June 30, 2020
DA
6
IntroductionMotivation
  • Finding the maximal way to ship goods from a set
    of factories to a set of stores.
  • Bipartite matching

6
6
6
June 30, 2020
DA
7
IntroductionNaïve algorithm
A
2
2
S
t
2
4
3
B
7
7
7
June 30, 2020
DA
8
IntroductionNaïve algorithm
A
2
2
S
t
2
4
3
B
8
8
8
June 30, 2020
DA
9
IntroductionNaïve algorithm
A
2/2
0/2
S
t
2/2
2/4
0/3
B
9
9
9
June 30, 2020
DA
10
IntroductionNaïve algorithm
A
2/2
0/2
S
t
2/2
2/4
0/3
B
10
10
10
June 30, 2020
DA
11
IntroductionNaïve algorithm
There is no path where one can increase the flow
Therefore, the algorithm terminates
11
11
11
June 30, 2020
DA
12
IntroductionNaïve algorithm
Is it the maximum flow?
A
2/2
0/2
(Flow value 4)
S
t
2/2
4/4
2/3
B
12
12
12
June 30, 2020
DA
13
IntroductionNaïve algorithm
Maximum flow 5
13
13
13
June 30, 2020
DA
14
IntroductionEquivalent flow function
  • For each edge add ,
  • if doesnt exists, with capacity and flow
    zero.

0
0
5
0
1
8
source
sink
s
t
1
2
0
2
G
0
0
14
14
14
June 30, 2020
DA
15
IntroductionEquivalent flow function
  • Define for each edge

15
15
15
June 30, 2020
DA
16
IntroductionEquivalent flow function
v
DA
June 30, 2020
17
IntroductionEquivalent flow function
  • satisfy the following constraints
  • Capacity constraint

17
17
17
DA
June 30, 2020
18
IntroductionEquivalent flow function
  • satisfy the following constraints
  • 2. Skew symmetry

18
18
18
June 30, 2020
DA
19
IntroductionEquivalent flow function
  • satisfy the following constraints
  • 3. Flow conservation

19
19
19
June 30, 2020
DA
20
IntroductionEquivalent flow function
  • The net flow from v is defined as
  • The flow value is defined as the net flow from s

20
20
20
June 30, 2020
DA
21
IntroductionEquivalent flow function
Edge is called saturated if Residual capacity (possibility to add flow)
1st representation
2nd representation
21
21
21
June 30, 2020
DA
22
IntroductionEquivalent flow function
Edge is called saturated if
saturated
saturated
DA
June 30, 2020
23
IntroductionEquivalent flow function
Unsaturated edges
unsaturated
unsaturated
DA
June 30, 2020
24
IntroductionEquivalent flow function
Residual capacity (possibility to add flow)
cf 5-324
cf
cf 5-14
cf
DA
June 30, 2020
25
IntroductionEquivalent flow function
We will use the second representation,
denoting it by f
DA
June 30, 2020
26
Ford and FulkersonAlgorithm
Define Gf(V,Ef) the residual network. Ef
- the unsaturated edges with capacity cf(u,v)c(
u,v)-f(u,v)gt0.
2
1
-1/0
-2/0
1
-1/0
1
0/0
-1/0
DA
June 30, 2020
27
Ford and FulkersonAlgorithm
A path is an augmenting path if it contains only
unsaturated edges. for example
DA
June 30, 2020
28
Ford and FulkersonAlgorithm
FordFulkerson(G,s,t) 1. initialize flow
f(v,u) to 0 2. while there exists an
augmenting path P do 3. augment flow
f along P 4. return f
Published in 1956
When no augmenting path exists, the current flow
is maximum (Ford Fulkerson Theorem).
DA
June 30, 2020
29
Ford and FulkersonAlgorithm
FordFulkerson(G,s,t) 1. for each edge
(u,v)? Ef do 2. f(u,v)?0 3.
f(v,u)?0 4. while there exists a path P from s
to t in the Gf do 5. cf(P) min
e?Pcf(e)gt0 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) - cf(P)
DA
June 30, 2020
30
Ford and FulkersonAlgorithm
Comments Notice 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.
DA
June 30, 2020
31
Ford and FulkersonExample
DA
June 30, 2020
32
Ford and FulkersonExample
First iteration
DA
June 30, 2020
33
Ford and FulkersonExample
First iteration continue
DA
June 30, 2020
34
Ford and FulkersonExample
First iteration continue
DA
June 30, 2020
35
Ford and FulkersonExample
Second iteration
DA
June 30, 2020
36
Ford and FulkersonExample
Second iteration-continue
DA
June 30, 2020
37
Ford and FulkersonExample
There is no path at the residual network Gf The
flow is maximal
DA
June 30, 2020
38
Ford and FulkersonTime analysis
  • With rational capacities, the algorithm will
    always terminate.
  • With irrational capacities, the algorithm may run
    forever.
  • Runtime is bounded by O(Ef) when the
    capacities are integers.

DA
June 30, 2020
39
Ford and FulkersonProblem 1 (Integer case)
  • The algorithm runs in pseudo polynomial time

How many iterations??
DA
June 30, 2020
40
Ford and FulkersonProblem 1 (Integer case)
  • The algorithm runs in pseudo polynomial time

How many iterations??
2,000,000
DA
June 30, 2020
41
Ford and FulkersonProblem 2 (General case)
  • Convergence isnt guaranteed

DA
June 30, 2020
42
Ford and FulkersonOpen question?
  • The question of the existence of a polynomial, or
    finite algorithm, for the general case, remained
    open, for almost 10 years.
  • This was settled by Edmonds and Karp and by Y.
    Dinitz independently, at the late 60s.
  • Both algorithms are modifications of FF.

DA
June 30, 2020
43
Ford and FulkersonEdmonds-Karp(1972)
  • A small fix to the Ford-Fulkerson algorithm makes
    it work in polynomial time.
  • Compute the augmenting path using BFS on the
    residual network.
  • Run in time O(VE2)

DA
June 30, 2020
44
Dinitz AlgorithmA Historical Remark
  • The DA was invented in response to a
    pre-class-exercise in Adelson-Velskys
    Algorithm class.

At that time, the author was not aware the basic
facts regarding FF
DA
June 30, 2020
45
Dinitz AlgorithmMotivation
  • All parts of an iteration of FF except of finding
    an augmenting path P cost O(P).
  • Finding an augmenting path is the bottleneck of
    an iteration O(E).
  • Improving FF by using a smart data structure.

DA
June 30, 2020
46
Dinitz AlgorithmMotivation
  • Example BFS Tree

DA
June 30, 2020
47
Dinitz AlgorithmMotivation
  • Example BFS Tree

DA
June 30, 2020
48
Dinitz AlgorithmMotivation
DA
June 30, 2020
49
Dinitz AlgorithmMotivation
s and t become disconnected in the BFS tree!
DA
June 30, 2020
50
Dinitz AlgorithmExtended BFS
Dist dist from s
Dist2
Dist3
Dist4
Dist1
Dist3
Dist2
Dist3
Dist1
Dist2
Extended BFS includes the first edge found,
leading to each vertex from the previous layer.
DA
June 30, 2020
51
Dinitz AlgorithmLayered Network L(s)
V4
V0
V3
V1
V2
Vi is the set of all nodes with distance i from
s Ei is the set of all edges going from Vi-1 to
Vi
DA
June 30, 2020
52
Dinitz AlgorithmLayered Network L(s)
V4
V0
V3
V1
V2
L(s) (?Vi , ?Ei) the union of all shortest
paths from s in the graph.
DA
June 30, 2020
53
Dinitz AlgorithmLayered Network Definitions
  • Vi The i layer dist(v)i ? v?Vi
  • Ei Edges from Vi -1 to Vi
  • L(s) (?Vi , ?Ei) the union of all
    shortest paths from s in the graph.

Running time of regular BFS Running time of
extended BFS
DA
June 30, 2020
54
Dinitz AlgorithmLayered Network
DA
June 30, 2020
55
Dinitz AlgorithmLayered Network next step
Goal we want to maintain our data structure as
the union of all the shortest paths from s to t.
How can it be done? Prune into Run
extended BFS from t on L(s), in the opposite edge
direction
DA
June 30, 2020
56
Dinitz AlgorithmLayered Network next step
How can it be done? Prune into
L(s) in the opposite edge direction
Then run BFS from t on L(s)
DA
June 30, 2020
57
Dinitz AlgorithmLayered Network next step
How can it be done? Prune into
DA
June 30, 2020
58
Dinitz AlgorithmLayered Network
  • Claim
  • is the union of all the shortest paths
    from s to t(Invariant).
  • Property of
  • Doesn't have vertices with no any incoming edge,
    except s.
  • Doesnt have vertices with no any outgoing edge,
    except t.

DA
June 30, 2020
59
Dinitz AlgorithmAugmenting path finding
  • Just walk from s over . After l steps
    t is reached.

1
1
2
2
1
1
1
DA
June 30, 2020
60
Dinitz AlgorithmAugmenting path finding
  • Remove the saturated edges.

1
1
2
2
1
1
1
DA
June 30, 2020
61
Dinitz Algorithm Augmenting path finding
  • Just walk from s over . After l steps
    t is reached

1
1
1
1
1
1
DA
June 30, 2020
62
Dinitz AlgorithmCleaning dead ends
  • We might have vertices without outgoing edges
    called the dead-ends vertices.
  • We wish to remove them, so the next augmenting
    path finding from s wont get stuck and will work
    in O(l) time.

DA
June 30, 2020
63
Dinitz AlgorithmCleaning dead ends
  • Initialize two queues Ql and Qr by the list of
    saturated edges sat that were removed.
  • Define two procedures
  • Left pass
  • Right Pass

DA
June 30, 2020
64
Dinitz AlgorithmCleaning dead ends Left Pass
1
1
2
2
1
1
1
(d,t)
Ql
DA
June 30, 2020
65
Dinitz Algorithm Cleaning dead ends Left Pass
1
1
2
2
1
(c,d)
1
(a,d)
Ql
DA
June 30, 2020
66
Dinitz Algorithm Cleaning dead ends Left Pass
1
1
2
1
(s,c)
Ql
DA
June 30, 2020
67
Dinitz Algorithm Cleaning dead ends Left Pass
1
1
2
(s,c)
Ql
DA
June 30, 2020
68
Dinitz AlgorithmCleaning dead ends
  • After applying LeftPass all the vertices(except
    t) have outgoing edge.
  • After applying RightPass all the vertices(except
    s) have incoming edge.
  • Why we need both procedures???

DA
June 30, 2020
69
Dinitz AlgorithmCleaning dead ends
  • No path in the layered network from s to t could
    be removed.
  • Next augmenting path of length l can be found in
    O(l) time incase the cleaned layer is not
    vanished.

DA
June 30, 2020
70
Dinitz AlgorithmThe original algorithm
Phase
Iteration
DA
June 30, 2020
71
Dinitz AlgorithmThe original algorithm
Constructing of the layered network using two
BFS-es, at the beginning of a phase costs
O(E).
Phase
Iteration
DA
June 30, 2020
72
Dinitz AlgorithmThe original algorithm
Phase
Augmenting path finding using a walk from s over
the layered network costs O(l)O(V) every time
thanks to the cleaning maintenance .
Iteration
DA
June 30, 2020
73
Dinitz AlgorithmThe original algorithm
Phase
Flow updating costs O(l)O(V) as well.
Iteration
DA
June 30, 2020
74
Dinitz AlgorithmThe original algorithm
Phase
Cleaning dead ends vertices
Iteration
DA
June 30, 2020
75
Dinitz AlgorithmThe original algorithm
Phase
In practice a single iteration might cost
O(EV) because we should remove every edge
and vertex from the graph.
Iteration
DA
June 30, 2020
76
Dinitz AlgorithmTime analysis
  • Cost of the algorithm

O(iterations V Phases E)
E
V
How many Iterations? How many Phases?
DA
June 30, 2020
77
Dinitz AlgorithmTime analysis
  • Intuition After any iteration, there is no
    augmenting path of length less then l.

s
t
Augmenting path
New path
DA
June 30, 2020
78
Dinitz AlgorithmTime analysis
  • If there are paths of length l they are contained
    in

s
t
Augmenting path
New path
DA
June 30, 2020
79
Dinitz AlgorithmTime analysis
  • In the end of the phase(when the layer vanish),
    doesnt contain paths of length l.
  • We can prove that the residual network doesnt
    contain paths of length l.
  • Conclusion The length of the layered network
    grows from phase to phase.

DA
June 30, 2020
80
Dinitz AlgorithmTime analysis
- In every iteration at least one edge is being
removed (min edge of path augmenting). - At
most E edges are being removed during a phase
? There are at most E iterations during a
phase.
Phase
Iteration
DA
June 30, 2020
81
Dinitz Algorithm Time analysis
Constructing of the layered network
O(E) Path finding and capacity updating
O(l)O(V). It is done at most E times during
a phase. Maintenance of the layered network
O(E). So, a phase costs O(EEVE)O(E
V).
Phase
Phase
Iteration
DA
June 30, 2020
82
Dinitz AlgorithmTime analysis
- Distance(s,t)?V-1 ? There are at most V-1
phases in DA
Phase
Iteration
DA
June 30, 2020
83
Dinitz AlgorithmTime analysis
DA running time is O(EVV) O(V2E)
Phase
Iteration
DA
June 30, 2020
84
Further Progress
Time Method Discover Year
O(V E2) Shortest Path Edmonds and Karp 1972
O(V3) Preflow-push Karzanovs Algorithm 1974
Dynamic trees Sleator-Tarjan 1983
FIFO preflow-push Goldberg-Tarjan 1986
Length function Goldberg-Rao 1997
About PowerShow.com