首页 文章

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

提问于
浏览
4

我有一套规则如下:

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 .

3 回答

  • 0

    那么你正在使用激活组而不是规则流组?激活组将导致只执行一条规则,并且如果激活,则会提到具有较高显着性的规则 . 干杯

  • 3

    无国籍 Session :

    如果您正在处理事实集合和无状态会话,请注意激活组,因为只有一个规则会触发,它会跳过其他事实 . 最佳解决方案是在事实上使用Salience和处理过的旗帜

  • 0

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

    从您的控制台输出中,您至少有3个 MarginByGrade ,因此为这些中的每一个触发不同的规则是正确的 MarginByGrade

相关问题