teacherTimeEfficiency with max 2 lesson in dayOfWeek? #1322
hangocanh2303
started this conversation in
General
Replies: 1 comment 2 replies
-
There are various ways:
private static boolean isConsecutive(Lesson a, Lesson b) {
Duration between = Duration.between(lesson1.getTimeslot().getEndTime(),
lesson2.getTimeslot().getStartTime());
return !between.isNegative() && between.compareTo(Duration.ofMinutes(30)) <= 0;
}
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()))
// can do a filter here to check for subject
.filter(SchoolTimetablingConstraintProvider::isConsecutive)
.ifNotExist(Lesson.class,
Joiners.equal(Lesson::getTeacher),
Joiners.equal((lesson) -> lesson.getTimeslot().getDayOfWeek()),
// lesson1 is before lesson2
// check if lesson3 is consecutively before lesson1 or consecutively after lesson2
Joiners.filtering((lesson1, lesson2, lesson3) -> isConsecutive(lesson3, lesson1) || isConsecutive(lesson2, lesson3))
)
.reward(HardSoftScore.ONE_SOFT)
.justifyWith((lesson1, lesson2, score) -> new TeacherTimeEfficiencyJustification(lesson1.getTeacher(), lesson1, lesson2))
.asConstraint("Teacher time efficiency 2 consecutive lessons");
}
Constraint teacherTimeEfficiency(ConstraintFactory constraintFactory) {
// A teacher prefers to teach sequential lessons and dislikes gaps between lessons.
return constraintFactory
.forEach(Lesson.class)
.groupBy(
// If you want consecutive lessons on the same subject, uncomment the next line
// lesson -> lesson.getSubject(),
lesson -> lesson.getTimeslot().getDayOfWeek(),
ConstraintCollectors.toConnectedTemporalRanges(
lesson -> lesson.getTimeslot().getStartTime(),
lesson -> lesson.getTimeslot().getEndTime())
)
.flattenLast(ConnectedRangeChain::getConnectedRanges)
.filter((day, connectedRange) -> connectedRange.
getContainedRangeCount() == 2) // note: overlapping lessons would be counted as consecutive, but that usually handled by a hard constraint
.reward(HardSoftScore.ONE_SOFT)
.asConstraint("Teacher time efficiency 2 consecutive lessons");
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In school timetabling, function teacherTimeEfficiency. Sometimes timefold sets 3 or 4 consecutive lessons of the same teacher in 1 dayOfWeek.
How to set priority 2 consecutive lessons with some subjects like literature or math?
Beta Was this translation helpful? Give feedback.
All reactions