[rules-users] Get rid of redundant conditions in combined rules.

Wolfgang Laun wolfgang.laun at gmail.com
Tue Oct 19 13:53:56 EDT 2010


I think that a single helper class
  class Marker {
     String property;
     Object target;
  }
would be sufficient:
   // 1st consequence
   insert( new Tag( "London", customer ) );

   // 2nd condition
   Tag( property == "London", $target : target )
   Customer( this == $target, job == "teacher" )

You may need to have a strategy for retracting obsolete Tag facts.

-W



2010/10/19 Dominik Hüttner <d.huettner at tiq-solutions.de>:
> Hi Leonardo,
>
> the performance problem I thought of meant removing and inserting the facts
> again and again, if I would remove the facts, that don’t fit the first rule
> and execute the second rule only on the remaining facts.
>
> The solution you offered, does, what I intend, but the problem is, that I
> have to create a new class for every rule-pair and I want to use it
> flexible, without having to create a new class / model for every rule. Is
> there maybe another way to solve this problem?
>
>
>
> Kind regards,
>
>
>
> Dominik
>
>
>
>
>
>
>
> Von: rules-users-bounces at lists.jboss.org
> [mailto:rules-users-bounces at lists.jboss.org] Im Auftrag von Leonardo Gomes
> Gesendet: Dienstag, 12. Oktober 2010 16:37
> An: Rules Users List
> Betreff: Re: [rules-users] Get rid of redundant conditions in combined
> rules.
>
>
>
> If your problem is performance, don't worry. Conditions evaluation is
> shared, so in the second rule you won't re-evaluate the entire working
> memory (to know more:http://www.drdobbs.com/184405218).
>
> If you're worried about not having to repeat the conditions on the second
> rule, I would create inferred facts when the first rule matches and use then
> in the second rule + the additional conditions.
>
> Something like:
>
> Rule1:
>
> when
>
>             customer:Customer(town=="London")
>
> then
>
>             insert new LondonCustomer( customer );
>
>
>
> Rule2:
>
> when
>
>             london : LondonCustomer(customer.job=="TEACHER")
>
> then
>
>             System.out.println(london.customer.getLname() + " is a
> teacher");
>
>
>
> 2010/10/12 Dominik Hüttner <d.huettner at tiq-solutions.de>
>
> Hello everyone,
>
> I’ve got a question. I’m using drools-guvnor to execute some rule-scenarios.
> I have to solve the following problem: I have an amount of objects in my
> working memory and can’t remove objects from the working memory in the
> then-part of the rule. I want to combine two rules, the first rule selects
> some objects and the second rule checks only these selected objects for
> additional criteria. I have to use two rules, because I want to report the
> objects selected in the first rule, too. Now I have implemented this with
> two rules and in the second rule, the criterias of the first rule are copied
> to the second rule, my question is, is there a way to get rid of this
> redundandance?
>
> I have tried this with a rule flow, but the problem is, this always works on
> the whole working memory, but I can’t remove the not used objects from
> working memory for performance reasons. Is there another way to solve this
> problem?
>
>
>
> Here is an example for what I intend to do:
>
>
>
> Rule1:
>
> when
>
>             customer:Customer(town=="London")
>
> then
>
>             System.out.println(customer.getLname() + " is inhabitant of
> London");
>
>
>
> Rule2:
>
> when
>
>             customer:Customer(town=="London",job=="TEACHER")
>
> then
>
>             System.out.println(customer.getLname() + " is a teacher");
>
>
>
> This example illustrates, with the first rule I want to get to know, how
> many customers are from London and in the second rule I want to know, how
> many of the London customers are teachers. I want to create a kind of
> statistics. I have quite a lot of conditions for the first rule, so I don’t
> want to have them redundantly.
>
>
>
> Greetings, Dominik
>
> _______________________________________________
> 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