order of rules firing
by Smitha Bhat
Hi,
I am new to JBoss rules.
My drl file is not resulting in the functionality that I am expecting.
I know that I shouldn't be counting on the rules firing in a particular order, but I find that as I debug my code, the 'when' of the 3 rules are evaluated first, and then the 'then's. For eg. the SetWatch gets called after DistanceKm(Rule1), DistanceKm(Rule2) and CountWatching(rule3) are called. I expected SetWatch to get called after DistanceKm of Rule2 got called i.e. I expected the 'when' and the 'then' to get evaluated sequentially. Is my understanding wrong? I tried setting the salience of the 3 rules, but I get the same behaviour. Is there something else I need to do, to get the functionality I need?
Thanks
The 3 rules in my drl as given below.
rule "Rule1"
when
$GeoPosition1 : GeoPosition()
$GeoPosition2 : GeoPosition()
eval(util.StringEqual($GeoPosition1.getType(), "PRPT"))
eval(util.StringEqual($GeoPosition2.getType(), "SI"))
eval(util.DistanceKm($GeoPosition1, $GeoPosition2) > 100.0)
eval(util.Watching($GeoPosition1, $GeoPosition2))
then
util.ClearWatch($GeoPosition1, $GeoPosition2);
end
rule "Rule2"
when
$GeoPosition1 : GeoPosition()
$GeoPosition2 : GeoPosition()
eval(util.StringEqual($GeoPosition1.getType(), "PRPT"))
eval(util.StringEqual($GeoPosition2.getType(), "SI"))
eval(util.DistanceKm($GeoPosition1, $GeoPosition2) <= 100.0)
eval(! util.Watching($GeoPosition1, $GeoPosition2))
then
util.SetWatch($GeoPosition1, $GeoPosition2);
end
rule "Rule3"
when
$GeoPosition1 : GeoPosition()
eval(util.StringEqual($GeoPosition1.getType(), "PRPT"))
eval(util.CountWatching($GeoPosition1) >= 1)
then
util.SetThreat($GeoPosition1, 1.0);
util.SetColor($GeoPosition1, "red");
end
---------------------------------
Got a little couch potato?
Check out fun summer activities for kids.
18 years, 6 months
Problem with update(fact)
by Felipe Piccolini
I know I already asked this in a previous email, but no answer and
diferent subject... so I'll ask again
I have an issue using update in 2 rules that update the same
object... a loop is created even when I try to
avoid the loop adding an extra condition to each rule... Im inserting
an ArrayList as a fact too, so I can check
the extra condition...
Can anyone tell me how to fix this?
Consider this:
//-------RULES-----------------------------
package cl.bluesoft.test
#list any import classes here.
import java.util.List
import java.util.ArrayList
import cl.bluesoft.test.rules.Fact
#declare any global variables here
rule "test update A"
salience 699
no-loop
when
$f : Fact($n: number > 0)
$list: ArrayList( this excludes "key1")
then
System.out.println("A-fact number1:"+$f.getNumber()+" list 1:"+$list);
$list.add("key1");
$f.setNumber($n + 1);
update ($f);
update ($list);
System.out.println("A-fact number2:"+$f.getNumber()+" list 2:"+$list);
end
rule "test update B"
salience 699
no-loop
when
$f : Fact($n: number > 1)
$list: ArrayList( this excludes "key2")
then
System.out.println("B-fact number1:"+$f.getNumber()+" list 1:"+$list);
$list.add("key2");
$f.setNumber($n + 1);
update ($f);
update ($list);
System.out.println("B-fact number2:"+$f.getNumber()+" list 2:"+$list);
end
//-------FACT-----------------------------
public class Fact implements Serializable {
private static final long serialVersionUID = 331627137981862975L;
private int number;
public Fact(int number){
this.number = number;
}
public Fact(){
this(0);
}
/**
* @return the number
*/
public int getNumber() {
return number;
}
/**
* @param number the number to set
*/
public void setNumber(int number) {
this.number = number;
}
}
//------TEST---------
public class TestUpdateFact implements Serializable {
private static final long serialVersionUID = -574789596641083743L;
/**
* @param args
*/
public static void main(String[] args) {
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
Package pkg = builder.getPackage();
....
WorkingMemory session = ruleBase.getStatefulSession();
...etc etc...
List list = new ArrayList();
Fact fact1 = new Fact(1);
session.fireAllRules();
....etc, etc...
}
}
//--------OUTPUT------------
A-fact number1:1 list 1:[]
A-fact number2:2 list 2:[key1]
B-fact number1:2 list 1:[key1]
B-fact number2:3 list 2:[key1, key2]
A-fact number1:3 list 1:[key1, key2]
A-fact number2:4 list 2:[key1, key2, key1]
B-fact number1:4 list 1:[key1, key2, key1]
B-fact number2:5 list 2:[key1, key2, key1, key2]
A-fact number1:5 list 1:[key1, key2, key1, key2]
A-fact number2:6 list 2:[key1, key2, key1, key2, key1]
B-fact number1:6 list 1:[key1, key2, key1, key2, key1]
B-fact number2:7 list 2:[key1, key2, key1, key2, key1, key2]
A-fact number1:7 list 1:[key1, key2, key1, key2, key1, key2]
A-fact number2:8 list 2:[key1, key2, key1, key2, key1, key2, key1]
B-fact number1:8 list 1:[key1, key2, key1, key2, key1, key2, key1]
.... for ever.....
So I have a loop... only when I use update and both rules...
condition about the
list not containing "key1" and "key2" seems not properly chequed... I
dont know...
Can somebody help me? Am I missing something here?
Thanks.
Felipe Piccolini M.
felipe.piccolini(a)bluesoft.cl
18 years, 6 months
Help with MR3
by s erel
Hello,
I've just started integrating MR3 into my project (I've previously
used 3.06). The
drl compiles and everything seems fine, but during
tests the following exception is thrown for time to time:
java.lang.ArrayIndexOutOfBoundsException: 17
at org.drools.util.AbstractHashTable$HashTableIterator.next(
AbstractHashTable.java:250)
at org.drools.reteoo.Rete$ObjectTypeConf.buildCache(Rete.java:434)
at org.drools.reteoo.Rete$ObjectTypeConf.getObjectTypeNodes(Rete.java:425)
at org.drools.reteoo.Rete.assertObject(Rete.java:172)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:190)
at
org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute(
ReteooWorkingMemory.java:163)
at org.drools.common.AbstractWorkingMemory.executeQueuedActions(
AbstractWorkingMemory.java:1135)
at org.drools.common.AbstractWorkingMemory.insert(
AbstractWorkingMemory.java:781)
at org.drools.common.AbstractWorkingMemory.insert(
AbstractWorkingMemory.java:584)
at org.drools.jsr94.rules.StatefulRuleSessionImpl.addObject(
StatefulRuleSessionImpl.java:162)
This only happens during high load tests.
Can anyone help me?
Thanks
18 years, 6 months
Running Drools on Sun Portal Server 7
by Tom Finlayson
Folks,
I'm having an issue running Drools 3.0.5 on Sun Portal Server 7. When our
rules are loaded and compiled, they come back as being invalid. Debugging
reveals this is because the consequence is null. As such, addRule in
AbstractRuleBase throws the following exception:
java.lang.IllegalArgumentException: The rule called Test Rule is not valid.
Check for compile errors reported.
This is very similar to a previously reported issue however all our rules
work fine under Eclipse when running JUnit. Additionally they have been
successfully run when deployed as a servlet to Sun Application Server 8.1.
This suggests the problem is due to classloading issues in the Portal
environment.
Has anyone else experienced this issue or can suggest a fix?
Cheers,
Tom Finlayson
18 years, 6 months
Retrieve a package from rule base
by Natraj Gudla
Hi Mark,
I could not find a method which would return a package object given a name
from a rule base. All that we have is the getPackages() method which returns
an array. Incases when i want to get a given package, i am forced to iterate
over the array checking for a given package name.
It would be a nice feature to have a getPackage() accepting a name and
returning a package object against it. As a work around i have extended the
ReotooRuleBase to add a new method which will do this. In turn i can have my
app use the new rule base. I am sure extending a rule base is not so
recommended.
Pl let me know the feasibility of this change. If required i can raise a
JIRA on this.
Thanks
Natraj Gudla.
18 years, 6 months
Problem while using the global - Drools 3.0.6
by Natraj Gudla
Hello,
I am using Drools 3.0.6. While using a global variable in a function, the
compiler complains it cannot resolve the global variable name. Something
like below
*
global* com.*sample*.ExampleLogger *customLogger*;
*
function* *void* logMessage(String msg){
customLogger.logMessage("Log Message from the function");
}
In the above code, it complains "customLogger cannot be resolved". I am able
to refer the global in the consequence of a rule directly. What is the
problem using the reference within a function.
On the other hand, i am able to do something like
* *
function *void* logMessage(ExampleLogger custLogger,String msg){
custLogger.logMessage(msg+" Accept gloabal as function parameter");
}
and call from the consequence of a rule : logMessage(customLogger); // I am
passing the global to the function as an argument and then use it to log a
message.
This way is working. But not the first way of using the global in the
function.
Any help??
Thanks
--
Natraj Gudla
18 years, 6 months
rete changing !!
by hypnosat7
What's the difference between the three expressions : (because I'm seeing the
rete tree changing when I change my expression) :
$ct : ControleTechnique(resultat == ControleTechnique.KO);Voiture(ct ==$ct)
and
$ct : ControleTechnique(resultat == ControleTechnique.KO) Voiture(ct ==$ct)
and
$ct : ControleTechnique(resultat == ControleTechnique.KO)
Voiture(ct ==$ct)
Thanks
--
View this message in context: http://www.nabble.com/rete-changing-%21%21-tf4024937.html#a11432535
Sent from the drools - user mailing list archive at Nabble.com.
18 years, 6 months
4.0.0.MR3 Problems
by Ronald R. DiFrango
All,
I am in the process of migrating my 3.0. project to the 4.x series and when
I attempt to run my code I get the following exception when I attempt to
load my .drl files:
Caused by: org.drools.RuntimeDroolsException: Unable to load dialect '
org.drools.rule.builder.dialect.java.JavaDialect:java'
Here is my package builder code:
static
{
try
{
builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader(
RtvDecisionEngine.class.getResourceAsStream("rtv.drl" ) ) );
builder.addPackageFromDrl( new InputStreamReader(
RtvDecisionEngine.class.getResourceAsStream("modelDiscrepancyRules.drl" ) )
);
ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( builder.getPackage() );
}
catch(Exception e)
{
throw new RuntimeException("Failure loading the Rules", e);
}
}
Any thoughts appreciated.
Ron
18 years, 6 months