Jeevan, sorry, I missed your e-mail in the limbo.

  Just create a class or an attribute to be your accumulator...
For instance, if you create a "branchCounter" attribute in the Tree object, you can do that:

rule "Count branches" salience 10
when
     $t : Tree()
     Branch( tree == $t )
then
     $t.incrementBranchCounter();
     modify( $t );
end

rule "Check branch count" salience 0
when
     $t : Tree( branchCounter > 100 )
then
    // do something
end

The only trick is the salience. The first rule must have a higher salience in order to only fire the second rule after all branches are counted.

Yes, in trunk you could do better with "accumulate" or "collect". For your case, "collect" would be simpler:

rule "Check branches"
when
   $t : Tree()
   $branches : ArrayList( size > 100 ) from collect( Branch( tree == $t ) )
then
   // do something
end

  []s
  Edson

Jeevan Tambuluri wrote:

Hello all,

I have been told that you could implement a helper class to simulate "accumulate" command in drools. Could you please ealborate on how to do this? Some code snippet to illustrate this would be very much appreciated.

My problem is as follows.I have two types of facts - Tree and Branch. Each Branch object has a reference to the Tree object it belongs to. I want to write a rule: The number of branches in a tree must not exceed 100. I guess this would be easy to write with "accumulate" command, which is not yet available in 3.0.x.

Thanks

Jeevan

------------------------------------------------------------------------

_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users


--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3124-6000
Mobile: +55 11 9218-4151
JBoss, a division of Red Hat @ www.jboss.com


_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to