TExcelTAD
Home › Approximation Algorithms › Rounding the Vertex Cover LP

Rounding the Vertex Cover LP

The matching algorithm of Vertex Cover from a Maximal Matching cannot handle weights: a cheap vertex and an expensive one look the same to it. Linear programming handles weights without effort. Solve the LP relaxation, then round its fractional solution to an integral one, losing a bounded factor. This lesson does it for weighted vertex cover and set cover, and explains the special structure, half-integrality, that makes vertex cover's LP so well behaved.

The relaxation

Weighted vertex cover: a graph G=(V,E)G = (V, E), weights wv≥0w_v \ge 0; find a cover of minimum total weight. As an integer program and its relaxation:

min⁡∑v∈Vwvxvs.t.xu+xv≥1  ∀uv∈E,xv∈{0,1}  (IP)orxv≥0  (LP).\min \sum_{v \in V} w_v x_v \quad \text{s.t.} \quad x_u + x_v \ge 1 \ \ \forall uv \in E, \qquad x_v \in \{0, 1\} \ \ (\text{IP}) \quad \text{or} \quad x_v \ge 0 \ \ (\text{LP}) .

Every cover is LP-feasible, so LP≤OPT\text{LP} \le \text{OPT}. The LP can be solved in polynomial time (The Ellipsoid Method for the theory, simplex or interior point in practice).

Threshold rounding

text
ROUND-VC(G, w)
1  x* = an optimal solution of the LP
2  return C = { v : x*_v >= 1/2 }

Theorem (Hochbaum, 1982). CC is a vertex cover of weight at most 2 LP≤2 OPT2\,\text{LP} \le 2\,\text{OPT}.

Proof. For each edge uvuv, xu∗+xv∗≥1x^*_u + x^*_v \ge 1, so the larger of the two is at least 12\frac{1}{2} and that endpoint is in CC. For the weight, each v∈Cv \in C has 2xv∗≥12x^*_v \ge 1, so w(C)=∑v∈Cwv≤∑v∈C2wvxv∗≤2∑vwvxv∗=2 LPw(C) = \sum_{v \in C} w_v \le \sum_{v \in C} 2 w_v x^*_v \le 2 \sum_v w_v x^*_v = 2\,\text{LP}. □\square

The same proof is the template for every rounding algorithm: show that rounding keeps feasibility, and bound the cost of each rounded variable by a multiple of its fractional cost.

python · try it yourself
import random
from itertools import combinations
from scipy.optimize import linprog

def lp_cover(n, E, w):
    A = [[-1 if v in e else 0 for v in range(n)] for e in E]
    res = linprog(w, A_ub=A, b_ub=[-1] * len(E), bounds=[(0, None)] * n, method="highs-ds")
    return [round(float(x), 6) + 0.0 for x in res.x], float(res.fun)

def opt_cover(n, E, w):
    best = sum(w)
    for k in range(n + 1):
        for C in combinations(range(n), k):
            if all(u in C or v in C for u, v in E):
                best = min(best, sum(w[v] for v in C))
    return best

rng = random.Random(12)
print(" n  |E|      LP  rounded  OPT  rounded/OPT  values in x*")
for _ in range(6):
    n = rng.randint(8, 11)
    E = [(u, v) for u in range(n) for v in range(u + 1, n) if rng.random() < 0.5]
    w = [rng.randint(1, 10) for _ in range(n)]
    x, lp = lp_cover(n, E, w)
    C = [v for v in range(n) if x[v] >= 0.5]
    assert all(u in C or v in C for u, v in E)
    rounded, opt = sum(w[v] for v in C), opt_cover(n, E, w)
    print(f"{n:2} {len(E):4} {lp:7.1f} {rounded:8} {opt:4} {rounded / opt:12.3f}  {sorted(set(x))}")
 n  |E|      LP  rounded  OPT  rounded/OPT  values in x*
11   23    31.0       55   32        1.719  [0.0, 0.5, 1.0]
 8   19    19.0       38   19        2.000  [0.5]
 8   11    20.0       28   20        1.400  [0.0, 0.5, 1.0]
11   24    26.5       48   30        1.600  [0.0, 0.5, 1.0]
10   22    25.5       51   31        1.645  [0.5]
 8    9    21.0       21   21        1.000  [0.0, 1.0]

Rounding loses up to the full factor 2. In the second row the LP value equals OPT, but the solver returned the all-12\frac{1}{2} point, another optimal vertex, and rounding takes every vertex. The last column shows something remarkable: the LP optimum (a vertex of the polytope, as returned by the dual simplex method) only ever uses the values 00, 12\frac{1}{2} and 11.

Half-integrality

Theorem (Nemhauser and Trotter, 1974). Every vertex of the polytope {x≥0:xu+xv≥1 ∀uv∈E}\{x \ge 0 : x_u + x_v \ge 1 \ \forall uv \in E\} has all coordinates in {0,12,1}\{0, \frac{1}{2}, 1\}.

Proof. Let xx be a feasible point with a coordinate outside {0,12,1}\{0, \frac{1}{2}, 1\}. We may assume x≤1x \le 1 (coordinates above 1 at a vertex would be lowered by a cheaper feasible point; formally, a vertex has xv≤1x_v \le 1 because otherwise x±εevx \pm \varepsilon e_v are both feasible). Let V+={v:12<xv<1}V^+ = \{v : \frac{1}{2} < x_v < 1\} and V−={v:0<xv<12}V^- = \{v : 0 < x_v < \frac{1}{2}\}; at least one is non-empty. For a small ε>0\varepsilon > 0 define y=x+ε(1V+−1V−)y = x + \varepsilon(\mathbf{1}_{V^+} - \mathbf{1}_{V^-}) and z=x−ε(1V+−1V−)z = x - \varepsilon(\mathbf{1}_{V^+} - \mathbf{1}_{V^-}). Both are feasible: an edge with slack keeps it for small ε\varepsilon, and a tight edge xu+xv=1x_u + x_v = 1 has either both endpoints at 12\frac{1}{2} (unchanged), or both integral (unchanged), or one endpoint in V+V^+ and the other in V−V^- (the changes cancel). Since x=12(y+z)x = \frac{1}{2}(y + z) with y≠zy \ne z, xx is not a vertex. □\square

Nemhauser and Trotter (1975) proved more: there is an optimal cover that contains every vertex with xv∗=1x^*_v = 1 and no vertex with xv∗=0x^*_v = 0. Only the half-valued vertices remain undecided, a fact used for kernelization in parameterized algorithms (an instance asking for a cover of size kk shrinks to at most 2k2k undecided vertices).

The factor 2 is the best possible for this relaxation: on the complete graph KnK_n, setting xv=12x_v = \frac{1}{2} gives LP=n2\text{LP} = \frac{n}{2} while OPT=n−1\text{OPT} = n - 1, a gap of 2−2n2 - \frac{2}{n} (Integrality Gaps).

Set cover with bounded frequency

The same rounding works for weighted set cover when each element lies in at most ff sets: solve min⁡∑jwjxj\min \sum_j w_j x_j subject to ∑j:e∈Sjxj≥1\sum_{j : e \in S_j} x_j \ge 1, x≥0x \ge 0, and take every set with xj∗≥1fx^*_j \ge \frac{1}{f}. Each element's at most ff variables sum to at least 1, so one of them is at least 1f\frac{1}{f}: the result is a cover. Each chosen set costs at most fwjxj∗f w_j x^*_j, so the cover costs at most f⋅LPf \cdot \text{LP}. Vertex cover is the case f=2f = 2.

python · try it yourself
import random
from itertools import combinations
from scipy.optimize import linprog

rng = random.Random(8)
n, m = 14, 10
sets = [set() for _ in range(m)]
for e in range(n):                                   # every element in 2 or 3 sets
    for j in rng.sample(range(m), rng.choice([2, 3])):
        sets[j].add(e)
w = [rng.randint(1, 9) for _ in range(m)]
f = max(sum(e in S for S in sets) for e in range(n))

A = [[-1 if e in sets[j] else 0 for j in range(m)] for e in range(n)]
res = linprog(w, A_ub=A, b_ub=[-1] * n, bounds=[(0, None)] * m, method="highs")
x = [float(v) for v in res.x]
chosen = [j for j in range(m) if x[j] >= 1 / f - 1e-9]
cost = sum(w[j] for j in chosen)
opt = min(sum(w[j] for j in C) for k in range(1, m + 1) for C in combinations(range(m), k)
          if set().union(*(sets[j] for j in C)) == set(range(n)))
print("frequency f =", f, " LP values used:", sorted({round(v, 3) + 0.0 for v in x}))
print("LP =", round(float(res.fun), 3), " rounded cover", chosen, "cost", cost, " OPT", opt)
print("cost <= f * LP:", cost <= f * res.fun + 1e-9, f"({cost} <= {f * res.fun:.3f})")
frequency f = 3  LP values used: [0.0, 0.333, 0.667, 1.0]
LP = 29.667  rounded cover [0, 1, 2, 3, 5, 6, 7, 8, 9] cost 53  OPT 31
cost <= f * LP: True (53 <= 89.000)

The LP solution uses thirds, as it may for f=3f = 3, and rounding at 13\frac{1}{3} takes nine of the ten sets: 53 against an optimum of 31, well within the guarantee 3⋅LP=893 \cdot \text{LP} = 89 but a reminder that the guarantee is a worst-case bound and rounding at a low threshold is wasteful. When ff is large, the threshold 1f\frac{1}{f} is too generous; randomized rounding gives O(log⁡n)O(\log n) instead (Randomized Rounding for Set Cover).

Rounding without solving the LP

Solving an LP is polynomial but not free. Two cheaper routes reach the same factor 2 for weighted vertex cover:

  • The primal-dual method raises dual edge variables until vertex constraints become tight and takes the tight vertices; it runs in linear time (The Primal-Dual Method for Vertex Cover).
  • The local-ratio method (Bar-Yehuda and Even, 1985) repeatedly picks an edge uvuv, subtracts min⁡(wu,wv)\min(w_u, w_v) from both weights, and takes the vertices whose weight reaches 0. It is the primal-dual method in a different language.

Note: The LP is solved here by SciPy's HiGHS. method="highs-ds" (dual simplex) returns a vertex of the polytope, so the half-integrality theorem applies to its answer. An interior-point method may return a point in the middle of an optimal face, with values such as 0.37; the threshold rounding is still correct for it, since the proof only uses feasibility and optimality.

Test yourself

Why does taking every vertex with xv∗≥12x^*_v \ge \frac{1}{2} give a vertex cover?

  1. Because the LP optimum is integral
  2. For each edge, xu∗+xv∗≥1x^*_u + x^*_v \ge 1, so at least one endpoint has value at least 12\frac{1}{2}
  3. Because every vertex has xv∗≥12x^*_v \ge \frac{1}{2}
  4. Because of complementary slackness

What does the half-integrality theorem of Nemhauser and Trotter say?

  1. The LP optimum is always integral
  2. Every vertex of the vertex cover polytope has coordinates in {0,12,1}\{0, \frac{1}{2}, 1\}
  3. The integrality gap is 12\frac{1}{2}
  4. Every vertex cover has half the vertices

For set cover where every element lies in at most ff sets, what does threshold rounding at 1f\frac{1}{f} guarantee?

  1. An HnH_n-approximation
  2. An ff-approximation
  3. A 2-approximation for every ff
  4. An optimal cover

Which instance shows that no rounding of the vertex cover LP can guarantee better than about 2?

  1. A single edge
  2. The complete graph KnK_n: LP n2\frac{n}{2}, OPT n−1n - 1
  3. A star
  4. A bipartite graph