9

I know that the 2D and 3D Knapsack problems are NPC, but is there any way to solve them in reasonable time if the instances are not very complicated? Would dynamic programming work?

By 2D (3D) Knapsack I mean I have a square (cube) and a I have list of objects, all data are in centimeters and are at most 20m.

Raphael
  • 73,212
  • 30
  • 182
  • 400
Anonymous
  • 621
  • 7
  • 5

2 Answers2

1

Knapsack can be solved by dynamic programming in pseudo-polynomial time $O(nW)$ with $n$ the number of objects and $W$ the size of the knapsack. So, as long as your container is small (numerically), you can solve the problem efficiently. Note that you can adjust $W$ by changing resolution; no need to measure a shipping container to the µm, but meters are probably to coarse (depending on your objects).

Knapsack can also be approximated arbitrarily well in polynomial time (see polynomial-time approximation schemes).

However, Knapsack only considers fitting numbers into another number; it does not care about geometrics. If you need to "puzzle", you need another problem; considering Tetris, this is probably much harder than Knapsack.

Raphael
  • 73,212
  • 30
  • 182
  • 400
0

GREEDY will always find a reasonable solution, but not necessarily the optimal one. Simply put the largest object which will fit each time in the knapsack. Stop when no more objects will fit.

salsaman
  • 117
  • 1