TExcelTAD
Home › Linear Programming & Duality for Algorithms › Degeneracy, Cycling and Bland's Rule

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 nn constraints are tight at the vertex (in Rn\mathbb{R}^n), 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.

python · try it yourself
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: (43)=4\binom{4}{3} = 4 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 n×nn \times n bipartite graph is a perfect matching: nn positive variables out of a basis of size 2n−12n - 1 (the 2n2n degree equations have rank 2n−12n - 1), so n−1n - 1 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).

max⁡10x1−57x2−9x3−24x4s.t.12x1−112x2−52x3+9x4≤012x1−32x2−12x3+x4≤0x1≤1,x≥0\begin{aligned} \max \quad & 10x_1 - 57x_2 - 9x_3 - 24x_4 \\ \text{s.t.} \quad & \tfrac{1}{2}x_1 - \tfrac{11}{2}x_2 - \tfrac{5}{2}x_3 + 9x_4 \le 0 \\ & \tfrac{1}{2}x_1 - \tfrac{3}{2}x_2 - \tfrac{1}{2}x_3 + x_4 \le 0 \\ & x_1 \le 1, \qquad x \ge 0 \end{aligned}
python · try it yourself
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 {s1,s2,s3}\{s_1, s_2, s_3\}, 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 x=(1,0,1,0)x = (1, 0, 1, 0) 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 xtx_t be the fickle variable with the largest index. Look at two moments: a tableau DD where xtx_t leaves while some xex_e enters, and a later tableau D∗D^* where xtx_t enters again. In D∗D^*, xtx_t 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 D∗D^* and the equations of DD describe the same LP, so they can be combined. Substitute the parametric solution of DD (let xe=λx_e = \lambda, the other non-basic variables of DD zero, the basic ones read off DD) into the objective row of D∗D^*. Comparing the two expressions for the objective as functions of λ\lambda gives an identity, and the sign constraints just listed force some fickle variable xrx_r with r<tr < t to have been a candidate to leave in DD at the same (zero) ratio as xtx_t. Bland's leaving rule would then have chosen xrx_r instead of xtx_t, 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 AB−1A_B^{-1} lexicographically. Equivalent to perturbing bb to b+(ε,ε2,…,εm)b + (\varepsilon, \varepsilon^2, \ldots, \varepsilon^m) for an infinitesimal ε\varepsilon, which makes every vertex non-degenerate.
  • Random perturbation of bb, 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.

cpp · try it yourself
#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?

  1. The objective strictly increases
  2. The basis changes but the point and the objective value stay the same
  3. The LP becomes infeasible
  4. Two variables enter at once

Why can the simplex method only cycle through degenerate pivots?

  1. Because non-degenerate pivots are never allowed
  2. A non-degenerate pivot strictly increases the objective, so the basis it leaves can never come back
  3. Because cycles need integer data
  4. Because Bland's rule is always used

How many bases describe the apex of a square pyramid in R3\mathbb{R}^3 (four faces meet there)?

  1. 1
  2. 3
  3. 4
  4. 6