Search code examples
rubyopenstreetmap

How can I use openstreet map to order waypoints?


I saw in articles that OpenStreet map provides an API that, given a route with an origin and destination and multiple (unlimited?) waypoints it sorts the waypoints according to the best route. I couldn't tell which endpoint it was. Could someone point me to the part of the documentation that explains how to achieve this? Is there a ruby gem that wraps up this endpoint request?

Thank you very much


Solution

  • This is the traveling salesman problem. There is more than one OSM-based router for solving this problem. According to a similar question at help.openstreetmap.org:

    All major OSM routing engines support this:

    • Mapzen's Valhalla ("Valhalla also includes tools like time+distance matrix computation, isochrones, elevation sampling, map matching and tour optimization (Travelling Salesman)."),
    • Mapbox's OSRM ("The trip plugin solves the Traveling Salesman Problem using a greedy heuristic...")
    • Graphhopper uses the JSPrit library for route optimization ("TSP problem can be modelled by defining a vehicle routing problem...")

    None of these services have a free and unlimited online offering (it would quickly be abused by people trying to save on their own AWS cost). Mapzen has an offer where you register a free API key and use that. OSRM doesn't need an API key, you can just use it. Graphhopper requires registration and while they have a free trial, I don't think they have a free tier.

    All three are Open Source and you can install and use them without limits locally.

    For GraphHopper take a look at the Route Optimization API. For OSRM see the trip plugin.