680 likes | 1.07k Views
Minimum cost flows: basic algorithms (Part II). Adi Haviv (+ Ben Klein) 18/03/2013. Lecture Overview. Introduction (Reminder) Optimality Conditions (Reminder) Pseudo-flow MCF Algorithms: Successive shortest Path Algorithm Primal-Dual Algorithm Out-Of-Kilter Algorithm Summary.
E N D
Minimum cost flows: basic algorithms (Part II) Adi Haviv (+ Ben Klein) 18/03/2013
Lecture Overview • Introduction (Reminder) • Optimality Conditions (Reminder) • Pseudo-flow • MCF Algorithms: • Successive shortest Path Algorithm • Primal-Dual Algorithm • Out-Of-Kilter Algorithm • Summary
Notations and Assumptions • G=(V,E) is a directed graph • If then u w v z
Notations and Assumptions • G=(V,E) is a directed graph • If then • Capacity \ Utility function u(v,w) > 0 for every u w v z
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 u w v z
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 2 -2 u w v z 2 -2
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 2 -2 u w v z 2 -2
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.
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.
Optimality Conditions (Reminder) • Negative cycle • Reduced cost • Complementary slackness
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
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
PseudoFlows • Flow f that satisfy only the following constraints: • Capacity constraint: • Non negativity constraint:
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
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) withas the length of (i, j). Then: • (a) The pseudoflowx 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
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) withas the length of (i, j). Then: • (a) The pseudoflowx 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
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 ' = – das 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
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
Successive Shortest Path Algorithm • algorithm successive shortest path; • begin • x: = 0 and : = 0; • e(i) : = b(i) for all iN; • initialize the sets E: = {i: e(i) > O} and D : = {i: e(i) < O}; • while Edo • begin • selectk 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;
Successive Shortest Path Algorithm b(i) b(j) • Example (,) i j 0 2 (,) (,) 4 -4 (,) 4 1 (,) (,) 3 0 E = {1} , D= {4}
(,) Successive Shortest Path Algorithm i j • Initial residual network for x=0, : = 0 e(2)=0 (2)=0 0 e(4)=-4 (4)=0 2 2 (,) (,) (,) (,) 4 4 -4 (,) (,) 4 1 1 e(1)=4 (1)=0 (,) (,) (,) 3 (,) 3 0 e(3)=0 (3)=0 E = {1} , D= {4}
(,) Successive Shortest Path Algorithm i j • Run shortest path from 1 : d = (0,2,2,3) • P = 1-3-4 e(2)=0 (2)=0 e(4)=-4 (4)=0 2 (,) (,) 4 (,) 1 e(1)=4 (1)=0 (,) (,) 3 e(3)=0 (3)=0 E = {1} , D= {4}
(,) Successive Shortest Path Algorithm i j • Run shortest path from 1 : d = (0,2,2,3) • Update = - d e(2)=0 (2)=-2 2 (,) (,) e(4)=-4 (4)=-3 4 (,) 1 e(1)=4 (1)=0 (,) (,) 3 e(3)=0 (3)=-2 E = {1} , D= {4}
(,) Successive Shortest Path Algorithm i j • Run shortest path from 1 : d = (0,2,2,3) • Update e(2)=0 (2)=-2 2 (,) (,) e(4)=-4 (4)=-3 4 (,) 1 e(1)=4 (1)=0 (,) (,) 3 e(3)=0 (3)=-2 E = {1} , D= {4}
(,) Successive Shortest Path Algorithm i j • , e(2)=0 (2)=-2 2 (,) (,) e(4)=-4 (4)=-3 4 (,) 1 e(1)=4 (1)=0 (,) (,) 3 e(3)=0 (3)=-2 E = {1} , D= {4}
(,) Successive Shortest Path Algorithm i j • After augmenting 2 units along the path 1-3-4 e(2)=0 (2)=-2 2 (,) (,) e(4)=-2 (4)=-3 4 (,) 1 (, e(1)=2 (1)=0 (,) (,) 3 e(3)=0 (3)=-2 E = {1} , D= {4}
(,) Successive Shortest Path Algorithm i j • Shortest path from 1: d=(0,0,1,1) , P=1-2-3-4 • updating e(2)=0 (2)=-2 2 (,) (,) e(4)=-2 (4)=-4 4 (,) 1 (, e(1)=2 (1)=0 (,) (,) 3 e(3)=0 (3)=-1 E = {1} , D= {4}
(,) Successive Shortest Path Algorithm i j • After augmenting 2 units along the path 1-2-3-4 e(2)=0 (2)=-2 2 (,) (,) e(4)=0 (4)=-4 (,) 4 (,) 1 (, e(1)=0 (1)=0 (,) (,) 3 e(3)=0 (3)=-3 E = , D=
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
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 nUiterations. • 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 )
Primal –Dual Algorithm b(i) b(j) (,) i j • min-cost max-flow • single excess node and single deficit node. -2 2 (,) u w (,) (,) v z (,) 2 -2
Primal –Dual Algorithm b(i) b(j) (,) i j • min-cost max-flow • single excess node and single deficit node. • Add nodes s and t. -2 2 (,) u w s t (,) (,) v z (,) 2 -2
Primal –Dual Algorithm b(i) b(j) (,) i j • 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) = -2 2 (,) u w 4 (,) s t (,) (,) (,) v z (,) 2 -2
Primal –Dual Algorithm b(i) b(j) (,) i j • 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) = -2 2 -4 (,) u w 4 (,) (,) s t (,) (,) (,) (,) v z (,) 2 -2
Primal –Dual Algorithm b(i) b(j) (,) i j • 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 0 0 -4 (,) u w 4 (,) (,) s t (,) (,) (,) (,) v z (,) 0 0
Primal –Dual Algorithm b(i) b(j) (,) i j • 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. 0 0 (,) -4 u w 4 (,) (,) s t (,) (,) (,) (,) v z (,) 0 0
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.
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.
Primal –Dual Algorithm • algorithmprimal-dual; • begin • x: = 0 and : = 0; • e(s) : = b(s) and e(t) : = b(t); • whilee(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;
Primal –Dual Algorithm b(i) b(j) (,) i j • Example network: -2 2 (,) u w (,) (,) v z (,) 2 -2
b(i) b(j) Primal –Dual Algorithm (,) i j • Transformed network -2 0 2 0 (,) (,) u w u w (,) (,) -4 s t 4 (,) (,) (,) (,) (,) (,) v z v z (,) (,) 2 -2 0 0
b(i) b(j) Primal –Dual Algorithm (,) i j • We start with x=0, so G(x) = G 0 0 (,) u w (,) (,) -4 s t 4 (,) (,) (,) (,) v z (,) 0 0
b(i) b(j) Primal –Dual Algorithm (,) i j • =0, so = (i) + (j) = 0 0 (,) u w (,) (,) -4 s t 4 (,) (,) (,) (,) v z (,) 0 0
b(i) b(j) Primal –Dual Algorithm (,) i j • Running shortest path from s yield vector d = (0,0,0,1,2,1) 0 0 (,) u w (,) (,) -4 s t 4 (,) (,) (,) (,) v z (,) 0 0
b(i) b(j) Primal –Dual Algorithm (,) i j • Running shortest path from s yield vector d = (0,0,0,1,2,1) 1 0 0 0 1 (,) 0 u w (,) (,) -4 s t 4 (,) (,) (,) (,) v z (,) 0 0 0 2
Primal –Dual Algorithm (,) i j • G(x) after updating (=-d) : (w) = 1 1 0 (u) = 0 (s) = 0 e(s) = 4 0 e(s)= -4 (t) = 1 0 (,) (,) u w u w (,) 0 (,) (,) 1 (,) s t -4 s t 4 (,) (,) (,) (,) (,) (,) (,) (,) v z v z (,) (,) 0 0 (v) = 0 (z) = 2 0 2
Primal –Dual Algorithm i j • The admissible network ( = 0) (w) = 1 (u) = 0 (s) = 0 e(s) = 4 e(s)= -4 (t) = 1 (,) u w u w (,) (,) s t s t (,) (,) (,) (,) v z v z (,) (v) = 0 (z) = 2
Primal –Dual Algorithm i j • Run max flow from s to t: u w s t v z
Primal –Dual Algorithm i j • Run max flow from s to t: u w s t v z
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.