Degeneracy, Cycling and Bland's Rule
The simplex method's termination argument looks easy: there are finitely many bases, the objective improves at every pivot, so no basis repeats. The hole is the word "improves". At a degenerate vertex a pivot can change the basis without moving the point, and the objective stays the same. A sequence of such pivots can come back to its starting basis, and then the method loops forever: it cycles. LPs from combinatorics are almost always highly degenerate, so this is not a curiosity. This lesson shows degeneracy, a real cycle, and why Bland's rule ends it.
Degenerate vertices
A basic feasible solution is degenerate if some basic variable is zero. Geometrically, more than constraints are tight at the vertex (in ), so several bases describe the same point. The apex of a square pyramid is the standard picture: four facets meet there, and any three of them determine the point.
from fractions import Fraction as F
from itertools import combinations
def solve3(M, r):
"""Cramer's rule for a 3 x 3 system, None if singular."""
det = lambda X: (X[0][0] * (X[1][1] * X[2][2] - X[1][2] * X[2][1]) - X[0][1] * (X[1][0] * X[2][2] - X[1][2] * X[2][0])
+ X[0][2] * (X[1][0] * X[2][1] - X[1][1] * X[2][0]))
d = det(M)
if d == 0:
return None
return tuple(F(det([[r[i] if k == j else M[i][k] for k in range(3)] for i in range(3)]), d) for j in range(3))
# square pyramid with base [0,2] x [0,2] at z = 0 and apex (1, 1, 1)
cons = [((0, 0, -1), 0), ((-1, 0, 1), 0), ((1, 0, 1), 2), ((0, -1, 1), 0), ((0, 1, 1), 2)]
apex_bases = 0
vertices = {}
for S in combinations(range(len(cons)), 3):
p = solve3([cons[i][0] for i in S], [cons[i][1] for i in S])
if p and all(sum(a * x for a, x in zip(row, p)) <= rhs for row, rhs in cons):
vertices.setdefault(p, []).append(S)
for p, bases in sorted(vertices.items()):
print(f"vertex {tuple(str(v) for v in p)}: {len(bases)} choice(s) of 3 tight constraints")vertex ('0', '0', '0'): 1 choice(s) of 3 tight constraints
vertex ('0', '2', '0'): 1 choice(s) of 3 tight constraints
vertex ('1', '1', '1'): 4 choice(s) of 3 tight constraints
vertex ('2', '0', '0'): 1 choice(s) of 3 tight constraints
vertex ('2', '2', '0'): 1 choice(s) of 3 tight constraints
Each base corner is defined by exactly three constraints, but the apex by any 3 of the 4 sloping faces: bases for one point. A simplex pivot between two of these bases is degenerate: the ratio test returns 0, the entering variable enters at value 0, and neither the point nor the objective changes.
Combinatorial LPs are degenerate by nature. A vertex of the assignment polytope of an bipartite graph is a perfect matching: positive variables out of a basis of size (the degree equations have rank ), so basic variables are zero at every vertex.
A cycle
The classic small example below (it appears in Chvátal's Linear Programming, 1983) uses the "textbook" rule: enter the variable with the largest reduced cost, and break ties in the ratio test by the smallest index. The origin is degenerate (two right-hand sides are 0).
from fractions import Fraction as F
def simplex(c, A, b, rule, max_pivots=20):
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)]
name = lambda j: f"x{j + 1}" if j < n else f"s{j - n + 1}"
seen = {}
for k in range(max_pivots + 1):
key = tuple(sorted(basis))
print(f" pivot {k}: basis {{{', '.join(name(j) for j in key)}}}, value {-z[-1]}")
if key in seen:
return f"CYCLE: basis of pivot {seen[key]} repeated"
seen[key] = k
improving = [j for j in range(n + m) if z[j] > 0]
if not improving:
return "optimal, x = " + str([str(T[basis.index(j)][-1]) if j in basis else "0" for j in range(n)])
e = min(improving) if rule == "bland" else max(improving, key=lambda j: (z[j], -j))
rows = [i for i in range(m) if T[i][e] > 0]
l = min(rows, 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
c = [10, -57, -9, -24]
A = [[F(1, 2), F(-11, 2), F(-5, 2), 9], [F(1, 2), F(-3, 2), F(-1, 2), 1], [1, 0, 0, 0]]
b = [0, 0, 1]
for rule in ["largest reduced cost", "bland"]:
print(rule)
print(" ->", simplex(c, A, b, rule))largest reduced cost
pivot 0: basis {s1, s2, s3}, value 0
pivot 1: basis {x1, s2, s3}, value 0
pivot 2: basis {x1, x2, s3}, value 0
pivot 3: basis {x2, x3, s3}, value 0
pivot 4: basis {x3, x4, s3}, value 0
pivot 5: basis {x4, s1, s3}, value 0
pivot 6: basis {s1, s2, s3}, value 0
-> CYCLE: basis of pivot 0 repeated
bland
pivot 0: basis {s1, s2, s3}, value 0
pivot 1: basis {x1, s2, s3}, value 0
pivot 2: basis {x1, x2, s3}, value 0
pivot 3: basis {x2, x3, s3}, value 0
pivot 4: basis {x3, x4, s3}, value 0
pivot 5: basis {x4, s1, s3}, value 0
pivot 6: basis {x1, s1, s3}, value 0
pivot 7: basis {x1, x3, s1}, value 1
-> optimal, x = ['1', '0', '1', '0']
With the largest-coefficient rule, six degenerate pivots lead back to the starting basis , and the value never leaves 0: the method would loop forever. Bland's rule follows the same first five pivots, then makes a different choice at pivot 6 (a smaller-index entering variable) and reaches the optimum with value 1 at pivot 7.
Why Bland's rule cannot cycle
Theorem (Bland, 1977). With the smallest-index rule for both the entering and the leaving variable, the simplex method terminates.
Proof sketch
Suppose it cycles. All pivots of the cycle are degenerate (the objective is constant along the cycle), so the point does not move. Call a variable fickle if it enters and leaves during the cycle, and let be the fickle variable with the largest index. Look at two moments: a tableau where leaves while some enters, and a later tableau where enters again. In , has a positive reduced cost and, by the rule, every fickle variable with a smaller index has a non-positive one.
The objective row of and the equations of describe the same LP, so they can be combined. Substitute the parametric solution of (let , the other non-basic variables of zero, the basic ones read off ) into the objective row of . Comparing the two expressions for the objective as functions of gives an identity, and the sign constraints just listed force some fickle variable with to have been a candidate to leave in at the same (zero) ratio as . Bland's leaving rule would then have chosen instead of , a contradiction. The full bookkeeping is in Chvátal's and in Matoušek and Gärtner's textbooks.
Two other cures are common:
- Lexicographic rule (Dantzig, Orden and Wolfe, 1955): break ties in the ratio test by comparing whole rows of lexicographically. Equivalent to perturbing to for an infinitesimal , which makes every vertex non-degenerate.
- Random perturbation of , as production solvers do, followed by a clean-up phase.
Neither cure makes the method polynomial. Cycling is about termination; the number of pivots is a separate problem.
In C++
The same experiment in C++: both rules on the cycling LP, stopping when a basis repeats. Exact arithmetic again. The data must be entered exactly as above: scaling a row would rescale its slack variable and change which reduced cost is largest, so the largest-coefficient rule is not even invariant under rescaling, one more reason not to trust it.
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <set>
#include <vector>
struct Q {
long long p, q;
Q(long long a = 0, long long b = 1) : p(a), q(b) { if (q < 0) { p = -p; q = -q; } long long g = std::gcd(p < 0 ? -p : p, q); if (g > 1) { p /= g; q /= g; } }
Q operator-(Q o) const { return Q(p * o.q - o.p * q, q * o.q); }
Q operator*(Q o) const { return Q(p * o.p, q * o.q); }
Q operator/(Q o) const { return Q(p * o.q, q * o.p); }
bool operator<(Q o) const { return p * o.q < o.p * q; }
};
int run(bool bland) {
int m = 3, n = 4, w = n + m + 1;
Q A[3][4] = {{Q(1, 2), Q(-11, 2), Q(-5, 2), Q(9)}, {Q(1, 2), Q(-3, 2), Q(-1, 2), Q(1)}, {Q(1), Q(0), Q(0), Q(0)}};
long long b[3] = {0, 0, 1}, c[4] = {10, -57, -9, -24};
std::vector<std::vector<Q>> T(m, std::vector<Q>(w));
std::vector<Q> z(w);
std::vector<int> basis(m);
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) T[i][j] = A[i][j];
T[i][n + i] = Q(1); T[i][w - 1] = Q(b[i]); basis[i] = n + i;
}
for (int j = 0; j < n; j++) z[j] = Q(c[j]);
std::set<std::vector<int>> seen;
for (int k = 0;; k++) {
std::vector<int> key = basis;
std::sort(key.begin(), key.end());
if (!seen.insert(key).second) { std::printf(" basis repeated after %d pivots: cycling\n", k); return k; }
int e = -1;
for (int j = 0; j < n + m; j++)
if (Q(0) < z[j] && (e < 0 || (!bland && z[e] < z[j]))) e = j;
if (e < 0) { std::printf(" optimal after %d pivots, value %lld\n", k, (Q(0) - z[w - 1]).p); return k; }
int l = -1;
for (int i = 0; i < m; i++) {
if (!(Q(0) < T[i][e])) continue;
if (l < 0) { l = i; continue; }
Q ri = T[i][w - 1] / T[i][e], rl = T[l][w - 1] / T[l][e];
if (ri < rl || (!(rl < ri) && basis[i] < basis[l])) l = i;
}
Q piv = T[l][e];
for (auto& v : T[l]) v = v / piv;
for (int i = 0; i < m; i++) if (i != l) { Q f = T[i][e]; for (int j = 0; j < w; j++) T[i][j] = T[i][j] - f * T[l][j]; }
Q f = z[e];
for (int j = 0; j < w; j++) z[j] = z[j] - f * T[l][j];
basis[l] = e;
}
}
int main() {
std::printf("largest reduced cost:\n");
run(false);
std::printf("Bland's rule:\n");
run(true);
}largest reduced cost:
basis repeated after 6 pivots: cycling
Bland's rule:
optimal after 7 pivots, value 1
Test yourself
What happens in a degenerate pivot?
- The objective strictly increases
- The basis changes but the point and the objective value stay the same
- The LP becomes infeasible
- Two variables enter at once
Why can the simplex method only cycle through degenerate pivots?
- Because non-degenerate pivots are never allowed
- A non-degenerate pivot strictly increases the objective, so the basis it leaves can never come back
- Because cycles need integer data
- Because Bland's rule is always used
How many bases describe the apex of a square pyramid in (four faces meet there)?
- 1
- 3
- 4
- 6