Drools-规则层次结构和条件执行 [英] Drools - rule hierarchy and conditional execution

查看:755
本文介绍了Drools-规则层次结构和条件执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否存在一种方法来定义规则之间的层次结构(而不​​仅仅是执行顺序)并控制规则的执行-即,如果父规则被触发,则不应评估下面的规则等.

I was wondering if there is a way to define hierarchy (not just order of execution) between rules and control the rule execution - i.e. if the parent rule fired then the ones below should not be evaluated etc...

此线程中的信息是一个选项,但实际上是IF/THEN/ELSE

有其他选择吗?

谢谢

推荐答案

我不确定我是否理解您的问题,但是结合使用激活组和传统的冲突解决策略可能会满足您的需求.例如,假设您有3条规则,A,B和C.您想使用显着性按顺序将执行优先级赋予它们,一旦执行,该组中的其他规则均不应执行.您可以这样定义它们:

I am not sure if I understand your question, but using a combination of Activation Groups and the traditional conflict resolution strategies might achieve what you need. For instance, lets say you have 3 rules, A, B and C. You want to use, lets say, salience to give priority of execution to them in that order, and once one is executed, no other rule in that group should execute. You can define them like this:

rule A
    salience 30
    activation-group "x"
...

rule B
    salience 20
    activation-group "x"
...

rule C
    salience 10
    activation-group "x"
...

显着性保证如果A被激活,它将首先触发,然后被B触发,如果被激活则被C触发.激活组保证一旦其中一个规则触发,该组中所有其他激活的规则将被取消.因此,可以说,在您的会话中,规则B和C激活,但没有激活A,则B将触发,C将被取消.

The salience guarantees that if A activates, it will fire first, followed by B, followed by C if they were activated. The Activation Group guarantees that once one of the rules fire, all other activated rules in that group will be cancelled. So, lets say that in your session, rules B and C activate, but not A, then B will fire and C will be cancelled.

请注意,激活组不会阻止以后重新激活规则.当群组中的规则之一触发时,它只会取消当前在议程中的所有激活.

Please note that activation groups do not prevent rules from later being re-activated. It just cancels any activations currently in the agenda at the time one of the rules in the group fire.

这篇关于Drools-规则层次结构和条件执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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