第 13 章
一般线性规划的对偶与互补松弛
把对偶从规范形推广到任意线性规划,证明互补松弛定理并用它从原问题最优解反推对偶解,再用力学类比证明强对偶,最后以 König 定理收尾。
Duality for General Linear Programs and Complementary Slackness
We extend duality beyond canonical form, prove complementary slackness and use it to recover a dual optimum from a primal one, prove strong duality via a mechanical analogy, and finish with König's theorem.
篇内目录
- From canonical form to arbitrary programs
- Timeline
- Three possible fates
- Duals of arbitrary programs
- An easier route
- Complementary slackness
- Proof
- Recovering a dual solution
- Three proofs of strong duality
- The mechanical proof
- Application: König's theorem
- What this lecture establishes
- Comprehension check
- Relation to neighbouring lectures
从规范形推广到任意形式
上一讲只对规范形(全部约束是 、全部变量非负)给出了对偶。真实问题里约束方向混杂、变量有正有负,所以这一讲先补上一般规则,再证明两个核心定理:互补松弛与强对偶。
时间轴
| 时间 | 内容 |
|---|---|
| 0:00 | 回顾规范形的对偶与弱对偶 |
| 2:42 | 线性规划的三种情形:有有限最优、不可行、无界 |
| 4:16 | 弱对偶的推论:原问题无界则对偶不可行 |
| 6:41 | 任意线性规划取对偶的符号规则 |
| 14:42 | 更省事的做法:先化成规范形再取对偶 |
| 19:18 | 互补松弛定理 |
| 28:45 | 用互补松弛从原问题最优解求对偶最优解 |
| 33:23 | 强对偶的三种证明路线 |
| 36:47 | 力学类比证明强对偶 |
| 53:17 | 应用:König 定理(最大匹配 = 最小顶点覆盖) |
三种可能的情形
任何线性规划恰属于下列之一:
- 有有限最优值:存在可行解,且最优值有限。
- 不可行:可行域为空,例如 且 。
- 无界:可行,但目标函数可以任意大(或任意小),例如 且 。
由弱对偶立刻得到两个推论:
- 若原问题无界,则对偶不可行。否则任取一个对偶可行解 ,它的值 就是原问题上界,与原问题无界矛盾。
- 若对偶无界,则原问题不可行。
原问题与对偶同时不可行也是可能的。这种情况少见,但不是矛盾——弱对偶只说「若两者都可行,则不等式成立」。
任意线性规划的对偶规则
设原问题是最大化。规则只有一张表:
| 原问题 | 对偶 |
|---|---|
| 第 条约束是 | |
| 第 条约束是 | |
| 第 条约束是 | 无约束 |
| 第 个变量 | 第 条对偶约束是 |
| 第 个变量 | 第 条对偶约束是 |
| 第 个变量 无约束 | 第 条对偶约束是 |
理由就是弱对偶的证明:要把约束相加而不翻转不等号, 约束的权重必须非负, 约束的权重必须非正,等式约束的权重随意。反过来,变量 的符号决定了对偶约束的方向。
例子。 原问题
按表:第一条约束给 ,第二条给 ,第三条给 无约束。于是对偶是
(注意第二条约束右端是 ,故系数为 ;若把约束写成 ,则系数变为 ,两者等价),约束为
更省事的做法
课程明说:不喜欢「负变量」的规则,因为容易出错。替代方案是先把原问题化成规范形,再套上一讲的公式。
对上面的例子:把第二条约束取负变成 ,把自由变量 拆成 或者保留为等式后再按规则处理。课程采用的写法是保留等式、但把自由变量对应的对偶约束写成等式,得到
所有变量都在规范方向上,没有「」这种反直觉的东西。
互补松弛
定理。 设 是规范形原问题的可行解, 是对偶可行解。则 与 同时最优,当且仅当
用一句话说:约束越紧,对应的对偶权重可以非零;约束有松弛,对偶权重必须为零。 反过来,原变量非零则对应的对偶约束必须取等号。
证明
弱对偶的链条是
若 都最优,由强对偶可知两端相等,于是中间每一步都必须取等号。
先看第一个不等号。 且 ,所以
取等号意味着这个非负量等于 。它是 项之和 ,每项都非负,所以每项都为 :对每个 ,要么 ,要么 。
再看第二个不等号。 且 ,所以
取等号意味着每项 ,即对每个 ,要么 ,要么 。
反过来,如果这些互补条件都成立,上面两个不等号都取等号,于是 ,由弱对偶可知两者都达到最优。
用互补松弛反推对偶解
继续上面的例子。已知 是原问题最优解(验证: 紧, 松, 紧;目标值 )。
由互补松弛:
- ,所以第一条对偶约束取等号:。
- ,所以第二条对偶约束取等号:。
- 第二条原约束不紧(),所以 。
解出 ,,。对偶目标值 ,与原问题相等——强对偶得到验证。
这个过程也说明了互补松弛的实际用途:手算时不必再解第二个 LP,直接列出线性方程组即可。
强对偶的三种证明
课程列出了三条路线:
- 单纯形表。 算法结束时表上同时读出原问题与对偶的最优解,两者相等。完全严格,但依赖算法细节。
- Farkas 引理。 直接用分析中的引理。问题是这条引理本身与强对偶几乎是同一句话换个写法,证明不带来新理解。
- 维力学。 用几条经典力学定理,把 LP 想成小球在斜面上滚动。课程选的是这一条,因为它给出几何直觉。
力学证明
把每条约束 看成一张超平面。目标函数 是重力方向,小球被重力往下拉,落在可行区域最低的点上停住——那就是最优解。
停住意味着受力平衡:所有接触到的超平面施加的支持力之和等于重力。设第 张超平面施加的力为
方向沿法向量 (指向可行区域外侧),大小是 。平衡条件写成
再看接触条件:
- 小球碰到第 张超平面时,约束取等号 ;
- 没碰到时,那张超平面不施力,。
这正是互补松弛。于是
而 给出 ,所以
原问题与对偶问题的最优值相等,强对偶得证。这个论证的美妙之处在于:它把「线性规划强对偶」与「 维静力学自洽」说成了同一件事。
应用:König 定理
设定。 是二分图。匹配是一组两两不共端点的边;顶点覆盖是一组与每条边都相邻的顶点。
定理(König)。 最大匹配的大小等于最小顶点覆盖的大小。
一个方向是显然的。 任何顶点覆盖都必须覆盖匹配的每条边,而匹配的边两两不交,所以覆盖至少要有「匹配大小」那么多个顶点。
另一个方向用 LP。 给每条边 一个变量 ,把匹配写成
每条边最多被选一次,每个顶点最多被一条选中的边占用——这就是匹配的「分数版本」。它的对偶是给每个顶点 一个变量 ,
这正是分数顶点覆盖。
为什么最优解可以是整数? 若存在分数解,可以沿一条交替路径或偶环调整:把 0.5 的边按奇偶交替加减同一个 ,直到某个变量碰到 或 。二分图没有奇环,所以调整总能进行,最终消掉所有分数值。于是匹配 LP 有整数最优解;同理对偶也有整数最优解。两边的整数最优值相等,正是 König 定理。
课程在这里没有把细节讲完,但给出了完整的思路骨架:把组合问题写成 LP,证明松弛仍取整数解,再让强对偶替你完成计数。
本节结论
- 线性规划只有三种命运:有限最优、不可行、无界;原问题无界则对偶不可行。
- 任意 LP 的对偶由一张符号表决定;更稳妥的做法是先化成规范形。
- 互补松弛:紧约束才可能有非零对偶权重,非零原变量才要求对偶约束取等号。
- 互补松弛可直接从原问题最优解解出对偶最优解。
- 强对偶有一个力学证明:支持力平衡即 ,接触条件即互补松弛。
- König 定理:最大匹配 = 最小顶点覆盖,本质是匹配 LP 与其对偶的强对偶。
理解检验
1. 原问题是 ,第一条约束是 ,第二个变量自由,第三个变量 。对应的对偶变量与对偶约束各是什么?
参考答案:第一条约束是 ,故 ;第二个变量自由,故第二条对偶约束取等号;第三个变量 ,故第三条对偶约束是 。若不想记「负变量」规则,可先取负把约束改成 、把变量改成非负,再套规范形公式。
2. 用互补松弛求对偶最优解:原问题 ,约束 、、,已知 最优。
参考答案: 使第一、二条对偶约束取等号;第二条原约束不紧()使 。于是 ,。对偶目标 ,等于原问题目标值 ,验证强对偶。
3. 证明规范形下的互补松弛定理。
参考答案:弱对偶给出 。若两者最优,由强对偶两端相等,两个不等号都取等号。第一处等号意味着 ;因为 、,这是非负项之和,故每项为零: 或 。第二处等号意味着 ;因为 、,故 或 。反向由同样的等式链即得。
4. 在力学证明中, 代表什么?为什么「没接触」对应 ?
参考答案: 是第 张超平面施加在小球上的支持力大小,方向沿法向量 。小球没碰到那张超平面时,它与小球之间没有接触,也就没有力,所以 ;碰到时约束取等号 。两者合起来正是互补松弛。受力平衡 给出 ,于是 ,强对偶成立。
5. 为什么二分图匹配的 LP 松弛一定有整数最优解?
参考答案:任取一个分数最优解。若存在分数边,就能找到一条由分数边组成的交替路径或偶环(二分图没有奇环)。沿这条路径把边按 交替调整,顶点约束保持不变,目标值不变;取最大的可行 ,至少有一条边变成 或 。反复进行,最终所有边都取 或 ,得到整数最优解。对偶(分数顶点覆盖)同理,于是整数最优值相等,即 König 定理。
与前后课的关系
上一讲建立了对偶公式与弱对偶;本讲补全一般规则、互补松弛与强对偶,并用 König 定理展示了「LP + 整数性」这套组合拳。下一讲把这套工具用在零和博弈上:原问题给出先手的最优混合策略,对偶给出后手的最优策略,强对偶就是极小极大定理。再下一讲的最大流最小割是同一模板的第三次出现。
From canonical form to arbitrary programs
The previous lecture defined the dual only for canonical form, where every constraint is and every variable is non-negative. Real problems mix constraint directions and allow variables of either sign, so this lecture supplies the general rules and then proves the two central theorems: complementary slackness and strong duality.
Timeline
| Time | Topic |
|---|---|
| 0:00 | Recap: the canonical dual and weak duality |
| 2:42 | Three fates of an LP: finite optimum, infeasible, unbounded |
| 4:16 | Consequences: an unbounded primal has an infeasible dual |
| 6:41 | Sign rules for taking the dual of an arbitrary LP |
| 14:42 | An easier route: normalise to canonical form first |
| 19:18 | The complementary slackness theorem |
| 28:45 | Using it to recover a dual optimum from a primal optimum |
| 33:23 | Three proof routes to strong duality |
| 36:47 | The mechanical proof of strong duality |
| 53:17 | Application: König's theorem (max matching = min vertex cover) |
Three possible fates
Every linear program is exactly one of:
- Finite optimum: feasible, and the optimal value is finite.
- Infeasible: the feasible set is empty, e.g. and .
- Unbounded: feasible, but the objective can be made arbitrarily large (or small), e.g. with .
Weak duality gives two consequences at once:
- If the primal is unbounded, the dual is infeasible. Otherwise any dual feasible would give an upper bound , contradicting unboundedness.
- If the dual is unbounded, the primal is infeasible.
Primal and dual may also be infeasible simultaneously. This is rare but not contradictory: weak duality only says that if both are feasible, the inequality holds.
Duals of arbitrary programs
Let the primal be a maximisation. One table decides everything:
| Primal | Dual |
|---|---|
| Constraint is | |
| Constraint is | |
| Constraint is | free |
| Variable | Dual constraint is |
| Variable | Dual constraint is |
| Variable free | Dual constraint is |
The reason is the proof of weak duality: to add constraints without flipping inequalities, weights on constraints must be non-negative, weights on constraints non-positive, and weights on equations arbitrary. Symmetrically, the sign of fixes the direction of the dual constraint.
Example. Primal:
The table gives , , free, so the dual is
(The coefficient of is because the right-hand side of the second constraint is ; writing that constraint as would produce instead, with the same dual.)
An easier route
The lecture admits a dislike for the "negative variable" rule, because mistakes are easy. The alternative is to normalise the primal to canonical form first, then apply the previous lecture's formula.
For the example: negate the second constraint to , keep the free variable but give its dual constraint an equality, and read off
Now every dual variable points the intuitive way; nothing says "".
Complementary slackness
Theorem. Let be primal feasible and dual feasible, for the canonical pair. Then and are both optimal if and only if
In words: a tight constraint may carry a nonzero dual weight; a slack constraint must carry zero weight. Conversely, a nonzero primal variable forces its dual constraint to be tight.
Proof
The chain behind weak duality is
If both are optimal, strong duality makes the ends equal, so both inequalities must be equalities.
For the first: and , so
Equality forces this non-negative quantity to be . It is a sum of non-negative terms , so every term is zero: for each , either or .
For the second: and , so
Equality forces every term to vanish: for each , either or .
Conversely, if all these conditions hold, both inequalities are equalities, so and weak duality makes both optimal.
Recovering a dual solution
Return to the example. Suppose is known to be optimal (check: tight, slack, tight; objective ).
Complementary slackness gives:
- , so dual constraint 1 is tight: .
- , so dual constraint 2 is tight: .
- Primal constraint 2 is slack (), so .
Solving gives , , . Dual objective: , equal to the primal value — strong duality confirmed.
The practical lesson: you do not have to solve a second LP; write down the linear system and solve it.
Three proofs of strong duality
The lecture lists three routes:
- The simplex tableau. When the algorithm stops, the tableau yields optimal solutions of both problems, and they are equal. Completely rigorous, but depends on algorithmic detail.
- Farkas' lemma. Taken from analysis. The objection is that Farkas' lemma is essentially strong duality in different notation, so the proof adds no insight.
- Mechanics in dimensions. A few classical theorems from mechanics, with the LP pictured as a ball rolling on surfaces. The lecture chooses this one for its geometric intuition.
The mechanical proof
Treat each constraint as a hyperplane. Gravity points in the direction , pulling the ball down until it comes to rest at the lowest point of the feasible region — the optimum.
Rest means force balance: the support forces from all hyperplanes the ball touches sum to the gravitational force. Let the force from hyperplane be
along the normal (pointing out of the feasible region) with magnitude . Balance reads
Now the contact conditions:
- If the ball touches hyperplane , then the constraint is tight, ;
- If it does not touch it, that hyperplane exerts no force, so .
That is exactly complementary slackness. Therefore
while gives , hence
Primal and dual optima coincide, which is strong duality. The appeal is that "strong duality for linear programming" and "-dimensional statics is consistent" become the same statement.
Application: König's theorem
Setting. Let be a bipartite graph. A matching is a set of edges with no shared endpoint; a vertex cover is a set of vertices meeting every edge.
Theorem (König). The size of a maximum matching equals the size of a minimum vertex cover.
One direction is immediate. Any vertex cover must cover every matching edge, and matching edges are disjoint, so the cover needs at least as many vertices as the matching has edges.
The other direction uses an LP. Give each edge a variable and write the matching as
Each edge is chosen at most once and each vertex is used by at most one chosen edge — the "fractional" version of a matching. Its dual assigns to each vertex:
That is a fractional vertex cover.
Why can the optimum be integral? Given a fractional solution, follow an alternating path or an even cycle of fractional edges and add alternately. Vertex constraints stay satisfied and the objective is unchanged; choosing maximal drives some variable to or . Bipartiteness rules out odd cycles, so the adjustment always exists, and all fractional values eventually disappear. Hence the matching LP has an integral optimum; the same argument works for the dual. The two integral optima are equal, which is König's theorem.
The lecture does not finish every detail, but the skeleton is complete: write the combinatorial problem as an LP, show the relaxation still has integral optima, and let strong duality do the counting.
What this lecture establishes
- An LP has exactly one of three fates: finite optimum, infeasible, unbounded; an unbounded primal implies an infeasible dual.
- The dual of an arbitrary LP follows one sign table; normalising to canonical form first is safer.
- Complementary slackness: only tight constraints may carry dual weight, and only nonzero primal variables force tight dual constraints.
- It recovers a dual optimum directly from a primal optimum.
- Strong duality has a mechanical proof: force balance is , contact conditions are complementary slackness.
- König's theorem — max matching equals min vertex cover — is strong duality for the matching LP.
Comprehension check
1. The primal is ; constraint 1 is , variable 2 is free, variable 3 is . What are the dual variable signs and dual constraint directions?
Reference answer: Constraint 1 being gives ; variable 2 being free makes dual constraint 2 an equality; variable 3 being makes dual constraint 3 a . If the negative-variable rule is unwelcome, negate constraints and variables first so everything is canonical, then apply the canonical formula.
2. Use complementary slackness: primal with , , , and optimal.
Reference answer: make dual constraints 1 and 2 tight; primal constraint 2 is slack (), so . Then gives , and gives . The dual objective is , matching the primal value .
3. Prove complementary slackness in canonical form.
Reference answer: Weak duality gives . If both are optimal, strong duality makes the ends equal, so both inequalities are equalities. The first equality means ; since and , this is a sum of non-negative terms, so each vanishes: or . The second means ; since and , each term vanishes: or . The converse follows by running the same chain backwards.
4. In the mechanical proof, what is , and why does "no contact" mean ?
Reference answer: is the magnitude of the support force exerted by hyperplane on the ball, directed along the normal . Without contact there is no force, so ; with contact the constraint is tight, . Together these are complementary slackness. Force balance gives , hence and strong duality.
5. Why does the LP relaxation of bipartite matching always have an integral optimum?
Reference answer: Take a fractional optimum. If a fractional edge exists, there is an alternating path or even cycle of fractional edges (bipartiteness excludes odd cycles). Add alternately along it: vertex constraints remain satisfied and the objective is unchanged, while the maximal feasible sends at least one variable to or . Iterating eliminates all fractional values, yielding an integral optimum. The same holds for the dual, so the two integral optima agree — König's theorem.
Relation to neighbouring lectures
The previous lecture built the duality formula and weak duality; this one completes the general rules, complementary slackness and strong duality, and uses König's theorem to show the LP-plus-integrality pattern. The next lecture applies the toolkit to zero-sum games: the primal yields the row player's optimal mixed strategy, the dual the column player's, and strong duality becomes the minimax theorem. The max-flow min-cut theorem after that is the third appearance of the same template.