在Drools和Optaplanner中进行数学运算

时间:2019-11-25 21:23:40

标签: java drools optaplanner

我正在将Optaplanner与Drools结合使用,并且有Drools规则:

basename `cat /proc/1/cpuset`
7be92808767a667f35c8505cbf40d14e931ef6db5b0210329cf193b15ba9d605

这很好。

我想确保学生没有背对背的课程:

rule "No student double booked"
    when
        ScheduledLesson($timeslot : timeslot, $student : lesson.student)
        ScheduledLesson(timeslot == $timeslot, lesson.student == $student)
    then
        scoreHolder.addHardConstraintMatch(kcontext, -1);
end

请注意第四行的rule "Student does not have contiguous lessons" when ScheduledLesson($timeslot : timeslot, $student : lesson.student) ScheduledLesson(timeslot == $timeslot + 1, lesson.student == $student) then scoreHolder.addHardConstraintMatch(kcontext, -1); end 件。这给出了以下错误:

timeslot == $timeslot + 1

这似乎与Drools documentation which touches on maths不符。我要去哪里错了,如何在Drools中实施此规则?

Exception in thread "main" java.lang.RuntimeException: Error evaluating constraint 'timeslot == $timeslot + 1' in [Rule "Student does not have contiguous lessons" filename] 看起来像这样:

ScheduledLesson

谢谢。

1 个答案:

答案 0 :(得分:0)

我怀疑redisAsyncSetConnectCallback返回了实例ScheduledLesson.getTimeslot(),而不是Timeslot

  1. 在Java中,添加一个int方法 ScheduledLesson.getTimeslotIndex()
  2. 然后在de DRL中执行:return timeslot.getIndex()