ProblemFactChange导致影子变量损坏?

时间:2019-06-26 08:49:33

标签: optaplanner

我遇到一个问题事实更改,该问题更改是在构建启发式阶段结束时触发的。该问题事实更改会更改“任务”问题事实的某些属性,这些属性与它们各自的“预订”计划实体具有1对1的关系。

我的域(仅被截短以演示此问题):
[Booking] 1..1 [Task]

SolutionClass(也被截断):

@PlanningEntityCollectionProperty
Collection<Booking> bookings;

@ProblemFactCollectionProperty
Collection<Task> tasks;

到目前为止,这是我的ProblemFactChange:

scoreDirector -> {
    certainBookings.forEach(booking -> {
        BookingSolution workingSolution = scoreDirector.getWorkingSolution();
        Booking workingBooking = scoreDirector.lookUpWorkingObject(booking);
        Task task = workingBooking.getTask();

        // clone task
        Task taskClone = new Task(task);

        // shallow-clone the tasks collection and assign it to the working solution
        Collection<Task> tasksClone = new ArrayList<>(workingSolution.getTasks());
        workingSolution.setTasks(tasksClone);

        // remove the task from the working booking
        scoreDirector.beforeProblemPropertyChanged(workingBooking);
        workingBooking.setTask(null);
        scoreDirector.afterProblemPropertyChanged(workingBooking);

        // remove the task from the cloned list
        scoreDirector.beforeProblemFactRemoved(task);
        tasksClone.remove(task);
        scoreDirector.afterProblemFactRemoved(task);

        // add the cloned task to the cloned list
        scoreDirector.beforeProblemFactAdded(taskClone);
        tasksClone.add(taskClone);
        scoreDirector.afterProblemFactAdded(taskClone);

        // add the cloned task to the working booking
        scoreDirector.beforeProblemPropertyChanged(workingBooking);
        workingBooking.setTask(taskClone);
        scoreDirector.afterProblemPropertyChanged(workingBooking);

        // modify the cloned task's properties
        scoreDirector.beforeProblemPropertyChanged(taskClone);
        taskClone.setThis(newThis);
        taskClone.setThat(newThat);
        scoreDirector.afterProblemPropertyChanged(taskClone);
    });

    scoreDirector.triggerVariableListeners();
};

我期望当Task属性更改并再次调用变量侦听器时解决方案的分数会改变(因为变量侦听器使用这些Task属性来计算相应的Booking参数)。目前,我收到以下损坏消息:

VariableListener corruption after completedAction (Initial score calculated):
    The entity (BookingABC)'s shadow variable (Booking.eventDateTime)'s corrupted value (2019-04-25T13:14) changed to uncorrupted value (2019-04-25T09:10) after all VariableListeners were triggered without changes to the genuine variables.
      Maybe the VariableListener class (ListenerXYZ) for that shadow variable (Booking.eventDateTime) forgot to update it when one of its sources changed.

既然ProblemFactChanges更新了它们,我的变量侦听器是否也必须侦听Booking任务的属性?还是我的ProblemFactChange逻辑损坏或丢失了其他东西?

0 个答案:

没有答案