Week3 Solving Linear Programming Problems Using The Simplex Method
Week3 Solving Linear Programming Problems Using The Simplex Method
Programming Problems
The Simplex Method
Mohammed Brahimi
ENSIA/Intelligent Systems Enginnering
LP Standard Form
A Naive Algorithm
Protoype example
Simplex Algorithm
Conclusion
2/36
Key Takeaways from Last Lecture
• If an optimal solution exists for the LP, then at least one of the corner points is
optimal.
3/36
Key Takeaways from Last Lecture
• If an optimal solution exists for the LP, then at least one of the corner points is
optimal.
• The feasible region for any LP is a convex set.
3/36
LP Standard Form
Maximize z = c1 x1 + c2 x2 + · · · + cn xn
Subject to a11 x1 + a21 x2 + · · · + an1 xn = b1 ,
a12 x1 + a22 x2 + · · · + an2 xn = b2 ,
..
.
a1m x1 + a2m x2 + · · · + anm xn = bm ,
xi ≥ 0 (1 ≤ i ≤ n)
But ...
Why this LP Standard Form ?!
4/36
LP Standard Form
Maximize z = c1 x1 + c2 x2 + · · · + cn xn
Subject to a11 x1 + a21 x2 + · · · + an1 xn = b1 ,
a12 x1 + a22 x2 + · · · + an2 xn = b2 ,
..
.
a1m x1 + a2m x2 + · · · + anm xn = bm ,
xi ≥ 0 (1 ≤ i ≤ n)
Because ...
To solve a system of equations.
5/36
How to convert to the LP Standard Form
• Introduce non-negative slack and excess variable variables, Si ≥ 0, to transform
the inequality constraints into equality constraints.
∑n ∑n
– i=1
aij xi ≤ bj , add a slack variable Sj ≥ 0 such that ( i=1
aij xi ) + Sj = bj .
∑n ∑n
– i=1
aij xi ≥ bj , add a surplus variable Sj ≥ 0 such that ( i=1
aij xi ) − Sj = bj .
6/36
How to convert to the LP Standard Form
• Introduce non-negative slack and excess variable variables, Si ≥ 0, to transform
the inequality constraints into equality constraints.
∑n ∑n
– i=1
aij xi ≤ bj , add a slack variable Sj ≥ 0 such that ( i=1
aij xi ) + Sj = bj .
∑n ∑n
– i=1
aij xi ≥ bj , add a surplus variable Sj ≥ 0 such that ( i=1
aij xi ) − Sj = bj .
6/36
How to convert to the LP Standard Form
• Introduce non-negative slack and excess variable variables, Si ≥ 0, to transform
the inequality constraints into equality constraints.
∑n ∑n
– i=1
aij xi ≤ bj , add a slack variable Sj ≥ 0 such that ( i=1
aij xi ) + Sj = bj .
∑n ∑n
– i=1
aij xi ≥ bj , add a surplus variable Sj ≥ 0 such that ( i=1
aij xi ) − Sj = bj .
6/36
How to convert to the LP Standard Form
• Introduce non-negative slack and excess variable variables, Si ≥ 0, to transform
the inequality constraints into equality constraints.
∑n ∑n
– i=1
aij xi ≤ bj , add a slack variable Sj ≥ 0 such that ( i=1
aij xi ) + Sj = bj .
∑n ∑n
– i=1
aij xi ≥ bj , add a surplus variable Sj ≥ 0 such that ( i=1
aij xi ) − Sj = bj .
6/36
How to convert to the LP Standard Form
• Introduce non-negative slack and excess variable variables, Si ≥ 0, to transform
the inequality constraints into equality constraints.
∑n ∑n
– i=1
aij xi ≤ bj , add a slack variable Sj ≥ 0 such that ( i=1
aij xi ) + Sj = bj .
∑n ∑n
– i=1
aij xi ≥ bj , add a surplus variable Sj ≥ 0 such that ( i=1
aij xi ) − Sj = bj .
• All the original variables xi and the added variables Si are positive.
6/36
LP Standard Form
Maximize z = c1 x1 + c2 x2 + · · · + cn xn
Subject to a11 x1 + a21 x2 + · · · + an1 xn = b1 ,
a12 x1 + a22 x2 + · · · + an2 xn = b2 ,
..
.
a1m x1 + a2m x2 + · · · + anm xn = bm ,
xi ≥ 0 (1 ≤ i ≤ n)
But ...
More variables than equations (m ≪ n).
7/36
LP Standard Form
Maximize z = c1 x1 + c2 x2 + · · · + cn xn
Subject to a11 x1 + a21 x2 + · · · + an1 xn = b1 ,
a12 x1 + a22 x2 + · · · + an2 xn = b2 ,
..
.
a1m x1 + a2m x2 + · · · + anm xn = bm ,
xi ≥ 0 (1 ≤ i ≤ n)
But ...
Take m variables and solve the system.
7/36
Solving LP problem: A Naive Algorithm
• Generate all feasible corner points
– Determine all the intersection points between constraints.
– Test whether it is feasible.
• Use the objective function to determine which corner point is the optimal solution.
But ...
What is the number of intersection points for a LP problem with m
constraints and n variables?
8/36
Solving LP problem: A Naive Algorithm
• Generate all feasible corner points
– Determine all the intersection points between constraints.
– Test whether it is feasible.
• Use the objective function to determine which corner point is the optimal solution.
But ...
(n) n!
m
= m!(n−m)!
8/36
Solving LP problem: A Naive Algorithm
• Generate all feasible corner points
– Determine all the intersection points between constraints.
– Test whether it is feasible.
• Use the objective function to determine which corner point is the optimal solution.
But ...
(30)
10 = 30045015 !!!
8/36
Basic and Nonbasic Variables
• A Basic Solution is obtained by setting (n − m) variables to 0 and solving the
remaining system of m variables.
• The remaining variables are the Basic variables, and the removed ones are the
Non-basic variables.
• The non basic variables set to zero represent the fully satisfied constraints.
• A Basic Feasible Solution (BFS) is a basic solution that satisfies all of the
constraints.
Key Idea
A corner point in the feasible region of an LP is a Basic
Feasible Solution (BFS).
9/36
Basic Variables Nonbasic Variables
n
∑
x1 = b1 + a1ixi
i=m+1
...
∑
n
xm = bm + amixi
i=m+1
Basic Variables Nonbasic Variables
n
∑
x1 = b1 + a1ixi
i=m+1
... Assign to 0
∑
n
xm = bm + amixi
i=m+1
Basic Variables Nonbasic Variables
n
∑
x1 = b1 + a1ixi
i=m+1
Assign to b’s ... Assign to 0
∑
n
xm = bm + amixi
i=m+1
10/36
Example: Basic Feasible solutions (BFS’s)
Maximize x+y
subject to x + 2y ≤6
2x + y ≤ 6
11/36
Example: Basic Feasible Solutions (BFS’s)
Maximize z =x+y E
subject to x + 2y ≤ 6
2x + y ≤ 6
A D F
12/36
Example: Basic Feasible Solutions (BFS’s)
• Variables {x, y, S1 , S2 }
Maximize z =x+y
subject to x + 2y + S1 = 6
2x + y + S2 = 6
x, y, S1 , S2 ≥ 0
13/36
Example: Basic Feasible Solutions (BFS’s)
• Variables {x, y, S1 , S2 }
Maximize z =x+y
subject to x + 2y + S1 = 6
• Number of variables n =4
2x + y + S2 = 6 • Number of constraints m =2
x, y, S1 , S2 ≥ 0
13/36
Example: Basic Feasible Solutions (BFS’s)
• Variables {x, y, S1 , S2 }
Maximize z =x+y
subject to x + 2y + S1 = 6
• Number of variables n =4
2x + y + S2 = 6 • Number of constraints m =2
x, y, S1 , S2 ≥ 0 (n)
• Number of Basic solutions m
(4)
• 2
= 6 Basic Solutions
13/36
Example: Basic Feasible Solutions (BFS’s)
• Basic solutions
– A, B, C, D, E, F
B
• Feasible Basic Solutions
– A, B, C, D
C
A D F
14/36
Example: Basic Feasible Solutions (BFS’s)
• Basic solutions
– A, B, C, D, E, F
B
• Feasible Basic Solutions
– A, B, C, D
C
• How to find these FBS’s ?!
A D F
14/36
Example: BFS (S1, S2) - A -
Maximize z =x+y E
subject to S1 = 6 − x − 2y
S2 = 6 − 2x − y
x, y, S1 , S2 ≥ 0
B
A D F
15/36
Example: BFS (y, S2)- B -
1 1
Maximize z = 3 + x − S1 E
2 2
1 1
subject to y = 3 − x − S1
2 2
3 1
S2 = 3 − x + S1 B
2 2
x, y, S1 , S2 ≥ 0 C
A D F
16/36
Example: BFS (x, y)- C -
1 1
Maximize z = 4 − S1 − S2 E
3 3
1 2
subject to x = 2 + S1 − S2
3 3
2 1
y = 2 − S1 + S2 B
3 3
x, y, S1 , S2 ≥ 0 C
A D F
17/36
Example: BFS (x, S1)- D -
1 1
Maximize z = 3 + y − S2 E
2 2
1 1
subject to x = 3 − y − S2
2 2
3 1
S1 = 3 − y + S2 B
2 2
x, y, S1 , S2 ≥ 0 C
A D F
18/36
Example: Infeasible solution (y, S1)- E -
Maximize z = 6 − x − s2 E
subject to y = 6 − 2x − S2
S1 = −6 + 3x + 2S2
x, y, S1 , S2 ≥ 0
B
A D F
19/36
Example: Infeasible solution (x, S2)- F -
Maximize z = 6 − y − s1 E
subject to x = 6 − 2y − S1
S2 = −6 − 3y + 2S1
x, y, S1 , S2 ≥ 0
B
A D F
20/36
Example: Summary
21/36
State 1: Basic Feasible Solution
1 1
Maximize z = 3 + x − s1
2 2
1 1
subject to y = 3 − x − S1
2 2
3 1
S2 = 3 − x + S1
2 2
x, y, S1, S2 ≥ 0
22/36
State 1: Basic Feasible Solution
1 1
Maximize z = 3 + x − s1
2 2
1 1
subject to y = 3 − x − S1
2 2
3 1
S2 = 3 − x + S1
2 2
x, y, S1, S2 ≥ 0
22/36
State 2:Infeasible Solution
Maximize z = 6 − x − s2
subject to y = 6 − 2x − S2
S1 = −6 + 3x + 2S2
x, y, S1, S2 ≥ 0
23/36
State 2:Infeasible Solution
Maximize z = 6 − x − s2
subject to y = 6 − 2x − S2
S1 = -6 + 3x + 2S2
x, y, S1, S2 ≥ 0
23/36
State 3:Optimal Basic Feasible Solution
1 1
Maximize z = 4 − S1 − S2
3 3
1 2
subject to x = 2 + S1 − S2
3 3
2 1
y = 2 − S1 + S2
3 3
x, y, S1, S2 ≥ 0
24/36
State 3:Optimal Basic Feasible Solution
1 1
Maximize z = 4 − S1 − S2
3 3
1 2
subject to x = 2 + S1 − S2
3 3
2 1
y = 2 − S1 + S2
3 3
x, y, S1, S2 ≥ 0
24/36
Simplex Algorithm
• Convert to the standard form
∑
n
subject to x1 = b1 + a1i xi
• Output the optimal solution.
i=m+1
..
.
∑
n
xm = bm + ami xi
i=m+1
25/36
Simplex Algorithm
• While (∃Ci > 0)
∑
n
∑
n
– Introduce this variable in the basis by
subject to x1 = b1 + a1i xi removing a basic variable: Leaving
i=m+1 variable
..
. – Perform Gaussian elimination
∑n
25/36
Simplex Algorithm
4: Choose a basic variable to leave the basis using the minimum ratio test.
5: Update the basis by replacing the leaving variable with the entering variable.
7: end while
26/36
The minimum ratio test
Maximize z =x+y
subject to S1 = 6 − x − 2y
S2 = 6 − 2x − y
x, y, S1 , S2 ≥0
27/36
The minimum ratio test
Maximize z =x+y
subject to S1 = 6 − x − 2y
S2 = 6 − 2x − y
x, y, S1 , S2 ≥0
• We only consider constraints with Negative coefficients (ai ≤ 0) for the entering
variable, so the ratio is necessarily positive.
27/36
The minimum ratio test
Maximize z =x+y
subject to S1 = 6 − x − 2y
S2 = 6 − 2x − y
x, y, S1 , S2 ≥0
Old BFS is
• Basic Variables = {S1 , S2 }
• Non Basic variables = {x, y}
New BFS is
• Basic Variables = {x, S1 }
• Non Basic variables = {y, s2 }
27/36
Example: BFS (S1, S2) - A -
Maximize z =x+y E
subject to S1 = 6 − x − 2y
S2 = 6 − 2x − y
x, y, S1 , S2 ≥ 0
B
A D F
28/36
Example: BFS (x, S1)- A → D -
1 1
Maximize z = 3 + y − S2 E
2 2
1 1
subject to x = 3 − y − S2
2 2
3 1
S1 = 3 − y + S2 B
2 2
x, y, S1 , S2 ≥ 0 C
A D F
29/36
Example: BFS (x, y)- A → D → C -
1 1
Maximize z = 4 − S1 − S2 E
3 3
1 2
subject to x = 2 + S1 − S2
3 3
2 1
y = 2 − S1 + S2 B
3 3
x, y, S1 , S2 ≥ 0 C
A D F
30/36
Simplex Tableau Method
• The simplex should be updated to consider the sign modifications (optimality test,
how to choose leaving/entering variables, minimum ratio test).
31/36
Simplex Tableau Method
Base z x y S1 S2 b Ratio
1 -1 -1 0 0 0
6
S1 0 1 2 1 0 6 1 =6
6
S2 0 2 1 0 1 6 3 =2
• Entering variable: x
• Leaving variable: S2
32/36
Simplex Tableau Method
Base z x y S1 S2 b Ratio
1 0 − 21 0 1
2 3
S1 0 0 3
2 1 − 12 3 3 × 2
3 =2
x 0 1 1
2 0 1
2 3 3× 2
1 =6
• Entering variable: y
• Leaving variable: S1
33/36
Simplex Tableau Method
Base z x y S1 S2 b Ratio
1 1
1 0 0 3 3 4
y 0 0 1 2
3 − 31 2
x 0 1 0 − 31 2
3 2
34/36
Simplex: Special cases
• Unboundedness: occurs when the objective function can be increased indefinitely
without violating any of the constraints.
• Infeasibility: occurs when there is no feasible solution that satisfies all of the
constraints.
• Degeneracy: occurs when one or more basic variables become zero during the
iteration process.
35/36
Conclusion
• Simplex method is an efficient algorithm for finding optimal solutions
to LP problems by navigating through the corner points of the
feasible region.
36/36