在Drools和Optaplanner中进行数学运算

问题描述 投票:0回答:1

我与Drools一起使用optaplanner,并且有Drools规则:

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

注意第4行中的timeslot == $timeslot + 1件。这给出了以下错误:

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

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

ScheduledLesson看起来像这样:

@PlanningEntity
public class ScheduledLesson {
    public Lesson lesson;

    public Lesson getLesson() {
        return this.lesson;
    }

    public void setLesson(Lesson lesson) {
        this.lesson = lesson;
    }

    public Integer timeslot;

    @PlanningVariable(valueRangeProviderRefs = {"timeslot"})
    public Integer getTimeslot() {
        return this.timeslot;
    }
    public void setTimeslot(Integer timeslot) {
        this.timeslot = timeslot;
    }

    public Room room;
    @PlanningVariable(valueRangeProviderRefs = {"room"})
    public Room getRoom() {
        return this.room;
    }
    public void setRoom(Room room) {
        this.room = room;
    }
}

谢谢。

java drools optaplanner
1个回答
0
投票

在Java中,添加一个ScheduledLesson.getTimeslotIndex()return timeslot.getIndex()

© www.soinside.com 2019 - 2024. All rights reserved.