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.
13 years, 9 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
13 years, 9 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.
13 years, 9 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.
13 years, 9 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.
13 years, 9 months
Reloading knowledge base from another thread
by gkalabin
Hi everybody!
I'm using Drools 5.4.0.Final.
I'm checking changes in knowledge repository and if there is any - update
knowledge base.
The changes listening I perform like described in article:
https://community.jboss.org/wiki/PublishDroolsArtifactsFromAProductionEnv....
Updating knowledge base code:
private static final Environment JBPM_ENVIRONMENT =
KnowledgeBaseFactory.newEnvironment();
private static final KnowledgeSessionConfiguration JBPM_CONFIG;
static {
JBPM_ENVIRONMENT.set(EnvironmentName.ENTITY_MANAGER_FACTORY,
Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa"));
JBPM_ENVIRONMENT.set(EnvironmentName.TRANSACTION_MANAGER,
TransactionManagerServices.getTransactionManager());
JBPM_ENVIRONMENT.set(EnvironmentName.GLOBALS, new
MapGlobalResolver());
Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory",
"org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory",
"org.jbpm.persistence.processinstance.JPASignalManagerFactory");
JBPM_CONFIG =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);
}
....
private static StatefulKnowledgeSession createSession() {
StatefulKnowledgeSession session =
JPAKnowledgeService.newStatefulKnowledgeSession(readKnowledgeBase(),
JBPM_CONFIG, JBPM_ENVIRONMENT);
session.getWorkItemManager().registerWorkItemHandler("Human Task",
new CommandBasedWSHumanTaskHandler(session));
return session;
}
When I load changes from main thread (on startup, for example) everything is
fine, but when I try to reload knowledge base from another thread it falls
with exception ( full stacktrace
<http://drools.46999.n3.nabble.com/file/n4020008/error_log.txt> ):
15:00:56,420 ERROR [org.drools.persistence.SingleSessionCommandService]
(Timer-14) Could not commit session: java.lang.NullPointerException
at
org.drools.persistence.jta.JtaTransactionManager.getStatus(JtaTransactionManager.java:205)
[drools-persistence-jpa-5.4.0.Final.jar:5.4.0.Final]
How can I solve it?
Thank you for your attention. Have a good day!
--
View this message in context: http://drools.46999.n3.nabble.com/Reloading-knowledge-base-from-another-t...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
How to integrate Drools application with Servlet
by zeeshan
Hi All !
I have an existing web application "Bonus Calculation Management System"
which has been developed in servlet and Hibernate which is interacting with
DB. I have developed a product in Drools using Struts. Now the task is I
have to integrate this drools product in the Existing Servlet application. I
have integrating it converting Struts to Servlet. But it is giving this
exception about my Rule File :
*
com.drools.action.PolicyAction
hurrrrrrrrrrrrrr
java.io.FileNotFoundException: Cannot find rule file:Sample.drl
at com.drools.facts.RuleRunner.loadRuleFile(RuleRunner.java:89)
at com.drools.facts.RuleRunner.loadRules(RuleRunner.java:67)
at com.drools.facts.RuleRunner.getStatefulSession(RuleRunner.java:227)
at com.drools.facts.RuleMain.main(RuleMain.java:46)*
*In my Servlet class I have written like this :* public int
calculate(HttpServletRequest req, String schId,String schStepID, Date
clcFrDate, Date clcToDate,String runNo)
{
System.out.println("hurrrrrrrrrrrrrr");
InputFormBean inputFormBean=new InputFormBean();
inputFormBean.setFromDate(clcFrDate.toString());
inputFormBean.setToDate(clcToDate.toString());
String fromDateArray[]=inputFormBean.getFromDate().trim().split("/");
String toDateArray[]=inputFormBean.getToDate().trim().split("/");
inputFormBean.setFromDateArray(fromDateArray);
inputFormBean.setToDateArray(toDateArray);
RuleMain ruleMain=new RuleMain();
try {
ruleMain.main(inputFormBean);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
*In the RuleMain.java* : public class RuleMain extends HttpServlet {
private final String[] RULES_FILES8 = new String[] {"Sample.drl"}; // *I
also tried : com.drools.rules/Sample.drl but dint work*
static HashMap<Integer, Double>agntAPEMap=new HashMap<Integer, Double>();
public void main(InputFormBean inputFormBean) throws Exception {
HashMap<String, Object> globals = new HashMap<String, Object>();
//globals.put("index", new Index(0));
StatefulSession statefulSession=new
RuleRunner().getStatefulSession(RULES_FILES8,null,null, globals, null);
......
........
Thanks !!!
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-integrate-Drools-application-wit...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months
Planner: Vehicle Routing, but with return to home after last delivery
by jimirn
Hi all,
I have changed the Vehicle Routing example to suit my domain model.
My domain is:
- Consultant (the person that will drive to a DeliveryPlace and spent some
time there, each Consultant has a max total time available, implements
Appearance)
- DeliveryPlace (the place where a Consultant will drive to and spent some
time making a delivery, implements Appearance)
- Location (a Consultant has a home and a DeliveryPlace has a location)
I need the soft constraints to take into account returning from last
DeliveryPlace to the home location of the Consultant.
But how do I know if a DeliveryPlace is the last one so I can add that to
the rule ?
Right now I have a rule that just takes each DeliveryPlace and calculates
minutes to previousAppearance:
rule "minutesToPreviousAppearance"
when
$deliveryPlace : DeliveryPlace(previousAppearance != null,
$minutesToPreviousAppearance : minutesToPreviousAppearance)
then
insertLogical(new
IntConstraintOccurrence("minutesToPreviousAppearance",
ConstraintType.NEGATIVE_SOFT,
$minutesToPreviousAppearance,
$deliveryPlace));
end
--
View this message in context: http://drools.46999.n3.nabble.com/Planner-Vehicle-Routing-but-with-return...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 9 months