Minimal Distance Hamiltonian Path Javascript

自作多情 提交于 2019-12-18 13:20:49

问题


I know this is a fairly frequent question (tsp in general), but I've been stumped by it for awhile now. I'm looking to find the minimal distance hamiltonian path given a set of x,y coordinates. The start and end point are completely arbitrary but it must NOT cycle, so standard tsp is out (although supposedly adding a dummy point at 0 distance to all other nodes and then removing it later works, i have no idea how I'd do that).

There are plenty of links to math papers and the like discussing algorithms to solve similar problems, but I'd much rather work with code than complex equations and i'd really rather not reinvent the wheel.

Surely there is a fairly straightforward implementation in a major language java,c#,c++,ruby,javascript,php,etc that can solve a ~20 node version of my problem.

Edit: I'm also looking for as accurate as possible, obviously it can't be completely accurate as 20! is a lot of permutations, but equal to or better than what a human could do in a couple minutes would be perfect.

Edit2: Also to clarify, I'm working with standard 2d coordinates on an unweighted graph. The distance A->B == B->A

Edit3: To eliminate confusion, here's a visual example with just a few points to show how tsp can be suboptimal (this case is an easy fix but with more nodes it can be more extreme).

TSP Minus Longest Segment (red line)

Desired Output


回答1:


You can solve the bitonic euclidean traveling-salesman problem. Is a simplified version of the tsp solvable through dynamic programming in O(n^2): http://en.wikipedia.org/wiki/Bitonic_tour



来源:https://stackoverflow.com/questions/7341687/minimal-distance-hamiltonian-path-javascript

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