4 LP - Simplex Algorithm
4 LP - Simplex Algorithm
Programming
Simplex Algorithm
Simplex algorithm outline
Stop
Simplex algorithm
• Simplex algorithm works on LP in a
standard form
Find a basic • All constraints should be in the
feasible solution form of equalities
• Steps of simplex algorithms:
1. Convert all inequality
constraints into equality
Generate a new
Is current No constraints by adding slack
basic feasible
solution
solution to
variables
optimal? 2. Find a basic feasible solution
improve z
3. Evaluate whether current
Yes solution is optimal
4. If current solution is not
Stop optimal, generate a new basic
feasible solution
Use simplex table to perform step 2
to 4
Simplex algorithm – example 1
max z = 7x1+ 10x2
subject to
5x1+ 4x2 ≤ 24
2x1+ 5x2 ≤ 13 Two variables in simplex algorithm:
• Basic variables: variables that exist on one
x1 , x2 ≥ 0
equation only and has zero coefficient in
other equations
Convert the inequalities into equations form • In this example s1, s2
• Non-basic variables: variables that have
max z = 7x1+ 10x2
non-zero coefficients in more than one
subject to equation
5x1+ 4x2 + s1 = 24 • In this example x1, x2
2x1+ 5x2 + s2 = 13 • In each iteration there will be a set of basic
variables and a set of non-basic variables
x1, x2, s1, s2 ≥ 0 • A set of basic variables represents a basic
feasible solutions
s1, s2 are slack variables that represent unused resources
Simplex algorithm – example (cont’d)
S2 2 5 0 1 13 13/5=2.6
Pivot row
Z -7 -10 0 0 0
Pivot element
Note:
• For maximization problem, pivot column is chosen based on the most negative value in row Z. For
minimization, choose the largest positive value.
• Pivot row is chosen based the smallest positive ratio (apply both for maximization and minimization)
Simplex algorithm – example (cont’d)
From initial simplex table, Entering variable: x2, Leaving variable: s2.
Iteration 1:
Set 0 to cells in the pivot column except
pivot element
• Current solution:
Basic x1 x2 s1 s2 RHS Ratio s1=68/5
x2=13/5
S1 17/5 0 1 -4/5 68/5 (68/5)/(17/5)=4 Z=26
X2 2/5 1 0 1/5 13/5 (13/5)/(2/5)=6.5 • Current solution is
not optimal solution
Z -3 0 0 2 26
since there is still
negative value in row
Apply Gauss-Jourdan Z
All elements in the pivot row are divided elimination to other cells • For the next iteration,
by pivot element entering variable: x1,
leaving variable: s1
• New value = old value – (new value of element in
the pivot row in the respective column)(old value
of the pivot column in the respective row)
Gauss-Jordan
Elimination • Example: cell s1 – x1
new value = 5 – (2/5)(4)
= 17/5
Simplex algorithm – example (cont’d)
From simplex table iteration 1, Entering variable: x1, Leaving variable: s1.
Iteration 2:
Z 0 0 15/17 22/17 38
Since all the coefficients in Row Z are now all non-negative, the current solution is optimal
Note: for minimization, solution is optimal when all coefficient of Row Z are all non-positive
Simplex summary
• The optimum solution can always be associated with a
feasible extreme (corner) point in the solution space
x2 • In each iteration, all variables are portioned into basic
variables and non basic variables
6 • Basic variables represent the solution in each
iteration
• All non-basic variables are set to zero
Leaving variable
Iteration 1 13/5
(4,1)
Iteration 2
Entering variable
Simplex algorithm:
two-phase method
Simplex method for solving a general LP problem
Consider the following LP model:
n
max z = cjxj
j =1
Subject to :
n
a x
j =1
ij j + si = bi i = 1,2,..., m
x j 0, j = 1,..., n
subject to
5x1+ 4x2 ≥ 24 (1)
2x1+ 5x2 ≤ 13 (2)
x1 , x2 ≥ 0
When x1=0 and x2=0 (initial solution), constraint (1) is violated → initial solution
lies in infeasible region
→ Use two-phase method
Simplex method: example 2
Phase 1
• Step 1: Define an artificial variable ri for each of the ≥ or = type constraint and add them to the LP model
max z = -r1 (1) Note:
subject to For minimization, min 𝑧 = σ𝑖 𝑟𝑖
5x1+ 4x2 - s1 + r1 = 24 (2)
2x1+ 5x2 + s2 = 13 (3)
x1, x2, s1, s2, r1 ≥ 0
• Step 2:
• Set artificial variable as basic variable by eliminating r1 from the objective function (eq. 1) by
substituting eq. (2) so that r1 only has value in one of the constraints. Thus eq. (1) becomes
z - 5x1 - 4x2 + s1 = -24
Simplex method: example 2
Phase 1
Iteration 0
Basic x1 x2 s1 s2 r1 RHS Ratio
r1 5 4 -1 0 1 24 24/5=4.8
S2 2 5 0 1 0 13 13/2=6.5
Z -5 -4 1 0 0 -24
Iteration 1
Basic x1 x2 s1 s2 r1 RHS
x1 1 4/5 -1/5 0 1/5 24/5
S2 0 17/5 2/5 1 -2/5 3.4
Z 0 0 0 0 1 0
The solution to the Phase-I LP problem is now optimal. Hence we have obtained a basic feasible solution
to the original LP problem → r1 is a non-basic variable
Simplex method: example 2
Phase 2
• Step 1: Drop the artificial column and optimize the original objective function
Based on the last Simplex tableu Phase 1, the LP formulation is as follows.
max z = 7x1+ 10x2 (4)
subject to
x1+ (4/5)x2 – (1/5)s1 = 4.8 (5)
(17/5)x2 + (2/5)s1 + s2 = 3.4 (6)
x1, x2, s1, s2 ≥ 0
An initial basic feasible solution is:
x1 = 4.8, s2 = 3.4 → basic variable: x1 and s2
Since x1 and s2 are basic variables, x1 should be eliminated from the objective function
• Step 2: Eliminate x1 from objective function (eq. 4) by substituting eq. (5). Thus, eq. (4) becomes
z – (22/5)x2 – (7/5)s1 = 33.6
Simplex method: example 2
Phase 2
Iteration 2
Since all the coefficients in Row Z are now all nonnegative, the current solution to the Phase 2 LP problem is optimal.
Special cases of LP solution
1. If there is a tie
1. For entering non-basic variables: Choose any one of them.
2. For leaving basic variables: Choose any one of them.
2. What if when you solve for basic variables, one of them has a value of zero?
It does not matter, it is only theoretical important. The name given to this kind of solution is
degenerate.
3. How can you tell if the LP problem has no solution (that is, the model is inconsistent)?
This can be detected if some artificial variables have positive values when the LP solution is optimal.
4. How can you tell if the LP solution is unbounded?
This can be detected if an entering variable can be increased without limit. That is, the pivot column
has no positive coefficients.
5. How can you tell if there is more than one optimal solution?
This can be detected if there exists a non-basic variable which has a coefficient of zero in the final
objective function row. Note that if P1and P2 are two optimal corner points then λP1+(1- λ )P2 are
equally good solution, for any 0 ≤ λ ≤ 1.
Thank you