JESS: general question about using module to control rule execution

View: New views
4 Messages — Rating Filter:   Alert me  

JESS: general question about using module to control rule execution

by Felix Chan-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
 
I have a general question how to control execution using modules.
 
I have business rules that apply at the country (US) level, and rules that apply at state level. What I would like to do is to apply country-level rules first and then state-level rules second. The state-level rules will overwrite some of the facts that were modified or asserted as a result of the country-level rules.
 
I do NOT want to have any state-level rules applied before country-level rules have a chance to fire.
 
I can group all the country-level rules in module COUNTRY and state-level rules in module STATE. I understand that I can put (focus STATE) on the RHS to move from one module to another to control execution flow.
 
Question: What should I do to ensure that I will switch to the STATE module only after ALL APPLICABLE country-level rules have been applied (fired)?
 
I can use salience, but the book says that it's bad form. So I am wondering if I should module.
 
Thanks.
 
Felix

Re: JESS: general question about using module to control rule execution

by Ernest Friedman-Hill :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Salience is considered bad form for two reasons: first, because it's  
considered bad form, in general, to try to force the engine to fire  
rules in a particular order; and second, it negatively impacts  
performance.  The truth is, though, if it's the most sensible or  
elegant alternative in a particular application, there's really no  
reason not to use it.

If you want to not fire any rules in module B until all rules in  
module A have had a chance to fire, then rather than putting the focus  
statements into a rule, you probably want to put them into the same  
code that calls "run" -- i.e.,

(focus A)
(run)
(focus B)
(run)




On Oct 12, 2009, at 3:44 PM, Felix Chan wrote:

> Hi,
>
> I have a general question how to control execution using modules.
>
> I have business rules that apply at the country (US) level, and  
> rules that apply at state level. What I would like to do is to apply  
> country-level rules first and then state-level rules second. The  
> state-level rules will overwrite some of the facts that were  
> modified or asserted as a result of the country-level rules.
>
> I do NOT want to have any state-level rules applied before country-
> level rules have a chance to fire.
>
> I can group all the country-level rules in module COUNTRY and state-
> level rules in module STATE. I understand that I can put (focus  
> STATE) on the RHS to move from one module to another to control  
> execution flow.
>
> Question: What should I do to ensure that I will switch to the STATE  
> module only after ALL APPLICABLE country-level rules have been  
> applied (fired)?
>
> I can use salience, but the book says that it's bad form. So I am  
> wondering if I should module.
>
> Thanks.
>
> Felix

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com







--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


RE: JESS: general question about using module to control rule execution

by Brian Rogosky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I thought that modules, by design as a stack, only fire rules after the
previous modules' rules have had the chance to fire.  There doesn't seem
to be any reason to run each module separately unless I'm missing
something.  In other words, shouldn't the following be equivalent to the
previous method?

(focus B)
(focus A)
(run)

Or in Java
rete.setFocus("B");
rete.setFocus("A");
rete.run();

Would there be a performance difference between a single run for all
modules and multiple runs, one for each module?

Also, another reason to use modules instead of salience is that salience
can be more difficult to maintain as a rule set grows, assuming the
design would use more salience declarations than modules.

Brian

-----Original Message-----
From: owner-jess-users@... [mailto:owner-jess-users@...]
On Behalf Of Ernest Friedman-Hill
Sent: Monday, October 12, 2009 7:23 PM
To: jess-users
Subject: Re: JESS: general question about using module to control rule
execution

Salience is considered bad form for two reasons: first, because it's  
considered bad form, in general, to try to force the engine to fire  
rules in a particular order; and second, it negatively impacts  
performance.  The truth is, though, if it's the most sensible or  
elegant alternative in a particular application, there's really no  
reason not to use it.

If you want to not fire any rules in module B until all rules in  
module A have had a chance to fire, then rather than putting the focus  
statements into a rule, you probably want to put them into the same  
code that calls "run" -- i.e.,

(focus A)
(run)
(focus B)
(run)




On Oct 12, 2009, at 3:44 PM, Felix Chan wrote:

> Hi,
>
> I have a general question how to control execution using modules.
>
> I have business rules that apply at the country (US) level, and  
> rules that apply at state level. What I would like to do is to apply  
> country-level rules first and then state-level rules second. The  
> state-level rules will overwrite some of the facts that were  
> modified or asserted as a result of the country-level rules.
>
> I do NOT want to have any state-level rules applied before country-
> level rules have a chance to fire.
>
> I can group all the country-level rules in module COUNTRY and state-
> level rules in module STATE. I understand that I can put (focus  
> STATE) on the RHS to move from one module to another to control  
> execution flow.
>
> Question: What should I do to ensure that I will switch to the STATE  
> module only after ALL APPLICABLE country-level rules have been  
> applied (fired)?
>
> I can use salience, but the book says that it's bad form. So I am  
> wondering if I should module.
>
> Thanks.
>
> Felix

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com







--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify
owner-jess-users@....
--------------------------------------------------------------------



--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users you@...'
in the BODY of a message to majordomo@..., NOT to the list
(use your own address!) List problems? Notify owner-jess-users@....
--------------------------------------------------------------------


Re: JESS: general question about using module to control rule execution

by Jason Morris :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Felix,

BTW -- I think that Brian was intending

;; Set the focus stack
(focus A B)
(run)

There is nothing to preclude you from using modules and salience together.
There is an essay on the proper use of salience on the Jess wiki here
<http://www.jessrules.com/jesswiki/view?SalienceUsageTips>.  Salience is
best used to control the priority of sets of rules within a module.  It
should NEVER be used to control the priority of any individual rule.  Of
course, a set of rules may have just a single member at a particular time,
but the principle holds in general as stated.  The best way to think about
salience is that it is to liken it to the old GOTO statement; terrible if
you use it to create spaghetti code, but useful if you take care to create
"structured gotos" (e.g. labled statements).  For CS historians, see
here<http://pic.plover.com/knuth-GOTO.pdf>