Rule dependency in chaining
- Last Updated: April 30, 2021
- 2 minute read
- Corticon.js
- Documentation
This section explores how Corticon determines the sequencing of rules, and looping, which involves controls you can set over the revisiting, re-evaluating, and possible re-firing of rules.
What is rule dependency?
Dependencies between rules exist when a conditional expression of one rule evaluates data produced by the action of another rule. The second rule is said to be dependent on the first.
Forward chaining
When a Ruleflow is compiled into a Decision Service, a dependency network for the rules is automatically generated. Corticon uses this network to determine the order in which rules fire at run time. For example, in the following simple rules, the proper dependency network is 1 > 2 > 3 > 4.
![]()
This is not to say that all three rules will always fire for a given test—clearly, a test with B as
the initial value will only cause rules 2, 3, and 4 to fire. But, the dependency network
ensures that rule 1 is always evaluated before rule 2, and rule 2
is always evaluated before rule 3, and so on. This mode of
Rulesheet execution is called optimized inferencing, meaning that
the rules execute in the optimal sequence determined by the dependency network generated
by the compiler. Optimized inferencing is the only mode of rule
processing for all Corticon.js Rulesheets.
Optimized inferencing processing is a powerful capability that enables the rule modeler to break up complex logic into a series of smaller, less complex rules. Once broken up into smaller or simpler rules, the logic is executed in the proper sequence automatically, based on the dependencies determined by the compiler.
An important characteristic of Optimized Inferencing processing: the flow of
rule execution is single-pass, meaning a rule in the sequence is evaluated once and
never revisited, even if the data values (or data state) evaluated by its Conditions
change over the course of rule execution. In the preceding example, this effectively
means that rule execution ceases after rule 4. Even if rule 4 fires (with resulting
value = B ), the second rule will
not be revisited, re-evaluated, or re-fired even though its condition (if value =
B) would be satisfied by the current value
(state).