Now that we have finished modeling our rules, we should analyze our rules
for logical errors. Often, initial business rule specifications are ambiguous and
incomplete. By ambiguous, we mean that the rules are conflicting under certain scenarios.
By incomplete, we mean that the rules fail to address all possible scenarios.
Before we automate our rules, it is critical to eliminate logical errors in
order to ensure that our decision service provides correct, consistent results. Corticon
Studio provides unique and powerful features to help you ensure that rules are complete and
consistent.
Check for conflicts
Let’s begin by checking for conflicts in our rules:
Ensure that the Rulesheet is open and that the Cargo.ers tab is
selected.
Select Rulesheet > Logical Analysis > Check for Conflicts.
If Corticon Studio detects conflicts, columns containing conflicting
rules are shaded in pink. This indicates that one or more conflicts exist between the
shaded rules. The total number of conflicts is also displayed in a dialog box. Click OK
to dismiss the dialog box.
Resolve conflicts
Sometimes, conflicts may not be immediately visible just by looking at
the rules. This is because each rule is actually made up of sub-rules (rules without
dashes) and it is the sub-rules that are in conflict. To see these sub-rules, select
Rulesheet > Rule Column(s) > Expand Rules.
This helps you pinpoint the source of the conflict.
Rule 1 is expanded into three columns, 1.1, 1.2, and 1.3, and rule 2 is
expanded into three columns 2.1, 2.2, and 2.3. The expansion shows all of the logical
possibilities for each rule. Rule 1 states Cargo weighing <= 20,000 kilos, regardless
of volume, must be packaged in a standard container. Corticon Studio recognizes that
there are three possible ranges for Cargo.volume (<=30, >30, and null), which we
see in the expanded rules.
With the rules expanded, the source of the conflict becomes obvious.
Scenarios with Cargo.weight <=20000 and Cargo.volume > 30 are in conflict, since
they define mutually exclusive actions (rule 1.2 assigns a standard container while rule
2.1 assigns an oversize container). To get your rules right, this conflict must be
addressed.
To resolve the conflict, you can either change your original rules, or
decide that one rule should override the other. Let’s implement the override:
Collapse your rules back to the original state by selecting
Rulesheet > Rule Column(s) > Collapse Rules.
Override Rule 1 with Rule 2. In the Overrides cell in Rule 2, select
the column number of the rule that you want Rule 2 to override—in this case, Rule 1.
Check for conflicts again by selecting Rulesheet > Logical
Analysis > Check for Conflicts. You will see that the conflict has been resolved.
With the override, Rule 2 now means “Use oversized containers when volume is >30,
even when weight is <=20,000.”
Dismiss the dialog box by clicking OK. Save your Rulesheet. Click on the
Save icon on the toolbar or choose File>Save.
Check for completeness
Conflict is one form of logical error. Another form is incompleteness in
our logic.
To see if our rules are complete, select Rulesheet > Logical Analysis
> Check for Completeness.
A message window opens informing us that the rules are incomplete. We
missed some scenarios.
The completeness checking algorithm calculates the set of all possible
combinations of values in all conditions. The algorithm then compares this set of
possible combinations to those already specified in the Rulesheet and automatically
inserts missing combinations of conditions as new columns. These new columns are shaded
in green.
In this case, Corticon Studio has added a new rule in column 3—where the
cargo weighs > 20000 and the cargo volume is less than or equal to 30. The
completeness check adds condition values, but does not choose actions—that is left to
the rule modeler.
Click OK to dismiss the window.
Resolve completeness errors
We begin by adding a new rule statement for Rule 3: Cargo weighing
> 20,000 kilos, with volume <= 30 cubic meters, must be packaged in a
heavyweight container. Note: Don’t forget to link the rule statement with the
corresponding column.
Define an action in rule cell 3A. In this case, select “heavyweight”
as the container option.
Post an Info message to the Cargo entity as we did for the first two
rules in the Rulesheet.
Select Rulesheet > Logical Analysis > Clear Analysis Results.
This removes the highlighting in Rule 3. After you clear analysis results, your Rulesheet will look like this.
Run the completeness check again. The dialog box should indicate
that the Rulesheet is complete.
Click OK in the dialog box.
Note: Although checking for completeness can identify rules that you should
include in your Decision Service, there may be situations where you don’t want a
newly-added rule. In this case, you can just delete the rule.
Save your Rulesheet.
Check for logical loops
A third form of logical error is circular logic or loops. To check for
this, select Rulesheet > Logical Analysis > Check for Logical Loops.
You see the following result.
This is a very simple Rulesheet and contains no logical loops. Click OK
in the dialog box to dismiss it. Note: While unintended logical loops should be fixed,
sometimes logical loops are a useful technique for implementing rule logic that requires
recursive reasoning.