[rules-dev] [accumulate] sum is always a double? What if it's only an int?

Edson Tirelli tirelli at post.com
Sun Jul 22 15:30:18 EDT 2007


    Geoffrey,

    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
        sum($distance)
     );

    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.

    []s
    Edson


2007/7/22, Geoffrey De Smet < ge0ffrey.spam at gmail.com>:
>
> 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"
>    when
>      $scoreFact : ScoreFact(); // singleton
>      $total : Integer() from accumulate(
>         Hop($distance : distance ), // distance is an int
>         sum($distance)
>      );
>    then
>      $scoreFact.setSoftConstraintsBroken($total);
> end
>
>
> svn is still here, till it's ready for drools:
> https://taseree.svn.sourceforge.net/svnroot/taseree/trunk
>
> --
> With kind regards,
> Geoffrey De Smet
>
> _______________________________________________
> rules-dev mailing list
> rules-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-dev
>



-- 
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-dev/attachments/20070722/6bf90b41/attachment.html 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-dev/attachments/20070722/6bf90b41/attachment-0001.html 


More information about the rules-dev mailing list