Drools - 多个规则触发,即使它们都属于同一个激活组

发布于 2024-12-05 15:47:13 字数 1932 浏览 0 评论 0原文

我有一组规则如下:

rule "Default Margin By Grade"
ruleflow-group "MarginByGrade"
enabled false
when
    $mg : MarginByGrade()
    $u  : PriceUnit( resale==null, trimGrade memberOf $mg.grades  )
then    
end

rule "Grade Margin By Group, Style" extends "Default Margin By Grade"
activation-group "Margin By Grade"
salience 500
when
    MarginByGrade(this == $mg, $u.model memberOf $mg.models,  $u.style memberOf $mg.styles)
then
    System.out.println("Found match : " + $mg);
end

rule "Grade Margin By Style" extends "Default Margin By Grade"
activation-group "Margin By Grade"
salience 100
when
    MarginByGrade(this == $mg, models == null, $u.style memberOf $mg.styles)
then
    System.out.println("Found match : " + $mg);
end

rule "Grade Margin By Group" extends "Default Margin By Grade"
activation-group "Margin By Grade"
salience 50
when
    MarginByGrade(this == $mg, prefixes memberOf prefixes, styles == null)
then
    System.out.println("Found match : " + $mg);
end

rule "Margin by Grade" extends "Default Margin By Grade"
salience 5
activation-group "Margin By Grade"
when
    MarginByGrade(this == $mg, prefixes == null, styles == null)
then
    System.out.println("Found match : " + $mg);
end

规则是基于规则流触发的(因此是“ruleflow-group”属性)。我的要求是,一旦具有最高显着性的规则触发,具有较低显着性的规则不应触发然而,当我运行提供激活多个规则的事实时,所有激活的规则都会被解雇:

Start Process: Mon Sep 19 15:58:39 EDT 2011
Found match : MarginByGrade( prefixes=null, styles=null, grades=[C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S], margin=26.0000 )
Found match : MarginByGrade( prefixes=[015, 215], styles=[572], grades=[A, B, D], margin=25.5000 )
Found match : MarginByGrade( prefixes=[015, 010], styles=[515, 215, 572], grades=[C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S], margin=24.5000 )
015572  D 015572  D933079 FN 175->null
Dispose Session: Mon Sep 19 15:58:39 EDT 2011

我使用 Drools Expert 5.2.0-Final 做错了什么?

I have a set of rules as follows:

rule "Default Margin By Grade"
ruleflow-group "MarginByGrade"
enabled false
when
    $mg : MarginByGrade()
    $u  : PriceUnit( resale==null, trimGrade memberOf $mg.grades  )
then    
end

rule "Grade Margin By Group, Style" extends "Default Margin By Grade"
activation-group "Margin By Grade"
salience 500
when
    MarginByGrade(this == $mg, $u.model memberOf $mg.models,  $u.style memberOf $mg.styles)
then
    System.out.println("Found match : " + $mg);
end

rule "Grade Margin By Style" extends "Default Margin By Grade"
activation-group "Margin By Grade"
salience 100
when
    MarginByGrade(this == $mg, models == null, $u.style memberOf $mg.styles)
then
    System.out.println("Found match : " + $mg);
end

rule "Grade Margin By Group" extends "Default Margin By Grade"
activation-group "Margin By Grade"
salience 50
when
    MarginByGrade(this == $mg, prefixes memberOf prefixes, styles == null)
then
    System.out.println("Found match : " + $mg);
end

rule "Margin by Grade" extends "Default Margin By Grade"
salience 5
activation-group "Margin By Grade"
when
    MarginByGrade(this == $mg, prefixes == null, styles == null)
then
    System.out.println("Found match : " + $mg);
end

The rules are triggered based on a Rule Flow (hence the 'ruleflow-group' attribute. My requirement is that once the rule with the highest salience fires, the rules with the lower salience should not fire. Yet when I run provide a fact that activates multiple rules, all activated rules get fired:

Start Process: Mon Sep 19 15:58:39 EDT 2011
Found match : MarginByGrade( prefixes=null, styles=null, grades=[C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S], margin=26.0000 )
Found match : MarginByGrade( prefixes=[015, 215], styles=[572], grades=[A, B, D], margin=25.5000 )
Found match : MarginByGrade( prefixes=[015, 010], styles=[515, 215, 572], grades=[C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S], margin=24.5000 )
015572  D 015572  D933079 FN 175->null
Dispose Session: Mon Sep 19 15:58:39 EDT 2011

What am I doing wrong? I'm using Drools Expert 5.2.0-Final.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉墨 2024-12-12 15:47:13

那么您使用的是激活组而不是规则流组,对吧?激活组将导致仅执行一条规则,正如您提到的,如果激活的话,将执行具有更高显着性的规则。
干杯

Well you are using activation-group and not ruleflow-group right?.. The activation-group will cause that only one rule get executed and as you mention the one with higher salience will be executed if it is activated.
Cheers

单身情人 2024-12-12 15:47:13

无状态会话:

如果您正在使用事实集合和无状态会话,请注意激活组,因为只有一个规则会触发,它会跳过其他事实。
最好的解决方案是在事实上使用显着性和已处理的标志

Stateless Session:

Be-aware of activation-group in case you are working with collection of Facts and stateless session, since only one rule will fire, it would skip other facts.
Best solution is to use Salience and a processed flag on facts

予囚 2024-12-12 15:47:13

激活组将为单个 MarginByGrade 触发一次

从控制台输出来看,您至少有 3 个 MarginByGrade,因此为这 3 个 中的每一个触发不同的规则是正确的>按等级保证金

The activation group will fire once for a single MarginByGrade

From your console output, you have at least 3 MarginByGrade, so it's correct to fire different rules for each of these 3 MarginByGrade

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文