Exercises
Fifteen problems covering the whole course: LP geometry and the simplex method, duality and its combinatorial consequences, polynomial-time solvers, integrality, semidefinite programming and multiplicative weights. Each has a short Answer and a full Solution; several solutions include a program that checks the result in exact arithmetic or with SciPy. Try each one on paper first.
Tip: For any claim of optimality, produce the certificate: a primal solution, a dual solution and the equality of their values (or complementary slackness). For any claim of infeasibility, produce a Farkas vector. The programs below do exactly this.
| # | Exercise | Practises |
|---|---|---|
| 1 | Into standard form | conversions |
| 2 | Vertex or not? | tight constraints, BFS |
| 3 | Two pivots by hand | simplex with Bland's rule, reading the dual |
| 4 | A dual with every kind of constraint | the dualization recipe |
| 5 | Certify a claimed optimum | complementary slackness |
| 6 | Prove infeasibility | Farkas' lemma |
| 7 | Round a fractional cut | threshold rounding, max-flow duality |
| 8 | A matching and its certificate | König's theorem |
| 9 | Greedy vertex cover as set cover | dual fitting |
| 10 | How many ellipsoid steps? | the iteration bound |
| 11 | TU or not? | total unimodularity, Ghouila-Houri |
| 12 | Odd cycles do not give gap 2 | integrality gaps |
| 13 | The triangle's SDP | max-cut SDP, Goemans-Williamson |
| 14 | Tuning the learning rate | MWU regret |
| 15 | A game without a saddle point | minimax |
Exercise 1: Into standard form
Convert to the form :
How many variables and constraints does the result have?
Answer
Four variables (, , , ) and three rows: maximize subject to , , , all variables .
Solution
Negate the objective to turn the minimization into a maximization. Substitute with (a non-positive variable becomes a non-negative one), so becomes and, after negation, ; the first constraint becomes . Split the free variable . Multiply the row by , and replace the equation by two opposite inequalities. The optimal value of the original is minus the optimal value of the converted LP (Standard Form, Slack Form and Combinatorial LPs).
Exercise 2: Vertex or not?
For , decide whether and are vertices.
Answer
is not a vertex (only one constraint is tight); is a vertex (two tight constraints with independent normals).
Solution
At only is tight. In the plane a vertex needs two linearly independent tight constraints, and indeed is the midpoint of the feasible points and . At both and are tight, with normals and , which are independent: a basic feasible solution, hence a vertex (Polytopes, Vertices and Basic Feasible Solutions).
Exercise 3: Two pivots by hand
Solve subject to , , with the simplex method and Bland's rule, starting from the slack basis. Read an optimal dual solution off the final tableau.
Answer
Two pivots: enters and leaves (value 8), then enters and leaves (value 9). Optimum , value 9, dual .
Solution
Both reduced costs are positive; Bland picks the smaller index, . Ratios and : leaves. Then , , . Now has reduced cost 1; the ratio test compares (row of ) with (row of ), so leaves: , , . All reduced costs are negative: optimal. The negated slack reduced costs give , with (Weak and Strong Duality).
from fractions import Fraction as F
A, b, c = [[1, 1], [1, 3]], [4, 6], [2, 3]
x, y = [F(3), F(1)], [F(3, 2), F(1, 2)]
print("primal feasible:", all(sum(A[i][j] * x[j] for j in range(2)) <= b[i] for i in range(2)) and min(x) >= 0)
print("dual feasible: ", all(sum(A[i][j] * y[i] for i in range(2)) >= c[j] for j in range(2)) and min(y) >= 0)
print("values:", sum(c[j] * x[j] for j in range(2)), sum(b[i] * y[i] for i in range(2)))primal feasible: True
dual feasible: True
values: 9 9
Exercise 4: A dual with every kind of constraint
Write the dual of
Answer
subject to , , , with , , free. Both optima equal 12, attained at and .
Solution
By the recipe (Building the Dual Mechanically): the row gets , the row , the equation a free . Columns: gives ; free gives the equation ; gives . At the first two rows are tight and , so complementary slackness asks for equality in the first and third dual constraints; with the equation this gives , of value , the primal value . The program solves both.
from fractions import Fraction
from scipy.optimize import linprog
primal = linprog([-3, 1, -2], A_ub=[[1, 1, 1], [-2, 0, 1]], b_ub=[5, -1], A_eq=[[0, 1, 1]], b_eq=[3],
bounds=[(0, None), (None, None), (0, None)], method="highs")
dual = linprog([5, 1, 3], A_ub=[[-1, -2, 0], [-1, 1, -1]], b_ub=[-3, -2], A_eq=[[1, 0, 1]], b_eq=[-1],
bounds=[(0, None), (None, 0), (None, None)], method="highs")
print("primal optimum:", Fraction(float(-primal.fun)).limit_denominator(100))
print("dual optimum: ", Fraction(float(dual.fun)).limit_denominator(100))primal optimum: 12
dual optimum: 12
Exercise 5: Certify a claimed optimum
Someone claims that is optimal for subject to , , , . Prove or refute it with complementary slackness.
Answer
It is optimal: the certificate is , and both values are 14.
Solution
Row 3 has slack (), so . Since , the first two dual constraints are tight: and , so , . Dual feasibility: , and the third dual constraint holds. So is dual feasible and complementary to , which proves optimality (Complementary Slackness).
from fractions import Fraction as F
A, b, c = [[1, 1, 1], [2, 1, 0], [1, 3, 1]], [4, 6, 9], [4, 3, 1]
x, y = [2, 2, 0], [2, 1, 0]
Ax = [sum(A[i][j] * x[j] for j in range(3)) for i in range(3)]
ATy = [sum(A[i][j] * y[i] for i in range(3)) for j in range(3)]
print("primal feasible", all(Ax[i] <= b[i] for i in range(3)), " dual feasible", all(ATy[j] >= c[j] for j in range(3)))
print("row products", [y[i] * (b[i] - Ax[i]) for i in range(3)], " column products", [x[j] * (ATy[j] - c[j]) for j in range(3)])
print("values", sum(c[j] * x[j] for j in range(3)), sum(b[i] * y[i] for i in range(3)))primal feasible True dual feasible True
row products [0, 0, 0] column products [0, 0, 0]
values 14 14
Exercise 6: Prove infeasibility
Show that , , , has no solution by exhibiting a Farkas certificate for the form .
Answer
Write the rows as , , and take : and .
Solution
Adding the three rows gives . In the language of the second variant of Farkas' lemma: , and , so no satisfies . (A certificate with exactly is not required for this form, since makes enough.)
Exercise 7: Round a fractional cut
In the network (capacity 4), (1), (2), (1), (4), the potentials with form a feasible solution of the min-cut LP. Compute its value, the expected capacity of the threshold cut, and the best threshold cut. Is the dual solution optimal?
Answer
Value ; expected threshold cut ; best threshold cut with capacity 4. Not optimal: the maximum flow is 4.
Solution
on the five arcs, so . Thresholds in give (capacity 5), in give (capacity ), in give (capacity 5). The expectation is , equal to the dual value as the analysis predicts (Max-Flow Min-Cut as LP Duality). The flow (1), (2), (1) has value 4, so the cut is minimum and the fractional solution was not optimal.
Exercise 8: A matching and its certificate
Left vertices , right vertices , edges . Find a maximum matching and a vertex cover of the same size.
Answer
A maximum matching has size 3 (for example , , or , , ); a cover of size 3 is .
Solution
Vertex 4 is isolated, and , , have neighbourhoods inside , so at most two of them can be matched, giving at most 3. The cover touches every edge: by , by 2, by 3. Equal sizes certify both (Bipartite Matching and König's Theorem). The program finds them with augmenting paths and König's construction.
L = ["a", "b", "c", "d"]
adj = {"a": ["1", "2"], "b": ["2"], "c": ["2", "3"], "d": ["3"]}
match = {}
def augment(u, seen):
for w in adj[u]:
if w not in seen:
seen.add(w)
if w not in match or augment(match[w], seen):
match[u], match[w] = w, u
return True
return False
for u in L:
augment(u, set())
Z = {u for u in L if u not in match}
stack = list(Z)
while stack:
u = stack.pop()
for w in adj[u]:
if w not in Z and match.get(u) != w:
Z.add(w)
if w in match and match[w] not in Z:
Z.add(match[w]); stack.append(match[w])
cover = sorted(set(L) - Z) + sorted({w for u in L for w in adj[u]} & Z)
print("matching", sorted((u, match[u]) for u in L if u in match), " cover", cover)matching [('a', '1'), ('b', '2'), ('c', '3')] cover ['a', '2', '3']
Exercise 9: Greedy vertex cover as set cover
Vertex cover is the special case of set cover where the elements are the edges and each vertex is the set of edges at . What ratio does the dual fitting analysis of greedy give in a graph of maximum degree ? Compare with threshold rounding.
Answer
. Threshold rounding of the LP gives 2, which is better once ().
Solution
The largest set has elements, so greedy (repeatedly pick the vertex with the smallest weight per newly covered edge) costs at most (Dual Fitting). , , , . So for graphs of maximum degree at most 3, greedy has the better guarantee; beyond that, the threshold rounding bound 2 wins. (For unweighted vertex cover, taking both ends of a maximal matching also gives 2.)
Exercise 10: How many ellipsoid steps?
A convex set in lies in a ball of radius and, if non-empty, contains a ball of radius . How many iterations of the ellipsoid method suffice to find a point or declare it empty?
Answer
.
Solution
The bound is (The Ellipsoid Method). With and , . The volume of the ellipsoid shrinks by at least per step, so after 3050 steps it is below , the volume ratio of the two balls.
Exercise 11: TU or not?
Which of these matrices are totally unimodular?
Answer
: yes. : no (). : yes (an interval matrix).
Solution
is the transpose of the incidence matrix of a 4-cycle (bipartite), so it is TU; in Ghouila-Houri form, give alternate rows of the cycle opposite signs (Bipartite, Network and Interval Matrices). has . In every column has its ones in consecutive rows (column 1: rows 1-2, column 2: rows 1-3, column 3: rows 2-3), so the alternating signing of any row subset works and it is TU; its determinant is .
Exercise 12: Odd cycles do not give gap 2
Compute the LP and integer optima of vertex cover on the odd cycle . What does this family say about the integrality gap?
Answer
LP , IP , ratio . Odd cycles only show a gap of (for the triangle); the gap 2 needs dense graphs such as .
Solution
All- is feasible, and summing the edge constraints gives , so the LP optimum is exactly . A cover of the cycle needs vertices. The ratio is largest for (the triangle, ) and tends to 1. The lower bound 2 comes from complete graphs, where the LP is and the optimum (Integrality Gaps).
Exercise 13: The triangle's SDP
Find the optimal max-cut SDP vectors for the triangle, the SDP value, and the expected cut of Goemans-Williamson rounding.
Answer
Three unit vectors in a plane at degrees; SDP ; the expected cut is , the maximum cut.
Solution
Each edge contributes , so the vectors give . Optimality: of the triangle's Laplacian is 3, so the dual has value (The Max-Cut SDP). Each edge is separated with probability , so ; a line through the centre of an equilateral triangle always splits its vertices 1-2, so every rounding gives a cut of size 2.
import math
import numpy as np
V = np.array([[math.cos(2 * math.pi * k / 3), math.sin(2 * math.pi * k / 3)] for k in range(3)])
E = [(0, 1), (1, 2), (0, 2)]
sdp = sum((1 - float(V[u] @ V[v])) / 2 for u, v in E)
L = np.array([[2, -1, -1], [-1, 2, -1], [-1, -1, 2]], dtype=float)
lam = float(np.linalg.eigvalsh(L).max())
expected = sum(math.acos(float(V[u] @ V[v])) / math.pi for u, v in E)
print(f"SDP value {sdp:.4f}, dual value 3 * lambda_max / 4 = {3 * lam / 4:.4f}, expected GW cut {expected:.4f}")SDP value 2.2500, dual value 3 * lambda_max / 4 = 2.2500, expected GW cut 2.0000
Exercise 14: Tuning the learning rate
MWU runs for rounds over decisions with costs in . Which minimizes the regret bound, and what is the bound? How many rounds are needed for an average regret of at most ?
Answer
; regret at most (average ). For average regret : .
Solution
The bound is minimized at , giving (The Multiplicative Weights Update Method). With : and . The average regret is at most when .
Exercise 15: A game without a saddle point
The row player pays . Find both optimal mixed strategies and the value.
Answer
Row player: . Column player: . Value .
Solution
There is no pure saddle point: the smallest row maximum is and the largest column minimum is . In a game without a saddle point, each optimal strategy makes the opponent indifferent. For the row player: , so and ; the payment is . For the column player: gives , and both rows then cost . Equal guarantees prove optimality (Zero-Sum Games and the Minimax Theorem).
Test yourself
You have feasible and with for a primal-dual pair. What follows?
- Nothing without a solver
- Both are optimal (weak duality)
- Only is optimal
- The LP is degenerate
Which property guarantees integral optimal vertices for every integral right-hand side?
- A non-singular constraint matrix
- A totally unimodular constraint matrix
- A positive semidefinite constraint matrix
- Non-negative costs
What is the Goemans-Williamson guarantee for max-cut?
- An expected cut of at least
- An optimal cut