簡體   English   中英

在 Drools 和 Optaplanner 中進行數學運算

[英]Doing maths in Drools and Optaplanner

我將 optaplanner 與 Drools 結合使用,並且我有一個 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]

這似乎與涉及 mathsDrools 文檔不一致。 我哪里出錯了,我如何在 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;
    }
}

謝謝。

我懷疑ScheduledLesson.getTimeslot()返回一個實例Timeslot ,而不是int

  1. 在java中,添加一個確實return timeslot.getIndex()ScheduledLesson.getTimeslotIndex()方法
  2. 然后在 de DRL 中執行: ScheduledLesson(timeslotIndex == $timeslot.getIndex() + 1, ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM