# Project Management Chapter 6 3 More approximation algorithms Dept

Document Sample

```					                            Chapter 6.3

More approximation algorithms

Dept of Computer Science, University of Bristol.   COMS21101. Chapter 6.3 Slide 1
Bin Packing
 The bin-packing problem is stated as follows:
 There are n objects whose sizes range between 0
and 1. They have to be packed into bins each of
which has capacity of 1.
 Solution: the minimum number of bins required to
pack the n objects.
 The bin-packing problem has been shown to
be intractable. The number of possible
partitions of the n objects into n or fewer
subsets is exponential in n.
 (see Baase and Van Gelder, chapter 13)

Dept of Computer Science, University of Bristol.   COMS21101. Chapter 6.3 Slide 2
Applications of Bin-packing
Packing data in computers with
minimum empty storage space
placing files in disk blocks/tracks
program segments in memory pages
Filling orders for a product to be cut
from large standard-size pieces
e.g. cutting lengths of fabric or timber with
minimum waste

Dept of Computer Science, University of Bristol.   COMS21101. Chapter 6.3 Slide 3
The First-Fit Strategy
Simple first-fit strategy:
take the objects in any order
place each object in the first bin in which it
fits.
First-fit decreasing (FFD) strategy:
Sort the objects into descending order
Then apply the simple strategy above.

Dept of Computer Science, University of Bristol.   COMS21101. Chapter 6.3 Slide 4
FFD-strategy: example
Given objects
0.4, 0.2, 0.4, 0.8, 0.2, 0.2, 0.5, 0.3
Sorted into decreasing order
0.8, 0.5, 0.4, 0.4, 0.3, 0.2, 0.2, 0.2

0.2
0.2
0.4
0.3
0.8
0.5
0.4
0.2

Note: this is not optimal. The objects would fit into 3 bins.

Dept of Computer Science, University of Bristol.   COMS21101. Chapter 6.3 Slide 5
FFD complexity
 The objects are sorted in O(n log n)
 The first fit strategy is O(n2), since each of the
n objects must be “tried” in at most n bins.
 Hence overall complexity is O(n2), since n2 +
n log n is O(n2).
 It has been proved that the FFD strategy
gives a solution that is at worst about 22%
sub-optimal (i.e. requires at most 22% more
bins than necessary).
In practice, it usually gives solutions much
closer to the optimal one.
Dept of Computer Science, University of Bristol.   COMS21101. Chapter 6.3 Slide 6
Best-fit strategy
Instead of placing an object in the first
bin in which it fits, we could put it in the
fullest of those bins in which it fits.
Intuitively, this “best-fit” strategy might
be expected to give better solutions,
since, it attempts to fill bins as much as
possible.
 However, in practice, it works only about as
well as the FFD strategy.

Dept of Computer Science, University of Bristol.   COMS21101. Chapter 6.3 Slide 7
The Knapsack problem
Given a “knapsack” with capacity C, and
a set of n objects each of which has a
size and a value.
Find the “most valuable” set of objects
that fit in the knapsack.
Applications:
 creating an investment portfolio for a sum of
money C to achieve the greatest profit.
 selecting the most “profitable” tasks, given
available resources C (e.g. on a space flight).

Dept of Computer Science, University of Bristol.   COMS21101. Chapter 6.3 Slide 8
An approximate knapsack algorithm

 We present an algorithm for simple version of the
knapsack algorithm, where we assume that the value
of each object is proportional to its size.
 Hence, we consider only the size.
 The general knapsack algorithm as stated above can
be obtained by extending this simple version (see
Baase and Van Gelder, Chapter 13).

Dept of Computer Science, University of Bristol.   COMS21101. Chapter 6.3 Slide 9
k-th approximation
 Let S be the given set of n objects. Let C be the size
of the knapsack.
 For fixed k < n, we first consider all subsets of S with
at most k elements, whose total size is less than C.
 E.g. for k=2, we consider all pairs of objects that fit in the
knapsack.
 For each subset of k objects which fits in the
knapsack, we then try to fill up the knapsack by
picking the objects in some fixed order until it is full.
 The maximum value so obtained is the k-th
approximation.
 Clearly, by increasing k, we get a better and better
approximation. However, the complexity is O(knk+1)
Dept of Computer Science, University of Bristol.   COMS21101. Chapter 6.3 Slide 10
Algorithm for k-th approximation
knapSack_k(C,S) // S an array with n values (the sizes)
int maxSum, sum, j; // C is the size of the knapsack
Set T = new Set;
take = ; maxSum = 0;
for each subset T  {1,...,n}
with k elements {
sum = the sum of the values S[i] such that i  T;
if (sum  C) {
for each j not in T {
if (sum + S[j]  C){
sum = sum + S[j];
T = T  {j};}
}
if (maxSum < sum) {maxSum = sum}
}
} return maxSum;

Dept of Computer Science, University of Bristol.   COMS21101. Chapter 6.3 Slide 11
Example: 1-approximation
 Consider objects {54,45,43,29,23,21,14,1}
 Let C = 110
 Consider all singleton sets (k=1)

Subset                Objects added by inner “for” loop      sum
{54}                  {45,1}                                 100
{45}                  {54,1}                                 100
{43}                  {54,1}                                 98
{29}                  {54,23,1}                              107
{23}                  {54,29,1}                              107
{21}                  {54,29,1}                              105
{14}                  {54,29,1}                              98
{1}                   {54,45}                                100

Thus maxSum = 107.
Dept of Computer Science, University of Bristol.   COMS21101. Chapter 6.3 Slide 12
Example - continued
 In fact the optimal solution to the above example is
found by the approximation with k=2. Some
examples of the 28 pairs considered are
Subset               Objects added by inner “for” loop sum
{54,45}              {1}                               100
{54,29}              {23,1}                            107
...
{45,43}              {21,1}                                110
{43,29}              {23,14,1}                             110
...
{23,14}              {54,14,1}                             106
...

Since C=110, {45,43,21,1} or {43,29,23,14,1} completely fill the
knapsack and hence either is optimal (assuming size and value are the same).
Dept of Computer Science, University of Bristol.   COMS21101. Chapter 6.3 Slide 13

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 70 posted: 12/26/2011 language: pages: 13