[rules-users] Re: Is this scenario suitable for using Drools?
Anstis, Michael (M.)
manstis1 at ford.com
Wed Apr 23 03:50:57 EDT 2008
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:-
package com.sample
global com.sample.DBUtils dbutils;
rule "a1"
when
$max : Integer() from accumulate( Integer( $v : intValue ) from
dbutils.getNumbers(), max($v) )
then
System.out.println($max);
end
public class DBUtils {
public Integer[] getNumbers() {
Integer[] numbers = new Integer[10];
for (int i = 0; i < numbers.length; i++) {
numbers[i] = (int) (Math.random() * 100);
}
return numbers;
}
}
However this led to some errors:-
org.drools.RuntimeDroolsException: java.lang.ClassCastException:
[Ljava.lang.Integer; incompatible with java.lang.Integer
at org.drools.rule.Accumulate.accumulate(Accumulate.java:131)
at org.drools.reteoo.AccumulateNode.assertTuple(AccumulateNode.java:127)
at
org.drools.reteoo.CompositeTupleSinkAdapter.createAndPropagateAssertTuple(Co
mpositeTupleSinkAdapter.java:73)
at
org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.jav
a:116)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObject
SinkAdapter.java:22)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:153)
at org.drools.reteoo.Rete.assertObject(Rete.java:177)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:192)
at
org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute(
ReteooWorkingMemory.java:179)
at
org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorking
Memory.java:1292)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:89
1)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:85
8)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:65
9)
at com.sample.DroolsTest.main(DroolsTest.java:36)
Caused by: java.lang.ClassCastException: [Ljava.lang.Integer; incompatible
with java.lang.Integer
at org.drools.base.java.lang.Integer968047027$intValue.getIntValue(Unknown
Source)
at
org.drools.base.ClassFieldExtractor.getIntValue(ClassFieldExtractor.java:197
)
at org.drools.rule.Declaration.getIntValue(Declaration.java:230)
at
com.sample.Rule_a1_0AccumulateExpression0Invoker.evaluate(Rule_a1_0Accumulat
eExpression0Invoker.java:16)
at
org.drools.base.accumulators.JavaAccumulatorFunctionExecutor.accumulate(Java
AccumulatorFunctionExecutor.java:74)
at org.drools.rule.Accumulate.accumulate(Accumulate.java:123)
... 13 more
Have I done something really stupid and is Drools a fit?
Cheers,
Mike
_____
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Cheng Wei Lee
Sent: 22 April 2008 17:27
To: rules-users at lists.jboss.org
Subject: [rules-users] Re: Is this scenario suitable for using Drools?
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:
Algorithm 1:
Cost = MAX(P1, T1, P2, T2, P3, T3, ...)
Algorithm 2:
Cost = MIN(P1, P2, P3, ...) + MIN(T1, T2, T3, ...)
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?
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20080423/08a44276/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 7206 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20080423/08a44276/attachment.bin
More information about the rules-users
mailing list