When I say box I am talking about shipping boxes.
I have a number of random sized, small items that I need to pack into as few boxes as possible. I need to know what box sizes are optimal.
What algorithm exists that allows me to calculate the box sizes I need to use for optimal space usage? To fit the most items into as few boxes as possible.
The available box sizes come from what I have available, in-stock. You can create a finite number of made up box sizes for example purposes.
This is a generalization of the Bin packing problem, meaning it is NP-Hard.
To see this, imagine all bins and packages have the same width and height, and additionally all bins (but not packages) have the same length. Then it is a one-dimensional problem: we have bins of size V, and packages of size a1, a2, ..., an. This simplified case is exactly the Bin-packing problem. Thus, a fast solution to your problem gives us a fast solution to bin-packing, so your problem is at least as hard; and since bin-packing is NP-Hard, so is your problem.
There are some approximation algorithms available though; for example, it's easy to show that the simple first-fit algorithm (put every item in the first bin that it fits into) will never do worse than 2x the optimal solution.
The similar "First Fit Decreasing" algorithm (sort the items in descending order, then put every item in the first bin it fits into) is even better, guaranteeing to be within about 25% of the optimal solution. There is also another, slightly more complicated algorithm called MFFD which guarantees to be within about 20%.
And of course, with only 7 boxes, you could always just brute-force the solution. This will require about 7n steps (where n
is the number of items), so this solution is infeasible with more than a dozen or so items.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With