Brain Dump

Bin Packing

Tags
math algorithm

Refers to a series of algorithms for problems that can be modelled by packing boxes of different heights into fixed-size bins. In general the problem assumes an infinite number of available bins, with the goal of packing the boxes into as few bins as possible.

We define the lower bound as the lowest theoretical value for a bin packing problem. This is the sum of the values of the boxes divided by the size of the bin. When necessary you should round up to the largest available bin. \[ \text{Lower Bound} = [\frac{\sum_x \text{Height}_x}{\text{Bin Size}}] \] By definition it's impossible to find a bin packing solution that uses less bins than this.

First Fit Algorithm

This algorithm simply takes each box in the order that it is listed and fits it into the first available bin with enough space to take the box. If there isn't one then a new bin is used.

First Fit Decreasing Algorithm

Reuses the same approach as the first fit algorithm, but reorders boxes by height before trying to pack them into bins.

Full Bins Algorithm

This approach tries to observe the combinations of boxes which fill a bin exactly and then tries to fit these first. Then it uses the first fit algorithm to pack the remaining items.

The idea behind this approach is that you must place every box in a bin. If two boxes together fill a bin then that's an optimum pairing for those boxes, there's no other bin that you could place them in separately that fills as little space as they do together (except of course another sequence of boxes which also fill a bin exactly).