There are currently 3 ways to write your accumulate pattern in drools:
  1. 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.
  2. Use some of the predefined accumulate functions like sum(), avg(), count(), etc.
  3. 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.  
Best Regards,



XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti
- Blog @ http://ilesteban.wordpress.com


On Tue, Jan 22, 2013 at 10:04 AM, Michiel Vermandel <mvermand@yahoo.com> wrote:
Hi,

In lots of rules in the drools planner examples the accumulate function is used in this way:

rule "requiredCpuPowerTotal"
    when
        $computer : CloudComputer($cpuPower : cpuPower)
        $requiredCpuPowerTotal : Number(intValue > $cpuPower) from accumulate(
            CloudProcess(
                computer == $computer,
                $requiredCpuPower : requiredCpuPower),
            sum($requiredCpuPower)
        )
    then
        insertLogical(new IntConstraintOccurrence("requiredCpuPowerTotal", ConstraintType.NEGATIVE_HARD,
                $requiredCpuPowerTotal.intValue() - $cpuPower,
                $computer));
end

(example from cloudBalancing).

Though, documentation says (http://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html_single/#d0e6921) one should this syntax:

<result pattern> from accumulate( <source pattern>,
                                  init( <init code> ),
                                  action( <action code> ),
                                  reverse( <reverse code> ),
                                  result( <result expression> ) )


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 "requiredCpuPowerTotal" ?

Thanks


-----------------
http://www.codessentials.com - Your essential software, for free!
Follow us at http://twitter.com/#!/Codessentials

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users