Mohan:

   What version of drools are you using--V2.5?  What about conflict
resolvers?  Do you have any loaded?  Once the conditions are all
true...the rule is asserted.........The Conflict reolvers will fire
based on any loaded.   One of the Conflict Resolver is:
SalienceConflictResolver.   This will prioritize your rules.  Here an
example:

     ConflictResolver[] conflictResolvers = new ConflictResolver[] {
        
SalienceConflictResolver.getInstance(), 
        
RecencyConflictResolver.getInstance(),
        
SimplicityConflictResolver.getInstance(),
        
LoadOrderConflictResolver.getInstance()};
          
      CompositeConflictResolver resolver = 
                          new
CompositeConflictResolver(conflictResolvers);


 
RuleBaseLoader.loadFromUrl(BusinessLayer.class.getResource(BUSINESS_RULE
_FILE), resolver);

   

     If none are loaded.....I think the behavior is whatever was loaded
first.....  

    I am sure others with more experience than I will verify my
thoughts......

Russ 

-----Original Message-----
From: Mohan Navaratna [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 09, 2006 1:32 PM
To: [email protected]
Subject: [drools-user] salience in Rule Class


Hi,

I have recently started using drools and I am having some issues. 

 

I have two classes Rule1 and Rule2 which extends the class Rule. (I am
not
using drl files. Lets just say we cannot use drl files).

I set the salience for Rule1 as 10 and Rule2 as 20 in the constructor of
these classes.

When I fire all rules Rule1 is getting triggered first. Here is the
snippet
of my testcase :

 

        RuleSet ruleSet = new RuleSet( "Testing Salience feature" );

        Rule1 rule1 = new Rule1();

        Rule2 rule2 = new Rule2();

        ruleSet.addRule(rule1);

        ruleSet.addRule(rule2);

        RuleBaseBuilder builder = new RuleBaseBuilder( );

        builder.addRuleSet( ruleSet );

        RuleBase ruleBase = builder.build( );

        WorkingMemory workingMemory = ruleBase.newWorkingMemory( );

        workingMemory.assertObject( new SomeObject());

        workingMemory.fireAllRules( );

 

However if I interchange adding rules to the rule set as follows then
Rule2
is fired first.

        ruleSet.addRule(rule2);

        ruleSet.addRule(rule1);

 

that is,  the load order is dictating the firing. I tried all
combinations
and rules are getting triggered on how I add them to rule base.

I thought it has something to do with the conflict resolver and added
the
following code with no success.

builder.setConflictResolver(SalienceConflictResolver.getInstance());

 

I tried this on drools 2.1 as well as 2.5-final with the same results.

How can I make sure that the rules are triggered depending on their
salience
value and not the load order ?

 

Any help is highly appreciated.

Mohan

 

 

 

 

Reply via email to