Optaplanner:求解器中不完整的对正列表

时间:2019-03-25 18:53:21

标签: optaplanner

我正在使用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

您可以看到这里没有打印多个约束。中等约束条件根本不会记录。再加上缺少许多软约束。

这可能是什么原因?

2 个答案:

答案 0 :(得分:1)

呼叫guiScoreDirector.calculateScore()之后再呼叫guiScoreDirector.setWorkingSolution(planningSolutionInstance)

答案 1 :(得分:0)

这可能是分数损坏。打开environmentMode FULL_ASSERT进行验证(让它运行很长时间)。如果将其打开,则可以阻止该错误的发生,请改用NON_INTRUSIVE_FULL_ASSERT。