How to create an optimized 3D volume-packing function in python?

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.


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


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