<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3132" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=195244906-23042008><FONT face=Arial
color=#0000ff size=2>So, in my usual helpful manner I thought Drools would be a
perfect match and put together what I thought would be a simple
example:-</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=195244906-23042008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=195244906-23042008><FONT face="Courier New"
color=#0000ff size=2>package com.sample</FONT></SPAN></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2></FONT> </DIV>
<DIV dir=ltr align=left><SPAN class=195244906-23042008><FONT face="Courier New"
color=#0000ff size=2>global com.sample.DBUtils dbutils;<BR></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=195244906-23042008></SPAN><SPAN
class=195244906-23042008><FONT face="Courier New" color=#0000ff size=2>rule
"a1"<BR> when</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=195244906-23042008><FONT face="Courier New"
color=#0000ff size=2> $max : Integer()
from accumulate( Integer( $v : intValue ) from dbutils.getNumbers(), max($v)
)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=195244906-23042008><FONT face="Courier New"
color=#0000ff size=2> then<BR></FONT></SPAN><SPAN
class=195244906-23042008><FONT face="Courier New" color=#0000ff
size=2>
System.out.println($max);</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=195244906-23042008><FONT face="Courier New"
color=#0000ff size=2>end </FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff
size=2></FONT><FONT face="Courier New" color=#0000ff size=2></FONT> </DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2></FONT> </DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2>public class DBUtils
{</FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2> public
Integer[] getNumbers() {</FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><FONT face="Courier New" color=#0000ff
size=2> Integer[] numbers = new
Integer[10];<BR> for (int i = 0; i
< numbers.length; i++)
{<BR>
numbers[i] = (int) <SPAN class=195244906-23042008>(</SPAN>Math.random() *
100<SPAN
class=195244906-23042008>)</SPAN>;<BR>
}<BR> return
numbers;<BR> }<BR>}</FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=195244906-23042008></SPAN><FONT face=Arial><FONT
color=#0000ff><FONT size=2>H<SPAN class=195244906-23042008>owever this led to
some errors:-</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=195244906-23042008></SPAN></FONT></FONT></FONT> </DIV>
<DIV><FONT><FONT color=#0000ff><FONT face="Courier New" size=2><SPAN
class=195244906-23042008>org.drools.RuntimeDroolsException:
java.lang.ClassCastException: [Ljava.lang.Integer; incompatible with
java.lang.Integer<BR> at
org.drools.rule.Accumulate.accumulate(Accumulate.java:131)<BR> at
org.drools.reteoo.AccumulateNode.assertTuple(AccumulateNode.java:127)<BR> at
org.drools.reteoo.CompositeTupleSinkAdapter.createAndPropagateAssertTuple(CompositeTupleSinkAdapter.java:73)<BR> at
org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:116)<BR> at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:22)<BR> at
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:153)<BR> at
org.drools.reteoo.Rete.assertObject(Rete.java:177)<BR> at
org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)<BR> at
org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute(ReteooWorkingMemory.java:179)<BR> at
org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:1292)<BR> at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:891)<BR> at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:858)<BR> at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:659)<BR> at
com.sample.DroolsTest.main(DroolsTest.java:36)<BR>Caused by:
java.lang.ClassCastException: [Ljava.lang.Integer; incompatible with
java.lang.Integer<BR> at
org.drools.base.java.lang.Integer968047027$intValue.getIntValue(Unknown
Source)<BR> at
org.drools.base.ClassFieldExtractor.getIntValue(ClassFieldExtractor.java:197)<BR> at
org.drools.rule.Declaration.getIntValue(Declaration.java:230)<BR> at
com.sample.Rule_a1_0AccumulateExpression0Invoker.evaluate(Rule_a1_0AccumulateExpression0Invoker.java:16)<BR> at
org.drools.base.accumulators.JavaAccumulatorFunctionExecutor.accumulate(JavaAccumulatorFunctionExecutor.java:74)<BR> at
org.drools.rule.Accumulate.accumulate(Accumulate.java:123)<BR> ... 13
more<BR></SPAN></FONT></FONT></FONT></DIV>
<DIV><SPAN class=195244906-23042008></SPAN><FONT face=Arial><FONT
color=#0000ff><FONT size=2>H<SPAN class=195244906-23042008>ave I done something
really stupid and is Drools a fit?</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=195244906-23042008></SPAN></FONT></FONT></FONT> </DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=195244906-23042008>Cheers,</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=195244906-23042008></SPAN></FONT></FONT></FONT> </DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=195244906-23042008>Mike</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT><FONT face=Arial color=#0000ff
size=2></FONT><FONT face=Arial color=#0000ff size=2></FONT><BR></DIV>
<BLOCKQUOTE style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] <B>On Behalf Of </B>Cheng Wei
Lee<BR><B>Sent:</B> 22 April 2008 17:27<BR><B>To:</B>
rules-users@lists.jboss.org<BR><B>Subject:</B> [rules-users] Re: Is this
scenario suitable for using Drools?<BR></FONT><BR></DIV>
<DIV></DIV>I've 2 algorithms to calculate the cost of a product. At any one
time, there is only 1 algorithm in use. Initially algorithm 1 will be the
default. Subsequently, the decision to use which algorithm will depend on
customers feedback. The algorithms are:<BR><BR>Algorithm 1:<BR>Cost = MAX(P1,
T1, P2, T2, P3, T3, ...)<BR><BR>Algorithm 2:<BR>Cost = MIN(P1, P2, P3, ...) +
MIN(T1, T2, T3, ...)<BR><BR>The values of P1, P2, ... are stored within a
database. The number of Ps & Ts are unknown but can be determined by
querying the database, Would drools be a good option to use to store the
algorithms? If so, how could I be able to retrieve the values of P1, P2, etc
from the database from within
drools?<BR><BR>Thanks!<BR><BR></BLOCKQUOTE></BODY></HTML>