TExcelTAD
Home › Approximation Algorithms › Randomized Rounding for Set Cover

Randomized Rounding for Set Cover

Threshold rounding gives an ff-approximation for set cover, which is useless when an element can lie in many sets. Randomized rounding, introduced by Raghavan and Thompson (1987), reads the fractional solution as a probability distribution: a set with xj∗=0.3x^*_j = 0.3 is chosen with probability 0.30.3. One round of sampling costs LP in expectation but leaves some elements uncovered; repeating it O(log⁡n)O(\log n) times covers everything with high probability. The result is an O(log⁡n)O(\log n)-approximation, matching greedy's HnH_n up to the constant, and a method that extends to problems greedy cannot handle.

The algorithm

Weighted set cover with universe UU of nn elements, sets S1,…,SmS_1, \ldots, S_m, weights wjw_j. Let x∗x^* be an optimal solution of

LP=min⁡∑jwjxjs.t.∑j:e∈Sjxj≥1  ∀e∈U,0≤xj≤1.\text{LP} = \min \sum_j w_j x_j \quad \text{s.t.} \quad \sum_{j : e \in S_j} x_j \ge 1 \ \ \forall e \in U, \qquad 0 \le x_j \le 1 .
text
RANDOMIZED-ROUNDING(U, sets, w, c)
1  x* = an optimal LP solution
2  C = empty
3  repeat  t = ceil(c ln n)  times              -- independent rounds
4      for each set j:  add j to C with probability x*_j
5  if some element is uncovered, add for it the cheapest set containing it   -- rarely needed
6  return C

Analysis of one round

Fix an element ee and let Je={j:e∈Sj}J_e = \{j : e \in S_j\}. In one round, ee stays uncovered only if no set of JeJ_e is chosen:

Pr⁡[e uncovered in a round]=∏j∈Je(1−xj∗)≤∏j∈Jee−xj∗=e−∑j∈Jexj∗≤e−1,\Pr[e \text{ uncovered in a round}] = \prod_{j \in J_e} (1 - x^*_j) \le \prod_{j \in J_e} e^{-x^*_j} = e^{-\sum_{j \in J_e} x^*_j} \le e^{-1},

using 1−y≤e−y1 - y \le e^{-y} and the LP constraint for ee. The expected cost of a round is ∑jwjxj∗=LP\sum_j w_j x^*_j = \text{LP} by linearity of expectation.

Theorem. With t=⌈cln⁡n⌉t = \lceil c \ln n \rceil rounds (c≥2c \ge 2), the sets chosen in lines 3 and 4 cover every element with probability at least 1−n1−c1 - n^{1-c}, and their expected cost is at most t⋅LP=O(log⁡n)⋅OPTt \cdot \text{LP} = O(\log n) \cdot \text{OPT}.

Proof. Rounds are independent, so Pr⁡[e uncovered after t rounds]≤e−t≤n−c\Pr[e \text{ uncovered after } t \text{ rounds}] \le e^{-t} \le n^{-c}. By the union bound over the nn elements, the probability that any element is uncovered is at most n1−cn^{1-c}. The cost of the union is at most the sum of the costs of the rounds, whose expectation is t⋅LPt \cdot \text{LP}. □\square

To turn "expected cost" and "high probability" into one statement: by Markov's inequality the cost exceeds 4t⋅LP4t \cdot \text{LP} with probability at most 14\frac{1}{4}, so with probability at least 34−n1−c\frac{3}{4} - n^{1-c} the result is a cover of cost at most 4t⋅LP4t \cdot \text{LP}. If it is not, run the algorithm again; the expected number of attempts is a constant. Line 5 is a cheaper safety net: each fix-up costs at most OPT (the cheapest set containing ee is at most the weight of the optimal set containing ee), and is needed with probability at most n1−cn^{1-c} per run, so it adds at most n⋅n−c⋅OPTn \cdot n^{-c} \cdot \text{OPT} to the expectation. Either way, the algorithm is an O(log⁡n)O(\log n)-approximation.

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

rng = random.Random(1)
n, m = 20, 14
sets = [set(rng.sample(range(n), rng.randint(3, 7))) for _ in range(m)]
for e in range(n):
    if not any(e in S for S in sets):
        sets[rng.randrange(m)].add(e)
w = [rng.randint(2, 9) for _ in range(m)]

A = [[-1 if e in S else 0 for S in sets] for e in range(n)]
lp = linprog(w, A_ub=A, b_ub=[-1] * n, bounds=[(0, 1)] * m, method="highs")
x = [float(v) for v in lp.x]
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("LP =", round(float(lp.fun), 3), " OPT =", opt, " fractional sets:", sum(0 < v < 1 for v in x))

def rounding(x, rounds, rng):
    C = set()
    for _ in range(rounds):
        C |= {j for j in range(m) if rng.random() < x[j]}
    covered, fixes = set().union(*(sets[j] for j in C)), 0
    for e in range(n):                               # line 5: fix-ups
        if e not in covered:
            j = min((j for j in range(m) if e in sets[j]), key=lambda j: w[j])
            C.add(j)
            covered |= sets[j]
            fixes += 1
    return sum(w[j] for j in C), fixes

t = math.ceil(2 * math.log(n))
for rounds in [1, 3, t]:
    results = [rounding(x, rounds, rng) for _ in range(200)]
    avg = sum(c for c, _ in results) / len(results)
    needed = sum(f > 0 for _, f in results)
    print(f"{rounds:2} rounds: average cost {avg:6.2f} ({avg / opt:.2f} x OPT), runs that needed fix-ups {needed:3} of 200")
LP = 28.333  OPT = 31  fractional sets: 6
 1 rounds: average cost  36.17 (1.17 x OPT), runs that needed fix-ups 143 of 200
 3 rounds: average cost  41.99 (1.35 x OPT), runs that needed fix-ups  18 of 200
 6 rounds: average cost  46.80 (1.51 x OPT), runs that needed fix-ups   1 of 200

With one round the sampled sets miss elements most of the time and the fix-ups do much of the work; with t=⌈2ln⁡n⌉t = \lceil 2 \ln n \rceil rounds misses are rare, at the price of paying several rounds. The bound t⋅LPt \cdot \text{LP} is loose here because many sets are chosen in several rounds but paid only once.

Scaling instead of repeating

An equivalent and slightly cheaper version chooses set jj once, with probability min⁡(1,αxj∗)\min(1, \alpha x^*_j) for α=ln⁡n+O(1)\alpha = \ln n + O(1). The same computation gives Pr⁡[e uncovered]≤e−α\Pr[e \text{ uncovered}] \le e^{-\alpha}, about 1n\frac{1}{n}, and expected cost at most α⋅LP\alpha \cdot \text{LP}. Careful versions of this analysis (with alterations and fix-ups) give (1+o(1))ln⁡n(1 + o(1))\ln n, the same leading constant as greedy and as the hardness threshold.

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

rng = random.Random(1)
n, m = 20, 14
sets = [set(rng.sample(range(n), rng.randint(3, 7))) for _ in range(m)]
for e in range(n):
    if not any(e in S for S in sets):
        sets[rng.randrange(m)].add(e)
w = [rng.randint(2, 9) for _ in range(m)]
A = [[-1 if e in S else 0 for S in sets] for e in range(n)]
x = [float(v) for v in linprog(w, A_ub=A, b_ub=[-1] * n, bounds=[(0, 1)] * m, method="highs").x]

# exact probability that each element is missed when set j is taken with probability min(1, alpha x_j)
for alpha in [1, 2, math.log(n), math.log(n) + 2]:
    miss = [math.prod(1 - min(1, alpha * x[j]) for j in range(m) if e in sets[j]) for e in range(n)]
    cost = sum(w[j] * min(1, alpha * x[j]) for j in range(m))
    print(f"alpha = {alpha:5.2f}: expected cost {cost:6.2f}, worst miss probability {max(miss):.4f} <= e^-alpha = {math.exp(-alpha):.4f}")
alpha =  1.00: expected cost  28.33, worst miss probability 0.2963 <= e^-alpha = 0.3679
alpha =  2.00: expected cost  40.67, worst miss probability 0.0370 <= e^-alpha = 0.1353
alpha =  3.00: expected cost  47.97, worst miss probability 0.0000 <= e^-alpha = 0.0500
alpha =  5.00: expected cost  48.00, worst miss probability 0.0000 <= e^-alpha = 0.0068

These numbers are exact, not sampled: the probability of missing element ee is a product over the sets containing it. The bound e−αe^{-\alpha} is respected element by element, and is often far from tight because many elements have LP coverage well above 1 once multiplied by α\alpha.

Derandomization

The method of conditional expectations (The Method of Conditional Expectations) turns the scaled rounding into a deterministic algorithm. Define the pessimistic estimator Φ=costα⋅LP+2∑ePr⁡[e uncovered]\Phi = \frac{\text{cost}}{\alpha \cdot \text{LP}} + 2\sum_e \Pr[e \text{ uncovered}]. With α=ln⁡n+1\alpha = \ln n + 1 its expectation is at most 1+2ne−α=1+2e<21 + 2n e^{-\alpha} = 1 + \frac{2}{e} < 2. Decide the sets one by one, each time choosing the option (take or skip) that does not increase the conditional expectation of Φ\Phi; both terms are easy to compute exactly given the decisions so far, the second as a product over the undecided sets. At the end nothing is random: Φ<2\Phi < 2, the second term is twice the number of uncovered elements, so it is 0, and the cost is below 2α⋅LP=O(log⁡n)⋅LP2\alpha \cdot \text{LP} = O(\log n) \cdot \text{LP}.

How good can rounding be?

The set cover LP has an integrality gap of Ω(log⁡n)\Omega(\log n) (Integrality Gaps), so no rounding of this LP beats O(log⁡n)O(\log n) by more than a constant factor; Dinur and Steurer (2014) showed that no polynomial algorithm whatsoever achieves (1−ε)ln⁡n(1 - \varepsilon)\ln n unless P = NP. The real power of randomized rounding appears where greedy has no natural analogue: problems with packing and covering constraints mixed, such as integer multicommodity flow and congestion minimization (route each demand on one path so that the most loaded edge carries as little as possible). There Raghavan and Thompson's analysis with Chernoff bounds gives congestion O(log⁡nlog⁡log⁡n)O(\frac{\log n}{\log \log n}) times the LP optimum, the bound that gave the method its name.

Test yourself

Why is the probability that one round misses element ee at most 1e\frac{1}{e}?

  1. Because each set has probability at most 12\frac{1}{2}
  2. It equals ∏j(1−xj∗)\prod_j (1 - x^*_j) over the sets containing ee, which is at most e−∑jxj∗≤e−1e^{-\sum_j x^*_j} \le e^{-1} by 1−y≤e−y1 - y \le e^{-y} and the LP constraint
  3. By Markov's inequality
  4. Because the rounds are dependent

How many independent rounds make all nn elements covered with probability at least 1−1n1 - \frac{1}{n}?

  1. One round
  2. About 2ln⁡n2\ln n rounds, so each element is missed with probability at most n−2n^{-2}, then the union bound
  3. nn rounds
  4. n\sqrt{n} rounds

What is the expected cost of one round of randomized rounding?

  1. OPT
  2. Exactly the LP value ∑jwjxj∗\sum_j w_j x^*_j, by linearity of expectation
  3. HnH_n times LP
  4. It cannot be computed