So we solved the planning problem and found a best solution which has a score of 0hard/-123soft. Why -123soft? Where does that penalty come from? Which constraints are broken? Let’s see how we can break down the score and visualize the pain points in a UI.
Let’s approach this problem from two sides on the course scheduling example:
In the bottom-up approach, we visualize the score impact per lecture:
Red lectures impact hard constraints.
Orange lectures impact only soft constraints. The higher the impact, the heavier the color.
White lectures don’t impact the score.
Solution
Normal view
Indictment heat map
Score
Initialized
-4hard/-18soft
Feasible
0hard/-68soft
Near optimal
0hard/-1soft (*)
Optimal
0hard/0soft
As OptaPlanner, now continued as Timefold Solver, finds better and better solutions, there is less and less orange on the heat map. Looks like the history courses are particularly hard to schedule. Maybe the school should look for an additional history teacher?
(*) Notice that -1soft is shared by multiple lectures: 3 lectures break the room stability constraint together because two of them use a different room than the other one.
OptaPlanner 7 provides this information out of the box through the ConstraintMatch API:
First build a ScoreDirector with Solver.getScoreDirectorFactory() and then:
Break down the score per constraint type with ScoreDirector.getConstraintMatchTotals(). Each ConstraintMatchTotal represents one score rule and has its total score.
Determine the score impact per planning entity with ScoreDirector.getIndictmentMap(). Each Indictment holds the total score impact of one planning entity. Use that score to create the heat map in your UI.