从VRP移除车辆 [英] Remove a vehicle from VRP

查看:119
本文介绍了从VRP移除车辆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过ProblemFactChange从计划实体集合(类似于OptaPlanner VRP样本中的VehicleRoutingSolution.VehicleList)中删除(=删除)车辆的正确方法是什么?

What is the correct way to remove (=delete) a vehicle from planning entity collection (similar to VehicleRoutingSolution.VehicleList in OptaPlanner VRP samples) via ProblemFactChange?

到目前为止,我已经尝试过

So far I've tried to

  • 在删除车辆之前重置nextCustomer
  • 重置next车辆客户并保持其第一个客户的状态
  • 对车辆上的所有连锁客户进行相同的操作
  • 通过客户列表进行暴力破解

由于prevStandstill和nextCustomer之间的不匹配,或者本地搜索阶段由于未初始化的解决方案而开始失败,因此我得到了IllegalStateException.

I'm getting IllegalStateException, either because of mismatch between prevStandstill and nextCustomer or Local Search phase start failing with an uninitialized solution.

将链中的第一个客户转移到另一辆车上似乎工作正常.

moving the first customer in chain to another vehicle seems to be working fine.

我尝试使用此代码段重设链中的所有客户

I tried to reset all customers in chain with this snippet

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击中

but I'm getting hit with IllegalStateException on second run through loop

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)

这似乎很明显(状态无效,因为第一个客户与第二个客户分离,但是第二个仍指向第一个客户),但是我不知道正确的路线是什么.)

It seems obvious (the state is invalid because first customer is detached from second, but second is still pointing at the first one), but I don't know what's the correct route ;) around it.

    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可以正常工作,并且避免了异常情况.但是,这很糟糕吗?

seems to work - CH is fired for each of the removed customers, move count is correct, EasyScore works and the exception is avoided. But, is it bad?

推荐答案

执行所有这些操作:

  • 该车辆的每个nextCustomer时,将客户的previousStandstill(= var)设置为null,将nextCustomer(=反阴影var)也设置为null,将vehicle(=锚定阴影var)也设置为null
  • 从解决方案的车辆列表中删除车辆
  • While each nextCustomer of that vehicle, set that customer's previousStandstill (= var) on null and it's nextCustomer (= inverse shadow var) also on null and it's vehicle (= anchor shadow var) also on null.
  • Remove the vehicle from the solution's vehicle list

请确保适当地调用before/after方法.

Make sure to call the before/after methods appropriately.

该车辆的客户随后将被初始化,而求解器的CH将对其进行初始化.

The customers of that vehicle will then be uninitialized and the solver's CH will initialize them.

这篇关于从VRP移除车辆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆