【发布时间】:2015-03-20 14:21:20
【问题描述】:
通过 ProblemFactChange 从规划实体集合中移除(=删除)车辆的正确方法是什么(类似于 OptaPlanner VRP 示例中的 VehicleRoutingSolution.VehicleList)?
到目前为止,我已经尝试过
- 在删除车辆之前重置 nextCustomer
- reset nextCustomer of vehicle and prevStandstill of its first customer
- 对车辆上的所有连锁客户做同样的事情
- 暴力破解客户列表
我收到 IllegalStateException,可能是因为 prevStandstill 和 nextCustomer 不匹配,或者本地搜索阶段开始失败并使用未初始化的解决方案。
编辑:将链中的第一个客户转移到另一辆车上似乎工作正常。
编辑 2
我试图用这个 sn-p 重置链中的所有客户
Customer customer = vehicle.getNextCustomer();
while(customer!=null)
{
Customer nextCustomer = customer.getNextCustomer();
scoreDirector.beforeVariableChanged(customer, "previousStandstill"); //Exception on second customer
customer.setPreviousStandstill(null);
scoreDirector.afterVariableChanged(customer, "previousStandstill");
scoreDirector.beforeVariableChanged(customer, "nextCustomer");
customer.setNextCustomer(null);
scoreDirector.afterVariableChanged(customer, "nextCustomer");
customer.setVehicle(null);
customer=nextCustomer;
}
但我在第二次循环运行时遇到了 IllegalStateException
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: The entity (CUST39(after CUST39)) has a variable (previousStandstill) with value (CUST39(after null)) 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.
at org.optaplanner.core.impl.domain.variable.inverserelation.SingletonInverseVariableListener.retract(SingletonInverseVariableListener.java:82)
at org.optaplanner.core.impl.domain.variable.inverserelation.SingletonInverseVariableListener.beforeVariableChanged(SingletonInverseVariableListener.java:44)
at org.optaplanner.core.impl.domain.variable.listener.VariableListenerSupport.beforeVariableChanged(VariableListenerSupport.java:145)
at org.optaplanner.core.impl.score.director.AbstractScoreDirector.beforeVariableChanged(AbstractScoreDirector.java:257)
at org.optaplanner.core.impl.score.director.AbstractScoreDirector.beforeVariableChanged(AbstractScoreDirector.java:228)
看起来很明显(状态无效,因为第一个客户与第二个客户分离,但第二个仍然指向第一个客户),但我不知道它周围的正确路线是什么;)。
这个
Customer nextCustomer = customer.getNextCustomer();
customer.setPreviousStandstill(null);
customer.setNextCustomer(null);
scoreDirector.beforeVariableChanged(customer, "previousStandstill");
scoreDirector.beforeVariableChanged(customer, "nextCustomer");
scoreDirector.afterVariableChanged(customer, "nextCustomer");
scoreDirector.afterVariableChanged(customer, "previousStandstill");
似乎工作 - 为每个被移除的客户解雇 CH,移动计数正确,EasyScore 有效并且避免了异常。但是,不好吗?
【问题讨论】:
标签: optaplanner