Document

advertisement
Lecture 9: Finding Max Flows:
The Ford-Fulkerson Labeling
Algorithm
(Chapter 6, Sections 2–3)
1
The Maximum Flow Problem
Given: Directed network G = (N, A) in which each arc (i, j)
has an associated capacity uij , source node s and sink
node t.
(s, t)-flow: xij , (i, j) ∈ A, satisfying
∑
∑
xij =
j∈A(i)
xji s ̸= i ̸= t
j∈B(i)
0 ≤ xij ≤ uij
(i, j) ∈ A
value of flow:
v = v(x) =
∑
xsj −
j∈A(s)
=
∑
j∈B(t)
∑
fjs
j∈B(s)
xjt −
∑
xtj
j∈A(t)
Find: (s, t)-flow in G having the maximum value.
2
Example Network and Flow
xij , uij
2
7,8
7,10
0,1
1
5,6
3
4
5,10
2
8,8
7,10
1,1
1
6,6
3
4
5,10
Standard Flow Increase
Is this a max flow?
3
Finding Max Flows:
The Residual Network
How do we keep track of further flow increases in the network?
residual arc: indicates how much flow can be increased in
that direction.
residual arcs associated with arc (i, j) having capacity uij
and flow xij :
residual arc conditions residual capacity
(i,j)
xij < uij rij = uij − xij
(j,i)
xij > 0
rji = xij
uij − xij
xij , ,uij
j
i
j
i
xij
4
6 , 10
i
j
j
i
6
4
The Residual Network
The residual network with respect to flow x is the network
G(x) of residual arcs with their associated residual capacities.
2
7,8
7,10
0,1
1
4
5,6
5,10
3
Initial flow
2
1
3
7
7
1
4
1
1
5
5
5
3
Residual network
5
The Archive Procedure ResidualNetwork
Input: Directed network G with arc capacities G.arc(a).u and
arc flows G.arc(a).x
Output: Residual network Gr with residual capacities Gr.arc(a).r,
along with the link Gr.arc(a).orig to the index of the arc
in G associated with residual arc a in Gr.
Example: Given the following flow in our network
2
a1
Gr.arc(i).r
a3
8,8
8,10
2
a4
8
8
0,1
1
2
1
4
4
1
4
6,6
6
6,10
a2
3
6
a5
3
Residual network
Flow
The call Gr=ResidualNetwork(G) gives network
>> DisplayNetwork(Gr,{},{’r’,’orig’})
Arc Data:
index
1
2
3
4
5
6
7
tail
1
2
3
4
3
3
4
head
2
1
1
2
2
4
3
r
2
8
6
8
1
4
6
6
orig
1
1
2
3
4
5
5
Augmenting Paths in the Residual Network
Fact: Any (s, t)-path Γ in G(x) corresponds to a path
along which flow can be increased. We call Γ an
augmenting path with respect to flow x.
This corresponds to an (s, t)-path Γ0 in G whose
forward arcs have xij < cij , and whose backwards arcs have xij > 0.
residual capacity of Γ:
δ(Γ) = min{rij : (i, j) ∈ Γ}
augmenting along Γ: Send ∆ = δ(Γ) units of flow
along Γ. In Γ0 this corresponds to increasing flow
by ∆ along forward arcs of Γ0 and decreasing
flow by ∆ along backward arcs of Γ0.
modifying the residual capacities: For each arc
(i, j) ∈ Γ set
′
rij′ = rij − ∆, rji
= rji + ∆
Idea: Find max flow by repeatedly finding and augmenting along augmenting paths.
7
The Ford-Fulkerson
Max Flow Algorithm
Given: Capacitated source-sink network G
Find: Maximum (s, t)-flow in G
The Algorithm:
Initialize: Set initial flow x0 ≡ 0 and create initial
residual network G(x0);
while there is at least one directed (s, t)-path in G(x);
begin
find a directed directed (s, t)-path Γ in G(x);
determine ∆ = δ(Γ) and send ∆ units of
flow along Γ;
update all rij ’s, modifying G(x) accordingly.
end
8
Example
Starting with the given residual network
Residual network
Flow
2
2
1
3
7
1
4
1
1
∆=1
5
5
3
2
2
7
4
1
∆=1
1
1
5
6
8
7
8
6
5
3
2
2
1
4
1
0
1
4
6
8
8
8
8
6
6
3
4
6
3
9
4
5
3
2
4
5
3
3
1
0
1
5
5
7
7
7
How Do We Know That x is a Max Flow?
1. No more augmenting paths exist in G(x).
2. An (s, t)-cut exists in G(x) that contains no arcs.
Residual network
Flow (with capacities)
2
2
2
8
8
1
4
1
0,1
1
4
6
8,8
8,10
6,6
6
3
4
6,8
3
Question: What does this mean in the original network
G?
Definition: For any (s, t) cut (X, X̄) in G, define the capacity of (X, X̄) to be
u(X, X̄) = {uij : i ∈ X, j ∈ X̄}
For example, the cut above has capacity
u13 + u24 = 14
10
Weak Duality Theorem for
the Max Flow Problem
For any feasible flow x in G and any (s, t)-cut (X, X̄) in G,
the value v(x) of the flow is at most the capacity of cut
(X, X̄), and if v(x) = u(X, X̄) then the flow x is a max
flow and the cut (X, X̄) is a minimum capacity cut.
Proof: Define the flow across (X, X̄) to be
∑
∑
xij −
x(X, X̄) =
(i,j)∈(X,X̄)
xji
(j,i)∈(X̄,X)
By adding the flow equations across all i ∈ X (including s)
we get
x(X, X̄) = v(x)
But now note that
x(X, X̄) =
≤
∑
xij −
∑
(i,j)∈(X,X̄)
(j,i)∈(X̄,X)
∑
∑
(i,j)∈(X,X̄)
uij −
xji
0
(j,i)∈(X̄,X)
= u(X, X̄)
so that v ∗(x) ≤ u(X, X̄). Further, if v ∗(x) = u(X, X̄) then
it must be that x is a max flow and (X, X̄) is a min cut
(why?).
11
(∗)
The Max Flow Min Cut Theorem
For any source-sink capacitated network G, the maximum
value of an (s, t)-flow in G is equal to the minimum capacity
of an (s, t)-cut in G.
Proof: At the end of the Ford-Fulkerson algorithm, we have
a flow x∗ and an associated (s, t)-cut (X ∗, X̄ ∗) in G(x) with
no arcs. Then (X ∗, X̄ ∗) corresponds to a cut in G that satisfies
xij = uij for every arc (i, j) ∈ (X ∗, X̄ ∗)
xji = 0 for every arc (j, i) ∈ (X̄ ∗, X ∗)
It follows that the inequality (∗) is an equality, and the theorem follows.
12
Computational Complexity of the
Ford-Fulkerson Algorithm
Let all capacities be integer, and let U be the size of the
largest capacity of an arc in G, and let v ∗ be the value of
the max flow. Then v ∗ ≤ nU , and so the Ford-Fulkerson
Algorithm ends after O(v ∗) = O(nU ) flow augmentations,
for a total of O(mnU ) time (pseudopolynomial). However,
consider the following network:
uij
2
M
M
1
4
1
M
M
3
where M is a large number. This has max flow 2M , and if we
augmented alternately along the augmenting paths 1 − 3 −
2 − 4 and 1 − 2 − 3 − 4, we would take 2M flow-augmenting
steps to reach this max flow, exponential in the size of the
input. This is in spite of the fact that it takes only 2 flow
augmentation steps (along 1 − 2 − 4 and 1 − 3 − 4 to reach
the max flow.
To get polynomial-time algorithms, we must be careful how
we choose our augmenting paths.
13
Combinatorial Applications of Max-Flow
Min-cut
Network Invulnerability: Another measure of invulnerability of a network G is the minimum number of
arcs whose removal disconnects s from t.
Question: What is the relationship between this and the
maximum number of disjoint (s, t)-paths in G?
Menger’s Theorem (arc version): These two numbers
are equal.
Proof: We know that the maximum number of disjoint
(s, t)-paths in G is equal to the value of the maximum
(s, t)-flow with all capacities set to 1. By the Max-Flow
Min-Cut Theorem, this value is equal to the minimum
capacity=cardinality of an (s, t)-cut in G. Since any set
of arcs that disconnect s from t must contain at least
one (s, t)-cut (Why?) then this is also the minimum
cardinality of a set of arcs disconnecting s from t.
14
The Max-Flow Min-Cut Theorem with node capacities: In network G with node and arc capacities,
the maximum (s, t)-flow in G is equal to the minimum
capacity of a set of nodes and arcs whose removal disconnects s from t
Proof: (Exercise, follows from the node capacity transformation given in the last lecture.)
Menger’s Theorem (node version): Suppose G has no
arcs directly from s to t. Then the maximum number
of node-disjoint (s, t) paths in G is equal to the minimum number of nodes whose removal disconnects s
from t.
15
Min Cuts and the Feasibility Problem
For any subset S of nodes define the net demand of S to
be
∑
b(S) =
bi
i∈S
The Feasibility Theorem: Let G be a capacitated networks with here exists a feasible flow in G if and only
if there exists no cut (X, X̄) having
−b(X̄) > u(X, X̄)
Proof: Exercise. Note that the Feasibility Theorem also
applies when supplies represent upper bounds.
16
Example
Suppose in our feasibility example we changed the capacity
of arc (2, 4) to 2.
−2
2
2
5
1
9
4
2
4
−8
6
3
1
2
5
t
2
2
2
2
4
1
7 8
4
2 0
4
9 8
s
4
1
1
5
3
Then we have −b({3, 4}) = −(1−8) > 4+2 = u({1, 2}, {3, 4})
17
Cardinality Matchings
node cover: set C of nodes of G such that each arc of G
has at least one endpoint in G.
The König-Egerváry Graph Theorem: For any bipartite graph G, the maximum cardinality of a matching
in G is equal to the minimum cardinality of a node cover
for G.
Proof: For any matching M and cover C, |M | ≤ |C|, since
every edge of M must have at least one endpoint in
C. Now formulate the associated capacitated max flow
graph F for G as was done in the previous lecture, so that
the maximum (s, t)-flow in F is equal to the maximum
cardinality of a matching in G. Further, by the MaxFlow Min-Cut Theorem this is equal to the minimum
capacity=cardinality of an (s, t)-cut (X, X̄) in F .
18
Now (X, X̄) can contain no arcs of G, since these arcs
all have infinite capacity. It follows that all arcs of G
either come from X̄ ∩ S, or go to X ∩ T . Thus C =
(X̄ ∩ S) ∪ (X ∩ T ) comprises a node cover of G. Further
the cardinality of C is equal to the cardinality of the
set of arcs from s to X̄ ∩ S together with those from
X ∩ T , which is precisely the cardinality=capacity of
the (s, t)-cut in F .
5
1
1
1
1
s
2
6
1
t
1
7
3
1
1
1
4
8
19
The ACC Tournament Problem
Consider the problem of determining whether Georgia
Tech. can win the ACC regular season title outright after Maryland beats NC State. Since GT’s constructed
flow problem is infeasible, then by the Feasibility Theorem there exists a set S = SG ∪ ST of game and team
nodes such that
−b(S) = −b(SG) − b(ST ) > u(X, X̄).
Now since all arc capacities are infinite, then the only
way u(X, X̄) could be finite is if it contained no arcs,
that is, all of teams playing the games in SG are in
ST . This makes u(X, X̄) = 0, and so it must be that
−b(SG) > b(ST ), or equivalently, that the number of
games played in SG exceeds the total supply available at
ST .
This is summarized in the following result.
Proposition: The tournament problem has a feasible
solution if and only if there does not exist a set ST
of teams such that the set SG of games to be played
between those teams has cardinality that is strictly
less than the total number of excess wins available to
teams in ST .
20
Cl−Duke
Cl−FS
1
1
1
Cl−UNC
1
Cl−UVa
1
Cl−WF
1
Duke−FS
1
Duke−Md 1
Duke−NCSU 1
Duke−UNC 1
Duke−UVa 1
Cl−Md
2
Cl
8−8
1
Duke
5
FS
8−8
8−8
GT
FS−Md
9−7
FS−NCSU
s
2
Md
7
NCSU
5
UNC
3
UVa
0
WF
FS−UNC
8−8
FS−WF
1
1
1
1
7−9
demand
8−8
8−8
1
Md−UNC 1
Md−UVa
1
NCSU−UNC 1
NCSU−UVa 1
Md−NCSU
8−8
supply
A Feasible Flow
21
NCSU−WF
1
UNC−UVa
1
UNC−WF
1
UVa−WF
1
t
Cl−Duke
Cl−FS
1
1
no flow!
Cl−Md 1
1
1
Cl−WF 1
Duke−FS 1
Duke−Md1
Duke−NCSU 1
Duke−UNC1
Duke−UVa1
Cl−UNC
Cl−UVa
Cl
6−4
2
2
Duke
7−3
1
1
5
5
FS
3−7
GT
1
1
FS−UNC 1
FS−WF 1
FS−Md
9−7
s
1
FS−NCSU
1
Md
7−4
7
NCSU
5
5
3
5
0
t
1−10
demand
UNC
3−6
3 UVa
5−5
Md wins!
Md−NCSU
0
WF
8−3
Md−UNC 1
Md−UVa 1
1
NCSU−UVa 1
NCSU−UNC
NCSU−WF
17 games left to give
among these teams
1
UNC−UVa1
18 games
between these teams!
UNC−WF1
UVa−WF 1
Example: Suppose Maryland Beats State
22
A Mining Problem
The Stripper Mining Company wants to dig an open-pint
mine on a tract of land. The geological surveyors have divided
the subterranean region into sectors, and have estimated the
cost of digging out that sector and the profit of ore obtained
from that sector. The diagram below gives the net worth of
digging out that sector (negative means a net cost):
A
−10
E
B
4
H
−5
F
5
C
−1
I
−4
G
D
−6
7
12
A sector cannot be dug out until the sectors lying on top of
it have been dug out. What sectors should be dug out so as
to maximize the net profit of mining this tract?
23
The Maximum Weight Closure of an
Acyclic Network
Given: Acyclic network G = (N, A) with node weights
(positive and negative) wi, i ∈ N .
closure set (upper ideal, filter): set F of nodes such
that if u is in F and (u, v) is an arc then v is in F .
Find: The maximum weight closure set in G.
In the mining case, G has nodes corresponding to
the sectors, and arcs from each sector to the sectors
immediately above it. Then the closure F corresponds
to the set of sectors being dug out.
24
Modeling the Closure Problem as a
Max Flow Problem
1. Let S = {i : wi ≥ 0} and T = {i : wi < 0}
2. Add a super source s and arcs (s, i), i ∈ S with capacity
wi.
3. Add a super sink t and arcs (i, t), i ∈ T with capacity
−wi.
4. All arcs in the original network have infinite capacity.
5. Determine a max (s, t)-flow, and a corresponding (s, t)cut (X, X̄).
The min cut (X, X̄) again must have the property that no
original arc can cross (X, X̄), so that the nodes in X constitute a closure set in G.
Now the capacity of the cut (X, X̄) is
∑
∑
wi +
(−wi)
i∈S∩X̄
=
=
∑
i∈S
∑
wi −
(i∈T ∩X
∑
i∈S∩X
wi +
∑
)
wi
i∈T ∩X
wi − weight of closure X.
i∈S
Since this is the minimum capacity cut, then F = X must
constitute the maximum weight closure set.
25
Example
The associated max flow problem is
t
(red arcs have infinite capacity)
10
A
B
−10
E
5 1 4 6
C
−5
F
4
H
−1
I
5
4
−4
G
D
−6
7
12
5 12
7
s
and the max flow and min cut is
t
9
A
−10
9
E
5 1 4 6
B
C
D
−6
−5
−4
5
4 6
F
G
4
−1
7
5
6 4
I
I
5
12
4
5 10
6
s
It follows that sectors B, C, D, F, G, I should be dug out, for
a net profit of (12 + 7) − (5 + 4 + 6 + 1) = 3.
26
Download