<div dir="ltr">There are currently 3 ways to write your accumulate pattern in drools:<div style><ol style><li style>The way you have pointed out containing all the different sections: init, action, reverse and result. The problem with this syntax is that you have to embed java code in your rules making them hard to read and maintain. Following this syntax, if you want to reuse an accumulate function you have to copy and paste it. This form of accumulate is highly discouraged by drools team.</li>

<li style>Use some of the predefined accumulate functions like sum(), avg(), count(), etc.</li><li style>If the predefined set of accumulate functions is not enough you can create your accumulate function in a Java class and then register it in drools and use it in your DRL. Please refer to the documentation for further information.  </li>

</ol>Best Regards,</div><div style><br></div></div><div class="gmail_extra"><br clear="all"><div><br>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br><br>Esteban Aliverti<br>- Blog @ <a href="http://ilesteban.wordpress.com" target="_blank">http://ilesteban.wordpress.com</a></div>


<br><br><div class="gmail_quote">On Tue, Jan 22, 2013 at 10:04 AM, Michiel Vermandel <span dir="ltr">&lt;<a href="mailto:mvermand@yahoo.com" target="_blank">mvermand@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><div style="font-size:10pt;font-family:arial,helvetica,sans-serif">Hi,<br><br>In lots of rules in the drools planner examples the accumulate function is used in this way:<br><br>rule &quot;requiredCpuPowerTotal&quot;<br>

    when<br>        $computer : CloudComputer($cpuPower : cpuPower)<br>        $requiredCpuPowerTotal : Number(intValue &gt; $cpuPower) from accumulate(<br>            CloudProcess(<br>                computer == $computer,<br>

                $requiredCpuPower : requiredCpuPower),<br>           
 sum($requiredCpuPower)<br>        )<br>    then<br>        insertLogical(new IntConstraintOccurrence(&quot;requiredCpuPowerTotal&quot;, ConstraintType.NEGATIVE_HARD,<br>                $requiredCpuPowerTotal.intValue() - $cpuPower,<br>

                $computer));<br>end<br><br>(example from cloudBalancing).<br><br>Though, documentation says (<a href="http://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html_single/#d0e6921" target="_blank">http://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html_single/#d0e6921</a>) one should this syntax:<br>

<span style="font-family:Courier New,courier,monaco,monospace,sans-serif"><br>&lt;result pattern&gt; from accumulate( &lt;source
 pattern&gt;,<br>                                  init( &lt;init code&gt; ),<br>                                  action( &lt;action code&gt; ),<br>                                  reverse( &lt;reverse code&gt; ),<br>                                  result( &lt;result expression&gt; )
 )</span><br><br>Does this mean that the axemples could be optimized and that I should go for that syntaxt as well rather than using the syntax like rule &quot;requiredCpuPowerTotal&quot; ?<br><br>Thanks<br><br><br><div>

-----------------<br><a href="http://www.codessentials.com" target="_blank">http://www.codessentials.com</a> - Your essential software, for free!<br>Follow us at <a href="http://twitter.com/#!/Codessentials" target="_blank">http://twitter.com/#!/Codessentials</a></div>

</div></div><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>
<br></blockquote></div><br></div>