当前位置: 首页 > 知识库问答 >
问题:

如何使规则引擎始终选择显著性较高的规则?

权弘新
2023-03-14

我使用显著性来确定每个规则的优先级,但当我使用所有规则时,它并不总是选择显著性更高的规则。如何使规则引擎始终选择显著性较高的规则?

输出

[10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0   Salience:   10
Positon1   Salience:   10
Positon2   Salience:   10
Rule Number:0
pleasant:false    activation:false   context:working   multitasking:true    state:stuck
[9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0   Salience:   9
Positon1   Salience:   10
Positon2   Salience:   10
Rule Number:1
pleasant:false    activation:false   context:working   multitasking:true    state:stuck
[9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0   Salience:   9
Positon1   Salience:   9
Positon2   Salience:   10
Rule Number:1
pleasant:false    activation:false   context:working   multitasking:true    state:stuck
[9, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0   Salience:   9
Positon1   Salience:   8
Positon2   Salience:   10
Rule Number:2
pleasant:false    activation:false   context:working   multitasking:true    state:stuck
[9, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0   Salience:   9
Positon1   Salience:   8
Positon2   Salience:   9
Rule Number:2
pleasant:false    activation:false   context:working   multitasking:true    state:stuck
[9, 8, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0   Salience:   9
Positon1   Salience:   8
Positon2   Salience:   8
Rule Number:2
pleasant:false    activation:false   context:working   multitasking:true    state:stuck
[9, 8, 7, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0   Salience:   9
Positon1   Salience:   8
Positon2   Salience:   7
Rule Number:2
pleasant:false    activation:false   context:working   multitasking:true    state:stuck
[9, 8, 6, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
Positon0   Salience:   9
Positon1   Salience:   8
Positon2   Salience:   6
Rule Number:0

触发规则的Actionlistener

simula.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                FactHandle fact1;
                fact1= new SimulaRegras(pleas, act, context.getText(), mtask, state.getText(),sal);

                ksession.insert(fact1);
                ksession.fireAllRules(1);

            }

        }
                );

口水主

public class DroolsTest {

        public static void main(String[] args) {
            KieContainer kc = KieServices.Factory.get().getKieClasspathContainer();
            new DroolsTest().init(kc);
        }

        public DroolsTest() {
        }

        public void init(final KieContainer kc) {
            KieSession ksession = kc.newKieSession("ksession-rule");

            TeleInterface t = new TeleInterface(ksession);
            FactHandle fact2;
            fact2 = ksession.insert(t);
        }
    }

规则结构

    rule "Num1"
            salience(sr.gSal(0))

        when 

            t: TeleInterface ()
            sr: SimulaRegras(pleasant == false && activation == false && context == "working", multitask == true, state == "stuck")

        then
            t.gMap.setEnabled(true);
            t.gMap.setForeground(Color.GREEN);
            t.background.setIcon(new ImageIcon("ponto.png"));
            t.action("gMap", false);
            t.infoBox("optimization", "add", "Adicionar ponto no grid map e fornecer o caminho");
            t.sSal(0);
end

共有1个答案

仇炜
2023-03-14

我不太确定你想要实现什么,但使用显著性并不是一条路。基于事实属性中的值的显著性可以用逻辑来代替,即通过检查没有其他此类事实具有更高的该属性值。此外,修改提供显著性的属性不是一个好主意,因为Drools不会重新评估显著性。

我不打算进一步研究这个问题,因为用户界面(TeleInterface)没有描述实际插入的内容。

 类似资料:
  • 我正在为我的项目评估一个规则引擎。该项目将基于hadoop。我用DROOLS做了一些POC。基本上,我使用DROOL在映射器一侧。基于此,以下是我的观察和质疑。 1) a)我使用DROOLS在300万对象上启动了规则(大约需要17秒)b)我使用简单的Java对象(大约需要17秒)为没有DROOLS的300万对象使用了与DRL文件中相同的if/else循环逻辑。b大约比a快100倍。这是正常行为吗?

  • 我有一个简单的JAVA bean,有两个int字段:'a'和'b'。 更新 非常感谢你的回答。 也许我应该详细描述一下我的问题。我有一套1500条规则。每条规则: null Java代码: 解决方案2的DRL文件:我向每个规则添加了相同的激活组:

  • 我正在向drools规则引擎插入数据,但我无法理解它是如何处理插入的数据的。插入数据的代码是:

  • 我正在从事这个项目,我的角色是开发使用标准健康保险xml的服务。服务必须在不同的xml字段上进行验证,这涉及将xml数据与数据库表中的数据进行比较。目前,我们假设所有保险公司的验证保持不变。但我怀疑它会保持不变,并且每家公司可能有不同的验证要求。在这种情况下,使用Drools规则引擎并为每家公司开发drl文件并使用规则引擎进行xml验证是个好主意吗

  • 选择器使用规则 1. 可以使用 * 通用选择器。 * 通用选择器效率低是一个误区,如有必要可以使用。测试文章关于css通配符性能问题不完全测试 例如: * { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } 2. 不要在选择器末尾使用 * 通用选择器。 CSS

  • 我们已经使用Drools引擎几年了,但是我们的数据已经增长了,我们需要找到一个新的分布式解决方案来处理大量数据。我们有复杂的规则,可以查看几天的数据,这就是为什么Drools非常适合我们,因为我们的内存中只有数据。 你对类似于流口水但分布式/可扩展的东西有什么建议吗? 我确实对这件事进行了研究,但我找不到任何符合我们要求的东西。 谢谢