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

感情迁移 提交于 2019-12-18 21:18:19

问题


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 is NP Complete so the solution doesn't need to be optimal, rather if it is fairly efficient and easily implemented that would be good.

The problem is this:

  • I have many work items, with each taking a different (but fixed and known) amount of time to complete.
  • I need to divide these work items into groups so as to have the smallest number of groups (ideally), with each group of work items taking no longer than a given total threshold - say 1 hour.

I am flexible about the threshold - it doesnt need to be rigidly applied, though should be close. My idea was to allocate work items into bins where each bin represents 90% of the threshold, 80%, 70% and so on. I could then match items that take 90% to those that take 10%, and so on.

Any better ideas?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/2392284/algorithm-design-can-you-provide-a-solution-to-the-multiple-knapsack-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!