Drools planner & Scala
by Adam Warski
Hello,
I'm using Planner in a Scala program and it almost works without problems; the only one is in implementing the Solution interface, as it uses raw (erased) version of Score, which is normally generic (Score<S extends Score>). Scala generally doesn't like raw types and in most cases it's impossible to extend/implement interfaces which use them. A work-around is to introduce an "adapter" in Java, which you can later extend in Scala:
public abstract class ScalaSolution implements Solution {
public Score getScore() { return getScoreScala(); }
public abstract Score<?> getScoreScala();
public void setScore(Score score) { setScoreScala(score); }
public abstract void setScoreScala(Score<?> score);
}
and then in Scala:
class Schedule(...) extends ScalaSolution {
var score: Score[_] = _
def setScoreScala(score: Score[_]) = { this.score = score }
def getScoreScala = score
...
}
So the fix is to replace the raw Score type with Score<?>. Maybe it would be possible to apply that in the code? I tried it locally and it compiles without problems.
And a side question: do you have any plans on implementing multithreading in planner? So that several moves could be explored concurrently? I saw there's an open Jira issue for some time, but it didn't have any timeframe information.
--
Adam Warski
http://www.warski.org
http://www.softwaremill.eu
14 years, 1 month
Conflict detection problem
by AlisterC
Greetings,
I am working on a collaborative platform project which will contain datas,
informations and knowledges
such as buisness rules. Consequently, a rule engine is a requisite and I am
testing the Drools suite.
Because a lot of different people will be able to define rules, some
combinations might be contradictory.
So the rule user need to know which rules are in conflict, and eventually
choose the ones to disabled to fix the problem.
Here is my use case : I fill in a java class some information about a
people, his hame and his age, and I want to check if he is an adult.
Two different users have written a rule to check this. The first, living in
place where a 18 years old people is an adult wrote this rule :
___________________________________________
rule "Is Major"
when
$a : Applicant (age >= 18)
then
$a.setMajor( true );
end
___________________________________________
The second one, write this one :
___________________________________________
rule "Is Minor"
when
$a : Applicant (age < 21)
then
$a.setMajor( false );
end
___________________________________________
I've tried to solve this knowledge base with a 19 years old people, but no
conflict was detected.
In fact the rules are executed sequentially and the result depends of the
order the rules are called.
My use case is very simple, but I think I am not considering it correctly.
Or maybe it is impossible with forward chaining ?
Does anyone can help me to solve this problem, by telling what is wrong or
giving me some internet ressource link ?
Thanks a lot in advance.
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Conflict-detection-pr...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 1 month
Misunderstanding salience?
by Peter Ashford
Hi There
I'm new to drools. I've just set up the Drools-Server and it is (finally!) working and serving my test rule-set. The one thing that's not working as I expect it is the rule ordering via salience. This is my simple test rule set:
rule "General brain eating advice"
when
p : Patient(eatsBrains == true)
then
p.setAdvice("Stop eating brains, or at least, try to cut down");
end
rule "Zombie exception to brain eating advice"
salience -50
when
p : Patient(eatsBrains == true, isZombie == true)
then
p.setAdvice("Evidence suggests that the undead cannot contract Kuru or that the effects are irellevant given the " +
"patient's current zombified state.\nSuggest euthenasing patient lest he/she eat your (or someone " +
"else's) brains");
end
The idea is that the first rule fires all the time unless the patient happens to be a zombie, in which case the exception rule (the second rule) kicks in. Now, as I have it here, with the exception at salience at -50 it actually works, which is the opposite of what I was expecting. I'd thought that I would have had to have the exception at a higher salience to fire first. That was what I tried first but that didn't work - everyone got the general advice, zombies included.
What am I misunderstanding here?
Thanks!
Peter.
---
"It is very difficult to get a man to understand something when his tribal identity depends on his not understanding it" - Michael Bérubé on Republican climate change denial.
14 years, 1 month
OptionalDataException while running sample mortagage example
by Aditya
HI,
I had downloaded the drools 5.1 examples which is present in
http://www.jboss.org/drools/downloads.html url
and trying to run drools-examples-brms\ mortgage-example by following all
the steps listed in the how-to document But as RuleAgent is depricated I
changed it to KnowledgeAgent and used ChangeSet.xml to provide the URL and
authentication details
When I started running the application(FinalTest.java) I was getting the
followign error:
java.lang.RuntimeException: KnowledgeAgent exception while trying to
deserialize KnowledgeDefinitionsPackage
at
org.drools.agent.impl.KnowledgeAgentImpl.createPackageFromResource(KnowledgeAgentImpl.java:664)
at
org.drools.agent.impl.KnowledgeAgentImpl.addResourcesToKnowledgeBase(KnowledgeAgentImpl.java:889)
at
org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:704)
at
org.drools.agent.impl.KnowledgeAgentImpl.buildKnowledgeBase(KnowledgeAgentImpl.java:584)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:185)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:168)
at FinalTest.main(FinalTest.java:25)
Caused by: java.io.OptionalDataException
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at
org.drools.rule.JavaDialectRuntimeData.readExternal(JavaDialectRuntimeData.java:167)
The code used is as follows:
FinalTest.java:
/**
*
*/
import org.drools.KnowledgeBase;
import org.drools.agent.KnowledgeAgent;
import org.drools.agent.KnowledgeAgentFactory;
import org.drools.builder.ResourceType;
import org.drools.definition.type.FactType;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatelessKnowledgeSession;
/**
* @author aditya.madhav.k
*
*/
public class FinalTest {
/**
* @param args
*/
public static void main(String[] args) throws InstantiationException,
IllegalAccessException{
// TODO Auto-generated method stub
KnowledgeAgent ka = KnowledgeAgentFactory.newKnowledgeAgent("MyAgent");
ka.applyChangeSet(ResourceFactory.newClassPathResource("changeset.xml"));
KnowledgeBase kb = ka.getKnowledgeBase();
FactType appType = kb.getFactType("mortgages", "LoanApplication");
FactType incomeType = kb.getFactType("mortgages", "IncomeSource");
Object application = appType.newInstance();
Object income = incomeType.newInstance();
appType.set(application, "amount", 25000);
appType.set(application, "deposit", 1500);
appType.set(application, "lengthYears", 20);
incomeType.set(income, "type", "Job");
incomeType.set(income, "amount", 65000);
StatelessKnowledgeSession ks = kb.newStatelessKnowledgeSession();
ks.execute( new Object[] {application, income} );
}
}
and changeset.xml code is:
<?xml version="1.0" encoding="UTF-8" ?>
-
-
If anyone knows a solution for this kindly share the same
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/OptionalDataException...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 1 month
eval in DSL
by Saleem Lakhani
How do we get this done in Drools 5.2.1:
[when]Cov is not equal to "{value}" percent of Coverage A =
eval(math.calculatePercentages(covTO.getCoverage(), covTO.getD()) !=
{value})
This used to compile in Drools 3.
Thanks
saleem
14 years, 1 month
Infinite loop in rule condition matching
by Sartaj Shaik
Hi,
I have written some rules in Decision table (Web-guided editor), and I
have implemented the AgendaFilter to fire rules that ends with the rule
name specified (EndAgendaFilter)
here is the accept method I have written.
When I fire the rules ends with some "XXXXX", this accept method goes into
infinite loop and my Sysout prints "Rule 1 XXXXX" infinite times.
(Note: all the condition variables that i have passed to guvnor matches
with the first row of that rule, hence getting Rule 1 XXXXX)
public boolean accept(final Activation activation) {
System.out
.println(activation.getRule().getName());
if (activation.getRule().getName().endsWith(this.
suffix)) {
return this.accept;
} else {
return !this.accept;
}
}
All my other rules are working fine, even I have created the same rule
again (same conditions, actions, data etc) it is working properly.
Don't know what is the root cause, any ideas?
I have 3 similar rules which are failing, and those rules contains lot of
rows, so can't create the new rules for those again to make them work :(
Please help!!!
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you
14 years, 1 month
Guvnor and drools implementation - questions
by ioda100
Hi,
i have a few questions :
1) my facts are in fact java Maps, is there an easy way to deal with them in
guvnor? it's not like in the example where facts are objects and we give
guvnor the Pojo model to know what we can do with it
for example i have :
$m : Map((this["attribute1_of_the_map"] == "test1"))
How to deal with the map and have a prepopulated list of properties of the
map? And to store it in the variable $m. Without using the "free from drl"
where we have to write it by hand.
2) how to deal with global constant with guvnor?
i have something like :
WorkingMemory wm = drools.getWorkingMemory();
wm.setGlobal("resultValue", "OK");
Is it a direct way to play with global constant in Guvnor? Without using the
"free from drl" where we have to write it by hand.
3) for stopping firing rules after one rule fire successfully, do you know
if there is an option to do that?
For now i insert a boolean in the session and the first condition in all my
rules is that this boolean is there. When a rule fires successfully, i
retract it. I suppose there is a bettre way to do it?
Thanks in advance for your help
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Guvnor-and-drools-imp...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 1 month
EvalConditionNode cannot be cast to org.drools.reteoo.RightTupleSink
by nanic23
We are seeing this exception when trying to complete flows in wait state.
This happens after we deploy a newer release of our application.
Context:
1. we start several process that go to wait state
2. we make bug fixes to our application and deploy a new version
3. we try to resume the existing flows that are in wait state.
4. we get this exceptions when trying to load existing session
NOTE: drools version is the same so I don't think this is a serialization
incompatibility issue.
Exception:
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedConstructorAccessor622.newInstance(Unknown Source)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at
org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:95)
... 202 more
Caused by: java.lang.RuntimeException: Unable to load session snapshot
at
org.drools.persistence.session.JPASessionMarshallingHelper.loadSnapshot(JPASessionMarshallingHelper.java:96)
at
org.drools.persistence.session.SingleSessionCommandService.initKsession(SingleSessionCommandService.java:202)
at
org.drools.persistence.session.SingleSessionCommandService.(SingleSessionCommandService.java:165)
... 206 more
Caused by: java.lang.ClassCastException: org.drools.reteoo.EvalConditionNode
cannot be cast to org.drools.reteoo.RightTupleSink
at
org.drools.marshalling.impl.InputMarshaller.readRightTuple(InputMarshaller.java:401)
at
org.drools.marshalling.impl.InputMarshaller.readRightTuples(InputMarshaller.java:391)
at
org.drools.marshalling.impl.InputMarshaller.readFactHandles(InputMarshaller.java:326)
at
org.drools.marshalling.impl.InputMarshaller.readSession(InputMarshaller.java:205)
at
org.drools.marshalling.impl.DefaultMarshaller.unmarshall(DefaultMarshaller.java:91)
at
org.drools.persistence.session.JPASessionMarshallingHelper.loadSnapshot(JPASessionMarshallingHelper.java:91)
... 208 more
Thanks,
Nick
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/EvalConditionNode-can...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 1 month
Drools command line interface
by Diego López León
Hi ppl,
in my spare time I've been working on a tool that may be of interest
to some of you.
I call it Drools Shell.
"The aim of this project is to provide a simple command line interface
to test rules allowing you to insert, modify and retract facts. You
also have commands to query the state of the stateful knowledge
session running behind the shell." (quoted from README.md)
You can clone it from github
https://github.com/diega/drools-shell
Take a look at the fancy readme below that page. If you'd like to
help, there are some items already loaded in the issues section.
Any feedback is welcome :)
--
diego
14 years, 1 month