Two other ways to achieve what'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"><<a href="mailto:frank.vanhoenshoven@agserv.eu">frank.vanhoenshoven@agserv.eu</a>></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>
><br>
> I have 3 rules<br>
><br>
> R1 - state=GA, policy type = Home Owner, Rating program = Standard, then<br>
> print a<br>
> R2 - State=GA, Rating Program = Standard, then print b<br>
> R3 - State=GA, then print c<br>
><br>
> Now I insert the fact with state = GA, policy = HOwner, rating program =<br>
> Standard,<br>
> it matches on all the above 3 rules.<br>
><br>
> So I wrote my own ComplexityConflictresolver so only one rule should fire<br>
> based on the most matched conditions. But it is firing all the above three<br>
> rules.<br>
><br>
> This is the piece of code I have in complexity resolver<br>
><br>
> public int compare(Activation lhs,<br>
> Activation rhs)<br>
> {<br>
> Rule lhsRule = lhs.getRule();<br>
> int numLhsConstraints = getNumConstraintsForRule(lhsRule);<br>
><br>
> Rule rhsRule = rhs.getRule();<br>
> int numRhsConstraints = getNumConstraintsForRule(rhsRule);<br>
><br>
> //return numRhsConstraints - numLhsConstraints;<br>
><br>
> if ( numLhsConstraints > numRhsConstraints ) {<br>
> return 1;<br>
> } else if ( numLhsConstraints < numRhsConstraints ) {<br>
> return -1;<br>
> } else {<br>
> return 0;<br>
> }<br>
> }<br>
><br>
> private int getNumConstraintsForRule(Rule rule)<br>
> {<br>
> int numConstraints = 0;<br>
><br>
> Declaration[] declarations = rule.getDeclarations();<br>
> for (Declaration declaration : declarations)<br>
> {<br>
> List constraints = declaration.getPattern().getConstraints();<br>
> if (null != constraints)<br>
> {<br>
> numConstraints += constraints.size();<br>
> }<br>
> }<br>
> return numConstraints;<br>
> }<br>
><br>
><br>
><br>
> This is the piece of code where I hook in the resolver<br>
> RuleBaseConfiguration configuration = new RuleBaseConfiguration();<br>
><br>
> ConflictResolver[] conflictResolvers = new ConflictResolver[] {<br>
><br>
> com.test.rulesengine.conflict.ComplexityConflictResolver.getInstance()<br>
> };<br>
> CompositeConflictResolver resolver = new<br>
> CompositeConflictResolver(conflictResolvers);<br>
> configuration.setConflictResolver(resolver);<br>
><br>
><br>
> KnowledgeBase knowledgeBase =<br>
> KnowledgeBaseFactory.newKnowledgeBase(configuration);<br>
><br>
><br>
> It looks like it is adding all three activations to Agenda and firing each<br>
> one of them.<br>
><br>
> What am I doing wrong. Any help will be appreciated.<br>
><br>
> Thanks<br>
><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>