Rules and Decision Tables


Tutorial Index     Rules & Decision Tables     Column Queries     Arrays     Tables & Pattern Matching     Lists     VBA     Multiple Rule Sets     Array Queries


loans_01_rules.xls
loans_02_decision_tables.xls

Before jumping into the collections, it is important to understand the basic concepts of ARulesXL rule sets, facts, decision tables and rules. This is a brief overview, see the tutorial and documentation for more details.

For this example, the conditions when a loan can be sold are:

Facts

An ARulesXL rule set works with facts. Some facts are input, some are output, and some are used in between.

A query to a rule set asks for the value of an output fact based on certain input facts.

The input facts for this example are:

FICO
LTV
Occupancy

The output fact is:

Resell

Facts have values associated with them. In this example, FICO will have values like 720 or 680, and Occupancy will have values like "Owner" or "2nd Home" (text values need to be single or double quoted). These fact values will be input to the rule set.

The output fact, Resell, will have a value of "yes" or "no" depending on the values of the input facts.

Rules

Rules are used to set values of output or intermediate facts based on input or other intermediate facts.

The rules that cover this example are ( the <> symbol means not equal):

Resell = "yes" WHEN FICO >= 720 AND LTV >= 80
Resell = "yes" WHEN FICO >= 700 AND LTV >= 90
Resell = "yes" WHEN Occupancy <> "Owner" AND FICO >= 720 AND LTV >= 90
Resell = "no"

The last rule is a catch all rule, setting Resell to "no" if none of the other rules apply.


loans_01_rules.xls

Rule Sets

Rules are entered into ARulesXL rule sets.

Rule sets are created by selecting a range of cells on a worksheet and using the right mouse, or ARulesXL menu, to select New Rule Set. The name you choose is put in the upper left cell of the range and the range is given a double line border.

(By convention, the rule sets in this tutorial are also given an ivory background.)

The name of the rule set in the sample is ResaleRules.

When you are editting rules, the rules cannot be used in queries, and you will see an error message indicating the rules are being changed.

Once you finish editting the rules reload the rules using either the ARulesXL menu item Load Modified Rules or the right mouse menu for the same thing. At that point RQuery()s using the rule set are re-executed.

The rule set name serves two purposes:

Inputs/Outputs ( RQuery() )

The function RQuery() is used to provide inputs to a rule set and to get outputs. It is placed in a cell outside of the rule set. The syntax is:

RQuery( RuleSet, QueryString, CellReference1, CellReference2, ... )

The arguments are:

In the example the input properties are taken from cells D5, E5, and F5.

=RQuery(Resell, "FIND Resell WHEN FICO = _1 AND LTV = _2 AND Occupancy = _3", D5, E5, F5)

The value of Resell is returned as the value for the RQuery() function.

Rule Engine

The ARulesXL rule engine determines which rules to use based on the required output fact(s). It dynamically searches for rules that can provide the output. Because it figures out which rules to use, it is not necessary to worry about the flow of control through the rules.

Decision Tables

Decision tables often are an easier, more readable way to enter rules. A decision table is started in a multi-column rule set with a statement defining the property being set by a decision table. In this example:

Table Resell

Next, column headings are provided for the input and output properties of the decision table. And then the table is filled in with the values. A * means a value isn't needed for that property.

When the rules are loaded, the ARulesXL editor will put a single line border around the decision table indicating it knows about the table.


loans_02_decision_tables.xls

The rule sets in the two examples are equivalent, but one was entered using rule syntax and the other using decision table syntax.

The two can be combined in a single rule set, so a decision table for Resell can appear before or after rules for Resell. The only point to consider is that the rules or table rows are evaluated in the order they appear in the rule set.

In general:

 


Copyright ©2005-7 Amzi! inc. All Rights Reserved.
ARulesXL and Amzi! are trademarks or registered trademarks of Amzi!
Microsoft and Excel are trademarks or registered trademarks of Microsoft Corporation.