Deactivating optaplanner rule

隐身守侯 提交于 2019-12-25 09:33:49

问题


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.

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?

Below is an example of a rule myrule.drl:

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

and here the solver config:

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

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

ANSWER

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


回答1:


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.



来源:https://stackoverflow.com/questions/43492946/deactivating-optaplanner-rule

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!