MathsAdvanced Equations

Simplex Method
calculator.

Solve a linear program with tableaux, pivots and, for two variables, a drawing.

How it's worked out

A linear program asks for the largest or smallest value of a straight-line objective, subject to straight-line limits. Every variable must be 0 or more.

z\displaystyle z=c1x1+c2x2+…\displaystyle {}= c_1x_1 + c_2x_2 + \dots

The corner point principle/03%3A_Linear_Programming_-_A_Geometric_Approach/3.01%3A_Maximization_Applications) says the best value, when one exists, sits at a corner of the region the limits allow. The simplex method starts at one corner and walks along edges to better corners until no neighbor is better.

  • Slack. Each ≤ row gets a slack variable for the unused amount, so the row becomes an equation.
  • Pivot column. The most negative entry in the bottom row/04%3A_Linear_Programming_The_Simplex_Method/4.02%3A_Maximization_By_The_Simplex_Method) picks the variable that raises z fastest.
  • Pivot row. Divide each right side by the positive entry in that column. The smallest quotient wins, which keeps every variable at 0 or more.
  • Stop. When the bottom row has no negative entry, z cannot rise any further.

A ≥ or = row has no slack to start from, because the origin breaks it. So it gets a surplus variable taken away and an artificial variable added. Phase 1 drives the artificial variables down to 0 to find a first corner. If it cannot, no point meets every limit. Phase 2 then runs the usual method on the real objective. A minimum is found by making −z as large as it can be.

Worked examples

The Wyndor glass plant picks a product mix

Each batch of product 1 earns 3 and each batch of product 2 earns 5, in thousands. Plant 1 has 4 hours, plant 2 has 12 and plant 3 has 18. Product 1 needs 1 hour in plant 1 and 3 in plant 3, and product 2 needs 2 hours in each of plants 2 and 3.

x1\displaystyle x_1≤4\displaystyle {}\le 4
2x2\displaystyle 2x_2≤12\displaystyle {}\le 12
3x1+2x2\displaystyle 3x_1 + 2x_2≤18\displaystyle {}\le 18

The method takes 2 pivots. Product 2 comes in first because 5 is the bigger profit, then product 1. The best plan is 2 batches and 6 batches, for z = 36.

The check puts the plan back in: plant 1 uses 2 of its 4 hours, so 2 are spare, while plants 2 and 3 are full. The 5 corners give z from 0 to 36, so the graph agrees. One more hour in plant 3 raises z to 37.

If product 1 earned 6 and product 2 only 2, the objective line would tilt and the best corner would move to (4, 3) with z = 30.

Open this example in the tool

Niki splits her week between two jobs

Job I pays $40 an hour and job II pays $30. Niki can work at most 12 hours, and she has 16 hours to prepare. Each hour of job I takes 2 hours of preparation, and each hour of job II takes 1.

x1+x2\displaystyle x_1 + x_2≤12\displaystyle {}\le 12
2x1+x2\displaystyle 2x_1 + x_2≤16\displaystyle {}\le 16

The best week is 4 hours of job I and 8 of job II, for $400. Both limits are used up, so both slack variables end at 0.

The what-if table shows which limit is worth more. One more working hour lifts her best pay to $420, which is $20 an hour. One more preparation hour lifts it to $410, only $10.

Open this example in the tool

A cheapest diet that needs phase 1

Food 1 costs 2 a serving and food 2 costs 3. The diet needs at least 4 units of one nutrient and at least 6 of another.

x1+x2\displaystyle x_1 + x_2≥4\displaystyle {}\ge 4
x1+3x2\displaystyle x_1 + 3x_2≥6\displaystyle {}\ge 6

Eating nothing breaks both rows, so the slack start does not work. Phase 1 takes 3 tableaux to reach a real corner. The cheapest plan is 3 servings of food 1 and 1 of food 2, at a cost of 9.

The other corners, (6, 0) and (0, 4), both cost 12.

Open this example in the tool

Reading your result

Basis. The variables listed down the left of a tableau are the ones allowed to be above 0. Their values sit in the right-hand column, and every other variable is 0.

Binding and spare. A binding constraint is met exactly at the best point, so it holds the answer back. A constraint with some to spare is not limiting, and changing its right side a little changes nothing.

Rate per unit. When the right side of a binding constraint rises by 1 and the same constraints stay binding, z moves by a fixed amount, its shadow price. In the Wyndor plant one hour in plant 3 is worth 1.

A tie. If a variable outside the basis has 0 in the bottom row, another corner gives the same z, and so does every point on the edge between them.

No answer. Asking for x₁ + x₂ to be at most 2 and at least 5 is infeasible. Maximizing x₁ + x₂ with only x₁ − x₂ ≤ 1 is unbounded, because nothing caps x₂.

Common mistakes

  • Flipping a ≥ row to ≤ and starting anyway. Multiplying x₁ + x₂ ≥ 4 by −1 leaves a negative right side, and the slack start is then not a real corner. That is the case phase 1 exists for.
  • Choosing the pivot row by the biggest entry. The row comes from the smallest ratio of right side to a positive entry. A zero or negative entry is skipped.
  • Rounding to whole numbers at the end. The best point may need fractions. The nearest whole numbers can break a limit or miss the true best whole-number plan.
  • Mixing units in one row. Each constraint must count one thing, such as hours or kilograms, in every term and on the right side.

Questions people ask

The objective is a straight-line rule, so its level lines are parallel. Sliding one in the improving direction, the last point of the region it touches is a corner, or a whole edge if the line runs parallel to it. That is why the method only visits corners.

Sources