Think Inside the Box

During a trip to Indonesia, I watched an art dealer handmake a cardboard box. He started with a flat sheet, measured the dimensions, scored it, and neatly folded it all up.

Back home in the US, I’m disappointed whenever I receive packages shipped in oversized boxes filled with peanuts or plastic air pouches. It’s not just wasteful, it’s bad business. Volume is a bigger and more expensive constraint than weight.

That’s why Amazon, and most other smart e-comm retailers, now use bin packing algorithms to find the most efficient box sizes and packing arrangements for their shipments.

Imagine you’re shipping an order to Reno, NV:

And you have 3 standard box sizes:

Instead of using trial & error to figure out the best arrangement, calculate it with BoxPacker, a 3D bin packing library from Max White:

```ruby require ‘box_packer’

BoxPacker.builder do |b| # establish container sizes c1 = b.container [5, 5, 4] # volume: 100 c2 = b.container [6, 5, 4] # volume: 120 c3 = b.container [5, 5, 5] # volume: 125

# assign items to each container c1.items = [ # total volume: 90 b.item([3, 1, 3], label: ‘A’, colour: ‘red’), b.item([5, 3, 5], label: ‘B’, colour: ‘blue’), b.item([1, 2, 3], label: ‘C’, colour: ‘green’) ] c3.items = c2.items = c1.items

# Pack em! c1.pack!; c2.pack!; c3.pack!

# visualize each container by layers and perspective c1.draw!(‘examples/c1’, scale_longest_side_to: 500, margin: 15) c2.draw!(‘examples/c2’, scale_longest_side_to: 500, margin: 15) c3.draw!(‘examples/c3’, scale_longest_side_to: 500, margin: 15)

# print output to console puts c1; puts c2; puts c3

end ```

Here are the results:

```text Container| 5x5x4 Packing| Remaining Volume:10 Item| B 5x5x3 (0,0,0) Volume:75 Item| A 3x3x1 (0,0,3) Volume:9 Item| C 2x3x1 (3,0,3) Volume:6

Container 6x5x4
Packing Remaining Volume:30
Item B 5x5x3 (0,0,0) Volume:75
Item A 3x3x1 (0,0,3) Volume:9
Item C 2x3x1 (3,0,3) Volume:6

Container| 5x5x5 Packing| Remaining Volume:35 Item| B 5x5x3 (0,0,0) Volume:75 Item| A 3x3x1 (0,0,3) Volume:9 Item| C 2x3x1 (3,0,3) Volume:6 ```

The ideal box is b1, which has the least wasted volume: 10 cm^3. Here’s what the packing arrangement looks like (includes layers & length / width / height views):

BoxPacker output for b1

This is a simple example, but BoxPacker can also take into account weight and # of items/box packing limits. You could even use it to find the optimal packing arrangement for your next road trip!

Comment with markdown & emoji
2017 Neal Shyam