Algorithm design: can you provide a solution to the multiple knapsack problem?

后端 未结 2 1808
终归单人心
终归单人心 2021-01-04 12:50

I am looking for a pseudo-code solution to what is effectively the Multiple Knapsack Problem (optimisation statement is halfway down the page). I think this problem

相关标签:
2条回答
  • 2021-01-04 13:12

    You need http://www.or.deis.unibo.it/knapsack.html, chapter 6.6 "Multiple knapscack problem - Approximate algorithms". There is pseudo-code (Pascal style) in the text and Fortran implementations (yes, it's an old book) as a ZIP file.

    0 讨论(0)
  • 2021-01-04 13:12

    As far as I know, the problem is NP complete (Wikipedia confirms), so there's probably not much sense in attempting to solve it exactly. However, any number of approaches might be good enough for you: greedy, genetic algorithms, simulate annealing...greedy is probably the easiest to implement:

    while (time available in block greater than smallest task duration)
      find the longest fitting task
      add it
    

    ...you get the idea.

    0 讨论(0)
提交回复
热议问题