I've narrowed it down to a smaller example. The order of insertion seems to
trump the rule salience.
The following rule inserts 4 objects. Inserted as A4,A3,A2,A1 the rules
sequence is unexpected. Inserted A1,A3,A4,A2 they fire as expected.
rule "setup.two"
when
then
// generates out of salience rule execution
insert (new RuleLink("A4", new Double(65), null));
insert (new RuleLink("A3", new Double(70), null));
insert (new RuleLink("A2", new Double(65), null));
insert (new RuleLink("A1", new Double(70), null));
/* // works ok
insert (new RuleLink("A1", new Double(70), null));
insert (new RuleLink("A3", new Double(70), null));
insert (new RuleLink("A4", new Double(65), null));
insert (new RuleLink("A2", new Double(65), null));
*/
end
Here are 3 of the 6 identical LHS rules differing only by salience
(70,65,60,55,50,0):
rule "a70"
salience 70
when
link: RuleLink( linkName: name matches "A.", d :
aasDouble)
RuleLink( name == "SKINS", partsO : a)
then
System.out.println("START 070 " + d);
if ( d > 69.9) {
System.out.println(drools.getRule().getName() + " retract " +
linkName);
retract(link);
} else {
System.out.println(drools.getRule().getName() + " no retract " +
linkName);
}
end
rule "a65"
salience 65
when
link: RuleLink( linkName: name matches "A.", d :
aasDouble)
RuleLink( name == "SKINS", partsO : a)
then
System.out.println("START 065 " + d);
if ( d > 64.9) {
System.out.println(drools.getRule().getName() + " retract " +
linkName);
retract(link);
} else {
System.out.println(drools.getRule().getName() + " no retract " +
linkName);
}
end
rule "a60"
salience 60
when
link: RuleLink( linkName: name matches "A.", d :
aasDouble)
RuleLink( name == "SKINS", partsO : a)
then
System.out.println("******* ERROR ************");
System.out.println("START 060 " + d);
if ( d > 59.9) {
System.out.println(drools.getRule().getName() + " retract " +
linkName);
retract(link);
} else {
System.out.println(drools.getRule().getName() + " no retract " +
linkName);
}
end
// One more setup rule
rule "setup.one"
when
then
List skinParts = new ArrayList();
insert (new RuleLink("SKINS", skinParts, null));
end
Here is the test run:
START 070 70.0
a70 retract A1
START 070 65.0
a70 no retract A2
START 070 70.0
a70 retract A3
START 070 65.0
a70 no retract A4
START 065 65.0
a65 retract A2
******** ERROR ********
START 060 65.0
a60 retract A4
A4 never ran rule 065. It skipped to rule 060 from 070.
The error is very sensitive to other rules in the package.
Is this the expected behavior?
(I would like to keep the reasons for a branch on the RHS vs an eval on the
LHS out of this discussion.)
--
View this message in context:
http://n3.nabble.com/User-and-or-Code-problem-with-insert-retract-and-sal...
Sent from the Drools - User mailing list archive at
Nabble.com.