在一个有时间窗的Capcity vehicle Routing Problem (CVRPTW)中,我在跟踪车辆的持续能力时遇到了问题。
当车辆达到最大载客量时,我正试图使车辆返回仓库。
根据我在这里得到的回应,https://groups.google.com/forum/#!topic/optaplanner-dev/IMG_7D1JvmQ,我目前正在尝试实现每天n次旅行的设计。
我尝试在车辆上使用阴影变量,并在其上使用变量侦听器。
我修改了vehicle类,如下所示:
@XStreamAlias("VrpVehicle")
public class Vehicle extends AbstractPersistable implements Standstill {
...planning entities
...other shadow variables
protected Integer currentDemand;
@CustomShadowVariable(sources = {@PlanningVariableReference(variableName = "previousStandstill")})
public Integer getCurrentDemand() { return currentDemand; }
}
}
我的变量监听器如下:
public class VehicleCapacityReuseVariableListener implements VariableListener<Customer> {
@Override
public void afterEntityAdded(ScoreDirector scoreDirector,Customer customer) {
if (customer instanceof TimeWindowedCustomer) {
updateVehicleDemandTotal(scoreDirector, (TimeWindowedCustomer) customer);
}
}
@Override
public void afterVariableChanged(ScoreDirector scoreDirector, Customer customer) {
if (customer instanceof TimeWindowedCustomer) {
updateVehicleDemandTotal(scoreDirector, (TimeWindowedCustomer) customer);
}
}
...
protected void updateVehicleDemandTotal(ScoreDirector scoreDirector, Customer sourceCustomer) {
Standstill previousStandstill = sourceCustomer.getPreviousStandstill();
Vehicle vehicle = previousStandstill == null ? null : previousStandstill.getVehicle();
TimeWindowedCustomer shadowCustomer = (TimeWindowedCustomer) sourceCustomer;
Integer currentDemand = shadowCustomer.getDemand();
Vehicle currentVehicle = shadowCustomer.getVehicle();
Vehicle nextVehicle = currentVehicle;
while (shadowCustomer != null) {
scoreDirector.beforeVariableChanged(shadowCustomer, "vehicle");
currentVehicle = shadowCustomer.getVehicle();
scoreDirector.afterVariableChanged(shadowCustomer, "vehicle");
shadowCustomer = shadowCustomer.getNextCustomer();
if (shadowCustomer != null) {
nextVehicle = shadowCustomer.getVehicle();
if (!currentVehicle.equals(nextVehicle)){
nextVehicle.setCurrentDemand(currentDemand);
currentVehicle.setCurrentDemand(currentVehicle.getCurrentDemand() - currentDemand);
currentDemand = nextVehicle.getCurrentDemand();
}
currentDemand += shadowCustomer.getDemand();
nextVehicle.setCurrentDemand(currentDemand);
}
}
}
}
如果有人能帮我跟踪容量,那就太好了。
我认为解决方案(回到仓库)应该是将下一个客户设置为“仓库”客户。
PS。还有其他与此相关的堆栈溢出问题,我已经尝试过了,但都没有用。出于完整性考虑:
感谢你花时间来看这篇文章,也非常感谢任何回复的人。
发布于 2018-06-06 09:03:47
我不能完全回答您的问题,但我确实在您的侦听器实现中发现了一个问题。台词
scoreDirector.beforeVariableChanged(shadowCustomer, "vehicle");
scoreDirector.afterVariableChanged(shadowCustomer, "vehicle");
必须将修改计划变量的任何线括起来,例如:
nextVehicle.setCurrentDemand(currentDemand);
我认为Geoff建议的是,如果您的容量达到0,您的vehicle.getDistanceToPreviousStandstill函数会将到站点的距离添加到计算中。(这只是我的猜测,我没有读太多关于Geoff的设计评论)。
https://stackoverflow.com/questions/50705596
复制相似问题