[rules-users] problem in firing dependent rules..

Greg Barton greg_barton at yahoo.com
Fri Jan 9 11:23:18 EST 2009


"Is there a way we can handle this requirement."

Yes.  Educate your users. :)  Seriously.  Rules programming is non-trivial, and this is a good example.  One of the advantages of rules is this cascading activation, and reactivation, or rules.  It does require some skill on the part of the rule writer to know when that is necessary.  There's just too much nuance necessary.

That being said, you can make life a bit easier for the rule writer.  I don't know the details of your drools front end, but if in your rule writing GUI you're listing the objects being matched, you have some options.  The best one is a "propagate" checkbox for each object matched.  (For each object checked put a modify statement in your generated DRL.)  

But the most important piece of education for business users is this: writing rules is not easy.  It is programming.  The problems are complex, so the solutions are complex as well.  There's no escaping it.

--- On Fri, 1/9/09, Sudhir M <sudhir.cse at gmail.com> wrote:

> From: Sudhir M <sudhir.cse at gmail.com>
> Subject: Re: [rules-users] problem in firing dependent rules..
> To: "Rules Users List" <rules-users at lists.jboss.org>
> Date: Friday, January 9, 2009, 9:24 AM
> Thanks Edson  for a quick response.
> Actually our requirement is to have our own custom rule
> builder which will
> use drools as a rule engine behind. So we are using Drools
> API to create the
> drl. since the end-user who models a rule is a business guy
> it is difficult
> to ask him to manage the dependencies. In this case it may
> not be possible
> for us to know when to update a fact. Initially we were by
> default adding
> modify() block to update the facts for every rule. In this
> case if more than
> one rule is eligible to fire then its going into a loop
> firing all the rules
> again and again in a loop. Is there a way we can handle
> this requirement.
> Below is the sample rule that we created which ran into
> loop through drools
> API
> rule "PolicyTierClassification"
>  no-loop true
>  when
> healthInsuredbindings : HealthInsured( weight >= 285 ,
> weight < 327 , height
> == "6ft 6in" , gender == "Male" )
> 
>  then
> modify(healthInsuredbindings){setPolicyTier("Standard
> II")};
> list.add("To determine tier based on insured gender,
> height and
> weight(weight>=285 , weight<327 , height==6ft 6in ,
> gender==Male ) ->
> (PolicyTier = Standard II)"); end
> 
> 
> 
> On Fri, Jan 9, 2009 at 8:27 PM, Edson Tirelli
> <tirelli at post.com> wrote:
> 
> >
> >    Sudhir:
> >
> >    In Rete, you must tell the engine a fact has
> changed, either by using a
> > modify() block (recommended), or update() or property
> listeners.
> >
> >    LEAPS is a different algorithm that was originally
> maintained by a
> > community user that long ago abandoned it. It is no
> longer included in the
> > drools distribution.
> >
> >    []s
> >    Edson
> >
> > 2009/1/9 Sudhir M <sudhir.cse at gmail.com>
> >
> >> Hi All,
> >> I don't know whether I have encountered a
> strange problem or my
> >> understanding of drools is wrong.
> >>
> >> I have 3 rules out of which two are dependent.
> Between the dependent ones
> >>  one rule makes the other rule eligible to fire
> but I don't know why the
> >> dependent rule is not firing. Below are the rules
> I have written.
> >> package com.valueMomentum;
> >> import com.valuemomentum.eligibilitymodel.oo.*;
> >> import java.util.ArrayList;
> >> global java.util.ArrayList list;
> >>
> >> rule "PolicyTierClassification"
> >>  no-loop true
> >>  when
> >> healthInsuredbindings : HealthInsured( weight
> >= 134 , weight < 157 ,
> >> height == "4ft 10in" , gender ==
> "Male" )
> >>
> >>  then
> >> healthInsuredbindings.setPolicyTier("Standard
> I");
> >>
> >>
> System.out.println("PolicyTierClassification");
> >> list.add("To determine tier based on insured
> gender, height and
> >> weight(weight>=134 , weight<157 ,
> height==4ft 10in , gender==Male ) ->
> >> (PolicyTier = Standard I)"); ;end
> >>
> >> rule "AlcoholConsumptionClassRule"
> >>  no-loop true
> >>  when
> >> healthInsuredbindings : HealthInsured(
> alcoholConsumptionFrequencyPerWeek
> >> == "2-3" )
> >>
> >>  then
> >>
> healthInsuredbindings.setAlcoholConsumptionClass("B");
> >> 
> System.out.println("AlcoholConsumptionClassRule");
> >> list.add("To derive the alcohol consumption
> class based on consumption
> >> frequencyalcoholConsumptionFrequencyPerWeek==2-3
> -> (AlcoholConsumptionClass
> >> = B)"); end
> >>
> >>
> >> rule "UnderwritingFactorRule"
> >>  no-loop true
> >>  when
> >> healthInsuredbindings : HealthInsured(
> alcoholConsumptionClass =="B" )
> >>
> >>  then
> >>  healthInsuredbindings.setUnderwritingFactor(1);
> >> 
> System.out.println("UnderwritingFactorRule");
> >>      list.add("To derive UnderwritingFactor
> from
> >>  alcoholConsumptionClass==B ->
> (UnderwritingFactor = 1)");end
> >>
> >> this my initial fact HealthInsured healthInsured =
> new HealthInsured();
> >>  healthInsured.setAge(25);
> >> healthInsured.setGender("Male");
> >>  healthInsured.setWeight(140);
> >> healthInsured.setHeight("4ft 10in");
> >>  healthInsured.setTobaccoUser("No");
> >> healthInsured.setMotorcycleRider("No");
> >> 
> healthInsured.setRelationToInsured("Insured");
> >> healthInsured.setUnderwritingFactor(0);
> >> 
> healthInsured.setPolicyTier("Preferred");
> >>
> healthInsured.setAlcoholConsumptionFrequencyPerWeek("2-3");
> >> 
> healthInsured.setAlcoholConsumptionClass("A");
> >> Based on the above fact PolicyTierClassification,
> AlcoholConsumptionClassRule
> >> are eligible  to fire. AlcoholConsumptionClassRule
>  is setting a property
> >> alcoholConsumptionClass to B based on which
> UnderwritingFactorRule rule
> >> becomes eligible fire but in this case the
> dependent rule is not firing. I
> >> think we can use update in 
> AlcoholConsumptionClassRule  but I think if
> >> we have to manage those dependencies it will be
> more error prone and the
> >> results are might be more inconsistent.
> >>
> >> I have tested it Using RETEOO in drools 3.x and
> 4.x which yields me the
> >> same results. But when I used LEAPS algorithm then
> i even got the dependent
> >> rule i.e UnderwritingFactorRule  rule  also fired.
> >>
> >> Thanks in Advance,
> >>
> >> sudhir.
> >>
> >>
> >> _______________________________________________
> >> rules-users mailing list
> >> rules-users at lists.jboss.org
> >>
> https://lists.jboss.org/mailman/listinfo/rules-users
> >>
> >>
> >
> >
> > --
> >  Edson Tirelli
> >  JBoss Drools Core Development
> >  JBoss, a division of Red Hat @ www.jboss.com
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users


      



More information about the rules-users mailing list