Possible Combination of Knapsack problem and?

瘦欲@ 提交于 2019-12-04 16:19:44

Okay, well, knapsack is NP-hard so I'm pretty certain this will be NP-hard as well (if it weren't you could solve knapsack by doing this with only one outer bag.) So for an exactly optimal solution, you're probably going to be able to do no beter than searching all combinations. So the outline of the program you want will be like

 for each possible combination
 do
   if current combination is better than best previous
      save current combination as best so far
   fi
 od

and the run time will be exponential. It sounds, though, like you might be able to get a near solution with dynamic programming.

Consider using Prolog for your logical programming. There's multiple implementations of it including P# on mono (.NET). Theres a bit of a learning curve, but once you get used to it, it's pretty much in a league of its own for this kind of problem solving.

Hope this helps. Cheers!

link to P#

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