Distributed Real-Time Control Systems Lecture 13-14 Distributed Control Linear Programming 1
Linear Programs Optimize a linear function subject to a set of linear (affine) constraints. Many problems can be posed as linear programs and have wide application in operations research: scheduling assignment problems supply chain management automation optimal pricing transportation 2
Example: Mr. Silva s Electronics, Lda Mr. Silva has an electronics company that produces two products: (P1) MP3 players (P2) Alarm Clocks. MP3 players can be sold at 7 and Alarm Clocks at 5. The company has a stock of 100 NIMH battery cells and 240 push buttons. Each MP3 player needs 2 battery cells and 4 pushbuttons. Each Alarm Clock needs 1 battery cell and 3 pushbuttons. How many items of each product should Mr. Silva produce to maximize his profit? 3
Example: Mr. Silva s Electronics, Lda x 1 : amount of MP3 players to produce x 2 : amount of Alarm clocks to produce Maximize Profit: Battery Cells constraint: Push Buttons constraint: Positivity constraints: 7x 1 + 5x 2 2x 1 +1x 2 100 4x 1 + 3x 2 240 x 1 0, x 2 0 4
Example: Mr. Silva s Electronics, Lda maximize c T x subject to Ax b, x 0! x = x 1 x 2 c =! 7 5! A = 2 1 4 3! b = 100 240 5
Example: Mr. Silva s Electronics, Lda x 2 100 80 2x 1 +1x 2 100 When constraints are written as: v T i x + b i 0 then, their gradient (v i ), points toward the feasible region. v 3 apple 1 0 apple 0 1 x 1 0 v 1 v 1 = v 2 = v 2 x 2 0 4x 1 + 3x 2 240 50 60 x 1 v 3 = apple 2 1 v 4 = apple 4 3 v 4 6
Example: Mr. Silva s Electronics, Lda x 2 100 80 2x 1 +1x 2 100 x 2 0 Feasible Region 4x 1 + 3x 2 240 x 2 0 50 60 x 1 7
Example: Mr. Silva s Electronics, Lda x 2 Profit level sets Feasible Region! 7 5 Profit Gradient x 1 8
Example: Mr. Silva s Electronics, Lda x 2 Optimal Solution 2x 1 +1x 2 =100! 4x 1 + 3x 2 x 1 = 240 x 2 =! 2 1 4 3 1! 100 240 80! x 1 x 2 =! 30 40 40 Feasible Region 30 50 x 1 9
Properties of linear programs Feasible regions are convex polyhedra. Both minimization and maximization problems are convex (linear functions are both convex and concave). Local optima are also global optima. 10
Unboundedness: If the feasible set is unbounded in the direction of the gradient, there is no finite solution (solution at infinity) Infeasibility: If the conjunction of the constraint is the empty set. The problem is impossible (no solution) Impossible Cases 11
Degenerate Cases Non-uniqueness: If the gradient is orthogonal to a constraint with optimal solutions, all corners associated to that constraint are also optima (multiple solutions) Gauge freedom: Multiple corners at the same point. Solution is unique but some algorithms may have problems with this. constraint 2 continuum of optimal solutions constraint 1 constraint 3 12
Solutions to Linear Programs Unfortunately most real-world problems have more than two variables. Graphical methods are not possible. Two main types of approaches: Simplex methods: iterate over sequences of extreme points (vertices) of the feasibility polyhedron. Interior point methods: iterate on the interior of the feasibility region. Performance depends on problem type. 13
Simplex methods Start on a feasible solution (vertex) of the problem and move along edges to a neighboor with a better cost. Stop when minimum is reached or unbounded edge visited. NOTE: Requires an initial feasible solution at a vertex. 14
Standard equality form minimize c T x subject to Ax = b, x 0, b 0 Minimization instead of maximization. Only equality constraints. All variables non-negative. All entries of vector b non-negative. 15
Conversion to Standard Equality Form If problem is max z convert it to min z. If there are constraints with negative right hand side, multiply them by -1 To convert a unconstrained variables x, replace it by two new non-negative variables x + -x -. max 7x 1 + 5x 2 min 7x 1 5x 2 x 1 2x 2 8 x 1 + 2x 2 8 x 1 unrestricted x 1 = x 1 + x 1, x 1 + 0, x 1 0 16
Conversion to Standard Equality Form Convert lower-than-orequal inequalities to equalities by adding nonnegative slack variables. Convert greater-than-orequal inequalities to equalities by subtracting non-negative surplus variables. 4x 1 + 3x 2 240 4x 1 + 3x 2 + s 1 = 240, s 1 0 x 1 + 2x 2 8 x 1 + 2x 2 s 2 = 8, s 2 0 Set each slack and surplus variables s coefficients in the cost function to zero. 17
Example: Mr. Silva s Electronics, Lda x 1 : amount of MP3 players to produce x 2 : amount of Alarm clocks to produce s 1 : amount of unused battery cells. s 2 : amount of unused push buttons. Minimize negative profit: Battery Cells constraint: Push Buttons constraint: Positivity constraints: 7x 1 5x 2 2x 1 + x 2 + s 1 =100 4x 1 + 3x 2 + s 2 = 240 x 1 0, x 2 0, s 1 0, s 2 0 18
Example: Mr. Silva s Electronics, Lda Linear Program in Standard Equality form: minimize c T x subject to Ax = b, x 0, b 0! x = x 1 x 2 s 1 s 2 c = 7 5 0 0! A = 2 1 1 0 4 3 0 1! b = 100 240 19
Definitions minimize c T x subject to Ax = b, x 0 x R n b R d A R d n c R n c i R A i R d T! T h i = c i A i H = h i { } i=1...n G H - i th entry of vector c - i th column of matrix A - problem column - set of all problem columns - A subset of the problem columns d = number of affine constraits = number of rows of A = number of slack/surplus variables n = number of original + slack/surplus variables c G A G x G - cost vector reconstructed from columns in G - constraint matrix reconstructed from columns in G - decision variables reconstructed from columns in G 20
Table Form! H 0 b Fully represents the LP in standard equality form H x 1 7 x 2 5 s 1 0 s 2 0 0 2 1 1 0 100 4 3 0 1 240 A b c 21
Basis Assume rank(a)=d. A set B of exactly d columns is called a basis if rank(a B )=d Example. B = {h 3, h 4 } h 3 h 4 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240 A B 22
Basic Solutions Basic solution is a solution x composed of d basic variables x B 0, and a set of n-d non-basic variables x N =0. A basic variable is a variable with only non-negativity constraints. A basic solution is feasible if all basic variables are positive. Example: x = [0 0 100 240] Basic variables: s 1 = 100 s 2 = 240 Non-basic variables: x 1 = 0 x 2 = 0 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240 This is a trivial basic solution and can be used to initialize the simplex search. 23
Computing Basic Solutions Having selected a basis B, a basic solution can be computed by solving the linear system:! A B x B = b x N = 0! x B = A 1 B b x N = 0 The associated cost is: z B = c B T x B The solution is feasible if all elements of x B are nonnegative. 24
Example: Mr. Silva s Electronics, Lda Computing a non-trivial basic solution. Let the basis be B = {h 2,h 3 }. c B 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240 b A 1 B = 0 1/ 3 1 1/ 3 [ ] T = A B 1 b = 80 20 x B = x 2, s 1 80 40 Feasible Region x B T A B FEASIBLE BASIC SOLUTION 30 50 25
Example: Mr. Silva s Electronics, Lda Now let the basis be B = {h 2,h 4 }. A 1 b = apple 1 0 3 1 c B x B =[x 2,s 2 ] T = [100, 60] T 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240 A B b x 2 100 80 x 2 0 2x 1 +1x 2 100 Feasible Region x B 4x 1 + 3x 2 240 x 2 0 NON FEASIBLE BASIC SOLUTION 50 60 x 1 26
Adjacent Bases Two basis B 1 and B 2 are said to be adjacent if only one variable differs from one to the other, i.e. there exists an entering column e and a leaving column l such that: e B 2, l B 1, B 2 = { B 1 e} \ { l} Example: B 1 and B 2 are adjacent bases: e = h 2, l = h 4. 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240 B 2 B 1 27
Perturbation Analysis To evaluate the effect of changing from a basis to an adjacent one, let us consider: B current basis x B current basic solution x h non-basic variable, corresponding to column h. Let us perturb the solution by allowing x h to have values above 0 (feasible). The basic variables will change their value to x B and the solution must verify: Ax = b A B A h x B x h = b x B = A B 1 (b A h x h ) x 0 B = x B A 1 B A hx h 28
Example: Mr. Silva s Electronics, Lda Perturbed solution: Example: B = {h 2, h 3 } A h = A 1, x h = x 1 x 0 B = apple 80 20 x 0 B = x B A 1 B A hx h ( x 0 2 = 80 4 3 x 1 s 0 1 = 20 2 3 x 1 apple 0 1 3 1 1 3 apple 2 4 x 1 A h = A 4, x h = s 2 x 0 B = apple 80 20 ( x 0 2 = 80 1 3 s 2 s 0 1 = 20 + 1 3 s 2 apple 0 1 3 1 1 3 apple 0 1 x 1 29
Graphical Analysis Perturbations around the current solution (green dot). A unit increase in the variable x 1 will make the solution travel along the green arrow and decrease 4/3 on x 2. 80 40 x 2 x 2 = 4 3 x 1 x 2 = 1 3 s 2 A unit increase in variable s 2 will make the solution travel along the red arrow and decrease 1/3 on x 2. 30 50 x 1 30
Reduced cost Given a basis B and a single non-basic column h, its reduced cost represents its contribution to the cost (unitary cost variation) if it enters the basis: z = c T! x = c T B c h! x B x h z = c B T A B 1 (b A h x h )+ c h x h z = c B T x B + (c h c B T A B 1 A h )x h What we gain by adding one element of this variable to the solution c h = c h c B T A B 1 A h What we loose by consuming the resources required. 31
Example: Mr. Silva s Electronics, Lda Reduced costs: c h = c h c B T A B 1 A h Example: B = {h 2, h 3 } c h = c h A h T c 1 = c 1 2 4 c 4 = c 4 0 1 1 ( A B ) T c B 0 1 1/ 3 1/ 3 0 1 1/ 3 1/ 3 5 0 5 0 c B A 1 A 4 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240-1/3 5/3 A B reduced costs 32
Graphical Analysis The cost variation is the inner product of the cost gradient with the perturbation vector. 80 x 2 4x 1 + 3x 2 = 240 c 1 = c 1 x 1 2 3 7 = 6 5 7 4 0 5 0 T 2 6 4 1 4 3 2 3 0 3 7 5 x 1 apple 7 5 40 30 2x 1 +1x 2 =100 50 x 1 = 1 3 x 1 Cost Gradient 33
Analysis Current solution: x =! 0 80 20 0 Reduced costs: c = 1/ 3 0 0 5 / 3 A 1 A 4 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240-1/3 5/3 A B Adding a unit of MP3 Player (x 1 ) has a value of 7 but in the current solution it requires 4 unavailable push buttons, that must be removed from alarm clocks. Because one alarm clock uses 3 push buttons, removing 4 push buttons will penalize us in 4/3 of the value of the alarm clock (5). Therefore we gain 7 but loose 20/3, so the net gain is 1/3. Adding a unit of a push button (s 2 ) has no value and forces us to remove 1 push button from an Alarm clock. By the same reasoning as before, we loose 1/3 of the value of an alarm clock, i.e. 5/3. 34
The entering column Any column whose reduced cost is negative can enter the basis: c h = c h A h T ( 1 A ) T B c B < 0 Often it is chosen the column with the minimal negative cost: T e = argmin{c h A h h ( 1 A ) T B c B c h < 0} 35
The leaving column Given an entering column e we are allowing the nonbasic variable x e to grow from zero to a positive value. As x e grows, what is the first basic variable reaching value 0? x 2 80 40 x e 30 50 x 1 36
The leaving column The basic variables will change as (check the Perturbation Analysis slide):! A B A e! x B x e x B = A B 1 (b A e x e ) = b 37
The leaving column 2/2 To assure feasibility we need: x 0 B = A 1 B (b A ex e ) 0 (x 0 B) j =(A 1 B b) j (A 1 B A e) j x e The first variable x j reaching 0 as x e grows enters the non basic variable set. j = argmin ( A 1 B b) j A ( A 1 B A ) B e j ( 1 A ) e > 0 j 0, 8j x e apple (A 1 B b) j (A 1 B A, (A 1 B e) A e) j > 0, 8j j ( 38
Optimal Solutions Fundamental theorems: If an LP has an optimal feasible solution, then it has an optimal feasible basic solution. Every fully non-degenerate LP has at most one optimal solution. If an LP has an optimal solution and is non-degenerate, then there exists a sequence of adjacent bases from any basis B to the unique optimal basis B*. 39
Basic Simplex Procedure 1. Let a feasible basis B be given. 2. While there exists an entering column e such that e B, c e < 0 find a leaving basic column l such that { B e} \ { l} is still a feasible basis. 3. Exchange l with e to find a new basis. This operation is denoted Pivot. 40
The initial basis Choose a subset of the columns of A forming an diagonal matrix (easily invertible), arising from slack variables. For constraints without slack variables, add an artificial variable with large associated cost M. Advantage: Initial basis is feasible. 41
Initial Basis : Artificial Variables Artificial variables allow an initial identity basis. Greater-than-or-equal constraints take surplus variables instead of slack variables. 2x 1 + x 2 100 =) 2x 1 + x 2 s 1 + a 1 = 100, s 1,a 1 0 Equality constraits have neither slack nor surplus variables. 4x 1 +3x 2 = 240 =) 4x 1 +3x 2 + a 2 = 240, a 2 0 42
Initial Basis : Example b i s must be non-negative min 7x 1 5x 2 ( 2x 1 + x 2 100 s.t. 4x 1 3x 2 240 ( 2x 1 + x 2 100 4x 1 3x 2 240 ( 2x 1 + x 2 s 1 + a 1 = 100 4x 1 3x 2 s 2 + a 2 = 240 x 1 x 2 s 1 s 2 a 1 a 2 b 7 5 0 0 M M 2 1 1 0 1 0 100 4 3 0 1 0 1 240 Initial basis 43
The iterations As seen in the previous slides the inverse of the basis matrix A B plays an important role in many operations. Computing the basic solution x B = A B 1 b Computing the reduced cost c h = c h c B T A B 1 A h Select the entering column T e = argmin{c h A h h Selecting the leaving column j = argmin ( A 1 B b) A 1 j B A e 1 ( A B ) T c B c h < 0} ( ) A j ( 1 B A e ) > 0 j { } 44
Gauss Elimination When the initial basis is the identity, the computation of the inverse can be done in a simple way with Gaussian elimination at each pivot operation, and the problem table transformed so as the new basis is the identity again. [A B A N ] apple xb x N = b A B 1 I A 1 B A apple x B N = A 1 x B b N Having the basis as the identity is very useful because the solution, entering and leaving columns can be checked by inspection. 45
Gauss Elimination Remember Mr. Silva. c c T Bx B = b T c B 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240 A b 46
Gauss Elimination Starting with identity basis 2 6 4 x 1 x 2 s 1 s 2 b 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240 3 7 5 A B 47
Gauss Elimination We want to make columns 1 enter the basis and column 3 leave the basis. 2 6 4 x 1 x 2 s 1 s 2 b 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240 3 7 5 e l A B 48
Gauss Elimination The new basis will be composed by columns 1 and 4. 2 6 4 x 1 x 2 s 1 s 2 b 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240 3 7 5 A B A B We have to make linear combinations of the rows of [A b] to let the identity matrix emerge from columns 1 and 4. 49
Gauss Elimination Locate the pivot element a je in the entering column e at the row where the leaving column had value 1. 2 6 4 x 1 x 2 s 1 s 2 b 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240 3 7 5 Pivot A B The objective is to make the pivot equal to 1 and all other elements of that column equal to 0 50
Gauss Elimination Divide the pivot line a j by the pivot value a je. a j a j / a je Pivot 2 6 4 x 1 x 2 s 1 s 2 b 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240 3 7 5 A B 51
Gauss Elimination Divide the pivot line a j by the pivot value a je. a j a j / a je Pivot 2 6 4 x 1 x 2 s 1 s 2 b 7 5 0 0 0 1 0.5 0.5 0 50 4 3 0 1 240 3 7 5 A B 52
Gauss Elimination Let the remaining lines be a i = a i a ie a j a i a i a ie a j Pivot 2 6 4 x 1 x 2 s 1 s 2 b 7 5 0 0 0 1 0.5 0.5 0 50 4 3 0 1 240 3 7 5 A B 53
Gauss Elimination Let the remaining lines be a i = a i a ie a j a i a i a ie a j Pivot 2 6 4 x 1 x 2 s 1 s 2 b 7 5 0 0 0 1 0.5 0.5 0 50 0 1 2 1 40 3 7 5 A B 54
Gauss Elimination Let the remaining lines be a i = a i a ie a j a i a i a ie a j Pivot 2 6 4 x 1 x 2 s 1 s 2 b 0 1.5 3.5 0 350 1 0.5 0.5 0 50 0 1 2 1 40 3 7 5 A B 55
Gauss Elimination The new basic solution is now x 1 = 50, s 2 = 40 The associated cost is 350 2 x 1 x 2 s 1 s 2 b 3 Pivot 6 4 0 1.5 3.5 0 350 1 0.5 0.5 0 50 0 1 2 1 40 7 5 A B 56
Simple computations Once the basis is the identity, computations are simpler: x B = b j = argmin c h = c h c B T A h e = argmin{c h A T h c B c h < 0} h ( b ) j A e ( ) j ( A e ) j > 0 { } 57
The Simplex Algorithm (1/2) 1. Put the problem in standard equality form for minimization with enough slack/auxiliary variables to have a initial identity basis. 2. Determine which variable to enter the solution. Identify the column with the lowest negative reduced cost. This is the pivot column e. e = argmin{c h A T h c B c h < 0} h 3. Determine which variable to replace. Consider only rows with positive values in the pivot column. Divide each amount in the quantity column (last column) by the corresponding number of the entering column. The row with the smallest non-negative number is the pivot row j. If all are negative, the problem is unbounded. Exit. j = argmin ( b ) j A e ( ) j ( A e ) j > 0 { } 58
The Simplex Algorithm (2/2) 4. Compute new values for the pivot row. Divide all elements by the pivot number. a j a j / a je 5. Compute new values for the remaining rows. Take the element of this row at the pivot column, multiply it by the pivot row, and subtract the result from itself. a i a i a ie a j 6. Compute the reduced costs. If all are non-negative, the algorithm converged, goto 7. Otherwise goto 2. c h = c h c B T A h 7. If an artificial variable is in the basis, the problem is unfeasible. Otherwise this is the optimal solution. Exit. 59
Mr. Silva Full Solution Step 1 Table Form 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240 60
Mr. Silva Full Solution Step 2 Compute reduced costs and choose entering column. 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240 7 5 0 0 e = argmin{c h A T h c B c h < 0} h 61
Mr. Silva Full Solution Step 3 Determine which variable to replace 7 5 0 0 0 2 1 1 0 100 4 3 0 1 240 50 60 7 5 0 0 j = argmin ( b ) j A e ( ) j ( A e ) j > 0 { } 62
Mr. Silva Full Solution Step 4 Normalize Pivot Row 7 5 0 0 0 1 0.5 0.5 0 50 4 3 0 1 240 50 60 7 5 0 0 a j a j / a je 63
Mr. Silva Full Solution Step 5 Compute remaining rows 7 5 0 0 0 1 0.5 0.5 0 50 0 1 2 1 40 50 60 7 5 0 0 a i a i a ie a j 64
Mr. Silva Full Solution Step 6 Recompute reduced costs c h = c h c B T A h 7 5 0 0 0 1 0.5 0.5 0 50 0 1 2 1 40 0 1.5 3.5 0 Goto 2. 65
Mr. Silva Full Solution Step 2 Choose entering column 7 5 0 0 0 1 0.5 0.5 0 50 0 1 2 1 40 0 1.5 3.5 0 e = argmin{c h A T h c B c h < 0} h 66
Mr. Silva Full Solution Step 3 Determine which variable to replace 7 5 0 0 0 1 0.5 0.5 0 50 0 1 2 1 40 100 40 0 1.5 3.5 0 j = argmin ( b ) j A e ( ) j ( A e ) j > 0 { } 67
Mr. Silva Full Solution Step 4 Normalize Pivot Row 7 5 0 0 0 1 0.5 0.5 0 50 0 1 2 1 40 100 40 0 1.5 3.5 0 a j a j / a je 68
Mr. Silva Full Solution Step 5 Compute remaining rows 7 5 0 0 0 1 0 1.5 0.5 30 0 1 2 1 40 100 40 0 1.5 3.5 0 a i a i a ie a j 69
Mr. Silva Full Solution Step 6 Re-compute reduced costs c h = c h c B T A h 7 5 0 0 0 1 0 1.5 0.5 30 0 1 2 1 40 0 0 0.5 1.5 All reduced costs positive: converged. 70
Mr. Silva Full Solution Step 7 Conclude 7 5 0 0 0 1 0 1.5 0.5 30 0 1 2 1 40 No artificial variable in the basis. Optimal solution: x 1 = 30, x 2 = 40, remaining 0. 71
Homework Formulate the illumination control problem with two luminaires as a linear program with energy minimization. Solve the problem for a sensible set of values for the cost and coupling constraints. 72