# Harmonic bin packing

Harmonic bin-packing is a family of online algorithms for bin packing. The input to such an algorithm is a list of items of different sizes. The output is a packing - a partition of the items into bins of fixed capacity, such that the sum of sizes of items in each bin is at most the capacity. Ideally, we would like to use as few bins as possible, but minimizing the number of bins is an NP-hard problem.
The harmonic bin-packing algorithms rely on partitioning the items into categories based on their sizes, following a Harmonic progression. There are several variants of this idea.

## Harmonic-k

The Harmonic-k algorithm partitions the interval of sizes $(0,1]$ harmonically into $k-1$ pieces $I_{j}:=(1/(j+1),1/j]$ for $1\leq j<k$ and $I_{k}:=(0,1/k]$ such that $\bigcup _{j=1}^{k}I_{j}=(0,1]$. An item $i\in L$ is called an $I_{j}$-item, if $s(i)\in I_{j}$.
The algorithm divides the set of empty bins into $k$ infinite classes $B_{j}$ for $1\leq j\leq k$, one bin type for each item type. A bin of type $B_{j}$ is only used for bins to pack items of type $j$. Each bin of type $B_{j}$ for $1\leq j<k$ can contain exactly $j$ $I_{j}$-items. The algorithm now acts as follows:
* If the next item $i\in L$ is an $I_{j}$-item for $1\leq j<k$, the item is placed in the first (only open) $B_{j}$ bin that contains fewer than $j$ pieces or opens a new one if no such bin exists.
* If the next item $i\in L$ is an $I_{k}$-item, the algorithm places it into the bins of type $B_{k}$ using Next-Fit.
This algorithm was first described by Lee and Lee. It has a time complexity of ${\mathcal {O}}(n\log(n))$ where n is the number of input items. At each step, there are at most $k$ open bins that can be potentially used to place items, i.e., it is a k-bounded space algorithm.
Lee and Lee also studied the asymptotic approximation ratio. They defined a sequence $\sigma _{1}:=1$, $\sigma _{i+1}:=\sigma _{i}(\sigma _{i}+1)$ for $i\geq 1$ and proved that for $\sigma _{l}<k<\sigma _{l+1}$ it holds that $R_{Hk}^{\infty }\leq \sum _{i=1}^{l}1/\sigma _{i}+k/(\sigma _{l+1}(k-1))$. For $k\rightarrow \infty$ it holds that $R_{Hk}^{\infty }\approx 1.6910$. Additionally, they presented a family of worst-case examples for that $R_{Hk}^{\infty }=\sum _{i=1}^{l}1/\sigma _{i}+k/(\sigma _{l+1}(k-1))$

## Refined-Harmonic (RH)

The Refined-Harmonic combines ideas from the Harmonic-k algorithm with ideas from Refined-First-Fit. It places the items larger than $1/3$ similar as in Refined-First-Fit, while the smaller items are placed using Harmonic-k. The intuition for this strategy is to reduce the huge waste for bins containing pieces that are just larger than $1/2$.
The algorithm classifies the items with regard to the following intervals: $I_{1}:=(59/96,1]$, $I_{a}:=(1/2,59/96]$, $I_{2}:=(37/96,1/2]$, $I_{b}:=(1/3,37/96]$, $I_{j}:=(1/(j+1),1/j]$, for $j\in \{3,\dots ,k-1\}$, and $I_{k}:=(0,1/k]$. The algorithm places the $I_{j}$-items as in Harmonic-k, while it follows a different strategy for the items in $I_{a}$ and $I_{b}$. There are four possibilities to pack $I_{a}$-items and $I_{b}$-items into bins.
* An $I_{a}$-bin contains only one $I_{a}$-item.
* An $I_{b}$-bin contains only one $I_{b}$-item.
* An $I_{a}b$-bin contains one $I_{a}$-item and one $I_{b}$-item.
* An $I_{b}b$-bin contains two $I_{b}$-items.
An $I_{b}'$-bin denotes a bin that is designated to contain a second $I_{b}$-item. The algorithm uses the numbers N_a, N_b, N_ab, N_bb, and N_b' to count the numbers of corresponding bins in the solution. Furthermore, N_c= N_b+N_ab
This algorithm was first described by Lee and Lee. They proved that for $k=20$ it holds that $R_{RH}^{\infty }\leq 373/228$.

## Other variants

Modified Harmonic (MH) has asymptotic ratio $R_{MH}^{\infty }\leq 538/33\approx 1.61562$.
Modified Harmonic 2 (MH2) has asymptotic ratio $R_{MH2}^{\infty }\leq 239091/148304\approx 1.61217$.
Harmonic + 1 (H+1) has asymptotic ratio $R_{H+1}^{\infty }\geq 1.59217$.
Harmonic ++ (H++) has asymptotic ratio $R_{H++}^{\infty }\leq 1.58889$ and $R_{H++}^{\infty }\geq 1.58333$.