0

I'm relatively new to Drools. I have those rules :

import models.Demarche;
declare IsMarque
 demarche : Demarche
end 

rule "Add type Marque taxe"
salience 2
no-loop true
lock-on-active true
when
    $d : Demarche( typeDemarche == "Marque" )
then
    modify($d){
        listTaxes.put(14, 1)
    }
    insert( new IsMarque( $d ) );
    System.out.println("infer marque");
end

And :

rule "Add Marque Polynesie extention taxe"
no-loop true
lock-on-active true
when
    $d : Demarche( extPolynesie == true)
    IsMarque(demarche == $d)
then
    $d.listTaxes.put(17, 1);
    System.out.println("marque");
end



rule "Add Not Marque Polynesie extention taxe"
no-loop true
lock-on-active true
when
    $d : Demarche( extPolynesie == true)
    not(IsMarque(demarche == $d))
then

    System.out.println("not marque");
end

For the rules 2 or 3, nothing happens. One of them should be true, but nothing is printed, as if the infered IsMarque cannot be evaluated. If I comment the IsMaqrue evaluation this is working, i can see the messages printed in the console. Any idea?

Lempkin
  • 1,458
  • 2
  • 26
  • 49
  • Whatever makes you use lock-on-active? Remove this. -- Apart from that, you can't be sure that the first rule fires on a Demarche where extPolynesie is true, which would be required for rules #2 and #3. If you still have problems with lock-on-active removed: please add your code inserting facts. – laune Dec 22 '14 at 18:59
  • If i remove lock-on-active my rules are in an infinite loop. And yes i'm sure that my demarche is extPolynesie = true, in my DB i have only one demarche (in which extPolynesie is true) – Lempkin Dec 23 '14 at 08:38
  • Loop: if so, you haven't shown all of what you do on the right hand side. -1 – laune Dec 23 '14 at 09:45
  • extPolynesie: Maybe there will be another Demarche in WM some day? You better make your constraints proof. – laune Dec 23 '14 at 09:47
  • I've edited my post to show the missing parts, i make changes on the evaluated demarche that's why i'm in an infinite loop. And yes obviously one day i will have a extPolynesie = false, but for now i just try to make it works – Lempkin Dec 23 '14 at 10:12

1 Answers1

0

This rule needs to be rewritten as

rule "Add type Marque taxe"
when
    $d : Demarche( typeDemarche == "Marque", $t:  listTaxes)  // I AM GUESSING HERE
    not IsMarque(demarche == $d)
then
    modify($t){
        put(14, 1)
    }
    insert( new IsMarque( $d ) );
    System.out.println("infer marque");
end

And no no-loop true and lock-on-active true if you have shown everything there is.

Note that you could write the first rule also as

rule "Add type Marque taxe"
when
    $d : Demarche( typeDemarche == "Marque")
then
    $d.getListTaxes().put(14, 1);
    insert( new IsMarque( $d ) );
    System.out.println("infer marque");
end

if (and only if) no other rule as CEs referring to the listTaxes property. Since you have used this "dirty update" in rule "Add Marque Polynesie extention taxe", it seems to be OK.

Please post complete rules - #1 doesn't compile.

laune
  • 31,114
  • 3
  • 29
  • 42
  • Thx, actually i've used a global list for adding my taxes, but this was the good way, not updating the evaluated object, and drop the no loop and lock on active. Thx :) – Lempkin Dec 23 '14 at 10:37