我想强制同一系列学生的学生组处于同一课程类型的同一时间段和同一房间。
这是我的尝试:
Constraint seminarsGroupedInTheSameTimeslot(ConstraintFactory constraintFactory){
return constraintFactory
//select each 2 pair of different lessons
.forEachUniquePair(Lesson.class,
//with the same group
Joiners.equal((lesson) -> lesson.getStudentGroup().getGroup()),
//with the same series
Joiners.equal((lesson) -> lesson.getStudentGroup().getName()),
//with the same subject
Joiners.equal(Lesson::getSubject),
//with the same Seminar type
Joiners.equal((lesson) -> lesson.getType().equals(LessonType.SEMINAR))
)
//check if the lessons have different timeslots and rooms
.filter(((lesson, lesson2) -> {
return !(lesson.getTimeslot().equals(lesson2.getTimeslot()) &&
lesson.getRoom().equals(lesson2.getRoom()));
}))
.penalize(HardSoftScore.ONE_HARD)
.asConstraint("Seminars should be grouped in the same timeslot and room");
}
我知道这不是最好的解决方案,因为不可扩展,并且它会给每一对违反约束的课程带来惩罚(即,如果分析了 10 个课程,并且只有一个课程实例违反了约束,则分数将是 -9 而不是 -1)。
我尝试添加 ifNotExists() 方法以仅考虑连续的课程 ID,但收到以下警告:未检查 varargs 参数的泛型数组创建。
我怎样才能更好地写出这种约束呢?