Optimal map routing with Google Maps

后端 未结 5 2020
臣服心动
臣服心动 2021-01-31 05:49

Is there a way using the Google Maps API to get back an \"optimized\" route given a set of waypoints (in other words, a \"good-enough\" solution to the traveling salesman proble

5条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 06:13

    Google has a ready solution for Travel Salesman Problem. It is OR-Tools (Google's Operations Research tools) that you can find here: https://developers.google.com/optimization/routing/tsp

    What you need to do basically is 2 things:

    • Get the distances between each two points using Google Maps API: https://developers.google.com/maps/documentation/distance-matrix/start

    • Then you will feed the distances in an array to the OR-Tools and it will find a very-good solution for you (For certain instances with millions of nodes, solutions have been found guaranteed to be within 1% of an optimal tour).

    You can also note that:

    In addition to finding solutions to the classical Traveling Salesman Problem, OR-Tools also provides methods for more general types of TSPs, including the following:

    • Asymmetric cost problems — The traditional TSP is symmetric: the distance from point A to point B equals the distance from point B to point A. However, the cost of shipping items from point A to point B might not equal the cost of shipping them from point B to point A. OR-Tools can also handle problems that have asymmetric costs.

    • Prize-collecting TSPs, where benefits accrue from visiting nodes

    • TSP with time windows

    Additional links:

    • OR-tools at Github: https://github.com/google/or-tools
    • Get Started: https://developers.google.com/optimization/introduction/get_started

提交回复
热议问题