我正在使用optaplanner解决名册分配问题。当解算器结束时,我会看到日志
INFO [2019-03-25 22:42:41,486] org.optaplanner.core.impl.solver.DefaultSolver: Solving ended: time spent (4083), best score (-500hard/-6133758medium/-1477130soft)
之后我使用打印得分理由列表
ScoreDirectorFactory<MyPlanningSolution> scoreDirectorFactory = solver.getScoreDirectorFactory();
ScoreDirector<MyPlanningSolution> guiScoreDirector = scoreDirectorFactory.buildScoreDirector();
guiScoreDirector.setWorkingSolution(planningSolutionInstance);
for (ConstraintMatchTotal constraintMatchTotal : guiScoreDirector.getConstraintMatchTotals()) {
String constraintName = constraintMatchTotal.getConstraintName();
// The score impact of that constraint
Score scoreTotal = constraintMatchTotal.getScoreTotal();
this.logger.info("constraintName " + constraintName + " scoreTotal " + scoreTotal + " Justification List :");
for (ConstraintMatch constraintMatch : constraintMatchTotal.getConstraintMatchSet()) {
List<Object> justificationList = constraintMatch.getJustificationList();
this.logger.info(justificationList.toString() + " Score : " + constraintMatch.getScore());
}
}
这只打印一些约束:
constraintName Sample constraint1 scoreTotal -100hard/0medium/0soft Justification List :
[...] Score : -100hard/0medium/0soft
constraintName Sample constraint3 scoreTotal -400hard/0medium/0soft Justification List :
[...] Score : -100hard/0medium/0soft
[...] Score : -100hard/0medium/0soft
[...] Score : -100hard/0medium/0soft
[...] Score : -100hard/0medium/0soft
constraintName Sample constraint3 scoreTotal 0hard/-6133758medium/-1345422soft Justification List :
[...] Score : 0hard/0medium/-3125soft
[...] Score : 0hard/0medium/-625soft
[...] Score : 0hard/0medium/-25soft
[...] Score : 0hard/0medium/-16384soft
[...] Score : 0hard/0medium/-3125soft
[...] Score : 0hard/0medium/-3125soft
[...] Score : 0hard/0medium/-625soft
[...] Score : 0hard/0medium/-625soft
[...] Score : 0hard/0medium/-625soft
[...] Score : 0hard/0medium/-125soft
[...] Score : 0hard/0medium/-125soft
[...] Score : 0hard/0medium/-64soft
[...] Score : 0hard/0medium/-9soft
如果你把这里打印的分数加起来,你会得到-500hard/0medium/-28607soft
如您所见,这里没有打印多个约束。根本不记录介质约束。此外,还缺少许多软约束。
这可能是什么原因?
打电话给guiScoreDirector.calculateScore()
后打电话给guiScoreDirector.setWorkingSolution(planningSolutionInstance)
。
这可能是得分腐败。打开environmentMode FULL_ASSERT来证明它(让它运行很长时间)。如果打开它,停止发生错误,请尝试NON_INTRUSIVE_FULL_ASSERT。