Questions about logically justified objects
by Geoffrey De Smet
Let's say I have 2 rooms:
- Room A with penalty 10
- Room B with penalty 5
Both are inserted into the WM and never change.
Let's say I have 1 exam:
- Exam X which starts out assigned to Room A.
It's inserted into the WM, but it will change when rules are fired.
Let's say I have this rule:
rule "roomPenalty"
when
$exam : Exam();
then
Object cause = $exam;
int weight = $exam.getRoom().getPenalty();
insertLogical(new Penalty(cause, weight);
end
After my first fireAllRules, there is 1 logical asserted Penalty(10).
Next, I switch Exam X to Room B (instead of Room A) and I fire all Rules.
The _same_ rule applies on the _same_ fact and a logical asserted
Penalty(5) is inserted.
How do I enable the following different use cases?
1) Keep Penalty(10), discard Penalty(5)
2) Remove Penalty(10), add Penalty(5)
3) Keep Penalty(10), add Penalty(5)
What happens if:
1) Penalty's equals/hashcode only uses "cause"?
2) Penalty's equals/hashcode uses both "cause" and "weight"?
--
With kind regards,
Geoffrey De Smet
16 years, 11 months
java.lang.NullPointerException atorg.drools.rule.builder.dialect.java.JavaConsequenceBuilder.build(JavaConsequenceBuilder.java:54)
by Shiva Shankar Reddy Katula
Hi All,
I am using Drools 4.0.3
I have the following in drl file.
package com.framework.service.remote.rules;
import com.framework.service.EssRuleConditionService;
import com.framework.service.util.CurrentLeg;
import java.util.ArrayList;
import java.util.List;
import java.lang.Boolean;
function List depStationFun68307cu() {
EssRuleConditionService essRuleConditionService = new EssRuleConditionService();
essRuleConditionService.setDepStation("21618");
return essRuleConditionService.getDepStation();
}
function List depStationFun68308cu() {
EssRuleConditionService essRuleConditionService = new EssRuleConditionService();
essRuleConditionService.setDepStation("20932");
return essRuleConditionService.getDepStation();
}
function List depStationFun68309cu() {
EssRuleConditionService essRuleConditionService = new EssRuleConditionService();
essRuleConditionService.setDepStation("21972");
return essRuleConditionService.getDepStation();
}
rule "68307"
dialect "java"
when
currentLeg : CurrentLeg()
eval(currentLeg.getORGSTN().size()!=0 && depStationFun68307cu().containsAll(currentLeg.getORGSTN()))
then
currentLeg.setDataProcessedByDrool(new Boolean(true));
currentLeg.setRuleSetId("9003");
currentLeg.setFssBoardDailyLegId("");
end
rule "68308"
dialect "java"
when
currentLeg : CurrentLeg()
eval(currentLeg.getORGSTN().size()!=0 && depStationFun68308cu().containsAll(currentLeg.getORGSTN()))
then
currentLeg.setDataProcessedByDrool(new Boolean(true));
currentLeg.setRuleSetId("9003");
currentLeg.setRuleSetCategoryId("15722");
currentLeg.setFssBoardDailyLegId("");
end
rule "68309"
dialect "java"
when
currentLeg : CurrentLeg()
eval(currentLeg.getORGSTN().size()!=0 && depStationFun68309cu().containsAll(currentLeg.getORGSTN()))
then
currentLeg.setDataProcessedByDrool(new Boolean(true));
currentLeg.setRuleSetId("9003");
currentLeg.setRuleSetCategoryId("15722");
currentLeg.setFssBoardDailyLegId("");
end
I have the following code to access drl file :
// get the .drl constructed as inputstream
// droolsInputString is drl file read into String.
// I dont have any issue reading the file but i get the null pointer exception
byte[] bytesOfDRL = droolsInputString.getBytes();
InputStream inputStream = new ByteArrayInputStream(bytesOfDRL);
Reader source = new InputStreamReader(inputStream);
PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
PackageBuilder builder = new PackageBuilder(conf);
builder.addPackageFromDrl(source);
// when the last line is executed. builder.addPackageFromDrl(source);
Here i get the following exception
17:57:50,776 ERROR [STDERR] java.lang.NullPointerException
17:57:50,776 ERROR [STDERR] at org.drools.rule.builder.dialect.java.JavaConsequenceBuilder.build(JavaConsequenceBuilder.java:54)
17:57:50,776 ERROR [STDERR] at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:67)
17:57:50,776 ERROR [STDERR] at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:446)
17:57:50,791 ERROR [STDERR] at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:304)
17:57:50,791 ERROR [STDERR] at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:167)
17:57:50,791 ERROR [STDERR] at com.egatematrix.ess.framework.service.remote.rules.RulesEngineInvoker.readRule(RulesEngineInvoker.java:108)
17:57:50,791 ERROR [STDERR] at com.egatematrix.ess.framework.service.RuleService.doProcess(RuleService.java:302)
17:57:50,791 ERROR [STDERR] at com.egatematrix.ess.framework.service.FetchFSSData.invokeRuleService(FetchFSSData.java:141)
17:57:50,791 ERROR [STDERR] at com.egatematrix.ess.framework.service.FetchFSSData.triggerData(FetchFSSData.java:69)
17:57:50,791 ERROR [STDERR] at com.egatematrix.ess.framework.service.FetchFSSData$1.run(FetchFSSData.java:85)
17:57:50,791 ERROR [STDERR] at java.util.TimerThread.mainLoop(Timer.java:512)
17:57:50,791 ERROR [STDERR] at java.util.TimerThread.run(Timer.java:462)
I have tried compiling the drl file in drl editor. There is no error in drl file.
Can any one help me resolving the issue?
Regards,
Shiva
Tel: +91-40-27782000 Ext: 4259
16 years, 11 months
what is "pluggable dialects"
by jack wu
i read the documentation saying drools 4.x supports pluggable dialects, but i can't find anything else that explains what it is. i think by default i am using java dialect. and there is a MVEL dialect. is that it?
i am trying to see if there is a way to not use java beans as fact objects.
i have been looking to the MVEL website where they have a sample like this:
Map vars = new HashMap();
vars.put("x", new Integer(5));
vars.put("y", new Integer(10));
Integer result = (Integer) MVEL.eval("x * y", vars);
my question is if i use MVEL dialect, can i pass in a Map similar to the above for fact objects? Thanks.
jack.
---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.
16 years, 11 months
Bug and/or confusion with collect and new rules
by Dirk Bergstrom
I have modified my application to allow adding/removing/updating rules during
runtime. However, when I add a new rule to the rulebase, I don't get the
behavior I expect.
First, as soon as I call RuleBase.addPackage(), the new rules fire (the RHS code
runs). Shouldn't that happen only when I call fireAllRules()?
Second, newly added collect() rules don't collect already asserted objects. New
non-collect rules can see the objects just fine.
Attached is a testcase, and below is the output it produces. Am I doing
something wrong, or is this a bug? I'm running Drools 4.0.3 on JDK 1.5.0.13.
Start
RuleBase created
Adding rules about 'tom':
package rules;
import java.util.ArrayList;
import test.Tester.Record;
import test.Tester;
rule "Collect tom"
when
$list : ArrayList(size > 0) from collect( Record(field1 == "tom") )
then
Tester.show($list, "Collect tom");
end
rule "Non collect tom"
when
$rec : Record( field1 == "tom" )
then
System.out.println("Find 'tom' " + $rec.dump());
end
inserting record 1:"tom",
inserting record 2:"fred",
inserting record 3:"harry",
inserting record 4:"fred",
inserting record 5:"ed",
inserting record 6:"tom",
inserting record 7:"sreeni",
inserting record 8:"jill",
inserting record 9:"ralph",
inserting record 10:"tom",
fireAllRules()
Find 'tom' 10:"tom",
'Collect tom' collected 3 records => 1:"tom", 6:"tom", 10:"tom",
Find 'tom' 6:"tom",
Find 'tom' 1:"tom",
adding rules about 'fred':
package morerules;
import java.util.ArrayList;
import test.Tester.Record;
import test.Tester;
rule "Collect fred"
when
$list : ArrayList(size > 0) from collect( Record(field1 == "fred") )
then
Tester.show($list, "Collect fred");
end
rule "Non collect fred"
when
$rec : Record( field1 == "fred" )
then
System.out.println("Find 'fred' " + $rec.dump());
end
==> Why do the new rules fire when added?
Find 'fred' 4:"fred",
Find 'fred' 2:"fred",
'Collect fred' collected 0 records =>
==> Why doesn't the collect rule collect? The non-collect rule works.
fireAllRules()
Changing record 3 to 'fred'
fireAllRules()
Find 'fred' 3:"fred",
'Collect fred' collected 1 records => 3:"fred",
==> Why does the collect rule not see the other two 'fred' records?
--
Dirk Bergstrom dirk(a)juniper.net
_____________________________________________
Juniper Networks Inc., Computer Geek
Tel: 408.745.3182 Fax: 408.745.8905
16 years, 11 months
Populating Objects...
by James Carman
I am somewhat new to rules-based programming, so I thought I'd ask if my
approach to our problem seems valid (or if there are any better ways of
doing it). Basically, we have a bunch of data from public sources. Let's
call them public records. I am going to assert those into the working
memory. Then, we have summary objects that are supposed to summarize
everything we know from the public sources about a specific item. The
summary objects have properties that are to be populated from the related
public record objects. Now, we trust records from some public sources more
than others. So, we would use the values from those public records first to
populate the properties. Anyway, here's my thoughts on my approach:
1. Assert the public records into the working memory.
2. Find the corresponding summary object and assert that into working
memory.
3. Insert RequiredProperty objects (they will have a propertyName field)
for all properties on the summary object that need to be populated.
4. Write my rules based on the existence of a RequiredProperty objects (and
the summary object of course) with a specified propertyName.
So, when my rule fires that sets a property, I'll remove the
RequiredProperty object from working memory so that other rules that try to
set the same property from less trusted public sources won't fire anymore.
We'll use salience to give the rules priority based on our preferences.
Does this sound feasible? Is this the "drools way"?
James Carman
16 years, 11 months
Performance Question with Stateless Session
by coscos
Hi guys,
I have a questions regarding how to maintain the performance as the rule
engine fresh restarted when using stateless sessions (with drools 4.0.3).
We use drools in a web server to filter out unwanted facts coming from each
request. There are about 20 rules, but each request can have 500 to 2000
facts. We are trying to serve 10+ requests concurrently. Since it is pure
filtering, we use stateless sessions, with a singleton ruleBase; the
sequencial is set TRUE. We do remove the unwanted facts in our rules (RHS),
for example:
rule "Locale Restrictions"
when
$actionCollection : ActionFacts ()
$scoredAction : ScoredAction ( action.type == TYPE.LOCAL ) from
$actionCollection.scoredActions
$country : Country ()
eval ( $country != Country.UNITED_STATES )
then
if (logger.isDebugEnabled()) {
logger.debug("remove action " + $scoredAction.getAction() + " from
action list because country is " + $country);
}
modifyRetract($actionCollection);
$actionCollection.getScoredActions().remove($scoredAction);
modifyInsert($actionCollection);
end
Every time we get a request, we file the rules like this:
ruleBase.newStatelessSession().execute(facts).
The problem is, when the rules engine just starts, it is very fast; on
average it can process 2 facts in 1 ms ( -- great work, guys!). However,
after a while ( a few thousands requests), it is slowing down; on average
processing each fact will take about 2 to 5 ms (4x to 10x slower). Since we
use stateless sessions, I expect the initial performance should be
maintained overtime. I did a thread dump, and found some threads in drools
are blocked (in a fresh restarted rule engine, I don't see these blockings):
Thread 20582: (state = BLOCKED)
- java.lang.Class.forName0(java.lang.String, boolean,
java.lang.ClassLoader) @bci=0 (Compiled frame; information may be imprecise)
- java.lang.Class.forName(java.lang.String) @bci=5, line=169 (Compiled
frame)
- org.mvel.util.ParseTools.resolveType(java.lang.Class) @bci=256, line=696
(Compiled frame)
- org.mvel.math.IEEEFloatingPointMath.doOperation(java.lang.Object, int,
java.lang.Object) @bci=29, line=24 (Compiled frame)
- org.mvel.util.ParseTools.doOperations(java.lang.Object, int,
java.lang.Object) @bci=6, line=767 (Compiled frame)
- org.mvel.ast.BinaryOperation.getReducedValueAccelerated(java.lang.Object,
java.lang.Object, org.mvel.integration.VariableResolverFactory) @bci=24,
line=20 (Compiled frame)
- org.mvel.MVELRuntime.execute(boolean, org.mvel.CompiledExpression,
java.lang.Object, org.mvel.integration.VariableResolverFactory) @bci=134,
line=88 (Compiled frame)
- org.mvel.CompiledExpression.getValue(java.lang.Object,
org.mvel.integration.VariableResolverFactory) @bci=15, line=108 (Compiled
frame)
- org.mvel.MVEL.executeExpression(java.lang.Object, java.lang.Object,
org.mvel.integration.VariableResolverFactory) @bci=6, line=230 (Compiled
frame)
- org.drools.base.mvel.MVELPredicateExpression.evaluate(java.lang.Object,
org.drools.spi.Tuple, org.drools.rule.Declaration[],
org.drools.rule.Declaration[], org.drools.WorkingMemory) @bci=22, line=36
(Compiled frame)
- org.drools.rule.PredicateConstraint.isAllowed(java.lang.Object,
org.drools.common.InternalWorkingMemory) @bci=15, line=210 (Compiled frame)
- org.drools.reteoo.FromNode.assertTuple(org.drools.reteoo.ReteTuple,
org.drools.spi.PropagationContext, org.drools.common.InternalWorkingMemory)
@bci=113, line=73 (Compiled frame)
-
org.drools.reteoo.CompositeTupleSinkAdapter.createAndPropagateAssertTuple(org.drools.common.InternalFactHandle,
org.drools.spi.PropagationContext, org.drools.common.InternalWorkingMemory)
@bci=26, line=73 (Compiled frame)
-
org.drools.reteoo.LIANodePropagation.doPropagation(org.drools.common.InternalWorkingMemory)
@bci=16, line=22 (Interpreted frame)
-
org.drools.common.AbstractWorkingMemory.fireAllRules(org.drools.spi.AgendaFilter,
int) @bci=41, line=448 (Compiled frame)
-
org.drools.common.AbstractWorkingMemory.fireAllRules(org.drools.spi.AgendaFilter)
@bci=3, line=434 (Compiled frame)
- org.drools.reteoo.ReteooStatelessSession.execute(java.util.Collection)
@bci=42, line=162 (Compiled frame)
My question is, is there something buit-up in the stateless session? how to
maintain the initial performance effectively?
Any suggestion is highly appreciated.
thanks
--
View this message in context: http://www.nabble.com/Performance-Question-with-Stateless-Session-tp14704...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 11 months
Checking fact "id"
by Massi Gmail
Hi guys,
Now I am strugglin' with "fact id checking" or whatever we can call it.... :D
Let's take into account the followong scenario:
I have class A (it's just a name) javabeans to be inserted into the WM.
I define two objects of class A: A1 and A2.
Somewhere I do "insert(A1)" and "insert(A2)" ( let's say I do it in the same package of R1 and R2..see below...)
Then I define two different rules R1 and R2 that reason over class "A" facts (let's say R1 and R2 are in the same package) .
The point is.... I want R1 to fire only on A1 and R2 only on A2.
Is that possible in drools? Is there a sort of "fact id" I can reason over?
I do not think globals will be of any help, cause in the guide i have read that globals should never be used within LHS.
We should never reason over globals.
Let me know.
Massi
16 years, 11 months
The "Object" field in the DSL IDE Editor
by mmquelo massi
Hi guys,
I did not find any documentation related to the "Object" field (betweem
'mapping' and 'sorting by')
in the DSL IDE editor.
What does it stand for?
Thank You very much.
Massi
16 years, 11 months