0

我正在使用显着性来确定每个规则的优先级,但是当我触发AllRules 时,它并不总是选择显着性更高的规则。如何使规则引擎始终选择具有更高显着性的规则?

输出

[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

触发规则的动作监听器

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
4

1 回答 1

0

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

我不打算对此进行进一步调查,因为用户界面 ( TeleInterface) 没有描述实际插入的内容。

于 2017-05-03T12:26:55.093 回答