[rules-users] form of accumulate in examples is depricated?
Wolfgang Laun
wolfgang.laun at gmail.com
Tue Jan 22 05:07:56 EST 2013
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 at 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
More information about the rules-users
mailing list