Algorithm Design (XVII)
Approximation Algorithms IIGuoqiang Li
Bin Packing: Problem Statement
Givennitems with sizesa1, . . . ,an∈(0,1], find a packing inunit-sized bins
An 2-approximation Algorithm
First-Fit Algorithm:
• Consider items inarbitrary order.
• In thei-th step, it has a list of partially packed bins, sayB1, . . . ,Bk. • It attempts to put the next item,ai, in one of these bins, in this order. • Ifai does not fit into any of these bins, it opens anewbinBk+1, and puts
An 2-approximation Algorithm
First-Fit Algorithm:
• Consider items inarbitrary order.
• In thei-th step, it has a list of partially packed bins, sayB1, . . . ,Bk. • It attempts to put the next item,ai, in one of these bins, in this order. • Ifai does not fit into any of these bins, it opens anewbinBk+1, and puts
An 2-approximation Algorithm
First-Fit Algorithm:
• Consider items inarbitrary order.
• In thei-th step, it has a list ofpartially packed bins, sayB1, . . . ,Bk.
• It attempts to put the next item,ai, in one of these bins, in this order. • Ifai does not fit into any of these bins, it opens anewbinBk+1, and puts
An 2-approximation Algorithm
First-Fit Algorithm:
• Consider items inarbitrary order.
• In thei-th step, it has a list ofpartially packed bins, sayB1, . . . ,Bk. • It attempts to put the next item,ai, in one of these bins, in this order.
• Ifai does not fit into any of these bins, it opens anewbinBk+1, and puts ai in it.
An 2-approximation Algorithm
First-Fit Algorithm:
• Consider items inarbitrary order.
• In thei-th step, it has a list ofpartially packed bins, sayB1, . . . ,Bk. • It attempts to put the next item,ai, in one of these bins, in this order. • Ifai does not fit into any of these bins, it opens anewbinBk+1, and puts
Analysis
If the algorithm usesmbins, thenat leastm−1bins aremore than half full. Therefore, n X i=1 ai >m−1 2
Since the sum of the item sizes is alower boundonOPT,m−1<2·OPT, i.e.,m≤2·OPT.
Analysis
If the algorithm usesmbins, thenat leastm−1bins aremore than half full.
Therefore, n X i=1 ai >m−1 2
Since the sum of the item sizes is alower boundonOPT,m−1<2·OPT, i.e.,m≤2·OPT.
Analysis
If the algorithm usesmbins, thenat leastm−1bins aremore than half full. Therefore, n X i=1 ai >m−1 2
Since the sum of the item sizes is alower boundonOPT,m−1<2·OPT, i.e.,m≤2·OPT.
Analysis
If the algorithm usesmbins, thenat leastm−1bins aremore than half full. Therefore, n X i=1 ai >m−1 2
Since the sum of the item sizes is alower boundonOPT,m−1<2·OPT, i.e.,m≤2·OPT.
A Hardness Result
For any > 0, there is noapproximation algorithmhaving a guarantee of3/2−for the bin packing problem, assumingP=NP.
Theorem
Proof.
If there were such an algorithm, then theNPC problemof deciding if there is a way to partitionn nonnegative numbersa1, . . . ,an into two sets, each adding up to1/2P
iai.
The answer to this question is “yes” iff thenitems can be packed in2bins of size1/2P
iai.
If the answer is “yes” the3/2−factor algorithm will have to give an optimal packing.
A Hardness Result
For any > 0, there is noapproximation algorithmhaving a guarantee of3/2−for the bin packing problem, assumingP=NP.
Theorem
Proof.
If there were such an algorithm, then theNPC problemof deciding if there is a way to partitionn nonnegative numbersa1, . . . ,an into two sets, each adding up to1/2P
iai.
The answer to this question is “yes” iff thenitems can be packed in2bins of size1/2P
iai.
If the answer is “yes” the3/2−factor algorithm will have to give an optimal packing.
A Hardness Result
For any > 0, there is noapproximation algorithmhaving a guarantee of3/2−for the bin packing problem, assumingP=NP.
Theorem
Proof.
If there were such an algorithm, then theNPC problemof deciding if there is a way to partitionnnonnegative numbersa1, . . . ,an into two sets, each adding up to1/2P
iai.
The answer to this question is “yes” iff thenitems can be packed in2bins of size1/2P
iai.
If the answer is “yes” the3/2−factor algorithm will have to give an optimal packing.
A Hardness Result
For any > 0, there is noapproximation algorithmhaving a guarantee of3/2−for the bin packing problem, assumingP=NP.
Theorem
Proof.
If there were such an algorithm, then theNPC problemof deciding if there is a way to partitionnnonnegative numbersa1, . . . ,an into two sets, each adding up to1/2P
iai.
The answer to this question is “yes” iff thenitems can be packed in2bins of size1/2P
iai.
If the answer is “yes” the3/2−factor algorithm will have to give an optimal packing.
A Hardness Result
For any > 0, there is noapproximation algorithmhaving a guarantee of3/2−for the bin packing problem, assumingP=NP.
Theorem
Proof.
If there were such an algorithm, then theNPC problemof deciding if there is a way to partitionnnonnegative numbersa1, . . . ,an into two sets, each adding up to1/2P
iai.
The answer to this question is “yes” iff thenitems can be packed in2bins of size1/2P
iai.
If the answer is “yes” the3/2−factor algorithm will have to give an optimal packing.
APTAS
Anasymptotic polynomial-time approximation scheme (APTAS)is a
family of algorithm{A}along with a constantc where there is an algorithmA for each > 0such thatA returns a solution of valueat
most(1+)OPT+c for minimization problems. Definition
An APTAS for Bin-Packing
For any,0< ≤1/2, there is an algorithmAthat runs in time polynomial innand finds a packing using at most(1+2)OPT+1bins.
An APTAS for Bin-Packing
For any,0< ≤1/2, there is an algorithmAthat runs in time polynomial innand finds a packing using at most(1+2)OPT+1bins.
Instances with Large Items
Let >0be fixed, and let K be a fixed nonnegative integer. Consider the restriction of the bin packing problem to instances in which each item isof size at leastand the number of distinct item sizes isK. There isa polynomial time algorithm that optimally solves
this restricted problem. Lemma
Instances with Large Items
Proof.
The number of items in a bin is bounded byb1/c. Denote this byM. Therefore, the number of different bin types is bounded by
R= M+K M
!
which is alargeconstant.
The total number of bins used is at mostn. Therefore, the number of possible feasible packings is bounded by
P= n+R R
!
which ispolynomial inn.
Instances with Large Items
Proof.
The number of items in a bin is bounded byb1/c. Denote this byM. Therefore, the number of different bin types is bounded by
R= M+K M
!
which is alargeconstant.
The total number of bins used is at mostn. Therefore, the number of possible feasible packings is bounded by
P= n+R R
!
which ispolynomial inn.
Instances with Large Items
Proof.
The number of items in a bin is bounded byb1/c. Denote this byM. Therefore, the number of different bin types is bounded by
R= M+K M
!
which is alargeconstant.
The total number of bins used is at mostn. Therefore, the number of possible feasible packings is bounded by
P= n+R R
!
Instances with Large Items
Proof.
The number of items in a bin is bounded byb1/c. Denote this byM. Therefore, the number of different bin types is bounded by
R= M+K M
!
which is alargeconstant.
The total number of bins used is at mostn. Therefore, the number of possible feasible packings is bounded by
P= n+R R
!
which ispolynomial inn.
k Composition ofM
x1+x2+. . .+xk=M
• k composition ofM: xi ≥1
k Composition ofM
x1+x2+. . .+xk=M
• k composition ofM: xi≥1
k Composition ofM x1+x2+. . .+xk=M • k composition ofM: xi≥1 M−1 k−1 ! • weakkcomposition ofM: xi≥0
k Composition ofM x1+x2+. . .+xk=M • k composition ofM: xi≥1 M−1 k−1 ! • weakkcomposition ofM: xi≥0
k Composition ofM x1+x2+. . .+xk=M • k composition ofM: xi≥1 M−1 k−1 ! • weakkcomposition ofM: xi≥0 M+k−1 k−1 !
Removing the Restriction of K
Let > 0be fixed. Consider the restriction of the bin packing problem to instances in which each item is of size at least. There is a polyno-mial time approximation algorithmthat solves this restricted problem
within a factor of(1+). Lemma
Removing the Restriction of K
LetI denote the given instance. Sort thenitems byincreasing size, and partition them intoK =d1/2egroups each having at mostQ=bn2citems. Notice that two groups may contain items of the same size.
Removing the Restriction of K
Construct instanceJbyrounding upthe size of each item to the size of the largest item in its group. InstanceJ has at mostK different item sizes. Then we can find anoptimal packingforJ, this will also be a valid packing for the original item size.
We will show that
Removing the Restriction of K
Construct instanceJbyrounding upthe size of each item to the size of the largest item in its group. InstanceJ has at mostK different item sizes.
Then we can find anoptimal packingforJ, this will also be a valid packing for the original item size.
We will show that
Removing the Restriction of K
Construct instanceJbyrounding upthe size of each item to the size of the largest item in its group. InstanceJ has at mostK different item sizes. Then we can find anoptimal packingforJ, this will also be a valid packing for the original item size.
We will show that
Removing the Restriction of K
Construct instanceJbyrounding upthe size of each item to the size of the largest item in its group. InstanceJ has at mostK different item sizes. Then we can find anoptimal packingforJ, this will also be a valid packing for the original item size.
We will show that
Removing the Restriction of K
Construct instanceJbyrounding upthe size of each item to the size of the largest item in its group. InstanceJ has at mostK different item sizes. Then we can find anoptimal packingforJ, this will also be a valid packing for the original item size.
We will show that
Proof
Let us construct another instance, sayJ0, byrounding downthe size of each item to that of the smallest item in its group.
ClearlyOPT(J0)≤OPT(I).
The crucial observation is that a packing for instanceJyields a packing for all but the largestQ items of instanceJ. Therefore,
OPT(J)≤OPT(J0) +Q≤OPT(I) +Q Since each item inI has size at least,OPT(I)≥n. Therefore
Proof
Let us construct another instance, sayJ0, byrounding downthe size of each item to that of the smallest item in its group.
ClearlyOPT(J0)≤OPT(I).
The crucial observation is that a packing for instanceJyields a packing for all but the largestQ items of instanceJ. Therefore,
OPT(J)≤OPT(J0) +Q≤OPT(I) +Q Since each item inI has size at least,OPT(I)≥n. Therefore
Proof
Let us construct another instance, sayJ0, byrounding downthe size of each item to that of the smallest item in its group.
ClearlyOPT(J0)≤OPT(I).
The crucial observation is that a packing for instanceJyields a packing for all but the largestQ items of instanceJ. Therefore,
OPT(J)≤OPT(J0) +Q≤OPT(I) +Q Since each item inI has size at least,OPT(I)≥n. Therefore
Proof
Let us construct another instance, sayJ0, byrounding downthe size of each item to that of the smallest item in its group.
ClearlyOPT(J0)≤OPT(I).
The crucial observation is that a packing for instanceJyields a packing for all but the largestQ items of instanceJ. Therefore,
OPT(J)≤OPT(J0) +Q≤OPT(I) +Q Since each item inI has size at least,OPT(I)≥n. Therefore
Proof
Let us construct another instance, sayJ0, byrounding downthe size of each item to that of the smallest item in its group.
ClearlyOPT(J0)≤OPT(I).
The crucial observation is that a packing for instanceJyields a packing for all but the largestQ items of instanceJ. Therefore,
OPT(J)≤OPT(J0) +Q≤OPT(I) +Q
Since each item inI has size at least,OPT(I)≥n. Therefore Q=bn2c ≤OPT(I). Hence,OPT(J)≤(1+)OPT(I).
Proof
Let us construct another instance, sayJ0, byrounding downthe size of each item to that of the smallest item in its group.
ClearlyOPT(J0)≤OPT(I).
The crucial observation is that a packing for instanceJyields a packing for all but the largestQ items of instanceJ. Therefore,
OPT(J)≤OPT(J0) +Q≤OPT(I) +Q Since each item inI has size at least,OPT(I)≥n. Therefore
The Algorithm
Now we present theAPTASalgorithm for Bin-Packing.
• LetI denote the given instance, andI0denote the instance obtained by discarding items of size< fromI.
• By previous lemma, we can find a packing forI0using at most (1+)OPT(I0)bins.
• Next, we start packing the small items (of size< ) in aFirst-Fit manner
in the bins opened for packingI. Additional bins are opened if an item does not fit into any of the already open bins.
The Algorithm
Now we present theAPTASalgorithm for Bin-Packing.
• LetI denote the given instance, andI0denote the instance obtained by discarding items of size< fromI.
• By previous lemma, we can find a packing forI0using at most (1+)OPT(I0)bins.
• Next, we start packing the small items (of size< ) in aFirst-Fit manner
in the bins opened for packingI. Additional bins are opened if an item does not fit into any of the already open bins.
The Algorithm
Now we present theAPTASalgorithm for Bin-Packing.
• LetI denote the given instance, andI0denote the instance obtained by discarding items of size< fromI.
• By previous lemma, we can find a packing forI0using at most (1+)OPT(I0)bins.
• Next, we start packing the small items (of size< ) in aFirst-Fit manner
in the bins opened for packingI. Additional bins are opened if an item does not fit into any of the already open bins.
The Algorithm
Now we present theAPTASalgorithm for Bin-Packing.
• LetI denote the given instance, andI0denote the instance obtained by discarding items of size< fromI.
• By previous lemma, we can find a packing forI0using at most (1+)OPT(I0)bins.
• Next, we start packing the small items (of size< ) in aFirst-Fit manner
in the bins opened for packingI. Additional bins are opened if an item does not fit into any of the already open bins.
Analysis
If no additional bins are needed, then we have a packing in (1+)OPT(I0)≤(1+)OPT(I)bins.
In the second case, letM be the total number of bins used. Clearly, all but the last bin must be full to the extent of at least1−.
Therefore, the sum of the item sizes inI is at least(M−1)(1−). Since this
Analysis
If no additional bins are needed, then we have a packing in (1+)OPT(I0)≤(1+)OPT(I)bins.
In the second case, letM be the total number of bins used. Clearly, all but the last bin must be full to the extent of at least1−.
Therefore, the sum of the item sizes inI is at least(M−1)(1−). Since this
Analysis
If no additional bins are needed, then we have a packing in (1+)OPT(I0)≤(1+)OPT(I)bins.
In the second case, letM be the total number of bins used. Clearly, all but the last bin must be full to the extent of at least1−.
Therefore, the sum of the item sizes inI is at least(M−1)(1−). Since this
Analysis
If no additional bins are needed, then we have a packing in (1+)OPT(I0)≤(1+)OPT(I)bins.
In the second case, letM be the total number of bins used. Clearly, all but the last bin must be full to the extent of at least1−.
Therefore, the sum of the item sizes inI is at least(M−1)(1−). Since this
Analysis
M≤ OPT
(1−)+1≤(1+2)OPT+1
where we have used the assumption that≤1/2.
Hence, for each value of,0< ≤1/2, we have a polynomial time algorithm achieving a guarantee of(1+2)OPT+1.
Analysis
M≤ OPT
(1−)+1≤(1+2)OPT+1
where we have used the assumption that≤1/2.
Hence, for each value of,0< ≤1/2, we have a polynomial time algorithm achieving a guarantee of(1+2)OPT+1.
Analysis
M≤ OPT
(1−)+1≤(1+2)OPT+1
where we have used the assumption that≤1/2.
Hence, for each value of,0< ≤1/2, we have a polynomial time algorithm achieving a guarantee of(1+2)OPT+1.
Summary of Algorithm
AlgorithmA is summarized below.
1. Remove items of size< .
2. Round to obtain constant number of item sizes.
3. Find optimal packing.
4. Use this packing for original item sizes.
Summary of Algorithm
AlgorithmA is summarized below.
1. Remove items of size< .
2. Round to obtain constant number of item sizes.
3. Find optimal packing.
4. Use this packing for original item sizes.
Summary of Algorithm
AlgorithmA is summarized below.
1. Remove items of size< .
2. Round to obtain constant number of item sizes.
3. Find optimal packing.
4. Use this packing for original item sizes.