You can rewrite this rule like this (if I managed to juggle the inequality correctly):

   client: Client()
   contextProd: PortfolioProduct(prodAdded == true, productId =="PROFESSIONAL")
   Number(qty_00001: intValue == 1 ) from accumulate(pp: PortfolioProduct(productId in ("BOX_001"), prodAdded == true), count(pp))
   Number(qty_00002: intValue) from accumulate(pp: PortfolioProduct(productId in ("BOX_002"), prodAdded == true), count(pp))
   Number(qty_00003: intValue) from accumulate(pp: PortfolioProduct(productId in ("BOX_003"), prodAdded == true), count(pp))
   Number(qty_00004: intValue) from accumulate(pp: PortfolioProduct(productId in ("BOX_004"), prodAdded == true), count(pp))
   Number(qty_00005: intValue > qty_00002 - qty_00003 - qty_00004 )
      from accumulate(pp: PortfolioProduct(productId in ("BOX_005"), prodAdded == true), count(pp))

Especially the == 1in the first Number should block additional useless work.

But the performance hit might also be due to the excessive use of accumulate.

-W



On 13 March 2012 20:12, fx242 <drools@fx242.com> wrote:
I have a question regarding eval() use. My rulebase is around ~3k rules, most
of them are auto-generated by templates, and they end up looking like this:

rule "CONFIG_114"
   salience 0
when
   client: Client()
   contextProd: PortfolioProduct(prodAdded == true, productId ==
"PROFESSIONAL")
   Number(qty_00001: intValue) from accumulate(pp:
PortfolioProduct(productId in ("BOX_001"), prodAdded == true), count(pp))
   Number(qty_00002: intValue) from accumulate(pp:
PortfolioProduct(productId in ("BOX_002"), prodAdded == true), count(pp))
   Number(qty_00003: intValue) from accumulate(pp:
PortfolioProduct(productId in ("BOX_003"), prodAdded == true), count(pp))
   Number(qty_00004: intValue) from accumulate(pp:
PortfolioProduct(productId in ("BOX_004"), prodAdded == true), count(pp))
   Number(qty_00005: intValue) from accumulate(pp:
PortfolioProduct(productId in ("BOX_005"), prodAdded == true), count(pp))
   eval(qty_00001 == 1)
   not(eval(qty_00002 >= (qty_00003 + qty_00004 + qty_00005)))
then
   balance(kcontext, contextProd, qty_00002, ">=", (qty_00003 + qty_00004 +
qty_00005));
end

These rules have all one or two evals in the end, comparing product
quantities that are present in the Working Memory.
My question is: Is there any better way to write this kind of rules without
resorting to eval()?
I'm currently getting hit (in performance terms) by over-using these, so I
wonder if there is a  better way to do this.
Thanks!

Tiago Lopes




--
View this message in context: http://drools.46999.n3.nabble.com/drools-arithmetics-without-eval-tp3823232p3823232.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users