Search code examples
javajsprit

How to use FastVehicleRoutingTransportCostsMatrix , I have Time Matrix?


FastVehicleRoutingTransportCostsMatrix

I am having adjacency Matrix of time ,taken from Mapbox . Mapbox distance API . I don't have the distance Matrix .How can I calculate cost ?


Solution

  • A quick scan of the documentation suggests that the "Distance API" is only capable of returning travel times... how illogical!

    Using this API I would say there is no way to do this, but perhaps building your matrix via the Directions API would be possible. The only thing you could do would be to estimate an average driving speed and calculate the estimated distance. But adding .setCostPerDistance with this estimate would have no bearing on the solution because all you do is inflate the travel costs by a fixed factor.

    If your issue is that JSprit is throwing errors because both a distance and time matrix are required for a custom matrix (I don't remember), just make fake distances and don't set a cost parameter per distance (or 0 cost).

    So, your options are to stick to Mapbox Distance API and not consider cost per distance, or switch API to one that gives you both distance and time. One option would be hosting your own Graphhopper server, and there are simple quick-start guides available to do this. Jsprit and Graphhopper have teamed up, and it is also bundled into ODL Studio.