开发者

Minimal Distance Hamiltonian Path Javascript

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 开发者_Python百科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)

Minimal Distance Hamiltonian Path Javascript

Desired Output

Minimal Distance Hamiltonian Path Javascript


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜