Teri Tassara

Ruleset Organization Best Practice

Discussion created by Teri Tassara on Sep 23, 2008

Q. How to organize rules into rulesets (Best Practice).

A. Rulesets should be organized in a way that makes sense for execution and maintenance. For example, rules that need to work on the same object might be grouped together. Having a common object to pass as an argument to a set of rules that only refer to that object simplifies coding, rather than passing multiple arguments to a set of rules written against different objects, or the use of globals to avoid multiple arguments.

 

Arguments can be passed to rulesets using the keyword: apply. All RETE mode rulesets are part of the RETE network, and an initial evaluation of the RETE network occurs on the entry to the first RETE ruleset. If the rules reference globals rather than arguments to the ruleset, then the conditions against those globals will be fully evaluated for all rulesets. Rules referencing arguments perform their initial evaluation against the special value of "unknown", and most condition evaluation is skipped. Then when the ruleset is passed an argument object, the RETE network reevaluates those rule conditions against the change in the argument. If a significant number of rulesets could not be called in a particular execution of a rule service, using arguments instead of globals can definitely improve performance, as you can avoid full evaluation of the rules that never have a chance to fire. Sequential and Compiled Sequential rulesets are not part of the RETE network, and their rule conditions are evaluated only when the rulesets are called.

 

The overhead of using the "apply" keyword is relatively minor, but it is not zero, so avoid creating more rulesets than you need.

 

A decision metaphor (such as a decision table, decision tree, and score model) resolves to a single ruleset. However, you can generate additional instances using the appropriate decision metaphor template.

Outcomes