1
MINIMUM COST FLOWS: BASIC ALGORITHMS (PART II)Adi Haviv (+ Ben Klein) 18/03/2013
2
LECTURE OVERVIEW Introduction (Reminder) Optimality Conditions (Reminder) Pseudo-flow MCF Algorithms:
Successive shortest Path Algorithm Primal-Dual Algorithm Out-Of-Kilter Algorithm
Summary
3
NOTATIONS AND ASSUMPTIONS G=(V,E) is a directed graph
If then
v
u w
z
4
NOTATIONS AND ASSUMPTIONS G=(V,E) is a directed graph
If then Capacity \ Utility function u(v,w) > 0
for every
v
u w
z
1
1
13
5
NOTATIONS AND ASSUMPTIONS G=(V,E) is a directed graph
If then Capacity \ Utility function u(v,w) > 0
for every Cost function c(v,w) for every
v
u w
z
6
NOTATIONS AND ASSUMPTIONS G=(V,E) is a directed graph
If then Capacity \ Utility function u(v,w) >
0 for every Cost function c(v,w) for every Balance function b(v) for every we
will have a number b(v) > 0 – supply b(v) < 0 – demand
v
u w
z2 -2
2 -2
7
NOTATIONS AND ASSUMPTIONS G=(V,E) is a directed graph
If then Capacity \ Utility function u(v,w) > 0
for every Cost function c(v,w) for every Balance function b(v) for every we
will have a number b(v) > 0 – supply b(v) < 0 – demand
All data (cost, balance and capacity) are integrals
v
u w
z2 -2
2 -2
8
NOTATIONS AND ASSUMPTIONSRESIDUAL NETWORK G(X) For a feasible flow x, G(x) is the residual network that
corresponds to the flow x: We replace each arc by two arcs and . The arc has cost and residual capacity . The arc has cost and residual capacity .
The residual network consists only of arcs with positive residual capacity.
9
MINIMUM COST FLOWS - DEFINITION Flow is a function on the edges. A feasible flow is a flow that satisfies:
Capacity constraint: Non negativity constraint: Mass balance constraint:
The cost of a feasible flow f: The min cost flow problem is : find a feasible flow f,
with the minimum cost.
10
OPTIMALITY CONDITIONS (REMINDER) Negative cycle Reduced cost Complementary slackness
11
OPTIMALITY CONDITIONS (REMINDER) Negative cycle:Theorem: A feasible solution x* is an optimal solution of the MCF problem if and only if it satisfies the negative cycle optimality conditions: namely, the residual network G(x*) contains no negative cost (directed) cycle.
Cycle–Canceling Algorithm
12
OPTIMALITY CONDITIONS (REMINDER) Reduced cost:Theorem: A feasible solution x* is an optimal solution of the minimum cost flow problem if and only if some set of node potentials satisfy the following reduced cost optimality conditions:
Successive shortest path Algorithm Primal-Dual Algorithm
13
PSEUDOFLOWS Flow f that satisfy only the following
constraints: Capacity constraint: Non negativity constraint:
14
PSEUDOFLOWS Imbalance function e:
e(i) > 0 : excess of node i e(i) < 0 : -e(i) deficit of node i e(i) = 0 : i is balanced
Denote E and D be the sets of excess and deficits notes Observation:
0
15
PSEUDOFLOWS - PROPERTIES Lemma: if a pseudoflow (flow) x satisfies the reduced cost
optimality conditions with potentials . Let the vector d represent the shortest path distances from some node s to all other nodes in G(x) with as the length of (i, j). Then: (a) The pseudoflow x also satisfies the reduced cost optimality conditions
with potentials ' = - d. (b) in a shortest path from node s to every other node.
proof (a) :
From the conditions : 0 , (i)+ (j) (i)–d(i)) + ((j)-d(j)) 0
16
PSEUDOFLOWS - PROPERTIES Lemma: if a pseudoflow (flow) x satisfies the reduced cost
optimality conditions with potentials . Let the vector d represent the shortest path distances from some node s to all other nodes in G(x) with as the length of (i, j). Then: (a) The pseudoflow x also satisfies the reduced cost optimality conditions
with potentials ' = - d. (b) in a shortest path from node s to every other node.
proof (b) : let P be a shortest path from s to some node l.
(i)+ (j) (i)–d(i)) + ((j)-d(j)) 0
17
PSEUDOFLOWS - PROPERTIES Corollary : Suppose that a pseudoflow (flow) x satisfies the reduced
cost optimality conditions and we obtain x' from x by sending flow along a shortest path from node s to some other node k; then x' also satisfies the reduced cost optimality conditions.
Proof : define ' = – d as in the lemma From the lemma (a) : x satisfies the reduced cost optimality with ' From the lemma (b) : the shortest path In G(x’) changes are only for ; we may add , but since so the arc also
satisfy the optimality condition
18
SUCCESSIVE SHORTEST PATH ALGORITHM Iterative algorithm
Start with optimal (RC) feasible pseudoflow
At every step keeps optimality (RC) and tries to build a feasible flow.
At each step, the algorithm selects a node s with excess supply (e(i) > 0) and a node t with unfulfilled demand (e(i) < 0) and sends flow from s to t along a shortest path in the residual network.
The algorithm terminates when the current solution satisfies all the mass balance constraints
19
SUCCESSIVE SHORTEST PATH ALGORITHM algorithm successive shortest path; begin
x: = 0 and : = 0; e(i) : = b(i) for all i N; initialize the sets E: = {i : e(i) > O} and D : = {i : e(i) < O}; while Edo begin
select k E and l D; determine shortest path distances d(j) from node k to all other nodes
in G(x) with respect to the reduced costs ; let P denote a shortest path from node k to node l; update : = - d; : = min[e(k), - e(l), min{: (i, j) P}]; augment units of flow along the path P; update x, G(x), E, D, and the reduced costs;
end; end;
20
SUCCESSIVE SHORTEST PATH ALGORITHM Example
3
1
2
44
0
0
-4
(, )
(, )
(, )
(, )
i j(, )
b(i) b(j)
(, )
E = {1} , D= {4}
21
SUCCESSIVE SHORTEST PATH ALGORITHM Initial residual network for x=0, : = 0
3
1
2
44
0
0
-4
(, )
(, )
(, )
(, )
i j(, )
(, )
E = {1} , D= {4}
3
1
2
4
e(2)=0(2)=0
(, )
(, )
(, )
(, )
(, )
e(1)=4(1)=0
e(3)=0(3)=0
e(4)=-4(4)=0
22
SUCCESSIVE SHORTEST PATH ALGORITHM Run shortest path from 1 : d = (0,2,2,3) P = 1-3-4
i j(, )
E = {1} , D= {4}
3
1
2
4
e(2)=0(2)=0
(, )
(, )
(, )
(, )
(, )
e(1)=4(1)=0
e(3)=0(3)=0
e(4)=-4(4)=0
23
SUCCESSIVE SHORTEST PATH ALGORITHM Run shortest path from 1 : d = (0,2,2,3) Update = - d
i j(, )
E = {1} , D= {4}
3
1
2
4
e(2)=0(2)=-2
(, )
(, )
(, )
(, )(, )
e(1)=4(1)=0
e(3)=0(3)=-2
e(4)=-4(4)=-3
24
SUCCESSIVE SHORTEST PATH ALGORITHM Run shortest path from 1 : d = (0,2,2,3) Update
i j(, )
E = {1} , D= {4}
3
1
2
4
e(2)=0(2)=-2
(, )
(, )
(, )
(, )(, )
e(1)=4(1)=0
e(3)=0(3)=-2
e(4)=-4(4)=-3
25
SUCCESSIVE SHORTEST PATH ALGORITHM ,
i j(, )
E = {1} , D= {4}
3
1
2
4
e(2)=0(2)=-2
(, )
(, )
(, )
(, )(, )
e(1)=4(1)=0
e(3)=0(3)=-2
e(4)=-4(4)=-3
26
SUCCESSIVE SHORTEST PATH ALGORITHM After augmenting 2 units along the path 1-3-
4
i j(, )
E = {1} , D= {4}
3
1
2
4
e(2)=0(2)=-2
(, )
(, )
(, )
(, )(, )
e(1)=2(1)=0
e(3)=0(3)=-2
e(4)=-2(4)=-3
(,
27
SUCCESSIVE SHORTEST PATH ALGORITHM Shortest path from 1: d=(0,0,1,1) , P=1-2-3-4 updating
i j(, )
E = {1} , D= {4}
3
1
2
4
e(2)=0(2)=-2
(, )
(, )
(, )
(, )(, )
e(1)=2(1)=0
e(3)=0(3)=-1
e(4)=-2(4)=-4
(,
28
SUCCESSIVE SHORTEST PATH ALGORITHM After augmenting 2 units along the path 1-2-3-4
i j(, )
E = , D=
3
1
2
4
e(2)=0(2)=-2
(, )
(, )
(, )
(, )(, )
e(1)=0(1)=0
e(3)=0(3)=-3
e(4)=0(4)=-4
(,
(, )
29
SUCCESSIVE SHORTEST PATH ALGORITHM Correctness + Runtime:
We start with feasible pseudoflow that satisfy the RC optimality x = 0 =
At every iteration until the nodes are balanced there exist at least on node in E and one node at D
Each iteration solves a shortest path problem with nonnegative lengths and decreases the excess from some
30
SUCCESSIVE SHORTEST PATH ALGORITHM Correctness + Runtime:
Let U be an upper bound to the supply
Since everything is integral The algorithm will terminate in at most nU iterations.
We can use Dijkstra to find the shortest path at each iterations with Fibonacci Heaps we get o(m+nlongn)
Total Running time is O(Ulogn+nUm )
31
PRIMAL –DUAL ALGORITHM min-cost max-flow
single excess node and single deficit node.
v
u w
z
i j
2 -2
(, )
2 -2
b(i) b(j)
(, )
(, )
(, )(, )
32
PRIMAL –DUAL ALGORITHM min-cost max-flow
single excess node and single deficit node.
Add nodes s and t.
v
u w
z
i j
2 -2
(, )
2 -2
b(i) b(j)
(, )
(, )
(, )(, )s t
33
min-cost max-flow single excess node and single deficit
node.
Add nodes s and t. For every v such that b(v)>0:
Add an edge (s,v) such that u(s,v)=b(v) b(s) = v
u w
z
i j
2 -2
(, )
2 -2
b(i) b(j)
(, )
(, )
(, )(, )s t
4 (, )
PRIMAL –DUAL ALGORITHM
(, )
34
PRIMAL –DUAL ALGORITHM min-cost max-flow
single excess node and single deficit node.
Add nodes s and t. For every v such that b(v)>0:
Add an edge (s,v) such that u(s,v)=b(v) b(s) =
For every v such that b(v)<0: Add an edge (v,t) such that u(v,t)= -b(v) b(t) =
i j(, )
b(i) b(j)
v
u w
z
2 -2
2 -2
(, )
(, )
(, )(, )s t
4 (, )
(, )
-4(, )
(, )
35
PRIMAL –DUAL ALGORITHM min-cost max-flow
single excess node and single deficit node.
Add nodes s and t. For every v such that b(v)>0:
Add an edge (s,v) such that u(s,v)=b(v) b(s) =
For every v such that b(v)<0: Add an edge (v,t) such that u(v,t)= -b(v) b(t) =
For all
i j(, )
b(i) b(j)
v
u w
z
0 0
0 0
(, )
(, )
(, )(, )s t
4 (, )
(, )
-4(, )
(, )
36
PRIMAL –DUAL ALGORITHM min-cost max-flow
single excess node and single deficit node.
a minimum cost flow in the transformed network gives a minimum cost flow in the original network
There exists a feasible solution iff all the edges from s are saturated.
i j(, )
b(i) b(j)
v
u w
z
0 0
0 0
(, )
(, )
(, )(, )s t
4 (, )
(, )
-4(, )
(, )
37
PRIMAL –DUAL ALGORITHM Similar to the previous SSP :
Start with optimal (RC) feasible pseudoflow At every step keeps optimality (RC) and tries to build a feasible
flow.
Instead of sending flow along one shortest path at a time it solve maximum flow that send flow along all shortest paths.
38
PRIMAL –DUAL ALGORITHM (x) Admissible network :
will contain only arcs in G(x) with =0
=
Every directed path from node s to node t in is a shortest path in G(x) between the same pair of nodes.
39
PRIMAL –DUAL ALGORITHM algorithm primal-dual; begin
x: = 0 and : = 0; e(s) : = b(s) and e(t) : = b(t); while e(s) > 0 do begin
determine shortest path distances d(·) from node s to all other nodes in G(x) with respect to the reduced costs ;
update : = - d; define the admissible network ; establish a maximum flow from node s to node t in ; update e(s) , e(t), and G(x);
end; end;
40
PRIMAL –DUAL ALGORITHM Example network:
v
u w
z
i j
2 -2
(, )
2 -2
b(i) b(j)
(, )
(, )
(, )(, )
41
PRIMAL –DUAL ALGORITHM Transformed network
v
u w
z
i j
2 -2
(, )
2 -2
b(i) b(j)
(, )
(, )
(, )(, )
v
u w
z
0 0
0 0
(, )
(, )
(, )(, )s t4
(, )
(, )
-4
(, )
(, )
42
PRIMAL –DUAL ALGORITHM We start with x=0, so G(x) = G
i j(, )
b(i) b(j)
v
u w
z
0 0
0 0
(, )
(, )
(, )(, )s t4
(, )
(, )
-4
(, )
(, )
43
PRIMAL –DUAL ALGORITHM =0, so = (i) + (j) =
i j(, )
b(i) b(j)
v
u w
z
0 0
0 0
(, )
(, )
(, )(, )s t4
(, )
(, )
-4
(, )
(, )
44
PRIMAL –DUAL ALGORITHM Running shortest path from s yield vector
d = (0,0,0,1,2,1)
i j(, )
b(i) b(j)
v
u w
z
0 0
0 0
(, )
(, )
(, )(, )s t4
(, )
(, )
-4
(, )
(, )
45
PRIMAL –DUAL ALGORITHM Running shortest path from s yield vector
d = (0,0,0,1,2,1)
v
u w
z
0 0
0 0
(, )
(, )
(, )(, )s t4
(, )
(, )
-4
(, )
(, )
0
0
0
1
1
2
i j(, )
b(i) b(j)
PRIMAL –DUAL ALGORITHM G(x) after updating (= -d) :
46
v
u w
z
(, )
(, )
(, )(, )s t
(, )
(, )
(, )
(, )
(s) = 0e(s) = 4
(u) = 0
(v) = 0
(w) = 1
e(s)= -4(t) = 1
(z) = 2
v
u w
z
0 0
0 0
(, )
(, )
(, )(, )s t4
(, )
(, )
-4
(, )
(, )
0
0
0
1
1
2
i j(, )
𝑐𝑢 ,𝑣𝜋 =𝑐𝑢 ,𝑣− 𝜋 (𝑢)+𝜋 (𝑣 )
PRIMAL –DUAL ALGORITHM The admissible network ( = 0)
47
v
u w
z
1
2
11s t
2
2
2
i j𝑟 𝑖𝑗❑
𝑐𝑢 ,𝑣𝜋 =𝑐𝑢 ,𝑣− 𝜋 (𝑣 )+𝜋 (𝑢 )
v
u w
z
(, )
(, )
(, )(, )s t
(, )
(, )
(, )
(, )
(s) = 0e(s) = 4
(u) = 0
(v) = 0
(w) = 1
e(s)= -4(t) = 1
(z) = 2
PRIMAL –DUAL ALGORITHM Run max flow from s to t:
48
i j𝑟 𝑖𝑗❑
v
u w
z
1
2
11s t
2
2
2
PRIMAL –DUAL ALGORITHM Run max flow from s to t:
49
i j𝑟 𝑖𝑗❑
v
u w
z
0
2
01s t
1
1
0
50
PRIMAL –DUAL ALGORITHM Correctness + Runtime:
The primal-dual algorithm sends flow along all shortest paths at once; therefore, proof of correctness is similar to the successive shortest path one
Excess of the node s decreases at every iteration
Since everything is integral the distance between s and t increases by at least one unit.
51
PRIMAL –DUAL ALGORITHM Correctness + Runtime:
Let U be an upper bound to the supply and C an upper bound to the costs.
Number of iteration bounded by min{nU,nC}e(s)The value of no node potential can fall below –nC
If for example we use Dinitz blocking flow algorithm we get O(n2m * min{nU,nC})
52
OPTIMALITY CONDITIONS (REMINDER) Complementary Slackness:Theorem: A feasible solution x* is an optimal solution of the MCF problem if and only if for some set of node potentials , the reduced costs and flow values satisfy the following complementary slackness conditions for every edge (u,v) in the network: If then If then If then
Out-Of-Kilter Algorithm
54
THE OUT OF KILTER ALGORITHM An edge can be in one of 2 states:
In-kilter : satisfy the complementary slackness
Out-of-kilter : don’t satisfy the complementary slackness
55
KILTER DIAGRAM The kilter diagram represents
the conditions:
If then If then If then
56
KILTER NUMBER kilter number of each edge (i, j) is the
magnitude of the change in required to make the edge an in-kilter arc while keeping fixed.
A kilter number can be thought of as the change required to bring a flow into feasibility and eventually optimality.
we can add up all the kilter numbers to find how far from optimality we are at any given time.
An in-kilter edge has a kilter number of zero.
57
KILTER NUMBER
If then If then If then
< 0 - |
= 0
58
KILTER NUMBER – RESIDUAL NETWORK
We must send units of flow in the edge (I,j) so that it drops out of the residual network and satisfy the RC
59
THE OUT OF KILTER ALGORITHM Start with a feasible flow and = 0 Iterate while we still have out-of-kilter edges Look at G(x) and select and OFK edge (p,q) Edges are given a cost of the higher of zero or the reduced cost. Run shortest path and update the potential function same as before If after the update the reduce cost of the edge(p,q) is negative
We use a shortest path to find the cheapest cycle that includes the out of kilter edge using the residual graph.
Having found the cycle, we check the amount of flow that can be augmented (min in the cycle ) and update the flow variables (x) and the residual graphs (G(x)).
60
THE OUT OF KILTER ALGORITHM Correctness:
Kilter numbers of the edges are non-increasing Two operations in the algorithm affect the kilter numbers of
arcs: updating node potentials augmenting flow along the cycle W
At each iteration the algorithm selects and edge (p,q) Makes it in-kilter during potential update decrease it by at least 1 by the flow augmentation
61
THE OUT OF KILTER ALGORITHM Runtime:
The algorithm terminate within O(mU) iterations
Dominant computation is shortest path computation
total runtime is : O(
62
SUMMERY Algorithm Complexity Features Cycle-canceling Maintains a feasible flow x at
every iteration and augments flows along negative cycles in G(x).
Successive shortest Path O(Ulogn+nUm ) Maintains a pseudoflow x satisfying the optimality and augments flow along shortest paths from excess nodes to deficit nodes in G(x).
Primal-dual O(m * min{nU,nC}) Maintains a pseudo flow x satisfying the optimality and reduce primal infeasibility by the maximum amount by solving a maximum flow
Out-of-kilter O( Maintains a feasible flow x at each iteration and attempts to satisfy the optimality conditions by augmenting flows along shortest paths.
63
THANK YOU