Total time should be optimized by JSprit without any customization. About same amount time - i think easest way is to create custom SolutionCostCalculator
and increase route cost if time is not same.
public class CustomSolutionCostCalculator implements SolutionCostCalculator {
private StateManager stateManager;
public SPSolutionCostCalculator(StateManager aStateManager) {
stateManager = aStateManager;
}
@Override
public double getCosts(VehicleRoutingProblemSolution solution) {
double cost = 0.0;
// calculate cost
return cost;
}
}
and then use it while create algorithm:
VehicleRoutingProblem vrp = vrpBuilder.build();
// init your vrp
VehicleRoutingAlgorithm algorithm = Jsprit.Builder.newInstance(vrp)
.setObjectiveFunction(new SPSolutionCostCalculator(stateManager))
.buildAlgorithm();
Collection<VehicleRoutingProblemSolution> searchSolutions = algorithm.searchSolutions();
VehicleRoutingProblemSolution solution = Solutions.bestOf(searchSolutions);