停用Optaplanner规则 [英] Deactivating optaplanner rule

查看:163
本文介绍了停用Optaplanner规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个优化问题,我想用optaplanner解决.解决方案算法使用一组规则.引擎使用一个对象来捕获每个规则的权重.规则的最终分数是规则的中间分数乘以权重.分数设置在每个规则的右侧.每个规则的左侧评估其权重是否不为零,然后才执行右侧.将规则的权重设置为零是一种停用规则的机制.我已经进行了一些检查,并且可以正常工作.

I have an optimisation problem which I am trying to solve with optaplanner. The solution algorithm uses a set of rules. The engine uses an object that captures the weight of each rule. The final score of a rule is an intermediate score of the rule multiplied with the weight. The score is set in the right hand side of every rule. The left hand side of every rule evaluates if its weight is not zero and only then executes the right hand side. Setting the weight of a rule to zero is a mechanism to deactivate the rule. I have run some checks and it works.

该机制的替代方法是通过从optaplanner求解器配置文件中完全删除规则来永久性地停用"该规则.

An alternative to this mechanism is to "deactivate" a rule permanently by completely removing it from the optaplanner solver config file.

我希望将权重设为零并删除规则将导致相同的结果,但事实并非如此.从配置文件中删除规则比将权重设置为零会产生更好的解决方案.

I would expect that putting weight to zero and removing the rule would lead to identical results but it is not true. Removing the rule from config file yields a better solution than putting weight to zero.

为什么会这样? 如何在运行时停用规则?

Why is it so? How can I deactivate a rule at run time?

下面是myrule.drl规则的示例:

Below is an example of a rule myrule.drl:

rule "myrule"
    when
        MyWeights($weight: myRuleWeight != 0)
    then
        scoreHolder.addHardConstraintMatch(context, $weight)
end

,这里是求解器配置:

<solver>
    <scoreDirectorFactory>
        <scoreDrl>myrule.drl</scoreDrl>
    </scoreDirectorFactory>
</solver>

从求解器配置中注释myrule.drl可以提供比将权重设置为零更好的解决方案.

commenting out myrule.drl from solver config gives a better solution than setting weight to zero.

答案

配置xml中的secondsSpentLimit不够大,以至于权重设置为0的优化在给定的时间段内仅执行了111个本地搜索(LS)步骤,而没有规则的优化则执行了301个LS步骤.增加secondsSpentLimit解决了问题

The secondsSpentLimit in the config xml was not big enough such that the optimisation with weight set to 0 had done only 111 Local Search (LS) steps within the given time period and the optimisation without the rule had done 301 LS steps. Increasing the secondsSpentLimit solved the problem

推荐答案

这不可能(如果它们都运行相同数量的步骤). 打开DEBUG记录org.optaplanner ,以查看它们都运行了多少步以及它们的得分速度.

That's impossible if they both ran the same number of steps. Turn on DEBUG logging for org.optaplanner to see how many steps they both ran, as well as well as their score speed.

在任何步骤中,两次运行都必须具有完全相同的步骤分数和完全相同的最佳分数.如果不是,则说明您有错误,请在文档中查找可复制以查找可能的原因.

At any step, both runs must have the exact same step score and exact same best score. If not, you got a bug, look for reproducible in the docs for potential causes.

这篇关于停用Optaplanner规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆