Optaplanner VRP将客户从工作解决方案中移除 [英] Optaplanner VRP remove customer from working solution
问题描述
基于此示例从云平衡问题出发,我正尝试从一个可行的解决方案中删除客户,如下所示:
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:实体 (客户--6361356485874019865)具有变量(previousStandstill) 值(客户--9027426768799526425)具有 具有值(null)的sourceVariableName变量(nextCustomer),其中 不是那个实体.验证您输入问题的一致性 该sourceVariableName变量
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
在那之后,我还尝试了setPreviousStandstill
到null
:
After that, I tried to also setPreviousStandstill
to null
:
scoreDirector.beforeVariableChanged(customer, "previousStandstill");
customer.setPreviousStandstill(null);
scoreDirector.afterVariableChanged(customer, "previousStandstill");
但是,我收到了:
java.lang.IllegalStateException:实体 (客户--6361368382933429785)具有变量(previousStandstill) 的价值(客户--9027434800388369945)具有 具有值(null)的sourceVariableName变量(nextCustomer),其中 不是那个实体.验证您输入问题的一致性 该sourceVariableName变量.
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.
需要帮助.
推荐答案
如果您当前有[Customer1,Customer2,Customer3]链,则VRP中的客户是链接/链接的.
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
,并且您要尝试从中删除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
这篇关于Optaplanner VRP将客户从工作解决方案中移除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!