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 . 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 . 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
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 and are unit vectors at angle , the probability that the random hyperplane separates them is .
Proof. The Gaussian vector is rotationally symmetric, so its projection onto the plane spanned by and 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 from exactly when it passes through the angle between them, which happens for a fraction of all directions.
The constant 0.878
Edge contributes to the SDP and is cut with probability . So the expected cut, summed edge by edge, satisfies
The minimum is attained where the derivative vanishes, at the solution of in (an elementary calculation: ). The program locates it numerically.
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 with . Because the SDP is solved only to within an additive , the guarantee is for any constant . 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 (Feige and Schechtman, 2002); and assuming the Unique Games Conjecture, no polynomial-time algorithm achieves (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 is NP-hard (Håstad, 2001; Trevisan, Sorkin, Sudan and Williamson, 2000).
Rounding the 5-cycle
The optimal vectors of are at degrees, so each edge is cut with probability and the expected cut is exactly . The program draws hyperplanes with a fixed seed and compares the empirical average with the exact expectation and with .
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 , and keeps the best of 30 hyperplanes.
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 is close to ; the factor is only lost on edges at about 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 for MAX 2SAT and 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 and . For graph colouring, Karger, Motwani and Sudan (1998) rounded vector colourings to colour 3-colourable graphs with 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 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 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 .
#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 ?
Where does the ratio reach its minimum ?
- At
- At radians (about 133.6 degrees), the solution of
- At
- At
Which statement about the optimality of Goemans-Williamson is correct?
- It is NP-hard to beat
- Beating is UGC-hard, and beating is NP-hard
- Max-cut has a PTAS
- The SDP's integrality gap is