Thanks Mike!<br><br>I'm a total newbie here with Drools, so what I'm going to do is to take your solution and try it out.<br><br>Cheers!<br><br><div class="gmail_quote">On Wed, Apr 23, 2008 at 4:28 PM, Anstis, Michael (M.) <<a href="mailto:manstis1@ford.com">manstis1@ford.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2">Thanks Steve,</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2">This fixed the problem!</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2">For Cheng Wei Lee's benefit this is the complete solution
(I had to fix another part):-</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2">public class DBUtils {</font></span></div>
<div><font face="Courier New"></font> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2"> public Collection getNumbers()
{</font></span></div>
<div><font face="Courier New"></font> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2"><div class="Ih2E3d"> Integer[]
numbers = new Integer[10];<br> for
(int i = 0; i < numbers.length; i++)
{<br>
numbers[i] = (int)Math.random() *
100;<br>
}<br></div> return
Arrays.asList(numbers);<br> }<br>}</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" size="2"></font></span> </div>
<div><font color="#0000ff" face="Courier New" size="2">rule "a1"<br><span> </span>when<br><span> </span>$max
: <span><font color="#008000">Number</font></span>()
from accumulate( <span><font color="#008000">Number</font></span>( $v : intValue ) from dbutils.getNumbers(),
max($v) )<br><span>
</span>then<br></font><font><font face="Courier New"><font color="#0000ff"><font size="2"><span>
S</span>ystem.out.println($max.<span>intValue</span>());<br><span>
</span>end </font></font></font></font></div>
<div dir="ltr" align="left"><span></span><span></span><span><font color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2">With kind regards,</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2">Mike</font></span></div><font color="#0000ff" size="2"></font><br>
<blockquote style="margin-right: 0px;">
<div dir="ltr" align="left" lang="en-us">
<hr>
<font face="Tahoma" size="2"><b>From:</b> <a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>
[mailto:<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>] <b>On Behalf Of </b>Steven
Williams<br><b>Sent:</b> 23 April 2008 09:07<br><b>To:</b> Rules Users
List<br><b>Subject:</b> Re: [rules-users] Re: Is this scenario suitable for
using Drools?<br></font><br></div><div><div></div><div class="Wj3C7c">
<div></div>change DBUtils to return a Collection and it should work I
think.<br><br>
<div class="gmail_quote">On Wed, Apr 23, 2008 at 5:50 PM, Anstis, Michael (M.)
<<a href="mailto:manstis1@ford.com" target="_blank">manstis1@ford.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" 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><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2">package com.sample</font></span></div>
<div><font color="#0000ff" face="Courier New" size="2"></font> </div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2">global com.sample.DBUtils dbutils;<br></font></span></div>
<div dir="ltr" align="left"><span></span><span><font color="#0000ff" face="Courier New" size="2">rule "a1"<br>
when</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2"> $max : Integer() from
accumulate( Integer( $v : intValue ) from dbutils.getNumbers(), max($v)
)</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2"> then<br></font></span><span><font color="#0000ff" face="Courier New" size="2">
System.out.println($max);</font></span></div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Courier New" size="2">end </font></span></div>
<div><font color="#0000ff" face="Arial" size="2"></font><font color="#0000ff" face="Arial" size="2"></font><font color="#0000ff" face="Courier New" size="2"></font> </div>
<div><font color="#0000ff" face="Courier New" size="2"></font> </div>
<div><font color="#0000ff" face="Courier New" size="2">public class DBUtils
{</font></div>
<div><font color="#0000ff" face="Arial" size="2"></font> </div>
<div><font color="#0000ff" face="Courier New" size="2"> public
Integer[] getNumbers() {</font></div>
<div><font color="#0000ff" face="Arial" size="2"></font> </div>
<div><font color="#0000ff" face="Courier New" size="2"> Integer[] numbers = new
Integer[10];<br> for (int i = 0; i
< numbers.length; i++)
{<br>
numbers[i] = (int) <span>(</span>Math.random() *
100<span>)</span>;<br>
}<br> return
numbers;<br> }<br>}</font></div>
<div><font color="#0000ff" face="Arial" size="2"></font> </div>
<div><span></span><font face="Arial"><font color="#0000ff"><font size="2">H<span>owever this led to some
errors:-</span></font></font></font></div>
<div><font face="Arial"><font color="#0000ff"><font size="2"><span></span></font></font></font> </div>
<div><font size="-0"><font color="#0000ff"><font face="Courier New" size="2"><span>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></span><font face="Arial"><font color="#0000ff"><font size="2">H<span>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></span></font></font></font> </div>
<div><font face="Arial"><font color="#0000ff"><font size="2"><span>Cheers,</span></font></font></font></div>
<div><font face="Arial"><font color="#0000ff"><font size="2"><span></span></font></font></font> </div>
<div><font face="Arial"><font color="#0000ff"><font size="2"><span>Mike</span></font></font></font></div>
<div><font color="#0000ff" face="Arial" size="2"></font><font color="#0000ff" face="Arial" size="2"></font><font color="#0000ff" face="Arial" size="2"></font><br></div>
<blockquote style="margin-right: 0px;">
<div dir="ltr" align="left" lang="en-us">
<hr>
<font face="Tahoma" size="2"><b>From:</b> <a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a> [mailto:<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>] <b>On Behalf Of
</b>Cheng Wei Lee<br><b>Sent:</b> 22 April 2008 17:27<br><b>To:</b> <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br><b>Subject:</b>
[rules-users] Re: Is this scenario suitable for using
Drools?<br></font><br></div>
<div>
<div></div>
<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></div></div></blockquote></div><br>_______________________________________________<br>rules-users
mailing list<br><a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Steven Williams<br><br>Supervising
Consultant<br><br>Object Consulting<br>Office: 8615 4500 Mob: 0439 898 668
Fax: 8615 4501<br><a href="mailto:steven.williams@objectconsulting.com.au" target="_blank">steven.williams@objectconsulting.com.au</a><br><a href="http://www.objectconsulting.com.au" target="_blank">www.objectconsulting.com.au</a><br>
<br>consulting
| development | training | support<br>our experience makes the difference
</div></div></blockquote></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>