How can I programmatically determine how to fit smaller boxes into a larger package?

0 votes
asked Sep 26, 2008 by polara

Does anyone know of existing software or algorithms to calculate a package size for shipping multiple items?

I have a bunch of items in our inventory database with length, width and height dimesions defined. Given these dimensions I need to calculate how many of the purchased items will fit into predefined box sizes.

9 Answers

0 votes
answered Sep 26, 2008 by nick-johnson

This is a Bin Packing problem, and it's NP-hard. For small number of objects and packages, you might be able to simply use the brute force method of trying every possibility. Beyond that, you'll need to use a heuristic of some sort. The Wikipedia article has some details, along with references to papers you probably want to check out.

The alternative, of course, is to start with a really simple algorithm (such as simply 'stacking' items) and calculate a reasonable upper-bound on shipping using that, then if your human packers can do better, you make a slight profit. Or discount your calculated prices slightly on the assumption that your packing is not ideal.

0 votes
answered Sep 26, 2008 by herms

Are you trying to see how many of a single type fits into a particular sized package, or are you trying to mix types as well?

Sounds like you're trying to solve the Knapsack Problem. You might be able to find some algorithms for that which could be adapted to your specific requirements. Just understand that it will be hard to find an efficient algorithm, as the problem is NP complete (though depending on your specific requirements you may be able to find an efficient approximation, or your inputs may be small enough that it doesn't matter).

0 votes
answered Sep 27, 2008 by gregg-lind

Maybe this will sound obvious, but it might be worthwhile to memoize the problem, then do some of them by hand. Finding a most effecient solution for arbitrary inputs and boxes in NP-hard, but by restricting the problem space, and accepting some inefficiency, that NP size might be something reasonable, and by memoizing, you might be able to bring the "common-case" time down substantially.

It might also help to think about things in terms of hierarchical packing.

0 votes
answered Sep 29, 2008 by freespace

If the boxes are to be hand packed, then you might consider writing an algorithm which would do what a reasonable human would do. The reason I suggest this is because unless you want to print out packing instructions for each order, then whoever is doing your packing is going to have to workout how they are going to fit the ordered items in however many boxes it has been allocated for the order.

This might then lead to your human packers coming to SO asking on how to programmatically workout how to pack n items into m boxes. :-P (They might also ask you to do it, ask you for instructions, etc).

As long as your algorithm does what a reasonable human being would do, I would personally accept its shipping estimate.

0 votes
answered Sep 16, 2009 by user211888

maybe this thing i hacked the last hours may help:

0 votes
answered Sep 10, 2010 by max

The literature on "3D Bin packing" is far and wide. You can get a good overview by tracking the publications of Professor David Pisinger. He also published one of the few high quality implementations of bin packing with sourcecode: 3dbpp.c

My own logistics toolkit pyShipping comes with a 3D Bin Packing implementation for Warehousing applications. It is basically implementing 4D Bin Packing (3D size & weigth) and gets an acceptable solution for typical order sizes (a few dozens of packages) in under a second runtime. It is used in production (meaning a warehouse) for some months now to determine the upper bound of shipping crates to be used. The warehouse workers are often able to pack somewhat more efficiently but that's OK with me.

0 votes
answered Sep 27, 2010 by geoffrey-de-smet

Metaheuristics are good to deal with real world bin packing problems when there are many packages and/or many constraints. One open source Java implementation is Drools Planner.

0 votes
answered Sep 22, 2014 by tomee

Pisinger is one of the few academics who posts working code. In one of his papers he mentions the "Minimum Depth" problem.

Here is a practical and efficient algorithm for 3D Rectangular Box Packing that adjusts the height of the enclosing box.

And here is an implementation in php.

0 votes
answered Sep 15, 2017 by ammar

After lot of searching i have found a GitHub repository that might help someone. Function PackingService.Pack() takes list of Container and list of Item(s) to be packed as parameter and return result which contains lot of information including

"container(s) packed in percentage and list of packed and unpacked items"

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter