The problem has been solved. Here are my personal insights. Please correct me if I'm wrong. This problem can be abstracted as: in all real-time planning problems, how to synchronously update the shadow variables when changing non-planned variables. In the changeProblemProperty() method of version 9.44.0, it automatically updates the shadow variables, but since I changed the non-planned variables, this modification did not trigger the modification of the listener. I was very troubled by this problem. It's impossible to set this non-planned variable as a planned variable, right? Later, after studying the shadow variables in the official Optaplanning manual, I noticed the description of Piggyback shadow variable, and understood that shadow variables can also influence each other. So, in the changeProblemProperty(), I manually updated the shadow variables, and as I expected, this update triggered the listener, and the subsequent shadow variables also changed, achieving the expected result.The problem has been solved. Here are my personal insights. Please correct me if I'm wrong. This problem can be abstracted as: in all real-time planning problems, how to synchronously update the shadow variables when changing non-planned variables. In the changeProblemProperty() method of version 9.44.0, it automatically updates the shadow variables, but since I changed the non-planned variables, this modification did not trigger the modification of the listener. I was very troubled by this problem. It's impossible to set this non-planned variable as a planned variable, right? Later, after studying the shadow variables in the official Optaplanning manual, I noticed the description of Piggyback shadow variable, and understood that shadow variables can also influence each other. So, in the changeProblemProperty(), I manually updated the shadow variables, and as I expected, this update triggered the listener, and the subsequent shadow variables also changed, achieving the expected result.
Here is the updated code.
private static void modifyTheOrderQuantityToProblem(SolverManager<ProductionSchedule, UUID> solverManager,
UUID problemId, Long sl1, Integer sl2) {
solverManager.addProblemChange(problemId, (workingSolution, problemChangeDirector) -> {
List<ProductionOrder> allOrder = workingSolution.getOrders();
allOrder.stream().filter(order -> order.getOrderId().equals(sl1)).findFirst().ifPresent(order -> {
problemChangeDirector.changeProblemProperty(order,orderOne->{
orderOne.setQuantity(sl2);
List<LocalDateTime> startTimeAndEndTime = orderOne.getStartTimeAndEndTime(workingSolution.getTimePeriodList());
orderOne.setEndTime(startTimeAndEndTime.get(1));
});
});
});
}