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(CompositeTupleSinkAdapter.java:73)
at
org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:116)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.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(AbstractWorkingMemory.java:1292)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:891)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:858)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:659)
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_0AccumulateExpression0Invoker.java:16)
at
org.drools.base.accumulators.JavaAccumulatorFunctionExecutor.accumulate(JavaAccumulatorFunctionExecutor.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
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!