views:

312

answers:

3

So I have been given the task to create a shipping module for a webshop system. It may be a bit overkill, but I would really like to create one that can figure out how to pack parcels in the most optimized way. Having learned programming simply by doing it, this is an area where I have no knowledge - yet! Anyways I can just give short description of the actual problem.

So when users by stuff at webshops they will have x products in their cart with possibly varying sizes and weight. So I want to give that list of products to the function and let it figure out how these products should be packed in parcel(s).

  • max length of parcel: 100
  • max width of parcel: 50
  • max height of parcel: 50
  • max weight of parcel: 20

Every product has a weight, length, width and height as well.

Since parcels and products is basically boxes, I'm guessing this would be rather complex, as there are different ways of putting the products inside the parcel. My goal is not to make the perfect packaging function, but I would like to do something better than just putting products inside the parcel until a limit has been reached.

Now, I don't expect you guys to make this for me, but what I would like to ask is three things.

  1. Where can I find good online resources that will teach me the basics needed?
  2. Are there some native python tools that would be good to use?
  3. Some pointers of what I need to be aware of, pitfalls ect

Like I said, I don't plan for this to be perfect and 100% optimized, but I would like to end up with something that will come close. I would hate if users feel that the sending fee will be a lot higher than it actual is.

+4  A: 

That’s your typical knapsack problem. Many solutions for different languages can be found at Rosetta Code.

Bombe
It isn't is it? The Knapsack problem specifies you have a container the size of x, and you need to fit items in maximizing the sum of item property y.What googletorp wants is how to pack it in the most efficant way, including item placement.
Yacoby
It was an interesting read, but it wont exactly solve what I'm looking as it only looks at volume. Given 7 products that are 51x26x26 I would only be able to fit one of those in a parcel, but using volume calculation all 7 would fit in one parcel.
googletorp
Okay, the “typical” knapsack problem has only one dimension (volume). The problem depicted here would have four dimensions, three for space and one for weight. That’s still the knapsack problem, only a bit more complicated.
Bombe
I think going 3D makes it a whole lot more complicated. Check the links in my answer. But you're right, we can call it a generalized knapsack problem.
Matt
+1  A: 

This seems a good problem to which to apply the simplex algorithm or some sort of genetic algorithm. If you never heard of the latter, I highly recommend you to read about them. As I can see from your question, you're doing this enhancement because you like to make things work optimally, and not because you were told to do so. Imagine when you tell them you applied an Artificial Intelligence technique for solving their problem!

There are many straight-forward algorithms that solve your problem, but this can be a great opportunity to learn some evolutionary computation. Some interesting links about genetic algorithms [everyone, feel free to edit and add]:

  1. These pages introduce some fundamentals of genetic algorithms.
  2. Genetic Algorithms in Plain English

Luck with that!
Manuel

Manuel
+3  A: 

The fact that you have height, length and width makes it harder than a simple knapsack problem. Here's an interesting discussion of a 3D knapsack problem.

Here's a paper on the topic by the same guys.

Matt