Constraint roomConflict(ConstraintFactory constraintFactory) { // A room can accommodate at most one lesson at the same time. return constraintFactory // Select each pair of 2 different lessons ... .forEachUniquePair(Lesson.class, // ... in the same timeslot ... Joiners.equal(Lesson::getTimeslot), // ... in the same room ... Joiners.equal(Lesson::getRoom)) // ... and penalize each pair with a hard weight. .penalize("Room conflict", HardSoftScore.ONE_HARD); }
There is no automated translation available; the constraint just has to be re-implemented in the Drools language.
For this particular constraint, it would be something along these lines:
rule "room conflict"
when
Lesson($id : id, $timeslot : timeslot, $room : room)
Lesson(id > $id, timeslot == $timeslot, room == $room)
then
scoreHolder.addHardConstraintMatch(kcontext, 1);
end
It's actually similar to the original constraint definition: we penalize every pair of two distinct lessons that take place in the same room and at the same timeslot.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.