Part I · trunk A · linear programming · spine
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
Bases and dictionaries. Reduced costs certify optimality. A pivot moves along an edge.
Degenerate pivots and cycling (Beale). Anti-cycling (Bland). Exponential paths (Klee–Minty).
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.
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
An algebraic handle on a geometric walk.
02 · bases
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$.
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.
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
$\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.
| basis | set to 0 | solve for the basis | point $(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.
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
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$$If the BFS is feasible and every reduced cost $\bar c_j \le 0$, it is optimal.
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.
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
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.
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$.
If the minimizing $\bar b_i = 0$, then $t^* = 0$. The basis changes but the point does not move: a degenerate pivot.
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
$\max\ 2x+y$ over unit 01's polygon. Dantzig's rule: enter $x$ (coefficient 2), then $y$.
Two pivots, and the vertex $(0,4)$ was never visited. Simplex visits only an improving path, not the whole vertex set.
02 · bases
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₁ | 1 | 1 | 1 | 0 | 4 |
| s₂ | 2 | 1 | 0 | 1 | 6 |
| z | −3 | −2 | 0 | 0 | 0 |
| s₁ | 0 | ½ | 1 | −½ | 1 |
| x | 1 | ½ | 0 | ½ | 3 |
| z | 0 | −½ | 0 | 3⁄2 | 9 |
| y | 0 | 1 | 2 | −1 | 2 |
| x | 1 | 0 | −1 | 1 | 2 |
| z | 0 | 0 | 1 | 1 | 10 |
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
Twice: by never stopping, and by taking exponentially long to stop.
02 · failure
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.
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
$\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.
$\tfrac54$ at $x = (1, 0, 1, 0)$. Bland's rule reaches it in 6 pivots.
| pivot | enters | leaves | basis 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.
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
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.
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
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$ | Dantzig | Bland | HiGHS |
|---|---|---|---|
| 4 | 15 | 9 | 1 |
| 6 | 63 | 25 | 1 |
| 8 | 255 | 67 | 9 |
| 10 | 1 023 | 177 | 9 |
| 12 | 4 095 | 465 | 9 |
Reference run of uv run co then 02. HiGHS: primal simplex, presolve off.
02 · failure · example
$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.
| pivot | enters | vertex $(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
On real LPs the number of iterations is typically a small multiple of the number of constraints. Worst cases are artificial.
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
Two phases, the revised method, better pricing, and tolerances.
02 · practice
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.
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.
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
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$.
| pivot | enters | leaves | at $(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.
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 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:
02 · practice
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.
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.
Typically far fewer pivots, and much less sensitivity to how variables are scaled. (The one-sentence answer the checkpoint asks for.)
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
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|$ |
|---|---|---|---|
| 6 | 1.5e7 | 1.3e-10 | 4.4e-10 |
| 7 | 4.8e8 | 3.9e-9 | 1.2 |
| 8 | 1.5e10 | 1.3 | 1.2 |
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
uv run co test 02
uv run co then 02 # 1000 LPs vs HiGHS · Klee–Minty table · floats on the Hilbert system
02 · checkpoint
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).
03 Duality: the bottom row of your final tableau, read as a solution to a different LP. 04 (branch): the polynomial-time alternatives.