4

The Google API offers good directions for routing point a-b, and now offer multiple waypoints and TSP optimization (https://developers.google.com/maps/documentation/directions/#Waypoints).

I'd like to take it a step further and solve the Traveling Salesman Problem with time windows (TSPTW) also known as vehicle routing problem with time windows. In other words, I want to add appointments and service time into the optimization step.

Google maps offers the distanceMatrix API method which, given a set of multiple starting locations and multiple ending locations, returns a matrix of distance AND estimated travel time between each. Given that information, how would one go about calculating a route where n number of waypoints have to be visted at certain times, i.e. an appointment? https://developers.google.com/maps/documentation/javascript/reference#DistanceMatrixService

I've found a paper on the subject, but am having a hard time transalting the theory and math into actual code: http://www.akk.ke.hu/index.php?mid=60&did=739

I'm a LAMP developer, and am looking for a solution in PHP or JavaScript.

Are there any other suggestions for solving the VRPTW using data from google maps API, or any other mapping solution?

Mike Marsh
  • 63
  • 1
  • 6
  • Can you get all-pairs distances for the base and the appointment locations? I don't think there's a way to use the API to solve the VRPTW directly, but there may be external tools that you could integrate. – David Eisenstat Apr 28 '14 at 00:16
  • @DavidEisenstat Yes, I believe you get all-pairs distances for the base and the appointment locations. Its limited to 25 locations, but I believe you can use the same locations for starting and ending points which would give you all-pairs distances for at most 12 locations. Here is very good example of what the service returns: http://googlegeodevelopers.blogspot.co.uk/2011/05/what-is-distance-matrix.html – Mike Marsh Apr 28 '14 at 20:27

2 Answers2

0

Try this: Make an array with each appointment, and add an "Effort" property. Step through the array and calculate the effort as the sum of the squares of the physical distance between each item and the item above it and below it, calculate distance in space, and also in time. Find the item in the array with the highest value for "Effort", and attempt to re-place it in the array in each location to find the lowest place for that item. Perform this process for each item. Repeat the above procedure until the total Effort for all items stops decreasing, or falls below an acceptable value.

  • Thanks for thes response @user4292363, I've yet to resort to coding a solution, and have resorted to other out of the box api solutions, namely from ESRI's ArcGIS API. I do hope to come back to this and script it myself... but deadlines loom. – Mike Marsh Jan 09 '15 at 16:33
0

In this video https://www.youtube.com/watch?v=RR7GXoWiUw4 you can see how to solve TSP problem. When you will calculate a cost of a route you need check than all tasks are placed in their time windows.

if you don't want write this algorithm you can use Google's library: https://developers.google.com/optimization/routing/tsp/vehicle_routing_time_windows

artamonovdev
  • 2,260
  • 1
  • 29
  • 33