[英]Optaplanner / Drools throws exception in solverFactory.buildSolver()
[英]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]
這似乎與涉及 maths的Drools 文檔不一致。 我哪里出錯了,我如何在 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
。
return timeslot.getIndex()
的ScheduledLesson.getTimeslotIndex()
方法ScheduledLesson(timeslotIndex == $timeslot.getIndex() + 1, ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.