How to modify the Javascript code to specify a certain order for some points?

60 views
Skip to first unread message

AD

unread,
Oct 10, 2011, 12:38:23 PM10/10/11
to Google Maps TSP Solver
Let's say I have a list of locations that I must visit in a certain
order. What can I do in order to specify this to the algorithm?

If I have locations A, B, C, D, I want to have a way to specify that I
want to visit B before C (not necessarily directly, of course).

I have tried to set the dist[][] and dur[][] between those locations
to 0, and while that gives the correct order, it does not compute the
shortest way.

Geir Kokkvoll Engdahl

unread,
Oct 11, 2011, 1:33:03 AM10/11/11
to google-maps...@googlegroups.com
There is no quick fix (like setting dist and dur to specific values)
to implement this. You need to enforce those constraints during the
solver routine, for instance by checking that B has been visited
already when adding C to a solution. The easiest algorithm to modify
will be tspBruteForce (this will not work for more than ~12
locations). At the beginning of that routine, you would check that the
dependencies of the current node have all been visited:

for (var i = 0; i < dependencies.length; i++) {
if (!visited[dependencies[i]]) {
return; // Cut off the search if not all the dependencies of this
node have already been visited.
}
}

Geir

Reply all
Reply to author
Forward
0 new messages