Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

..isn't it supposed to return to the origin city ? #1

Closed
sp00x opened this issue Oct 19, 2018 · 1 comment
Closed

..isn't it supposed to return to the origin city ? #1

sp00x opened this issue Oct 19, 2018 · 1 comment

Comments

@sp00x
Copy link

sp00x commented Oct 19, 2018

I've tried various things here now, but the resulting array does neither end nor start with "0", which is part of the point of the algorithm, isn't it? (it is suppsoed to return to the origin .. most of the time it just seems to pass by the origin)

e.g. test script

let salesman = require('salesman.js');
let a = [[0, 0], [20000, 200], [100, 0], [100, 100], [100, 0]];
let b = a.map(p => new salesman.Point(p[0], p[1]));
let sol = salesman.solve(b);
console.dir(sol);

Ran multiple times:

[ 1, 3, 0, 4, 2 ]
[ 4, 2, 0, 3, 1 ]
[ 4, 1, 3, 0, 2 ]
[ 0, 3, 1, 4, 2 ]
[ 3, 0, 4, 2, 1 ]

I've tried closing the loop also (duplicating the first elem last) without any big amount of luck...

@lovasoa
Copy link
Owner

lovasoa commented Oct 19, 2018

I just made a change so that it always starts and ends with the first point you give.

The point of the algorithm is to find a loop with the shortest overall distance, so the starting point does not have much importance (you start at any point and just follow the path in the order given by the solution).
[ 0,1,2,3], [1,2,3,0],[ 2,3,0,1], and [3,0,1,2] are all the same solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants