【问题标题】:Optaplanner : Incomplete justification list in solverOptaplanner:求解器中不完整的理由列表
【发布时间】:2019-04-01 15:32:37
【问题描述】:

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

如您所见,这里没有打印多个约束。完全不记录中等约束。此外,还缺少许多软约束。

这可能是什么原因?

【问题讨论】:

    标签: optaplanner


    【解决方案1】:

    在调用guiScoreDirector.setWorkingSolution(planningSolutionInstance)之后再调用guiScoreDirector.calculateScore()

    【讨论】:

    • 好的。我在设置工作解决方案后添加了guiScoreDirector.calculateScore()。等待运行完成,看看这是否有帮助。你能解释一下为什么需要这一步吗?为什么没有它会导致分数不匹配?
    • 使用此配置运行。约束列表现在加起来就是总分。你能详细解释一下为什么省略 calculateScore() 方法会导致不正确的理由列表吗?没有这个调用它会显示什么数据?
    【解决方案2】:

    这可能是分数损坏。打开 environmentMode FULL_ASSERT 来证明(让它运行很长时间)。如果打开它,阻止错误发生,请尝试 NON_INTRUSIVE_FULL_ASSERT。

    【讨论】:

    • 但我没有编写自己的移动选择器。即使在使用默认移动选择器时,是否有任何方式可能损坏分数?
    • 另外,如果出现分数损坏,在 FULL_ASSERT 和 NON_INTRUSIVE_FULL_ASSERT 模式下会发生什么?求解器是否会抛出错误并停止?
    • 是的,这些断言模式是在分数损坏发生后立即检测它。
    • 好的,我运行了这个。现在已经在 FULL_ASSERT 模式下运行了将近 2 天。看不到任何错误日志。只有传入的日志是通过 BestSolutionChangedEvent 侦听器。我该如何进行?
    • 好的,所以我在 97 小时后停止了以 FULL_ASSERT 模式运行的求解器。我在结果中没有看到这个问题。我也在 NON_INTRUSIVE_FULL_ASSERT 模式下运行它。它运行了50个小时。我在这种模式下也看到不完整的理由列表。但是,它没有抛出任何错误。这是为什么呢?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    • 1970-01-01
    相关资源
    最近更新 更多