views:

2271

answers:

7

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.

+12  A: 

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.

Nick Johnson
Your definition is accurate, and I voted your answer up since it provided some useful reference info. Ideally I'd like to find a ready made solution.
polara
+3  A: 

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).

Herms
Your description and referenced link are accurate as well. As in the case with the Bin Packing problem that Arachnid referenced, there can be an extreme number of different possible solutions compounded by the ability to turn items sideways in the box.
polara
A: 

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.

Gregg Lind
Thanks. Yes, heuristics were suggested by Arachnid as well. The application of this was to calculate shipping charges, and I could imagine a fully automated solution coming up with all sorts of impractical arrangements.
polara
A: 

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.

freespace
A: 

maybe this thing i hacked the last hours may help: http://github.com/yetzt/boxing

A: 

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 publised 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 4 D Bin Packing (3D size & weigth) and gets an acceptable solution for typical oder sizes (a few dozens of packages) in under a second runtime.

mdorseif
A: 

hi, I was wondering if anyone know if a programe on-line preferably free that I can access to figure out what size of box to use to ship identical items. I can't find the exact size of box, so I have to combine a few in a single box, but I can't figure out what size of box to use from the standard sizes available at the stores. Any help would be greatly appreciated. thank you very, very much!!!!!!

Jez