[rules-users] Why double rule activation?

Anstis, Michael (M.) manstis1 at ford.com
Thu Apr 17 04:11:11 EDT 2008


I have tried to re-produce using "System.out.println" instead of IELogger
and I don't get any double activations :-(

Could the problem be elsewhere (e.g. IELogger?).


package com.sample

import com.sample.MyVariable;

rule "Light is off"
        when
                $brightness : MyVariable(uniqueName == "ds1 at brightness",
currentValue == 0.0)
        then
                System.out.println("DimmerSwitch1 has no brightness value");
end

rule "Light Below 50%"
        when
                $brightness : MyVariable(uniqueName == "ds1 at brightness",
currentValue < 0.50, currentValue > 0.0)
        then
                System.out.println("DimmerSwitch1 is below 50% brightness");
end

rule "Light 50% or Above"
        when
                $brightness : MyVariable(uniqueName == "ds1 at brightness",
currentValue >= 0.5)
        then
                System.out.println("DimmerSwitch1 is at or above 50%
brightness");
End

    public static final void main(String[] args) {

        WorkingMemoryFileLogger logger = null;

        try {

            RuleBase ruleBase = readRule();
            WorkingMemory workingMemory = ruleBase.newStatefulSession();
            logger = new WorkingMemoryFileLogger(workingMemory);
            logger.setFileName("events.log");

            MyVariable v1 = new MyVariable("ds1 at brightness", 0.0d);
            MyVariable v2 = new MyVariable("ds1 at brightness", 0.4d);
            MyVariable v3 = new MyVariable("ds1 at brightness", 0.6d);
            workingMemory.insert(v1);
            workingMemory.insert(v2);
            workingMemory.insert(v3);
            workingMemory.fireAllRules();

        } catch (Throwable t) {
            t.printStackTrace();
        } finally {
            if (logger != null) {
                logger.writeToDisk();
            }
        }
    }

-----Original Message-----
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Bagwell, Allen F
Sent: 16 April 2008 20:50
To: Rules Users List
Subject: [rules-users] Why double rule activation?

I've encountered rule engine behavior I'm knocking my head against the wall
trying to figure out.  I'm a Drools newbie, so please forgive if this I am
doing something bone-headed wrong.

Basically I'm inserting an object into my working memory.  The object itself
has a default setting of 0.0 for a brightness value, and this setting
matches the LHS condition for my first rule.  The problem is the rule
activates twice for a single object insertion as described in the audit log.
It consequently executes twice when I fire all rules. Then whenever I change
the value in question, any single update to the same object also causes
double rule activation and execution.

The rules I've written are not complex. Here's my drl file:

package dimmerie;

#list any import classes here.

import knowledgebase.*;
import NipcLogger;

#declare any global variables here

global NipcLogger IELogger;

rule "Light is off"
        when
                $brightness : MyVariable(uniqueName == "ds1 at brightness",
currentValue == 0.0)
        then
                IELogger.info("DimmerSwitch1 has no brightness value");
end

rule "Light Below 50%"
        when
                $brightness : MyVariable(uniqueName == "ds1 at brightness",
currentValue < 0.50, currentValue > 0.0)
        then
                IELogger.info("DimmerSwitch1 is below 50% brightness");
end

rule "Light 50% or Above"
        when
                $brightness : MyVariable(uniqueName == "ds1 at brightness",
currentValue >= 0.5)
        then
                IELogger.info("DimmerSwitch1 is at or above 50%
brightness");
end

I'm hoping I've described enough without having to post additional code.
Can anyone suggest why this is happening?

Thanks,
Allen


_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 7206 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20080417/0d7297ce/attachment.bin 


More information about the rules-users mailing list