Part I · trunk A · linear programming · spine

03

Duality — the load-bearing unit

Every LP has a shadow LP that bounds it, prices its constraints, certifies its optimum, and re-solves it cheaply after a change.

needs 02~2½ h slides + 2½ h lablab: uv run co lab 03

03 · overview

Four faces of one idea

1 · a bound

Nonnegative combinations of constraints bound the objective. The best such bound is an LP, and it is exact.

2 · a certificate

A pair $(x, y)$ with equal objectives proves both optimal. Complementary slackness is the pointwise version.

3 · a set of prices

$y_i$ is what one more unit of $b_i$ is worth, exactly, within a computable range: a shadow price.

4 · an algorithm

The dual simplex method keeps optimality and restores feasibility. It is the method used after adding a cut or a bound.

getting around

Words with a dotted underline are glossary terms: click one for its definition. G lists every term in the unit, N shows the notes, where the longer proofs live. One LP, $\max 3x + 2y$, runs through every section: a solid underline like that one shows it on hover. Optional extra: interactive figures, linked from the slides they support by a small ▸ chip; skip them freely.

section 1

The dual as a bound

Adding up constraints, done as well as possible.

03 · bound

Where the dual comes from

$\max\ 3x + 2y\;$ s.t. $\;x + y \le 4,\ \ 2x + y \le 6,\ \ x, y \ge 0$.

Call this the primal. Multiply the constraints by multipliers $u, v \ge 0$ and add:

$$(u + 2v)\,x + (u + v)\,y \;\le\; 4u + 6v$$

If $u + 2v \ge 3$ and $u + v \ge 2$, the left side is at least $3x + 2y$ for every $x, y \ge 0$. So $4u + 6v$ is an upper bound on the optimum.

try some multipliers

$u = 3, v = 0$: $\ 3x + 3y \le 12$, bound 12.
$u = 2, v = 1$: $\ 4x + 3y \le 14$, bound 14.
$u = 1, v = 1$: $\ 3x + 2y \le 10$, bound 10. Can any do better?

The best such bound is itself an LP:

the dual $$\begin{aligned}\min\ & 4u + 6v\\ \text{s.t. } & u + 2v \ge 3\\ & u + v \ge 2\\ & u, v \ge 0\end{aligned}$$

$u = v = 1$ gives the bound $10$, and $x = y = 2$ attains $10$. Both are optimal, and neither needed a solver to check.

03 · bound

The rules, once

The dualization rules, for a max primal. In general the multipliers are $y = (y_1, \dots, y_m)$; on the textbook LP they are $(u, v)$.

primal (max $c^\top x$)dual (min $b^\top y$)
constraint $i$: $a_i x \le b_i$$y_i \ge 0$
constraint $i$: $a_i x \ge b_i$$y_i \le 0$
constraint $i$: $a_i x = b_i$$y_i$ free
$x_j \ge 0$dual constraint $j$: $(A^\top y)_j \ge c_j$
$x_j \le 0$dual constraint $j$: $(A^\top y)_j \le c_j$
$x_j$ freedual constraint $j$: $(A^\top y)_j = c_j$
how to rebuild it

Multipliers must keep inequalities pointing the right way: $\le$ constraints get $y \ge 0$. The combination must dominate the objective on the variable's allowed sign: $x_j \ge 0$ needs coefficient $\ge c_j$.

involution

For a min primal, flip every sign. Then $\text{dual}(\text{dual}(P)) = P$ exactly, and lab step 1 tests this on 40 random LPs.

03 · bound · example

Dualizing, line by line

primal $$\begin{aligned}\max\ & x_1 + 2x_2\\ \text{s.t. } & x_1 + x_2 \le 3 \\ & x_1 - x_2 \ge -1 \\ & x_1 \ge 0,\ \ x_2 \text{ free}\end{aligned}$$
dual $$\begin{aligned}\min\ & 3y_1 - y_2\\ \text{s.t. } & y_1 + y_2 \ge 1 \\ & y_1 - y_2 = 2 \\ & y_1 \ge 0,\ \ y_2 \le 0\end{aligned}$$
primal pieceruledual piece
constraint 1 is $\le$$\le$ constraint$y_1 \ge 0$
constraint 2 is $\ge$$\ge$ constraint$y_2 \le 0$
$x_1 \ge 0$, column $(1, 1)$, cost 1$x_j \ge 0$$y_1 + y_2 \ge 1$
$x_2$ free, column $(1, -1)$, cost 2$x_j$ free$y_1 - y_2 = 2$
right-hand sides $(3, -1)$→ costs$3y_1 - y_2$
both solved

Primal: $x = (1, 2)$, value $1 + 4 = \mathbf 5$.
Dual: $y = (\tfrac32, -\tfrac12)$, value $\tfrac92 + \tfrac12 = \mathbf 5$.

Check the dual: $\tfrac32 - \tfrac12 = 1 \ge 1$ ✓, $\ \tfrac32 + \tfrac12 = 2$ ✓, signs ✓. Equal values, so both are optimal.

03 · bound

Weak and strong duality

weak duality

For $\max\{c^\top x : Ax \le b,\, x \ge 0\}$ and its dual: if $x$ and $y$ are feasible, $c^\top x \le b^\top y$.

Why: $c^\top x \le (A^\top y)^\top x = y^\top (Ax) \le y^\top b$: the first step uses $x \ge 0$, the second $y \ge 0$. It is "add up the constraints", written with matrices.

strong duality

If the primal has an optimal solution, so does the dual, and the optimal values are equal.

Why: if every dual bound stayed above $z^* + \varepsilon$, the constraints plus "objective $\ge z^* + \varepsilon$" would have no solution. Farkas (unit 01) hands over weights proving that, and those weights are a dual solution with a bound below $z^* + \varepsilon$. Contradiction.

full proof in the notes (N)

on the running example
primal $(x, y)$$3x + 2y$dual $(u, v)$$4u + 6v$
$(1, 1)$5$(2, 1)$14
$(3, 0)$9$(3, 0)$12
$(2, 2)$10$(1, 1)$10

Every primal value is below every dual value: weak duality, nine comparisons at once. The last row has no gap: strong duality, and both are optimal.

The difference $b^\top y - c^\top x$ is the duality gap of a pair. For $(1,1)$ against $(2,1)$ it is 9; it closes to 0 only at the optimum.

03 · bound

Four possible outcomes, not nine

The outcome table: which primal status can pair with which dual status.

primal \ dualoptimalunboundedinfeasible
optimal✓ equal values✗✗
unbounded✗✗✓
infeasible✗✓✓ possible

Unbounded primal ⇒ infeasible dual: any dual solution would bound it.

Both infeasible happens, for example with $\max\ x_1$ subject to $x_1 - x_2 \le -1,\ -x_1 + x_2 \le -1$.

It is why presolve sometimes can only say "infeasible or unbounded". In the lab's random general LPs, HiGHS found 246 optimal pairs and 154 unbounded/infeasible pairs out of 400.

section 2

The dual as a certificate

Where the multipliers must be zero, and where they can be read off.

03 · certificate

Complementary slackness

theorem

Feasible $x$ and $y$ are both optimal if and only if

$$y_i\,(b_i - a_i x) = 0 \ \text{ for every constraint } i, \qquad x_j\,\big((A^\top y)_j - c_j\big) = 0 \ \text{ for every variable } j.$$
why: the gap splits into pieces

$b^\top y - c^\top x = \underbrace{y^\top (b - Ax)}_{\ge 0} + \underbrace{x^\top (A^\top y - c)}_{\ge 0}$

Every piece is (nonnegative) × (nonnegative). The gap is 0 exactly when every piece is 0, and a zero gap means both are optimal.

In words: a constraint with slack has price 0. A variable that is used has zero reduced cost. Only a binding constraint can carry a price.

Checking takes two matrix–vector products: an optimality certificate, lab step 3. The next slide runs the checks on the example.

03 · certificate · example

Complementary slackness, on the example

the optimal pair

$x = (2, 2)$ and the dual's $(u, v) = (1, 1)$:

pieceslackpaired withproduct
constraint 1$4 - 4 = 0$$u = 1$0
constraint 2$6 - 6 = 0$$v = 1$0
variable $x$$3 - 3 = 0$$x = 2$0
variable $y$$2 - 2 = 0$$y = 2$0

All four products are 0, so the gap $10 - 10$ is 0.

feasible, but not optimal

$x = (0, 0)$ with $(u, v) = (1, 1)$. Constraint 1 has slack 4 but price 1: product 4. Constraint 2: slack 6, price 1: product 6. The gap is $10 - 0 = 4 + 6$, exactly the sum. The certificate check rejects it on constraint 1.

using it to find the dual

Given only $x = (2, 2)$: both variables are positive, so both dual constraints must be tight:

$u + 2v = 3,\quad u + v = 2 \;\Rightarrow\; v = 1,\ u = 1.$

Two equations, no optimization. Then check $u, v \ge 0$: yes, so $(2, 2)$ is proved optimal.

a constraint with slack gets price 0

Add the constraint $x \le 3$. At $(2, 2)$ it has slack 1, so its price must be 0. Solving confirms duals $(1, 1, 0)$, optimum still 10. Loosening a constraint that isn't pressing changes nothing.

03 · certificate

Reading the dual off the final tableau

At an optimal basis, $y^\top = c_B^\top A_B^{-1}$, and the reduced cost of every column is $\bar c_j = c_j - y^\top a_j$.

A slack $s_i$ has cost 0 and column $e_i$, so $\bar c_{s_i} = -y_i$. The objective row, which stores $-\bar c$, holds $y_i$ in slack column $i$.

so

The optimal dual solution is the slack columns of the objective row (reading duals off the tableau). Every simplex solve returns a primal solution and a dual certificate at once.

Unit 02's final tableau:

y012−12
x10−112
z001110

$(u, v) = (1, 1)$, and $4u + 6v = 10 = 3x + 2y$.

section 3

The dual as prices

What a unit of each resource is worth, and for how long.

03 · prices

Shadow prices

slope 3 slope 1 = y₁ slope 0 b₁=4, z*=10 3 6 b₁ 9 12 z*

Optimum of the textbook LP as the right-hand side of $x + y \le b_1$ varies. Shaded: the range where the current basis stays optimal.

theorem

If the optimal basis is nondegenerate, $\;\dfrac{\partial z^*}{\partial b_i} = y_i$.

More generally the value function $z^*(b)$ is concave and piecewise linear, and $y$ is a supergradient.

Here $y_1 = u = 1$ on $b_1 \in [3, 6]$. Below 3, constraint 2 stops binding and the price jumps to 3. Above 6, constraint 1 itself stops binding and the price drops to 0.

03 · prices

Ranging: how long the price holds

Ranging: change $b_i$ to $b_i + \delta$. Reduced costs don't involve $b$, so the basis stays optimal for as long as it stays feasible:

$$x_B(\delta) = A_B^{-1}(b + \delta e_i) = \bar b + \delta\, d$$

where $d$ is slack column $i$ of the final tableau.

Feasible while $\bar b_r + \delta d_r \ge 0$ for all rows:

$$\max_{d_r > 0} \frac{-\bar b_r}{d_r} \;\le\; \delta \;\le\; \min_{d_r < 0} \frac{-\bar b_r}{d_r}$$
example

Slack column 1 is $d = (2, -1)$ with $\bar b = (2, 2)$: $\delta \in [-1, 2]$, so $b_1 \in [3, 6]$. Inside, $z^* = 10 + 1\cdot\delta$.

HiGHS's ranging report gives $[3, 6]$ with objective 9 and 12 at the ends. The lab's then checks 103 binding constraints, and all agree.

Outside the range the basis changes and the slope changes. A linear prediction there is wrong, which is why lab step 5 must refuse it.

03 · prices

Sign conventions: an afternoon, as promised

The same LP, $\max 3x + 2y$, $x + y \le 4$, $2x + y \le 6$:

source$u$$v$
your tableau11
HiGHS, sense=max11
HiGHS, written as $\min -c^\top x$−1−1
SciPy linprog marginals−1−1
one sign convention covers all four

A reported dual is $\partial(\text{objective})/\partial(\text{rhs})$ in the solver's own objective sense.

Maximizing, loosening a $\le$ constraint helps, so the dual is $\ge 0$. Minimizing $-c^\top x$, the same loosening lowers the objective, so it is $\le 0$.

section 4

The dual as an algorithm

Keep optimality, restore feasibility.

03 · dual simplex

The dual simplex method

State: a basis whose objective row is nonnegative (dual feasible) but with some negative right-hand sides (no primal feasibility).

  1. Leaving row: any row $r$ with $\bar b_r < 0$. The most negative is the usual choice.
  2. Entering column: among $j$ with $T_{rj} < 0$, minimize $\;\dfrac{T_{mj}}{-T_{rj}}$, the dual ratio test.
  3. Pivot. If no $T_{rj} < 0$, row $r$ reads "nonnegative combination = negative": the LP is infeasible.
why it works

It is exactly the primal simplex method applied to the dual LP, run on the same tableau.

The dual ratio test keeps every objective-row entry nonnegative after the pivot, and the objective value decreases monotonically toward the optimum from above.

Row $r$ in the infeasible case, an infeasible row, is a Farkas certificate: unit 01 again.

The next slide runs one pivot of it on the example.

03 · dual simplex · example

One dual simplex pivot, on the example

From the optimum $(2, 2)$, add the cut $x \le 1.5$ with slack $s_3$. Written in the current basis, its row is $s_1 - s_2 + s_3 = -\tfrac12$:

xys₁s₂s₃rhs
y012−102
x10−1102
s₃001−11−½
z0011010

1. Objective row still $\ge 0$: dual feasible. Only $s_3 = -\tfrac12$ is wrong, so row $s_3$ leaves.
2. Negative entries in that row: only $s_2$, ratio $1 / 1$. $s_2$ enters.
3. Pivot. New point $(1.5, 2.5)$, $z = 9.5$, every rhs $\ge 0$: optimal after one pivot.

A cold re-solve from the origin takes 2 pivots. New duals $(2, 0, 1)$: constraint 2 now has slack $\tfrac12$, and price 0.

(2,2) z=10 (1.5,2.5) z=9.5 x = 1.5 P

Shaded: what the cut removes. Ring: the old optimum, now infeasible. The pivot slides along $x + y = 4$ to the new corner.

03 · dual simplex

Why branch-and-cut lives on it

After an optimal solve, add a cut $a^\top x \le \beta$ (unit 08) or tighten a bound $x_j \le \lfloor x_j^* \rfloor$ (unit 07):

  • the new row, written in the current basis, leaves the objective row unchanged, so the basis is still dual feasible;
  • only the new row's rhs can be negative, so the tableau is still almost primal feasible.

That is the dual simplex's starting state, and it is typically a few pivots away from optimal: a warm start, not a cold start.

Lab then, 163 random LPs with one added cut:

warmcold
your dual simplex (pivots)0.983.34
HiGHS (iterations)0.963.47

On 4×5 LPs. The ratio widens with size: a cold solve's pivots grow with the LP, while a warm re-solve's pivots grow with the size of the change.

03 · the load

This unit, wearing seven hats

08 cutting planescuts are new constraints; the dual simplex re-optimizes after each round; Gomory cuts are read off the tableau.
10 column generationthe master's duals are the pricing problem's objective; a column with positive reduced cost enters.
11 Lagrangian relaxationprice the hard constraints, and the best prices give a bound: a partial dual, climbed by subgradients.
12 Benderssubproblem duals become cuts on the master: duals as rows instead of columns.
15 matchingthe Hungarian algorithm keeps dual potentials feasible and grows the matching on tight edges: primal–dual, and complementary slackness.
24 primal–dual approximationraise duals until constraints go tight, buy what goes tight, and bound the cost by weak duality.
29 KKTthe conditions of this unit for curved objectives and constraints: feasibility, dual feasibility, complementary slackness.

When one of those units feels hard, come back to the slide here that it generalizes: the seven hats are one idea.

03 · lab

Lab 03 — what you build

about 2½ hours · uv run co lab 03 · on unit 02's tableaux
  1. The dual transformer for every constraint sense and variable sign, as an exact involution.
  2. Duals from the tableau: one slice.
  3. An optimality certificate checked exactly, with the reason when it fails.
  4. Warm start: add a cut, then the dual simplex. Agrees with a cold re-solve.
  5. Sensitivity: ranges, and predictions that must be exact inside and refused outside.
uv run co test 03
uv run co then 03     # sign conventions · ranging vs HiGHS · warm vs cold

03 · checkpoint

Done when

checkpoint
  • All five lab steps are ✓.
  • Given a solved LP, you can read off the shadow price of each constraint, predict the objective change from a small right-hand-side perturbation before re-solving, and be right.
  • You can say why the dual simplex is the method used after adding a cut.

Reading

Bertsimas & Tsitsiklis, ch. 4 (§4.1–4.5) and §5.1–5.2.
Chvátal, ch. 5 and 10.
Gärtner & Matoušek, §6.5–6.6 (optional).

Next

05 formulations (IP begins) · 04 ellipsoid and interior point (branch) · 11 Lagrangian relaxation, which needs 16 as well · 29 convexity, if you want the continuous view now.