Two other ways to achieve what&#39;s wanted:<div><br></div><div>(1) Retract the fact on the RHS of the matching rule.</div><div>(2) Add a boolean attribute a to the fact, add a constraint a == false</div><div>and modify the fact on the RHS of the matching rule, setting a to true.<br>
<br>-W<br><br><div class="gmail_quote">On 26 March 2012 15:58, FrankVhh <span dir="ltr">&lt;<a href="mailto:frank.vanhoenshoven@agserv.eu">frank.vanhoenshoven@agserv.eu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
To my knowledge, conflict resolvers are only used to determine priority of<br>
rule activations. It does not prevent rules from firing.<br>
<br>
You should be able to get the behavior you want by adding activation-groups.<br>
In an activation group, only one rule can fire. See documentation.<br>
<br>
Regards,<br>
Frank<br>
<br>
<br>
vanithap wrote<br>
&gt;<br>
&gt; I have 3 rules<br>
&gt;<br>
&gt; R1 - state=GA, policy type = Home Owner, Rating program  = Standard, then<br>
&gt; print a<br>
&gt; R2 - State=GA, Rating Program = Standard, then print b<br>
&gt; R3 - State=GA, then print c<br>
&gt;<br>
&gt; Now I insert the fact with state = GA, policy = HOwner, rating program =<br>
&gt; Standard,<br>
&gt; it matches on all the above 3 rules.<br>
&gt;<br>
&gt; So I wrote my own ComplexityConflictresolver so only one rule should fire<br>
&gt; based on the most matched conditions. But it is firing all the above three<br>
&gt; rules.<br>
&gt;<br>
&gt; This is the piece of code I have in complexity resolver<br>
&gt;<br>
&gt; public int compare(Activation lhs,<br>
&gt;                        Activation rhs)<br>
&gt;     {<br>
&gt;         Rule lhsRule = lhs.getRule();<br>
&gt;         int numLhsConstraints = getNumConstraintsForRule(lhsRule);<br>
&gt;<br>
&gt;         Rule rhsRule = rhs.getRule();<br>
&gt;         int numRhsConstraints = getNumConstraintsForRule(rhsRule);<br>
&gt;<br>
&gt;         //return numRhsConstraints - numLhsConstraints;<br>
&gt;<br>
&gt;         if ( numLhsConstraints &gt; numRhsConstraints ) {<br>
&gt;             return 1;<br>
&gt;         } else if ( numLhsConstraints &lt; numRhsConstraints ) {<br>
&gt;             return -1;<br>
&gt;         } else {<br>
&gt;             return 0;<br>
&gt;         }<br>
&gt;     }<br>
&gt;<br>
&gt;     private int getNumConstraintsForRule(Rule rule)<br>
&gt;     {<br>
&gt;         int numConstraints = 0;<br>
&gt;<br>
&gt;         Declaration[] declarations = rule.getDeclarations();<br>
&gt;         for (Declaration declaration : declarations)<br>
&gt;         {<br>
&gt;             List constraints = declaration.getPattern().getConstraints();<br>
&gt;             if (null != constraints)<br>
&gt;             {<br>
&gt;                 numConstraints += constraints.size();<br>
&gt;             }<br>
&gt;         }<br>
&gt;         return numConstraints;<br>
&gt;     }<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; This is the piece of code where I hook in the resolver<br>
&gt;         RuleBaseConfiguration configuration = new RuleBaseConfiguration();<br>
&gt;<br>
&gt;         ConflictResolver[] conflictResolvers = new ConflictResolver[] {<br>
&gt;<br>
&gt; com.test.rulesengine.conflict.ComplexityConflictResolver.getInstance()<br>
&gt;         };<br>
&gt;         CompositeConflictResolver resolver = new<br>
&gt; CompositeConflictResolver(conflictResolvers);<br>
&gt;         configuration.setConflictResolver(resolver);<br>
&gt;<br>
&gt;<br>
&gt;         KnowledgeBase knowledgeBase =<br>
&gt; KnowledgeBaseFactory.newKnowledgeBase(configuration);<br>
&gt;<br>
&gt;<br>
&gt; It looks like it is adding all three activations to Agenda and firing each<br>
&gt; one of them.<br>
&gt;<br>
&gt; What am I doing wrong. Any help will be appreciated.<br>
&gt;<br>
&gt; Thanks<br>
&gt;<br>
<br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Complexity-Conflict-Resolver-not-working-as-expected-tp3851854p3858196.html" target="_blank">http://drools.46999.n3.nabble.com/Complexity-Conflict-Resolver-not-working-as-expected-tp3851854p3858196.html</a><br>

Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br></div>