You are on page 1of 33

The Simplex Algorithm

Part 1
Teuku Naraski Zahari, S.T., M.T.
Introduction
Previously, we saw how to solve two-variable linear programming
problems graphically. Unfortunately, most real-life LPs have many
variables, so a method is needed to solve LPs with more than two
variables.

In this chapter, we will discuss the simplex algorithm, which is used to


solve even very large LPs.

In many industrial applications, the simplex algorithm is used to solve


LPs with thousands of constraints and variables.
Standard Form
Before the simplex algorithm can be used to solve an LP,
the LP must be converted into a problem where all the
constraints are in equality and all variables are
nonnegative.

An LP in this form is said to be in standard form.


How to Convert an LP to Standard Form
(1/2)
To convert an inequality constraint with less-than-or-equal-to (≤) to an
equality, we define for each constraint a slack variable 𝑠 where 𝑠𝑖 is
the slack variable for the 𝑖 th constraint.

A slack variable is the amount of the resource unused in the 𝑖 th


constraint.

Add the slack variable 𝑠𝑖 to the 𝑖 th constraint and add the sign
restriction 𝑠𝑖 ≥ 0.
How to Convert an LP to Standard Form
(2/2)
To convert an inequality constraint with more-than-or-equal-to (≥) to
an equality constraint, we define an excess variable/surplus variable
𝑒 where 𝑒𝑖 is the excess variable for the 𝑖 th constraint.

An excess variable 𝑒𝑖 is the amount by which 𝑖 th constraint is over


satisfied.

Subtract the excess variable 𝑒𝑖 from the 𝑖 th constraint and add sign
restriction 𝑒𝑖 ≥ 0.

If an LP has both inequality constraints (≤ and ≥), apply the previous


procedures to the individual constraints.
Example 1
Leather Limited (1/5)
Leather Limited manufactures two types of belts: the deluxe model
and the regular model. Each type requires 1 sq.yd of leather. A
regular belt requires 1 hour of skilled labor, and a deluxe belt requires
2 hours. Each week, 40 sq.yd of leather and 60 hours of skilled labor
are available. Each regular belt contributes $3 to profit and each
deluxe belt, $4.

Write an LP to maximize profit.


Example 1
Leather Limited (2/5)
The decision variables are:
𝑥1 = number of deluxe belts produced weekly
𝑥2 = number of regular belts produced weekly

The appropriate LP is:


max 𝑧 = 4𝑥1 + 3𝑥2
s.t. 𝑥1 + 𝑥2 ≤ 40 (leather constraint)
2𝑥1 + 𝑥2 ≤ 60 (labor constraint)
𝑥1, 𝑥2 ≥ 0
Example 1
Leather Limited (3/5)
Convert the model into standard form. Since both constraints are in a
≤ inequality, then we need to introduce slack variables for each of
them:

For the 1st constraint (leather constraint),


𝑥1 + 𝑥2 ≤ 40 → 𝑥1 + 𝑥2 + 𝑠1 = 40

For the 2nd constraint (labor constraint),


2𝑥1 + 𝑥2 ≤ 60 → 2𝑥1 + 𝑥2 + 𝑠2 = 60
Example 1
Leather Limited (4/5)
• Observe that a point (𝑥1, 𝑥2) satisfies the 𝑖 th
constraint if and only if 𝑠𝑖 ≥ 0. 𝑥2
• For example, 60
o 𝑥1 = 15, 𝑥2 = 20 satisfies the 1st constraint Constraint 2

because 𝑠1 = 40 − 15 − 20 = 5 ≥ 0, which
40
means 5 sq.yd of leather are unused.
o Point (15, 20) also satisfies the 2nd constraint
, because 𝑠2 = 60 − 2(15) − 20 = 10 labor
hours are unused. (20,20)
o Finally, note that the point x1 = x2 = 25 fails
Constraint 1
to satisfy the 2nd constraint, because 𝑠2 =
60 − 2(25) − 25 = −15 indicates that (25, 25)
uses more labor than is available.
30 40 𝑥1
Example 1
Leather Limited (5/5)
Hence the standard form of the original LP is,
Example 2
Converting a ≥ inequality constraint (1/2)
Let’s consider the following LP:
Example 2
Converting a ≥ inequality constraint (2/2)
• Define an excess variable for each of the 𝑖 th constraint 𝑒𝑖, which
are the amount by which the 𝑖 th constraint is over satisfied.
• Thus, the LP in standard form will be:
The Simplex Algorithm
The simplex algorithm can be used to solve LPs in which the goal is to maximize
the objective function.
Step 1 Convert the LP to standard form
Step 2 Obtain a Basic Feasible Solution (BFS) from the standard form, if
possible
Step 3 Determine whether the current BFS is optimal
Step 4 If the current BFS is not optimal, determine which non-basic variable
(NBV) should become a basic variable (BV) and which basic variable
should become a non basic variable to find a BFS with a better
objective function value.
Step 5 Use elementary rule operations (EROs) to find a new BFS with a better
objective function value. Go back to Step 3.
Basic and Nonbasic Variables (1/2)
• To solve a LP with 𝑛 variables and 𝑚
constraints algebraically, we would need 𝑥2

(𝑛 − 𝑚) variables to solve the problem. 60


Constraint 2
o e.g. to solve an equation with two
variables, we need 1 known variable. A
40
• Consider the LP in Example 1. There are 4
extreme points (corner points): A, B, C,
and D. B
(20,20)
o At each points, variables that are not
equal to zero are basic variables (BV) and Constraint 1
those which are equal to zero are nonbasic
variables (NBV) D C
o For each points, the basic and nonbasic 30 40 𝑥1
variables are different.
Basic and Nonbasic Variables (2/2)
In the LP in Example 1, the basic non basic
variables for each points are: 𝑥2

60
Constraint 2
Point NBV BV Z
A
A 𝑥1 ; 𝑠1 𝑥2 ; 𝑠2 120 40
𝑧 = 4𝑥1 + 3𝑥2

B 𝑠1 ; 𝑠2 𝑥1 ; 𝑥2 240
B
(20,20)
C 𝑥2 ; 𝑠2 𝑥1 ; 𝑠1 120 Constraint 1

D 𝑥1 ; 𝑥2 𝑠1 ; 𝑠2 0 D C
30 40 𝑥1
Basic Feasible Solution
• A set of constraints can be written as 𝐀𝐱 = 𝐛, a system of 𝑚 linear
equations in 𝑛 variables, where
𝑎11 𝑎21 ⋯ 𝑎1𝑛 𝑥1 𝑏1
𝑎12 𝑎22 ⋯ 𝑎2𝑛 𝑥2 𝑏2
𝐀= ⋮ ⋮ ⋮ , 𝐱 = , 𝐛 =
⋮ ⋮
𝑎1𝑛 𝑎2𝑛 ⋯ 𝑎𝑚𝑛 𝑥𝑛 𝑏𝑚
• A basic solution to 𝐀𝐱 = 𝐛 is obtained by setting 𝑛 – 𝑚 variables equal
to 0 and solving for the remaining m variables.
o This assumes that setting the 𝑛 – 𝑚 variables equal to 0 yields a
unique value for the remaining 𝑚 variables.
• Any basic solution in which all variables are nonnegative is called a
basic feasible solution (or BFS).
Example 2
Dakota Furniture Company (1/17)
The Dakota Furniture company manufactures desk, tables, and
chairs. The manufacture of each type of furniture requires lumber
and two types of skilled labor: finishing and carpentry. The amount of
each resource needed to make each type of furniture is given in the
table below.
Resource Desk Table Chair

Lumber 8 board ft 6 board ft 1 board ft

Finishing hours 4 hours 2 hours 1.5 hours

Carpentry hours 2 hours 1.5 hours 0.5 hours


Example 2
Dakota Furniture Company (2/17)
At present, 48 board feet of lumber, 20 finishing hours, 8 carpentry
hours are available. A desk sells for $60, a table for $30, and a chair
for $ 20.

Dakota believes that demand for desks and chairs is unlimited, but at
most 5 tables can be sold.

Since the available resources have already been purchased, Dakota


wants to maximize total revenue.
Example 2
Dakota Furniture Company (3/17)
Define:
𝑥1 = number of desks produced
𝑥2 = number of tables produced
𝑥3 = number of chairs produced

The LP is:
max 𝑧 = 60𝑥1 + 30𝑥2 + 20𝑥3
s.t. 8𝑥1 + 6𝑥2 + 𝑥3 ≤ 48 (lumber constraint)

4𝑥1 + 2𝑥2 + 1.5𝑥3 ≤ 20 (finishing constraint)


2𝑥1 + 1.5𝑥2 + 0.5𝑥3 ≤ 8 (carpentry constraint)
𝑥2 ≤ 5 (table demand constraint)

𝑥1, 𝑥2, 𝑥3 ≥ 0
Example 2
Dakota Furniture Company (4/17)
• Begin the simplex algorithm by converting the constraints of the LP
to the standard form.
• Then convert the LP’s objective function into equation and put in
the row 0.
• To put the constraints in standard form, simply add slack variables
s1, s2, s3, s4, respectively to the four constraints.
• Label the constraints row 1, row 2, row 3, row 4, and add the sign
restrictions si ≥ 0
Example 2
Dakota Furniture Company (5/17)
• Putting rows 1-4 together in row 0 and the sign restrictions yields
these equations and basic variables.

Canonical Form 0 Basic


Variable

Row 0 z – 60x1 – 30x2 – 20x3 =0 z=0

Row 1 8x1 + 6x2 + x 3 + s1 = 48 s1 = 48

Row 2 4x1 + 2x2 + 1.5x3 + s2 = 20 s2 = 20

Row 3 2x1 + 1.5x2 + 0.5x3 + s3 =8 s3 = 8

Row 4 x2 + s4 =5 s4 = 5
Example 2
Dakota Furniture Company (6/17)
• To perform the simplex algorithm, we need a basic (although not
necessarily nonnegative) variable for row 0.
• Since z appears in row 0 with a coefficient of 1, and z does not
appear in any other row, we use z as the basic variable.
• With this convention, the basic feasible solution for our initial
canonical form has BV = {𝑧, 𝑠1, 𝑠2, 𝑠3, 𝑠4} and NBV = {𝑥1, 𝑥2, 𝑥3}.
• The initial BFS is then, 𝑧 = 0, 𝑠1 = 48, 𝑠2 = 20, 𝑠3 = 8, 𝑠4 = 5, 𝑥1 = 𝑥2 = 𝑥3 =
0.
• A slack variable can be used as a basic variable if the right hand
side of the constraint is nonnegative.
Example 2
Dakota Furniture Company (7/17)
• Once we have obtained a BFS, we need to determine whether it is
optimal. To do this, we try to determine if there is any way 𝑧 can be
increased by increasing some NBV from its current value of zero
while holding all other NBV at their current values of zero.
• For each NBV in the objective function 𝑍 = 60𝑥1 + 30𝑥2 + 20𝑥3, we
can determine if increasing a NBV will increase z.
• Increasing 𝑥1 causes the greatest rate of increase in 𝑧. If 𝑥1
increases from its current value of zero, it will have to become a
basic variable.
o For this reason, 𝑥1 is called the entering variable.
o Note that 𝑥1 has the most negative coefficient in row 0.
Example 2
Dakota Furniture Company (8/17)
• Next choose the entering variable by identifying the NBV with the
most negative coefficient in row 0.
• Increasing 𝑥1 will make z increase the largest per unit. But as it
increases, the current BV will change value. Thus, increasing 𝑥1 may
cause a current BV to become negative.
• 𝑥1 can only be increased as long as the BV are nonnegative i.e.
𝑠1 , 𝑠2 , 𝑠3 , 𝑠4 ≥ 0. By keeping the other NBV 𝑥2 , 𝑥3 = 0,
48 20 8
𝑥1 ≤ 8
= 6 for 𝑠1 ≥ 0, 𝑥1 ≤ 4
= 5 for 𝑠2 ≥ 0, and 𝑥1 ≤ = 4
2
• In other words, 𝑥1 ≤ 4 for 𝑠1 , 𝑠2 , 𝑠3 , 𝑠4 ≥ 0.
Example 2
Dakota Furniture Company (9/17)
The rule for determining how large an entering variable can be:
• When entering a variable into the basis, compute the ratio
𝑅𝐻𝑆 𝑖𝑛 𝑟𝑜𝑤 𝑗
𝐶𝑜𝑒𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡 𝑜𝑓 𝑒𝑛𝑡𝑒𝑟𝑖𝑛𝑔 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒 𝑖𝑛 𝑟𝑜𝑤 𝑗

for every constraint in which the entering variable has a positive


coefficient.
• The constraint with the smallest ratio is called the winner of the ratio
test.
• The smallest ratio is the largest value of the entering variable that
will keep all the current basic variables nonnegative.
Example 2
Dakota Furniture Company (10/17)
• Always make the entering variable a basic variable in a row that
wins the ratio test.
• To make 𝑥1 a basic variable in row 3, we use elementary row
operations (EROs) to make 𝑥1 have a coefficient of 1 in row 3 and a
coefficient of 0 in all other rows.
o This procedure is called pivoting on row 3; and row 3 is called the
pivot row.
o The final result is that 𝑥1 replaces s3 as the basic variable for row
3.
Example 2
Dakota Furniture Company (11/17)
Canonical Form 0 Basic ERO 1 Create a coefficient of 1 for 𝑥1 in row 3 by
Variable
multiplying row 3 by 1Τ2. The resulting row
(marked with a prime to show it is the first
Row 0 z – 60x1 – 30x2 – 20x3 =0 z=0
iteration) is
Row 1 8x1 + 6x2 + x 3 + s1 = 48 s1 = 48 Row 3’
Row 2 4x1 + 2x2 + 1.5x3 + s2 = 20 s2 = 20 ERO 2 To create a zero coefficient for x1 in row 0,
replace row 0 with 60(row 3’)+row 0
Row 3 2x1 + 1.5x2 + 0.5x3 + s3 =8 s3 = 8
Row 0’
Row 4 x2 + s4 =5 s4 = 5 ERO 3 To create a zero coefficient for x1 in row 1,
replace row 1 with -8(row 3’)+row 1
Row 1’
ERO 4 To create a zero coefficient for x1 in row 2,
replace row 2 with -4(row 3’)+row 2
Row 2’
Example 2
Dakota Furniture Company (12/17)
• The result is
Canonical Form 1 Basic
Variable
Row 0 z + 15x2 - 5x3 + 30s3 = 240 z = 240

Row 1 - x3 + s1 - 4s3 = 16 s1 = 16
Row 2 - x2 + 0.5 x3 + s2 - 2 s3 =4 s2 = 4
Row 3 x1 + 0.75x2 + 0.25x3 + 0.5s3 =4 x1 = 4
Row 4 x2 + s4 =5 s4 = 5

• The procedure used to go from one bfs to a better adjacent bfs is


called an iteration of the simplex algorithm.
Example 2
Dakota Furniture Company (13/17)
• Attempt to determine if the current bfs is optimal.
• Rearranging row 0 from Canonical Form 1, and solving for z yields
z = 240 – 15x2 +5x3 -30s3

• The current bfs is NOT optimal because increasing x3 to 1 (while


holding the other nonbasic variable to zero) will increase the value
of z.
• Making either x2 or s3 basic will cause the value of z to decrease.
Example 2
Dakota Furniture Company (14/17)
• Recall the rule for determining the entering variable is the row 0
coefficient with the greatest negative value.
• Since x3 is the only variable with a negative coefficient, x3 should be
entered into the basis.
• Performing the ratio test using x3 as the entering variable yields the
following results (holding other NBVs to zero):
o From row 1, s1 ≥ 0 for all values of x3 since s1 = 16 + x3
o From row 2, s2 ≥ 0 if x3 ≤ 4 / 0.5 = 8
o From row 3, x1 ≥ 0 if x3 ≤ 4 / 0.25 = 16
o From row 4, s4 ≥ 0 for all values of x3 since s4 = 5
Example 2
Dakota Furniture Company (15/17)
• This means to keep all the basic variables nonnegative, the largest
we can make x1 is min {8,16} = 8. So, row 2 becomes the pivot row.
• The result of using EROs, to make x2 a basic variable in row 2.
Canonical Form 2 Basic
Variable

Row 0 z + 5x2 + 10s2 + 10s3 = 280 z = 280

Row 1 - 2x2 + s1 + 2s2 - 8s3 = 24 s1 = 24

Row 2 - 2x2 + x3 + 2s2 - 4s3 =8 x3 = 8

Row 3 x1 + 1.25x2 - 0.5 s2 + 1.5s3 =2 x1 = 2

Row 4 x2 + s4 =5 s4 = 5
Example 2
Dakota Furniture Company (16/17)
• In Canonical Form 2
o BV = {z, s1, x3, x1, s4}
o NBV = {s3, s2, x2}
• Yielding the BFS 𝑧 = 280, 𝑠1 = 24, 𝑥3 = 8, 𝑥1 = 2, 𝑠4 = 5, and 𝑠2 = 𝑠3 =
𝑥2 = 0
• Solving for z in row 0 yields
𝑧 = 280 − 5𝑥2 − 10𝑠2 − 10𝑠3
• We can see that increasing 𝑥2, 𝑠2, or 𝑠3 (while holding the other NBVs
to zero) will not cause the value of z to increase.
Example 2
Dakota Furniture Company (17/17)
• The solution at the end of the 2nd iteration is therefore optimal.
• The following rule can be applied to determine whether a
canonical form’s BFS is optimal:
o A canonical form is optimal (for a max problem) if each NBV has
a nonnegative coefficient in the canonical form’s row 0.

You might also like