Stateless session with pre-inserted facts
by Chris Selwyn
I have a need to execute a set of rules on a complicated hierarchical data structure where some of the rules use a bunch of reference facts.
At the moment I load the reference facts and the hierarchical structure into the WM of a stateless session on every execution.
There are a lot of reference facts and they start off in the same state on every execution though they can get modified as part of the rules execution.
I would really like to be able to save the WM after inserting the reference facts so that I can start each execution with those facts pre-loaded and thereby avoid loading them each time.
Is this an easy thing to do? Could someone give me some pointers?
Chris
12 years, 2 months
Inserting String Object and accessing it in Guvnor
by Manasi
Hi,
Currently in my application I want to insert a *String object* into a
StatefulKnowledgeSession.
I don't want to insert object of any *User defined type* ,as input parameter
contains only one string parameter.
I am able to insert String object into my StatefulKnowledgeSession, but
don't know how to access it in Guvnor , as I want to use value from this
string object to satisfy one of the rule in my Guvnor decision table. I want
to use this String object as one of the condition columns in Guvnor.
Below is some code I am using:
StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();
String myString = new String("department");
session.insert(myString);
session.fireAllRules();
Is there any way to access this String object in Guvnor?
Thanks,
Manasi.
--
View this message in context: http://drools.46999.n3.nabble.com/Inserting-String-Object-and-accessing-i...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
function in drools
by thano
HI,
I am new to drools. I would like to know if it is possible to define a
function in drools or something similar. For example, Rule 1 would call
another rule say Rule 2 and pass some parameters to be analysed with in Rule
2. I need to know if this can be achieved purely in drools.
many thanks
--
View this message in context: http://drools.46999.n3.nabble.com/function-in-drools-tp4020021.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
Does JIT give me a hard time?
by wasperen
Hi,
I have been using Drools for some years now and really happy with it!
But I am struggling now with the 5.4 version. It seems that the JIT compiler
does not like me. For example, I have a rule that says:
rule "activate operations, for operator"
when
$worker : VCMShiftWorker( selectQuery == "operatorSelect" )
$ea : ExecutableAction(
action.subject.parentActionable != null,
$worker.isUnderManagement( action.subject.parentActionable )
)
not RelevantExecutableAction(
$worker;
executableAction != $ea,
executableAction.priority > $ea.priority ||
(executableAction.priority == $ea.priority && executableAction.workTime >
$ea.workTime) ||
(executableAction.priority == $ea.priority && executableAction.workTime
== $workTime && $critical && ! executableAction.critical)
)
then
System.out.println($worker+" makes relevant :"+$ea);
insert( new RelevantExecutableAction( $worker, $ea ) );
end
When I run this, I get a Thread that tell me there is a NPE because $ea is
null... So I had to re-write that same rule as
rule "activate operations, for operator"
when
$worker : VCMShiftWorker( selectQuery == "operatorSelect" )
$ea : ExecutableAction(
$prio : priority,
$workTime : workTime,
$critical : critical,
action.subject.parentActionable != null,
$worker.isUnderManagement( action.subject.parentActionable )
)
not RelevantExecutableAction(
$worker;
executableAction != $ea,
executableAction.priority > $priority ||
(executableAction.priority == $priority &&
executableAction.workTime.compareTo($workTime) > 0) ||
(executableAction.priority == $priority && executableAction.workTime ==
$workTime && $critical && ! executableAction.critical)
)
then
System.out.println($worker+" makes relevant :"+$ea);
insert( new RelevantExecutableAction( $worker, $ea ) );
end
This works, but it's not nice.. And: why?
Also, I get errors like "java.lang.RuntimeException: Null accessor on node:
tick", again from these separate threads. I think this means that MVEL
cannot determine a getTick() from the fact that it should look at. In this
case, this.tick does also not work; same thing.
I tried to switch JIT off by adding the -Dmvel.disable.jit=true property to
the start-up, but that does not eliminate this issue.
A full stack-trace for the last error is as follows:
java.lang.RuntimeException: Null accessor on node: tick
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeNode(ConditionAnalyzer.java:229)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeNode(ConditionAnalyzer.java:162)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeSingleCondition(ConditionAnalyzer.java:109)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeCondition(ConditionAnalyzer.java:102)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeCombinedCondition(ConditionAnalyzer.java:134)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeCondition(ConditionAnalyzer.java:94)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeCondition(ConditionAnalyzer.java:73)
at
org.drools.rule.constraint.MvelConditionEvaluator.getAnalyzedCondition(MvelConditionEvaluator.java:83)
at
org.drools.rule.constraint.MvelConstraint.executeJitting(MvelConstraint.java:214)
at
org.drools.rule.constraint.MvelConstraint.access$000(MvelConstraint.java:41)
at org.drools.rule.constraint.MvelConstraint$1.run(MvelConstraint.java:201)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Another thing that fails to work in 5.4 is casting. For instance:
((Ship)mover).currentContainer does not compute. I get a Null accessor on
mover...
Should I worry about this at all? Or is it just bad luck this time and will
Drools just continue to process my rules?
To give you some context. We have built an agent based simulation engine,
where the agents are "Smart". They can interact, responding to the Actions
published by the agents in their environment by reasoning over them using
Drools rules. Works really nice but I am getting worried by these exceptions
now...
--
View this message in context: http://drools.46999.n3.nabble.com/Does-JIT-give-me-a-hard-time-tp4020032....
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
Planner: Hard Constraint Prevents Moves and Swaps
by Jason Virtue
All,
I have a problem where I need to assign tasks:
1.) Times
2.) Resources based on a Resource Type
I've used the nurse rostering problem as an example and come up with a
planning entity ResourceAssignment that looks like:
Facts:
Task
ResourceType
Variables:
Time
Resource
For example:
1.) Lets say there are two resource types Type1 & Type2
2.) A pool of resources: Resource1(type1), Resource2(type1),
Resource3(type1), Resource4(type2), Resource4(type2), Resource5(type2) ...
3.) Task A: that requires 1 resource of type1 and one resource of type2
My program creates two PlanningEntities
ResourceAssignment1
Fact:
Task=A
ResourceType=1
Variables
Time
Resource
ResourceAssignment2
Fact:
Task=A
ResourceType=2
Variables:
Time
Resource
I've created a rule that is designed to keep tasks starting at the same
time:
//tasks need to be in the same timeSlot
rule "taskInTimeSlot"
when
$ra1 : ResourceAssignment ( task != null, time != null, $id : id, $task :
task, $time : time)
$ra2 : ResourceAssignment ( task != null, timeSlot != null, id != $id, task
== $task, time != $time )
then
insertLogical(new IntConstraintOccurrence("taskInTimeSlot",
ConstraintType.NEGATIVE_HARD,
1,$ra1, $ra2));
end
*PROBLEM*
This results in: Cancelled step index (7), time spend (2848): there is no
doable move. Terminating phase early.
If I change the constraint to a NEGATIVE_SOFT the problem is solved, but it
doesn't scale. Any more that a few tasks and it doesn't seem to be able to
find solutions.
What I need is for swaps and moves to change the time on multiple
ResourceAssignments together.
Am I going about the problem the right way? Do I need something other than
the generic move/swap factories?
Thanks in advance,
Jason
12 years, 2 months
Drools Rule Evaluations are Inconsistent
by bdolbeare
Drools is not producing consistent results in the following example. If you
run the DRL shown below, you will see that rules 2 and 3 activate and log a
message. If you then comment out rule 3 in the DRL (you must put the entire
rule inside /* */ characters rather than simply disabling it), and rerun
it, you'll notice that rules 1 and 2 fire. How is it that the presence of
rule 3 affects whether or not rule 1 activates? These two rules are not
dependent in their DRL.
It appears to be related to the fact that rule 1 uses single quotes instead
of double quotes. If you change that, then Drools starts behaving
consistently. This makes me believe that the problem is somehow related to
how Drools is building the Rete tree with the single quotes.
With all three rules active I get:
[main]::INFO ::DroolsTest::test 3 hit on RecordA( id=100 ) - RecordB(
id=100, role=2 )
[main]::INFO ::DroolsTest::test 2 hit on RecordA( id=100 ) - RecordB(
id=100, role=1 )
With rule 3 commented out I get:
[main]::INFO ::DroolsTest::test 2 hit on RecordA( id=100 ) - RecordB(
id=100, role=1 )
[main]::INFO ::DroolsTest::test 1 hit on RecordA( id=100 ) - RecordB(
id=100, role=1 )
Interestingly, if you comment out rule 2 so only rules 1 and 3 are active,
rule 1 fires again:
[main]::INFO ::DroolsTest::test 3 hit on RecordA( id=100 ) - RecordB(
id=100, role=2 )
[main]::INFO ::DroolsTest::test 1 hit on RecordA( id=100 ) - RecordB(
id=100, role=1 )
*Environment: Drools 5.4.0*
package tests
import org.apache.log4j.Logger;
global Logger log
declare RecordA
id : long
end
declare RecordB
id : long
role : String
end
rule "insert data 1"
salience 99999
when
then
insert (new RecordA(100));
insert (new RecordB(100, "1"));
insert (new RecordB(100, "2"));
end
rule "test 1"
when
a : RecordA( )
b : RecordB( id == b.id, role == '1' )
then
log.info(String.format("%s hit on %s - %s", kcontext.getRule().getName(),
a, b));
end
rule "test 2"
when
a : RecordA( )
b : RecordB( id == b.id, role == "1" )
then
log.info(String.format("%s hit on %s - %s", kcontext.getRule().getName(),
a, b));
end
rule "test 3"
when
a : RecordA( )
b : RecordB( id == b.id, role == "2" )
then
log.info(String.format("%s hit on %s - %s", kcontext.getRule().getName(),
a, b));
end
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Rule-Evaluations-are-Inconsisten...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
how is Integer converted when comparing with primitive?
by mpgong
Hello
I have a rule that looks something like this
when
$mydate : TaskRowDate(0 < currentLateCount < 100)
then
doSomething();
My problem is that currentLateCount is an Integer type because i want to be
able to store null. 0 means something different in my app.
The problem is when a fact that is inserted with the currentLateCount =
null, the above rule matches and is fired.
Is this suppose to be the case and what value does currentLateCount take
that makes it match?
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/how-is-Integer-converted-when-comparing...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
Drools 5.4 final and jbpm: problem in acces process variable
by Manasi
Hi all,
I am newbie in drools and jbpm. I am getting problem in retrieving the
updated process variable value.
Here is the code:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(flowName),
ResourceType.BPMN2);
KnowledgeBase knowledgeBase= kbuilder.newKnowledgeBase();
StatefulKnowledgeSession ksession = knowledgeBase
.newStatefulKnowledgeSession();
// Retrieving request parameters
Map<String, Object> parameterMap = new HashMap<String, Object>();
parameterMap.put("screenId",screenId);
parameterMap.put("hello","abc");
ksession.startProcess("com.yousee.drools.services.DroolsAuthorizationService",
parameterMap);
ksession.fireAllRules();
I am passing parameter to the jbpm while starting the process for the
execution of flow.
Now if my process chnages this value. say process variable hello value to
"abcd".
How to get the updated variable value in java? wahts the api?
Plz help asap.
Regards
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-5-4-final-and-jbpm-problem-in-ac...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months