LP and Duality for Algorithms: What This Course Covers
Part I of the Algorithm Theory track met linear programming twice: as a modelling language in Formulating Linear Programs and as a way to write shortest paths and flows in Shortest Paths and Flows as Linear Programs. The Optimization course treats the same object from the continuous side: convexity, the KKT conditions, Lagrangian duality and the numerical behaviour of solvers. This course takes the algorithm designer's view. An LP is a tool for three jobs:
- Describing a combinatorial problem exactly or approximately. Matchings, flows, covers and cuts become polytopes; the question "is the optimum integral?" becomes a question about the vertices of that polytope.
- Proving things. Every LP has a dual LP, and a feasible dual solution is a certificate: a short, checkable proof that no primal solution is better than a given value. Max-flow min-cut, König's theorem and the analysis of greedy set cover are all instances of this one idea.
- Designing algorithms. Solve the relaxation and round it (deterministically, randomly, or with a random hyperplane, as Goemans and Williamson do for max-cut), or never solve an LP at all and run a primal-dual or multiplicative-weights scheme whose analysis is LP duality in disguise.
The topics follow the core of a graduate course on LP in algorithm design, in the spirit of Matoušek and Gärtner's Understanding and Using Linear Programming (2007), the appendices and first chapter of Williamson and Shmoys' The Design of Approximation Algorithms (2011) and Arora, Hazan and Kale's survey of the multiplicative weights method (2012). The text, the proofs as sketched here and all programs are written for this site.
A first example: covering a triangle
A vertex cover of a graph is a set of vertices touching every edge. As an integer program, give vertex a variable and require for every edge ; minimize . Relaxing to gives an LP. On a triangle the integer optimum is 2 (one vertex covers only two of the three edges), but the LP can do better.
from scipy.optimize import linprog
edges = [(0, 1), (1, 2), (0, 2)]
n = 3
# minimize x0 + x1 + x2 subject to -(x_u + x_v) <= -1 for every edge, 0 <= x <= 1
A = [[-1 if v in e else 0 for v in range(n)] for e in edges]
res = linprog([1] * n, A_ub=A, b_ub=[-1] * len(edges), bounds=[(0, 1)] * n, method="highs")
print("LP optimum x =", [round(float(v), 6) for v in res.x], "value", round(float(res.fun), 6))
# the dual: maximize sum of y_e subject to sum of y_e over edges at v <= 1, y >= 0
At = [[-1 if v in e else 0 for e in edges] for v in range(n)]
dual = linprog([-1] * len(edges), A_ub=[[-a for a in row] for row in At], b_ub=[1] * n, bounds=[(0, None)] * len(edges), method="highs")
print("dual optimum y =", [round(float(v), 6) for v in dual.x], "value", round(float(-dual.fun), 6))LP optimum x = [0.5, 0.5, 0.5] value 1.5
dual optimum y = [0.5, 0.5, 0.5] value 1.5
The LP puts on every vertex, value , below the integer optimum 2. The second LP is its dual: one variable per edge, at most 1 in total at each vertex (a fractional matching). Its optimum is also , and that equality is no accident. Any feasible gives a lower bound on every vertex cover, because each edge's is "paid for" by a cover vertex on that edge:
This three-step inequality is weak duality, the most used inequality in this course. It shows that proves that no fractional cover is cheaper than , without trusting the solver. Strong duality says that the two optima are always equal when both LPs are feasible.
A certificate you can check by hand
A solver's answer is only as good as your ability to check it. With a primal solution and a dual solution in hand, checking optimality is three loops: primal feasibility, dual feasibility, equal objective values. The program checks the triangle answer in exact rational arithmetic, so no rounding error can hide a mistake.
from fractions import Fraction as F
edges = [(0, 1), (1, 2), (0, 2)]
x = [F(1, 2)] * 3 # claimed optimal fractional cover
y = {e: F(1, 2) for e in edges} # claimed optimal fractional matching
primal_ok = all(x[u] + x[v] >= 1 for u, v in edges) and all(0 <= xv <= 1 for xv in x)
dual_ok = all(sum(y[e] for e in edges if v in e) <= 1 for v in range(3)) and all(ye >= 0 for ye in y.values())
print("primal feasible:", primal_ok, " dual feasible:", dual_ok)
print("primal value", sum(x), " dual value", sum(y.values()))
print("certified optimal:", primal_ok and dual_ok and sum(x) == sum(y.values()))primal feasible: True dual feasible: True
primal value 3/2 dual value 3/2
certified optimal: True
Equal values plus feasibility on both sides is a complete proof of optimality. The course builds up exactly this machinery and then uses it to analyse algorithms, often without ever solving an LP.
The map of the course
| Section | Main results | Typical use |
|---|---|---|
| LP geometry and simplex | vertices = basic feasible solutions; simplex walks along edges; Bland's rule prevents cycling; smoothed analysis (Spielman and Teng, 2001) | understanding why optima are vertices, and when vertices are integral |
| Duality | weak and strong duality, Farkas' lemma, complementary slackness, max-flow min-cut and König as LP duality, dual fitting | certificates of optimality, min-max theorems, analysing greedy algorithms |
| Polynomial-time solvers | the ellipsoid method (Khachiyan, 1979) and separation oracles; interior-point methods (Karmarkar, 1984) | LPs with exponentially many constraints, complexity results |
| Integrality | integer programs, total unimodularity, integrality gaps | when the relaxation is exact, and how far off it can be |
| Semidefinite programming | PSD matrices, vector programs, the Goemans-Williamson 0.878 bound (1995) | rounding vectors instead of numbers |
| Multiplicative weights | weighted majority, the MWU regret bound, the minimax theorem, approximate LP solving | fast approximate solvers, learning, games |
The approximation algorithms built on these tools (LP rounding, the primal-dual method, hardness of approximation) are the subject of the next course, Approximation Algorithms.
Conventions
- Vectors are columns; is an inner product; inequalities between vectors such as hold entry by entry.
- The primal is usually and the dual , with an matrix. Lessons that use another form say so.
- denotes the bit length of an LP's input (all numbers of , , written in binary). Polynomial-time means polynomial in , the number of variables and the number of constraints.
- Programs use
fractions.Fractionwhen the point is an exact certificate, and SciPy'slinprog(the HiGHS solver) when a numerical answer is enough. Floating-point results are rounded before printing. - When a theorem is quoted without a full proof, the lesson says so and gives a sketch of the idea. Long sketches sit in collapsible boxes.
Test yourself
Why is the LP optimum of vertex cover on a triangle smaller than the integer optimum?
- The solver is inaccurate
- The relaxation allows on every vertex, which covers each edge exactly with total
- The triangle has no vertex cover
- LPs always overestimate minimization problems
What does a feasible dual solution of a minimization LP give you?
- An upper bound on the primal optimum
- A lower bound on the primal optimum (weak duality)
- The primal optimal solution itself
- Nothing unless it is optimal
Which three checks together certify that a primal solution is optimal?
- is integral, is integral, both are vertices
- is primal feasible, some is dual feasible, and the two objective values are equal
- The solver reports status 0 twice
- satisfies every constraint with equality