Klee-Minty Cubes and Smoothed Analysis
The simplex method is one of the most successful algorithms ever written, and for decades it was also an embarrassment for theory: on real problems it needs a number of pivots roughly linear in the number of constraints, yet for every classical pivoting rule there are inputs that force exponentially many pivots. Worst-case analysis says "exponential", practice says "fast". This lesson builds the classic bad input, measures it, and then states the theorem that resolved the paradox: smoothed analysis (Spielman and Teng, 2001), which shows that bad inputs are isolated points that disappear under a small random perturbation.
The Klee-Minty cube
Klee and Minty (1972) deformed the -dimensional cube so that the path of Dantzig's rule (enter the variable with the largest reduced cost) visits all vertices. A common way to write it (the version in Chvátal's textbook) is
The feasible region is a squashed cube: constraint caps between roughly and , with the cap tilted by the earlier coordinates. The optimum is with value , one pivot away from the origin, but Dantzig's rule takes the longest possible route. The program counts pivots in exact arithmetic for both rules from the previous lessons.
from fractions import Fraction as F
def simplex(c, A, b, rule):
m, n = len(A), len(c)
T = [[F(v) for v in A[i]] + [F(int(i == k)) for k in range(m)] + [F(b[i])] for i in range(m)]
z = [F(v) for v in c] + [F(0)] * (m + 1)
basis = [n + i for i in range(m)]
pivots = 0
while True:
improving = [j for j in range(n + m) if z[j] > 0]
if not improving:
return pivots, -z[-1]
e = min(improving) if rule == "bland" else max(improving, key=lambda j: (z[j], -j))
l = min((i for i in range(m) if T[i][e] > 0), key=lambda i: (T[i][-1] / T[i][e], basis[i]))
T[l] = [v / T[l][e] for v in T[l]]
for i in range(m):
if i != l and T[i][e] != 0:
f = T[i][e]
T[i] = [a - f * p for a, p in zip(T[i], T[l])]
f = z[e]
z = [a - f * p for a, p in zip(z, T[l])]
basis[l] = e
pivots += 1
def klee_minty(n):
c = [10 ** (n - j) for j in range(1, n + 1)]
A = [[2 * 10 ** (i - j) if j < i else int(j == i) for j in range(1, n + 1)] for i in range(1, n + 1)]
b = [100 ** (i - 1) for i in range(1, n + 1)]
return c, A, b
print(" n Dantzig pivots 2^n - 1 Bland pivots optimum")
for n in range(1, 9):
c, A, b = klee_minty(n)
d, value = simplex(c, A, b, "dantzig")
bl, _ = simplex(c, A, b, "bland")
print(f"{n:2} {d:14} {2 ** n - 1:7} {bl:12} {value}") n Dantzig pivots 2^n - 1 Bland pivots optimum
1 1 1 1 1
2 3 3 3 100
3 7 7 5 10000
4 15 15 9 1000000
5 31 31 15 100000000
6 63 63 25 10000000000
7 127 127 41 1000000000000
8 255 255 67 100000000000000
Dantzig's rule makes exactly pivots: it visits every vertex of the cube. Bland's rule does better on this particular input, but its counts satisfy , Fibonacci growth, which is still exponential. Avis and Chvátal (1978) gave inputs on which Bland's rule is exponential in this way, and similar "deformed cubes" defeat the other classical deterministic rules (Jeroslow, 1973, for the greatest-improvement rule; Goldfarb and Sit, 1979, for steepest edge).
Why 2^n: an induction on n (sketch)
the first 2^(n-1) - 1 pivots solve the cube in x_1..x_(n-1) (x_n stays 0)
one pivot raises x_n (the top facet)
the last 2^(n-1) - 1 pivots solve the (n-1)-cube again, upside down
total T(n) = 2 T(n-1) + 1 = 2^n - 1Typical inputs are easy
On LPs that are not built to be bad, the number of pivots is small. The program solves random LPs with constraints and integer data, using floating point with a tolerance (as real solvers do), and prints the average pivot count over 10 instances.
import random
def simplex_float(c, A, b, eps=1e-9):
m, n = len(A), len(c)
T = [list(map(float, A[i])) + [float(i == k) for k in range(m)] + [float(b[i])] for i in range(m)]
z = list(map(float, c)) + [0.0] * (m + 1)
basis = [n + i for i in range(m)]
pivots = 0
while True:
improving = [j for j in range(n + m) if z[j] > eps]
if not improving:
return pivots
e = max(improving, key=lambda j: z[j])
l = min((i for i in range(m) if T[i][e] > eps), key=lambda i: (T[i][-1] / T[i][e], basis[i]))
T[l] = [v / T[l][e] for v in T[l]]
for i in range(m):
if i != l and T[i][e] != 0:
f = T[i][e]
T[i] = [a - f * p for a, p in zip(T[i], T[l])]
f = z[e]
z = [a - f * p for a, p in zip(z, T[l])]
basis[l] = e
pivots += 1
rng = random.Random(2001)
print(" n m average pivots")
for n in [5, 10, 20, 40]:
counts = []
for _ in range(10):
A = [[rng.randint(1, 9) for _ in range(n)] for _ in range(2 * n)]
b = [rng.randint(10, 99) for _ in range(2 * n)]
c = [rng.randint(1, 9) for _ in range(n)]
counts.append(simplex_float(c, A, b))
print(f"{n:2} {2 * n:2} {sum(counts) / len(counts):14}") n m average pivots
5 10 2.5
10 20 3.0
20 40 6.2
40 80 11.9
The counts stay far below the number of constraints. Random LPs of this kind are, admittedly, easy for other reasons too (the optimum is often near the origin), so this is evidence about typical behaviour, not a proof of anything.
Worst cases are fragile
The Klee-Minty cube is a precise construction: its coefficients are tuned so that every pivot makes the smallest possible progress. The next program perturbs every coefficient of and by a random factor with standard normal and counts Dantzig pivots again for , where the unperturbed cube needs .
import random
def simplex_float(c, A, b, eps=1e-12):
m, n = len(A), len(c)
T = [list(map(float, A[i])) + [float(i == k) for k in range(m)] + [float(b[i])] for i in range(m)]
z = list(map(float, c)) + [0.0] * (m + 1)
basis = [n + i for i in range(m)]
pivots = 0
while True:
improving = [j for j in range(n + m) if z[j] > eps]
if not improving:
return pivots
e = max(improving, key=lambda j: z[j])
l = min((i for i in range(m) if T[i][e] > eps), key=lambda i: (T[i][-1] / T[i][e], basis[i]))
T[l] = [v / T[l][e] for v in T[l]]
for i in range(m):
if i != l and T[i][e] != 0:
f = T[i][e]
T[i] = [a - f * p for a, p in zip(T[i], T[l])]
f = z[e]
z = [a - f * p for a, p in zip(z, T[l])]
basis[l] = e
pivots += 1
n = 10
c = [10 ** (n - j) for j in range(1, n + 1)]
A = [[2 * 10 ** (i - j) if j < i else int(j == i) for j in range(1, n + 1)] for i in range(1, n + 1)]
b = [100 ** (i - 1) for i in range(1, n + 1)]
print("sigma pivots in 5 perturbed copies")
for sigma in [0.0, 0.01, 0.1, 0.3]:
rng = random.Random(7)
counts = []
for _ in range(5):
A2 = [[v * (1 + rng.gauss(0, sigma)) for v in row] for row in A]
c2 = [v * (1 + rng.gauss(0, sigma)) for v in c]
counts.append(simplex_float(c2, A2, b))
print(f"{sigma:5} {counts}")sigma pivots in 5 perturbed copies
0.0 [1023, 1023, 1023, 1023, 1023]
0.01 [1023, 1023, 1023, 1023, 1023]
0.1 [359, 419, 565, 647, 613]
0.3 [90, 150, 108, 183, 257]
A perturbation of 1% leaves the cube's structure intact, but at 10% and 30% the pivot counts drop sharply. This is only an illustration with Dantzig's rule and multiplicative noise; the theorem below is about a different rule and additive Gaussian noise, and it gives a proof rather than an experiment.
The smoothed analysis theorem
Worst-case analysis takes the maximum of the running time over all inputs; average-case analysis takes the expectation over a distribution chosen by the analyst. Smoothed analysis takes the worst case of an expectation: an adversary picks the input, then nature perturbs it slightly, and we measure the expected running time on the perturbed input, maximized over the adversary's choice.
with having independent standard Gaussian entries.
Theorem (Spielman and Teng, 2001; journal version 2004). For the shadow-vertex simplex method, the smoothed number of pivots on LPs with constraints in variables, under Gaussian perturbations of and of relative standard deviation , is bounded by a polynomial in , and .
What this does and does not say:
- It explains why bad inputs are not met in practice: they occupy a region of measure tending to zero, and any amount of noise in the data, such as measurement error or rounding, pushes the input off them with high probability.
- The shadow-vertex rule walks along the projection of the polytope onto the plane spanned by the objective and an auxiliary direction; the proof bounds the expected number of vertices of this two-dimensional "shadow" polygon. It is not Dantzig's rule, and smoothed bounds for Dantzig's rule are not known.
- The original polynomial was large. Later work (Vershynin, 2009; Dadush and Huiberts, 2018) reduced it substantially, but the bounds are still far above the pivot counts seen in practice.
- Spielman and Teng received the 2008 Gödel Prize for this work. Smoothed analysis has since been applied to many other algorithms, such as -means and local search for TSP.
Note: Smoothed analysis does not make LP polynomial-time solvable by simplex in the worst case; that question is still open. The polynomial-time guarantees for linear programming come from the ellipsoid method and interior-point methods.
Test yourself
How many pivots does Dantzig's largest-coefficient rule make on the -dimensional Klee-Minty cube starting from the origin?
What does smoothed analysis measure?
- The best case over all inputs
- The average over uniformly random inputs
- The worst case, over the adversary's input, of the expected cost after a small random perturbation
- The cost of the smoothest input
Which statement about Spielman and Teng's theorem is correct?
- It proves Dantzig's rule is polynomial in the worst case
- It bounds the smoothed number of pivots of the shadow-vertex rule by a polynomial in , and
- It shows that linear programming is NP-hard
- It holds without any perturbation