[rules-users] Complexity Conflict Resolver not working as expected
Wolfgang Laun
wolfgang.laun at gmail.com
Mon Mar 26 13:16:11 EDT 2012
Two other ways to achieve what's wanted:
(1) Retract the fact on the RHS of the matching rule.
(2) Add a boolean attribute a to the fact, add a constraint a == false
and modify the fact on the RHS of the matching rule, setting a to true.
-W
On 26 March 2012 15:58, FrankVhh <frank.vanhoenshoven at agserv.eu> wrote:
> Hi,
>
> To my knowledge, conflict resolvers are only used to determine priority of
> rule activations. It does not prevent rules from firing.
>
> You should be able to get the behavior you want by adding
> activation-groups.
> In an activation group, only one rule can fire. See documentation.
>
> Regards,
> Frank
>
>
> vanithap wrote
> >
> > I have 3 rules
> >
> > R1 - state=GA, policy type = Home Owner, Rating program = Standard, then
> > print a
> > R2 - State=GA, Rating Program = Standard, then print b
> > R3 - State=GA, then print c
> >
> > Now I insert the fact with state = GA, policy = HOwner, rating program =
> > Standard,
> > it matches on all the above 3 rules.
> >
> > So I wrote my own ComplexityConflictresolver so only one rule should fire
> > based on the most matched conditions. But it is firing all the above
> three
> > rules.
> >
> > This is the piece of code I have in complexity resolver
> >
> > public int compare(Activation lhs,
> > Activation rhs)
> > {
> > Rule lhsRule = lhs.getRule();
> > int numLhsConstraints = getNumConstraintsForRule(lhsRule);
> >
> > Rule rhsRule = rhs.getRule();
> > int numRhsConstraints = getNumConstraintsForRule(rhsRule);
> >
> > //return numRhsConstraints - numLhsConstraints;
> >
> > if ( numLhsConstraints > numRhsConstraints ) {
> > return 1;
> > } else if ( numLhsConstraints < numRhsConstraints ) {
> > return -1;
> > } else {
> > return 0;
> > }
> > }
> >
> > private int getNumConstraintsForRule(Rule rule)
> > {
> > int numConstraints = 0;
> >
> > Declaration[] declarations = rule.getDeclarations();
> > for (Declaration declaration : declarations)
> > {
> > List constraints = declaration.getPattern().getConstraints();
> > if (null != constraints)
> > {
> > numConstraints += constraints.size();
> > }
> > }
> > return numConstraints;
> > }
> >
> >
> >
> > This is the piece of code where I hook in the resolver
> > RuleBaseConfiguration configuration = new
> RuleBaseConfiguration();
> >
> > ConflictResolver[] conflictResolvers = new ConflictResolver[] {
> >
> > com.test.rulesengine.conflict.ComplexityConflictResolver.getInstance()
> > };
> > CompositeConflictResolver resolver = new
> > CompositeConflictResolver(conflictResolvers);
> > configuration.setConflictResolver(resolver);
> >
> >
> > KnowledgeBase knowledgeBase =
> > KnowledgeBaseFactory.newKnowledgeBase(configuration);
> >
> >
> > It looks like it is adding all three activations to Agenda and firing
> each
> > one of them.
> >
> > What am I doing wrong. Any help will be appreciated.
> >
> > Thanks
> >
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Complexity-Conflict-Resolver-not-working-as-expected-tp3851854p3858196.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120326/db7ada40/attachment.html
More information about the rules-users
mailing list