On Jun 24, 2008, at 2:51 PM, Deepak Pol wrote:


Now following are some questions I have:
1. Since the rules defined are being applied to any data, I want the rules to be created once and shared by different sessions for different data. For eg there can be a rule which says if total > 100 then return list of users u1, u2 and u3. Now for different organizations total can be different and each organization can run rules engine with its own data but the rules themselves are same so I want to share them across different organizations. Each organization will have its own session and data and the same rules in the memory are executed with this data. What I found in Jess docs was, you need to initialize the rule engine by using new Rete(); and add the rule language file (*.clp) and the data to the working memory. But like in above example, if I want to add the data for some other organization but for the same rules then I need to create another instance of Rete and provide the rule language file to it in which case I end up having one file in working memory for each organization. Is there any way to avoid this and share the file for different data or for different sessions?


Yes, in several different ways. First of all, you don't need to hard code values like "100" in the rules; you can supply these as data. For example, a rule might say

if total > threshold then return list of users

and then each client could supply their own value of "threshold". That way the rules are the same for everybody.

Secondly, you can have multiple values of "threshold" in the same engine at the same time. You could have

if processing client #1 and total for client #1 > threshold for client #1 then...

Finally, multiple instances of the rule engine can share a single loaded set of rules; this is called "peering" and it's new in Jess 7.1, which is about to go final.


2. As per my understanding, the only way to control the flow of rules execution is by creating different modules.

No, that's just one way.

If I have a condition like if Module_1 fires (i.e at least one rule from module is fired) the focus module_2 else focus module_3. This conditions can get even more complex. And also note that all rules from module_1 should get fired so I can't have focus statement in action part of any rule of module_1 since it will immediately focus to new module and other rules from module_1 would be skipped. Currenly I am planning to do it by having a global variable for each such condition. For eg if any rule from module_1 is fired then make this variable true and use it for further control. But as the conditions become more and more complex and provided that I want to create the language through some apis against using an existing one; I am not sure how much feasible this would be. Any suggestions on this?


There's a concept of a "focus stack". The focus stack keeps track of the order in which modules will be activated. You can add and remove modules from the stack at any time. So you an easily express "when all the rules in this module have fired, proceed to module 2".


3. I want to have some modules (which would be set of rules) which are exclusive i.e. only one of them should fire even if others also match. I can do this with auto-focus for the first rule in each module but how to avoid others from firing. I tried halt but didn't work. Retracting the facts as soon as they fire is not a feasible option since the same fact might be used in some other rule in the same module which I still want to fire.


There are other ways to do this besides retracting facts; for instance, you can do it by asserting a fact signaling that one of the rules has fired, then make all the rules in the set match the absence of that fact.



Any help in above ragards would be really appreciable.
Thanks in advance,
- Deepak

---------------------------------------------------------
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 [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to