Integer Programs and Their Relaxations
Combinatorial problems ask for discrete objects: a set of vertices, a tour, a schedule. Written as optimization problems they become integer linear programs (IPs): linear objective, linear constraints, and the extra requirement that the variables be integers. Integer programming is NP-hard, so the algorithmic strategy of this whole area is to drop the integrality requirement, solve the LP relaxation in polynomial time, and then deal with the difference. This lesson sets up the vocabulary: relaxations and their bounds, the integer hull, why two formulations of the same problem can behave very differently, and the simplest kind of cutting plane. The solver side (branch and bound, cutting-plane loops) is in Integer Programming and Branch and Bound.
Integer programs and relaxations
An integer program is
and its LP relaxation is the same problem with . Every integer solution is a fractional solution, so for a maximization
and for a minimization the inequality reverses. The LP value is a bound that can be computed in polynomial time, and its dual solutions are certificates for that bound. A 0/1 program, where each variable is a yes/no decision, has in its relaxation.
The first example is a 0/1 knapsack problem: items with values and weights, capacity 10. The LP relaxation is solved greedily by value density: take items in order of and a fraction of the first one that does not fit (Dantzig, 1957). The integer problem is solved here with SciPy's milp (branch and bound inside HiGHS).
import numpy as np
from fractions import Fraction as F
from scipy.optimize import milp, LinearConstraint, Bounds
values = [10, 13, 7, 8, 4]
weights = [5, 7, 4, 5, 3]
cap = 10
order = sorted(range(5), key=lambda i: -F(values[i], weights[i]))
room, x_lp = F(cap), [F(0)] * 5
for i in order:
take = min(F(1), room / weights[i])
x_lp[i] = take
room -= take * weights[i]
if room == 0:
break
lp = sum(v * xi for v, xi in zip(values, x_lp))
print("LP relaxation: x =", [str(v) for v in x_lp], " value", lp)
res = milp(c=-np.array(values), constraints=LinearConstraint([weights], 0, cap),
integrality=np.ones(5), bounds=Bounds(0, 1))
x_ip = [int(round(float(v))) for v in res.x]
print("integer optimum: x =", x_ip, " value", int(round(float(-res.fun))))
x_round = [int(v == 1) for v in x_lp]
print("rounding the LP down: x =", x_round, " value", sum(v * xi for v, xi in zip(values, x_round)))LP relaxation: x = ['1', '5/7', '0', '0', '0'] value 135/7
integer optimum: x = [1, 0, 0, 1, 0] value 18
rounding the LP down: x = [1, 0, 0, 0, 0] value 10
The LP takes the first item fully and of the second, value . Rounding that down keeps only the first item, value 10, while the integer optimum, value 18, replaces the second item by the fourth, which has a lower value density but fits exactly. The LP bound is a good estimate of the optimum, while the LP solution says little about the optimal set: getting a good integer solution out of a relaxation needs an actual rounding algorithm, the subject of Approximation Algorithms.
The integer hull
The integer hull of is , the convex hull of its integer points. For rational , it is again a polyhedron (Meyer, 1974), and
because a linear function is maximized over a polytope at a vertex, and the vertices of are integer points. So every IP is an LP, over ; the catch is that a description of by inequalities is usually exponentially long or unknown, and finding it is as hard as the IP. The good cases are those where , that is, is an integral polyhedron: all its vertices are integral. Then the LP relaxation solves the IP. The rest of this section is about recognising such cases (Totally Unimodular Matrices) and measuring the damage when (Integrality Gaps).
Formulations matter
The same integer set has many LP descriptions, and the relaxations can be very different. In uncapacitated facility location, facilities with opening cost serve clients at cost ; opens facility and assigns client to it. A client may only use an open facility. Two ways to say so:
Both have exactly the same integer solutions (the weak constraint is the sum of the strong ones), but the strong relaxation is much tighter: in the weak one, a facility can be "opened" to the fraction and still serve a client fully.
import numpy as np
from scipy.optimize import linprog, milp, LinearConstraint, Bounds
f = [12, 10, 14] # opening costs
c = [[2, 7, 9, 5], [8, 3, 4, 6], [6, 9, 2, 3]] # c[i][j]: facility i serves client j
nf, nc = 3, 4
nv = nf + nf * nc # y_0..y_2, then x_ij
X = lambda i, j: nf + i * nc + j
cost = np.array(f + [c[i][j] for i in range(nf) for j in range(nc)], dtype=float)
assign = np.zeros((nc, nv)) # every client assigned once
for j in range(nc):
for i in range(nf):
assign[j, X(i, j)] = 1
weak = np.zeros((nf, nv))
for i in range(nf):
weak[i, i] = -nc
for j in range(nc):
weak[i, X(i, j)] = 1
strong = np.zeros((nf * nc, nv))
for i in range(nf):
for j in range(nc):
strong[i * nc + j, i], strong[i * nc + j, X(i, j)] = -1, 1
for name, rows in [("weak", weak), ("strong", strong)]:
lp = linprog(cost, A_ub=rows, b_ub=np.zeros(len(rows)), A_eq=assign, b_eq=np.ones(nc), bounds=[(0, 1)] * nv, method="highs")
print(f"{name:6} LP bound {float(lp.fun):.4f}")
ip = milp(cost, constraints=[LinearConstraint(strong, -np.inf, 0), LinearConstraint(assign, 1, 1)],
integrality=np.ones(nv), bounds=Bounds(0, 1))
opened = [i for i in range(nf) if ip.x[i] > 0.5]
print(f"integer optimum {float(ip.fun):.4f}, open facilities {opened}")weak LP bound 22.5000
strong LP bound 31.0000
integer optimum 31.0000, open facilities [1]
The weak relaxation pays only a quarter of each opening cost it needs, and its bound 22.5 is far below the optimum 31; on this instance the strong relaxation's bound is exact. A tighter bound lets branch and bound prune far more of its search tree. A rule of thumb for modelling: disaggregate constraints whenever the number of constraints stays polynomial.
Cutting planes
A valid inequality for holds for every integer point of ; a cutting plane is a valid inequality violated by the current LP optimum. The simplest family are the Chvátal-Gomory cuts (Gomory, 1958; Chvátal, 1973): for any , the inequality is valid for ; if is integral, then for integer the left side is an integer, so
is valid for . Repeating this closure finitely often yields (Chvátal's theorem), although the number of rounds can be large. The program applies one cut to a two-variable IP.
from fractions import Fraction as F
from scipy.optimize import linprog
# maximize x + y s.t. 2x + 2y <= 3, -2x + 2y <= 1, x, y >= 0, integer
A, b = [[2, 2], [-2, 2]], [3, 1]
lp = linprog([-1, -1], A_ub=A, b_ub=b, bounds=[(0, None)] * 2, method="highs")
print("LP value before the cut:", round(float(-lp.fun), 6))
u = [F(1, 2), F(0)] # multiplier for the first row
lhs = [sum(u[i] * A[i][j] for i in range(2)) for j in range(2)]
rhs = sum(u[i] * b[i] for i in range(2))
print("u^T A =", [str(v) for v in lhs], " u^T b =", rhs, " -> cut: x + y <=", rhs.numerator // rhs.denominator)
lp2 = linprog([-1, -1], A_ub=A + [[1, 1]], b_ub=b + [1], bounds=[(0, None)] * 2, method="highs")
best_int = max(x + y for x in range(3) for y in range(3) if all(r[0] * x + r[1] * y <= bi for r, bi in zip(A, b)))
print("LP value after the cut:", round(float(-lp2.fun), 6), " integer optimum:", best_int)LP value before the cut: 1.5
u^T A = ['1', '1'] u^T b = 3/2 -> cut: x + y <= 1
LP value after the cut: 1.0 integer optimum: 1
One cut closes the gap completely here: the inequality is a facet of the integer hull. In general, cuts are combined with branching (branch and cut), and the families of cuts used for specific problems (subtour, comb and clique inequalities) come from studying the facets of , polyhedral combinatorics.
Test yourself
For a maximization IP, how do the IP and LP optima compare?
- They are always equal
- They cannot be compared
Why does maximizing over the integer hull solve the IP?
- Because always
- Because is a polyhedron whose vertices are integer points, and a linear objective is maximized at a vertex
- Because has few constraints
- Because the LP is NP-hard
Why is a Chvátal-Gomory cut (with and integral) valid for all integer points of ?
- makes valid, and when is integral the left side is an integer for integer , so the right side can be rounded down
- It is valid for every real point
- It follows from strong duality
- It requires to be totally unimodular