[rules-users] accumulate / collect behaviour question - another stupid question

Olenin, Vladimir (MOH) Vladimir.Olenin at moh.gov.on.ca
Wed Feb 21 15:48:49 EST 2007


Hi,

 

Edson quoted the following sample rule some time ago:

 

rule "transaction consistency"

when

    Transaction( $id : id )

    $credits: Double( )

              from accumulate( TransactionEntry( id == $id, operation ==
"credit", $amount : amount ),

                                          init( double balance = 0 ),

                                          action(  balance += $amount ),

                                          result( new Double( balance ) ) );

    $debits: Double( )

              from accumulate( TransactionEntry( id == $id, operation ==
"debit", $amount : amount ),

                                          init( double balance = 0 ),

                                          action(  balance -= $amount ),

                                          result( new Double( balance ) ) );

    eval( ! $credits.equals( $debits ) ) then

   // inconsistency for transaction $id

End

 

 

If there are 100 transactions overall and only 10 unique transaction ids
(eg, id = 1..10), so that we have on average 10 Transaction facts per id,

 

- how many times will 'eval' be called?

- how many times will the action be called, assuming 'eval' always returns
'true'?

 

I guess the answer for the above should be '10 times', once per each id?
What if I put another eval statement like "eval($id == 1)" after existing
'eval'? Would that be evaluated 100 times (for all Transaction facts) or
only 10 times (once per unique id)?

 

I think I'm missing quite significant piece on how tuples are selected in
DROOLS and how 'eval' and new 'from accumulate' features work.... Any
pointers would be greatly appreciated! (would some general literature on
rule engines help to clear up this types of questions?...)

 

Thanks,

 

Vlad

 

PS: sorry for posting so many questions and answering so few.....

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070221/e45c610f/attachment.html 


More information about the rules-users mailing list