TExcelTAD
Home › Approximation Algorithms › PTAS, FPTAS and the Class APX

PTAS, FPTAS and the Class APX

Some NP-hard problems can be approximated to any accuracy we like, at a price in running time. Others have a best constant, and some have none at all. This lesson defines the classes that sort problems by how well they can be approximated, proves the most useful dividing line (strong NP-hardness rules out an FPTAS), and runs a first approximation scheme.

Approximation schemes

Definition. An approximation scheme for a minimization problem is a family of algorithms AεA_\varepsilon, one for each ε>0\varepsilon > 0, where AεA_\varepsilon is a (1+ε)(1 + \varepsilon)-approximation. (For maximization, 1−ε1 - \varepsilon.)

  • A PTAS (polynomial-time approximation scheme): for each fixed ε\varepsilon, AεA_\varepsilon runs in time polynomial in nn. The degree may depend on ε\varepsilon: O(n1/ε)O(n^{1/\varepsilon}) is allowed.
  • An EPTAS (efficient PTAS): time f(1ε)⋅nO(1)f(\frac{1}{\varepsilon}) \cdot n^{O(1)} for some function ff, with the exponent of nn independent of ε\varepsilon.
  • An FPTAS (fully polynomial): time polynomial in both nn and 1ε\frac{1}{\varepsilon}, such as O(n3/ε)O(n^3 / \varepsilon).
Running time of AεA_\varepsilon ε=0.1\varepsilon = 0.1, n=1000n = 1000 class
n1/εn^{1/\varepsilon} 103010^{30} PTAS only
21/εn22^{1/\varepsilon} n^2 about 10910^9 EPTAS
n3/εn^3 / \varepsilon 101010^{10} FPTAS

Knapsack has an FPTAS (A Knapsack FPTAS by Profit Scaling); Euclidean TSP has a PTAS (Euclidean TSP: the Idea of Arora's PTAS); bin packing has an asymptotic PTAS but, as shown below, no PTAS unless P = NP.

A first scheme: makespan on a fixed number of machines

Jobs with processing times p1≥p2≥⋯≥pnp_1 \ge p_2 \ge \cdots \ge p_n go to mm identical machines; the makespan is the largest machine load. Graham (1969) gave this scheme for fixed mm:

text
PTAS-MAKESPAN(p sorted decreasingly, m, k)
1  schedule jobs 1..k optimally by trying all m^k assignments
2  for j = k+1 .. n:  put job j on the currently least loaded machine
3  return the schedule

Theorem (Graham, 1969). The schedule has makespan at most (1+1−1/m1+⌊k/m⌋)OPT\left(1 + \frac{1 - 1/m}{1 + \lfloor k/m \rfloor}\right)\text{OPT}.

Proof. Let job jj finish last. If j≤kj \le k, the makespan is that of the optimal schedule of the first kk jobs, which is at most OPT. Otherwise jj started on the least loaded machine, whose load was at most the average of the other jobs, 1m(∑ipi−pj)\frac{1}{m}(\sum_i p_i - p_j). So the makespan is at most 1m∑ipi+(1−1m)pj≤OPT+(1−1m)pk+1\frac{1}{m}\sum_i p_i + (1 - \frac{1}{m})p_j \le \text{OPT} + (1 - \frac{1}{m})p_{k+1}. Finally, the k+1k + 1 longest jobs each take at least pk+1p_{k+1}, and some machine receives at least ⌈k+1m⌉≥1+⌊km⌋\lceil \frac{k+1}{m} \rceil \ge 1 + \lfloor \frac{k}{m} \rfloor of them, so OPT≥(1+⌊km⌋)pk+1\text{OPT} \ge (1 + \lfloor \frac{k}{m} \rfloor)p_{k+1}. □\square

To reach 1+ε1 + \varepsilon, choose k=m⌈1ε⌉k = m \lceil \frac{1}{\varepsilon} \rceil; the running time O(mk+nlog⁡n)O(m^{k} + n \log n) is polynomial for fixed mm and ε\varepsilon, but exponential in mε\frac{m}{\varepsilon}. The program shows the trade-off.

python · try it yourself
from itertools import product

def optimal_makespan(p, m):
    loads = {tuple([0] * m)}
    for x in p:                                     # reachable sorted load vectors
        loads = {tuple(sorted(L[:i] + (L[i] + x,) + L[i + 1:])) for L in loads for i in range(m)}
    return min(max(L) for L in loads)

def ptas(p, m, k):
    p = sorted(p, reverse=True)
    best, tried = None, 0
    for assign in product(range(m), repeat=k):      # all m^k assignments of the k largest jobs
        tried += 1
        L = [0] * m
        for x, i in zip(p[:k], assign):
            L[i] += x
        if best is None or max(L) < max(best):
            best = L
    L = list(best)
    for x in p[k:]:
        L[L.index(min(L))] += x
    return max(L), tried

m = 3
for p in ([10, 10, 8, 8, 6, 6, 6, 3, 2, 1], [5, 5, 4, 4, 3, 3, 3]):
    opt = optimal_makespan(p, m)
    print("jobs", p, " OPT", opt)
    for k in [0, 3, 6, 9][: 1 + len(p) // 3]:
        ms, tried = ptas(p, m, k)
        bound = 1 + (1 - 1 / m) / (1 + k // m)
        print(f"  k = {k}: makespan {ms}, ratio {ms / opt:.3f} <= bound {bound:.3f}, assignments tried {tried}")
jobs [10, 10, 8, 8, 6, 6, 6, 3, 2, 1]  OPT 20
  k = 0: makespan 22, ratio 1.100 <= bound 1.667, assignments tried 1
  k = 3: makespan 22, ratio 1.100 <= bound 1.333, assignments tried 27
  k = 6: makespan 22, ratio 1.100 <= bound 1.222, assignments tried 729
  k = 9: makespan 20, ratio 1.000 <= bound 1.167, assignments tried 19683
jobs [5, 5, 4, 4, 3, 3, 3]  OPT 9
  k = 0: makespan 11, ratio 1.222 <= bound 1.667, assignments tried 1
  k = 3: makespan 11, ratio 1.222 <= bound 1.333, assignments tried 27
  k = 6: makespan 11, ratio 1.222 <= bound 1.222, assignments tried 729

The guessing work grows as 3k3^k while the guarantee shrinks towards 1. On the first instance only k=9k = 9 guesses well enough to be optimal. The second instance shows that the bound is tight: with k=6k = 6 the six largest jobs are spread perfectly as 8,8,88, 8, 8, yet the last job of length 3 then pushes one machine to 11, while the optimum 5+4, 5+4, 3+3+35 + 4,\ 5 + 4,\ 3 + 3 + 3 has makespan 9, a ratio of exactly 119\frac{11}{9}.

In C++

The same scheme with the brute force over the mkm^k assignments written as a counter in base mm.

cpp · try it yourself
#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>

int ptas(std::vector<int> p, int m, int k) {
    std::sort(p.begin(), p.end(), std::greater<int>());
    long long total = 1;
    for (int i = 0; i < k; i++) total *= m;
    std::vector<int> best;
    for (long long code = 0; code < total; code++) {
        std::vector<int> L(m, 0);
        long long c = code;
        for (int i = 0; i < k; i++) { L[c % m] += p[i]; c /= m; }
        if (best.empty() || *std::max_element(L.begin(), L.end()) < *std::max_element(best.begin(), best.end())) best = L;
    }
    for (size_t j = k; j < p.size(); j++) *std::min_element(best.begin(), best.end()) += p[j];
    return *std::max_element(best.begin(), best.end());
}

int main() {
    std::vector<int> p = {10, 10, 8, 8, 6, 6, 6, 3, 2, 1};
    for (int k : {0, 3, 6, 9}) std::printf("k = %d: makespan %d\n", k, ptas(p, 3, k));
}
k = 0: makespan 22
k = 3: makespan 22
k = 6: makespan 22
k = 9: makespan 20

Strong NP-hardness rules out an FPTAS

A problem is strongly NP-hard if it stays NP-hard when all numbers in the input are bounded by a polynomial in the input length (equivalently, written in unary). Bin packing, makespan with mm part of the input, and TSP are strongly NP-hard; knapsack and subset sum are not, which is exactly why their pseudo-polynomial dynamic programs exist (Subset Sum).

Theorem. Let Π\Pi be a minimization problem with integer objective values, and suppose OPT(I)<q(∣I∣,max(I))\text{OPT}(I) < q(\lvert I \rvert, \text{max}(I)) for a polynomial qq, where max(I)\text{max}(I) is the largest number in II. If Π\Pi has an FPTAS, it has a pseudo-polynomial exact algorithm. So if Π\Pi is strongly NP-hard, it has no FPTAS unless P = NP.

Proof. Run the FPTAS with ε=1/q(∣I∣,max(I))\varepsilon = 1 / q(\lvert I \rvert, \text{max}(I)). The time is polynomial in ∣I∣\lvert I \rvert and 1ε\frac{1}{\varepsilon}, hence in ∣I∣\lvert I \rvert and max(I)\text{max}(I). The result satisfies ALG≤(1+ε)OPT<OPT+εq=OPT+1\text{ALG} \le (1 + \varepsilon)\text{OPT} < \text{OPT} + \varepsilon q = \text{OPT} + 1, and since values are integers, ALG=OPT\text{ALG} = \text{OPT}. On instances with numbers bounded by a polynomial this exact algorithm is polynomial, contradicting strong NP-hardness unless P = NP. □\square

The program watches the argument happen on a small knapsack instance, using the profit-scaling FPTAS of A Knapsack FPTAS by Profit Scaling. Since OPT≤nP\text{OPT} \le nP, the choice ε=1nP+1\varepsilon = \frac{1}{nP + 1} is below 1OPT\frac{1}{\text{OPT}}, so the result must be exact, and the table of the dynamic program grows to the size of the pseudo-polynomial exact algorithm.

python · try it yourself
from itertools import combinations

def fptas(p, s, B, eps):
    n, P = len(p), max(p)
    K = eps * P / n
    q = [int(x // K) for x in p]                      # rounded profits
    best = {0: (0, ())}                               # rounded profit -> (smallest size, items)
    for i in range(n):
        for val, (size, items) in list(best.items()):
            nv, ns = val + q[i], size + s[i]
            if ns <= B and (nv not in best or ns < best[nv][0]):
                best[nv] = (ns, items + (i,))
    chosen = best[max(best)][1]
    return sum(p[i] for i in chosen), n * (sum(q) + 1)

p, s, B = [18, 13, 11, 9, 7], [9, 7, 6, 5, 4], 16
opt = max(sum(p[i] for i in S) for r in range(6) for S in combinations(range(5), r) if sum(s[i] for i in S) <= B)
print("OPT =", opt)
for eps in [0.9, 0.5, 0.2, 1 / (len(p) * max(p) + 1)]:
    val, cells = fptas(p, s, B, eps)
    print(f"eps = {eps:.4f}: value {val}, table cells {cells}")
OPT = 31
eps = 0.9000: value 31, table cells 85
eps = 0.5000: value 31, table cells 150
eps = 0.2000: value 31, table cells 400
eps = 0.0110: value 31, table cells 7320

On this small instance even the coarse roundings happen to find the optimum; only the last line is guaranteed to. With that ε\varepsilon the answer must be exact, at the price of a table as large as the one indexed by the original profits. For a strongly NP-hard problem such a pseudo-polynomial algorithm would be polynomial on the instances that remain hard, which is the contradiction.

APX and the limits of PTAS

The classes form a chain (each inclusion is strict unless P = NP):

PO⊆FPTAS⊆PTAS⊆APX⊆log-APX⊆poly-APX⊆NPO\text{PO} \subseteq \text{FPTAS} \subseteq \text{PTAS} \subseteq \text{APX} \subseteq \text{log-APX} \subseteq \text{poly-APX} \subseteq \text{NPO}

APX is the class of NP optimization problems with some constant-factor approximation: vertex cover, metric TSP, MAX-3SAT, bin packing, kk-center. log-APX allows O(log⁡n)O(\log n) (set cover); poly-APX allows ncn^{c} (maximum clique and independent set, where even n1−εn^{1-\varepsilon} is impossible unless P = NP, by Tight Thresholds: MAX-3SAT, Clique and Set Cover).

A problem is APX-hard if every APX problem reduces to it by an approximation-preserving reduction (a PTAS reduction). A consequence of the PCP theorem (The PCP Theorem) is that MAX-3SAT is APX-complete and that no APX-hard problem has a PTAS unless P = NP. Vertex cover, metric TSP, max-cut, kk-center and bin packing (in the absolute sense) are all APX-hard.

Bin packing shows the difference between absolute and asymptotic schemes. Deciding whether nn items fit into two bins is the NP-complete PARTITION problem, so no algorithm achieves an absolute ratio below 32\frac{3}{2} unless P = NP: on a two-bin instance it would have to answer 2, not 3. Yet the large-OPT behaviour is excellent: for every ε>0\varepsilon > 0 there is a polynomial algorithm using at most (1+ε)OPT+1(1 + \varepsilon)\text{OPT} + 1 bins (Fernandez de la Vega and Lueker, 1981), the subject of An Asymptotic PTAS for Bin Packing.

Test yourself

An algorithm runs in time O(n2/ε)O(n^{2/\varepsilon}) and returns a (1+ε)(1 + \varepsilon)-approximation. What is it?

  1. An FPTAS
  2. A PTAS but not, from this bound, an FPTAS
  3. An EPTAS
  4. Not an approximation scheme

Why does an FPTAS for a strongly NP-hard problem with polynomially bounded integer optimum imply P = NP?

  1. Because FPTAS algorithms are randomized
  2. Choosing ε\varepsilon below 1OPT\frac{1}{\text{OPT}} forces the answer to be exact, in time polynomial in the size and the largest number
  3. Because strongly NP-hard problems have no feasible solutions
  4. Because ε\varepsilon must be constant

In Graham's scheme for makespan with m=3m = 3 and k=6k = 6, what ratio is guaranteed?

  1. 43\frac{4}{3}
  2. 1+2/33=1191 + \frac{2/3}{3} = \frac{11}{9}
  3. 32\frac{3}{2}
  4. 1+161 + \frac{1}{6}

Why has bin packing no PTAS unless P = NP, although it has an asymptotic PTAS?

  1. It is not in NP
  2. Deciding whether the items fit into two bins is PARTITION, so an absolute ratio below 32\frac{3}{2} would solve an NP-complete problem; the asymptotic scheme allows an additive constant
  3. Because first fit is optimal
  4. Because its LP relaxation is integral