0 Replies Latest reply on May 1, 2017 11:03 AM by Ljoão Magalhães

    How can I make the rule engine always choose the rule with higher Salience?

    Ljoão Magalhães Newbie

      I´m using Salience to make the priority of each rule, but when I fireAllRules, it doesn't always choose the rule with higher Salience. How can I make the rule engine always choose the rule with higher Salience?

      Output

      [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
      [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
      [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 [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
      [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
      [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
      [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
      [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 that fire the rules

      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); 
      } 
      }
      );

      Drools Main

      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 Struct

      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