有地理,数学,历史,艺术,物理5门课程,每门课程分为3节课。例如GeographyA,GeographyB,GeographyC ...
200名学生每人需要在不同的时间段中选择3门课程的3门课程,我们不需要Day变量...
@PlanningEntity
class Lecture {
Student student // not null
Course course // not null
// there 3 timeslot, there is no same klass or same timeslot for student
@PlanningVariable
Klass Klass
@PlanningVariable
Integer timesolt
}
开始演讲
new Lecture(id++, student_1, course_history)
new Lecture(id++, student_1, course_math)
new Lecture(id++, student_1, course_art)
最后,我们需要一个规则,一个学生不应有两个相同的时隙。
rule "student should not have 2 same timeslot"
when
$student: Student()
$timeslotSet: Set() from accumulate (
Lecture(student == $student, $timeslot: timeslot, timeslot != null), collectSet($timeslot)
)
then
scoreHolder.addHardConstraintMatch(kcontext, -(3 - $timeslotSet.size()) * 17);
end
将引发异常,但
rule "student should not have 2 same timeslot"
when
Lecture($id : id, $student: student, $timeslot: timeslot)
Lecture(id > $id, student == $student, timeslot == $timeslot)
then
scoreHolder.addHardConstraintMatch(kcontext, -17); // if
end
效果很好
为什么??
我已经用Google搜索并阅读了文档,有关“ constraintMatch”的内容较少。 对不起我的英语不好