You must have misinterpreted the Expert manual.
At #d0e6921, which you quote, it says that "Accumulate with inline custom code
is not a good practice for several reasons". So we have
1) from accumulate (as used in the Planner example)
2) Inline custom code
3) Java implementation
But there is a fourth way, see 4.8.3.7.4.1., Accumulate CE (preferred syntax)
This is the Planner example, rewritten:
$computer : CloudComputer($cpuPower : cpuPower)
accumulate( CloudProcess(
computer == $computer,
$requiredCpuPower : requiredCpuPower);
$requiredCpuPowerTotal : sum($requiredCpuPower),
$requiredCpuPowerTotal > $cpuPower )
-W
On 22/01/2013, Michiel Vermandel <mvermand(a)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_...)
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