[rules-users] drools arithmetics without eval()

rouvas at mm.di.uoa.gr rouvas at mm.di.uoa.gr
Wed Mar 14 08:25:51 EDT 2012


Wolfgang Laun wrote:
> accumulate is not the way to go.
>
> If you need accumlated counts for certain facts, by type or, within
> some type, by attribute value, then you should set up secondary facts
> and maintain these during the element insertion process or by separate
> (static) rules.
>
> class ProductCounter {
>     String id;
>     int      count; }
>
> rule count
> when
>     $pp: PortfolioProduct($pid: productId, prodCounted == false )
>     $pc: ProductCounter( id == $pid )
> then
>     modify( $pc ){ setCount( $pc.getCount() + 1 ) }
> end

Shouldn't "then" be

 then
     modify( $pc ){ setCount( $pc.getCount() + 1 ) }
     modify ($pp ){ setProdCounted( true ) }
 end

I'm only asking to validate my understanding of the situation.

-Stathis

>
> And now you can generate the rules accessing the completed counts.
> -W
>
>
>
>
>
> On 14/03/2012, fx242 <drools at fx242.com> wrote:
>> Hi,
>>
>> These rules are all auto-generated every day, and I don't control what
>> is
>> going into them, so this kind of optimizations won't work for me. The
>> basic
>> problem here, is that I have tons of rules that count facts
>> (PortfolioProducts) and use the result as rule conditions.
>> Some conditions could look like this: count(PortfolioProduct(A)) +
>> count(PortfolioProduct(B)) <= ( count(PortfolioProduct(C)) -
>> count(PortfolioProduct(D)) ) - count(PortfolioProduct(E))
>> and so on...
>>
>> All rules look like the rule I've posted: I first calculate all relevant
>> fact counts to be used by the rule (accumulates), and then perform the
>> logic/arithmetic evaluation using evals(). Some rules end up having 15
>> accumulates and 2 evals as conditions...
>> My question is if using accumulate and eval() is the only choice I have
>> to
>> write these kind of rules.
>>
>> Regards,
>> Tiago Lopes
>>
>> --
>> View this message in context:
>> http://drools.46999.n3.nabble.com/drools-arithmetics-without-eval-tp3823232p3824958.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
>>
> _______________________________________________
> 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