【问题标题】:Remove a vehicle from VRP从 VRP 中移除车辆
【发布时间】: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


    【解决方案1】:

    做所有这些:

    • 当该车辆的每个 nextCustomer 时,将该客户的 previousStandstill (= var) 设置为 null 并且它的 nextCustomer (= inverse shadow var) 也设置为 null 并且它的 vehicle (= anchor shadow var) 也设置为 null .
    • 从解决方案的车辆列表中删除车辆

    确保正确调用 before/after 方法。

    然后,该车辆的客户将被取消初始化,求解器的 CH 将对其进行初始化。

    【讨论】:

    • 谢谢,车辆的方法是 Before/AfterEntityRemoved,每个客户变量的方法是 Before/AfterVariableChanged?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-24
    • 1970-01-01
    • 1970-01-01
    • 2020-04-17
    • 2019-06-15
    • 1970-01-01
    相关资源
    最近更新 更多