15.053 February 22, 2007: Introduction To The Simplex Algorithm
15.053 February 22, 2007: Introduction To The Simplex Algorithm
053
z
Give a man a fish dinner, and he will forget it by next week. Let a person catch the fish for himself, and hell remember it for a lifetime. -- Jim Orlin
S
5 4 3 2 1
Start at any feasible corner point. Move to an adjacent corner point with better objective value. Continue until no adjacent corner point has a better objective value.
This is a picture of the simplex algorithm in inequality form. In this form, the simplex algorithm moves from corner point to corner point. And each corner point is the intersection of two constraints. When we move to equality form, the simplex algorithm still moves from corner point to corner point. And the corner points are still found by solving a system of equations. So, there are many similarities.
Is it optimal?
Yes
No
No
Is the optimum unbounded from above?
Yes
As you can see, this is a fairly simple structure. At the same time, it may be difficult to keep everything in ones head at the same time. That is where the two dimensional example can help out. We will assume that we start with a feasible corner point solution. That immediately raises two questions. What does a corner point solution look like? And how do you find a corner point solution to start with? Both of these issues will be addressed shortly. The next slides deal with something even more preliminary. We will be assuming that we start with a linear program with equality constraints and non-negativity constraints, and nothing else. So we need to get each linear program into the correct starting form. We will show how to do that on the next few slides.
1.
2.
3.
Excel Solver does not require that you write an LP in standard form because it will immediately transform it to standard form via software. We show next what linear programming solvers do with an LP that does not start in standard form.
After
x1 + 2x2 + x3 - x4 +s1 = 5
s1 0
s1 is called a slack variable, which measures the amount of unused resource. Note that s1 = 5 - x1 - 2x2 - x3 + x4. To convert a constraint to an equality, add a slack variable.
7
So, we transform a constraint by 1. adding a slack variable 2. requiring that the slack variable is non-negative.
constraints
Consider the inequality -2x1 - 4x2 + x3 + x4 -1; Step 1. Eliminate the negative RHS. Multiply by -1. 2x1 + 4x2 - x3 - x4 1 Step 2. Convert to an equality 2x1 + 4x2 - x3 - x4 s2 = 1 s2 0
The variable added will be called a surplus variable. To convert a constraint to an equality, subtract a surplus variable.
8
We get rid of negative right hand sides by multiplying through by -1. We transform a constraint by 1. adding a surplus variable 2. requiring that the slack variable is non-negative. To be honest, I sometimes confuse the names slack and surplus because they are serving the exact same function, converting an inequality constraint to an equality constraint. They have different names because of their interpretations in practice. Often a constraint will model a case in which we have limited resources, and the slack represents the amount left over. Often a constraint will model a case in which we have to produce at least a specified amount. If we produce more than we need, we are said to have produced a surplus.
Converting Max to Min: multiply objective by -1 Example: Minimize z = 3x1 + 2x2 subject to constraints
Has the same optimum solution(s) as Maximize v = -3x1 - 2x2 subject to constraints
Minimizing z is equivalent mathematically to maximizing z. Interestingly, practitioners often have a very strong preference. If you tell a practitioner that you are maximizing the negative of the cost, it will sound very confusing, unless you convert it somehow to maximizing profit. But mathematically, there is no important distinction.
Other transformations
See tutorial on transformations.
10
The tutorial covers situations in which a variable x does not start with the constraint x 0. It is possible that in a model, some variables are constrained to be nonpositive, and possibly other variables have no constraint on sign at all. In all of these cases, the LP solver will first create an equivalent program in which all variables are constrained to be non-negative.
The set of equations with the xs written in the top row is called a tableau. We will use tableaus to illustrate the simplex algorithm.
x1 2 1 2 0 1 0
x2 2 1 -1 -3 -1 -2 1 0 0
x3 1 1/2 12 2 3/2
= = = = =
We want column 1 to be
Divide through equation 1 by 2. Subtract two times equation 1 from equation 2. Subtract equation 1 from equation 3.
12
For more information on solving systems of equations, see the tutorial on the website.
x1 1 0 0
x2 0 1 1 -3 0 -2 0 1 0
= = = = =
We want column 2 to be
Divide through equation 2 by -3. Subtract equation 2 from equation 1. Add two times equation 2 to equation 3.
13
x1 1 0 0
x2 0 1 0 0 0 1
== == ==
We want column 3 to be
Divide through equation 3 by 5/6. Subtract equation 3 from equation 1. Add 1/3 times equation 3 to equation 2.
14
x1 1 0 0
x2 0 1 0
== == ==
Resulting equations
x1 = 1, x2 = 2, x3 = 3.
The solution is now obvious. The system of equations is in a very special form.
15
At the end, each column for a variable has a single 1 and two 0s. The equations themselves are the same as the solution.
Start with a tableau in canonical form LP has equality constraints and non-negativity constraints. There is one basic variable for each equality constraint. The column for the basic variable for constraint j has a 1 in constraint j and 0s elsewhere. The remaining variables are called non-basic.
16
Standard form does not necessarily give a corner point solution. But standard form is a good place to get started. For a corner point solution,
z 1 0 0 0 x1 0 0 0 1 x2 2 2 -1 6 x3 0 1 0 0 x4 0 0 1 0 x5 1 -1 2 3 = = = = 2 4 1 3
The non-basic variablesxare 3 for There is one basic variable, 2and 4 5 LP has equality constraints and xx. . basic variables are 1, x x and z is consideredconstraints. variable. each equality constraint. non-negativity to bethat has one 1 They have a column a basic and all other components are 0
17
If we got rid of the non-basic variables (as in erasing the columns for x2 and x5), then the resulting equations would be the same as the solution. That is, the equations would be x3 = 4, x4 = 1, x1 = 3. In reality, we dont erase the columns. We just set the non-basic variables to 0, which is mathematically equivalent.
18
We will use the term basic feasible solution or bfs throughout the rest of the semester. Every bfs is also a corner point solution, in that it is not the midpoint of a line segment joining two other solutions. The simplex method will move from corner point to corner point along edges.
The first example is an LP in which 1. The objective function only has terms for the nonbasic variables. 2. The coefficients of the variables in the objective function are nonpositive and only involve the nonbasic variables. 3. The only constraints on the non-basic variables are nonnegativity constraints. So, all one needs to do is to set x2 and x5 optimally, which in this case sets them both to 0.
A second example maximize subject to z = -2x2 x5 + 2 x1 = 3 6x2 3x5 x3 = 4 2x2 + x5 x4 = 1 + x2 2x5 x1, x2, x3, x4, x5 0 What is an optimal solution for this problem?
20
The second example is an LP in which 1. The objective function only has terms for the nonbasic variables. 2. The coefficients of the variables in the objective function are nonpositive and only involve the nonbasic variables. 3. Setting the nonbasic variables to 0 gives a feasible solution. In this case, setting the nonbasic variables to 0 gives a feasible solution with z = 2. And any other solution has x2 0 and x5 0, and thus z 2. So, the solution with the nonbasic variables set to 0 must be optimal. So, all one needs to do is to set x2 and x5 optimally, which in this case sets them both to 0.
21
The objective function has the following properties: 1. The coefficients of the nonbasic variables are nonpositive 2. The coefficients of the basic variables are 0. And the feasible solution x is obtained by setting the nonbasic variables to 0.
It is optimal!
= = = =
2 4 1 3
z = -2x2 x5 + 2 s.t.
Optimality conditions for a bfs in tableau form: the coefficients in the z-row nonnegative for the nonbasic variables. Note that tableaus that correspond to bfss already have the following properties: 1. The coefficients of the basic variables in the objective function are 0 2. There is a feasible solution obtained by setting the nonbasic variables to 0. Thus the optimality condition stated above for a bfs in tableau form are the same as from the previous slides.
Optimality Conditions
z 1 0 0 0 x1 0 0 0 1 x2 2 2 -1 6 x3 0 1 0 0 x4 0 0 1 0 x5 1 -1 2 3 = = = = 2 4 1 3 Important Fact. If there is no negative coefficient in the z row, the basic feasible solution is optimal!
maximize
z = -2x2 x5 + 2
23
24
The objective function (for a max problem) in this example satisfies the following conditions: 1. The coefficients of the basic variables in the objective are 0 2. There is a positive coefficient in the objective for a nonbasic variable 3. The only constraints on the nonbasic variables are nonnegativity constraints. In this case, we can get a sequence of increasingly better solutions by making x5 increasingly larger.
A second example maximize subject to z = -2x2 + x5 + 2 x1 = 3 6x2 + 3x5 x3 = 4 2x2 + x5 x4 = 1 + x2 + 2x5 x1, x2, x3, x4, x5 0 What is an optimal solution for this problem?
25
The objective function (for a max problem) in this example satisfies the following conditions: 1. The coefficients of the basic variables in the objective are 0 2. There is a positive coefficient in the objective for the nonbasic variable x5. 3. For any fixed choice of x5 > 0, there is a feasible solution in which the only positive variables are x5 and the current basic variables. In this case, we can get a sequence of increasingly better solutions by making x5 increasingly larger.
Directions of Unboundedness maximize subject to z = -2x2 + x5 + 2 x1 = 3 6x2 + 3x5 x3 = 4 2x2 + x5 x4 = 1 + x2 + 2x5 x1, x2, x3, x4, x5 0 Let x5 = . Let x2 = 0. Assume that 0 Then x1 = 3 + 3 x3 = 4 + x4 = 1 + 2 z =
Direction of unboundedness
3 3 0 0 x = 4 + 1 1 2 0 1
26
When the solution is unbounded from above, we often keep track of the sequence of solutions whose objective is unbounded from above. This can be done very efficiently by storing a feasible x solution and a direction of unboundedness y. Then for every value of , the solution x + y is feasible. As gets increasingly larger, the objective for x + y gets increasingly larger, and approaches infinity in the limit.
Fact: an LP is unbounded from above if and only if there is a feasible solution and there is also a direction of unboundedness.
27
The property of direction of unboundedness is true for linear programs, but is not true for non-linear programs. For example, one could imagine a feasible region in two dimensions that is a spiral, and that the objective goes to infinity as one moves along the spiral. But there is no direction of unboundedness as defined on the slide.
z 1 0 0 0 x1 0 0 0 1 x2 2 2 -1 6 x3 0 1 0 0 x4 0 0 1 0 x5 -1 -1 -2 -3
= = = =
2 4 1 3
A maximization LP is unbounded from above if there is a bfs and a non-basic variable xs such that 1. The coefficient for xs is the z-row is negative, and 2. All coefficients in the column for xs are 0.
In the tableau form, the objective is written as z + 2x2 - x5 = 2. Unboundedness conditions when given a bfs in tableau form for a max problem: there is a negative coefficient in the z-row for some nonbasic variable xs. The column in the tableau for xs is nonpositive. For any specified value of xs, one can adjust the values of the current basic variables to provide a feasible solution. One shows that the objective value is unbounded from above by letting xs approach infinity.
28
Is it optimal?
No
No
An example maximize subject to z = -2x2 + x5 + 2 x1 = 3 6x2 - 1x5 x3 = 4 2x2 2x5 x4 = 1 + x2 + 2x5 x1, x2, x3, x4, x5 0
Together we will figure out how to get improved solutions. Can you find one or two solutions that are better than the bfs?
29
In this example, one of the basic variables x5 has a positive coefficient in the objective function. But the unboundedness conditions are not satisfied. If we make x5 a little larger than 0, we can adjust the current basic variables to give a feasible solution and this feasible solution will have a larger objective value than the current bfs. The larger that x5 is, the larger will be the objective value. So, we want to make x5 as large as possible so long as the other basic variables remain non-negative.
30
We copied the equations so that there would be space to write the improved solutions.
2 4 1 3
=+ z + 2x2 2x5 = 0 x1 = 3 - 1 x2 = 0 x3 = 4 2 x4 = 1 + 2 x5 =
Find a non-basic variable with a negative coefficient in the z-row. Set that variable to , and keep all other nonbasic variables at 0.
Choose maximum
31
We could look for improved solutions by just guessing the value of x5. But to do it systematically, we set it to . As you can see, I am fond of using as a parameter. Once we set it to , we can see how the current basic variables vary as a linear function of . We then choose as high as possible so that all of the current basic variables are nonnegative. In this case, we can let be as large as 2. If it were any larger, than x3 would be negative.
M&Ms really can be bought in very large packages with quantity discounts, and you can choose the colors. You can even have custom printing (e.g., I love 15.053). See http://www.mymms.com for more details.
Let x1 be the number of 7 pound bags purchased (in thousands) Let x2 be the number of 5 pound bags sold (in thousands) Measure the profit in $10,000s.
33
A 2-variable LP
maximize subject to z= -3x1 + 2x2 -3x1 + 3x2 -4x1 + 2x2 x1 0, x2 0 -3x1 + 2x2 -3x1 + 3x2 +x3 + x4 -4x1 + 2x2 x1, x2, x3, x4 x1 3 -3 -4 x2 -2 3 2 x3 0 1 0 x4 0 0 1
= = =
6 2
maximize subject to
z=
=6 =2 0
z 1 0 0
0 6 2
34
4 3
number sold
2 1
2 3 4 number bought
35
For this particular LP, the feasible region is unbounded, but there will be an optimal solution.
4 3 2 1
4
36
The optimal solution will be x1 = 1 and x2 = 3. The slack variables will both be 0.
LP canonical form
The initial tableau is already in canonical form.
z 1 0 0
x1 3 -3 -4
x2 -2 3 2
x3 0 1 0
x4 0 0 1
= = =
0 6 2
The basic variables are z, x3 and x4. The non-basic variables are x1 and x2. The basic feasible solution (bfs) for this basis is z = 0, x1 = 0, x2 = 0, x3 = 6, x4 = 2
37
0 6 2
The simplex method starts with a tableau in LP canonical form (or it creates canonical form at a preprocess step.) The first solution is the bfs for that tableau.
38
We will discuss next lecture what to do if there is no obvious way of getting a tableau in canonical form.
0 6 2
Is it optimal?
Yes
No We were lucky to be able to start with a feasible bfs. We now move on to the rest of the algorithm. Next lecture: how to find a starting bfs
40
0 6 2 If x1 = 0, and x2 = 1, then z = 2.
41
We can find a better solution by increasing x2 above 0 and adjusting the current basic variables to get a feasible solution.
z 1 0 0
x1 -3 3 -3 -4
x2 -2 2 3 2
x3 0 1 0
Cleaver 43
We dont know. So, well set x2 to be some unknown parameter . Well figure out the other variables in terms of . And then well make as large as we can.
Tim
Cleaver
44
Tim is always asking good questions, even if he doesnt know many of the answers.
z 1 0 0
x1 -3 3 -3 -4
x2 -2 2 3 2
x3 0 1 0
x4 0 0 1
= = =
0 6 2
Choose as large as it can be so that all variables remain non-negative. That is, the solution stays feasible. =1
z = 2, x1 = 0, x2 = 1, x3 = 3, x4 = 0.
45
Can you show me a picture of this. Im having trouble seeing what is going on.
Tim
46
-3x1 + 3x2
-4x1 + 2x2
max s.t
2
z= -3x1 + 2x2 -3x1 + 3x2 6 -4x1 + 2x2 2 x1 0, x2 0 Our initial solution was to do nothing. the simplex method then realized it could do better by selling bags. But it could sell at most 1.
4
Bags sold
3 2 1
m&m
2 3 4 Bags bought
47
Note that the solution x1 = 0 and x2 = 1 is a corner point. It turns out that it is also a basic feasible solution.
Ollie,
the computationally
wise owl.
48
All bfss correspond to corner point solutions. Ollie knew that, but decided to only tell you about a specific solution.
Non-basic variable x2 becomes basic. 0 6 2 Choose column 2. Basic variable x4 becomes non-basic. 0 0 1
49
Since x2 replaces x4, the column for x2 after the iteration (pivot) will be the same as the column for x4 before the iteration (pivot). In that way, we will still have canonical form after the pivot.
-z z 1 0 0
x1 -1 3 -3 3 -2 -4
x2 -2 0 0 3 1 2
x3 0 1 0
x4 1 0 -1.5 0 .5 1
2 0 3 6 1 2
z= 2 x1 = 0 x2 = 1 x3 = 3 x4 = 0
50
Note that the bfs after the pivot is exactly what we wanted. By letting x2 = and increasing from 0 to 1, we were moving along an edge of the feasible region. At the end of the edge is another corner point.
Start in canonical form with a basic feasible solution Check for optimality conditions If not optimal, determine a non-basic variable that should be made positive Increase that non-basic variable, and perform a pivot, obtaining a new bfs Continue until optimal (or unbounded).
1. 2.
3.
4.
51
z 1 0 0 0
x1 a b c d
x2 0 0 1 0
x3 0 1 0 0
x4 0 0 0 1
= = = =
3 6 3 5
1. What are the basic variables? What is the current bfs? 2. Under what condition is the current bfs optimal?
52
z 1 0 0 0
x1 a b c d
x2 0 0 1 0
x3 0 1 0 0
x4 0 0 0 1
= =
=
=
3 6 3 5
1. If we set x1 to , what are x2, x3, and x4, all expressed in terms of . 2. Assume that b > 0 and d < 0. Under what condition we will set = 3/c? 3. If = 3/c, what coefficient do we pivot on next?
53
Recognizing Unboundedness
If the non-cost coefficients in the entering column are 0, then the solution is unbounded z 1 0 0 x1 -1 -3 -2 x2 0 0 1 x3 0 1 0 x4 1 -1.5 .5
= = =
z - x1 + x 4 = 2
2 3 1 z= 2+ x1 = x2 = 1 + 2 x3 = 3 + 3. x4 = 0
z 1 0 0
x1 -1 3 -2
x2 0 0 1
x3 0 1 0
x4 1 -1.5 .5
= = =
2 3 1
z - x1 + x4 = 2 z= 2+ x1 = x2 = 1 + 2 x3 = 3 - 3. x4 = 0
The cost coefficient of x1 in the z-row is negative. Set x1 = and x4 = 0. Then = 3/3.
55
Another pivot
z 1 0 0 x1 -1 0 1 3 -2 0 x2 x3 x4
= = =
3 2 1 3 3 1
3 z= 2+ x1 = 1 1 x2 = 3 + 2 0 x3 = 3 - 3. x4 = 0
The largest value of is 3/3. Variable x1 becomes basic, x3 becomes nonbasic. So, x1 becomes the basic variable for constraint 1. Pivot on the coefficient with a 3.
56
3 1 3
There is no negative coefficient in the z-row. The current basic feasible solution is optimal!
57
58
Start in canonical form with a basic feasible solution Check for optimality conditions z Is there a negative coefficient in the cost row? If not optimal, determine a non-basic variable that should be made positive z Choose a variable with a negative coef. in the cost row. Increase that non-basic variable, and perform a pivot, obtaining a new bfs (or unboundedness) z We will review this step, and show a shortcut Continue until optimal (or unbounded).
2.
3.
4.
59
The Minimum Ratio Rule for determining the leaving variable. z - 3x1 = 3
z x1 -3 3 -2 2 x2 0 1 0 0 x3 0 0 1 0 x4 0 0 0 1 1 0 0 0
= = = =
3 6 1 5 z = 3 + 2 x1 = x2 = 6 - 3 x3 = 1 + 2 x4 = 5 - 2
= min (6/3, 5/2). At next iteration, pivot on the 3. ratio: RHS coefficient/ entering column coefficient s.t. entering column coefficient is positive
60
To determine the column to pivot on, select a variable with a negative cost coefficient To determine a row to pivot on, select a coefficient according to a minimum ratio rule Carry out a pivot as one does in solving a system of equations.
61
62