Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a practical solution to the Travelling Salesman prblem, using Google Maps?

What is a practical solution to the Travelling Salesman problem, using Google Maps / geolocation / route finding?

I don't need the best solution, within 5% would be fine.

For example, I have 20 locations in the UK to visit, in any order. This may need to scale to hundreds of locations.

What sort of algorithm can I use, given that I can lookup distances (but don't want to lookup hundreds of distances)?

like image 209
fadedbee Avatar asked Oct 12 '11 07:10

fadedbee


People also ask

How does Google Maps solve the travelling salesman problem?

In this work we present a methodology to calculate precise routes for the Traveling Salesman Problem. We use the google maps APIs to obtain information, then preprocess the data in order to convert it into a valid graph, and finally the instance is solved by a proposed metaheuristic.

Is there a solution to the travelling salesman problem?

The problem can be solved by analyzing every round-trip route to determine the shortest one. However, as the number of destinations increases, the corresponding number of roundtrips surpasses the capabilities of even the fastest computers.


2 Answers

There is this TSP project implemented in JS http://code.google.com/p/google-maps-tsp-solver/

You can see live demo here http://gebweb.net/optimap/

like image 74
Kunukn Avatar answered Nov 15 '22 09:11

Kunukn


Google does have a parameter on their directions API which will optimize the route as a travelling salesman problem:

  • API Documentation: Using Waypoints in Routes
  • Introduction and demo blog post

From the documentation (the key part is &waypoints=optimize:true|...):

The following example calculates a road trip route from Adelaide, South Australia to each of South Australia's main wine regions using route optimization.

http://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA
  &destination=Adelaide,SA
  &waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA
  &sensor=false

Inspection of the calculated route will indicate that the route is calculated using the following waypoint order:

"waypoint_order": [ 1, 0, 2, 3 ]

For a one-off it's probably easier to use OptiMap as recommended by @Kunukn

like image 20
rcoup Avatar answered Nov 15 '22 09:11

rcoup