By implementing checkSpareHoursAndNoonBreak()
in the RHS side, it doesn't do delta based score calculation as much as it could. (See docs section on incremental / delta based score calculation).
I'd try to write the rule something like this:
when
$t : Traject()
$l1 : Lecture(traject == $t, $d : day, $p1 : period)
// Another lecture on the same day, but after the original one
$l3 : Lecture(traject == $t, day == $d, period > $p1, $p3: period)
// No lecture in between
not Lecture(traject == $t, day == $d, period > $p1, period < $p3)
// It's not lunch
eval(!Utils.isLunch($l1, $l3)) // Even better is to move this into the $l3 Lecture part
then
// It's a spring hour
scoreHolder.addSoftConstraintMatch(kcontext,
// Punish more spring hours more
- ($p3.index - $1.index));
end