-
Notifications
You must be signed in to change notification settings - Fork 609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution is crashed if there is any unassigned drivers in solution when using MaxTimeInVehicleConstraint #454
Comments
I met the same question of Null pointer exception in MaxTimeInVehicleConstraint (line:106), but I think that is not because of the unassigned drivers, but the different types of vehicle. Here is the code, based on MaxTimeInVehicle_IT @Test
public void maxTimeNullPointer() {
Shipment s1 = Shipment.Builder.newInstance("s1").setPickupLocation(Location.newInstance(0, 0))
.setDeliveryLocation(Location.newInstance(100, 0))
.setDeliveryServiceTime(10).setMaxTimeInVehicle(100d).build();
Shipment s2 = Shipment.Builder.newInstance("s2").setPickupLocation(Location.newInstance(0, 0))
.setDeliveryLocation(Location.newInstance(100, 0))
.setDeliveryServiceTime(10).setMaxTimeInVehicle(100d).build();
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type1").addCapacityDimension(0, 10).build();
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type2").addCapacityDimension(0, 7).build();
VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance(0, 0)).setType(type1).build();
// ***** if the type of v2 change to type1, the program works fine. *****
VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance(0, 0)).setType(type2).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance()
.addVehicle(v1).addVehicle(v2).addJob(s1).addJob(s2).build();
StateManager stateManager = new StateManager(vrp);
StateId id = stateManager.createStateId("max-time");
StateId openJobsId = stateManager.createStateId("open-jobs-id");
stateManager.addStateUpdater(new UpdateMaxTimeInVehicle(stateManager, id, vrp.getTransportCosts(), vrp.getActivityCosts(), openJobsId));
ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager);
constraintManager.addConstraint(new MaxTimeInVehicleConstraint(vrp.getTransportCosts(), vrp.getActivityCosts(), id, stateManager, vrp, openJobsId), ConstraintManager.Priority.CRITICAL);
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp)
.setStateAndConstraintManager(stateManager, constraintManager)
.buildAlgorithm();
VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions());
SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);
} And the exception stacktrace
|
Since vehicle switch does not matter for this constraint, I've used the simple fix to replace line 106 in MaxTimeInVehicleConstraint with the following Basically to check previous vehicle if minSlack data is not found for new vehicle. |
Thanks, @sdTolik that's a huge help. I also needed a similar patch around line 144
|
MaxTimeInVehicleConstraint got crashed in fulfilled(...) method if there is any unassigned drivers in solution.
This will cause whole solution got error when we can still have solution with one drive.
Please try MaxTimeInVehicle with multi-vehicle and there is an unassigned driver in solution.
I move whole code in method above inside try/catch block and everything works fine.
The text was updated successfully, but these errors were encountered: