Search code examples
javajsprit

How to provide custom time to travel between the locations?


I have 2D array of distances between geo-locations . see the link Map box time to travel

How do I inject this to build the problem in jsprit .


Solution

  • you can try this :

    VehicleRoutingTransportCostsMatrix.Builder vrtcMatrix;
    VehicleRoutingTransportCostsMatrix costsMatrix;
    vrtcMatrix.addTransportDistance(String.valueOf(fromId), String.valueOf(toId),
                                    (double) distance.inMeters);
    vrtcMatrix.addTransportTime(String.valueOf(fromId), String.valueOf(toId),
                                    (double) duration.inSeconds);
    costsMatrix = vrtcMatrix.build();
    

    Then

    VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
        vrpBuilder = vrpBuilder.setRoutingCost(costsMatrix);
    

    You have to set it between all of your combinaison of points. Use a distance matrix calculator to get a good distance/time estimation.

    Hope it helps.