Part I · trunk A · linear programming · spine

02

Simplex, honestly

Walking from vertex to better vertex: why it works, when it loops forever, when it takes exponentially long, and why it is still the workhorse.

needs 01~2 h slides + 3 h lablab: uv run co lab 02

02 · overview

The route

1 · the method

Bases and dictionaries. Reduced costs certify optimality. A pivot moves along an edge.

2 · how it fails

Degenerate pivots and cycling (Beale). Anti-cycling (Bland). Exponential paths (Klee–Minty).

3 · why it wins anyway

Two phases. Revised simplex with LU. Steepest-edge pricing. Tolerances, and what they hide.

Lab: pivot, pricing rules, the loop with cycle detection, two phases, and Klee–Minty. Then 1000 LPs against HiGHS.

getting around

Words with a dotted underline are glossary terms: click one for its definition. G lists every term in the unit, N shows the notes. Unit 01's polygon, maximizing $2x + y$, is the running example: a solid underline like that one shows it on hover. Optional extra: interactive figures, linked from the slides they support by a small ▸ chip; skip them freely.

section 1

From vertices to bases

An algebraic handle on a geometric walk.

02 · bases

Bases and basic solutions

Add slacks: $\;Ax + s = b,\; x, s \ge 0$. Write all $n+m$ variables as one vector with matrix $[A \mid I]$, which has rank $m$.

definition

A basis $B$ is a set of $m$ columns of $[A\mid I]$ that are linearly independent. Setting the other ($N$, nonbasic) variables to 0 gives the basic solution $x_B = A_B^{-1} b$.

It is feasible when $x_B \ge 0$.

Basic feasible solutions are exactly the vertices of unit 01. Different bases can give the same vertex: a degenerate vertex.

the starting basis

If $b \ge 0$, the slacks form a feasible basis: $x = 0,\ s = b$. The origin is a vertex.

If some $b_i < 0$ it is not feasible. That is what phase 1 (section 3) is for.

Picture it: "nonbasic" means "held at 0", and a slack at 0 means its constraint is tight. So choosing a basis is choosing which walls to stand on. The next slide does all six choices for the polygon.

02 · bases · example

Bases on the example

$\max 2x + y$ with $x + y + s_1 = 4$, $\ x - y + s_2 = 1$, all four variables $\ge 0$. Here $m = 2$, so a basis is 2 of the 4 columns: $\binom42 = 6$ choices, all independent.

basisset to 0solve for the basispoint $(x,y)$
$s_1, s_2$$x, y$$s_1 = 4,\ s_2 = 1$$(0, 0)$✓
$x, s_1$$y, s_2$$x = 1,\ s_1 = 3$$(1, 0)$✓
$x, s_2$$y, s_1$$x = 4,\ s_2 = -3$$(4, 0)$✗
$y, s_1$$x, s_2$$y = -1,\ s_1 = 5$$(0, -1)$✗
$y, s_2$$x, s_1$$y = 4,\ s_2 = 5$$(0, 4)$✓
$x, y$$s_1, s_2$$x = 2.5,\ y = 1.5$$(2.5, 1.5)$✓

Four feasible bases, four corners: the same table as unit 01's "Finding corners by trying pairs of constraints", now in the language of variables. A negative basic value is a violated constraint.

x=y=0 y=s₂=0 s₁=s₂=0 x=s₁=0 P

Each corner labelled by its nonbasic variables, the two walls it stands on. $s_1 = 0$ is the line $x + y = 4$; $s_2 = 0$ is $x - y = 1$.

02 · bases

Reduced costs: the optimality certificate

Solve the constraints for the basic variables and substitute into the objective:

$$x_B = A_B^{-1} b - A_B^{-1} A_N\, x_N, \qquad c^\top x = \underbrace{c_B^\top A_B^{-1} b}_{\text{current value}} + \underbrace{(c_N^\top - c_B^\top A_B^{-1} A_N)}_{\bar c_N^\top}\, x_N$$
optimality criterion

If the BFS is feasible and every reduced cost $\bar c_j \le 0$, it is optimal.

why

Any other feasible point has some nonbasic variables above 0, and each one changes the value by $\bar c_j \le 0$ per unit. Nothing can raise it.

If some $\bar c_j > 0$, raising $x_j$ from 0 improves the objective at rate $\bar c_j$. That $j$ may be the entering variable.

the dictionary, on the example

At the origin (basis $s_1, s_2$):

$s_1 = 4 - x - y,\quad s_2 = 1 - x + y$
$z = 0 + \mathbf{2}\,x + \mathbf{1}\,y$

Reduced costs $2$ and $1$ are positive: not optimal, and either may enter.

At $(2.5, 1.5)$ (basis $x, y$):

$z = 6.5 - \tfrac32\, s_1 - \tfrac12\, s_2$

Both negative: raising either slack, $s_1$ or $s_2$ (leaving a wall), only lowers $z$. Optimal, certified by two signs.

02 · bases

The ratio test: how far to move

Increase entering $x_j$ to $t \ge 0$ with the other nonbasic variables held at 0. The basic variables change linearly:

$$x_B(t) = \bar b - t\, d, \qquad \bar b = A_B^{-1}b,\ \ d = A_B^{-1} a_j$$

The ratio test. Feasibility needs $\bar b_i - t d_i \ge 0$ for every row, which binds only where $d_i > 0$:

$$t^* = \min_{i:\,d_i > 0} \frac{\bar b_i}{d_i}$$

The row attaining the minimum names the leaving variable: it hits 0 first.

nothing blocks the move

If no $d_i > 0$, then $x_j$ can grow forever, and the LP is unbounded. The ray $x_B = \bar b - t d$, $x_j = t$ is a certificate: feasible for all $t$, with objective growing at rate $\bar c_j > 0$.

degenerate step

If the minimizing $\bar b_i = 0$, then $t^* = 0$. The basis changes but the point does not move: a degenerate pivot.

on the example, at the origin

Enter $x$: $d = (1, 1)$, $\bar b = (4, 1)$. Ratios $4/1$ and $1/1$: $t^* = 1$, $s_2$ leaves. Move to $(1, 0)$.

Enter $y$ instead: $d = (1, -1)$. Only the $s_1$ row counts: $t^* = 4$, move to $(0, 4)$. The $s_2$ row has $d_2 < 0$: $s_2 = 1 + y$ only grows.

02 · bases

A walk on the example polygon

z=0 z=2 z=6.5 z=4

$\max\ 2x+y$ over unit 01's polygon. Dantzig's rule: enter $x$ (coefficient 2), then $y$.

  1. Origin. Slack basis. $\bar c = (2, 1)$. Enter $x$. Ratio test: $x-y\le 1$ binds first, at $x=1$.
  2. $(1, 0)$. Now $x = 1 + y - s_2$ and $z = 2 + 3y - 2s_2$. Enter $y$. $x + y \le 4$ binds at $y = 1.5$.
  3. $(2.5, 1.5)$. Both reduced costs $\le 0$: optimal, $z = 6.5$.

Two pivots, and the vertex $(0,4)$ was never visited. Simplex visits only an improving path, not the whole vertex set.

02 · bases

The tableau: pivots as row operations

A second LP, the lab's SMALL: $\max 3x + 2y$, $\ x + y \le 4$, $\ 2x + y \le 6$. Columns $x, y, s_1, s_2 \mid$ rhs. Bottom row: $-\bar c$ and $z$. Boxed: the pivot element.

s₁11104
s₂21016
z−3−2000
s₁0½1−½1
x1½0½3
z0−½03⁄29
y012−12
x10−112
z001110

Pivot 1. Most negative $-\bar c$ is column $x$. Ratios $4/1,\ 6/2$: row 2 leaves.
Pivot 2. Column $y$. Ratios $1/\tfrac12 = 2,\ 3/\tfrac12 = 6$: row 1 leaves.

End. No negative entries in the bottom row: $x = y = 2$, $z = 10$.
The slack columns of the bottom row, $(1, 1)$, are the dual values. Remember them for unit 03.

section 2

How the naive method fails

Twice: by never stopping, and by taking exponentially long to stop.

02 · failure

Degeneracy and cycling

A degenerate pivot has $t^* = 0$: the basis changes and the point stays. The objective does not increase, so the usual termination argument (strict improvement, finitely many bases) fails.

Degenerate pivots in a row can bring the basis back to where it started. That is cycling, and the method then never stops. The smallest classic case is Beale's example, two slides on.

where degeneracy comes from, on the example

Add unit 01's constraint 5, $3x - y \le 6$, with slack $s_5$. It passes through $(2.5, 1.5)$.

Simplex reaches $(1, 0)$ as before and enters $y$. The ratio test now ties: $s_1$ row $\tfrac32$, $s_5$ row $\tfrac32$.

$s_1$ leaves. $s_5$ stays basic, at value 0. The corner $(2.5, 1.5)$ now has three bases, and a pivot among them would have $t^* = 0$.

Here the reduced costs are already $\le 0$, so it stops. Beale's example is built so that it doesn't.

02 · failure · example

Beale's cycle, pivot by pivot

Beale, 1955

$\max\ \tfrac34 x_1 - 20x_2 + \tfrac12 x_3 - 6x_4$
$\tfrac14 x_1 - 8x_2 - x_3 + 9x_4 \le 0$
$\tfrac12 x_1 - 12x_2 - \tfrac12 x_3 + 3x_4 \le 0$
$x_3 \le 1$

Two right-hand sides are 0, so the origin is a degenerate vertex: two slacks sit in the basis at value 0.

optimum

$\tfrac54$ at $x = (1, 0, 1, 0)$. Bland's rule reaches it in 6 pivots.

pivotentersleavesbasis after$z$
1$x_1$$s_1$$x_1, s_2, s_3$0
2$x_2$$s_2$$x_1, x_2, s_3$0
3$x_3$$x_1$$x_3, x_2, s_3$0
4$x_4$$x_2$$x_3, x_4, s_3$0
5$s_1$$x_3$$s_1, x_4, s_3$0
6$s_2$$x_4$$s_1, s_2, s_3$0

Dantzig's rule, ties to the lowest row. Six pivots, $z$ never moves, and pivot 6 returns to the starting basis. Then it repeats forever.

where Bland escapes: pivot 5

Improving columns: $x_1$ with $\bar c = \tfrac12$ and $s_1$ with $\bar c = 1$. Dantzig takes the larger, $s_1$. Bland takes the lower index, $x_1$. Then $s_3$ leaves at $t^* = \tfrac25$: the first real move, $z = \tfrac15$. One more pivot gives $\tfrac54$.

02 · failure

Bland's rule

theorem (Bland, 1977)

If the entering variable is always the lowest-index improving one, and ties in the ratio test go to the lowest-index basic variable, the simplex method never cycles.

why, in words

In a cycle some variables leave and later come back. Watch the one with the largest index among them. When it left, and when it came back, the rule chose by lowest index both times. Those two choices say opposite things about the same reduced costs, so a cycle can't close.

full proof in the notes (N)

On Beale's example it breaks the loop at pivot 5, by preferring $x_1$ over $s_1$.

Other cures (anti-cycling rules): the lexicographic ratio test (Dantzig, Orden, Wolfe 1955); perturbation of $b$, symbolic or numerical.

The price: Bland's rule ignores how much a column improves, so it is usually slow. Production codes use good pricing plus perturbation, and fall back to anti-cycling measures only when they detect stalling.

02 · failure

Klee–Minty: exponentially many pivots

The Klee–Minty cube: a squashed $n$-cube (Klee & Minty, 1972). In Chvátal's form:

$$\max \sum_{j=1}^{n} 10^{n-j} x_j \quad\text{s.t.}\quad 2\sum_{jFrom the origin, Dantzig's rule visits all $2^n$ vertices: exactly $2^n - 1$ pivots.

The cube is deformed so that each coordinate's "high" and "low" faces are nearly parallel, and the largest-coefficient choice always starts the long way round.

$n$DantzigBlandHiGHS
41591
663251
8255679
101 0231779
124 0954659

Reference run of uv run co then 02. HiGHS: primal simplex, presolve off.

02 · failure · example

Klee–Minty for n = 2 and 3, vertex by vertex

(0,0) z=0 (1,0) z=10 (1,80) z=90 (0,100) z=100

$n = 2$: $\max 10x_1 + x_2$, $\ x_1 \le 1$, $\ 20x_1 + x_2 \le 100$. Dantzig visits all 4 corners: 3 pivots. Not to scale horizontally.

pivotentersvertex $(x_1, x_2, x_3)$$z$
0$(0, 0, 0)$0
1$x_1$$(1, 0, 0)$100
2$x_2$$(1, 80, 0)$900
3$s_1$$(0, 100, 0)$1 000
4$x_3$$(0, 100, 8000)$9 000
5$x_1$$(1, 80, 8200)$9 100
6$s_2$$(1, 0, 9800)$9 900
7$s_1$$(0, 0, 10000)$10 000

$n = 3$, Dantzig: all $2^3 = 8$ vertices, $z$ rising every time. Rows 0–3 are the $n = 2$ walk on the floor $x_3 = 0$; rows 4–7 walk it backwards on the top.

Bland: $(0,0,0) \to (1,0,0) \to (1,80,0) \to (1,80,8200) \to (1,0,9800) \to (0,0,10000)$, 5 pivots. It climbs to the top one step earlier.

02 · failure

So why is simplex the workhorse?

in practice

On real LPs the number of iterations is typically a small multiple of the number of constraints. Worst cases are artificial.

in theory, eventually

Average case (Borgwardt 1982): polynomial expected pivots for the shadow-vertex rule on a random model.

Smoothed analysis (Spielman & Teng 2004): add small Gaussian noise to any LP, and shadow-vertex simplex takes polynomial expected time.

And a structural reason, which is the one that matters for this course: simplex warm-starts. Change the LP slightly and the old basis is nearly optimal. Branch-and-bound (unit 07) and cutting planes (unit 08) re-solve thousands of slightly changed LPs.

section 3

Starting, and what real codes do

Two phases, the revised method, better pricing, and tolerances.

02 · practice

Getting started: two phases

If some $b_i < 0$, the slack basis is infeasible. Phase 1: for each such constraint, negate it and add an artificial $a_i \ge 0$ with coefficient $+1$, then solve

$$\max\ -\textstyle\sum_i a_i$$

starting from the basis of slacks and artificials, which is feasible by construction.

  • Optimum $< 0$: the original LP is infeasible. The phase-1 duals give a Farkas certificate, as in unit 01.
  • Optimum $= 0$: pivot remaining artificials out of the basis, drop them, restore the true objective. Phase 2 continues from that feasible basis.
big-M, and why not

Alternative: one phase with objective $c^\top x - M\sum a_i$ for a huge $M$. It is simple to state and numerically poor, because $M$ mixes magnitudes in the reduced costs. The same disease comes back in unit 05 as big-M constraints.

redundant rows

An artificial stuck in the basis at 0 whose row has no nonzero real entry means that row is a combination of the others. Delete it. The lab's step 4 test includes one.

02 · practice · example

Phase 1, on the example

Add $x + y \ge 1$ to the polygon. The origin breaks it, so the slack basis is infeasible. As a $\le$ constraint: $-x - y \le -1$, a negative $b$.

Set up. Negate and add an artificial: $x + y - s_3 + a_1 = 1$. Start from $s_1 = 4,\ s_2 = 1,\ a_1 = 1$ and maximize $-a_1$, now $-1$.

pivotentersleavesat $(x,y)$what happened
1$x$$s_2$$(1, 0)$ratios $4, 1, 1$: tie, lowest row. $a_1 = 0$ now
2$y$$a_1$$(1, 0)$degenerate: $a_1$ was already 0
phase 1 ends at value 0: feasible. Drop $a_1$, restore $2x + y$, price out: $z = 2 + \tfrac32 s_3 + \dots$
3$s_3$$s_1$$(2.5, 1.5)$phase 2, optimal at $z = 6.5$

Three pivots in all. Phase 1 found a corner, $(1, 0)$, not the optimum; phase 2 walked from there. Had the constraint been $x + y \ge 5$, phase 1 would end below 0: infeasible.

(0,0) ✗ (1,0) (2.5,1.5) x + y = 1 P

Shaded corner: cut off by $x + y \ge 1$. Ring: the infeasible start. Phase 1 moves to $(1,0)$, phase 2 on to the optimum.

02 · practice

The revised simplex method

The revised simplex method starts from a complaint. The tableau stores $A_B^{-1}[A \mid I]$, which is dense, $m \times (n+m)$, and is updated in full at every pivot. A pivot actually needs only:

  1. $y^\top = c_B^\top A_B^{-1}$: one solve with $A_B^\top$ (BTRAN);
  2. reduced costs $\bar c_j = c_j - y^\top a_j$ for the candidates (pricing);
  3. $d = A_B^{-1} a_j$ for the chosen column: one solve (FTRAN);
  4. the ratio test, then an update of the factorization of $A_B$.
in a real solver
  • $A_B$ is kept as sparse LU factors (Markowitz ordering), not an inverse.
  • Each pivot updates the factors (Forrest–Tomlin), and periodically they are refactorized from scratch to control fill-in and error growth.
  • Real LPs are very sparse, so solves cost far less than $m^2$.

02 · practice

Pricing: which column enters

Dantzig: the largest $\bar c_j$. It measures improvement per unit of $x_j$, so it depends on the units $x_j$ is measured in.

Steepest edge (Goldfarb & Reid 1977): the largest improvement per unit of distance along the edge,

$$\max_j \frac{\bar c_j}{\|\eta_j\|}, \qquad \eta_j = \begin{pmatrix} -A_B^{-1} a_j \\ e_j \end{pmatrix}$$

where $\eta_j$ is the edge direction in the space of all variables.

on the example: change the units of one variable

Write $y = 10y'$. Column of $y'$: $(10, -10)$, cost $10$. At the origin:

Dantzig: $x$ scores $2$, $y'$ scores $10$ → picks $y'$.
Steepest edge: $x$ scores $2/\sqrt3 = 1.15$, $y'$ scores $10/\sqrt{201} = 0.71$ → still picks $x$, as it did before rescaling.

what it buys

Typically far fewer pivots, and much less sensitivity to how variables are scaled. (The one-sentence answer the checkpoint asks for.)

what it costs

The norms $\|\eta_j\|$ must be kept current, which takes an extra solve per pivot with clever update formulas. Devex (Harris 1973) approximates them cheaply.

02 · practice

Tolerances, and what they hide

Floating-point simplex needs tolerances: a reduced cost counts as negative only below $-10^{-7}$, a pivot element as usable only above some threshold, a constraint as satisfied within $10^{-7}$ or so.

The lab's then solves $Hx = H\mathbf{1}$ with $H$ the Hilbert matrix. The only solution is $x = \mathbf 1$, objective $n$:

$n$cond $H$floats: $\max|x-1|$HiGHS: $\max|x-1|$
61.5e71.3e-104.4e-10
74.8e83.9e-91.2
81.5e101.31.2
the lesson

At $n = 8$ both report objective $\approx 8.000$, so the value looks right. The point is wrong by more than 1 in some coordinate.

A wrong $x$ at the right value satisfies every constraint to within tolerance. From the solver's side nothing failed.

02 · lab

Lab 02 — what you build

about 3 hours · uv run co lab 02 · exact Fractions
  1. Tableau and pivot, the Gauss–Jordan step.
  2. Pricing and ratio test under Dantzig's and Bland's rules, ties included.
  3. The loop with cycle detection. Agrees with HiGHS, cycles on Beale, and Bland fixes it.
  4. Two phases for any $b$, with redundant rows and infeasibility.
  5. Klee–Minty, and exactly $2^n - 1$ pivots under Dantzig's rule.
uv run co test 02
uv run co then 02     # 1000 LPs vs HiGHS · Klee–Minty table · floats on the Hilbert system

02 · checkpoint

Done when

checkpoint
  • All five lab steps are ✓.
  • Your simplex agrees with HiGHS on 1000 random LPs, and you can exhibit an instance where it cycles without Bland's rule.
  • You can say in one sentence what steepest-edge pricing buys over Dantzig's rule.

Reading

Bertsimas & Tsitsiklis, ch. 3 (§3.1–3.7).
Chvátal, Linear Programming, ch. 3–4 and 8.
Koberstein (2005), thesis, ch. 1–3, for real implementations (optional).

Next

03 Duality: the bottom row of your final tableau, read as a solution to a different LP. 04 (branch): the polynomial-time alternatives.