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 , weights ; find a cover of minimum total weight. As an integer program and its relaxation:
Every cover is LP-feasible, so . The LP can be solved in polynomial time (The Ellipsoid Method for the theory, simplex or interior point in practice).
Threshold rounding
ROUND-VC(G, w)
1 x* = an optimal solution of the LP
2 return C = { v : x*_v >= 1/2 }Theorem (Hochbaum, 1982). is a vertex cover of weight at most .
Proof. For each edge , , so the larger of the two is at least and that endpoint is in . For the weight, each has , so .
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.
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- 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 , and .
Half-integrality
Theorem (Nemhauser and Trotter, 1974). Every vertex of the polytope has all coordinates in .
Proof. Let be a feasible point with a coordinate outside . We may assume (coordinates above 1 at a vertex would be lowered by a cheaper feasible point; formally, a vertex has because otherwise are both feasible). Let and ; at least one is non-empty. For a small define and . Both are feasible: an edge with slack keeps it for small , and a tight edge has either both endpoints at (unchanged), or both integral (unchanged), or one endpoint in and the other in (the changes cancel). Since with , is not a vertex.
Nemhauser and Trotter (1975) proved more: there is an optimal cover that contains every vertex with and no vertex with . Only the half-valued vertices remain undecided, a fact used for kernelization in parameterized algorithms (an instance asking for a cover of size shrinks to at most undecided vertices).
The factor 2 is the best possible for this relaxation: on the complete graph , setting gives while , a gap of (Integrality Gaps).
Set cover with bounded frequency
The same rounding works for weighted set cover when each element lies in at most sets: solve subject to , , and take every set with . Each element's at most variables sum to at least 1, so one of them is at least : the result is a cover. Each chosen set costs at most , so the cover costs at most . Vertex cover is the case .
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 , and rounding at takes nine of the ten sets: 53 against an optimum of 31, well within the guarantee but a reminder that the guarantee is a worst-case bound and rounding at a low threshold is wasteful. When is large, the threshold is too generous; randomized rounding gives 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 , subtracts 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 give a vertex cover?
- Because the LP optimum is integral
- For each edge, , so at least one endpoint has value at least
- Because every vertex has
- Because of complementary slackness
What does the half-integrality theorem of Nemhauser and Trotter say?
- The LP optimum is always integral
- Every vertex of the vertex cover polytope has coordinates in
- The integrality gap is
- Every vertex cover has half the vertices
For set cover where every element lies in at most sets, what does threshold rounding at guarantee?
- An -approximation
- An -approximation
- A 2-approximation for every
- An optimal cover
Which instance shows that no rounding of the vertex cover LP can guarantee better than about 2?
- A single edge
- The complete graph : LP , OPT
- A star
- A bipartite graph