jbossoptaplannerdrools-planner

Optaplanner: How to leave planning variables as null if it breaks hard constraint


The behaviour i'm seeing in the results is that two courses that can only be in one time period (like Monday 9am) is both being set in the same period anyway despite having a hard constraint. What I would like to happen is that one of them be set to null so i can retrieve them later on and inform the user.

Is there a configuration for this? If not, how should I handle cases like this? I'm expecting that hard constraints be broken in my applications but what's important to me is i can notify the user which courses cannot be scheduled, so he can schedule it himself (via UI).

Here's is the relevant hard constraint rule:

rule "roomOccupancy"
    when 
        Lecture(period != null, $leftPeriod:period, room != null, $leftRoom: room)
        Lecture(eval($leftPeriod.overlaps(period) == true), $leftRoom == room)
    then
        scoreHolder.addHardConstraintMatch(kcontext, -1);
end

Solution

  • If I understand correctly, you want one of the courses to be left unassigned in the schedule, if a certain constraint is broken. By default, each planning entity will be planned. The solution with the highest score will get be still a solution.

    I suggest that you have a look at over-constrained planning: where you assign as many entities as possible without breaking hard constraints. With over-constraint planning, entities can be left unassigned.