Real problems have many variables, too many to draw. The simplex method, devised by George Dantzig in 1947, moves from corner to corner by algebra until it reaches the optimum.

Standard Form

To apply the simplex method, each ≤ constraint is turned into an equation by adding a slack variable s ≥ 0, which measures the unused resource. For 2x1 + 3x2 ≤ 120 we write 2x1 + 3x2 + s1 = 120. A ≥ constraint gets a surplus variable subtracted and an artificial variable added, and is handled by the Big-M or two-phase method. A solution in which the non-basic variables are 0 and the basic variables are found from the equations is a basic feasible solution, and each one is a corner point.

Definition: Simplex method. An algebraic procedure that solves a linear programming problem by moving from one basic feasible solution to a better adjacent one until no further improvement is possible.

Steps of the Simplex Method (Maximisation)

  1. Write the problem in standard form and set up the initial simplex table, with the slack variables as the basic variables and the row Cj − Zj (or the Z row with coefficients −c). 2. Optimality test: if all Cj − Zj ≤ 0, the solution is optimal. 3. Otherwise choose the entering variable, the column with the largest positive Cj − Zj, called the key column. 4. Choose the leaving variable by the minimum ratio test: divide each right-hand side by the positive entry in the key column, and take the smallest ratio. This row is the key row, and the element where they cross is the pivot. 5. Divide the key row by the pivot, and make every other entry of the key column zero by row operations. 6. Return to step 2.

Reading the Results

In the final table, the values of the basic variables give the solution, and Z gives the optimum. If the key column has no positive entry, the problem is unbounded. If a non-basic variable has Cj − Zj = 0 in the final table, there are multiple optima. If an artificial variable stays positive in the final table, the problem is infeasible.

Table 4.3: Simplex terms

Term Meaning Rule
Slack variable Unused resource Added to ≤ constraints
Entering variable Joins the basis Largest positive Cj − Zj
Leaving variable Leaves the basis Minimum ratio
Optimality No further gain All Cj − Zj ≤ 0

Example 4.3: Simplex solution

Problem: Solve by simplex: maximise Z = 50x1 + 60x2 subject to 2x1 + 3x2 + s1 = 120, 4x1 + 2x2 + s2 = 160.

Solution:

  1. Start: basis s1 = 120, s2 = 160, Z = 0. Cj − Zj: x1 50, x2 60. x2 enters.
  2. Ratios: 120/3 = 40, 160/2 = 80. s1 leaves. Pivot 3.
  3. New table: x2 = 40 − (2/3)x1 − (1/3)s1, s2 = 80 − (8/3)x1 + (2/3)s1, Z = 2400 + 10x1 − 20s1. x1 enters.
  4. Ratios: 40/(2/3) = 60, 80/(8/3) = 30. s2 leaves.
  5. New table: x1 = 30, x2 = 20, Z = 2700, with all Cj − Zj ≤ 0.

Result: x1 = 30, x2 = 20, maximum Z = 2700, the same as the graphical answer.

from itertools import combinations
A = [[2, 3, 1, 0], [4, 2, 0, 1]]
b, c = [120, 160], [50, 60, 0, 0]
best = None
for i, j in combinations(range(4), 2):
    a, bb, cc, d = A[0][i], A[0][j], A[1][i], A[1][j]
    det = a * d - bb * cc
    if det == 0:
        continue
    xi = (b[0] * d - bb * b[1]) / det
    xj = (a * b[1] - cc * b[0]) / det
    if xi >= 0 and xj >= 0:
        z = c[i] * xi + c[j] * xj
        if best is None or z > best[0]:
            best = (z, i, xi, j, xj)
print(best)

Output

(2700.0, 0, 30.0, 1, 20.0)

Common mistakes

  • Choosing the leaving variable by the largest ratio instead of the smallest.
  • Including negative or zero entries in the ratio test.
  • Forgetting to update the Z row after each pivot.

Key takeaways

  • Slack variables turn ≤ constraints into equations.
  • The entering variable has the largest positive Cj − Zj.
  • The leaving variable is found by the minimum ratio test.
  • Stop when all Cj − Zj ≤ 0.

Practice questions

  1. What is a slack variable?
  2. How is the leaving variable chosen?
  3. When is a simplex table optimal (maximisation)?

Answers to the practice questions

  1. A variable added to a ≤ constraint to make it an equation, representing unused resource.
  2. By the minimum ratio of the right-hand side to the positive entries of the key column.
  3. When all Cj − Zj values are zero or negative.

Sources

  • Official BCA syllabus Mathematics Foundations to Computer Science II, course code 25BCA402DS01, Unit IV