Drools 当我在规则文件中使用collect(…)中的List()时,Optaplanner无法删除ConstraintMatch

Drools 当我在规则文件中使用collect(…)中的List()时,Optaplanner无法删除ConstraintMatch,drools,optaplanner,Drools,Optaplanner,在规则文件中使用collect(…)中的List()时,Optaplanner无法删除ConstraintMatch then $staff : StaffAssignment(shiftType != null) $li : HashSet() from collect ( TimeSetDto(timeSet != null) from $staff.getTimeSet(

在规则文件中使用collect(…)中的
List()
时,Optaplanner无法删除ConstraintMatch

then
    $staff : StaffAssignment(shiftType != null)
            $li : HashSet()
                    from collect (
                        TimeSetDto(timeSet != null) from $staff.getTimeSet()
                    )
then

在规则中使用集合对于OptaPlanner来说通常是有问题的,因为每次添加或删除对象时,集合的hashCode()都会更改。 这会混淆OptaPlanner的约束匹配算法,并导致您看到的异常

在OptaPlanner 8.3.0中,我们做了一些可能(也可能没有)有助于解决问题的更改。同时,有两种变通办法:

  • 禁用约束匹配或
  • 不要在规则中使用集合

在涉及的域对象上是否有equals和hashcode实现?