VehicleUpdatingVariableListener 从版本 6.0 中的 7.2 optaplanner 中删除
VehicleUpdatingVariableListener is removed from 7.2 optaplanner which was there in version 6.0
public class VehicleUpdatingVariableListener implements PlanningVariableListener<Customer> {}
以上 class 已在 7.2 最终版本中删除。
在我的 Optaplanner 实现中,我在 updateVehicle 方法中编写了一段代码,该方法位于 class.
上方
protected void updateVehicle(ScoreDirector scoreDirector, Customer sourceCustomer) {}
添加的代码在客户更新车辆时使用,我也用于更新对应车辆。
counterpart : 添加了一个额外的影子变量。
所以,我怎么能在 7.2 版中做到这一点?
编辑 1
protected void updateVehicle(ScoreDirector scoreDirector, Customer sourceCustomer) {
Standstill previousStandstill = sourceCustomer.getPreviousStandstill();
Vehicle vehicle = previousStandstill == null ? null : previousStandstill.getVehicle();
Customer shadowCustomer = sourceCustomer;
while (shadowCustomer != null && shadowCustomer.getVehicle() != vehicle) {
scoreDirector.beforeVariableChanged(shadowCustomer, "vehicle");
scoreDirector.beforeVariableChanged(shadowCustomer.getCounterpartCustomer(),"vehicle");
shadowCustomer.setVehicle(vehicle);
scoreDirector.afterVariableChanged(shadowCustomer, "vehicle");
scoreDirector.afterVariableChanged(shadowCustomer.getCounterpartCustomer(),"vehicle");
shadowCustomer = shadowCustomer.getNextCustomer();
}
}
public class VehicleUpdatingVariableListener implements PlanningVariableListener<Customer> {}
以上 class 已在 7.2 最终版本中删除。 在我的 Optaplanner 实现中,我在 updateVehicle 方法中编写了一段代码,该方法位于 class.
上方protected void updateVehicle(ScoreDirector scoreDirector, Customer sourceCustomer) {}
添加的代码在客户更新车辆时使用,我也用于更新对应车辆。 counterpart : 添加了一个额外的影子变量。
所以,我怎么能在 7.2 版中做到这一点?
编辑 1
protected void updateVehicle(ScoreDirector scoreDirector, Customer sourceCustomer) {
Standstill previousStandstill = sourceCustomer.getPreviousStandstill();
Vehicle vehicle = previousStandstill == null ? null : previousStandstill.getVehicle();
Customer shadowCustomer = sourceCustomer;
while (shadowCustomer != null && shadowCustomer.getVehicle() != vehicle) {
scoreDirector.beforeVariableChanged(shadowCustomer, "vehicle");
scoreDirector.beforeVariableChanged(shadowCustomer.getCounterpartCustomer(),"vehicle");
shadowCustomer.setVehicle(vehicle);
scoreDirector.afterVariableChanged(shadowCustomer, "vehicle");
scoreDirector.afterVariableChanged(shadowCustomer.getCounterpartCustomer(),"vehicle");
shadowCustomer = shadowCustomer.getNextCustomer();
}
}