The Design of Approximation Algorithms 第三章学习笔记

Study Notes Approx Alg

有些 NP-hard problem 在 input data 以 unaray 的形式表达时,可以使用 dynamic programming 在以 input size 为自变量的 polynomial time 解决,此时的 algorithm 被称为是 pseudopolynomial1 的。通过 rounding input value 可以得到一个 polynomial in the input size 的 approximation algorithm.

对于其他 problem, 则通常将 input instance 分为 “large” 和 “small” 两个部分,对 large input 进行 rounding, 然后使用 DP 在 polynomial-time 单独求解得到一个存在 error parameter 的 solution, 再通过一些方式结合 small input 得到最终的 solution.

The knapsack problem

给定 item 的集合 I={1,,n}I = \{1, \dots, n\}, 每个 item 有 value viv_{i} 与 size sis_{i}, 所有 value 与 size 都是正整数。knapsack 的容量为 BB, 也是一个正整数。要求出 item 的子集 SIS \subseteq I, 满足 iSsiB\sum_{i \in S}s_{i} \leq B, 使得 iSvi\sum_{i \in S}v_{i} 最大。

经典的 DP 算法如下:

Theorem 3.1

Algorithm 3.1 correctly computes the optimal value of the knapsack problem.

Algorithm 3.1 的时间复杂度为 O(nmin(B,V))O(n \min(B, V)), 其中 V=iIviV =\sum_{i \in I}v_{i}. 若所有 input 都用 binary 编码,此时 input BB 的 size 为 log2B\log_{2} B, O(nB)=O(n2log2B)O(nB)=O\left(n 2^{\log_{2}B}\right) 为 input number BB 的 exponential, 因此并不是 polynomial in input size.

Definition 3.2

An algorithm for a problem Π\Pi is said to be pseudopolynomial if its running time is polynomial in the size of of the input when the numneric part of the input is encoded in unary.

VVnn 的 polynomial, 那么 O(nmin(B,V))O(n \min(B, V)) 就会是 nn 的 polynomial. 我们可以通过将 viv_{i} round 到 nn 的 polynomial 来得到一个真正的 polynomial-time (但是 approximation) algorithm, 合适的 rounding 技巧可以使结果的误差较小。

Definition 3.3

A polynomial-time approximation scheme (PTAS) is a family of algorithms {Aϵ}\{A_{\epsilon}\}, where there is an algorithm for each ϵ>0\epsilon > 0, such that AϵA_{\epsilon} is a (1+ϵ)(1 + \epsilon)-approximation algorithm (for minimization problems) or a (1ϵ)(1 - \epsilon)-approximation algorithm (for maximization problems).

AϵA_{\epsilon} 的 running time 会取决于 1/ϵ1 / \epsilon, 一般考虑在 1/ϵ1 / \epsilon 上有较好的 bound 的 algorithm:

Definition 3.4

A fully polynomial-time approximation scheme (FPAS, FPTAS) is an approximation scheme such that the running time of AϵA_{\epsilon} is bounded by a polynomial in 1/ϵ1 / \epsilon.

下面给出一个 knapsack problem 的 FPAS. 考虑用一个与 nn 有关 (polynomial in nn) 的数 μ\mu 来估计 viv_{i}, 将 viv_{i} round 到 vi=vi/μv_{i}'=\lfloor v_{i} / \mu \rfloor, 然后跑 Algorithm 3.1 得到 item 集合 SS', 最终算法得到的解即为 iSvi\sum_{i \in S'}v_{i}.

记最优解得到的 item 集合为 SS, 则 μiSviOPTnμ\mu\sum_{i \in S}v_{i}' \geq \mathrm{OPT}-n\mu, 由于 SS' 为此时的最优解,因此有 μiSviμiSviOPTnμ\mu \sum_{i \in S'}v_{i}' \geq \mu \sum_{i \in S}v_{i}' \geq \mathrm{OPT} - n \mu, 又 μiSviiSvi\mu \cdot \sum_{i \in S'}v_{i}' \leq \sum_{i \in S'}v_{i}, 因此得到的解与 OPT\mathrm{OPT} 的差不超过 nμn \mu. 由于算法(需要)是 (1ϵ)(1-\epsilon)-approximation, 因此解与 OPT\mathrm{OPT} 的差不应超过 ϵOPT\epsilon \mathrm{OPT}. 记 M=maxiIviM = \max_{i \in I}v_{i}, 则显然有 OPTM\mathrm{OPT} \geq M, 不妨令 nμ=ϵMn \mu = \epsilon M 控制误差恒不超过 ϵM\epsilon M, 得到 μ=ϵM/n\mu = \epsilon M / n, 于是 vi=viϵM/nv_{i}' = \lfloor \frac{v_{i}}{\epsilon M / n} \rfloor.

此时有 V=i=1nvi=i=1nviϵM/n=O(n2/ϵ)V'=\sum_{i=1}^n v_{i}' = \sum_{i=1}^n \lfloor \frac{v_{i}}{\epsilon M / n} \rfloor = O(n^2 / \epsilon), 算法的时间复杂度为 O(nmin(B,V))=O(n3/ϵ)O(n \min(B, V')) = O(n^{3} / \epsilon), 满足 bounded by a polynomial in 1/ϵ1 / \epsilon.

Theorem 3.5

Algorithm 3.2 is a fully polynomial-time approximation scheme for the knapsack problem.

Proof.\textit{Proof}. 只需证明算法是 (1ϵ)(1-\epsilon)-approximation 即可。通过下列不等式可以证明:

iSviμiSviμiSviiSvinμ=OPTϵMOPTϵOPT=(1ϵ)OPT\begin{aligned} \sum_{i \in S'}v_{i} &\geq \mu\sum_{i \in S'}v_{i}'\\ &\geq \mu \sum_{i \in S}v_{i}'\\ &\geq \sum_{i \in S}v_{i} - n\mu \\ &= \mathrm{OPT} - \epsilon M\\ &\geq \mathrm{OPT} - \epsilon \mathrm{OPT}\\ &= (1-\epsilon)\mathrm{OPT} \end{aligned}

Scheduling jobs on identical parallel machines

不难想到将 job 分为 short job 和 long job, 然后对数量被限制到常数级别的 long job 求出 optimal schedule, 再将 short job 按照 list scheduling 加入当前 schedule 中。

具体来说,将 pi1kmi=1npip_{i} \geq \frac{1}{km} \sum_{i=1}^{n} p_{i}2 的 job 视为 long job, 则 long job 至多有 kmkm 个,其中 kk 为常数,若假定 mm 也是常数,那么 long job 的数量也是常数级别,此时可以直接暴力求出 optimal schedule for long jobs, 总的状态数为 O(mkm)O(m^{km}) 为常数,然后对 short jobs 从大到小排序后按照 list scheduling 加入 schedule 得到最终的 schedule, 最后的时间复杂度为 O(nlogn+mkm)=O(nlogn)O(n\log n + m^{km})=O(n\log n), 瓶颈在于排序,显然属于 polynomial-time algorithm. 记此类算法为 {Ak}\{ A_{k} \}.

在上一章中 list scheduling 算法有结论

Cmaxp+jpj/m,C_{\max} \leq p_{\ell} + \sum_{j \neq \ell}p_{j} / m,

其中 \ell 为最晚完成的 job. 对于 AkA_{k} 得到的 schedule, 若最晚完成的 job 是 long job, 那么此时的 Cmax=CmaxC_{\max}=C_{\max}^{\ast}; 若最晚完成的 job 是 short job, 根据结论有

Cmaxp+jpj/m1ki=1npi/m+jpj/m(1+1k)i=1npi/m(1+1k)Cmax\begin{aligned} C_{\max} &\leq p_{\ell} + \sum_{j \neq \ell}p_{j} / m \\ &\leq \frac{1}{k}\sum_{i=1}^{n}p_{i} / m + \sum_{j \neq \ell} p_{j} / m \\ &\leq \left( 1 + \frac{1}{k} \right)\sum_{i=1}^{n}p_{i} / m \\ &\leq \left( 1 + \frac{1}{k} \right) C_{\max}^{\ast} \end{aligned}

ϵ=1k\epsilon=\frac{1}{k}, 则 AkA_{k}(1+ϵ)(1+\epsilon)-approximation polynomial-time algorithm.

Theorem 3.6

The family of algorithms {Ak}\{ A_{k} \} is a polynomial-time approximation scheme for the problem of minimizing the makespan on any constant number of identical parallel machines.

如果只在最晚完成的 job 是 long job 时才对 long job 计算 optimal schedule, 否则沿用 knapsack 的 DP 方法计算一个非最优的 schedule, 这样可以移除 mm 是常数的限制。

由于 CmaxC_{\max}^{\ast} 未知,不妨设 target length 为 TT, 令 pjT/kp_{j} \geq T / k 的 job 为 long job, 若设置的 TCmaxT \geq C_{\max}^{\ast}, 此时 long job 的数量相对少,可以利用 DP 在 poly-time 得到一个关于 TT 的近似解,然后便可调小 TT 值;若设置的 T<CmaxT < C_{\max}^{\ast}, 此时 long job 的数量较多,poly-time 内难以找到与 TT 相关的近似解,因此可以 return false 并调大 TT 值,最终会得到一个 Cmax\leq C_{\max}^{\ast}TT 值并由此计算出一个近似解,最后再利用 list scheduling 加入 short job 即可。

记上述算法为 {Bk}\{ B_{k} \}, 具体过程如下:将 long job 的 length round 到最近的 T/k2T / k^{2} 的倍数 iT/k2i \cdot T / k^{2}, 之后只需要关心 ii 而不是 pjp_{j}. 在 target length 为 TT 的设定下,每个 machine 会被分配的 job 至多 T/Tk=kT / \frac{T}{k} = k 个,并且最大的 job 满足 pjTp_{j} \leq T (否则必然有 T<CmaxT < C_{\max}^{\ast}), 因此按照 ii 分类的话 long job 至多可以分为 T/Tk2=k2T / \frac{T}{k^{2}} = k^{2} 类,于是每个 machine 的状态可以用一个 k2k^{2} 维的 vector (s1,s2,,sk2)(s_{1}, s_{2}, \dots, s_{k^{2}}) 表示,当满足下列不等式时称它为 machine configuration:

i=1k2siiT/k2T.\sum_{i=1}^{k^{2}}s_{i} \cdot i T / k^{2} \leq T.

记所有 machine conofiguration 构成的集合为 C\mathcal{C}, 则 C(k+1)k2\lvert \mathcal{C} \rvert \leq (k+1)^{k^{2}}, 为常数级别。

然后 DP (类似分组背包) 的状态方程为

OPT(n1,,nk2)=1+min(s1,,sk2)COPT(n1s1,,nk2sk2).\mathrm{OPT}(n_{1}, \dots, n_{k^{2}}) = 1 + \min_{(s_{1}, \dots, s_{k^{2}}) \in \mathcal{C}} \mathrm{OPT}(n_{1} - s_{1}, \dots, n_{k^{2}} - s_{k^{2}}).

可以在 O(mC)O(m \cdot \lvert \mathcal{C} \rvert) 时间内求出 round 后的最优解。由于限定了单个 machine 的 load T\leq T, 设该解在任意 machine 上分配的 job 集合为 SS, 有 Sk\lvert S \rvert \leq k, 且单个 job 满足 pjpjT/k2p_{j} - p_{j}' \leq T / k^{2}, 所以有

jSpjT+kT/k2=(1+1k)T.\sum_{j \in S}p_{j} \leq T + k\cdot T / k^{2} = \left( 1 + \frac{1}{k} \right) T.

于是 DP 的近似解满足 Cmax(1+1k)TC_{\max}' \leq \left( 1 + \frac{1}{k} \right)T, 且如果 T<CmaxT < C_{\max}^{\ast} 就无法找到合法的解,最后加上 short job 不难证明在最后完成的 job 是 short job 时,由于 j=1npj/mT\sum_{j=1}^{n}p_{j} / m \leq T, 于是

Cmaxp+jpj/mT/k+T=(1+1k)T.\begin{aligned} C_{\max} &\leq p_{\ell} + \sum_{j \neq \ell}p_{j} / m \\ &\leq T / k + T \\ &= \left( 1 + \frac{1}{k} \right) T. \end{aligned}

因此,{Bk}\{ B_{k} \} 会在 poly-time 内要么返回 TT 无解要么返回 Cmax(1+1k)TC_{\max} \leq \left( 1 + \frac{1}{k} \right)T 的解。

L0=max{j=1npj/m,maxj=1,,npj},R0=j=1npj/m+maxj=1,,npj,L_{0} = \max \left\{ \left\lceil \sum_{j=1}^{n} p_{j} / m \right\rceil, \max_{j=1, \dots, n} p_{j} \right\}, R_{0} = \left\lceil \sum_{j=1}^{n} p_{j} / m \right\rceil + \max_{j=1, \dots, n} p_{j},

作为 TT 的上下界然后二分即可,最后得到的 TCmaxT \leq C_{\max}^{\ast}, 因此 {Bk}\{ B_{k} \} 可以给出 Cmax(1+1k)CmaxC_{\max} \leq \left( 1 + \frac{1}{k} \right)C_{\max}^{\ast} 的解,再令 ϵ=1k\epsilon = \frac{1}{k}, 于是 {Bk}\{ B_{k} \}(1+ϵ)(1 + \epsilon)-approximation poly-time algorithm.

Theorem 3.7

There is a polynomial-time approximation scheme for the problem of minimizing the makespan on an input number of identical parallel machines.

由于 DP 的状态数为 O((k+1)k2)O\left((k+1)^{k^{2}}\right), 即 exponential in O(1/ϵ2)O\left(1 / \epsilon^{2}\right), 因此 {Bk}\{ B_{k} \} 并不是 FPAS.

事实上,这个 scheduling problem 是 strongly NP-complete 的:即使将每个 job 的 processing time 限制为 q(n)q(n), 在这个特殊情况下也依旧是 NP-complete 的。若存在解决该 scheduling problem 的 FPTAS, 那么就可以令 k=2nq(n)2nPk=\lceil 2nq(n) \rceil \geq 2nP, 其中 P=maxj=1,,npjP = \max_{j=1, \dots, n}p_{j}, 于是算法的解满足 Cmax(1+1k)CmaxCmax+12C_{\max} \leq \left( 1 + \frac{1}{k} \right)C_{\max}^{\ast} \leq C_{\max}^{\ast} + \frac{1}{2}, 由于 Cmax,CmaxC_{\max}, C_{\max}^{\ast} 为整数,因此 Cmax=CmaxC_{\max} = C_{\max}^{\ast}, 从而存在算法在 poly-time 解决 processing time 被限制为 q(n)q(n) 的 scheduling problem, 从而可以推出 P=NP\mathrm{P=NP}.

一个更 general 的结论是:对于任意优化问题,若该问题是 strongly NP-complete 的,那么它不存在 FPAS.

The bin-packing problem

bin-packing problem 指的是下列问题:

给定 nn 个大小分别为 a1,a2,,ana_{1}, a_{2}, \dots, a_{n} 的 pieces (或 items), 满足

1>a1a2an>0;1 > a_{1} \geq a_{2} \geq \cdots \geq a_{n} > 0;

我们希望将这些 pieces 装进尽可能少的 bins, 其中每个 bin 的容量为 1.

bin-packing problem 的特殊情形下可以转化为 partition problem: 给定 nn 个正整数 b1,,bnb_{1}, \dots, b_{n} 满足 B=i=1nbiB=\sum_{i=1}^n b_{i} 为偶数,问能否将下标集合 {1,,n}\{ 1,\dots,n \} 划分为集合 SSTT 使得 iSbi=iTbi\sum_{i \in S}b_{i} = \sum_{i \in T}b_{i}.

只需令 ai=2bi/Ba_{i}=2b_{i} / B 并检查能否装进 2 个 bin 即可将 bin-packing problem 转化为 partition problem. 由于 partition problem 是 NP-complete 的,于是有下列 theorem.

Theorem 3.8

Unless P=NP\mathrm{P=NP}, there cannot exist a ρ\rho-approximation algorithm for the bin-packing problem for any ρ<3/2\rho < 3 / 2.

FFD(I)\mathrm{FFD}(I) 为 First-Fit-Descreasing 算法运行在 instance II 时得到的需要的 bin 的数量,OPT(I)\mathrm{OPT}(I) 表示 II 最少需要的 bin 数量,有证明表示,对于任意 instance II 都有 FFD(I)(11/9)OPT(I)+4\mathrm{FFD}(I) \leq (11 / 9) \mathrm{OPT}(I) + 4.

事实上,如果允许存在 small additive terms, 我们可以找到算法使得它得到的 packing 不会使用超过 OPT(I)+1\mathrm{OPT}(I)+1 个 bin.

尽管有 Theorem 3.8 的结论,bin-packing problem 在允许 small additive terms 时却可以做到优化乘法系数是因为它没有 rescaling property, 即对于任意 input II 和任意值 K\mathcal{K}, 可以构造一个等价的 instance II' 使得 objective function value of any feasible solution is rescaled by K\mathcal{K}.

前面讨论的所有 weighted problem 都拥有 rescaling property, ρOPT+c\rho \mathrm{OPT}+c 的 solution 都可以等价转化得到一个 ρ\rho-approximation 算法,例如 Section 3.2 中的 scheduling problem 若将所有 pjp_{j} 乘上系数 K\mathcal{K} 就能利用结果是整数的特性摆脱 additive terms. 因此只需考虑 no additive terms 的情形即可。

下面设计一系列 poly-time approx algorithms parameterized by ϵ>0\epsilon > 0, 其中每个算法都在任意 input II 下保证得到的 packing 所需 bin 数量不超过 (1+ϵ)OPT(I)+1(1+\epsilon)\mathrm{OPT}(I) + 1. 这样的算法不满足 PTAS 的定义,这启发了下列定义。

Definition 3.9

An asymptotic polynomial-time approximation scheme (APTAS) is a family of algorithms AϵA_{\epsilon} along with a constant cc where there is an algorithm AϵA\epsilon for each ϵ>0\epsilon > 0 such that AϵA\epsilon returns a solution of value at most (1+ϵ)OPT+c(1+\epsilon)\mathrm{OPT}+c for minimization problems.

bin-packing problem 与前面 scheduling problem 中关于 TT 的 decision problem 部分十分相似,不难想到用相同的 DP 来解决 bin-packing problem. 这要求:

  • pjp_{j} 除以 TT 得到 input for bin-packing problem
  • 不同的 piece size 数量需要是常数
    • 利用 linear grouping scheme
  • 每个 bin 能放入的 piece 数量是常数
    • 仅对 size 较大的 piece 进行 DP

具体而言,设定 threshold γ\gamma, 仅对 aiγa_{i} \geq \gamma 的 piece 进行 DP, 令 SIZE(I)=i=1nai\mathrm{SIZE}(I)=\sum_{i=1}^n a_{i}, 则需要 DP 的 piece 不超过 SIZE(I)/γ\mathrm{SIZE}(I) / \gamma 个,lemma 3.10 表明加入 small pieces 后结果的上界:

Lemma 3.10

Any packing of all pieces of size greater than γ\gamma into \ell bins can be extended to a packing for the entire input with at most max{,11γSIZE(I)+1}\max\left\{ \ell, \frac{1}{1-\gamma}\mathrm{SIZE}(I) + 1 \right\} bins.

Lemma 3.10 的证明依赖于 First-Fit algorithm,记 First-Fit 算法的结果为 FF(I)\mathrm{FF}(I), 这里不妨先证明 FF(I)2OPT(I)+1\mathrm{FF}(I) \leq 2\mathrm{OPT}(I)+1. 假设已经使用了 \ell 个 bin, 当前 piece 被放入第 +1\ell+1 个 bin 当且仅当前 \ell 个 bin 都放不下该 piece, 对于单个 bin 的情况不方便分析,但是两个 bin 结合起来就可以发现它们满足一些有用的 property:将 bin 1 和 bin 2 结合,bin 3 和 bin 4 结合,如此下去,当且仅当前 2k12k-1 个 bin 无法放入当前 piece 时会开启第 2k2k 个 bin, 因此这之后第 2k12k-1 个 bin 与第 2k2k 个 bin 所使用的容量之和必然 >1> 1, 从而若一共使用了 \ell 个 bin, 那么有 SIZE(I)/2\mathrm{SIZE}(I) \geq \lfloor \ell / 2 \rfloor, 于是 FF(I)2OPT(I)+1\mathrm{FF}(I) \leq 2\mathrm{OPT}(I)+1.

Proof of Lemma 3.10.\textit{Proof of Lemma 3.10}. 考虑 small pieces 按照 First-Fit 放入。若所有 small pieces 都被放入了原有的 \ell bins 中,那么答案显然是 \ell. 若当前的 small piece 被放入了一个新的 bin, 不妨设为第 k+1k+1 个 bin, 那么前 kk 个 bin 的剩余容量都 1γ\leq 1 - \gamma, 这样的 bin 至多有 11γSIZE(I)\frac{1}{1-\gamma}\mathrm{SIZE}(I) 个,于是答案至多为 11γSIZE(I)+1\frac{1}{1-\gamma}\mathrm{SIZE}(I)+1, 得证。

若我们希望设计的算法的 performance guarantee 为 1+ϵ1+\epsilon with 0<ϵ<10 < \epsilon < 1, 可以令 γ=ϵ/2\gamma=\epsilon / 2, 于是 1/(1ϵ/2)1+ϵ1 / (1 - \epsilon / 2) \leq 1 + \epsilon, 又有 SIZE(I)OPT(I)\mathrm{SIZE}(I) \leq \mathrm{OPT}(I), 从而最终的 composite algorithm 可以得到至多包含 max{,(1+ϵ)OPT(I)+1}\max\{ \ell, (1+\epsilon)\mathrm{OPT}(I) + 1 \} 个 bin 的 packing.

然后将这部分需要 DP 的 piece 按照 size 从大到小每个 kk 个分为一组, 最后一组的 piece 数量记为 hkh \leq k 个,再按照 Section 3.2 中的方式进行 DP, linear grouping 后的最优解与 grouping 前的最优解的大小关系如下:

Lemma 3.11

Let II' be the input obtained from an input II by applying linear grouping with group size kk. Then

OPT(I)OPT(I)OPT(I)+k,\mathrm{OPT}(I') \leq \mathrm{OPT}(I) \leq \mathrm{OPT}(I') + k,

and furthermore, any packing of II' can be used to generate a packing of II with at most kk additional bins.

Proof idea.\textit{Proof idea.} 从下图看很显然

最后分析算法性能来设定 kk. II' 包含不同 size 的数量至多为 n/kn / k, 其中 nnII 中 piece 的数量,而 II 中去除了 small pieces, 从而 SIZE(I)ϵn/2\mathrm{SIZE}(I) \geq \epsilon n / 2. 令 k=ϵSIZE(I)k=\lfloor \epsilon \mathrm{SIZE}(I) \rfloor, 于是 n/k2n/(ϵSIZE(I))4/ϵ2n / k \leq 2n / (\epsilon \mathrm{SIZE}(I)) \leq 4 / \epsilon^{2}, 当 ϵSIZE(I)<1\epsilon \mathrm{SIZE}(I) < 1 时 large pieces 足够少可以直接 DP, 因此这里假定了 ϵSIZE(I)1\epsilon \mathrm{SIZE}(I) \geq 1. 再结合 Lemma 3.10, 最终的 bin 数量不会超过 (1+ϵ)OPT(I)+1(1+\epsilon)\mathrm{OPT}(I) + 1.

Theorem 3.12

For any ϵ>0\epsilon > 0, there is a polynomial-time algorithm for the bin-packing problem that computes a solution with at most (1+ϵ)OPT(I)+1(1+\epsilon)\mathrm{OPT}(I)+1 bins; that is, there is an APTAS for the bin-packing problem.


  1. 1.Wikipedia 上的解释: Pseudo-polynomial time.
  2. 2.符号设定沿用 Chapter 2.

Author: f1a3h

Permalink: https://blog.rbkou.me/Study-Notes/Approx-Alg/tdaa-ch3/

文章默认使用 CC BY-NC-SA 4.0 协议进行许可,使用时请注意遵守协议。

Comments