we add negative soft constraint in OptaPlanner's XML file for curriculumcourse problem, like
<unavailablePeriodPenaltyList id="737">
<UnavailablePeriodPenalty id="738">
<id>0</id>
<course reference="66" />
<period reference="678" />
</UnavailablePeriodPenalty>
</unavailablePeriodPenaltyList>
But How to add positive soft constraint in xml file for curriculumcourse problem?
Which XML tag is used for that?
positive soft constraint example : Teacher B likes to teach on Monday morning
Out-of-the-box, the curriculumcourse example only supports a number of constraints (see docs for full list). The one new one you mention is not part of that. But it's easy to add (presuming you're a Java programmer):
The entry in the XML is only the data of specific instance.
That data is loaded and represented in the example as a domain object called UnavailablePeriodPenalty.java .
The curriculumCourseScoreRules.drl adds a constraint based on that domain object.
Here's how that score rule looks like:
// Availabilities: Each lecture in a period unavailable for that course.
rule "unavailablePeriodPenalty"
when
$unavailablePeriodPenalty : UnavailablePeriodPenalty($course : course, $period : period)
$lecture : Lecture(course == $course, period == $period)
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
Similarly, you could define:
a FavoritePeriodReward.java domain object (also add a List for it in CurriculumCourseSchedule
)
XML elements <FavoritePeriodReward>
and a score rule that rewards it.
For example:
rule "FavoritePeriodReward"
when
$reward : FavoritePeriodReward($teacher : teacher, $period : period)
$lecture : Lecture(teacher == $teacher, period == $period)
then
scoreHolder.addHardConstraintMatch(kcontext, 1); // +1 instead of -1
end
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.