Peter,

The EXACT way to accomplish the functionality that you are looking for is 
"activation-group"; if two rules are in the same activation group, only one of 
them will fire. Note that the rule with HIGHER salience will fire first; to 
accomplish what you are looking for you'd have to give the exception rule a 
higher salience.

I would also note that although there are specific instances where 
activation-group has a strong need, many in the community find that the most 
power and flexibility from the rule engine comes from "letting go" of trying to 
exactly order your rule execution, and instead letting the rule engine decide 
what would happen here. One way to accomplish this in your case would be to 
simply add (isZombie == false) to your constraint on the general rule.  Another 
way that involves salience but NOT agenda groups is to set a high salience on 
your exception rule, but only add advice if advice is null. The possibilities 
are endless.

With kind regards,
David Faulkner
david.faulk...@amentra.com

From: rules-users-boun...@lists.jboss.org 
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Peter Ashford
Sent: Wednesday, March 09, 2011 7:24 AM
To: Rules Users List
Subject: Re: [rules-users] Misunderstanding salience?

Actually, I think I've figured this one out : in the Zombie case, it's firing 
both rules and it's just that with the negative salience,  the zombie exception 
rule is the last rule fired, therefore, the last thing written into advice.

So... what would be the correct way to do what I'm trying to do here?  The idea 
is that the Zombie exception rule should fire in preference to the general rule 
and that none of the general processing should occur at all (imaging that these 
rules had side-effects for the rest of the system they're attached to, we don't 
want all the general rule side effects to apply and then all the exception case 
side effects)

Thanks in advance!

Peter.

From: rules-users-boun...@lists.jboss.org 
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Peter Ashford
Sent: Wednesday, 9 March 2011 1:31 p.m.
To: rules-users@lists.jboss.org
Subject: [rules-users] Misunderstanding salience?

Hi There

I'm new to drools.  I've just set up the Drools-Server and it is (finally!) 
working and serving my test rule-set.  The one thing that's not working as I 
expect it is the rule ordering via salience.  This is my simple test rule set:

rule "General brain eating advice"
       when
              p : Patient(eatsBrains == true)
       then
              p.setAdvice("Stop eating brains, or at least, try to cut down");
end

rule "Zombie exception to brain eating advice"
       salience -50
       when
              p : Patient(eatsBrains == true, isZombie == true)
       then
              p.setAdvice("Evidence suggests that the undead cannot contract 
Kuru or that the effects are irellevant given the " +
                              "patient's current zombified state.\nSuggest 
euthenasing patient lest he/she eat your (or someone " +
                              "else's) brains");
end


The idea is that the first rule fires all the time unless the patient happens 
to be a zombie, in which case the exception rule (the second rule) kicks in.  
Now, as I have it here, with the exception at salience at -50 it actually 
works, which is the opposite of what I was expecting.  I'd thought that I would 
have had to have the exception at a higher salience to fire first.  That was 
what I tried first but that didn't work - everyone got the general advice, 
zombies included.

What am I misunderstanding here?

Thanks!

Peter.

---
"It is very difficult to get a man to understand something when his tribal 
identity depends on his not understanding it" - Michael Bérubé on Republican 
climate change denial.

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to