TExcelTAD
Home › Linear Programming & Duality for Algorithms › LP and Duality for Algorithms: What This Course Covers

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:

  1. 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.
  2. 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.
  3. 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 vv a variable xv∈{0,1}x_v \in \{0, 1\} and require xu+xv≥1x_u + x_v \ge 1 for every edge uvuv; minimize ∑vxv\sum_v x_v. Relaxing xv∈{0,1}x_v \in \{0,1\} to 0≤xv≤10 \le x_v \le 1 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.

python · try it yourself
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 12\frac{1}{2} on every vertex, value 32\frac{3}{2}, below the integer optimum 2. The second LP is its dual: one variable ye≥0y_e \ge 0 per edge, at most 1 in total at each vertex (a fractional matching). Its optimum is also 32\frac{3}{2}, and that equality is no accident. Any feasible yy gives a lower bound on every vertex cover, because each edge's yey_e is "paid for" by a cover vertex on that edge:

∑eye≤∑e=uvye(xu+xv)=∑vxv∑e∋vye≤∑vxv.\sum_{e} y_e \le \sum_{e = uv} y_e (x_u + x_v) = \sum_v x_v \sum_{e \ni v} y_e \le \sum_v x_v .

This three-step inequality is weak duality, the most used inequality in this course. It shows that y=(12,12,12)y = (\frac{1}{2}, \frac{1}{2}, \frac{1}{2}) proves that no fractional cover is cheaper than 32\frac{3}{2}, 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.

python · try it yourself
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; cTxc^T x is an inner product; inequalities between vectors such as Ax≤bAx \le b hold entry by entry.
  • The primal is usually max⁡{cTx:Ax≤b, x≥0}\max \{ c^T x : Ax \le b,\ x \ge 0 \} and the dual min⁡{bTy:ATy≥c, y≥0}\min \{ b^T y : A^T y \ge c,\ y \ge 0 \}, with AA an m×nm \times n matrix. Lessons that use another form say so.
  • LL denotes the bit length of an LP's input (all numbers of AA, bb, cc written in binary). Polynomial-time means polynomial in LL, the number of variables and the number of constraints.
  • Programs use fractions.Fraction when the point is an exact certificate, and SciPy's linprog (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?

  1. The solver is inaccurate
  2. The relaxation allows xv=12x_v = \frac{1}{2} on every vertex, which covers each edge exactly with total 32<2\frac{3}{2} < 2
  3. The triangle has no vertex cover
  4. LPs always overestimate minimization problems

What does a feasible dual solution of a minimization LP give you?

  1. An upper bound on the primal optimum
  2. A lower bound on the primal optimum (weak duality)
  3. The primal optimal solution itself
  4. Nothing unless it is optimal

Which three checks together certify that a primal solution xx is optimal?

  1. xx is integral, yy is integral, both are vertices
  2. xx is primal feasible, some yy is dual feasible, and the two objective values are equal
  3. The solver reports status 0 twice
  4. xx satisfies every constraint with equality