TExcelTAD
Home › Approximation Algorithms › MAX-SAT: Random Assignments, LP Rounding and the Better of Two

MAX-SAT: Random Assignments, LP Rounding and the Better of Two

MAX-SAT: given a CNF formula with clauses C1,…,CmC_1, \ldots, C_m over variables x1,…,xnx_1, \ldots, x_n and weights wj≥0w_j \ge 0, find an assignment maximizing the total weight of satisfied clauses. It is NP-hard even when every clause has two literals. This lesson develops three algorithms, each with a clean analysis, and shows that two weak ones combine into a strong one: the uniformly random assignment is good for long clauses, LP rounding is good for short ones, and the better of the two achieves 34\frac{3}{4} on every formula (Goemans and Williamson, 1994).

Throughout, clauses contain no repeated variable and no complementary pair, and kjk_j is the length of clause jj. Since MAX-SAT is a maximization problem, an α\alpha-approximation satisfies weight at least α⋅OPT\alpha \cdot \text{OPT} with α≤1\alpha \le 1.

The random assignment

Set every variable true with probability 12\frac{1}{2}, independently. Clause jj fails only if all its kjk_j literals are false:

Pr⁡[Cj satisfied]=1−2−kj≥12,E[W]=∑jwj(1−2−kj)≥12∑jwj≥12 OPT.\Pr[C_j \text{ satisfied}] = 1 - 2^{-k_j} \ge \frac{1}{2}, \qquad \mathbb{E}[W] = \sum_j w_j \left(1 - 2^{-k_j}\right) \ge \frac{1}{2}\sum_j w_j \ge \frac{1}{2}\,\text{OPT} .

This is a 12\frac{1}{2}-approximation in expectation, derandomized by the method of conditional expectations into Johnson's algorithm (1974); for formulas whose clauses all have exactly 3 literals it gives 78\frac{7}{8}, which is optimal unless P = NP (Håstad, 2001). See The Method of Conditional Expectations. The weak spot is clauses of length 1: a unit clause is satisfied only half the time.

The LP relaxation and randomized rounding

Let PjP_j and NjN_j be the variables appearing positively and negatively in clause jj. Variables yi∈[0,1]y_i \in [0, 1] model the truth values and zj∈[0,1]z_j \in [0, 1] whether clause jj is satisfied:

max⁡∑jwjzjs.t.∑i∈Pjyi+∑i∈Nj(1−yi)≥zj  ∀j,0≤yi,zj≤1.\max \sum_j w_j z_j \quad \text{s.t.} \quad \sum_{i \in P_j} y_i + \sum_{i \in N_j} (1 - y_i) \ge z_j \ \ \forall j, \qquad 0 \le y_i, z_j \le 1 .

Every assignment gives a feasible integral point, so LP≥OPT\text{LP} \ge \text{OPT}: here the LP is an upper bound. Rounding sets xix_i true with probability yi∗y^*_i, independently.

Lemma. Clause jj is satisfied with probability at least (1−(1−1kj)kj)zj∗≥(1−1e)zj∗\left(1 - \left(1 - \frac{1}{k_j}\right)^{k_j}\right) z^*_j \ge \left(1 - \frac{1}{e}\right) z^*_j.

Proof. Rename variables so that every literal of the clause is positive (replace yiy_i by 1−yi1 - y_i for negated ones); the clause becomes x1∨⋯∨xkx_1 \vee \cdots \vee x_k with ∑iyi≥z\sum_i y_i \ge z. It fails with probability ∏i(1−yi)\prod_i (1 - y_i). By the inequality of arithmetic and geometric means,

∏i=1k(1−yi)≤(1−1k∑iyi)k≤(1−zk)k.\prod_{i=1}^k (1 - y_i) \le \left(1 - \frac{1}{k}\sum_i y_i\right)^k \le \left(1 - \frac{z}{k}\right)^k .

The function g(z)=1−(1−zk)kg(z) = 1 - (1 - \frac{z}{k})^k is concave on [0,1][0, 1] with g(0)=0g(0) = 0, so it lies above the chord: g(z)≥g(1)⋅z=(1−(1−1k)k)zg(z) \ge g(1) \cdot z = \left(1 - (1 - \frac{1}{k})^k\right) z. Finally (1−1k)k<1e(1 - \frac{1}{k})^k < \frac{1}{e} for every k≥1k \ge 1. □\square

Summing, E[W]≥(1−1e)∑jwjzj∗=(1−1e) LP≥(1−1e) OPT≈0.632 OPT\mathbb{E}[W] \ge (1 - \frac{1}{e})\sum_j w_j z^*_j = (1 - \frac{1}{e})\,\text{LP} \ge (1 - \frac{1}{e})\,\text{OPT} \approx 0.632\,\text{OPT}. Rounding is perfect for unit clauses (k=1k = 1 gives factor 1) and weakest for long ones, the opposite of the random assignment.

The better of the two

Write pk=1−2−kp_k = 1 - 2^{-k} and qk=1−(1−1k)kq_k = 1 - (1 - \frac{1}{k})^k. Run both algorithms and keep the better assignment. Its expected weight is at least the average of the two expectations:

E[max⁡(W1,W2)]≥12(E[W1]+E[W2])≥∑jwjzj∗⋅pkj+qkj2,\mathbb{E}[\max(W_1, W_2)] \ge \frac{1}{2}\left(\mathbb{E}[W_1] + \mathbb{E}[W_2]\right) \ge \sum_j w_j z^*_j \cdot \frac{p_{k_j} + q_{k_j}}{2},

using pk≥pkzj∗p_k \ge p_k z^*_j. The program tabulates the average.

python · try it yourself
from math import e

print(" k  uniform p_k   LP rounding q_k   average")
for k in range(1, 8):
    p = 1 - 2 ** -k
    q = 1 - (1 - 1 / k) ** k
    print(f"{k:2} {p:12.4f} {q:17.4f} {(p + q) / 2:9.4f}")
print("limits: p -> 1, q -> 1 - 1/e =", round(1 - 1 / e, 4), " average ->", round((2 - 1 / e) / 2, 4))
 k  uniform p_k   LP rounding q_k   average
 1       0.5000            1.0000    0.7500
 2       0.7500            0.7500    0.7500
 3       0.8750            0.7037    0.7894
 4       0.9375            0.6836    0.8105
 5       0.9688            0.6723    0.8205
 6       0.9844            0.6651    0.8247
 7       0.9922            0.6601    0.8261
limits: p -> 1, q -> 1 - 1/e = 0.6321  average -> 0.8161

Theorem (Goemans and Williamson, 1994). The better of the random assignment and LP rounding is a 34\frac{3}{4}-approximation for MAX-SAT.

Proof. pk+qk2≥34\frac{p_k + q_k}{2} \ge \frac{3}{4} for every kk: equality for k=1k = 1 (12\frac{1}{2} and 1) and k=2k = 2 (34\frac{3}{4} and 34\frac{3}{4}), and for k≥3k \ge 3, pk≥78p_k \ge \frac{7}{8} and qk>1−1eq_k > 1 - \frac{1}{e}, so the average exceeds 0.875+0.6322>0.75\frac{0.875 + 0.632}{2} > 0.75. Hence E[max⁡(W1,W2)]≥34 LP≥34 OPT\mathbb{E}[\max(W_1, W_2)] \ge \frac{3}{4}\,\text{LP} \ge \frac{3}{4}\,\text{OPT}. □\square

The guarantee is relative to the LP, and the LP has integrality gap exactly 34\frac{3}{4}: the four clauses x1∨x2x_1 \vee x_2, xˉ1∨x2\bar x_1 \vee x_2, x1∨xˉ2x_1 \vee \bar x_2, xˉ1∨xˉ2\bar x_1 \vee \bar x_2 have OPT=3\text{OPT} = 3 but the LP sets y=12y = \frac{1}{2} and z=1z = 1 everywhere for value 4. So no analysis against this LP can prove more than 34\frac{3}{4}.

Computing the expectations exactly

The program builds a random weighted formula with clauses of length 1 to 3, solves the LP, and computes the exact expected weight of both algorithms (a product formula per clause, no sampling), next to the optimum by brute force.

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

rng = random.Random(4)
n, m = 10, 30
clauses = []
for _ in range(m):
    k = rng.choice([1, 1, 2, 2, 3])
    vs = rng.sample(range(n), k)
    clauses.append(([(v, rng.random() < 0.5) for v in vs], rng.randint(1, 5)))   # (variable, negated)

# LP variables: y_0..y_{n-1}, z_0..z_{m-1};  maximize sum w_j z_j  ->  minimize -sum w_j z_j
c = [0] * n + [-w for _, w in clauses]
A, b = [], []
for j, (lits, w) in enumerate(clauses):            # z_j - sum_pos y_i + sum_neg y_i <= #neg
    row = [0] * (n + m)
    row[n + j] = 1
    for v, neg in lits:
        row[v] += 1 if neg else -1
    A.append(row)
    b.append(sum(neg for _, neg in lits))
res = linprog(c, A_ub=A, b_ub=b, bounds=[(0, 1)] * (n + m), method="highs")
y = [float(v) for v in res.x[:n]]
lp = -float(res.fun)

def expected(prob_true):
    total = 0.0
    for lits, w in clauses:
        fail = 1.0
        for v, neg in lits:
            fail *= prob_true[v] if neg else 1 - prob_true[v]
        total += w * (1 - fail)
    return total

def weight(assign):
    return sum(w for lits, w in clauses if any(assign[v] != neg for v, neg in lits))

opt = max(weight(a) for a in product([False, True], repeat=n))
r, l = expected([0.5] * n), expected(y)
print(f"total weight {sum(w for _, w in clauses)}, OPT {opt}, LP {lp:.2f}")
print(f"E[random]      = {r:6.2f}  ({r / opt:.3f} OPT)")
print(f"E[LP rounding] = {l:6.2f}  ({l / opt:.3f} OPT)")
print(f"average        = {(r + l) / 2:6.2f}  >= 3/4 LP = {0.75 * lp:.2f}")
total weight 95, OPT 85, LP 85.50
E[random]      =  67.75  (0.797 OPT)
E[LP rounding] =  74.75  (0.879 OPT)
average        =  71.25  >= 3/4 LP = 64.12

Both expectations can be turned into deterministic assignments by the method of conditional expectations, fixing variables one at a time, since the conditional expectation is again a sum of per-clause product formulas.

One rounding function for 3/4

Goemans and Williamson also showed that a single rounding achieves 34\frac{3}{4}: set xix_i true with probability f(yi∗)f(y^*_i) for any function with 1−4−y≤f(y)≤4y−11 - 4^{-y} \le f(y) \le 4^{y - 1} on [0,1][0, 1], for example f(y)=1−4−yf(y) = 1 - 4^{-y}. A positive literal is then false with probability 1−f(yi)≤4−yi1 - f(y_i) \le 4^{-y_i} and a negative one with probability f(yi)≤4−(1−yi)f(y_i) \le 4^{-(1 - y_i)}, so a clause fails with probability at most 4−zj∗4^{-z^*_j}, and the concave function 1−4−z1 - 4^{-z} lies above its chord: 1−4−z≥34z1 - 4^{-z} \ge \frac{3}{4}z on [0,1][0, 1].

State of the art

  • Semidefinite programming improves the factor: about 0.9400.940 for MAX-2SAT (Lewin, Livnat and Zwick, 2002) and about 0.7970.797 for MAX-SAT in general (Avidor, Berkovitch and Zwick, 2005), building on the vector programs of Goemans-Williamson Hyperplane Rounding.
  • For MAX-E3SAT (exactly 3 literals) the random assignment's 78\frac{7}{8} is optimal unless P = NP (Håstad, 2001); see Tight Thresholds: MAX-3SAT, Clique and Set Cover.

Test yourself

Which clauses are hardest for the uniformly random assignment, and which for LP rounding?

  1. Long clauses for both
  2. Unit clauses for the random assignment (probability 12\frac{1}{2}); long clauses for LP rounding (factor tending to 1−1e1 - \frac{1}{e})
  3. Unit clauses for both
  4. Neither depends on clause length

Why is the better of the two assignments at least 34 LP\frac{3}{4}\,\text{LP} in expectation?

  1. Because both algorithms are 34\frac{3}{4}-approximations
  2. The maximum is at least the average, and pk+qk2≥34\frac{p_k + q_k}{2} \ge \frac{3}{4} for every clause length kk
  3. Because the LP is integral
  4. Because of the union bound

In the LP rounding lemma, which two facts give Pr⁡[satisfied]≥(1−(1−1k)k)z∗\Pr[\text{satisfied}] \ge (1 - (1 - \frac{1}{k})^k) z^*?

  1. Markov's and Chebyshev's inequalities
  2. The AM-GM inequality on ∏(1−yi)\prod (1 - y_i) and the concavity of 1−(1−zk)k1 - (1 - \frac{z}{k})^k
  3. Linearity of expectation and the union bound
  4. Complementary slackness and duality

Why can no analysis against this LP prove a ratio above 34\frac{3}{4}?

  1. The LP is NP-hard to solve
  2. The four 2-clauses on x1,x2x_1, x_2 with all sign patterns have OPT 3 but LP value 4
  3. Because 1−1e<341 - \frac{1}{e} < \frac{3}{4}
  4. Because unit clauses exist