GENERALIZED FLOWS Jonathan Kalechstain 27.5.2013 Tel Aviv University Introduction • Until now, we made an assumption that if k units of flow leaves node u, then k units of flow arrives at node v. • This assumption may not be always true, like in transmission of unstable gas , or leaking pipes. u k v Using multipliers • We are given a graph πΊ = (π, πΈ) • We associate a positive ππ,π with every arc π, π ∈ E • Assume that if 1 unit of flow was sent from node i along the arc (π, π) then ππ,π units of flow arrived at node j. • Notice that the model is a generalization of the minimal cost flow problem, with every arc having the multiplier ππ,π = 1 Example Assume that ππ’,π£ = 0.8 V received 8 units of flow! u 10 v Notations and Assumptions • • • • • G=(V,E) is a directed graph Capacity function u(v,w) > 0 for every (π£, π€) ∈ πΈ Cost function c(v,w) ≥ 0 for every π£, π€ ∈ πΈ An arc multiplier ππ£,π€ ≥ 0 for every π£, π€ ∈ πΈ Balance function b(v) for every π£ ∈ π we will have a number – b(v) > 0 – supply – b(v) < 0 – demand Formulation Of The Generalized Flow Problem(linear programming) • Minimize Subject to: (π,π)∈πΈ π π, π ∗ π₯(π, π) π₯ π, π − {π:(π,π)∈πΈ} π₯ π, π ∗ ππ,π = π π ∀π ∈ π π: π,π ∈πΈ And 0 ≤ π₯ π, π ≤ π’ π, π , ∀(π, π) ∈ πΈ An Important Remark • π’(π, π) is an upper bound on the flow that we send from i, not the flow that arrives at node j. • π(π, π) is the cost per unit flow we send from i, not the per unit cost that arrives at node j Example Assume that ππ’,π£ = 0.8 and π π’, π£ = 4 V received 8 units of flow and we pay 40 units not 32! u X(u,v)=10 v Augmented Forest structures Flows along Paths • Let P be a path from node s to node t (not directed) in the network. Let π and π denote the sets of forward arcs and backwards arcs in P. • Definition: the path multiplier of a path P is defined as follows: Forward arc means that if we π π = π (π,π)∈π π,π (π,π)∈π ππ,π send flow along a path, the arc is the same direction as the path. If it’s in opposite direction we call it a backward arc Example All arcs are forward arcs ππ,π 1 u v 3 0.5 2 1 4 3 4 5 Example ( π₯ π, π πππππ‘πππ, ππ,π ) v u (2,3) 1 0.5 2 • Add two units of flow from 1 to 2! • 2 receives 6 units of flow 1 4 3 4 5 Example ( π₯ π, π πππππ‘πππ, ππ,π ) v u 3 1 (6,0.5) 2 • 2 send its 6 unit of flow out! • 3 receives 3 units of flow 1 4 3 4 5 Example ( π₯ π, π πππππ‘πππ, ππ,π ) 1 u v 3 0.5 2 • 3 send its 3 unit of flow out! • 4 receives 12 units of flow 1 (3,4) 3 4 5 Example ( π₯ π, π πππππ‘πππ, ππ,π ) 1 u v 3 0.5 4 3 2 • 4 send its 12 unit of flow out! • 5 receives 12 units of flow • 2 units were first sent, and eventually 12 were received. Notice the relation is 6 π π = (π,π)∈π ππ,π (π,π)∈π ππ,π (12,1) 4 = 3∗0.5∗4∗1 1 =6 5 Example Not all arcs are forward arcs ππ,π v u 2 1 6 2 2 3 4 Example ( π₯ π, π πππππ‘πππ, ππ,π ) v u (1,2) 1 6 2 • Add one units of flow from 1 to 2! • 2 receives 2 units of flow 2 3 4 Example ( π₯ π, π πππππ‘πππ, ππ,π ) 1 u v 2 (-3,6) 1 2 2 3 • In order to keep the mass balance constraint, after node 2 got 2 units of flow, 3 decreases it’s flow by one third of a unit • 2 receives -2 units of flow 4 Example ( π₯ π, π πππππ‘πππ, ππ,π ) v u 2 1 π π = (π,π)∈π ππ,π (π,π)∈π ππ,π = 2∗2 6 1 6 (2,3) 3 2 • Now to keep the mass balance constraint node 3 adds 1 of flow. 3 2 • Node 4 receives 3 extra units of flow. 2 • So after sending 1 unit of flow from 1, 4 gets 3 units. 2 Therefore the multiplier is 3 . 4 = 2 3 Conclusion • Property 1: If we send 1 unit of flow from node s to another node t along a path P, then π(π) units become available at node t. Flows along Cycles • Let W be a path from node s to itself (not directed, with some orientation) in the network. Let π and π denote the sets of forward arcs and backwards arcs in W. • The cycle multiplier of a circle W is : π π = (π,π)∈π ππ,π (π,π)∈π ππ,π Some definitions π π = π (π,π)∈π π,π (π,π)∈π ππ,π • If π π > 1, then an excess is created in node s. we call this a gainy cycle. • If π π < 1, then a deficit is created in node s. we call this a lossy cycle. • If π π = 1, then mass balanced is conserved in all nodes. we call this a breakeven cycle. π π = π (π,π)∈π π,π (π,π)∈π ππ,π • Property 2: if π π is the multiplier of a cycle 1 W with a particular orientation, then is π π the multiplier of the same cycle with opposite direction Proof: nominator and denominator switch by definition. • Property 3: if π π ≠ 1 the cycle is loosy with one orientation and gainy with the other. • Property 4: By sending π units along a nonbreakeven cycle starting at node s, we create an imbalance of |π ∗ π π − 1 | units at node s. Proof: at first we send π units, and then by property 1,π ∗ π π units arrive back at node s, so the size of the imbalance is |π ∗ π π - π| Reminder: Property 1: If we send 1 unit of flow from node s to another node t along a path P, then π(π) units become available at node t. Augmented Tree • Let πΊ πΌ = (π πΌ , π πΌ ) be a subgraph of G = (π, πΈ) such that π πΌ ⊆ π and π πΌ ⊆ πΈ. • πΊ πΌ is considered an augmented tree if π πΌ is a spanning tree of π πΌ together with some extra edge π = π, π which is called the extra arc • An augmented tree has a designated node called the root. Each augmented tree is hanging from it’s root Example b and c are two augmented trees of the graph a. The extra arc is represented by a dashed line • An augmented tree contains exactly one circle. • The cycle is referred to as the extra cycle • An augmented tree is called a good augmented tree if for the extra cycle W π(W) ≠ 1 Augmented Forest • We define an augmented forest πΊ π = (π, πΉ) when πΉ ⊆ πΈ as a collection of node-disjoint augmented trees that span all the nodes in the graph. • An augmented forest is considered good if each of it’s components is a good augmented tree. • See 2 slides ago at d, to see an example of an augmented forest of the graph. • The arcs of the augmented forest are called augmented-forest arcs and the remaining arcs are called nonaugmented-forest arcs Augmented Forest Structures and Optimality Conditions • Let πΊ = (π, πΈ) • Let πΈ = πΉ ∪ πΏ ∪ π define a partition of E, and let F be a good augmented forest. • we refer to the arcs in L as nonaugmentedforest arcs at their lower bound • we refer to the arcs in U as nonaugmentedforest arcs at their upper bound. • The triple (πΉ, πΏ, π) defines an augmented forest structure. Feasibility • An augmented forest structure (πΉ, πΏ, π) is feasible if we set π₯π,π = 0 ∀ π, π ∈ πΏ and π₯π,π = π’π,π ∀ π, π ∈ π and the flow X on the augmented-forest arcs satisfy the generalized flow definition (mass balance constraints and flow bounds). • We say that an augmented forest structure is nondegenerate if 0 < π₯π,π < π’π,π , ∀ π, π ∈ πΉ • We will also say that a feasible augmented forest structure (πΉ, πΏ, π) is an optimal augmented forest structure if its associated flow X is an optimal solution of the generalized flow problem Node Potentials and Reduced Costs • Let π: V → R be the node potentials function • With respect to π , we define the reduced cost of an arc (π, π) as : π ππ,π = ππ,π − π π + ππ,π π(π) Generalized Flow Optimality Condition • A flow x* is an optimal solution of the generalized network flow problem if it is feasible and for some potential function π the following conditions are satisfied: π ∗ 1. If 0 < π₯π,π < π’π,π then ππ,π =0 π ∗ 2. If π₯π,π = 0 then ππ,π ≥0 π ∗ 3. If π₯π,π = ππ,π then ππ,π ≤0 Proof Claim 1 : minimizing π,π ∈πΈ ππ,π π₯π,π is equivalent π to minimizing π,π ∈πΈ ππ,π π₯π,π Similar to a proof was given in the past Back to the sentence: let x be some arbitrary flow. 1. 2. 3. ∗ π If 0 < π₯π,π < ππ,π then ππ,π =0 ∗ π If π₯π,π = 0 then ππ,π ≥0 ∗ π If π₯π,π = π’π,π then ππ,π ≤0 π ∗ Looking at π,π ∈πΈ ππ,π ∗ (π₯π,π − π₯π,π ) Let’s prove that each term in the summation is not negative: Lets look at the following 3 cases to prove this: ∗ π 1. 0 < π₯π,π < π’π,π in this case it is given that ππ,π =0 ∗ ∗ π 2. π₯π,π = 0 in this case π₯π,π ≥ π₯π,π =0, and because ππ,π ≥ 0, we multiply two non negative numbers so the result is not negative. ∗ ∗ 3. π₯π,π = π’π,π in this case π₯π,π ≤ π₯π,π =π’π,π , and because π ππ,π ≤ 0, we multiply two non positive numbers so the result is not negative. So now π π ∗ π₯ − π₯ ∗ = π π π₯ − π π π₯ ∗ ≥ 0, which means that π π π₯ ≥ π π π₯ ∗ . We showed that with the 3 conditions, some feasible flow π₯ ∗ is minimal. Augmented Forest Structure Optimality Conditions This property’s proof is immediate from the last sentence: • A feasible augmented forest structure (πΉ, πΏ, π) with the associated flow π₯ ∗ is an optimal augmented forest structure if for some function π: π → π the pair(π, π₯ ∗ ) satisfy the following optimality conditions: π ∗ 1. ππ,π = 0, ∀ π, π ∈ πΉ (because 0 ≤ π₯π,π ≤ π’π,π ) π ∗ 2. ππ,π ≥ 0, ∀ π, π ∈ πΏ (because 0 = π₯π,π ) π ∗ 3. ππ,π ≤ 0, ∀ π, π ∈ π (because π’π,π = π₯π,π ) Determining Node Potentials for an Augmented Forest Structure • Let (πΉ, πΏ, π) be an augmented forest structure. The augmented forest F contains several augmented trees. • The following algorithm is performed per tree. • Let π ∪ { π, π } be some augmented tree, and let node h be it’s root. • We would like to satisfy the condition that π ππ,π = 0, ∀ π, π ∈ πΉ , so we use the following π equation: ππ,π = ππ,π − π π + ππ,π π π = 0 The main idea • We start by setting π β = π which will be determined later. • We then use DFS on the not directed tree T, and because of connectivity and DFS properties, we will always know π(π) or π(π) when ππ,π − π π + ππ,π π π = 0, so for each node we will get a single equation with one variable (and π). • We use the extra arc (π, π) to determine π, and update the potentials (they are linear functions of π). Algorithm pseudo code Example (ππ,π , ππ,π ) v u (10,1) (5,2) (6,3) (8,3) (10,2) Special arc Example Special arc (ππ,π , ππ,π ) π(π’) Determine π ππππ‘ = π root π (10,1) (5,2) (6,3) (8,3) (10,2) Example Special arc (ππ,π , ππ,π ) π(π’) root π (10,1) π − 10 (8,3) (5,2) (6,3) (10,2) 1. Running DFS(not including the special arc), going to red. 2. ππππππ,πππ − π πππππ + ππππππ,πππ π πππ = 10 − π + 1 ∗ π πππ = 0 → π πππ = π − 10 Example Special arc (ππ,π , ππ,π ) π(π’) root π (10,1) π − 10 (8,3) 3π − 22 (5,2) (6,3) (10,2) 1. Running DFS(not including the special arc), going to yellow. 2. ππ¦πππππ€,πππ − π π¦πππππ€ + ππ¦πππππ€,πππ π πππ = 8 − π π¦πππππ€ + 3 ∗ π − 10 =0 → π π¦πππππ€ = 3π − 22 ……… (ππ,π , ππ,π ) π(π’) root π (10,1) π − 10 (8,3) 3π − 22 (6,3) (5,2) −2.5 + 0.5π (10,2) −6.25 + 0.25π Special arc Special Arc Special arc (ππ,π , ππ,π ) π(π’) root −17 (10,1) −27 (8,3) −73 (6,3) (5,2) −11 (10,2) −10.5 ππππ,πππ’π − π πππ + ππππ,πππ’π π πππ’π = 6 − π − 10 + 3(−2.5 + 0.5π) =0 → 0.5θ = −8.5 → π = −17 Time complexity: O(n) Determining Flow for an Augmented Forest Structure • Let (πΉ, πΏ, π) be an augmented tree structure with the current assumption that the network is uncapacitated, which means π = ∅. • We present an algorithm determining the flow for each augmented tree. • In this algorithm we start from the leaf nodes, and advance toward the root. • Let π ∪ { π, π } be some augmented tree of the forest. • We define π(π) as the imbalance of a node, and begin with π π = π(π). • We set the flow of the extra arc π₯π,π = π and all other arcs get flow 0. • We can say we decreased the imbalance at node a by π units, and increased it at node b by πππ,π units. • Now we start updating the graph in the following way: Case 1: More of the tree e(i)+ππ,π π(π) e(i) π π π₯π,π = 0 π₯π,π = π(π) j j e(j) 0 j is a leaf node After update, we delete the leaf node j and the relevant edge Case 2: More of the tree After update, we delete the leaf node j and the relevant edge π(π) e(i) e(i)+ π π,π π π π₯π,π = 0 π₯π,π = − j j e(j) 0 j is a leaf node π(π) ππ,π • After updating the rest of the leaves (each time we get a new tree ) each arc is a function of π. • we set π ππππ‘ = 0, calculate the value of π, and place it in all of the arcs flows. • Now we have a flow that satisfy the mass balance constraint (if all arcs were not capacitated) Pseudo code Running Example 5 e(i) ππ,π , π₯π,π (1,0) (1,0) 0 0 (0.5, π) (3,0) e(j) 10 (2,0) -20 Special arc Running Example 5 e(i) ππ,π , π₯π,π (1,0) (1,0) 0 0 (0.5, π) (3,0) e(j) 10 (2,0) -20 Special arc We set : π πππ = π πππ − π = −π π πππ’π = π πππ’π + ππππ,πππ’π π = 0.5π Running Example 5 e(i) (ππ,π , π₯π,π ) (1,0) (1,0) −π 0.5π (0.5, π) (3,10) e(j) 10 (2,0) -20 Special arc Now lets look at the yellow leaf: We have an edge (yellow,red) So : π π¦πππππ€ = 0 π πππ = π πππ + ππ¦πππππ€,πππ ∗ 10 = −π + 3 ∗ 10 = −π + 30 Flow(yellow,red)=10 Running Example 5 e(i) (ππ,π , π₯π,π ) (1,0) (1,0) −π + 30 0.5π (0.5, π) e(j) (2,10) -20 Special arc Now lets look at the green leaf: We have an edge (blue,green) So : π πππππ = 0 π πππ’π = π πππ’π − 20 = 0.5π − 10 ππππ’π,πππππ Flow(blue,green)=10 Running Example 5 e(i) (ππ,π , π₯π,π ) (1,0) (1,0) −π + 30 0.5π − 10 (0.5, π) e(j) Special arc Now lets look at the blue leaf: We have an edge (black,blue) So : π πππ’π = 0 π πππππ = π πππππ + 0.5π − 10 = 0.5π − 5 1 Flow(black,blue)=−0.5π + 10 Running Example 0.5π − 5 e(i) (ππ,π , π₯π,π ) e(j) (1,0) −π + 30 Special arc Now lets look at the red leaf: We have an edge (black,red) So : π πππ = 0 π πππππ = π πππππ + −π + 30 = −0.5π + 25 1 Flow(black,red)=π − 30 Now to determine π: −0.5π + 25 = 0 → π = 50 Final flow 5 b(i) 20 π₯π,π -15 0 0 50 10 b(j) 10 10 -20 Special arc • It is easy to prove this algorithm finds a unique flow and value of π. • Eventually we get some linear function of π for π ππππ‘ = π ππππ‘ + g ππππ‘ π = 0 → π= π(ππππ‘) − π(ππππ‘) • It is important to show that g(root) is never 0. Proof: • It is easy to see that ππ ππππ‘ is the imbalance of the root, resulting from setting the flow on the arc (π, π) as π. • Setting the flow on the arc (π, π) as π creates a deficit of π units at a, and an excess of ππ,π π at b. let ππ₯→π¦ denote the tree path from x to y, and let π(ππ₯→π¦ ) denote the path multiplier. • We can cancel the deficit at node a by sending π π(πππππ‘→π ) from the root, and cancel the excess at node b by sending πππ,π from node b to the root (π ππ→ππππ‘ πππ,π units arrive at the root) • So using the last conclusions we can say that 1 g(root)= π ππ→ππππ‘ ππ,π − π(πππππ‘→π ) • So g(root)=0 ⇔ π ππ→ππππ‘ ππ,π π(πππππ‘→π )=1, but this is exactly the multiplier of the circle. So if the circle is not breakeven (i.e the augmented tree is good), the proof stands. Extending to capacitated case 1. The initialization is the same. 2. For every π, π ∈ π do begin π₯π,π = π’π,π :setting the required flow π π = π π − π’π,π : set deficit π π = π π + ππ,π π’π,π : set excess. 3. Run the previous algorithm Conclusion about the flow • We need the augmented trees to be good augmented tree. • Our flow satisfy mass balance constraint, but doesn’t promise the flow is legitimate (e.g. negative flow as seen in example) • The flow on the arcs of the augmented forest that satisfy the mass balance constraint is unique, so the forest structure is feasible if and only if the flow bounds are satisfied Properties from linear programming (no proof) • Arcs in a set B have a unique solution if and only if B is a good augmented forest • A set B of arcs defines a basis(an extreme point on the polytope) of the generalized network problem if and only if B is a good augmented forest. This means that there exist an optimal solution for a good augmented tree. The Generalized Network Simplex Algorithm • This algorithm maintains a good feasible augmented forest structure at every iteration, using pivot rules to eventually reach an improved augmented forest structure that satisfies the optimality conditions Pseudo Code Obtaining an Initial Good Augmented Forest Structure • Easy to achieve an artificial initial augmented forest structure, simply by adding self edges with sufficiently large cost, infinite capacity and appropriate multipliers on these edges. • We will avoid full details and proof but assume we have a good initial augmented forest structure. • Computing x and π like explained in previous slides. Initial Augmented Forest (ππ,π , ππ,π , π’π,π ) (0.5, π, ∞) The forest is the set of self arcs. b(i) π(π) Set π₯π,π = 1−π 5 (2, π, ∞) 0 (0.5, π, ∞) 10 (2, π, ∞) 0 (2, π, ∞) -20 π,π M is big enough so that if a feasible solution exists, no optimal solution with positive flow on the self arcs exists. Optimality Testing and the Entering Arc To determine whether a spanning tree structure is optimal we check: If the spanning tree structure satisfies the conditions it is optimal ο we terminate Else, the algorithm selects a non-forest violating arc to enter the forest: Pivot Rules π For any eligible arc (i, j) we refer to Iππ,π I as its violation. The network simplex algorithm can select any eligible arc to enter the tree and still would terminate finitely (with some provisions for dealing with degeneracy) Pivot rules for selecting entering arcs: • Dantzig's pivot rule • First eligible arc pivot rule • Candidate list pivot rule These rules were shown in the simplex lecture 70 Identifying the Leaving Arc • Assume the entering arc is π, π ∈ πΏ (will prove only for this case). • Denote π¦π,π as the change in flow units for π, π ∈ πΉ if we use 1 unit of flow on π, π • If we knew the values π¦π,π , ∀ π, π ∈ πΉ then it would be easy to know the maximum number of flow we can use on π, π so all edges will remain between their lower and upper bound. • This promise we have an arc that reached it’s lower or higher bound – this is the arc we drop. Determine π¦π,π • Use the Algorithm presented before to compute the value of each arc in the trees of k,l: • At first the flow is 0 for all edges, and the imbalance vector is: e(i) = -1 if i=k e(i) = ππ,π if i=l e(i) = 0 else The arc flow we obtain are the π¦π,π values Determine the Maximum Flow On (k,l) Within the Bounds • If we add πΏ units of flow to (k,l) then to keep the flow bounds : 0 ≤ π₯π,π + πΏπ¦π,π ≤ π’π,π ∀ π, π ∈ πΉ ∪ { π, π } • It is easy to see that if π¦π,π > 0 then the edge will go up to it’s lower bound, and if π¦π,π < 0 then the opposite will happen. • Denote πΏπ,π by the maximum number of units allowed to use to make π, π reach it’s lower\upper bound then: (π’π,π −π₯π,π ) • πΏπ,π = π¦π,π π₯π,π − π¦π,π ππ π¦π,π > 0 ππ π¦π,π < 0 ∞ ππ π¦π,π = 0 • So the largest value for which π₯ + πΏπ¦ is feasible is πΏ = min[πΏπ,π ] • We augment πΏ units on the arc (π, π) and change the value of each arc to π₯π,π + πΏπ¦π,π . • The leaving arc is one of the arcs for which πΏ is defined (the blocking arc). • We say that the iteration is not degenerate if πΏ > 0 (or else we had a degenerate tree) • All of these actions take O(m) time Updating the Augmented Forest • When leaving arc (p, q) is determined for a given entering arc (k, I), we updates the tree structure • If the leaving arc is the same as the entering arc, (when δ = δpq =upq), the tree does not change. -the arc (k, I) merely moves from the set L to the set U, or vice versa. • If the leaving arc differs from the entering arc, we need to prove we still have a good augmented forest. We use the fact that the simplex method moves from one basis to another, and each basis is a good augmented forest. Updating Potentials, Tree Indices • Use the node potential algorithm presented before for the new tree(s) O(n) time. • Update the tree indices – can do it from scratch in O(n) time. Termination (1) • The Algorithm moves from one feasible augmented forest structure to the other until it satisfies the optimality conditions. • In a pivot operation, the objective function π value decreases by the amount of πΏ|ππ,π | at every iteration (no proof) • If each pivot operation is nondegenrate (i.e πΏ > 0) each subsequent augmented forest structure has a smaller cost. Termination (2) • Since any network has a finite number of augmented forest structures, and each augmented forest structure has a unique associated cost(which decreases with every iteration), the generalized network simplex algorithm terminates. Dealing with Degenerate Pivots • We define π as an n-vector whose elements are (πΌ, πΌ, … , πΌ) for a sufficiently small real number πΌ. • If we replace π by π + π it is possible to prove that the augmented forest structure at every iteration is not degenerate and therefore the algorithm terminates. • It is also possible to prove that an optimal augmented forest structure of the perturbed problem is also an optimal augmented forest structure of the original problem. Complexity • #of iterations * complexity of iteration. • Cannot bound the number of iterations by any polynomial p(n,m). • In practice the number of iterations is generally a low order polynomial p(n,m). • All of the operations: identifying the entering arc, computing π¦π,π values, updating flows, potentials and tree indices require O(m) time. So in practice the time complexity is a low order polynomial p(n,m). • Empirical investigations found that the generalized network simplex algorithm is 2 to 3 times slower than that of the minimal cost simplex algorithm. An Application Example • Sally owns a warehouse of fixed capacity 1000 units to store a type of wine whose price is unstable • She knows the price of the product for the next 3 time periods, and she needs to manage her purchases, sales and storage patterns. • Suppose she holds πΌ0 = 100 units of the wine, and she has πΆ0 = 10,000 dollars in assets. • In each period she can sell and buy wine under the limitations. • The price of the wine varies(we define it as π(π) at time i) and ultimately all of the wine must be sold. • The idea is to maximize the amount of cash πΆ4 available at the end of the third period. (πππ π‘, πππππππ‘π¦, ππ’ππ‘ππππππ) v u π = (π1 , π2 , π3 ) Warehouse: Can store 1000 units of wine πΌ0 = 100 π’πππ‘π =10,000$ Flow represent wine quantity here 1 sell 1 (0, ∞, ) π1 buy 1’ Flow represent $ here $ (πππ£πππ‘πππ¦_βππππππ , 1000,1) π’πππ‘ 2 3v sell (0, ∞, π ) 3 sell buy 2’ (0, ∞, ππππ πππ‘πππ π‘) 3’ 4’ The End