TExcelTAD
Home › Linear Programming & Duality for Algorithms › Goemans-Williamson Hyperplane Rounding

Goemans-Williamson Hyperplane Rounding

The max-cut SDP returns unit vectors, one per vertex, with adjacent vertices pointing far apart. To get a cut, Goemans and Williamson (1995) proposed the simplest possible rounding: pick a random hyperplane through the origin and put the vertices whose vectors lie on one side into SS. An edge is cut with probability proportional to the angle between its vectors, and comparing that probability with the edge's SDP contribution gives the famous ratio 0.8780.878. It was the first approximation algorithm based on semidefinite programming, and it is still the best known for max-cut. This lesson proves the angle lemma, computes the constant, and runs the rounding on the optimal vectors of the previous lesson.

The algorithm

text
GOEMANS-WILLIAMSON(G)
1  solve the max-cut SDP: unit vectors v_1 .. v_n maximizing  sum over edges (1 - v_i.v_j) / 2
2  draw r with independent standard normal coordinates          -- a uniformly random direction
3  S = { i : r . v_i >= 0 }                                     -- one side of the hyperplane r.x = 0
4  return the cut (S, V \ S)

Lemma (the angle lemma). If viv_i and vjv_j are unit vectors at angle θij∈[0,π]\theta_{ij} \in [0, \pi], the probability that the random hyperplane separates them is θijπ\frac{\theta_{ij}}{\pi}.

Proof. The Gaussian vector rr is rotationally symmetric, so its projection onto the plane spanned by viv_i and vjv_j points in a uniformly random direction of that plane. In the plane, the hyperplane becomes a random line through the origin, perpendicular to that direction; it separates viv_i from vjv_j exactly when it passes through the angle between them, which happens for a fraction 2θij2π\frac{2\theta_{ij}}{2\pi} of all directions. □\square

The constant 0.878

Edge ijij contributes 1−cos⁡θij2\frac{1 - \cos\theta_{ij}}{2} to the SDP and is cut with probability θijπ\frac{\theta_{ij}}{\pi}. So the expected cut, summed edge by edge, satisfies

E[cut⁡]=∑ij∈Eθijπ  ≥  αGW∑ij∈E1−cos⁡θij2=αGW⋅SDP⁡  ≥  αGW⋅maxcut⁡,αGW=min⁡0<θ≤πθ/π(1−cos⁡θ)/2=min⁡0<θ≤π2θπ(1−cos⁡θ).\mathbb{E}[\operatorname{cut}] = \sum_{ij \in E} \frac{\theta_{ij}}{\pi} \;\ge\; \alpha_{GW} \sum_{ij \in E} \frac{1 - \cos\theta_{ij}}{2} = \alpha_{GW} \cdot \operatorname{SDP} \;\ge\; \alpha_{GW} \cdot \operatorname{maxcut}, \qquad \alpha_{GW} = \min_{0 < \theta \le \pi} \frac{\theta / \pi}{(1 - \cos\theta)/2} = \min_{0 < \theta \le \pi} \frac{2\theta}{\pi (1 - \cos\theta)} .

The minimum is attained where the derivative vanishes, at the solution of θ=tan⁡θ2\theta = \tan \frac{\theta}{2} in (0,π)(0, \pi) (an elementary calculation: ddθθ1−cos⁡θ=0  ⟺  1−cos⁡θ=θsin⁡θ\frac{d}{d\theta} \frac{\theta}{1 - \cos\theta} = 0 \iff 1 - \cos\theta = \theta \sin\theta). The program locates it numerically.

python · try it yourself
import math

f = lambda t: 2 * t / (math.pi * (1 - math.cos(t)))
grid = min((f(k * math.pi / 10000), k * math.pi / 10000) for k in range(1, 10001))
lo, hi = grid[1] - math.pi / 10000, grid[1] + math.pi / 10000
for _ in range(100):                                   # golden-section refinement of the minimum
    a, b = lo + (hi - lo) * 0.382, lo + (hi - lo) * 0.618
    lo, hi = (lo, b) if f(a) < f(b) else (a, hi)
theta = (lo + hi) / 2
print(f"critical angle  theta* = {theta:.6f} rad = {math.degrees(theta):.4f} degrees")
print(f"alpha_GW = {f(theta):.6f}")
lo2, hi2 = 2.0, 3.0                                    # bisection for the root of theta = tan(theta / 2)
for _ in range(60):
    mid = (lo2 + hi2) / 2
    lo2, hi2 = (mid, hi2) if mid - math.tan(mid / 2) > 0 else (lo2, mid)
print(f"check: the root of theta = tan(theta/2) is {lo2:.6f}")
for deg in [60, 90, 120, 133.56, 150, 180]:
    t = math.radians(deg)
    print(f"  angle {deg:6} deg: cut probability {t / math.pi:.4f}, SDP contribution {(1 - math.cos(t)) / 2:.4f}, ratio {f(t):.4f}")
critical angle  theta* = 2.331122 rad = 133.5635 degrees
alpha_GW = 0.878567
check: the root of theta = tan(theta/2) is 2.331122
  angle     60 deg: cut probability 0.3333, SDP contribution 0.2500, ratio 1.3333
  angle     90 deg: cut probability 0.5000, SDP contribution 0.5000, ratio 1.0000
  angle    120 deg: cut probability 0.6667, SDP contribution 0.7500, ratio 0.8889
  angle 133.56 deg: cut probability 0.7420, SDP contribution 0.8446, ratio 0.8786
  angle    150 deg: cut probability 0.8333, SDP contribution 0.9330, ratio 0.8932
  angle    180 deg: cut probability 1.0000, SDP contribution 1.0000, ratio 1.0000

Theorem (Goemans and Williamson, 1995). The algorithm returns a cut whose expected size is at least αGW⋅maxcut⁡(G)\alpha_{GW} \cdot \operatorname{maxcut}(G) with αGW>0.87856\alpha_{GW} > 0.87856. Because the SDP is solved only to within an additive ε\varepsilon, the guarantee is αGW−ε′\alpha_{GW} - \varepsilon' for any constant ε′>0\varepsilon' > 0. Repeating the rounding and keeping the best cut gives this ratio with high probability; Mahajan and Ramesh (1999) derandomized it.

The ratio is tight in three senses: there are graphs where the rounding loses exactly this factor; the SDP's integrality gap is αGW\alpha_{GW} (Feige and Schechtman, 2002); and assuming the Unique Games Conjecture, no polynomial-time algorithm achieves αGW+ε\alpha_{GW} + \varepsilon (Khot, Kindler, Mossel and O'Donnell, 2007, with the Majority is Stablest theorem of Mossel, O'Donnell and Oleszkiewicz, 2010). Unconditionally, approximating max-cut better than 1617≈0.941\frac{16}{17} \approx 0.941 is NP-hard (Håstad, 2001; Trevisan, Sorkin, Sudan and Williamson, 2000).

Rounding the 5-cycle

The optimal vectors of C5C_5 are at 144144 degrees, so each edge is cut with probability 144180=0.8\frac{144}{180} = 0.8 and the expected cut is exactly 4=maxcut⁡(C5)4 = \operatorname{maxcut}(C_5). The program draws hyperplanes with a fixed seed and compares the empirical average with the exact expectation and with αGW⋅SDP⁡\alpha_{GW} \cdot \operatorname{SDP}.

python · try it yourself
import math
import random

n = 5
step = 4 * math.pi / 5
V = [(math.cos(k * step), math.sin(k * step)) for k in range(n)]
E = [(k, (k + 1) % n) for k in range(n)]
rng = random.Random(1995)

trials, total, sizes = 20000, 0, {}
for _ in range(trials):
    r = (rng.gauss(0, 1), rng.gauss(0, 1))
    side = [r[0] * v[0] + r[1] * v[1] >= 0 for v in V]
    cut = sum(side[u] != side[v] for u, v in E)
    total += cut
    sizes[cut] = sizes.get(cut, 0) + 1
sdp = n / 2 * (1 + math.cos(math.pi / n))
print("empirical average cut:", round(total / trials, 3))
print("exact expectation sum theta/pi:", round(len(E) * step / math.pi, 6))      # every edge has angle 144 degrees
print("alpha_GW * SDP:", round(0.878567 * sdp, 4), "  max cut: 4")
print("distribution of cut sizes:", dict(sorted(sizes.items())))
empirical average cut: 4.0
exact expectation sum theta/pi: 4.0
alpha_GW * SDP: 3.9734   max cut: 4
distribution of cut sizes: {4: 20000}

Every hyperplane through the centre of the regular pentagram cuts exactly 4 of its 5 edges here: the rounding is optimal on every draw. On general graphs the cut size varies, and the guarantee holds in expectation.

Rounding vectors found by a local method

For the 7-vertex graph of the previous lesson, the program recomputes certified optimal SDP vectors with the same local method, computes the exact expected cut ∑θijπ\sum \frac{\theta_{ij}}{\pi}, and keeps the best of 30 hyperplanes.

python · try it yourself
import itertools
import math
import random
import numpy as np

n = 7
E = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 0), (0, 5), (5, 2), (5, 6), (6, 3), (1, 6)]
rng = random.Random(0)
V = [np.array([rng.gauss(0, 1) for _ in range(4)]) for _ in range(n)]
V = [v / np.linalg.norm(v) for v in V]
nbrs = [[j for e in E for j in e if i in e and j != i] for i in range(n)]
for _ in range(500):                                  # the local method of the previous lesson
    for i in range(n):
        g = sum(V[j] for j in nbrs[i])
        V[i] = -g / np.linalg.norm(g)

angles = [math.acos(max(-1.0, min(1.0, float(V[u] @ V[v])))) for u, v in E]
sdp = sum((1 - math.cos(t)) / 2 for t in angles)
expected = sum(t / math.pi for t in angles)
maxcut = max(sum((u in S) != (v in S) for u, v in E) for k in range(n + 1) for S in itertools.combinations(range(n), k))
print(f"SDP {sdp:.4f}, exact expected cut {expected:.4f}, ratio to SDP {expected / sdp:.4f} (>= 0.8786)")

rr = random.Random(7)
best = 0
for _ in range(30):
    r = np.array([rr.gauss(0, 1) for _ in range(4)])
    S = {i for i in range(n) if float(r @ V[i]) >= 0}
    best = max(best, sum((u in S) != (v in S) for u, v in E))
print(f"best of 30 hyperplanes: {best}, maximum cut: {maxcut}")
SDP 9.2840, exact expected cut 8.5140, ratio to SDP 0.9171 (>= 0.8786)
best of 30 hyperplanes: 9, maximum cut: 9

The expected cut is far above the worst-case factor here, because most edges sit at angles where θπ\frac{\theta}{\pi} is close to 1−cos⁡θ2\frac{1 - \cos\theta}{2}; the factor 0.8780.878 is only lost on edges at about 133.6133.6 degrees.

Beyond max-cut

The same pattern, a vector relaxation followed by hyperplane rounding, works for other two-variable constraint problems. Goemans and Williamson's paper already gave 0.8780.878 for MAX 2SAT and 0.7960.796 for MAX DICUT (directed cuts); by adding more constraints to the SDP and rotating the vectors before rounding, Lewin, Livnat and Zwick (2002) improved these to about 0.9400.940 and 0.8740.874. For graph colouring, Karger, Motwani and Sudan (1998) rounded vector colourings to colour 3-colourable graphs with O~(n1/4)\tilde O(n^{1/4}) colours. In each case the analysis is the angle lemma, or a variant of it, applied constraint by constraint.

Note: In practice, the SDP is solved approximately (to 10−610^{-6} or so by an interior-point solver), the rounding is repeated a few dozen times, and the best cut is then improved by local search (move one vertex if that cuts more edges). The guarantee comes from the SDP and the rounding; the local search only helps.

In C++

The rounding step for the C5C_5 vectors, with a seeded Mersenne Twister and Box-Muller Gaussians. It estimates the probability that each edge is cut, which the angle lemma predicts to be 0.80.8.

cpp · try it yourself
#include <cmath>
#include <cstdio>
#include <random>

int main() {
    const int n = 5, trials = 100000;
    const double pi = std::acos(-1.0), step = 4 * pi / 5;
    double vx[n], vy[n];
    for (int k = 0; k < n; k++) { vx[k] = std::cos(k * step); vy[k] = std::sin(k * step); }
    std::mt19937 rng(1995);
    auto uniform01 = [&]() { return (rng() + 0.5) / 4294967296.0; };      // in (0, 1)
    int cutCount[n] = {0};
    long long total = 0;
    for (int t = 0; t < trials; t++) {
        double u1 = uniform01(), u2 = uniform01();
        double rad = std::sqrt(-2 * std::log(u1));
        double gx = rad * std::cos(2 * pi * u2), gy = rad * std::sin(2 * pi * u2);  // Box-Muller
        bool side[n];
        for (int k = 0; k < n; k++) side[k] = gx * vx[k] + gy * vy[k] >= 0;
        for (int k = 0; k < n; k++) if (side[k] != side[(k + 1) % n]) { cutCount[k]++; total++; }
    }
    for (int k = 0; k < n; k++) std::printf("edge %d-%d cut with frequency %.3f\n", k, (k + 1) % n, (double)cutCount[k] / trials);
    std::printf("average cut %.3f (expected 4)\n", (double)total / trials);
}
edge 0-1 cut with frequency 0.801
edge 1-2 cut with frequency 0.801
edge 2-3 cut with frequency 0.800
edge 3-4 cut with frequency 0.797
edge 4-0 cut with frequency 0.800
average cut 4.000 (expected 4)

Test yourself

With what probability does a random hyperplane separate two unit vectors at angle θ\theta?

  1. 1−cos⁡θ2\frac{1 - \cos\theta}{2}
  2. θπ\frac{\theta}{\pi}
  3. 12\frac{1}{2}
  4. cos⁡2θ\cos^2\theta

Where does the ratio θ/π(1−cos⁡θ)/2\frac{\theta / \pi}{(1 - \cos\theta)/2} reach its minimum αGW≈0.8786\alpha_{GW} \approx 0.8786?

  1. At θ=π2\theta = \frac{\pi}{2}
  2. At θ≈2.331\theta \approx 2.331 radians (about 133.6 degrees), the solution of θ=tan⁡θ2\theta = \tan\frac{\theta}{2}
  3. At θ=π\theta = \pi
  4. At θ→0\theta \to 0

Which statement about the optimality of Goemans-Williamson is correct?

  1. It is NP-hard to beat αGW\alpha_{GW}
  2. Beating αGW\alpha_{GW} is UGC-hard, and beating 1617\frac{16}{17} is NP-hard
  3. Max-cut has a PTAS
  4. The SDP's integrality gap is 12\frac{1}{2}