timefold - teacherTimeEfficiency with max 2 lesson in dayOfWeek? - Stack Overflow

admin2025-04-27  3

In school timetabling, function teacherTimeEfficiency. Sometimes timefold sets 3 or 4 consecutive lessons of the same teacher in 1 dayOfWeek.

Constraint teacherTimeEfficiency(ConstraintFactory constraintFactory) {
        // A teacher prefers to teach sequential lessons and dislikes gaps between lessons.
        return constraintFactory
                .forEach(Lesson.class)
                .join(Lesson.class, Joiners.equal(Lesson::getTeacher),
                        Joiners.equal((lesson) -> lesson.getTimeslot().getDayOfWeek()))
                .filter((lesson1, lesson2) -> {
                    Duration between = Duration.between(lesson1.getTimeslot().getEndTime(),
                            lesson2.getTimeslot().getStartTime());
                    return !between.isNegative() && betweenpareTo(Duration.ofMinutes(30)) <= 0;
                })
                .reward(HardSoftScore.ONE_SOFT)
                .justifyWith((lesson1, lesson2, score) -> new TeacherTimeEfficiencyJustification(lesson1.getTeacher(), lesson1, lesson2))
                .asConstraint("Teacher time efficiency");
}

How to set priority 2 consecutive lessons with some subjects like literature or math?

转载请注明原文地址:http://anycun.com/QandA/1745706760a91097.html