Hi,
I am trying to run the optimizer while vehicles still have shipments to pick up and deliveries to (obviously) deliver. However, the optimizer throws an exception when I run VehicleRoute.Builder.build():
java.lang.IllegalArgumentException: there are still shipments that have not been delivered yet.
at com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute$Builder.build(VehicleRoute.java:298)
The code runs fine if I choose to not add shipments to the initial route. Code structure given below:
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
vrpBuilder.setRoutingCost(costMatrix);
for (int i = 0; i < vehicles.size(); i++) {
VehicleType vehicleType = VehicleTypeImpl.Builder.newInstance("vehicleType" + i)
// *** foo ***
.build();
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle" + i)
// *** foo ***
.setType(vehicleType)
.build();
vrpBuilder.addVehicle(vehicle);
VehicleRoute.Builder initialRoute = VehicleRoute.Builder.newInstance(vehicle);
for (int j = 0; j < assignedPackages.size(); j++) {
// check if package is picked up yet
if ( !assignedPackIsPicked.get(i) ) {
Shipment shipment = Shipment.Builder.newInstance("" + i)
// *** foo ***
.build();
vrpBuilder.addJob(shipment);
initialRoute.addPickup(shipment); // remove this line, and the optimizer runs fine, but without the shipments it should pick up
}
else {
Delivery service = Delivery.Builder.newInstance("" + i)
// *** foo ***
.build();
vrpBuilder.addJob(service);
initialRoute.addService(service);
}
}
vrpBuilder.addInitialVehicleRoute(initialRoute.build()); // exception thrown here
}
I have tried finding a solution to it for quite some time now, without success. Can anyone help with this?
EDIT: Wanted to add, that I am using JSprit 1.7-RC1