The "sum" function that is shipped with drools always uses double internally, but all numeric accumulate functions must have return type Number to avoid class cast exceptions... I must write that in the docs... so, recommendation is to do:

     Number( $total : intValue ) from accumulate(
        Hop($distance : distance ), // distance is an int

    Now, having said that, the decision to use double is because we needed a one size fits all to ship with drools. On the other hand I tried to make as simple as possible to plug new or replace built-in functions.  So, if you want a sum function that uses only integers, you can easily develop and plug it your own. Since I just wrote the docs on how to do it, may I ask you please to read them and provide a feedback if they are good, need more info, shall I write them in another way, etc?
    BTW, when I say it is really simple to create another sum function, I mean, you can do it in about 20 minutes. Really!

    Find attached the HTML doc page I'm talking about.


2007/7/22, Geoffrey De Smet <>:
Hi guys,

I finally got around to experimenting with the accumulate support in
LocalSearchSolver. Thanks for implementing it :)

I use nothing but int's in my calculations,
but I get a ClassCastExceptions, as sum() always returns a Double and
setSoftConstraintsBroken(int) failes.

In a previous benchmarks I 've proven that summing integers in double's
instead of int's hurts performance for 10% or more (which is rather big).

Is there a sumInteger() available (or do I need to write it)? Or can it
be overloaded over sum() in a much cleaner way?

rule "ScoreCalculator"
     $scoreFact : ScoreFact(); // singleton
     $total : Integer() from accumulate(
        Hop($distance : distance ), // distance is an int

svn is still here, till it's ready for drools:

With kind regards,
Geoffrey De Smet

rules-dev mailing list

  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @