One thing you ought to observe is a strict textual identity of all literals. So, the limit "thirty-point-zero" shouldn't be written as "30.0" in one place and "30" in another if a seamless or non-overlapping set of intervals [x,30[ and [30,y] is desired.
(There ought to s.th. like "const" or "final static" in DRL so you could create named constants. As it is, one might import them from a Java class.)
Also, avoid conversions from int to double at different times, i.e., compile time vs. runtime, or similar.
All of this isn't a peculiarity of Drools - it's the general "blessing" that comes with floating point.
BTW, I recall vaguely that your Java code creates another session for each insert of a BMIClass fact in the 10000 loop. As you are comparing execution speeds, it isn't fair to include this start-up call in the evaluation of rule firing.
-W2009/5/4 Femke De Backere <femmyke@gmail.com>I solved the problem by removing every double in the sample.drl. How van I fix the double problem if I really wanted to :)? In this case it is unnecassary but there must be a solution?Thanks for all the help!FemkeOp 4-mei-09, om 21:48 heeft Wolfgang Laun het volgende geschreven:Don't use doubles. Try the same thing, scaling the random weights with 10 (or 100) convert to int, and use suitably scaled integer limits for your weight classes.
I'm not at all sure, what various JVM versions and/or Rand generators could produce.
The javadoc for java.lang.Math is an indicator that things might not be as simple as they ought to be.
I could reproduce the problem this afternoon, but now I can't any more, on the same machine, same JVM and same Drools version.
-W2009/5/4 Femke De Backere <femmyke@gmail.com>So, I did as you suggested, with the following as result:BMI of 10 U heeft ondergewicht: 10BMI of 30 U heeft ondergewicht: 30BMI of 30 U heeft obesitas: 30BMI of 20 U heeft ondergewicht: 20So, I really don't get it, I used exactly the same code as you.FemkeOp 4-mei-09, om 17:11 heeft Greg Barton het volgende geschreven:
Well, approach this systematically, then: Create a new Drools project in Eclipse and replace the DroolsTest.java and Sample.drl with the ones I sent before. What results do you get? If they are correct, modify the project one step at a time until the problem is uncovered.
One place to focus on: you're using rule flows. I have no idea how that could cause a false positive result like you've seen, but you never know.
Finally, if you're comparing performance of rules vs plain java, plain java will easily win in this case. The rule of thumb is this: if you can easily write a plain non-rules algorithm it will outperform the rules solution.
--- On Mon, 5/4/09, Femke De Backere <femmyke@gmail.com> wrote:From: Femke De Backere <femmyke@gmail.com>
Subject: Re: [rules-users] Rule problemTo: "Rules Users List" <rules-users@lists.jboss.org>
Date: Monday, May 4, 2009, 6:53 AMI'm using this:package bmiimport bmi.DroolsTest.BMIClass;rule "Overgewicht"ruleflow-group "BMIrules"whenbmiClass : BMIClass($bmi: bmi >= 25, bmi < 30)
thenSystem.out.println("U heeft overgewicht: " +
$bmi);endrule "Obesitas"ruleflow-group "BMIrules"whenbmiClass : BMIClass($bmi : bmi >= 30)
thenSystem.out.println("U heeft obesitas: " +
$bmi);endrule "Ondergewicht"
ruleflow-group "BMIrules"whenbmiClass : BMIClass($bmi : bmi < 18.5)thenSystem.out.println("U heeft ondergewicht: " +$bmi);endrule "Normaal"ruleflow-group "BMIrules"
whenbmiClass : BMIClass($bmi : bmi >= 18.5, bmi < 25)
thenSystem.out.println("U heeft een normaal gewicht:
" + $bmi);endBut in essence it is the same as Greg's. I get outputs
as:U heeft ondergewicht: 25.0U heeft overgewicht: 25.0But I really don't see the problem.FemkeOp 4-mei-09, om 13:25 heeft Wolfgang Laun het volgendegeschreven:I cannot reproduce your findings.Which bmi values cause the firing of two rules?Are you using exactly the same .drl file Greg sent?-W2009/5/4 Femke De Backere <femmyke@gmail.com>Thanks for the answer! But I sometimes get 2 rulesthat are correct,and that is impossible. I embedded Greg's
DroolsTest class in myclass (I am doing some test on performance andstudying thedifference between performance with a plain javaclass), and itstill doesn't work, and I really don't seewhy. Anyone anysuggestions, in attachement, my class.
Thx,FemkeOp 4-mei-09, om 02:47 heeft Greg Barton het volgendegeschreven:Try the attached code.--- On Sun, 5/3/09, Femke De Backere
<femmyke@gmail.com> wrote:From: Femke De Backere <femmyke@gmail.com>Subject: Re: [rules-users] Rule problemTo: "Rules Users List"<rules-users@lists.jboss.org>
Date: Sunday, May 3, 2009, 6:18 PMThx for the answer. I tried this but I doesn't
seem towork. For a BMI of 20, i get the result"ondergewicht", and it should be"normal".
Op 4-mei-09, om 01:04 heeft Ingomar Otter het volgendegeschreven:
Femke,The "Overgewicht| rule matches for _two_ BMIClassfacts, one with bmi >- 25 and one for BMIClass<30.If you want to apply multiple constraints to a singlefact you have to list them as such:
rule "Overgewicht"whenbmiClass : BMIClass(bmi >= 25&& bmi
<30)thenSystem.out.println("U heeftovergewicht");endCheers,IngomarAm 04.05.2009 um 00:48 schrieb Femke De Backere:Hi!I want to make en BMI rule application, so I needto test the BMI values. But in rule"Overgewicht"
and "Normaal", I need to use an AND, but itdoesn't seem to work in any way I tried.
Does anybody see the problem? The rest of theapplication is based on de sample project (createdwhenmaking a new Drools project).Thx,Femkepackage bmiimport bmi.DroolsTest.BMIClass;
rule "Overgewicht"whenbmiClass : BMIClass(bmi >= 25)bmiClass : BMIClass(bmi < 30)thenSystem.out.println("U heeft
overgewicht");endrule "Obesitas"when
bmiClass : BMIClass($bmi : bmi >=30)thenSystem.out.println("U heeftobesitas");
endrule "Ondergewicht"whenbmiClass : BMIClass($bmi : bmi <
18.5)thenSystem.out.println("U heeft
ondergewicht");endrule "Normaal"whenbmiClass : BMIClass(bmi >= 18.5)bmiClass : BMIClass(bmi < 25)
thenSystem.out.println("U heeft eennormaalgewicht");
end_______________________________________________rules-users mailing listrules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________rules-users mailing listrules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users_______________________________________________rules-users mailing listrules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users<
DroolsTest.java><Sample.drl>_______________________________________________
rules-users mailing listrules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users_______________________________________________
rules-users mailing listrules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users_______________________________________________
rules-users mailing listrules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users_______________________________________________rules-users mailing listrules-users@lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users