开发者

Drools - Multiple rules fire even though they all belong to the same activation group

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, 开发者_Go百科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.


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜