TExcelTAD
Home › Approximation Algorithms › Euclidean TSP: the Idea of Arora's PTAS

Euclidean TSP: the Idea of Arora's PTAS

Metric TSP is APX-hard: unless P = NP no polynomial algorithm comes within a factor 123122\frac{123}{122} of the optimum (Christofides' Algorithm). For points in the plane with Euclidean distances, Arora (1996, journal version 1998) and, independently, Mitchell (1999) found something much stronger: for every fixed ε>0\varepsilon > 0 a (1+ε)(1 + \varepsilon)-approximation in polynomial time, a PTAS. The two shared the 2010 Gödel Prize. The full proof is long and technical; this lesson explains the four ideas behind Arora's scheme, checks the two quantitative steps with programs, and states the result precisely. Treat it as a guided sketch, not a proof.

The four ideas

  1. Snap to a grid. Rescale so the bounding box has side L=O(nε)L = O(\frac{n}{\varepsilon}) and move every point to the nearest grid point. Every tour changes by only a small fraction of OPT, and coordinates become small integers.
  2. Randomly shifted quadtree. Recursively split the (shifted) bounding box into four squares until each square holds at most one point. The tree has depth O(log⁡n)O(\log n).
  3. Portals. On each side of each square place m=O(log⁡nε)m = O(\frac{\log n}{\varepsilon}) equally spaced portals, and only allow the tour to cross a square's boundary at a portal. Bending the tour to the nearest portals costs little in expectation over the random shift.
  4. Few crossings and dynamic programming. A patching lemma shows that a tour can be modified, at small extra cost, to cross each side of each square at most r=O(1ε)r = O(\frac{1}{\varepsilon}) times. A tour that is both portal-respecting and rr-light can be found by dynamic programming over the quadtree: for each square, try every way the tour can enter and leave through its portals, and combine the four children.

Step 1: snapping loses little

Moving every point by at most ρ\rho changes the length of any tour by at most 2nρ2n\rho, since each of the nn edges has two endpoints. The optimal tour of points with bounding box side LL has length at least 2L2L. Snapping to a grid of spacing δ\delta moves each point by at most ρ=δ2\rho = \frac{\delta}{\sqrt{2}}; with δ=εL2 n\delta = \frac{\varepsilon L}{\sqrt{2}\,n}, the loss is at most 2n⋅εL2n=εL≤ε2 OPT2n \cdot \frac{\varepsilon L}{2n} = \varepsilon L \le \frac{\varepsilon}{2}\,\text{OPT}, and the grid has only Lδ=O(nε)\frac{L}{\delta} = O(\frac{n}{\varepsilon}) lines in each direction.

The program snaps random points to coarser and coarser grids, finds the optimal tour of the snapped points with the Held-Karp dynamic program, and measures that tour on the original points.

python · try it yourself
import random
from math import dist, inf, sqrt

def held_karp(pts):
    n = len(pts)
    D = [[inf] * n for _ in range(1 << n)]
    P = [[-1] * n for _ in range(1 << n)]
    D[1][0] = 0.0
    for S in range(1, 1 << n, 2):
        for j in range(n):
            if D[S][j] < inf:
                for k in range(1, n):
                    if not S >> k & 1 and D[S][j] + dist(pts[j], pts[k]) < D[S | 1 << k][k]:
                        D[S | 1 << k][k] = D[S][j] + dist(pts[j], pts[k])
                        P[S | 1 << k][k] = j
    full = (1 << n) - 1
    j = min(range(1, n), key=lambda j: D[full][j] + dist(pts[j], pts[0]))
    tour, S = [], full
    while j >= 0:
        tour.append(j)
        S, j = S & ~(1 << j), P[S][j]
    return tour

length = lambda pts, t: sum(dist(pts[t[i]], pts[t[i - 1]]) for i in range(len(t)))
rng = random.Random(31)
n, L = 9, 100.0
pts = [(rng.uniform(0, L), rng.uniform(0, L)) for _ in range(n)]
opt = length(pts, held_karp(pts))
print(f"OPT on the original points: {opt:.2f}")
for eps in [0.05, 0.2, 0.5, 1.0, 2.0]:
    delta = eps * L / (sqrt(2) * n)
    snapped = [(round(x / delta) * delta, round(y / delta) * delta) for x, y in pts]
    t = held_karp(snapped)
    print(f"eps = {eps:4}: grid spacing {delta:5.2f}, {int(L / delta) + 1:3} lines per axis, "
          f"tour from snapped points costs {length(pts, t):.2f} ({round(length(pts, t) / opt - 1, 6) + 0.0:+.2%}), bound +{eps / 2:.0%}")
OPT on the original points: 270.24
eps = 0.05: grid spacing  0.39, 255 lines per axis, tour from snapped points costs 270.24 (+0.00%), bound +2%
eps =  0.2: grid spacing  1.57,  64 lines per axis, tour from snapped points costs 270.24 (+0.00%), bound +10%
eps =  0.5: grid spacing  3.93,  26 lines per axis, tour from snapped points costs 270.24 (+0.00%), bound +25%
eps =  1.0: grid spacing  7.86,  13 lines per axis, tour from snapped points costs 270.24 (+0.00%), bound +50%
eps =  2.0: grid spacing 15.71,   7 lines per axis, tour from snapped points costs 276.31 (+2.25%), bound +100%

Only very coarse grids change the answer at all, and always by far less than the bound ε2\frac{\varepsilon}{2}.

Step 3: portals cost little on average

A tour edge that crosses a dissection line at level ii (a line that first appears when squares of side si=2L2is_i = \frac{2L}{2^i} are created) must be bent to a portal, at most si2m\frac{s_i}{2m} away, which costs at most sim\frac{s_i}{m} extra. Deep lines are cheap, but lines near the top of the tree are expensive. The random shift makes the expensive case rare: a given grid line becomes a level-ii line with probability about 2iL\frac{2^i}{L}, so the expected cost of one crossing is at most

∑i2iL⋅sim=∑i=1log⁡L2iL⋅2L2im=O ⁣(log⁡Lm).\sum_{i} \frac{2^i}{L} \cdot \frac{s_i}{m} = \sum_{i=1}^{\log L} \frac{2^i}{L} \cdot \frac{2L}{2^i m} = O\!\left(\frac{\log L}{m}\right).

A tour of length TT crosses the unit grid lines O(T)O(T) times, so the total expected detour is O(log⁡Lm)⋅TO(\frac{\log L}{m}) \cdot T, which is at most εT\varepsilon T with m=O(log⁡nε)m = O(\frac{\log n}{\varepsilon}). Without the random shift an adversary could place many crossings on the middle line, where every detour is large.

The program takes a good tour, applies many random shifts and computes the exact portal detour of every crossing, for several numbers of portals mm.

python · try it yourself
import random
from math import dist

rng = random.Random(8)
L = 64                                                   # bounding box after snapping; points at half-integers
pts = [(rng.randrange(L) + 0.5, rng.randrange(L) + 0.5) for _ in range(30)]

def two_opt(pts):
    t = list(range(len(pts)))
    improved = True
    while improved:
        improved = False
        for i in range(1, len(t) - 1):
            for j in range(i + 1, len(t)):
                a, b, c, d = pts[t[i - 1]], pts[t[i]], pts[t[j]], pts[t[(j + 1) % len(t)]]
                if dist(a, c) + dist(b, d) < dist(a, b) + dist(c, d) - 1e-9:
                    t[i:j + 1] = reversed(t[i:j + 1])
                    improved = True
    return t

def level_size(c):
    """Side of the squares created when the line at (shifted) coordinate c appears; box side 2L."""
    s = 2 * L
    while c % s:
        s //= 2
    return s

def detour(tour, shift, m):
    total = 0.0
    for i in range(len(tour)):
        p, q = pts[tour[i - 1]], pts[tour[i]]
        for axis in (0, 1):
            a, b = sorted((p[axis] + shift[axis], q[axis] + shift[axis]))
            for c in range(int(a) + 1, int(b) + 1):        # crossings with integer lines
                s = level_size(c)
                tpar = (c - shift[axis] - p[axis]) / (q[axis] - p[axis])
                y = p[1 - axis] + tpar * (q[1 - axis] - p[1 - axis]) + shift[1 - axis]
                gap = s / m
                total += 2 * abs(y - round(y / gap) * gap)
    return total

tour = two_opt(pts)
T = sum(dist(pts[tour[i]], pts[tour[i - 1]]) for i in range(len(tour)))
shifts = [(rng.randrange(L), rng.randrange(L)) for _ in range(40)]
print(f"tour length {T:.1f}")
for m in [4, 8, 16, 32, 64]:
    d = [detour(tour, s, m) for s in shifts]
    print(f"m = {m:2} portals per side: average detour {sum(d) / len(d) / T:6.1%} of the tour, worst shift {max(d) / T:6.1%}")
tour length 291.4
m =  4 portals per side: average detour  63.6% of the tour, worst shift  75.3%
m =  8 portals per side: average detour  30.8% of the tour, worst shift  37.5%
m = 16 portals per side: average detour  14.8% of the tour, worst shift  19.5%
m = 32 portals per side: average detour   7.0% of the tour, worst shift   9.5%
m = 64 portals per side: average detour   3.4% of the tour, worst shift   4.5%

The average detour falls roughly in proportion to 1m\frac{1}{m}, as the calculation predicts. The worst of the 40 shifts is noticeably worse than the average: the guarantee is a statement about the random shift, and derandomizing means trying all O(L2)O(L^2) shifts.

Step 4: the dynamic program, and the result

The patching lemma says that if a tour crosses a line segment of length ss more than twice, the crossings can be reduced to at most two by adding segments of total length O(s)O(s) along it. Charging these additions to the crossings, again in expectation over the shift, makes the tour rr-light with r=O(1ε)r = O(\frac{1}{\varepsilon}) at a cost of ε OPT\varepsilon\,\text{OPT}. For a square of the quadtree, an "interface" lists which of its 4m4m portals are used (at most 4r4r) and how the entry and exit portals are paired up by the pieces of tour inside. There are mO(r)=(log⁡n)O(1/ε)m^{O(r)} = (\log n)^{O(1/\varepsilon)} interfaces per square, O(nlog⁡n)O(n \log n) squares, and the best solution for each interface is assembled from the four children.

Theorem (Arora, 1998; Mitchell, 1999). For every fixed ε>0\varepsilon > 0, a tour of length at most (1+ε) OPT(1 + \varepsilon)\,\text{OPT} for nn points in the plane can be found in time n(log⁡n)O(1/ε)n (\log n)^{O(1/\varepsilon)} (Arora's randomized version; it can be derandomized at a polynomial cost).

  • Rao and Smith (1998) reduced the time to O(nlog⁡n)O(n \log n) for fixed ε\varepsilon, using spanners.
  • In Rd\mathbb{R}^d the running time is n(log⁡n)(O(d/ε))d−1n (\log n)^{(O(\sqrt{d}/\varepsilon))^{d-1}}: still a PTAS for fixed dimension, but when dd grows like log⁡n\log n no PTAS exists unless P = NP (Trevisan, 2000).
  • The same framework gives PTASs for Euclidean Steiner tree, kk-median, and many other geometric problems.

Note: No implementation of the full scheme is competitive in practice: the constants hidden in (log⁡n)O(1/ε)(\log n)^{O(1/\varepsilon)} are enormous. Its importance is structural. It shows exactly what geometry buys over general metrics, and the idea of a randomly shifted hierarchical decomposition reappears in metric embeddings into trees (Bartal, 1996; Fakcharoenphol, Rao and Talwar, 2003).

Test yourself

Why does snapping points to a grid of spacing about εLn\frac{\varepsilon L}{n} cost at most a small fraction of OPT?

  1. Because the grid is fine enough to contain the optimal tour
  2. Each point moves at most about εLn\frac{\varepsilon L}{n}, so any tour changes by at most about εL\varepsilon L, while OPT is at least 2L2L
  3. Because snapping never increases distances
  4. Because nn is small

What is the purpose of the random shift of the quadtree?

  1. To make the quadtree balanced
  2. To make every line unlikely to be a high-level line, so the expected portal detour per crossing is only O(log⁡Lm)O(\frac{\log L}{m})
  3. To randomize the order of the points
  4. To avoid points on the boundary

Why does Arora's scheme not contradict the APX-hardness of metric TSP?

  1. It is not polynomial
  2. Hardness concerns general metrics; the scheme uses the geometry of the plane (or of a fixed-dimensional space)
  3. It only works on random inputs
  4. Metric TSP is not APX-hard