Geoffrey, thanks for response.
The the Customer
"toRemove" instance IS the same instance as which is in the workingSolution's
Customer list. In fact, in the test example I have attached, I get that instance via:
final Customer toRemove = workingSolution.getCustomerList().get(0);
I try to reproduce the hack in CloudBalancing's problemFactChange implementation, but with no success. I mean, I tried:
// to clean the next variable of previous in the chain
Standstill prev = toRemove.getPreviousStandstill();
scoreDirector.beforeEntityRemoved(prev);
prev.setNextCustomer(null);
scoreDirector.afterEntityRemoved(prev);
but this throw an exception like:
java.lang.IllegalStateException: The entity (1(after 66)) has a variable (previousStandstill) with value (66(after 51)) which has a mappedBy variable (nextCustomer) with a value (null) which is not that entity.
Also, i try to clean the previous variable of the following item in the chain:
// to clean the previous variable of the following customer in the chain
Customer nextCustomer = toRemove.getNextCustomer();
if (nextCustomer != null) {
scoreDirector.beforeEntityRemoved(nextCustomer);
nextCustomer.setPreviousStandstill(null);
scoreDirector.beforeEntityRemoved(nextCustomer);
}
but this throw an exception like:
java.lang.IllegalStateException: The ScoreDirector (class org.optaplanner.core.impl.score.director.common.TrailingEntityMapSupport) is corrupted, because the entity (10(after null)) for chained planningVariable (previousStandstill) cannot be retracted: it was never inserted.