Sub topic 12
LP Relaxation and Rounding for Weighted Vertex Cover
This chapter assumes you know what a linear program (LP) is, that LPs can be solved in polynomial time, and how the matching-based 2-approximation for unweighted vertex cover works. It also assumes you can read Python that uses scipy.
Why Matching Fails With Weights
In weighted vertex cover, each vertex i has a weight w_i ≥ 0. The goal is a cover of minimum total weight. The maximal-matching algorithm ignores weights entirely. It can pick a vertex of weight 1000 when a neighbor of weight 1 would cover the same edge. To handle weights, we need a lower bound on OPT that takes weights into account. A linear program gives us one.
The Integer Program and Its Relaxation
Give each vertex a variable x_i, where 1 means "in the cover" and 0 means "not in it":
- minimize Σ wi xi
- subject to xu + xv ≥ 1 for every edge (u, v)
- x_i ∈ {0, 1}
This integer program is exactly vertex cover, so it is NP-hard. The LP relaxation replaces xi ∈ {0, 1} with 0 ≤ xi ≤ 1. Every integer cover is still feasible, so the LP optimum LP* satisfies LP* ≤ OPT. That inequality is the lower bound we were looking for.
Threshold Rounding
The LP may return fractional values such as xi = 0.5. Deterministic rounding converts them into a 0/1 solution with a fixed rule: put vertex i in the cover when xi ≥ 1/2.
from scipy.optimize import linprog
def lp_vertex_cover(n, edges, weights):
A_ub = []
for u, v in edges:
row = [0] * n
row[u] = -1
row[v] = -1
A_ub.append(row)
b_ub = [-1] * len(edges)
res = linprog(c=weights, A_ub=A_ub, b_ub=b_ub,
bounds=[(0, 1)] * n, method="highs")
return [i for i in range(n) if res.x[i] >= 0.5 - 1e-9]
print(lp_vertex_cover(4, [(0, 1), (1, 2), (2, 3)], [1, 3, 1, 2]))linprog only accepts constraints of the form A x ≤ b, so each constraint xu + xv ≥ 1 is written as −xu − xv ≤ −1. The 1e-9 tolerance keeps floating-point error from turning 0.4999999 into a missed vertex. On this path graph the output is [0, 2], with weight 2.
The Proof
Feasibility. For each edge, xu + xv ≥ 1, so at least one of the two values is ≥ 1/2. That endpoint gets picked, so every edge is covered.
Cost. Every picked vertex has xi ≥ 1/2, which means 1 ≤ 2xi. So:
cost = Σ over picked i of wi ≤ Σ over all i of 2 wi x_i = 2 · LP* ≤ 2 · OPT.
Common Errors
| Mistake | Consequence |
|---|---|
| Rounding at a threshold above 1/2 | An edge with x_u = x_v = 1/2 stays uncovered |
| Comparing to OPT directly | You can't compute OPT. The proof must go through LP* |
| Writing ≥ constraints straight into `A_ub` | The LP solves the wrong problem, often giving all zeros |
| Expecting rounding to beat 2 in general | The integrality gap prevents it (see below) |
Exercise
On a triangle with unit weights, what is LP*, what does threshold rounding return, and how does it compare to OPT?
Show answer
Setting all x_i = 1/2 is feasible with value 1.5, and it is optimal, so LP = 1.5. Rounding picks all three vertices, for cost 3 = 2 · LP. OPT is 2, so the rounded cover is 1.5 times optimal, within the proven factor of 2.
Exercise
Why is the LP solution x_i = 1 for all i never returned as the optimum when weights are positive and some vertex can be lowered?
Show answer
The LP minimizes Σ wi xi. If some x_i can be lowered without breaking any edge constraint, doing so reduces the objective, so the solver lowers it. The optimal LP solution is therefore minimal with respect to the edge constraints.