简体   繁体   English

Optaplanner 增量分数状态和解决方案之间的早期终止增量

[英]Optaplanner early termination deltas between Incremental Score state and solution

I'm using an incremental score calculator class because of the heavy use of maps and calculations which did not scale well in drools.我正在使用增量分数计算器类,因为大量使用地图和计算,这些地图和计算在流口水中不能很好地扩展。

It seems to work well, but as I've had to debug I've noticed differences between the number of moves used in the final solution and the moves processed by my before/afterVariableChanged handlers.它似乎运行良好,但由于我不得不调试,我注意到最终解决方案中使用的移动次数与我的 before/afterVariableChanged 处理程序处理的移动次数之间存在差异。 This causes a diffenence between what is actually assigned in the solution and the state in my incremental score objects.这会导致解决方案中实际分配的内容与增量分数对象中的状态之间存在差异。 Based on some logs it looks like the incremental does not know when the solution has stopped accepting moves because of early termination (i'm using secondsSpentLimit).根据一些日志,增量似乎不知道解决方案何时因提前终止而停止接受移动(我使用的是 secondsSpentLimit)。

How can I stop my incremental score implentation from receiving before/afterVariableChanged events that would not be considered in the solution because of early termination?如何阻止我的增量分数实施接收由于提前终止而不会在解决方案中考虑的 before/afterVariableChanged 事件?

Can you turn on TRACE logging to confirm this behavior?您能否打开TRACE日志记录以确认此行为?

In essence, LocalSearch looks like this (with moveThreadCount=NONE (= default)):本质上,LocalSearch 看起来像这样( moveThreadCount=NONE (= 默认)):

for (each step && not terminated) {
    stepStarted()
    for (each move && not terminated) {
         doMove(); // Triggers variable listeners
         if (better move) updateBestSolution();
         undoMove(); // Triggers variable listeners
    }
    stepEnded()
}

So termination is atomic versus move evaluation.所以终止是原子与移动评估。 So your issue should have another cause.所以你的问题应该有另一个原因。

With moveThreadCount=4 etc this story becomes a bit more complex, but each move thread has it's own ScoreDirector, so they pretty much work in isolation.使用moveThreadCount=4等,这个故事变得有点复杂,但每个移动线程都有自己的 ScoreDirector,所以它们几乎是独立工作的。

That being said, incremental java score calculation and shadow variables together can drive people insane... This is mainly caused because the before events happen in the middle of doMove()'s, right before a variable changes.话虽这么说,增量Java分数计算和影子变量一起可以让人发疯......这主要是因为before事件发生在doMove()的中间,就在变量改变之前。 At that time, half of the model can already be in an intermediate state that is impossible to understand, due to other variables that move was already changing.当时,模型的一半可能已经处于无法理解的中间状态,因为移动的其他变量已经发生了变化。 FWIW, take a look at VariableListener.requiresUniqueEntityEvents() , it might help a bit... Or try ConstraintStreams (BAVET implementation if you favor speed over functionality). FWIW,看看VariableListener.requiresUniqueEntityEvents() ,它可能会有所帮助......或者尝试 ConstraintStreams (如果你喜欢速度而不是功能,BAVET 实现)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM