Working Memory and agenda-group
by Mike Key
I am a fairly new Drools user and am trying to understand how working
memory is segmented when using agenda groups. I have an agenda-group that
has focus set immediately from the session as follows with a few objects
being inserted:
ksession.insert(objectA);
ksession.insert(objectB);
ksession.getAgenda().getAgendaGroup("Foo").setFocus();
I have 2 rules simplified down to illustrate my confusion. The first rule
simply sets some default values evaluated in the second rule if objectA
exists. In the example that works I set the defaults in the RHS
explicitly. However I want to use these defaults from different
agenda-groups, so when I put them in a function, the second rule never
fires, the activation is created for the first rule but never the second.
Can someone tell me why the use of a function seems to alter the truth of
the rule?
THIS WORKS:
declare SomeDefault
minValueA : Integer
minValueB : Double
maxValueB : Double
end
rule "Check Object A and Set Default"
agenda-group "Foo"
salience 100
when
$a : ObjectA()
then
default = new SomeDefault()
default.minValueA = 100
default.minValueB = 20.0
default.maxValueB = 20000.0
insert(default)
end
rule "Use the defaults"
agenda-group "Foo"
salience 100
when
$default : SomeDefault()
then
System.out.println("Default minA=" + $default.minValueA)
end
THIS DOES NOT WORK:
declare SomeDefault
minValueA : Integer
minValueB : Double
maxValueB : Double
end
rule "Check Object A and Set Default"
agenda-group "Foo"
salience 100
when
$a : ObjectA()
then
insertDefault(drools.getWorkingMemory())
end
rule "Use the defaults"
agenda-group "Foo"
salience 90
when
$default : SomeDefault()
then
System.out.println("Default minA=" + $default.minValueA)
end
function void insertDefault(WorkingMemory workingMemory) {
SomeDefault default = new SomeDefault();
default.setMinValueA(100);
default.setMinValueB(20.0);
default.setMaxValueB(20000.0);
workingMemory.insert(default);
}
In the latter (non-working) example the first rule activates and then
drools returns, it never even attempts to try to fire the second rule.
However in the working example BOTH rules fire as I would expect. I am
guessing this is a simple misunderstanding on my part. Any assistance in
understanding why this nuance doesn't seem to work would be greatly
appreciated.
Thanks.
MiKey
14 years, 6 months
Null pointers and field level validation
by Ronald Albury
I have been experimenting with using the same set of rules for both record
validation (when a completed record come to us from a 3rd party) and field
validation (when the record is filled out via a web app). I don't want to
have two separate sets of rule validation (twice the maintenance, twice the
confusion). I have no problems with the record validation, but some issues
with field validation that I would like to get input on.
First - the idea for the field validation is to use Ajax to send the field
contents to the server when the field looses focus, so that we can provide
rapid feedback to the user if they have entered a field incorrectly. Most
of the intra-field validation will take place at the end of the user input,
when the form is submitted.
The fact that Drools has lots of null protection was very helpful ... I
could partially fill in a sub-record with the field input, submit it to the
rules engine, and only those rules accessing a filled-in (non-null) field
would be evaluated. I am interested in feedback on this concept.
The general issue I'm having with my experiment is that not all
null-security is created equal.
1) if I have a Boolean field then Drools throws an exception if the rule
is based on that field and the field is null. I found a work around by
testing if the field is equal to true.
2) if I have a String field then Drools throws an exception if that
field is tested with 'matches'. The only work around I've come up with is
to use a null-protected utility method instead of the built-in 'matches'.
3) if I have a String field then Drools throws an exception if that
field is tested with 'in'. Here again, the only work around I've come up
with is a utility method.
Is my concept flawed from the start? Any suggestions on addressing the
issues mentioned above? Any suggestions on issues I have yet to encounter?
Thanks
Ron
14 years, 6 months
Access metadata of declared drools expert types in Java
by Tobias Neef
Hi,
First I have to say. Drools is a very nice tool with great
documentation. Thats the first time I have to use the ML because I
write a little framework which makes some obscure use of Drools expert
;).
But now my problem: I have a type which I declared like:
declare MyMarker
@Marker
feature : String @Feature
end
When I put an instance of that type into the KB I want to grab those
entries with a given @Marker / annotation. So I tried doing that with
reflection on the MyMarker class which did not work. Also when I try
to get a FactType instance I do not find a way to access those
metadata information. For the class annotation @Marker I see that the
FactType instance contains a private field annotation which includes
the correct type. But I see no way to access this information. The
feature field itself can be accessed but no annotation information is
available:
{feature=FieldDefinition{name='feature', type='java.lang.String',
key=false, inherited=false, index=1, initExpr='null',
annotations=null, accessor=[ClassFieldExtractor class=package.MyMarker
field=feature]}
A second minor problem is the way I access the fact type. Is there a
better way to do this?
for (Object object : result) {
Class c = object.getClass();
Package p = c.getPackage();
String packagename = p.getName();
String classname = c.getSimpleName();
FactType ft = knowledgeBase.getFactType(packagename, classname);
if (ft!=null) {
//stuff
}}}
Best Regards,
Tobias Neef
14 years, 6 months
Rule evaluation logic
by MarcoMojana
I have reduced my problem to a minimal example:
- I use a pseudo clock and stream mode processing
- The events are inserted using a succession of advanceTime(), insert(),
fireAllRules()
- I have three events named: Thief, SwitchOn and SwitchOff
- I have three rules similar to:
rule "detect theft"
when
$t : Thief() from entry-point "thieves" // Line A
$lastSwitchOn : SwitchOn(this before $t) from entry-point "lightsControl"
// Line B
SwitchOff(this before $t, this after $lastSwitchOn) from entry-point
"lightsControl" // Line C
not( SwitchOff(this before $t, this after $lastSwitchOn) from entry-point
"lightsControl" ) // Line D
then
System.out.println($t);
end
The first rule is composed of lines A, B, the second of lines A, B and
C and the third of lines A, B and D. Please note that line D is the negation
of line C.
- Inserting the same sequence of events, only the first rule triggers.
This seems strange to me, because:
1) if the first rule triggers, then "Line A" and "Line B" = true
2) if the second rule doesn't, then "Line A" and "Line B" and "Line C" =
false.
3) from 1) and 2), it follows "Line C" = false
4) from 1) and 3), it follows that "Line A" and "Line B" and not "Line C"
= true, so the third rule should be triggered, but it is not. Why?
--
MM
--
View this message in context: http://drools.46999.n3.nabble.com/Rule-evaluation-logic-tp3620772p3620772...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 6 months
DSL/DSLR question
by Rob Fisher
I have a question given the following code:
Inserted fact setter method:
public void setqrpQualRule6(String qrpQualRule6) {
qrpQualRule6 = qrpQualRule6;
}
DSL
[consequence][]Write {AttributeName} on {objectVarName} as
{customCode}=modify ({objectVarName}) \{{AttributeName}={customCode} \};
DSLR
rule "test rule 1"
dialect "mvel"
when
ThereIsQrpRuleFlagData called QrpFlags
- where $var04 is QrpQualFlagRule6 and is equal to "N"
then
Write QrpQualFlagRule6 on QrpFlags as "Y"
DRL Translation
modify (QrpFlags) {qrpQualRule6="Y" };
Question....Does Drools create the "get" behind the scenes? I'm guessing
yes, because the rule is firing and the qrpQualRule6 attribute is getting
set to "Y".
--
View this message in context: http://drools.46999.n3.nabble.com/DSL-DSLR-question-tp3619216p3619216.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 6 months
Usage of completeMoveTabuSize
by Patrik Dufresne
Hi,
I've try to use the completeMoveTabuSize for my problem and I come to
realize it's not working properly. To make sure, I've check it's usage in
the smart Travelling Tournament. It's look like, the hashCode function it
not well implement.
Here my comprehension of the completeMoveTabuSize functionnality :
When completeMoveTabuSize sets to 7, the last 7 moves are consider Tabu. So
the accept chance of the last 7 moves should be 0.0.
To check the tabu, the acceptor use a HashMap and so the hashCode of the
last 7 moves are used to speed up the comparison. In the smart travelling
tournament, the implementation of hashCode is wrong since it's include the
hashCode of the planning-entity which change over time.
May someone confirm this ??
To figure it out, I add a breakpoint in the equals function of the Move
object (and it's never called).
--
Patrik Dufresne
14 years, 6 months
Flow isn't behaving as I'd expect
by Jamie
I'm having some issues with the interaction between Flow, ruleflow-groups and
AgendaFilters. I've tried it with 5.1.1, 5.2.0 using .rf files and 5.2.0
using .bpmn files, all with the same results, so I'm sure I'm just
misunderstanding something.
I have a flow that looks like this:
http://drools.46999.n3.nabble.com/file/n3200994/fraud_analysis_flow.jpg
Rules 011 and 051 are in ruleflow-group customerAnalysis and rule 018 is in
ruleflow-group customerActivityFilterAndLookup. I added some debugging via
event listeners and if I don't use an agenda filter, I see the following
output:
Executing test Rule018TestCase001
Rules engine initialized
Invoking rules for rule name Rule 018 - Good AVS Buyer
Created activation for [Rule 018 - Good AVS Buyer]
Created activation for [Rule 011 - Bad Zip 9 Address]
Created activation for [Rule 051 - Suspicious Buyer Email]
Triggered node [Order Analysis]
Triggered node [Start Fraud Analysis Flow]
Triggered node [Customer Analysis]
About to fire [Rule 051 - Suspicious Buyer Email]
====> Rule 051 fired for order: 000000022
About to fire [Rule 011 - Bad Zip 9 Address]
====> Rule 011 fired for order: 000000022
Triggered node [Customer Activity Filter And Lookup]
About to fire [Rule 018 - Good AVS Buyer]
Created activation for [Rule 051 - Suspicious Buyer Email]
Created activation for [Rule 011 - Bad Zip 9 Address]
====> Rule 018 fired for order: 210105
Triggered node [Customer Activity Analysis]
Triggered node [Suspect Reason Code Review]
Triggered node [End Fraud Analysis Flow]
Rules executed successfully
The results are roughly what I'd expect, but I have some questions:
- Why do the activations get created for these 3 rules before any flows
have started?
- Why does the [Order Analysis] node get triggered before the [Start Fraud
Analysis Flow] node?
- Why are activations created again for 011 and 051 just prior to 018
firing?
If I introduce an AgendaFilter that only allows a rule with a specific name
to fire, things get stranger to me. If I only allow rule 018, I get the
following output:
Executing test Rule018TestCase001
Invoking rules for rule name Rule 018 - Good AVS Buyer
Created activation for [Rule 018 - Good AVS Buyer]
Created activation for [Rule 011 - Bad Zip 9 Address]
Created activation for [Rule 051 - Suspicious Buyer Email]
Triggered node [Order Analysis]
Triggered node [Start Fraud Analysis Flow]
Triggered node [Customer Analysis]
Rejecting firing of [Rule 051 - Suspicious Buyer Email] because name
doesn't match.
Cancelled activation for [Rule 051 - Suspicious Buyer Email] because FILTER
Rejecting firing of [Rule 011 - Bad Zip 9 Address] because name doesn't
match.
Cancelled activation for [Rule 011 - Bad Zip 9 Address] because FILTER
Rules executed successfully
Ruleflow customerActivityFilterAndLookup doesn't even get triggered, nor do
any nodes after that. Why not?
--
View this message in context: http://drools.46999.n3.nabble.com/Flow-isn-t-behaving-as-I-d-expect-tp320...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 6 months
OSGi version of Drools
by Flavius Vespasianus
Hello,
is there anywhere a OSGi bundle with Drools 4.0.7? I know about
com.springsource.org.drools.* but these had a lot of additional
dependencies and I wasn't able to get them work.
My problem is that I need to have three projects: one is the basic
library which uses Drools very intensively. The second project is editor
- an Eclipse plugin (that's why I need the OSGi bundle) using some
classes from the basic library. It doesn't use Drools, but there is a
dependency. The third project is classic Java application, also using
the basic library.
The basic library was originally created using standard Drools project
wizard (I have downloaded the Eclipse Drools plugin -
org.drools.eclipse). But when I tried to deploy it as an Eclipse plugin,
it couldn't find the Drools classes.
I found a little workaround - I have compiled the binaries (drools-core,
drools-compiler and from libs the mvel, antlr3 and eclipse-jdt-core)
into separate plugin using "Create a plugin from existing jars" wizard.
But if I add this dependency to the basic library, I get a
NullPointerException error on every dslr file and I cannot run the
application properly). At least the second project (editor) can be compiled.
What am I doing wrong? Or can I find somewhere the binaries compiled
correctly into OSGi bundle?
Thanks a lot!
Flavius
14 years, 6 months
Drools Expert 5 OSGi
by jflamy
I want to manage Drools Expert rules with Drools Guvnor. My understanding is
that requires the use of Drools Expert version 5.
I also need to use an OSGi-packaged version of Drools Expert.
I saw a forum posting in 2010 alluding to such a beast, but the springsource
forums only provide 4.0.7.
Is there a ready-made OSGi bundle for drools expert 5, or alternately
specific instructions for building one ?
Jean-François Lamy
--
View this message in context: http://n3.nabble.com/Drools-Expert-5-OSGi-tp681546p681546.html
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 6 months