TExcelTAD
Home › Linear Programming & Duality for Algorithms › Integer Programs and Their Relaxations

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

max⁡{cTx:Ax≤b, x∈Zn},\max \{ c^T x : Ax \le b,\ x \in \mathbb{Z}^n \},

and its LP relaxation is the same problem with x∈Rnx \in \mathbb{R}^n. Every integer solution is a fractional solution, so for a maximization

OPTIP≤OPTLP,\text{OPT}_{IP} \le \text{OPT}_{LP},

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 0≤x≤10 \le x \le 1 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 vi/wiv_i / w_i 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).

python · try it yourself
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 57\frac{5}{7} of the second, value 1357≈19.3\frac{135}{7} \approx 19.3. 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 P={x:Ax≤b}P = \{ x : Ax \le b \} is PI=conv⁡(P∩Zn)P_I = \operatorname{conv}(P \cap \mathbb{Z}^n), the convex hull of its integer points. For rational AA, bb it is again a polyhedron (Meyer, 1974), and

max⁡{cTx:x∈P∩Zn}=max⁡{cTx:x∈PI},\max \{ c^T x : x \in P \cap \mathbb{Z}^n \} = \max \{ c^T x : x \in P_I \},

because a linear function is maximized over a polytope at a vertex, and the vertices of PIP_I are integer points. So every IP is an LP, over PIP_I; the catch is that a description of PIP_I by inequalities is usually exponentially long or unknown, and finding it is as hard as the IP. The good cases are those where P=PIP = P_I, that is, PP 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 P≠PIP \ne P_I (Integrality Gaps).

Formulations matter

The same integer set has many LP descriptions, and the relaxations can be very different. In uncapacitated facility location, facilities ii with opening cost fif_i serve clients jj at cost cijc_{ij}; yi=1y_i = 1 opens facility ii and xij=1x_{ij} = 1 assigns client jj to it. A client may only use an open facility. Two ways to say so:

weak:  ∑jxij≤nclients⋅yi  ∀istrong:  xij≤yi  ∀i,j.\text{weak:} \ \ \sum_j x_{ij} \le n_{\text{clients}} \cdot y_i \ \ \forall i \qquad\qquad \text{strong:} \ \ x_{ij} \le y_i \ \ \forall i, j .

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 1n\frac{1}{n} and still serve a client fully.

python · try it yourself
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 PIP_I holds for every integer point of PP; 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 u≥0u \ge 0, the inequality uTAx≤uTbu^T A x \le u^T b is valid for PP; if uTAu^T A is integral, then for integer xx the left side is an integer, so

(uTA) x≤⌊uTb⌋(u^T A)\, x \le \lfloor u^T b \rfloor

is valid for PIP_I. Repeating this closure finitely often yields PIP_I (Chvátal's theorem), although the number of rounds can be large. The program applies one cut to a two-variable IP.

python · try it yourself
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 x+y≤1x + y \le 1 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 PIP_I, polyhedral combinatorics.

Test yourself

For a maximization IP, how do the IP and LP optima compare?

  1. OPTIP≥OPTLP\text{OPT}_{IP} \ge \text{OPT}_{LP}
  2. OPTIP≤OPTLP\text{OPT}_{IP} \le \text{OPT}_{LP}
  3. They are always equal
  4. They cannot be compared

Why does maximizing over the integer hull PIP_I solve the IP?

  1. Because PI=PP_I = P always
  2. Because PIP_I is a polyhedron whose vertices are integer points, and a linear objective is maximized at a vertex
  3. Because PIP_I has few constraints
  4. Because the LP is NP-hard

Why is a Chvátal-Gomory cut (uTA) x≤⌊uTb⌋(u^T A)\, x \le \lfloor u^T b \rfloor (with u≥0u \ge 0 and uTAu^T A integral) valid for all integer points of PP?

  1. u≥0u \ge 0 makes uTAx≤uTbu^T A x \le u^T b valid, and when uTAu^T A is integral the left side is an integer for integer xx, so the right side can be rounded down
  2. It is valid for every real point
  3. It follows from strong duality
  4. It requires AA to be totally unimodular