2

maybe somebody knows algorithm, or just what name it has, for putting stones (different weight) into different size backpacks? I should do it in Prolog. I give weights of stones and capacities of backpacks. Program should give me an answer how can I place all these stones into backpacks.

false
  • 10,264
  • 13
  • 101
  • 209
Mario
  • 335
  • 7
  • 20
  • I think in general this is often called a "knapsack" (or "backpack" to some) problem. There are algorithms for it. I don't know a specific implementation in Prolog, but Googling for "knapsack problem" should get you moving in the right direction... – FrustratedWithFormsDesigner Dec 10 '10 at 16:52
  • 1
    @FrustratedWithFormsDesigner: He has multiple knapsacks, so it's actually a bin-packing problem. – jason Dec 10 '10 at 16:53

3 Answers3

3

It's hard to tell since you haven't given much detail, but this sounds like a bin-packing problem. You can start on Wikipedia and Google to find algorithms that fit your needs (note that this an NP-Hard problem).

jason
  • 236,483
  • 35
  • 423
  • 525
2

It's called the knapsack problem.

sascha
  • 32,238
  • 6
  • 68
  • 110
1

it's a classic problem, check knapsack problem

matcheek
  • 4,887
  • 9
  • 42
  • 73