[英]How to use min-conflict algorithm with optaplanner
Is there a min-conflict algorithm in optaplanner? optaplanner中是否存在最小冲突算法? or how to do it?
或怎么做?
What about using it as part of the neighborhood selection like: 如何将其用作邻域选择的一部分,例如:
If that's viable, is there a way to get the constraintMatches without the need to re-call the calculateScore in order to speed up the process 如果可行,是否有一种方法可以获取constraintMatches,而无需重新调用calculateScore以加快流程
This algorithm isn't supported out of the box yet by OptaPlanner. OptaPlanner尚不支持此算法。 I 'd call it Guided Local Search .
我将其称为“ 本地指导搜索” 。 But it's not that hard to add yourself.
但是添加自己并不难。 In fact, it's not a matter of changing the algorithm, but changing the entity selectors.
实际上,更改算法不是问题,而是更改实体选择器。
Something like this should work: 这样的事情应该起作用:
<swapMoveSelector>
<entitySelector>
<cacheType>STEP</cacheType>
<probabilityWeightFactoryClass>...MyProbabilityWeightFactory</probabilityWeightFactoryClass>
</entitySelector>
</swapMoveSelector>
Read about the advanced swapMoveSelector configuration , entity selector , sorted selection and probability selection . 阅读有关高级swapMoveSelector配置 , 实体选择器 , 排序选择和概率选择的信息 。
The callback class you implement for the probabilistic selection or sorted selection should prioritize entities that are part of a conflict. 为概率选择或排序选择实现的回调类应优先考虑作为冲突一部分的实体。
I would definitely use sorted or probabilistic selection on the entity selector, not the entire swapMoveSelector because that is overkill, cpu hungry and memory hungry. 我肯定会在实体选择器上使用排序或概率选择,而不是整个swapMoveSelector,因为那太过分了,CPU饿了,内存也饿了。
I would prefer probabilistic selection over sorted selection. 与排序选择相比,我更喜欢概率选择。 Even though sorted selection better reflects your pseudo code, I believe (but haven't proven) that probabilistic selection will do better, given the nature of Metaheuristics.
即使排序选择更好地反映了您的伪代码,但我相信(但尚未证明),考虑到元启发式算法的性质,概率选择会更好。 Try both, run some benchmarks with the Benchmarker and let us know what works best ;)
尝试两者,使用Benchmarker进行一些基准测试,然后让我们知道最有效的方法;)
Not sure about how to solve your overall problem but for your last point: 不知道如何解决您的整体问题,但是对于最后一点:
You can create a PhaseLifecycleListener
and attach it via ((DefaultSolver) solver).addPhaseLifecycleListener
您可以创建一个
PhaseLifecycleListener
并通过((DefaultSolver) solver).addPhaseLifecycleListener
附加它。
In the stepStarted or stepEnded(depending on your need) you can then call 然后在stepStarted或stepEnded(取决于您的需要)中,可以调用
stepScope.getScoreDirector().getConstraintMatchTotals()
to get the constraint totals. 得到约束总数。
Hope this somewhat helps. 希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.