简体   繁体   中英

How to set positive soft constraint (reward) in Optaplanner's curriculumcourse XML file

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):

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM