Hello,
How can I write a hard constraint to make sure that no 2 vehicles are going to same location? Please suggest.
Hello,
How can I write a hard constraint to make sure that no 2 vehicles are going to same location? Please suggest.
for any jobs that share a same location, add a hard route constraint that all those jobs should be served by the same vehicle
Thanks @jie31best.
I was able to implement this with below approach, it is working fine but do let me know if it needs to be improved.
I am using a state updater to remember the route visiting that location -
stateManager.putProblemState(stateManager.createStateId(service.getLocation().getId()), VehicleRoute.class, route);
and wrote below route constraint -
@Override
public boolean fulfilled(JobInsertionContext insertionContext) {
VehicleRoute route = null;
Service service = (Service) insertionContext.getJob();
try {
route = stateManager.getProblemState(stateManager.createStateId(service.getLocation().getId()), VehicleRoute.class);
} catch (Exception e) {
//Nothing to do
}
if (route == null) return true;
String visitingVehicle = route.getVehicle().getId();
String currentVehicle = insertionContext.getNewVehicle().getId();
return visitingVehicle.equals(currentVehicle);
}