<div>You can rewrite this rule like this (if I managed to juggle the inequality correctly):</div><div><br></div><div> client: Client()</div><div> contextProd: PortfolioProduct(prodAdded == true, productId =="PROFESSIONAL")</div>
<div> Number(qty_00001: intValue<b> == 1</b> ) from accumulate(pp: PortfolioProduct(productId in ("BOX_001"), prodAdded == true), count(pp))</div><div> Number(qty_00002: intValue) from accumulate(pp: PortfolioProduct(productId in ("BOX_002"), prodAdded == true), count(pp))</div>
<div> Number(qty_00003: intValue) from accumulate(pp: PortfolioProduct(productId in ("BOX_003"), prodAdded == true), count(pp))</div><div> Number(qty_00004: intValue) from accumulate(pp: PortfolioProduct(productId in ("BOX_004"), prodAdded == true), count(pp))</div>
<div> Number(qty_00005: intValue <b>> qty_00002 - qty_00003 - qty_00004</b> )</div><div> from accumulate(pp: PortfolioProduct(productId in ("BOX_005"), prodAdded == true), count(pp))</div><div><br></div>
<div>Especially the == 1in the first Number should block additional useless work.</div><div><br></div><div>But the performance hit might also be due to the excessive use of accumulate.</div><div><br></div><div>-W</div><div>
<br></div><div><br></div><br><div class="gmail_quote">On 13 March 2012 20:12, fx242 <span dir="ltr"><<a href="mailto:drools@fx242.com">drools@fx242.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have a question regarding eval() use. My rulebase is around ~3k rules, most<br>
of them are auto-generated by templates, and they end up looking like this:<br>
<br>
rule "CONFIG_114"<br>
salience 0<br>
when<br>
client: Client()<br>
contextProd: PortfolioProduct(prodAdded == true, productId ==<br>
"PROFESSIONAL")<br>
Number(qty_00001: intValue) from accumulate(pp:<br>
PortfolioProduct(productId in ("BOX_001"), prodAdded == true), count(pp))<br>
Number(qty_00002: intValue) from accumulate(pp:<br>
PortfolioProduct(productId in ("BOX_002"), prodAdded == true), count(pp))<br>
Number(qty_00003: intValue) from accumulate(pp:<br>
PortfolioProduct(productId in ("BOX_003"), prodAdded == true), count(pp))<br>
Number(qty_00004: intValue) from accumulate(pp:<br>
PortfolioProduct(productId in ("BOX_004"), prodAdded == true), count(pp))<br>
Number(qty_00005: intValue) from accumulate(pp:<br>
PortfolioProduct(productId in ("BOX_005"), prodAdded == true), count(pp))<br>
eval(qty_00001 == 1)<br>
not(eval(qty_00002 >= (qty_00003 + qty_00004 + qty_00005)))<br>
then<br>
balance(kcontext, contextProd, qty_00002, ">=", (qty_00003 + qty_00004 +<br>
qty_00005));<br>
end<br>
<br>
These rules have all one or two evals in the end, comparing product<br>
quantities that are present in the Working Memory.<br>
My question is: Is there any better way to write this kind of rules without<br>
resorting to eval()?<br>
I'm currently getting hit (in performance terms) by over-using these, so I<br>
wonder if there is a better way to do this.<br>
Thanks!<br>
<br>
Tiago Lopes<br>
<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/drools-arithmetics-without-eval-tp3823232p3823232.html" target="_blank">http://drools.46999.n3.nabble.com/drools-arithmetics-without-eval-tp3823232p3823232.html</a><br>
Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br>