Optaplanner 8 - 学校时间表 constraintFactory 避免在同一天出现较早的空时隙
Optaplanner 8 - School timetabling constraintFactory avoid earlier empty timeslots in the same day
我正在学习 Optaplanner,如果涉及课程,我在创建新约束方面取得了巨大成功。但是,如果没有分配给时间段的课程,我正在努力弄清楚如何创建 constraintFactory。
我会从早上开始补课,如果可能的话,我会用 .reward("no empty earlier time slots", HardSoftScore.ONE_SOFT)。类似于:
import org.acme.kotlin.schooltimetabling.domain.Timeslot
...
fun noEmptyEarlierTimeslots(constraintFactory: ConstraintFactory): Constraint {
// try to fill the slots from the start and have not empty slots later in the day on the same day
return constraintFactory
.from(Timeslot::class.java)
.join(Timeslot::class.java)
.filter { slot1: Timeslot, slot2: Timeslot -> slot1.startTime.toLocalDate() === slot2.startTime.toLocalDate() }
slot1.startTime < slo2.startTime && ifNotExists(slot1::Lesson) && ifExists(slot2::Lesson)
.reward("no empty earlier time slots", HardSoftScore.ONE_SOFT)
}
[我将 startTime 和 endTime 更改为 localDateTime - 因此 toLocalDate() ]
任何帮助将不胜感激。
"if there is no lesson assigned to a timeslot."
我认为 .ifNotExists()
可能适用于此。基本上类似于 from(Timeslot.class).ifNotExists(Lesson.class, equal(identity(), Lesson::getTimeslot)...
"I would fill lessons from the morning and have not empty slots if possible"
看看示例中的这个约束:
Constraint teacherTimeEfficiency(ConstraintFactory constraintFactory) {
// A teacher prefers to teach sequential lessons and dislikes gaps between lessons.
return constraintFactory
.from(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() && between.compareTo(Duration.ofMinutes(30)) <= 0;
})
.reward("Teacher time efficiency", HardSoftScore.ONE_SOFT);
}
我正在学习 Optaplanner,如果涉及课程,我在创建新约束方面取得了巨大成功。但是,如果没有分配给时间段的课程,我正在努力弄清楚如何创建 constraintFactory。
我会从早上开始补课,如果可能的话,我会用 .reward("no empty earlier time slots", HardSoftScore.ONE_SOFT)。类似于:
import org.acme.kotlin.schooltimetabling.domain.Timeslot
...
fun noEmptyEarlierTimeslots(constraintFactory: ConstraintFactory): Constraint {
// try to fill the slots from the start and have not empty slots later in the day on the same day
return constraintFactory
.from(Timeslot::class.java)
.join(Timeslot::class.java)
.filter { slot1: Timeslot, slot2: Timeslot -> slot1.startTime.toLocalDate() === slot2.startTime.toLocalDate() }
slot1.startTime < slo2.startTime && ifNotExists(slot1::Lesson) && ifExists(slot2::Lesson)
.reward("no empty earlier time slots", HardSoftScore.ONE_SOFT)
}
[我将 startTime 和 endTime 更改为 localDateTime - 因此 toLocalDate() ]
任何帮助将不胜感激。
"if there is no lesson assigned to a timeslot."
我认为 .ifNotExists()
可能适用于此。基本上类似于 from(Timeslot.class).ifNotExists(Lesson.class, equal(identity(), Lesson::getTimeslot)...
"I would fill lessons from the morning and have not empty slots if possible"
看看示例中的这个约束:
Constraint teacherTimeEfficiency(ConstraintFactory constraintFactory) {
// A teacher prefers to teach sequential lessons and dislikes gaps between lessons.
return constraintFactory
.from(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() && between.compareTo(Duration.ofMinutes(30)) <= 0;
})
.reward("Teacher time efficiency", HardSoftScore.ONE_SOFT);
}