1/0 Knapsack Variation with Weighted Edges

我只是一个虾纸丫 提交于 2019-12-06 20:43:31

First of all, this problem is NP-hard. Here is a reduction from the shortest hamiltonian path in a weighted complete graph to this one. Given a graph, we can assign values of all nodes to 1 and then run binary search over the answer. If there was a polynomial solution for this problem, it could tell if there is a path that contains all vertices and is not longer than a given value. Thus, we would be able to solve the shortest hamiltonian path problem in polynomial time. In practice it means that no one knows an efficient correct polynomial solution to your problem.

Now there are two ways to go:

  1. If the number of vertices is rather small(around 20), you can use dynamic programming to get an exact solution. The state is (mask, last_vertex). The value is the shortest possible time we need to visit all vertices in the mask and stop in the last_vertex. The time complexity of this solution is O(2^n * n^2).

  2. If the number of vertices is much bigger, you can find an approximate solution. There are a lot ways to do it: heuristics, different greedy algorithms, random sampling with local optimizations and so on.

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