Hi @keymo13,
It is the same VehicleRoutingTransportCosts class Stefan mentioned in the second article.
So, for your purpose, firstly, you need to prepare a time/distance matrix for each time period: e.g., morningMatrix, afternoonMatrix, eveningMatrix, etc. You can use graphhopper or google maps or any similar service to calculate the matrices. If you would like to use graphhopper for this purpose, there are two blog posts on how to integrate traffic data into the process:
After you have got the time-dependent matrices, your problem would be to call corresponding cost matrix in the VehicleRoutingTransportCosts class.
Something like:
vrpBuilder.setRoutingCost(new TimeDependentCosts(vrpBuilder.getLocations(), morningMatrix, afternoonMatrix, eveningMatrix, ...));
Then in the TimeDependentCosts class, in
getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) {}
and
getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) {}
you have something like:
if (time is morning) {
double travelTime = morningMatrix[from.getIndex()][to.getIndex()][1];
double travelDistance = morningMatrix[from.getIndex()][to.getIndex()][0];
VehicleTypeImpl.VehicleCostParams costParams = vehicle.getType().getVehicleCostParams();
double cost = costParams.perDistanceUnit * travelDistance + costParams.perTimeUnit * travelTime;
....
}
Hopefully this helps.
Best regards,
He