Easy mistake...
by Willem van Asperen
Hi All,
Just wanted to share with you an easy mistake. This is done running
Drools 5.5.0.Final.
Imagine a fact
|Cheese (||
|| creationTick : double||
|| preservationTicks : double||
||)|
Then the following does not do what you expect:
|rule "dump old cheese"||
|| when||
|| $c : Cheese( $sbd : creationTick + preservationTicks )||
|| CurrentTime( tick >= $sbd )||
|| then||
|| System.out.println("||we have to dump "+$c);||
||end|
You would expect that $c is dumped when current time has passed
creationTick + preservationTicks. But no. The variable $sbd is bound to
creationTick /before/ the preservationTicks are added!! I must say that
I do not quite understand how ($sbd : creationTick) + preservationTicks
resolves to "true" to make the premise succeed... Maybe because it is != 0?
I found that it should be:
|rule "dump old cheese"||
|| when||
|| $c : Cheese( $sbd : (creationTick + preservationTicks) )||
|| CurrentTime( tick >= $sbd )||
|| then||
|| System.out.println("we have to dump "+$c);||
||end|
This makes sense. Now $sbd is bound to the result of the addition. But
it is an easy trap!!
Regards,
Willem
11 years, 9 months
[Bug] 5.5.0 Correctly compiled DRL runs into run time error: "incompatible types"
by Wolfgang Laun
Below is a fully self-contained DRL that compiles correctly but runs
into a runtime error when the LHS of rule "match" is evaluated. The
"culprit" is the test "this != $c", but one would expect simply a true
result from the comparison.
declare Person
name: String
end
declare Customer
extends Person
rating: int
end
declare Employee
extends Person
wage: int
end
rule initphone
salience 100
when
then
insert( new Customer( "Joe", 100 ) );
insert( new Employee( "Paul", 2100 ) );
end
rule match
when
$c: Customer()
$e: Employee( this != $c )
then
System.out.println( "c/e " + $c + " " + $e );
end
Exception in thread "main" Exception executing consequence for rule
"initphone" in express: [Error: incompatible types in statement: class
express.Customer (compared from: class express.Employee)]
[Near : {... this != $c ....}]
^
[Line: 1, Column: 1]
at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
at express.Main.execute(Main.java:92)
at express.Main.main(Main.java:126)
Caused by: [Error: incompatible types in statement: class
express.Customer (compared from: class express.Employee)]
[Near : {... this != $c ....}]
^
[Line: 1, Column: 1]
at org.mvel2.ast.BinaryOperation.<init>(BinaryOperation.java:84)
at org.mvel2.util.CompilerTools.finalizePayload(CompilerTools.java:118)
at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:287)
at org.mvel2.compiler.ExpressionCompiler.compile(ExpressionCompiler.java:62)
at org.mvel2.MVEL.compileExpression(MVEL.java:810)
at org.drools.base.mvel.MVELCompilationUnit.compile(MVELCompilationUnit.java:435)
at org.drools.base.mvel.MVELCompilationUnit.getCompiledExpression(MVELCompilationUnit.java:238)
at org.drools.rule.constraint.MvelConstraint.createMvelConditionEvaluator(MvelConstraint.java:206)
at org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:190)
at org.drools.rule.constraint.MvelConstraint.isAllowedCachedRight(MvelConstraint.java:184)
at org.drools.common.SingleBetaConstraints.isAllowedCachedRight(SingleBetaConstraints.java:134)
at org.drools.reteoo.JoinNode.propagateFromRight(JoinNode.java:156)
at org.drools.reteoo.JoinNode.assertObject(JoinNode.java:148)
at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:59)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:235)
at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:240)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:350)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:311)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:903)
at org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:192)
at org.drools.base.DefaultKnowledgeHelper.insert(DefaultKnowledgeHelper.java:186)
at express.Rule_initphone_aea184dfceb14326841c37daadabfdbc.defaultConsequence(Rule_initphone_aea184dfceb14326841c37daadabfdbc.java:8)
at express.Rule_initphone_aea184dfceb14326841c37daadabfdbcDefaultConsequenceInvokerGenerated.evaluate(Unknown
Source)
at express.Rule_initphone_aea184dfceb14326841c37daadabfdbcDefaultConsequenceInvoker.evaluate(Unknown
Source)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287)
... 7 more
11 years, 9 months
Delpoying Guvnor 5.5.0 on Tomcat 7.0.34 does not work
by oresch
I deployed the Tomcat Guvnor war (guvnor-5.5.0.Final-tomcat-6.0.war) and
renamed it to "guvnor". When I start the application I receive the following
error report:
java.lang.NullPointerException
org.jboss.seam.transaction.TransactionServletListener.requestInitialized(TransactionServletListener.java:106)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1822)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
java.lang.Thread.run(Thread.java:722)
Can anybody help? I have to admit that this is my first attempt to use
Guvnor Thank you in advance.
Olaf
--
View this message in context: http://drools.46999.n3.nabble.com/Delpoying-Guvnor-5-5-0-on-Tomcat-7-0-34...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 9 months
Guvnor Calendars
by Anton Nikulin
Hi
I have a problem with calendars in guvnor. I want to use calendars feature
in my rules and I've defined such rule in Guvnor:
rule "CalendarTest"
calendars "AUD Home Loans"
no-loop true
dialect "mvel"
when
then
System.out.println("CALENDAR IS WORKING!!!");
end
When in my application I consume ChangeSet.xml in which i specify recources
in binary format as PKG type, it always fires this rule even if there is no
calendar in session. However, if i defined sources in changeset in DRL
format, everything is ok.
Can you help me, why is it so?
Thanks, Anton
11 years, 9 months
Drools Planner 5.5.0.Final Memory corruption issues
by duggal
I am using Drools Planner for an optimization problem and facing weird memory
corruption issues.
The problem facts and planning entities are JPA entities which have lots of
relationships and are large in size.
When I use a few of the entities, then the solving works ok.
However when I use large number of these entities, then I get strange
exceptions indicating memory corruption in the result. E.g. the serialized
best solution (serialized by me for persistence purposes) appears to be have
invalid class types in members.
I see that there are the following exceptions in the log (for both small and
large data sets) -
Exception in thread "Thread-106" java.lang.RuntimeException: Unknown
accessor type:
org.mvel2.optimizers.impl.refl.collection.ArrayCreator@e7d1626d
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
org.drools.rule.constraint.ConditionAnalyzer.analyzeAccessor(ConditionAnalyzer.java:264)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
org.drools.rule.constraint.ConditionAnalyzer.analyzeNode(ConditionAnalyzer.java:250)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
org.drools.rule.constraint.ConditionAnalyzer.statementToExpression(ConditionAnalyzer.java:467)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
org.drools.rule.constraint.ConditionAnalyzer.readInvocationParams(ConditionAnalyzer.java:457)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
org.drools.rule.constraint.ConditionAnalyzer.analyzeAccessor(ConditionAnalyzer.java:345)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
org.drools.rule.constraint.ConditionAnalyzer.analyzeExpressionNode(ConditionAnalyzer.java:326)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
org.drools.rule.constraint.ConditionAnalyzer.analyzeAccessor(ConditionAnalyzer.java:286)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
org.drools.rule.constraint.ConditionAnalyzer.analyzeNode(ConditionAnalyzer.java:250)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
org.drools.rule.constraint.ConditionAnalyzer.analyzeSingleCondition(ConditionAnalyzer.java:133)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
org.drools.rule.constraint.ConditionAnalyzer.analyzeCondition(ConditionAnalyzer.java:99)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
org.drools.rule.constraint.ConditionAnalyzer.analyzeCondition(ConditionAnalyzer.java:70)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
org.drools.rule.constraint.MvelConditionEvaluator.getAnalyzedCondition(MvelConditionEvaluator.java:83)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
org.drools.rule.constraint.MvelConstraint.executeJitting(MvelConstraint.java:270)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
org.drools.rule.constraint.MvelConstraint.access$200(MvelConstraint.java:51)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
org.drools.rule.constraint.MvelConstraint$ConditionJitter.run(MvelConstraint.java:250)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
[2/12/13 12:35:34:309 IST] 00000174 SystemErr R at
java.lang.Thread.run(Thread.java:770)
Are these exceptions (which appear benign in the small data set solution)
causing my issue?
Are there any further troubleshooting that I can perform to isolate the root
cause?
Any help will be much appreciated. Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Planner-5-5-0-Final-Memory-corru...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 9 months
NullPointerException when using RuleAgent
by IPatel
Hi,
I have been trying to write the following code to automatically deploy any
changes made to the rules. However i am getting nullpointerexception errors.
I see many posts regarding this topic and have tried different options but
the error won;t go away.
public static void main(String[] args) {
try {
FileInputStream file = new
FileInputStream("C:\\Users\\folderabc\\workspace\\Drools
Sample\\bin\\Guvnor.properties");
Properties p = new Properties();
p.load(file);
RuleAgent agent = RuleAgent.newRuleAgent(p); *<-- this is where
it is failing* RuleBase rb = agent.getRuleBase();
WorkingMemory ksession = rb.newStatefulSession();
Car c = new Car("yellow", 2100);
Driver d = new Driver("Isha", 18, c, "lets try it" );
ksession.insert(d);
ksession.fireAllRules();
//logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
/Here are the errors i am getting on my console:/
java.lang.NullPointerException
at org.drools.agent.RuleAgent.refreshRuleBase(RuleAgent.java:384)
at org.drools.agent.RuleAgent.configure(RuleAgent.java:368)
at org.drools.agent.RuleAgent.init(RuleAgent.java:268)
at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:208)
at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:168)
at kijanowski.GuvnorTest.main(GuvnorTest.java:43)
Any help will be greatly appreciated. Thank you
--
View this message in context: http://drools.46999.n3.nabble.com/NullPointerException-when-using-RuleAge...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 9 months
Pattern order affects activation
by DOLECEK Ales
Hello,
I have following rule:
rule "Remove unsued phones"
when
exists Customer()
not Customer(phone == $value)
$unused: Phone($value: value)
then
retract($unused);
end
There might be multiple Customer and Phone facts in the working memory and the purpose of the rule is to remove phones that do not belong to any of the customers. The rule should not be activated while there are no Customers in WM - hence the "exists Customer()". This is becaus there are other rules, taht might use the phones to lookup customers.
There Phone with value = "test" in working memory when Customer with phone = "test" is inserted. BTW: Both facts are immutable.
The behavior differs depending on order of the 3 patterns in the LHS of the rule.
1) If the "exists Customer()" is first activation is created
- this is wrong since the "exists Customer()" shall be false
2) if I move the "exists Customer()" between the other patterns activation is created and immediatelly canceled
- this is also wrong since, although in my case (where are no side effects) it works
3) Finally if the "exists Customer()" comes last the then activation is not created at all
- this is correct
Is this bug or am I missing something important about rule language? Rewriting the LHS with expicit infix and does not help:
(exists Customer()) and
(not Customer(phone == $value)) and
($unused: Phone($value: value))
Ales
FYI: I'm using 5.5.0.Final
11 years, 9 months