I'm currently reading the course curriculum example of optaplanner and I can't seem to understand this:
rule "conflictingLecturesSameCourseInSamePeriod"
when
// line 1
Lecture($leftId : id, $leftCourse : course, $period : period, period != null)
// line 2
Lecture(course == $leftCourse, period == $period, id > $leftId)
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
Questions are:
- What's the difference between the Lecture() in line 1 and the Lecture in line 2?
- I understand the variable assignements are happening in Line 1 but in Line 2, what's the difference between course
and $leftCourse
, period
and $period
and id
and $leftId
So far, I can't seem to find any explanation in the documentation
A binding such as $leftCourse : course
establishes $leftCourse
as a variable that refers to the field course
of a Lecture
object.
The lecture in line 1 is identified by its id
; the one in line 2 has an id that is greater. Assuming that id
values are primary keys, this combination would basically match all possible unordered pairs of Lectures, but ...
... the constraint course == $leftCourse
restricts the pairings to those of identical courses and ...
... the constraint period == $period
furthermore restricts it to equal (non-null) periods.
In other words, the planning rules out an assignment for two different Lectures for the same course in the same period.