Part VII · Selected Topics Chapter 29

Linear Programming

Maximise a linear objective subject to linear constraints — the most broadly applicable optimisation framework there is, and the one that quietly contains half of Part VI.

A linear program optimises a linear function of real variables subject to linear inequalities. That sounds narrow and is not: maximum flow, shortest paths, bipartite matching, and the assignment problem are all linear programs, and so are resource allocation, blending, scheduling, and portfolio problems throughout industry. Chapter 29 covers the geometry, the simplex algorithm, and duality — the last of which generalises the max-flow min-cut theorem into a principle that applies to every LP.

4th edition note. Renumbered from 29 to 29 within the reordered Part VII, with the treatment somewhat condensed. Duality remains the conceptual centre.

Contents

  1. Standard and slack forms
  2. The geometry
  3. The simplex algorithm
  4. How fast is simplex?
  5. Duality
  6. Problems that are secretly LPs
  7. Integer linear programming
  8. Recap

Standard and slack forms

Standard form. Maximise cᵀx subject to Ax ≤ b and x ≥ 0, where c and x are n-vectors, b is an m-vector, and A is m × n.
maximize c₁x₁ + c₂x₂ + … + cₙxₙ subject to aᵢ₁x₁ + aᵢ₂x₂ + … + aᵢₙxₙ ≤ bᵢ for i = 1..m xⱼ ≥ 0 for j = 1..n

Any LP can be put into this form by mechanical transformations, all of which CLRS spells out:

If the LP hasDo this
A minimisation objectiveNegate c and maximise
A variable with no sign constraintReplace x by x′ - x″ with both ≥ 0
An equality constraintReplace with two inequalities, and
A constraintMultiply through by -1

Slack form converts every inequality into an equality by introducing a non-negative slack variable measuring how much room is left in that constraint. Slack form is what the simplex algorithm actually manipulates.

The geometry

Each constraint aᵢᵀx ≤ bᵢ defines a half-space. Their intersection is a convex region called the feasible region or simplex. The objective cᵀx defines a family of parallel level sets, and optimising means pushing that family as far as it will go while still touching the region.
optimum objective direction c feasible region = intersection of half-spaces (always convex) the optimum is always at a vertex, never strictly inside
Figure 29.1 — A two-variable LP. Push the objective as far as possible and it stops at a corner.
The fundamental theorem of linear programming. If an LP has an optimal solution, then it has one at a vertex of the feasible region. This is what converts a search over infinitely many points into a search over finitely many corners — and it is what makes simplex possible.

Three outcomes are possible: the LP is infeasible (the region is empty), unbounded (the objective grows without limit), or has a finite optimum.

The simplex algorithm

Simplex starts at a vertex of the feasible region and repeatedly walks to an adjacent vertex with a better objective value, stopping when no neighbour improves. Because the region is convex, a local optimum is a global optimum — there are no false summits.
SIMPLEX, outline 1. Convert to slack form and find an initial feasible vertex (the INITIALIZE-SIMPLEX subproblem). 2. repeat choose a nonbasic variable whose increase improves the objective determine how far it can increase before a constraint binds pivot: swap that variable into the basis, swap out the binding one until no nonbasic variable can improve the objective 3. Report the optimal solution.

Each pivot is a change of basis, algebraically identical to a step of Gaussian elimination from Chapter 28. The variables split into m basic ones (currently non-zero) and n nonbasic ones (currently zero), and each basis corresponds to one vertex.

Degeneracy and cycling. A pivot can sometimes leave the objective unchanged, and it is possible for simplex to cycle forever among such degenerate bases. The fix is an anti-cycling pivot rule; Bland’s rule — always pick the lowest-indexed eligible variable — provably terminates, at the cost of sometimes being slow. CLRS proves termination using it.

How fast is simplex?

AlgorithmWorst caseIn practice
SimplexExponential (Klee-Minty cubes)Excellent — usually O(m) pivots
Ellipsoid (Khachiyan 1979)PolynomialSlow; of theoretical importance only
Interior point (Karmarkar 1984)PolynomialCompetitive, better on very large problems
Simplex is the standard example of an algorithm with a terrible worst case and superb typical behaviour. The Klee-Minty construction forces it to visit all 2ⁿ vertices of a distorted cube, but such inputs essentially never arise. The ellipsoid method settled the theoretical question — LP is in P — without displacing simplex in practice. Modern solvers ship both simplex and interior-point and choose per problem.

Duality

The deepest idea in the chapter. Every LP (the primal) has a companion LP (the dual) built by transposing its structure.

PRIMAL DUAL maximize cᵀx minimize bᵀy subject to Ax ≤ b subject to Aᵀy ≥ c x ≥ 0 y ≥ 0
PrimalDual
n variablesn constraints
m constraintsm variables
MaximiseMinimise
Objective coefficients cConstraint bounds c
Constraint bounds bObjective coefficients b
Weak duality (Lemma 29.8). For any feasible primal x and any feasible dual y, cᵀx ≤ bᵀy. Every feasible dual solution is an upper bound on every feasible primal solution.
Strong duality (Theorem 29.10). If the primal has an optimal solution x*, then the dual has an optimal solution y*, and cᵀx* = bᵀy*. The two optima are equal.
Why duality matters practically: it gives certificates. Exhibiting a dual feasible solution with value v proves no primal solution exceeds v. Anyone can verify the proof without rerunning the algorithm. That turns “trust my optimiser” into a checkable claim, and it is why LP solvers report dual values alongside the answer.
Max-flow min-cut is LP duality. Chapter 24’s theorem said maximum flow equals minimum cut. Formulate max flow as an LP and its dual is the min-cut problem; strong duality gives the theorem immediately. Similarly, the shortest-path and assignment-problem dualities are instances of the same principle. Chapter 24 proved one case by hand; this chapter explains why such pairings exist at all.

Problems that are secretly LPs

ProblemAs a linear program
Maximum flowVariables are edge flows; constraints are capacities and conservation; maximise the flow out of s.
Shortest pathsMaximise dₜ subject to dᵛ ≤ dᵘ + w(u,v) for every edge — the triangle inequality as constraints.
Minimum-cost flowFlow constraints plus a linear cost objective. No purely combinatorial algorithm is as simple.
Assignment problemChapter 25’s Hungarian algorithm is a specialised primal-dual LP method.
Difference constraintsChapter 22 solved these with Bellman-Ford; they are an LP feasibility problem.
Vertex cover, set coverTheir LP relaxations drive the approximation algorithms of Chapter 35.
The practical skill is modelling: recognising that a problem can be written as a linear objective over linear constraints. Once it is, you hand it to a solver rather than inventing an algorithm. Given how good modern solvers are, this is often the right engineering answer even when a specialised algorithm exists.

Integer linear programming

Add the requirement that variables be integers and the problem becomes NP-hard. Linear programming is in P; integer linear programming is NP-complete. That gap is enormous and it is where most real difficulty lives, because scheduling, routing, and packing problems all need whole numbers — you cannot run 2.7 delivery vans.

The standard response is LP relaxation: drop the integrality requirement, solve the resulting LP, and then either round the answer or search around it with branch-and-bound. The relaxation’s optimum bounds the integer optimum, which is exactly what branch-and-bound needs to prune, and how far apart they are is the integrality gap. Chapter 35 uses relaxation and rounding to build approximation algorithms with proven quality guarantees.

Recap

The seven things to carry forward

Where this goes next

Chapter 30 turns to polynomials and the fast Fourier transform, which multiplies two degree-n polynomials in Θ(n lg n) instead of Θ(n²) by switching representation — a divide-and-conquer result as surprising as Strassen’s and vastly more used.


Ch 28 — Matrix Operations Ch 30 — Polynomials and the FFT