# Linear programming

### Linear programming – The Simplex Algorithm

The Simplex algorithm for solving LP’s requires that all constraints are equations (with exception of sign constraints on the variables) and all variables be nonnegative. An LP in this form is said to be in

### standard form

. Any LP can be converted into an equivalent one in standard form. Example: max

z

 20

x

1  15

x

2 s.t.

x

1 50

x

1 20

x

1  

x

2 35

x

2 15

x

2 , 2      100 100 6000 2000 0 max

z

 20

x

1  15

x

2 s.t.

x

1 50

x

1 20

x

1  

x

2 35

x

2 15

x

2 

s

1 

s

2   

s

3    4 100 100 6000 2000 all variables  0  

s e

variables are called variables are called

slack excess

variables or

surplus

variables We usually refer to both the slack and surplus variables as ‘slacks’. We can also convert an LP with unrestricted or nonpositive variables into standard form. 1

Suppose we have an LP in standard form with

n

variables and

m

constraints. For convenience, we label the variables

x x

1 , 2 , ,

x n

. max (or min)

z

    s.t.   2 2    

n n n

 

b

1

b

2

a x m

1 1 

a x m

2 2  

a x mn n

b m x x

1 , 2 , ,

x n

 0 If we define

A

     

a a a

 11 21

m

1

a

12

a

22 

a m

2   

a a

 1

n

2

a mn n

     ,

x

x x

1 2        

x n

, and

b

b b

2     , then the equation constraints of the LP can be written in matrix form as

. Usually,

### A

is called the

constraint matrix

and

### b

is the

right hand side

vector. We can write all the constraints of an LP in standard form as follows:

 

### b

0 Before we can present the Simplex method for solving LP’s we need to review some fundamental definitions and results. 2

Consider here a system of equations where we assume

n

m

### b

with

n

variables and (i.e., more variables than equations).

m

constraints,

### Definition:

A

basic solution

to the system of equations

### b

is obtained by: 1.

2.

3.

setting

n

m

variables equal to 0, solving for the

m

remaining variables, and confirming that the solution for these

m

remaining variables is unique. Comment: condition 3 is equivalent to requiring that the

m

columns of matrix

### A

that correspond to these

m

variables be

linearly independent

. This means that none of these

m

columns from

### A

can be expressed as a linear combination of the remaining

m

 1 columns. The

n

m

variables that are fixed equal to 0 are called

### nonbasic variables (NBV).

The remaining

m

variables are called

### basic variables (BV).

Note that, in general, different choices of nonbasic and basic variables will yield different (basic) solutions to the system of equations

### b

. Example: Find all basic solutions to the system

x

1 

x

2 

x

2 

x

3  3   1    NBV = NBV = NBV =

x

3

x

2

x

1 , BV= , BV= , BV= 3 3 2 }

x

1

x

1

x

1  2,

x

2  3,

x

2  0,

x

2  1,

x

3  0,

x

3  3,

x

3   0 2   1

### Definition:

A nonnegative basic solution is a called a

basic feasible solution

### (bfs)

since it is feasible to

 

and basic for

.

### Theorem:

the basic feasible solutions of polyhedral set defined by

 

.

### b

are the extreme points of the 3

Example:

x

1 2

x

1 

x

2 

x

2

x x

1 , 2  40  60  0 By drawing the polyhedron in 2 ) space, we see that its extreme points are: (0,0), (30,0), (20,20), (0,40). Now we want to identify the basic feasible solutions and see their correspondence with the extreme points. To do this, we need to convert the constraint into standard form by adding slacks.

x

1 2

x

1 

x

2 

x

2 

s

1 

s

2  40  60 BV NBV

x

1 , 2

x

2 2  0

s

1

s

2 bfs?

### Definition:

Two basic feasible solutions are called

if their sets of basic variables differ in only one variable.

### Theorem:

If a linear program has an optimal solution, then there is one that is an extreme point.

### Corollary:

we can solve an LP in standard form by considering only its basic feasible solutions. 4

### The Simplex Method

1.

Convert the LP to standard form. 2.

Obtain a bfs (if possible). 3.

Determine whether the current bfs is optimal 4.

If current bfs is not optimal, determine which nonbasic variables should become basic and which basic variable should become nonbasic, so that a new (adjacent) bfs with better objective function value is obtained. 5.

Compute the values of the variables in the new bfs by using elementary row operations (ero’s). Go back to step 3. Example: max

z

 60

x

1  30

x

2  20

x

3 s.t. 8

x

1 4

x

1 2

x

1  6

x

2  2

x

2  1.5

x

2

x

2 

x

3  1.5

x

3  0.5

x

3     , 3  0 48 20 8 5 We first write the objective function in the following form:

z

 60

x

1  30

x

2  20

x

3  0 and we convert the constraints to standard form: 5

Row 0 Row 1 Row 2 Row 3 Row 4

z

- 60

x

1 - 30

x

2 - 20

x

3 8

x

1 4

x

1 2

x

1 + 6 + 2

x

2

x

2

x

2 + 1.5

x

2 +

x

3 + 1.5

x

3 + 0.5

x

3 +

s

1 +

s

2 +

s

3 + = 0 = 48 = 20 = 8

s

4 = 5 Basic variable

z s

1

s

2

s

3

s

4 We need an initial bfs. Note BV = { bfs

s

1  48,

s

2  20,

s

3  8,

s

4  5 ,

x

1 

x

2 2  3

x

3 4  }, NBV = { 0 . The

value

2 , 3 } gives the of this bfs is

z

= 0.

The constraints in the above tabular formulation of our LP are not only in standard form, they are also in

Simplex tableau form

with respect to the choice we made of BV and NBV. Simplex tableau form means that each row is associated to a unique basic variable which appears in its row with a coefficient of 1 (and coefficient 0 in all other rows). We will consider also

z

to be the basic variable associated with row 0 (however, we don’t require

z

to be nonnegative like the decision variables). Is this bfs (

s

1  48,

s

2  20,

s

3  8,

s

4  5 ,

x

1 

x

2 

x

3  0 ) an optimal solution?  0 = 48 = 20 = 8 = 5 Note that, in this case, the value of

z

will improve if we can make 2 , or

x

3 positive. For a maximization LP, we will choose to increase the value of the nonbasic variable with the most negative coefficient in row 0 (in this case,

x

1 ) . We say we choose

x

1 to

enter

the set of basic variables. Note that we choose to increase the value of only one nonbasic variable per iteration, the others will remain fixed at value 0. This will have the effect of moving from one extreme point of the feasible region to a (better) adjacent one. 6

We need to determine now which (currently) basic variable should become nonbasic. Note that as we increase the value of

x

1 , the values of the current basic variables must update according to: 8

x

1 +

s

1 4

x

1 2

x

1 +

s

2 +

s

3

s

4 = 48 = 20 = 8 = 5 That is,

s

1 = 48 - 8

x

1

s

2

s

3

s

4 = We need to maintain the nonnegativity of all variables that are currently basic:

s

1

s

2

s

3 = = = = = 20 - 4

x

1 8 - 2

x

1 5 48 - 8 20 - 4 8 - 2

x

1 

x x

1 1   0 0 0

s

4 (

s

4 is not affected here by changes in value of

x

1 ) To preserve the nonnegativity of 2

s

3 ,

s

1 nonnegative if:

x

1  48  6 8

s

2 nonnegative if:

x

1  20  5 4

s

3 nonnegative if:

x

1 4 2 7

### Ratio test

: The largest value we can assign to

x

1 now is the minimum of 48 20 8 , , 8 4 2   = 4. Note that if we set

x

1  4 , then

s

3 becomes 0. Variable

s

3 is the one that we select to leave the set of basic variables and become nonbasic. Now we need to compute the values of the new bfs. In the same process we can update our Simplex tableau to a canonical form that represents the new choice of BV and NBV. The row of the entering variable (

x

1 ) in the new tableau will be the one of the leaving variable (

s

3 ). We transform our current tableau to obtain the new one by a sequence of elementary row operations.

x

1 enters BV  Row 0

z

- 60

x

1 - 30

x

2 - 20

x

3 Row 1 8

x

1 + 6

x

2 +

x

3 + Row 2 4

x

1 + 2

x

2 + 1.5

x

3 Row 3

### 2

x

1 + 1.5

x

2 + 0.5

x

3 Row 4

x

2

s

1 +

s

2 +

s

3 leaves BV 

s

3 +

s

4 = 0 = 48 = 20 = 8 = 5 The row of the leaving variable (in this case Row 3) is called the

### pivot row.

The coefficient of

x

1 in the pivot row is called the

### pivot term.

We will compute the values of the variables in the new basic feasible solution and update the Simplex tableau to reflect the new choice of BV and NBV. We will do this using elementary row operations (ero’s) on the current tableau. 8

Henceforth, we will save effort by dropping the variables from the Simplex tableau and show only the coefficient entries: Row 0 Row 1 Row 2 Row 3 Row 4 1 0 0 0 0

z x

1 - 60 - 30 - 20 8 4 2 0

x

2 6

x

3 1 2 1.5 1.5 0.5 1 0

s

1 0 1 0 0 0

s

2 0 0 1 0 0

s

3 0 0 0 1 0

s

4 0 0 0 0 1 rhs 0 48 20 8 5

z s

1   0 48

s

2  20

s

3  8

s

4  5 Elementary row operations to update the Simplex tableau: 1.

Divide all entries in the pivot row (here, row 3) by the pivot term so that the entering variable (here,

x

1 ) has a coefficient of 1 in the pivot row. (new row 3) = 0.5 * (old row 3)

z x

1

x

2

x

3 Row 0 Row 1 Row 2 Row 3 Row 4 1 0 0 0 0 - 60 - 30 - 20 8 6 1 4 2 1.5 1 .75 .25 0 1 0

s

1 0 1 0 0 0

s

2 0 0 1 0 0

s

3 0 0 0 .5 0

s

4 rhs 0 0 0 48 0 20 0 4 1 5 2.

Add appropriate multiples of the pivot row to eliminate the entering variable from all other rows. (new row 0) = (old row 0) + 60 * (new row 3) (new row 1) = (old row 1) - 8 * (new row 3) (new row 2) = (old row 2) - 4 * (new row 3) (new row 4) = (old row 4) - 0 * (new row 3) 9

The (updated) Simplex tableau for BV={ 2 1 4 } is: Row 0 Row 1 Row 2 Row 3 Row 4 1 0 0 0 0

z x

1 0 0 0 0

x

2 15 0 -1 1

x

3 - 5 -1 .5 1 .75 .25 0

s

1 0 1 0 0 0

s

2 0 0 1 0 0

s

3 30 -4 -2 .5 0

s

4 rhs 0 240 0 16 0 0 1 4 4 5

z s

1   240 16

s

2  4

x

1  4

s

4  5 We have completed one iteration of the Simplex Method. Now we need to determine if the current bfs is an optimal solution for the LP. Since the coefficient of

x

3 in row 0 is negative, we can improve

z

if we make

x

3 positive. Thus, we can not conclude that we have an optimal solution and we decide to have

x

3 become basic. We do the ratio test to determine which variable leaves the basis. We only consider rows with positive entries in the column of the entering variable (

x

3 ), since these correspond to the basic variables that decrease as

x

3 increases.

x

3 rhs ratios Row 0 Row 1 (

s

1 ) -1 16 no Row 2 (

s

2 ) Row 3 (

x

1 ) Row 4 (

s

4 ) .5 .25 0 4 4 5 4/.5 4/.25 no Minimum ratio attained at Row 2, thus

s

2 leaves basis. New set of basic variables is: BV={ 3 4 } . We use elementary row operations to update the tableau (see next page). 10

Row 0 Row 1 Row 2 Row 3 Row 4 1 0 0 0 0

z x

1 0 0 0 0

x

2 5 -2 -2 1 1.25 1

x

3 0 0 1 0 0

s

1 0 1 0 0 0

s

2 10 2 2 0

s

3 10 -8 -4 -.5 1.5 0

s

4 rhs 0 280 0 24 0 0 1 8 2 5

z s

1   280 24

x

3  8

x

1  2

s

4  5 Since the coefficients of the decision variables in row 0 are all nonnegative, we can conclude that the current solution is optimal.

### Remaining issues:

Finding an initial bfs: It is easy for LP’s were all original constraints are  and the right hand side data is nonnegative (as in the LP we just solved). In such case we can use the slacks as initial BV. In the general case, finding an initial bfs is not trivial and requires solving another LP (called the Phase I LP, for which we find an initial bfs by construction). Unbounded LP’s: We conclude that an LP is unbounded if at some iteration we select a variable to enter the basis but there are no upper bound on its value since all coefficients in its column has no positive coefficients (i.e., we can’t do the ratio test) Convergence: There are at most

n m

possible basic solutions. Assuming we don’t repeat a basis, the Simplex method will terminate in a finite number of iterations. Repeating a basis is called “cycling” and can only occur if the constraints are

degenerate.

There are anti-cycling rules that can be used with the Simplex method, but these are not implemented in commercial codes since cycling is rarely a problem in practice. 11