问题
Based on this example from cloud balancing problem, I'm trying to remove customer from a working solution as follows:
Location toBeRemovedLocation = customerToBeRemoved.getLocation();
Location lookUpWorkingObject = (Location) scoreDirector.lookUpWorkingObject(toBeRemovedLocation);
scoreDirector.beforeProblemFactRemoved(lookUpWorkingObject);
routingSolution.getLocationList().remove(lookUpWorkingObject);
scoreDirector.afterProblemFactRemoved(lookUpWorkingObject);
Customer workingCustomer=(Customer) scoreDirector.lookUpWorkingObject(customerToBeRemoved);
for (Customer customer : routingSolution.getCustomerList()) {
nextCustomer=customer.getNextCustomer();
if (nextCustomer==workingCustomer) {
scoreDirector.beforeVariableChanged(customer, "nextCustomer");
customer.setNextCustomer(null);
scoreDirector.afterVariableChanged(customer, "nextCustomer");
}
}
scoreDirector.beforeEntityRemoved(workingCustomer);
routingSolution.getCustomerList().remove(workingCustomer);
scoreDirector.afterEntityRemoved(workingCustomer);
scoreDirector.triggerVariableListeners();
I got this exception as a result:
java.lang.IllegalStateException: The entity (Customer--6361356485874019865) has a variable (previousStandstill) with value (Customer--9027426768799526425) which has a sourceVariableName variable (nextCustomer) with a value (null) which is not that entity.Verify the consistency of your input problem for that sourceVariableName variable
After that, I tried to also setPreviousStandstill
to null
:
scoreDirector.beforeVariableChanged(customer, "previousStandstill");
customer.setPreviousStandstill(null);
scoreDirector.afterVariableChanged(customer, "previousStandstill");
But, I received:
java.lang.IllegalStateException: The entity (Customer--6361368382933429785) has a variable (previousStandstill) with value (Customer--9027434800388369945) which has a sourceVariableName variable (nextCustomer) with a value (null) which is not that entity.Verify the consistency of your input problem for that sourceVariableName variable.
Need help, please.
回答1:
Customers in VRP are chained/linked, if you currently have a chain [Customer1, Customer2, Customer3]
- Customer1: nextCustomer = Customer2
- Customer2: nextCustomer = Customer2, prevStandstill = Customer1
- Customer3: prevStandstill = Customer2
and you're trying to remove Customer2 from it, you have to fix both previous and next elements:
- Customer1: nextCustomer = Customer3
- Customer2: nextCustomer = null, prevStandstill = null
- Customer3: prevStandStill = Customer1
来源:https://stackoverflow.com/questions/47913276/optaplanner-vrp-remove-customer-from-working-solution