Try this:
rule 'Rule One'
activation-group 'age-test'
salience 300
when
Person (location == 'A', age > 60 )
Then
do_something();
end
rule 'Rule Two'
activation-group 'age-test'
salience 200
when
Person (location == 'B', age > 70 )
Then
do_something();
end
rule 'Rule Three'
activation-group 'age-test'
salience 100
when
Person (location == 'C', age > 80 )
Then
do_something();
end
rule 'Rule Else'
activation-group 'age-test'
when
Person (age > 65 )
Then
do_something();
end
This will do what you want, and the first rule that matches will cancel the activation of
any other rules that matches. However, because these rules are not mutually exclusive,
this is not the best way to represent the logic, since a change to person could cause the
wrong rule to fire, since only the rules that are affected by the change would be
re-activated.
The EASIEST way to represent this is with an Excel Spreadsheet (or the Guvnor Decision
Table). Then you can craft the table to identify each rule exclusively, and use the
otherwise keyword to deal with the negation of all specified facts. If you can represent
your rules without requiring salience as the conflict resolver, then you will have better
(more predictable) rules, since this would mean that only one of the group rules could
ever be true at any instance in proessing.
-----Original Message-----
ronalbury wrote
> Hi - I am a Drools newbie and I apologize in advance if the answer to my
> question is intuitively obvious to the casual user.
>
> I have an object that has two fields: location(there are more than 50
> locations) and age. I am having difficulty building clean rules for the
> following pseudo-code
>
>
> // Rule One
> if(location == "A") {
> if(age> 60)
> do_something();
> }
> // Rule Two
> else if(location == "B") {
> if(age> 70)
> do_something();
> }
> // Rule Three
> else if(location == "C") {
> if(age> 80)
> do_something();
> }
> // Rule Four
> else {
> if(age> 65)
> do_something();
> }
>
> The issue comes with Rule Four. How do I avoid writing the rule so that I
> don't have to say
(location!="A"&&location!="B"&&location!="C")
? I also
> don't want to have to write an explicit rule for every possible location.
>
> I considered an activation-group with salience to have the rules executed
> in order, but the problem is that if rules 1-3 do not fire, then rule 4
> fires for all locations - I can get a hit if location=="C" and age==70.
>
> Is it possible to have a 'Map' and do something like
> (age>map.get(location)) ? I could live with creating a map with all
> possible locations for key, although I'd rather not go this route.
>
> This problem is typical for the types of rules I'll be writing ... there
> can be completely different sets of rule criteria depending on location.
>
>
> Thanks in advance for your suggestions and your patience.
>
> _______________________________________________
> rules-users mailing list
> rules-users@.jboss
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
--
View this message in context:
http://drools.46999.n3.nabble.com/rules-users-multi-factor-rule-tp3531130...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users