如何在python中解决旅行商问题?我没有找到任何库,应该有一种方法使用scipy函数进行优化或其他库.
我的hacky-extremelly-lazy-pythonic强制解决方案是:
tsp_solution = min( (sum( Dist[i] for i in izip(per, per[1:])), n, per) for n, per in enumerate(i for i in permutations(xrange(Dist.shape[0]), Dist.shape[0])) )[2]
Run Code Online (Sandbox Code Playgroud)
其中Dist(numpy.array)是距离矩阵.如果Dist太大,这将需要永远.
建议?