按照以下步骤尝试实施重复计划:
使用初始输入数据启动求解器,并使其运行一段时间
终止求解器-终止之前,将bestsolution保存在scoreDirectorFactory.buildScoreDirector()
使用solver.addProblemFactChange(AddCustomerProblemFactChange实例)添加新客户
遵循该方法的optaplanner指南7.10第16.5.1节。 我们在项目中使用过度约束的计划
终止方法(使用rest调用):
VehicleRoutingSolution sol = solver.getBestSolution();
scoreDirectorFactory = solver.getScoreDirectorFactory();
director = scoreDirectorFactory.buildScoreDirector();
director.setWorkingSolution(sol);
solver.terminateEarly();
CustomerList-我要在求解器启动后添加的客户列表
for (Customer customer : customerList) {
AddCustomerProblemFactChange add = new
AddCustomerProblemFactChange(customer);
solver.addProblemFactChange(add);
}
if (!solver.isSolving()) {
VehicleRoutingSolution solution = solver.solve(director.getWorkingSolution());
}
AddCustomerProblemFactChange
public class AddCustomerProblemFactChange implements ProblemFactChange<VehicleRoutingSolution> {
private Customer customer;
public AddCustomerProblemFactChange1(Customer customer) {
this.customer = customer;
}
@Override
public void doChange(ScoreDirector<VehicleRoutingSolution> scoreDirector) {
VehicleRoutingSolution solution = scoreDirector.getWorkingSolution();
solution.setCustomerList( new ArrayList<>(solution.getCustomerList()));
//solution.buildConnectedCustomer(this.distances, this.customer);
scoreDirector.beforeEntityAdded(customer);
solution.getCustomerList().add(customer);
scoreDirector.afterEntityAdded(customer);
scoreDirector.triggerVariableListeners();
}
}
13:31:01.738 [-8080-exec-7] INFO Solving restarted: time spent (3), best score (-1init/0hard/0medium/-39840000soft), environment mode (REPRODUCIBLE), random (JDK with seed 0).
13:31:01.749 [-8080-exec-7] DEBUG CH step (0), time spent (14), score (0hard/-70medium/-39840000soft), selected move count (11), picked move (TimeWindowedCustomer-123{null -> Vehicle-2}).
上述方法的问题是,在添加新客户的同时,总是总是将新添加的实体分配给过度约束的对象(车辆2)。我无法理解optalanner在施工启发式阶段如何选择Vehicle分配给客户。