TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
Service service = Service.Builder.newInstance("s").setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setStartLocationCoordinate(Coordinate.newInstance(0, 0))
.setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build();
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){
@Override
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime)*1;
double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime())*100;
return waiting + late;
}
});
VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addVehicle(vehicle).build();
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
assertEquals(0.0,Solutions.bestOf(solutions).getRoutes().iterator().next().getStart().getEndTime(),0.1);