问题描述
我遇到了这个异常:
调试后,我发现 ConstraintMatchSet
具有相同的 ConstraintMatch
对象,该对象现在正尝试将其删除(都具有相同的哈希码,并且现在等于),但无法将其删除
After debugging, I figured ConstraintMatchSet
has same ConstraintMatch
object which it's trying to remove right now(both has same hashcode and equals now), yet it's unable to remove it.
我想出的原因是, ConstraintMatch.justificationList
有一个内部列表,该列表的对象数量不同,因此在插入时它计算出不同的哈希码,因此由于set(哈希表)在当前哈希处找不到对象.
The reason I figured is, ConstraintMatch.justificationList
has an inner list whose number of objects are different and hence it calculated different hashcode at the time of insertions so it's not able to remove now because set (hashtable) does not find object at current hash.
我认为,如果我可以避免添加所有的何时"字样,它将解决我的问题.对象放入constraintMatch的justificationList中,但不知道该怎么做.帮助吗?
I think it'll solve my problem if I could avoid adding all "when" objects into justificationList of constraintMatch but dont know how to do it. Help?
这是我的规则:
rule "Minimum Consecutive Nights"
salience 20
when
$emp:Employee()
$shifts:ArrayList(size>0) from collect (ShiftRequestPhase(getInterval()!=null && employee.equals($emp)))
$constraintsPenality: Integer(intValue>0) from ($emp.checkConstraints($shifts,6))
then
$emp.breakLevelConstraints(scoreHolder,kcontext,6,$constraintsPenality);
end
推荐答案
我使用Java 9和最新的Drools&Optaplanner版本(7.6.0-最终版).我需要非常快速的 hack 来解决此问题,因此我只是禁用了ConstraintMatch集合. AbstractScoreHolder
类允许在构造函数中设置布尔值
I ran into the very same problem using Java 9 and newest Drools & Optaplanner Version (7.6.0-Final). I needed a very quick hack to circumvent this problem hence I simply disabled the ConstraintMatch collection. The AbstractScoreHolder
Class allows setting an boolean in the constructor
受保护的AbstractScoreHolder(布尔约束,MatchEnabled,零得分)
如果不需要 IndictmentMap
,则不需要 constraintMatchTotal
.我只是禁用了此功能.功能,并且有效.
The constraintMatchTotal
is not necessary if you do not need the IndictmentMap
. I simply disabled this. feature and it worked.
@GeoffreyDeSmet:不幸的是,我无法为您提供示例,但我将其缩小到规则文件中collect(...)中使用 List()的代码行.如果我在规则中完全避免使用这些
List()
,则一切正常.也许有帮助吗?!
@GeoffreyDeSmet: Unfortunately i cannot provide an example for you but I narrowed it down to code lines with List() from collect (...)
in the rule file. If i completely avoid those List()
in my rules everything works fine. Maybe this helps?!
这篇关于Optaplanner无法删除ConstraintMatch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!