Optaplanner将客户从工作VRP解决方案中删除
2022-09-04 23:22:57
基于这个问题,我尝试了以下方法:
public void doFactChange() {
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()) {
while (customer != null) {
if (customer == workingCustomer) {
if (customer.getPreviousStandstill() != null) {
scoreDirector.beforeVariableChanged(customer, "previousStandstill");
customer.getPreviousStandstill().setNextCustomer(customer.getNextCustomer());
scoreDirector.afterVariableChanged(customer, "previousStandstill");
}
scoreDirector.beforeVariableChanged(customer, "nextCustomer");
customer.getNextCustomer().setPreviousStandstill(customer.getPreviousStandstill());
scoreDirector.afterVariableChanged(customer, "nextCustomer");
}
customer = customer.getNextCustomer();
}
}
scoreDirector.beforeEntityRemoved(workingCustomer);
routingSolution.getCustomerList().remove(workingCustomer);
scoreDirector.afterEntityRemoved(workingCustomer);
scoreDirector.triggerVariableListeners();
}
注意:是在调用之前创建的实例对象customerToBeRemoved
doFactChange()
但是,即使在致电之前,我也收到了以下异常scoreDirector.triggerVariableListeners
java.lang.IllegalStateException:实体(Customer--9048381398840634905)有一个变量(previousStandstill)和值(Customer--9070671076516032025),它有一个sourceVariableName变量(nextCustomer),其值(Customer-8518512081385427431)不是该实体。验证该源变量的输入问题的一致性。
另一个问题:
我尝试直接删除实体,如下所示:
public void doFactChange() {
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);
scoreDirector.beforeEntityRemoved(workingCustomer);
routingSolution.getCustomerList().remove(workingCustomer);
scoreDirector.afterEntityRemoved(workingCustomer);
scoreDirector.triggerVariableListeners();
}
这有效吗?