问题
I have a Box with some dimension length, width, height.
I have items with different length, width, height.
Is there an existing algorithm that can determine the best items to use to put inside the box?
回答1:
This is called a Bin Packing/Cutting Stock/Knapsack problem, and it is NP hard. In general you can only get an approximate solution by using heuristics, see for example
http://en.wikipedia.org/wiki/Knapsack_problem
http://en.wikipedia.org/wiki/Bin_packing_problem
http://en.wikipedia.org/wiki/Cutting_stock_problem
回答2:
This perhaps isn't actually an answer, but I believe the answer is that the problem is unanswerable. Yes, it is a version of a packing problem. But take a look at Erich Friedma's research in 2 dimensions: It seems the problem for equal sized rectangles in square is still unsolved - Look at the complexity of some of these solutions!
http://www2.stetson.edu/~efriedma/squinsqu/
http://www2.stetson.edu/~efriedma/rigidrect/
(The problem is posed slightly differently, i.e. how to best arrange a certain number of items to occupy the least space, as opposed to choosing which items. But I expect your problem reduces to iterating this kind of calculation over several combinations of objects.)
and a 3-d variant which looks only very partially solved: http://www2.stetson.edu/~efriedma/cubincub/
Presumably your best bet is a heuristic as Anders suggests, though it almost certainly will be suboptimal for almost every problem. Interestingly, most optimal solutions appear to be highly irregular, so you probably wouldn't find them.
来源:https://stackoverflow.com/questions/6988300/fill-volume-algorithm