Optaplanner - Issue with real-time, chained and shadow variables
by Juan Ignacio Barisich
Hi everybody
I am using optaplanner in real-time style. My application domain is similar
to the "Vehicle Routing" example (
http://docs.jboss.org/drools/release/6.0.0.CR5/optaplanner-docs/html_sing...).
I mean, I am using chained variables and shadow variables. I have a problem
while trying to remove a fact (an entity), via a ProblemFactChange:
java.lang.IllegalArgumentException: The entity instance (...) was never
added to this ScoreDirector. Usually the cause is that that specific
instance was not in your Solution's entities.
The fact removing that I made is like:
solver.addProblemFactChange(new ProblemFactChange() {
@Override
public void doChange(ScoreDirector scoreDirector) {
...
scoreDirector.beforeEntityRemoved(toRemove);
workingSolution.getCustomerList().remove(toRemove);
scoreDirector.afterEntityRemoved(toRemove);
}
});
I think the problem is there. Do you know what I'm doing wrong?
I have attached a test case based on the "Vehicle Routing". To run it, just
put that file into the
optaplanner-distribution-6.0.0.CR5/examples/sources/src/test/java/org/optaplanner/examples/vehiclerouting/app/
directory.
<http://drools.46999.n3.nabble.com/file/n4017760/serverlog.zip>I'd
appreciate any ideas on how to resolve this.
Best regards,
Juan Ignacio Barisich
11 years
5.6.0.CR1 causes exceptions
by Jonathan Knehr
Just upgraded to the release candidate. I was using my own version of 5.6 that I had compiled a few months ago and everything was working fine.
Almost every single rule file now throws this exception when it gets added to the knowledge base.
java.lang.NoSuchMethodError: org.drools.base.ClassFieldReader.hasReadAccessor()Z
at org.drools.base.ClassFieldAccessorStore.getReader(ClassFieldAccessorStore.java:129)
at org.drools.base.ClassFieldAccessorStore.getReader(ClassFieldAccessorStore.java:104)
at org.drools.rule.builder.PatternBuilder.getFieldReadAccessor(PatternBuilder.java:1572)
at org.drools.rule.builder.PatternBuilder.buildRuleBindings(PatternBuilder.java:1123)
at org.drools.rule.builder.PatternBuilder.buildCcdDescr(PatternBuilder.java:691)
at org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:651)
at org.drools.rule.builder.PatternBuilder.processConstraintsAndBinds(PatternBuilder.java:505)
at org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:322)
at org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:133)
at org.drools.rule.builder.GroupElementBuilder.build(GroupElementBuilder.java:67)
at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:85)
at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:3169)
at org.drools.compiler.PackageBuilder.compileRules(PackageBuilder.java:1036)
at org.drools.compiler.PackageBuilder.compileAllRules(PackageBuilder.java:944)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:936)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:468)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:698)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40)
Sent from my iPhone
11 years
Data enumeration in Guvnor
by nkhogen
In advanced data enumeration in Guvnor, it is possible to define list of
values for a given condition.
Like
ZipCode, field1 = "55000", field2 = ['1','2','3'], field1 = "55000", field2
= ['1','2','3']
ZipCode, field1 = "66600", field2 = ['10','20','30']
But if I have something like
ZipCode, field1 = "OTHER", field2 value should not be bound. I should be
able to fill anything. But, Guvnor does not allow me once field1 is bound to
something else.
Please let me know if anyone has had this issue before.
--
View this message in context: http://drools.46999.n3.nabble.com/Data-enumeration-in-Guvnor-tp4026631.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years
[drools-fusion] Detecting a Trend in Data
by code4dc
Hey guys,
I am trying to come up with a way to get Drools to detect a trend in a
dataset. The data is very basic and looks something like this:
(each row represents an object in the WM)
Time Value
10:00 1
11:00 2
12:00 3
01:00 1
02:00 3
04:00 4
05:00 5
06:00 3
I want to set up a rule that detects when there is an upward trend in the
value for 3(configurable) or more consecutive data points.
It's easy to set up a rule to detect when there is a two consecutive rows
and the 2nd one has a higher value. But how can I set up a rule to detect
when there are multiple consecutive rows each with a higher value than the
previous one?
Any ideas are welcome(even if they are not complete!).
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/drools-fusion-Detecting-a-Trend-in-Data...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years
[OptaPlanner] Help on Construction Heuristics
by Tales Costa
Hi all,
I am new to Optaplanner and would like some help on understanding how to
control the planning value chosen by Optaplanner.
Based on the info on User Guide and the NQueen example, I understand that
for Local Search algorithms one can use the Move interface (for example
to forbid some specific row change).
However, for the Construction heuristics have not found any similar
option. For these algoritms the only option seems to be to make load
adjustements on the score calculations (as the nqueens example does for
queens on the same row). Is this correct or am I missing something ?
Regards
Tales
11 years
Ask for help with OptaPlanner
by Xi Gong
Hi Folks,
I am new to OptaPlanner, so please forgive me if this is a stupid question.
I developed a project to solve a worker assignment problem based on
OptaPlanner. I have a java class "Demand" which has the information of
capacity needed for each shift.
I added it to the solution class as a problem fact, since it should never
be changed. Then I wrote rules saying that when the supply on that shift
can not satisfy the demand there will be a point loss.
The problem I met is that when stepping into local search phase, the solver
can not access to this class.
For instance, I have the following rule:
rule " test rule"
when
$s : Shift($i : index)
$d : Demand(shift.getIndex() == $i)
then
System.out.println("Test rule fired.");
end
>From console log I observed that at local search phase this rule was never
fired.
Does anyone have any thoughts on why this happened and how I should solve
this problem? I will appreciate your help.
Thanks,
11 years
peephole technique -> cast to java.lang.Number problem
by Alexander Wolf
Drools 5.5.0 + Fusion / stateful session / STREAM mode
Hi,
I try to improve my rules using peephole technique (Thanks @W)
I think I got it right, but now I am stuck with a problem.
I want to keep a reference to my latest inserted event. Problem: the rule "print old" gives me an Exception (see below).
I think the peephole itself works pretty well, but somehow my Event Object (POJO with: Date timestamp, int value) is making problems when I try to use "before". (see marked line, when commenting it out, the rules run alright)
dialect "mvel"
import java.util.Date
import com.testmodel.Event
//declarations
declare Event
@role(event)
@timestamp( timestamp )
end
declare LastEvent
event: Event
end
rule "init"
when
//once...
then
System.out.println("init");
LastEvent l = new LastEvent();
Event e = new Event();
e.timestamp = new Date();
e.value = 0;
l.event = e;
insert(l);
end
rule "update LastEvent"
no-loop
salience 99
when
$event : Event()
$last : LastEvent()
then
System.out.println("update LastEvent");
retract ($last)
LastEvent l = new LastEvent();
l.event = $event;
insert(l);
end
rule "count old"
when
LastEvent($last : event)
$old : Event(this before [0 , 5s] $last) //<<<<<<<<<< THIS IS EVIL?!
then
System.out.println($old);
end
My test code looks like this:
Event event = new Event(new Date(), 1);
ksession.insert(event);
ksession.fireAllRules();
//sleep 1+ sec
Thread.sleep(1001);
Event event2 = new Event(new Date(), 2);
ksession.insert(event2);
ksession.fireAllRules();
And this is the Exception I get:
Exception executing consequence for rule "init" in testEasierLife: [Error: drools.insert(l): com.testmodel.Event cannot be cast to java.lang.Number]
[Near : {... System.out.println("init"); ....}]
^
[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 com.Test.test(PeepholeTest.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: [Error: drools.insert(l): com.testmodel.Event cannot be cast to java.lang.Number]
[Near : {... System.out.println("init"); ....}]
^
[Line: 1, Column: 1]
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:416)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:143)
at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113)
at org.mvel2.MVEL.executeExpression(MVEL.java:930)
at org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:104)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287)
... 29 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1104)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:987)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:377)
... 39 more
Caused by: java.lang.ClassCastException: com.testmodel.Event cannot be cast to java.lang.Number
at org.drools.base.evaluators.BeforeEvaluatorDefinition$BeforeEvaluator.evaluateCachedLeft(BeforeEvaluatorDefinition.java:337)
at org.drools.rule.constraint.EvaluatorConstraint.isAllowedCachedLeft(EvaluatorConstraint.java:67)
at org.drools.common.SingleBetaConstraints.isAllowedCachedLeft(SingleBetaConstraints.java:125)
at org.drools.reteoo.JoinNode.propagateFromLeft(JoinNode.java:105)
at org.drools.reteoo.JoinNode.assertLeftTuple(JoinNode.java:95)
at org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:196)
at org.drools.reteoo.SingleLeftTupleSinkAdapter.createAndPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:145)
at org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:154)
at org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:497)
at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:382)
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)
... 46 more
11 years
Drools fusion logic
by Elran Dvir
Hi all,
I am using Drools Fusion in stream mode.
Let's assume I have a very simple rule:
rule "Simple"
enabled true
dialect "java"
no-loop
when
$myEvent : MyEvent()
then
System.out.println($myEvent.toString());
end
1. When will the rule be fired? If there is a "MyEvent" in working memory? Or only if a new "MyEvent" was inserted since last activation?
2. Will the rule be activated for each compatible (as answered in q1) "MyEvent"? or for just one arbitrary "MyEvent"?
3. What if my LHS was "$myEvent : MyEvent() over window:time(60s)"? Were the answers for q2 and q3 different?
Thanks.
11 years
Re: [rules-users] multiple expiration definitions for the same face type in different drl files
by Elran Dvir
Can someone please answer my question?
Thanks.
From: Elran Dvir
Sent: Tuesday, October 22, 2013 3:35 PM
To: rules-users(a)lists.jboss.org
Subject: multiple expiration definitions for the same face type in different drl files
Hi all,
I am examining Drools Fusion in stream mode.
This is my case:
I have several drl files.
Each drl file contains one rule.
Each drl file is built to a knowledge package.
Each drl file contains declaration of the same fact (referencing to a imported class defined outside of the drl). The fact's role is of course event.
Can I define different expiration (@expires) for the fact in each drl?
Is expiration relevant only to the same drl?
Is the answer different if the fact is created in the rule's RHS or if it inserted to the session's working memory outside of the drl?
Thanks.
11 years
News from the community - 5.6.0.CR1 is out!
by Davide Sottara
Finally Drools 5.6.0.CR1 community edition has been released!
It has been mainly a community effort, driven by the use of Drools in
several applications and research projects,
but it was possible thanks to the collaboration of the main developer's
team and the help of everybody
who reported bugs, asked for new features and contributed with patches
or additions.
5.6 consolidates and finalizes the 5.x series. It comes with a number of
bug fixes and a still experimental,
but much more robust, second generation trait system - I will blog and
document it as soon as I can find
a moment next week.
The release is "candidate" to allow for some broader testing by the
community without requiring to download
and compile the code. If no major issues are reported, it will become
Final in a few weeks.
Let's keep sharing, looking forward to even more exciting innovations in
the 6.x series!
Best
Davide
11 years