# Online algorithms for 1-space bounded multi dimensional bin packing and hypercube packing

- First Online:

DOI: 10.1007/s10878-012-9457-z

- Cite this article as:
- Zhang, Y., Chin, F.Y.L., Ting, HF. et al. J Comb Optim (2013) 26: 223. doi:10.1007/s10878-012-9457-z

- 3 Citations
- 860 Downloads

## Abstract

In this paper, we study 1-space bounded multi-dimensional bin packing and hypercube packing. A sequence of items arrive over time, each item is a *d*-dimensional hyperbox (in bin packing) or hypercube (in hypercube packing), and the length of each side is no more than 1. These items must be packed without overlapping into *d*-dimensional hypercubes with unit length on each side. In *d*-dimensional space, any two dimensions *i* and *j* define a space *P*_{ij}. When an item arrives, we must pack it into an active bin immediately without any knowledge of the future items, and 90^{∘}-rotation on any plane *P*_{ij} is allowed.

The objective is to minimize the total number of bins used for packing all these items in the sequence. In the 1-space bounded variant, there is only one active bin for packing the current item. If the active bin does not have enough space to pack the item, it must be closed and a new active bin is opened. For *d*-dimensional bin packing, an online algorithm with competitive ratio 4^{d} is given. Moreover, we consider *d*-dimensional hypercube packing, and give a 2^{d+1}-competitive algorithm. These two results are the first study on 1-space bounded multi dimensional bin packing and hypercube packing.

### Keywords

Online algorithmsBin packing1-space boundedMulti dimensional## 1 Introduction

Bin packing is a very fundamental problem in computer science, and has been well studied for more than thirty years. Given a sequence of items, we pack them into unit-size bins without overlapping. The objective is to minimize the number of bins for all items in the sequence.

*asymptotic competitive ratio*. Consider an online algorithm

*A*and an optimal offline algorithm

*OPT*. For any sequence

*S*of items, let

*A*(

*S*) be the cost (number of bins used) incurred by algorithm

*A*and

*OPT*(

*S*) be the corresponding optimal cost incurred by algorithm

*OPT*. The

*asymptotic competitive ratio*for algorithm

*A*is:

In the online bin packing, there are two models: *bounded space model* and *unbounded space model*. If we do not impose a limit on the number of bins available for packing the items (called *active bins*), we call it *unbounded space*. Otherwise, if the number of active bins is bounded by a *constant*, and each item can only be packed into one of the active bins, we call it *bounded space*, which is more realistic in many applications. If none of the active bins has enough space to pack the arrival item, one of the active bins must be closed and a new active bin will be opened to pack that item.

In this paper, we consider *1-space bounded* multi-dimensional bin packing and hypercube packing. In the 1-space bounded variant, the number of active bins is only *one*. If an item cannot be packed into the active bin, we have to close it and open a new bin to pack this item. In the 1-space bounded *d*-dimensional bin packing problem (*d*≥2), each item is a *d*-dimensional hyperbox such that the length on each side is no more than 1, while in the *d*-dimensional hypercube packing, each item is a *d*-dimensional hypercube with side length no more than 1. The items must be packed into *d*-dimensional hypercubes with side length 1. Any two dimensions *i* and *j* define a plane *P*_{ij}. 90^{∘}-rotation of the item in any plane *P*_{ij} is allowed in 1-space bounded bin packing, otherwise, the competitive ratio is unbounded (Fujita 2003).

*A*,

*B*,

*C*and

*D*. After the packing position of

*A*is fixed, we have two choices to pack

*B*: rotation and without rotation. If we pack

*B*without rotation in the same bin with

*A*as shown in Fig. 1(b), when item

*C*arrives, we have to open a new bin since the current active bin does not have enough space for packing

*C*. In the optimal solution, these four items can be packed into one bin (Fig. 1(c)), since item

*B*,

*C*and

*D*can be rotated and the free space in the bin can accommodate all of them in their order of arrival.

### 1.1 Related works

Both the offline and online version of the bin packing problem have been well studied.

The offline bin packing is NP-Hard (Garey and Johnson 1979). For one-dimensional bin packing, Simchi-Levi gave a 1.5-approximation algorithm (Simchi-Levi 1994). Johnson and Garey (1985) gave an asymptotic 71/60-approximation algorithm. An AFPTAS was given by Karmarkar and Karp (1982). For two-dimensional bin packing. Chung et al. (1982) presented an approximation algorithm with an asymptotic performance ratio of 2.125. Caprara (2002) improved the upper bound to 1.69103. Bansal et al. (2006b) devised a randomized algorithm with an asymptotic performance ratio of at most 1.525. As for the offline lower bound of the approximation ratio, Bansal et al. (2006a) showed that the two-dimensional bin packing problem does not admit any asymptotic polynomial time approximation scheme.

The online bin packing has been studied for more than thirty years. For one-dimensional online bin packing, Johnson et al. (1974) showed that the First Fit algorithm (FF) has an asymptotic competitive ratio of 1.7. Yao (1980) improved the algorithm to obtain a better upper bound of 5/3. Lee and Lee (1985) introduced the class of Harmonic algorithms, and showed that an asymptotic competitive ratio of 1.63597 is achievable. Ramanan et al. (1989) further improved the upper bound to 1.61217. The best known upper bound is 1.58889, which was given by Seiden (2002). As for the lower bound of the competitive ratio of one dimensional bin packing, Yao (1980) showed that no online algorithm can have an asymptotic competitive ratio less than 1.5. The best known lower bound is 1.54014 (van Vliet 1992). For two-dimensional online bin packing, Coppersmith and Raghavan (1989) gave the first online algorithm with asymptotic competitive ratio 3.25. Csirik et al. (1993) improved the upper bound to 3.0625. Based on the techniques of the Improved Harmonic, Han et al. (2001) improved the upper bound to 2.7834. Seiden and van Stee (2003) showed an upper bound of 2.66013 by implementing the Super Harmonic Algorithm. The best known upper bound of the competitive ratio for two dimensional bin packing is 2.5545, which was given by Han et al. (201). The best known lower bound is 1.907 (Blitz et al. 1996).

For bounded space online bin packing, Harmonic algorithm by Lee and Lee (1985) can be applied for one dimensional case, the competitive ratio is 1.69103 when the number of active bins goes to infinity. Csirik and Johnson (2001) presented an 1.7-competitive algorithm (*K*-Bounded Best Fit algorithms (*BBF*_{K})) for one dimensional bin packing using *K* active bins, where *K*≥2. For multi-dimensional case, Epstein and van Stee (2005b) gave a 1.69103^{d}-competitive algorithm using (2*M*−1)^{d} active bins, where *M*≥10 is an integer such that *M*≥1/(1−(1−*ε*)^{1/(d+2)})−1, *ε*>0 and *d* is the dimension of the bin packing problem. For the *1-space bounded* variant, Fujita (2003) first gave an *O*((loglog*m*)^{2})-competitive algorithm, where *m* is the width of the square bin and the size of each item is *a*×*b* (*a*, *b* are integers and *a*,*b*≤*m*). Chin et al. (2012) proposed an 8.84-competitive packing strategy, then they further improved the upper bound to 5.155 (Zhang et al. 2010), they also gave the lower bound 3 for 1-space bounded two dimensional bin packing.

For a special case where the items are squares (or hypercubes), there are also many results (Epstein and van Stee 2005a, 2007; Ferreira et al. 1999; Han et al. 2008; Januszewski and Lassak 1997; Leung et al. 1990; Kohayakawa et al. 2004; Meir and Moser 1968). For bounded space online square packing, Epstein and van Stee (2007) gave a 2.3692-competitive algorithm, they also proved that the lower bound of the competitive ratio is at least 2.36343. For bounded space *d*-dimensional hypercube packing, an *O*(*d*/log*d*)-competitive algorithm was given (Epstein and van Stee 2007), however, to achieve this bound, the number of active bins is very large. Moreover, they proved that the asymptotic competitive ratio of bounded space hypercube packing is lower bounded by Ω(log*d*). Januszewski and Lassak (1997) proved that any sequence of square items with a total area of at most 5/16 can be packed into a unit bin. Han et al. (2008) studied a variant in which any packed item can be removed so as to guarantee a good competitive ratio and presented a packing algorithm that is 3-competitive. Note that in the above two studies, there is *only* one bin to pack the square items.

The remaining part of this paper is organized as follows. In Sect. 2, we show the 4^{d}-competitive algorithm for 1-space bounded *d*-dimensional bin packing. In Sect. 3, a 2^{d+1}-competitive algorithm is given for 1-space bounded *d*-dimensional hypercube packing.

## 2 1-space bounded *d*-dimensional bin packing

Let *d* be the highest dimension of the item and hypercube, each item *a* is associated with a vector (*a*_{1},*a*_{2},…,*a*_{d}), where *a*_{i} (1≤*i*≤*d*) is the length in the *i*-th dimension of item *a*.

In *d*-dimensional space, any two dimensions *i* and *j* define a space *P*_{ij}. For 1-space bounded multi-dimensional bin packing problem, rotation 90^{∘} in any plane *P*_{ij} is allowed. Otherwise, the performance ratio is unbounded. Consider an example of a sequence with 2*n* items: {*A*,*B*,*A*,*B*,…}, where *A*=(1/*n*,1,1,…,1) and *B*=(1,1/*n*,1,1,…,1). If rotation is not allowed, any two adjacent items cannot be packed into the same bin by any online algorithm, thus, the number of used bins is 2*n*. In the optimal packing, all *A* items can be packed into one bin, all *B* items can be packed into another bin, only two bins is enough to pack all these items. In this way, the performance ratio is *n*. If rotation is allowed, the first half part of items in the sequence can be packed into one bin by rotate *B* items 90^{∘} in the plane *P*_{12}. Similarly, the second half of items can be packed into another bin. Since rotation 90^{∘} in any plane *P*_{ij} is allowed, we may assume that the lengths in dimensions of any item *a* is non-increasing, i.e., *a*_{i}≥*a*_{j} (*i*<*j*) for each item.

Denote the *size* of an item *a*=(*a*_{1},*a*_{2},…,*a*_{d}) to be \(\prod_{i=1}^{d}a_{i}\). We say a (*k*+1)-dimensional hyperbox *b*=(*b*_{1},*b*_{2},…,*b*_{k+1}) is a (*k*+1,*h*)-*hyperbox* if *b*_{1}=⋯=*b*_{k−1}=1, *b*_{k}=1/2 and *b*_{k+1}=*h*.

*o*

_{i}and

*r*

_{i}(2≤

*i*<

*d*) be the average occupancy ratio in the worst case and competitive ratio for packing

*i*-dimensional items by our algorithm, respectively. Our target is to design an algorithm with competitive ratio as smaller as possible. Since any algorithm cannot pack items with total sizes more than 1 into one bin, we set

*r*

_{i}=1/

*o*

_{i}. The target can be done by designing algorithm with the average occupancy ratio as larger as possible. According to the algorithm,

*o*

_{i}(

*r*

_{i}) until

*o*

_{d}(

*r*

_{d}) can be recursively computed. We say an item is

*large w.r.t. its*(

*i*+1)

*-th dimension*if \(\prod_{j=1}^{i}a_{j}\ge o_{i}\), and

*small w.r.t. its*(

*i*+1)

*-th dimension*otherwise. For a small item

*a*w.r.t. its (

*k*+1)-th dimension, we have \(a_{k+1}\le a_{k}\le o_{k}^{1/k}= r_{k}^{-1/k}\). From Table 1 and Lemma 1 in the later part of this paper, we have \(r_{k}^{1/k}>2\), thus,

*a*

_{k+1}≤

*a*

_{k}<1/2. A small items

*a*w.r.t. its (

*k*+1)-th dimension can be packed into a (

*k*+1,

*h*)-hyperbox such that

*h*/2<

*a*

_{k+1}≤

*h*and \(h=2^{-j}\cdot o_{k}^{1/k}\) (for some

*j*=0,1,2,…).

The performance ratio for *k*=2 to 6

| 2 | 3 | 4 | 5 | 6 |
---|---|---|---|---|---|

| 5.15 | 30.86 | 127.969 | 518.156 | 2086.38 |

\(r_{k}^{1/k}\) | 2.269 | 3.13 | 3.36 | 3.49 | 3.57 |

### 2.1 Packing strategy

Roughly speaking, items are recursively packed by the strategy from higher dimension to lower dimension. For an incoming item *a*, if it is large w.r.t. the *d*-th dimension, we pack it in a top-down order along the *d*-th dimension. Otherwise, it is small w.r.t. the *d*-th dimension, we first pack it into a (*d*,*h*)-hyperbox, then pack this (*d*,*h*)-hyperbox into the bin in a bottom-up manner. Since the length of (*d*−1)-th dimension of the (*d*,*h*)-hyperbox is 1/2, the lower part along dimension *d* is partitioned into the “left” side and the “right” side: the “left” side is the area such that the (*d*−1)-th dimension is in the range [0,1/2], while the “right” side is in the range [1/2,1]. When packing the (*d*,*h*)-hyperbox into the bin, we try to balance the heights of the left and right sides. When packing small item into (*d*,*h*)-hyperbox, we have no need to consider the length of the *d*-th dimension. In another word, packing small item into (*d*,*h*)-hyperbox can be regarded as packing (*d*−1)-dimensional item into a bin, therefore, the dimension of the packing problem is decreased by one. By implementing this idea, we can recursively pack items from higher dimension into lower dimension.

Note that in our algorithm, small items can be only packed into a (*k*+1,*h*)-hyperbox with *h*<2*a*_{k+1}. Let \(o_{k+1}'\) be the average occupancy ratio for packing small items into (*k*+1,*h*)-hyper-box, we have the following fact.

### Fact 1

\(o_{k+1}'=o_{k}/2\).

### Proof

Since the length of the *k*-th dimension is no more than 1/2, any small item *a* can be packed into the corresponding (*k*+1,*h*)-hyperbox such that, *h*/2<*a*_{k+1}≤*h*. Packing small items can be regarded as packing general items into *k*-dimensional bin by doubling the length in the *k*-th dimension of the small item. Thus, the average occupancy ratio is preserved in the first *k* dimensions. In the (*k*+1)-th dimension, the length is at least *h*/2. Thus, \(o_{k+1}'=o_{k}/2\). □

*d*-dimensional items with

*d*≥3. In case of

*d*=2, we use our previous 5.15-competitive algorithm. Note that the occupation ratios

*o*

_{i}and competitive ratios

*r*

_{i}are all computed by analyzing the algorithm, thus, when packing an incoming item, these ratios are all known in advance.

*k*-th dimension, some small items packed in the (

*k*,

*h*)-hyperboxes which located in the lower part of the

*k*-th dimension such that the “left” and “right” part are balanced. When a large item comes, if it cannot be packed between the upper and lower part without overlapping, we will open a new bin. When a small item comes, we will first try to pack it into some existed (

*k*,

*h*)-hyperbox, if no such (

*k*,

*h*)-hyperbox, we open a new (

*k*,

*h*)-hyperbox then pack it into the right part.

The above algorithm recursively packing items from higher dimension to lower dimension, until dimension 3. We implement the algorithm in Zhang et al. (2010) for packing 2-dimensional items because that the performance ratio *r*_{2}=5.15 is better than implementing the above algorithm in dimension 2.

### 2.2 Analysis of the strategy

When packing items which are small w.r.t. the *k*-dimension into (*k*,*h*)-hyperbox, we say the (*k*,*h*)-hyperboxes with the same height *h* are of the same type. From Fact 1, the average occupancy ratio \(o_{k}'=o_{k-1}/2\). Thus, for each kind of (*k*,*h*)-hyperbox, except the last one, the average occupancy ratio is at least *o*_{k−1}/2.

### Fact 2

*The total lengths in dimension**k**of the last hyperboxes of each type is at most*\(2\cdot o_{k-1}^{1/(k-1)}\).

### Proof

From previous definition \(h_{j}=2^{-j}\cdot o_{k-1}^{1/(k-1)}\) (*j*=0,1,2,…), the length in dimension *k* of each type of (*k*,*h*_{j})-hyperbox is fixed. Thus, the total length is at most \(\sum_{j}h_{j}\le 2\cdot o_{k-1}^{1/(k-1)}\). □

*k*-dimension of the upper part is

*y*, the lengths in

*k*-dimension of the “left” and “right” parts are

*y*

_{1}and

*y*

_{2}respectively. W.l.o.g.,

*y*

_{1}≥

*y*

_{2}. The current occupancy in this bin is at least

*k*−1)-dimension of each hyperbox is 1/2, we divide 2 in the second term. By Fact 1, we know the occupancy in this bin is at least

If we only count the occupancy in one bin, the performance ratio is unbounded. For example, a bin contains a very small item, the next item is very large and cannot be packed together with the small one. We have to open a new bin for the later item. In this case, the occupancy in the previous bin is very small. This example gives us an heuristic to amortize the occupancies of adjacent two bins: if we have to open a new bin due to an item, this items has contribution to two bins, one is the bin it packed and the other is the previous bin it cannot be packed.

To amortize the occupancy of adjacent two bins, item from the upper part compensate half occupancy to the previous bin; item from the lower part compensate the part which is larger than the ratio *o*_{k−1}/4 to the previous bin.

a large item with length

*y*′ in dimension*k*cannot be packed into this bin.- a small item with length
*y*′ in dimension*k*cannot be packed into this bin.- if \((y')^{k}> \frac{y'\cdot o_{k-1}}{4}\), this small item has contribution \((y')^{k}-\frac{y'\cdot o_{k-1}}{4}\) to the previous bin. In this case,
*y*′>(*o*_{k−1}/4)^{1/(k−1)}. The amortized occupancy is at least the last inequality holds since*k*≥3 and \((o_{k-1}/4)^{1/(k-1)}< y'\le o_{k-1}^{1/(k-1)}<1/2\).

*k*=3, the above three formula are equivalent, when

*k*>3, the last two formulas are less. In this paper, the dimension we focused is at least 3, thus, we can say that the amortized occupancy ratio for packing

*k*-dimensional items is at least

*r*

_{k}=1/

*o*

_{k}, we have

In Table 1, we give the performance ratio *r*_{k} for some lower dimensions (*k*=2 to 6). We also compute \(r_{k}^{1/k}\), which will help us to give the upper bound for the performance ratio.

We can see that the performance ratio is increased very fast, but \(r_{k}^{1/k}\) is increased slowly.

### Lemma 1

\(3.5<r_{k}^{1/k}<4\)*if**k*>6 *and*\(3.5<r_{k-1}^{1/(k-1)}<4\).

### Proof

*x*

_{k−1}≥3.5, the above formula is larger than 1/4

^{k}. Thus, we can say that

*x*

_{k}<4 if

*x*

_{k−1}≥3.5. The last inequality holds if

*x*

_{k−1}<4. Thus, we can say that

*x*

_{k}>3.5 if

*x*

_{k−1}<4.

Combine the above two statements and *x*_{6}=3.57, this lemma can be proved by induction. □

From Lemma 1, we conclude that *x*_{k} is in the range (3.5,4) when *k*≥6. Therefore,

### Theorem 2

*The competitive ratio of the algorithm for* 1-*space bounded**d*-*dimensional bin packing is* 4^{d}.

## 3 1-Space bounded *d*-dimensional hypercube packing

In this section, we consider a special case of the multi-dimensional bin packing, where each item is a hypercube with side length no more than 1. Since the lengths of each side of a hypercube are same, this kind of items can be packed regularly inside a bin. We will first describe the packing strategy for hypercubes, then give the performance analysis to show the competitive ratio of this strategy is 2^{d+1}.

### 3.1 Packing strategy

- 1.
In

*d*-dimensional hypercube packing, an item with side length 2^{−i−1}<*x*≤2^{−i}can be packed into a hypercube with side length 2^{−i}, and the occupation ratio in this hypercube is at least 2^{−d}. - 2.
*d*-dimensional hypercube can be regularly partitioned: a hypercube with side length 2^{−i}can be partitioned into 2^{d}smaller hypercubes with side length 2^{−i−1}.

In our packing strategy, we will find a hypercube with proper size for each incoming item. If a hypercube inside the bin is assigned to pack an item, this hypercube cannot be used for other item. According to the first observation, the occupation ratio in this hypercube is guaranteed. To pack an item into a hypercube with proper size, we may partition the bin regularly according to the method from the second observation.

By implementing the partition mentioned above, we can define the packing configuration of the active bin as follows. Define 2^{−i}*-hypercube* to be the hypercube with side length 2^{−i}. Let *B*=(*b*_{0},*b*_{1},*b*_{2},…) denote the current packing configuration of an active bin, where *b*_{i} denotes the number of empty 2^{−i}-hypercubes. If *b*_{j}=0 for all *j*≥*i*, we will ignore *b*_{j} (*j*≥*i*) in *B*.

Initially, the whole bin is empty, in such configuration, *B*=(1). Suppose an item with side length 1/3 comes, to pack this item, the bin will be partitioned into 2^{d} 1/2-hypercubes and use one 1/2-hypercube to pack this item. After that, the configuration will be changed to *B*=(0,2^{d}−1).

*B*and the coming item with side length

*x*. W.l.o.g., suppose 2

^{−i−1}<

*x*≤2

^{−i}.

### 3.2 Performance analysis

### Lemma 3

*In a configuration**B*, 0≤*b*_{i}≤2^{d}−1 *and all empty* 2^{−i}-*hypercubes are within a* 2^{−i+1}-*hypercube*.

### Proof

From the packing strategy, only when a 2^{−i}-hypercube will be used and *b*_{i}=0, we partition a larger hypercube to create 2^{d} 2^{−i}-hypercubes. After the partition, one 2^{−i}-hypercube will be used, either for packing an item, or for partitioning to smaller hypercubes. Thus, *b*_{i} is at most 2^{d}−1.

When these 2^{d} 2^{−i}-hypercubes are created, they are within a 2^{−i+1}-hypercube. Only when these 2^{d} hypercubes are all used up, we will open another 2^{d} 2^{−i}-hypercubes. Therefore, at any time, all empty 2^{−i}-hypercubes are within a 2^{−i+1}-hypercube. □

### Lemma 4

*In a configuration**B*, *for any**i*≥0, *the total size of empty* 2^{−j}-*hypercubes* (*j*>*i*) *is no more than the size of a* 2^{−i}-*hypercube*.

### Proof

Suppose in the configuration *B*, *i*<*j*_{1}<*j*_{2}<⋯<*j*_{ℓ} such that \(b_{j_{x}}>0\) (1≤*x*≤*ℓ*). From Lemma 3, we have \(b_{j_{x}}\le 2^{d}-1\). In *d*-dimensional space, the ratio between the sizes of a 2^{−j}-hypercube and a 2^{−j−1}-hypercube is 2^{d}. Thus, the total size of these \(2^{-j_{x}}\)-hypercubes is no more than the size of a 2^{−i}-hypercube. □

### Theorem 5

*The competitive ratio of the packing strategy for hypercubes is* 2^{d+1}.

### Proof

^{−i}-hypercube is at least 2

^{d}. Thus, for an active bin with configuration

*B*=(

*b*

_{0},

*b*

_{1},

*b*

_{2},…), the total occupation in this bin is at least

Suppose at this time, an item comes and we have to open a new bin according to the packing strategy. This happens when the item with side length 2^{−i−1}<*x*≤2^{−i} and *b*_{j}=0 for all *j*≤*i* in the configuration *B*. The size of this item is *x*^{d}>2^{−id−d}.

^{−i}-hypercube. The average occupation in these two bins is at least

*ℓ*bins for a sequence of items, and the occupation in the

*i*-th bin is

*c*

_{i}. Thus, the total occupation is

In the bin packing problem, we are interested in the asymptotic competitive ratio, according to the above analysis, this ratio is 2^{d+1}. □

### Open Access

This article is distributed under the terms of the Creative Commons Attribution License which permits any use, distribution, and reproduction in any medium, provided the original author(s) and the source are credited.