skip to main content
Corticon Studio: Rule Modeling Guide : Rule dependency: Chaining and looping : Rulesheet processing: modes of looping

Try Corticon Now

Rulesheet processing: modes of looping

Occasionally, we want rules to be re-evaluated and re-fired (if satisfied). This scenario requires the Corticon rule engine to make multiple passes through the same Rulesheet. We call this behavior advanced inferencing, and to enable it in Rulesheet execution, we must set Rulesheet processing mode to Advanced Inferencing by selecting Rulesheet > Processing Mode > Advanced Inferencing from the Studio menubar, as shown:
Figure 146. Selecting Advanced Inferencing Processing Mode for a Rulesheet
Also note the circular icon to the immediate left of the Conditions header (see orange arrow).
If the rule engine is permitted to loop through the rules above, the following events occur:
Given a value of A as the initial data, the Condition in rule 1 will be satisfied and the rule will fire, setting the value to B. The 2nd rule's Condition is then satisfied, so the value will advance (or be reset) to C, and so on, until the value is once again B after the 4th rule fires. Up to this point, the rule engine is exhibiting standard, Optimized Inferencing behavior.
Now here's the new part: the value (state) has changed since the 2nd rule last fired, so the rule engine will re-evaluate the Condition, and, finding it satisfied, will fire the 2nd rule again, advancing the value to C. The 3rd rule will also be re-evaluated and re-fired, advancing the value to D, and so on. This sequence is illustrated in the following figure.
Figure 147. Loop Iterations
Here's the key to understanding looping: when a looping processing mode is enabled, rules will be continually re-evaluated and re-fired in a sequence determined by their dependency network as long as data state has changed since their last firing. Once data state no longer changes, looping will cease.
Notice that the last column of the table indicates the number of loop iterations – the first loop does not begin until rule 2 fires for the second time. The first time through the rules (steps 1-4) does not count as the first loop iteration because the loop does not actually start until step 5.
* Types of loops