Approximation
Introduction
- Dealing with HARD problems
- Getting around NP-completeness
- If is small, even is acceptable
- Solve some important special cases in polynomial time
- Find near-optimal solutions in polynomial time — approximation algorithm
Note: greedy 等 heuristics 不管效果,approximation 有近似解的质量方面的讨论
Approximation Ratio
[Definition] An algorithm has an approximation ratio of if, for any input of size , the cost of the solution produced by the algorithm is within a factor of of the cost of an optimal solution:
- If an algorithm achieves an approximation ratio of , we call it a -approximation algorithm.
[Definition] An approximation scheme for an optimization problem is an approximation algorithm that takes as input not only an instance of the problem, but also a value such that for any fixed , the scheme is a -approximation algorithm.
-
We say that an approximation scheme is a polynomial-time approximation scheme(PTAS) if for any fixed , the scheme runs in time polynomial in the size of its input instance.
-
is a fully polynomial-time approximation scheme(FPTAS) 完全多项式时间近似模式
Note: fully 的意思是关于和都是多项式级的
Approximate Bin Packing
- Given items of sizes , such that for all . Pack these items in the fewest number of bins, each of which has unit capacity.
- NP-Hard
- Decision problem: given bins, can we pack items? — NPC
Next Fit
1 | void NextFit ( ) |
[Theorem] Let be the optimal number of bins required to pack a list of items. Then next fit never uses more than bins. There exist sequences such that next fit uses bins.
A simple proof for Next Fit
-
If Next Fit generates (or ) bins, then the optimal solution must generate at least bins.
-
Let be the size of the th bin. Then we must have:
-
The optimal solution needs at least bins
First Fit
1 | void FirstFit ( ) |
[Theorem] Let be the optimal number of bins required to pack a list I of items. Then first fit never uses more than bins. There exist sequences such that first fit uses bins.
Best Fit
-
Place a new item in the tightest spot among all bins.
-
and bin number
On-line Algorithms
-
Place an item before processing the next one, and can NOT change decision.
-
Never know when the input might end.
-
No on-line algorithm can always give an optimal solution.
[Theorem] There are inputs that force any on-line bin-packing algorithm to use at least 5/3 the optimal number of bins.
Off-line Algorithms
- View the entire item list before producing an answer.
- Trouble-maker: The large items
- Solution: Sort the items into non-increasing sequence of sizes. Then apply first (or best) fit — first(or best) fit decreasing.
[Theorem] Let be the optimal number of bins required to pack a list of items. Then first fit decreasing never uses more than bins. There exist sequences such that first fit decreasing uses bins.
- Simple greedy heuristics can give good results
The Knapsack Problem
Fractional version
-
A knapsack with a capacity is to be packed. Given items. Each item has a weight and a profit . If is the percentage of the item being packed, then the packed profit will be .
-
An optimal packing is a feasible one with maximum profit. That is, we are supposed to find the values of such that obtains its maximum under the constrains
-
Solution:
- We must pack one item into the knapsack in each stage
- We shall be greedy on the criterion that choose maximum profit density for each stage.
0-1 version
-
is either 0 or 1
-
NP-Hard
A Greedy Solution
-
greedy on taking the maximum profit or profit density
-
The approximation ratio is 2
A Dynamic Programming Solution
-
the minimum weight of a collection from with total profit being exactly
- take :
- skip :
- impossible to get :
Note: input size包括的二进制编码长度,所以是指数级的复杂度
- If is very large, we can round all profit values up to lie in smaller range
- for any feasible solution , is a precision parameter
-center Problem
-
Input: Set of sites
-
Center selection problem: Select centers so that the maximum distance from a site to the nearest center is minimized.
-
distance
- Identity:
- Symmetry:
- Triangle inequality:
-
distance from to the closest center
-
smallest covering radius
-
Task: Find a set of centers that minimizes , subject to .
-
Number of candidate centers
A Greedy Solution
- Put the first center at the best possible location for a single center, and then keep adding centers so as to reduce the covering radius each time by as much as possible.
1 | Centers Greedy-2r ( Sites S[ ], int n, int K, double r ) |