stu96art has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Knapsack problem
by Roger (Parson) on Dec 09, 2003 at 04:58 UTC | |
Start with a single area, find the best fit rectangle for the area. After fitting the rectangle on to the area, there are two options of the left over areas. Traverse the left over options recursively for the next rectangle, until everything fits (a solution) or something not fit (a dead end). Collect the solutions and find the best solution at the end. The following is a very simplified approach, just to demonstrate the sort of idea I had. And the output -
| [reply] [d/l] [select] |
|
Re: Knapsack problem
by Zed_Lopez (Chaplain) on Dec 08, 2003 at 19:23 UTC | |
This is the knapsack problem. It is NP-hard. Were you to find a polynomial-time solution to it, you'd have basically solved all the hardest problems in computer science. There are heuristic approaches that shoot for decent solutions that don't attempt or claim to be optimal solutions. If you follow the Google link above, you'll probably find some. | [reply] |
|
Re: Knapsack problem
by Anonymous Monk on Dec 08, 2003 at 19:25 UTC | |
| [reply] |
by stu96art (Scribe) on Dec 08, 2003 at 20:00 UTC | |
| [reply] |
by Cody Pendant (Prior) on Dec 08, 2003 at 20:48 UTC | |
What's this business of a horizontal or vertical line dividing the area, by the way? That's just confusing the issue. Can I solve the problem for you by saying "put that line one millimetre from the edge and then solve the knapsack thing with your MaxX x MaxY area one millimetre smaller than before?" The practical side of this knapsack business, by the way, is that you can spend enormous amounts of time finding better and better solutions, but they'll only be slightly better. If you find a solution that's about 80% better than random, then stop looking and go with it. People who really understand math, please correct me if I'm wrong, but there's no point continuing trying to find a slightly-more-perfect solution, unless you're chopping up solid gold, I guess. | [reply] [d/l] |
by stu96art (Scribe) on Dec 08, 2003 at 21:01 UTC | |
by QM (Parson) on Dec 08, 2003 at 23:56 UTC | |
|
Re: Knapsack problem
by sauoq (Abbot) on Dec 08, 2003 at 19:22 UTC | |
This may not be a question all about Perl Not only is it not "all about Perl" it is not at all about Perl. Do you care to share with us the code you've written so far? Maybe we can help you find your mistakes... -sauoq "My two cents aren't worth a dime."; | [reply] |
|
Re: Knapsack problem
by zentara (Cardinal) on Dec 09, 2003 at 20:07 UTC | |
| [reply] |