Simple Algorithm
Algorithms & Data Structures · Optimal · 28 min

LP Relaxation & Rounding

Solve the relaxed problem, then round: vertex cover, set cover and integrality gaps.

Integer programs express almost every NP-hard optimization problem, and linear programs are solvable in polynomial time. Drop the word "integer", solve, and round the fractions back: the art lies in the rounding, and the limit of the art is one number per relaxation, its integrality gap.

What you’ll learn

  • Write weighted vertex cover and set cover as integer programs, relax them, and prove that rounding the vertex-cover LP at 12\tfrac12 gives a 2-approximation.
  • Define the integrality gap and use it to bound what any LP-based analysis can prove: 2−2/n2 - 2/n on KnK_n for vertex cover, Ω(log⁡n)\Omega(\log n) for set cover.
  • Use LP duality to design and analyze a primal–dual algorithm that never solves an LP.
  • Analyze randomized rounding for set cover with the union bound, and the 3/43/4 algorithm for MAX-SAT that combines two roundings.
  • Explain the Goemans–Williamson algorithm for MAX-CUT: a semidefinite relaxation rounded by a random hyperplane, with ratio αGW≈0.8786\alpha_{GW} \approx 0.8786.

Relax, solve, round

In weighted vertex cover every vertex vv has a weight wv≥0w_v \ge 0, and you want a cover of least total weight. The matching algorithm of the Optimized lesson ignores weights and can fail badly: on a star whose center weighs 10 and whose four leaves weigh 1, it may pay 11 where 4 suffice. Write the problem as an integer program, with xv=1x_v = 1 meaning "vv is in the cover":

min⁡∑v∈Vwvxvsubject toxu+xv≥1  for every edge uv,xv∈{0,1}\min \sum_{v \in V} w_v x_v \quad\text{subject to}\quad x_u + x_v \ge 1\ \text{ for every edge } uv, \qquad x_v \in \{0, 1\}
The LP relaxation replaces xv∈{0,1}x_v \in \{0, 1\} by 0≤xv≤10 \le x_v \le 1. Its optimum, written LP\mathrm{LP}, can only be smaller: LP≤OPT\mathrm{LP} \le \mathrm{OPT}.

Linear programs are solvable in polynomial time, by the ellipsoid method (Khachiyan, 1979) or by interior-point methods (Karmarkar, 1984), and the simplex method is fast in practice. So an optimal fractional solution x∗x^* is a computable lower bound. Rounding it turns it into a cover.

DerivationProof
  1. max⁡(xu∗, xv∗) ≥ 12\max(x^*_u,\ x^*_v)\ \ge\ \tfrac12

    A cover. Every edge uvuv has xu∗+xv∗≥1x^*_u + x^*_v \ge 1, so the larger of the two values is at least 12\tfrac12, and that endpoint is in CC:

  2. w(C) = ∑v∈Cwv ≤ ∑v∈C2 wvxv∗ ≤ 2∑v∈Vwvxv∗ = 2 LP ≤ 2 OPTw(C)\ =\ \sum_{v \in C} w_v\ \le\ \sum_{v \in C} 2\,w_v x^*_v\ \le\ 2\sum_{v \in V} w_v x^*_v\ =\ 2\,\mathrm{LP}\ \le\ 2\,\mathrm{OPT}

    Cost. Every vertex of CC has 2xv∗≥12x^*_v \ge 1, so rounding it up to 1 at most doubles its contribution:

The vertex-cover LP has a remarkable structure: it always has an optimal solution with every xv∈{0,12,1}x_v \in \{0, \tfrac12, 1\}, and then some minimum-weight cover contains every vertex valued 1 and avoids every vertex valued 0 (Nemhauser & Trotter, 1975). The Optimal lesson Parameterized Algorithms & Kernelization turns this into a kernel with at most 2k2k vertices.

For vertex cover, the complete graph KnK_n with unit weights is the wall. Setting every xv=12x_v = \tfrac12 satisfies all edge constraints, and adding the constraints of all edges, (n−1)∑vxv≥(n2)(n - 1)\sum_v x_v \ge \binom{n}{2}, shows that nothing is cheaper: LP=n/2\mathrm{LP} = n/2. But a cover that leaves out two vertices leaves their edge uncovered, so OPT=n−1\mathrm{OPT} = n - 1.

Predict before you look

What is OPT/LP\mathrm{OPT}/\mathrm{LP} for unit-weight vertex cover on K10K_{10}?

Show the answer

1.8

OPT=9\mathrm{OPT} = 9 and LP=10/2=5\mathrm{LP} = 10/2 = 5, so the ratio is 1.81.8. In general it is (n−1)/(n/2)=2−2/n(n - 1)/(n/2) = 2 - 2/n, which tends to 2: no analysis against this LP can prove a ratio below 2.

Duality and the primal–dual method

Every linear program has a dual that bounds it from the other side. For the vertex-cover LP, put a variable ye≥0y_e \ge 0 on every edge, a payment that edge ee offers toward covering itself; no vertex may be overpaid:

max⁡∑e∈Eyesubject to∑e∋vye≤wv  for every vertex v,ye≥0\max \sum_{e \in E} y_e \quad\text{subject to}\quad \sum_{e \ni v} y_e \le w_v\ \text{ for every vertex } v, \qquad y_e \ge 0
With unit weights this is the fractional matching LP.

The primal–dual method, introduced for this problem by Bar-Yehuda and Even (1981), builds a cover and a dual solution side by side and never solves an LP. Scan the edges; whenever one is still uncovered, raise its payment yey_e until one of its endpoints becomes tight (its constraint holds with equality), and put the tight endpoints in the cover.

python
def primal_dual_vc(edges, w):
    slack = dict(w)                    # w[v] minus the payments made to v
    y, cover = {}, set()
    for u, v in edges:
        if u in cover or v in cover:
            continue                   # this edge is already covered
        d = min(slack[u], slack[v])    # raise y_uv until u or v is tight
        y[(u, v)] = d
        slack[u] -= d
        slack[v] -= d
        cover |= {x for x in (u, v) if slack[x] == 0}
    return cover, sum(y.values())      # a cover, and a dual value <= OPT

w = {'c': 10, 'a': 1, 'b': 1, 'd': 1, 'e': 1}
star = [('c', 'a'), ('c', 'b'), ('c', 'd'), ('c', 'e')]
cover, dual = primal_dual_vc(star, w)
print(sorted(cover), dual)             # ['a', 'b', 'd', 'e'] 4

On the star, each edge pays 1 and makes its leaf tight, while the center's slack falls from 10 to 6 and it never becomes tight. The cover is the four leaves, weight 4, and the dual value 4 proves it optimal. With unit weights both endpoints become tight at once: this is exactly the maximal-matching algorithm.

DerivationWhy it is a 2-approximation
  1. slacku=0  ∨  slackv=0\text{slack}_u = 0\ \ \lor\ \ \text{slack}_v = 0

    A cover. After an uncovered edge is processed, at least one of its endpoints is tight, hence in CC:

  2. ∑e∈Eye ≤ OPT\sum_{e \in E} y_e\ \le\ \mathrm{OPT}

    A feasible dual. Payments stop as soon as a vertex is tight, so no slack becomes negative, and weak duality applies:

  3. w(C) = ∑v∈C ∑e∋vye ≤ 2∑e∈Eye ≤ 2 OPTw(C)\ =\ \sum_{v \in C}\ \sum_{e \ni v} y_e\ \le\ 2\sum_{e \in E} y_e\ \le\ 2\,\mathrm{OPT}

    Tight vertices are paid for by edges. Each v∈Cv \in C is tight, and a payment yey_e is counted once for each endpoint of ee in CC, at most twice:

Check your understanding

In the primal–dual analysis, where does the factor 2 come from?

  1. From rounding fractional values of at least 12\tfrac12 up to 1
  2. From weak duality, which loses a factor of 2
  3. Each payment yey_e is counted once for every endpoint of ee in the cover, and an edge has two endpoints
  4. From the approximation ratio of the LP solver
Show the answer

C. Each payment yey_e is counted once for every endpoint of ee in the cover, and an edge has two endpoints

w(C)=∑v∈C∑e∋vyew(C) = \sum_{v \in C}\sum_{e \ni v} y_e counts yey_e once per endpoint of ee in CC, so at most twice. Weak duality, ∑eye≤OPT\sum_e y_e \le \mathrm{OPT}, loses nothing.

Randomized rounding for set cover

For weighted set cover, with sets S1,…,SkS_1, \dots, S_k of weights wjw_j over a universe of nn elements, the LP relaxation is:

min⁡∑jwjxjsubject to∑j: e∈Sjxj≥1  for every element e,0≤xj≤1\min \sum_{j} w_j x_j \quad\text{subject to}\quad \sum_{j:\ e \in S_j} x_j \ge 1\ \text{ for every element } e, \qquad 0 \le x_j \le 1

Threshold rounding still works, but with threshold 1/f1/f, where ff is the largest number of sets containing one element, and it gives ratio ff, which can be as large as kk. Randomized rounding (Raghavan & Thompson, 1987) reads xj∗x^*_j as a probability instead: in each of tt independent rounds, take every set SjS_j with probability xj∗x^*_j, and output the union of all the sets taken.

DerivationAnalysis with the union bound
  1. Pr⁡[e uncovered in a round] = ∏j: e∈Sj(1−xj∗) ≤ exp⁡(−∑j: e∈Sjxj∗) ≤ e−1\Pr[e \text{ uncovered in a round}]\ =\ \prod_{j:\ e \in S_j}\big(1 - x^*_j\big)\ \le\ \exp\Big(-\sum_{j:\ e \in S_j} x^*_j\Big)\ \le\ e^{-1}

    One element, one round. Using 1−x≤e−x1 - x \le e^{-x} and the LP constraint of element ee:

  2. Pr⁡[some element uncovered] ≤ n e−t ≤ n⋅n−2 = 1n\Pr[\text{some element uncovered}]\ \le\ n\,e^{-t}\ \le\ n\cdot n^{-2}\ =\ \frac1n

    Many rounds. With t=⌈2ln⁡n⌉t = \lceil 2\ln n\rceil independent rounds, and the union bound over the nn elements:

  3. E[cost] ≤ t⋅LP,Pr⁡[cost≥4t⋅LP] ≤ 14\mathbb{E}[\text{cost}]\ \le\ t\cdot\mathrm{LP}, \qquad \Pr\big[\text{cost} \ge 4t\cdot\mathrm{LP}\big]\ \le\ \tfrac14

    Cost. By linearity of expectation each round costs LP\mathrm{LP} on average, and by Markov's inequality the total reaches four times its mean with probability at most 14\tfrac14:

  4. Pr⁡[a cover of cost<4⌈2ln⁡n⌉⋅OPT] ≥ 34−1n\Pr\big[\text{a cover of cost} < 4\lceil 2\ln n\rceil\cdot\mathrm{OPT}\big]\ \ge\ \tfrac34 - \tfrac1n

    Together. For n≥2n \ge 2 the output is a cover of cost below 4t⋅LP=O(log⁡n)⋅OPT4t\cdot\mathrm{LP} = O(\log n)\cdot\mathrm{OPT} with probability at least 34−1n≥14\tfrac34 - \tfrac1n \ge \tfrac14; repeat until it is.

Greedy already achieves HnH_n, so why bother? Because randomized rounding is a method. It applies to any covering LP, including ones with side constraints, to routing problems (Raghavan and Thompson's original motivation), and, with Chernoff bounds in place of the union bound, to packing problems whose constraints must hold with high probability.

Check your understanding

Why does randomized rounding for set cover use about 2ln⁡n2\ln n rounds instead of one?

  1. One round would cost more than the LP optimum
  2. The LP must be re-solved after each round
  3. To make the expected cost equal to OPT\mathrm{OPT}
  4. In one round an element can stay uncovered with probability about 1/e1/e; after 2ln⁡n2\ln n rounds this is at most 1/n21/n^2, small enough for a union bound over all nn elements
Show the answer

D. In one round an element can stay uncovered with probability about 1/e1/e; after 2ln⁡n2\ln n rounds this is at most 1/n21/n^2, small enough for a union bound over all nn elements

One round covers each element with probability at least 1−1/e1 - 1/e, a constant, so with many elements some would almost surely be missed. Independent rounds multiply the failure probabilities, and e−2ln⁡n=n−2e^{-2\ln n} = n^{-2} beats the nn terms of the union bound. The price is the O(log⁡n)O(\log n) factor in the cost.

Beyond thresholds: MAX-SAT and MAX-CUT

In MAX-SAT you are given clauses, each an OR of literals, and want an assignment that satisfies as many as possible. Two very different algorithms each fail where the other shines. A uniformly random assignment satisfies a clause of kk literals with probability 1−2−k1 - 2^{-k}: excellent for long clauses, only 12\tfrac12 for a single literal. LP rounding solves the relaxation below and then sets each variable xix_i true with probability yi∗y^*_i.

max⁡∑CzCsubject to∑i∈PCyi+∑i∈NC(1−yi) ≥ zC,0≤yi, zC≤1\max \sum_C z_C \quad\text{subject to}\quad \sum_{i \in P_C} y_i + \sum_{i \in N_C}(1 - y_i)\ \ge\ z_C, \qquad 0 \le y_i,\ z_C \le 1
PCP_C and NCN_C are the variables that appear positively and negatively in clause CC. By the AM–GM inequality and concavity, LP rounding satisfies a clause of kk literals with probability at least (1−(1−1k)k)zC∗≥(1−1e) zC∗\big(1 - (1 - \tfrac1k)^k\big)z^*_C \ge (1 - \tfrac1e)\,z^*_C.
Clause length kkRandom assignment, 1−2−k1 - 2^{-k}LP rounding, 1−(1−1k)k1 - (1 - \tfrac1k)^kAverage
10.510.75
20.750.750.75
30.8750.70370.7894
40.93750.68360.8105
k→∞k \to \infty→1\to 1→1−1/e≈0.6321\to 1 - 1/e \approx 0.6321→0.8161\to 0.8161
The two guarantees cross at k=2k = 2, and their average never drops below 34\tfrac34.
DerivationMAX-SAT within 3/4 (Goemans & Williamson, 1994)
  1. E[satisfied] = ∑C(1−2−kC) ≥ ∑C(1−2−kC) zC∗\mathbb{E}[\text{satisfied}]\ =\ \sum_C \big(1 - 2^{-k_C}\big)\ \ge\ \sum_C \big(1 - 2^{-k_C}\big)\,z^*_C

    Random assignment. Since zC∗≤1z^*_C \le 1:

  2. E[satisfied] ≥ ∑C(1−(1−1kC)kC) zC∗\mathbb{E}[\text{satisfied}]\ \ge\ \sum_C \Big(1 - \big(1 - \tfrac1{k_C}\big)^{k_C}\Big)\,z^*_C

    LP rounding, by the bound in the caption above:

  3. E[max⁡] ≥ ∑C34 zC∗ = 34 LP ≥ 34 OPT\mathbb{E}[\max]\ \ge\ \sum_C \tfrac34\,z^*_C\ =\ \tfrac34\,\mathrm{LP}\ \ge\ \tfrac34\,\mathrm{OPT}

    Keep the better one. Its expectation is at least the average of the two, and the table's last column is at least 34\tfrac34 for every kk:

MAX-CUT asks for a split of the vertices into two sides that cuts as many edges as possible. A random split cuts half of them in expectation, and for two decades 12\tfrac12 was essentially the best ratio known. Goemans and Williamson (1995) replaced the LP by a semidefinite program (SDP): relax each side label xi∈{−1,+1}x_i \in \{-1, +1\} to a unit vector vi∈Rnv_i \in \mathbb{R}^n.

max⁡∑ij∈E1−vi⋅vj2subject to∥vi∥=1  for every vertex i\max \sum_{ij \in E} \frac{1 - v_i \cdot v_j}{2} \quad\text{subject to}\quad \norm{v_i} = 1\ \text{ for every vertex } i
With every vi=±e1v_i = \pm e_1 the objective counts cut edges, so the SDP optimum is at least OPT\mathrm{OPT}. It can be solved to within any ε>0\varepsilon > 0 in polynomial time.
DerivationRandom hyperplane rounding
  1. Pr⁡[ ij is cut ] = θijπ\Pr[\,ij \text{ is cut}\,]\ =\ \frac{\theta_{ij}}{\pi}

    Pick a uniformly random direction rr and put vertex ii on side sign⁡(r⋅vi)\operatorname{sign}(r \cdot v_i). Projected onto the plane of viv_i and vjv_j, the direction is uniform on a circle, so the hyperplane separates the two vectors exactly when it falls inside the angle θij\theta_{ij} between them:

  2. θ/π(1−cos⁡θ)/2 ≥ αGW = min⁡0<θ≤π 2π⋅θ1−cos⁡θ ≈ 0.8786\frac{\theta/\pi}{(1 - \cos\theta)/2}\ \ge\ \alpha_{GW}\ =\ \min_{0 < \theta \le \pi}\ \frac{2}{\pi}\cdot\frac{\theta}{1 - \cos\theta}\ \approx\ 0.8786

    Compare with the edge's SDP term, 12(1−cos⁡θij)\tfrac12(1 - \cos\theta_{ij}), at the worst angle:

  3. E[edges cut] ≥ αGW⋅SDP ≥ αGW⋅OPT\mathbb{E}[\text{edges cut}]\ \ge\ \alpha_{GW}\cdot\mathrm{SDP}\ \ge\ \alpha_{GW}\cdot\mathrm{OPT}

    Sum over the edges by linearity of expectation:

python
import math

# alpha_GW: the worst ratio between Pr[cut] = theta/pi and the SDP term (1 - cos theta)/2
N = 10**6
alpha, theta = min((2 / math.pi * t / (1 - math.cos(t)), t)
                   for t in (math.pi * i / N for i in range(1, N + 1)))
print(round(alpha, 5), round(math.degrees(theta), 1))   # 0.87857 133.6

A brute-force minimization over a million angles. The worst angle is about 133.6°133.6°.

The 5-cycle shows that this SDP cannot do much better: consecutive vectors 144°144° apart give an SDP value of 5⋅1−cos⁡144°2≈4.525\cdot\tfrac{1 - \cos 144°}{2} \approx 4.52, while the best cut has 4 edges, a ratio of 0.8840.884. And if the Unique Games Conjecture holds, beating αGW\alpha_{GW} by any constant is NP-hard (Khot, Kindler, Mossel & O'Donnell, 2007, with the "Majority is Stablest" theorem of Mossel, O'Donnell & Oleszkiewicz, 2010): see Hardness of Approximation & the PCP Theorem.

Key takeaways

  • An LP relaxation gives a computable lower bound LP≤OPT\mathrm{LP} \le \mathrm{OPT}; rounding the vertex-cover LP at 12\tfrac12 gives a 2-approximation for weighted vertex cover, and the LP is half-integral (Nemhauser & Trotter).
  • The integrality gap limits every analysis against a relaxation: 2−2/n2 - 2/n on KnK_n for vertex cover, more than 12log⁡2(n+1)\tfrac12\log_2(n+1) for set cover.
  • Primal–dual algorithms raise dual payments until constraints become tight and pay only for tight elements; the ratio is how many times one payment can be counted, 2 for vertex cover and ff for set cover.
  • Randomized rounding with O(log⁡n)O(\log n) rounds, the union bound and Markov's inequality gives O(log⁡n)O(\log n) for set cover; combining two roundings gives 3/43/4 for MAX-SAT, and an SDP with a random hyperplane gives αGW≈0.8786\alpha_{GW} \approx 0.8786 for MAX-CUT.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

The vertex-cover LP has integrality gap 2−2/n2 - 2/n on KnK_n. Which statement follows?

  1. No polynomial-time algorithm can achieve a ratio below 2 for vertex cover
  2. Rounding at 12\tfrac12 returns an optimal cover of every complete graph
  3. On some graphs the LP optimum is smaller than OPT/2\mathrm{OPT}/2
  4. No proof of the form ALG≤α⋅LP\mathrm{ALG} \le \alpha\cdot\mathrm{LP} for all graphs can have α<2\alpha < 2
Show the answer

D. No proof of the form ALG≤α⋅LP\mathrm{ALG} \le \alpha\cdot\mathrm{LP} for all graphs can have α<2\alpha < 2

On KnK_n, ALG≥OPT=(2−2/n) LP\mathrm{ALG} \ge \mathrm{OPT} = (2 - 2/n)\,\mathrm{LP}, so any α\alpha valid for every nn is at least 2. The gap limits this proof technique; whether some other algorithm beats 2 is a different, open question tied to the Unique Games Conjecture.

Question 2

With all weights equal to 1, what does the primal–dual vertex-cover algorithm do?

  1. It solves the LP and rounds at 12\tfrac12
  2. It takes both endpoints of every uncovered edge it meets: the maximal-matching algorithm
  3. It repeatedly takes a vertex of maximum degree
  4. It returns an optimal cover, certified by the dual
Show the answer

B. It takes both endpoints of every uncovered edge it meets: the maximal-matching algorithm

An uncovered edge raises its payment to min⁡(1,1)=1\min(1, 1) = 1, which makes both endpoints tight at once, so both enter the cover; the edges that pay form a maximal matching.

Question 3

In randomized rounding for set cover, an element stays uncovered in one round with probability at most 1/e1/e. With tt independent rounds and nn elements, what does the union bound give for the probability that some element stays uncovered?

  1. At most t/et/e
  2. At most e−nte^{-nt}
  3. At most n e−tn\,e^{-t}
  4. At most (1−1/e)t(1 - 1/e)^t
Show the answer

C. At most n e−tn\,e^{-t}

Each element survives all tt rounds with probability at most e−te^{-t}, by independence across rounds; summing over the nn elements gives n e−tn\,e^{-t}, which is at most 1/n1/n once t≥2ln⁡nt \ge 2\ln n.

Question 4

In the Goemans–Williamson analysis, an edge whose vectors meet at angle θ\theta is cut with probability θ/π\theta/\pi and contributes (1−cos⁡θ)/2(1 - \cos\theta)/2 to the SDP. At which angle is the ratio of the two smallest?

  1. At θ=π\theta = \pi, opposite vectors
  2. As θ→0\theta \to 0, where both quantities vanish
  3. At θ=90°\theta = 90°, where the ratio is 1
  4. At θ≈134°\theta \approx 134°, where the ratio is about 0.87860.8786
Show the answer

D. At θ≈134°\theta \approx 134°, where the ratio is about 0.87860.8786

The ratio 2πθ1−cos⁡θ\frac{2}{\pi}\frac{\theta}{1 - \cos\theta} equals 1 at θ=π\theta = \pi and at 90°90°, tends to infinity as θ→0\theta \to 0 (the SDP term vanishes like θ2\theta^2), and reaches its minimum αGW≈0.8786\alpha_{GW} \approx 0.8786 near 133.6°133.6°.

Further reading

  • D. P. Williamson & D. B. Shmoys, The Design of Approximation Algorithms (Cambridge University Press, 2011), chapters 1, 5, 6 and 7.
  • M. X. Goemans & D. P. Williamson, "Improved approximation algorithms for maximum cut and satisfiability problems using semidefinite programming," Journal of the ACM 42(6) (1995), 1115–1145.
  • M. X. Goemans & D. P. Williamson, "New 3/4-approximation algorithms for the maximum satisfiability problem," SIAM Journal on Discrete Mathematics 7(4) (1994), 656–666.
  • P. Raghavan & C. D. Thompson, "Randomized rounding: a technique for provably good algorithms and algorithmic proofs," Combinatorica 7(4) (1987), 365–374.
  • R. Bar-Yehuda & S. Even, "A linear-time approximation algorithm for the weighted vertex cover problem," Journal of Algorithms 2(2) (1981), 198–203.