Approximation Ratios and Lower Bounds on OPT
Before designing algorithms we fix what "approximately optimal" means, for minimization and maximization alike, and look at the one idea every proof in this course rests on: the optimum is unknown, so the algorithm is compared with a bound on it that can be computed or reasoned about.
Optimization problems
An NP optimization problem consists of
- a set of instances, recognizable in polynomial time;
- for each instance , a set of feasible solutions , each of size polynomial in , with membership checkable in polynomial time;
- an objective computable in polynomial time, to be minimized or maximized.
is the best objective value over . Vertex cover (minimize the number of vertices touching every edge), set cover, TSP, bin packing and makespan scheduling are minimization problems; knapsack, max-cut, MAX-SAT and maximum independent set are maximization problems. The decision version ("is there a solution of value at most ?") is in NP, and for all of these problems it is NP-complete, so unless P = NP no polynomial algorithm computes OPT.
Approximation ratios
Definition. An algorithm for a minimization problem is a -approximation algorithm () if it runs in polynomial time and for every instance returns a feasible solution with
For a maximization problem, and the requirement is .
The factor may depend on the input size: greedy set cover is an -approximation, where is the number of elements. Three variants appear later:
- Asymptotic ratio: for a constant . First-fit decreasing for bin packing is , far better than its absolute ratio .
- Absolute approximation: . Rare, but it exists: every graph can be edge-coloured with at most colours (Vizing, 1964), while colours are needed, so an algorithm following Vizing's proof is within 1 of optimal although deciding between and is NP-hard (Holyer, 1981).
- Randomized: the guarantee holds for the expected value, , or with high probability.
A ratio is tight for an algorithm when instances exist on which it comes arbitrarily close to . Tightness of the analysis is a statement about one algorithm; whether another algorithm could do better is a question for hardness of approximation.
Why absolute guarantees are rare
For problems whose objective scales with the numbers in the input, an additive guarantee would solve the problem exactly. Knapsack is the standard example.
Claim. If P NP, no polynomial algorithm for knapsack guarantees for a constant .
Proof. Suppose does. Given an instance with integer profits, multiply every profit by and run . Feasible solutions are unchanged, and every value is a multiple of . The solution returned is within of the scaled optimum, so it is within of the original optimum, and since original values are integers it is optimal. That solves an NP-hard problem in polynomial time.
The program applies the scaling trick to a deliberately sloppy algorithm, an exact solver that throws away a few units of profit, to show the mechanism.
from itertools import combinations
items = [(13, 7), (11, 6), (9, 5), (8, 4), (6, 3), (4, 2)] # (profit, size)
B = 14
def solutions(items, B):
for r in range(len(items) + 1):
for S in combinations(range(len(items)), r):
if sum(items[i][1] for i in S) <= B:
yield S
def sloppy(items, B, c):
"""Returns some feasible set within c of optimal: the worst such set."""
vals = {S: sum(items[i][0] for i in S) for S in solutions(items, B)}
opt = max(vals.values())
return min((S for S in vals if vals[S] >= opt - c), key=lambda S: (vals[S], S))
c = 3
opt = max(sum(items[i][0] for i in S) for S in solutions(items, B))
S = sloppy(items, B, c)
print("OPT", opt, " sloppy answer", S, "value", sum(items[i][0] for i in S))
scaled = [(p * (c + 1), s) for p, s in items]
S2 = sloppy(scaled, B, c)
print("after scaling profits by", c + 1, ": answer", S2, "original value", sum(items[i][0] for i in S2))OPT 27 sloppy answer (0, 1) value 24
after scaling profits by 4 : answer (0, 3, 4) original value 27
The additive error of 3 was used in full on the original instance (24 instead of 27), but after scaling every suboptimal solution is at least 4 units worse, so the same sloppiness cannot hide any more. Ratios are invariant under scaling, which is why the course measures quality multiplicatively.
Bounding the optimum
A proof that for a minimization problem almost always has the shape
where LB is a lower bound on OPT that the algorithm can relate to its own cost. For maximization, the roles flip: an upper bound UB OPT with . The design of an approximation algorithm is often the design of the right bound.
| Problem | Bound on OPT | Why it holds |
|---|---|---|
| vertex cover | size of any matching | each matching edge needs its own cover vertex |
| metric TSP | weight of a minimum spanning tree | a tour minus an edge is a spanning tree |
| makespan on machines | some machine gets the longest job; the average load is attained by some machine | |
| knapsack (upper bound) | fractional optimum | the LP relaxation contains every integral solution |
| any covering IP | LP relaxation value, or any feasible dual solution | relaxing can only lower a minimum; weak duality |
The LP bound is the most powerful because it comes with a dual: every feasible dual solution is a lower bound, and an algorithm that builds a dual solution as it runs, as in The Primal-Dual Method for Vertex Cover, carries its own certificate. Its limit is the integrality gap (Integrality Gaps): no analysis against the LP value can prove a ratio better than the worst-case ratio between OPT and LP.
The program computes three lower bounds for vertex cover on random graphs: a greedy maximal matching, a maximum matching (by brute force here) and the LP relaxation, and compares them with OPT.
import random
from itertools import combinations
from scipy.optimize import linprog
def opt_cover(n, E):
for k in range(n + 1):
for C in combinations(range(n), k):
if all(u in C or v in C for u, v in E):
return k
def maximal_matching(E):
used, M = set(), 0
for u, v in E:
if u not in used and v not in used:
used |= {u, v}
M += 1
return M
def maximum_matching(E):
for k in range(len(E), 0, -1):
for M in combinations(E, k):
if len({x for e in M for x in e}) == 2 * k:
return k
return 0
def lp_value(n, E):
A = [[-1 if v in e else 0 for v in range(n)] for e in E]
return linprog([1] * n, A_ub=A, b_ub=[-1] * len(E), bounds=[(0, 1)] * n, method="highs").fun
rng = random.Random(3)
print(" n |E| maximal maximum LP OPT")
for _ in range(5):
n = rng.randint(7, 9)
E = [(u, v) for u in range(n) for v in range(u + 1, n) if rng.random() < 0.35]
print(f"{n:2} {len(E):4} {maximal_matching(E):8} {maximum_matching(E):8} {float(lp_value(n, E)):5.1f} {opt_cover(n, E):5}") n |E| maximal maximum LP OPT
7 5 3 3 3.0 3
7 5 1 2 2.0 2
8 10 3 4 4.0 4
7 10 3 3 3.5 4
8 6 3 3 3.0 3
Every bound sits at or below OPT, and the LP is never below the maximum matching (a matching gives a feasible solution of the LP's dual, the fractional matching LP). Better bounds allow better ratios: matching gives 2, and so does the LP, for vertex cover; for other problems the gap between bounds is where all the progress happens.
Upper bounds for maximization
For maximization the same table is read upside down. For max-cut the total edge weight is an upper bound, and a uniformly random cut gets half of it in expectation, a -approximation; Goemans and Williamson (1995) replace the trivial bound by a semidefinite one and reach (Goemans-Williamson Hyperplane Rounding). For MAX-SAT, the number of clauses is the trivial upper bound and the LP relaxation a better one (MAX-SAT: Random Assignments, LP Rounding and the Better of Two).
Note: A good lower bound can certify a solution after the fact even when the worst-case ratio is weak. Practical solvers report this as a gap: the distance between the best solution found and the best bound proved. An approximation guarantee is a gap that is promised in advance.
Test yourself
A minimization algorithm satisfies on every instance. What kind of guarantee is this?
- An absolute approximation
- An asymptotic ratio of 2: the additive constant matters only for small OPT
- A 5-approximation for every instance
- A randomized guarantee
Why can no polynomial algorithm guarantee for knapsack unless P = NP?
- Knapsack has no polynomial algorithm of any kind
- Scaling every profit by makes every suboptimal solution at least worse, so the guarantee would return an exact optimum
- Because the LP relaxation has a gap of 2
- Because must depend on
Which quantity is a valid lower bound on the optimal metric TSP tour?
- The weight of a minimum spanning tree
- Twice the weight of a minimum spanning tree
- The weight of the heaviest edge times
- The number of vertices
What limits any approximation proof that compares the algorithm with an LP relaxation value?
- The running time of the LP solver
- The integrality gap: the ratio cannot be proved better than the worst ratio between OPT and the LP value
- The number of constraints
- Nothing, LP bounds are always tight