Yes, it should
But this kind of rule implies that a PortfolioProduct has a unique contribution in a
unique counter (when prodCounted becomes true, the PortfolioProduct won't be counted
anymore).
And I am not sure whether this kind of rule is more efficient than an accumulate or a
query (it implies a lot of updates, and to me this is equivalent to an accumulate).
My way of doing such things is to count in a counter object (like the ProductCounter
here), but don't call modify (or update) to avoid loop and to avoid adding some
"too technical" stuff in rules.
Once all "counting" rules fired, I exec another rule (in a separate
ruleflow-group or agenda-group) that updates the counters.
Then I give the focus to decision rules ...
----- Mail original -----
De: rouvas(a)mm.di.uoa.gr
À: rules-users(a)lists.jboss.org
Envoyé: Mercredi 14 Mars 2012 13:25:51
Objet: Re: [rules-users] drools arithmetics without eval()
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(a)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-tp38232...
> Sent from the Drools: User forum mailing list archive at
Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users