OptaPlanner 解决方案的分数与 `ScoreManager::explainScore` 给出的分数不匹配

OptaPlanner Solution's score not matches the score given by `ScoreManager::explainScore`

老实说,我有一个复杂的模型,我的 OptaPlanner 模型有可能出现错误。

我不确定以下是否可行且正常,或者我的映射中某处存在错误,我应该根据我的实体创建一个 MCVE。

TLDR:

我的项目中某处有以下 Kotlin 代码:

        val solverJob = solverManager.solveAndListen(problem.id, problemMap::get) {
            val hardScore = it.score!!.hardScore
            if (scoreManager.explainScore(it).score.hardScore != hardScore) {
                throw IllegalStateException()
            }
            onBetterSolutionFoundCallback(mapSolutionToFrontendObject(it))
        }

很简单,给OptaPlanner一个问题,找到更好的解决方案就回调。这里的技巧是它会仔细检查解决方案是否可行。

Aaaaand,有时会抛出 IllegalStateExceptionscoreManager.explainScore(it).score 报告说有一个硬约束违规,而 solution.score 说没有硬约束违规。

棘手的部分是 solution.score 在调用 scoreManager.explainScore 方法后更新。

我查看了解决方案,ScoreManager 是正确的:解决方案中存在一个硬约束冲突。但是一切都报告说,在我调用 scoreManager.explainScore 方法之前,这是一个可行的解决方案。

OptaPlanner 在我的例子中抛出这个异常之前找到了 2 个正确的解决方案,所以有可行的解决方案,但 OptaPlanner 将它们替换为不可行的。

这是正确的行为吗?

还是我的领域模型有问题?

或者这是 OptaPlanner 中的一个错误,我应该根据这个创建一个错误报告吗?

我正在使用 Quarkus 1.11.1.Final 和 OptaPlanner 8.1.0.Final.

谢谢,

暂时将此添加到您的 application.properties 中以更快地失败,并提供指向原因的更清晰的错误消息:

# To detect common bugs in your code
quarkus.optaplanner.solver.environment-mode=FULL_ASSERT

给它更多时间,因为 FULL_ASSERT 会严重减慢速度。请参阅 optaplanner 文档部分“环境模式”以了解它的作用。