Task 5: Implementing sequential rule-based decision modeling

You learn about building decisions incrementally through a sequence of rules rather than by assembling pre-computed components.

In previous tasks, each rule independently made decisions based on available information for all applicable cases. For composite decisions, this approach requires all decision components to exist as predecessor nodes of the decision node. The decision logic then assembles these pre-computed components into a composite value.

An alternative is to construct both components and composite values within a single decision logic. This approach uses multiple rules to build the composite value incrementally:

  1. A first rule creates an instance of the composite type.
  2. Subsequent rules create each component and add it to the composite value.

Rules construct the decision node's value step-by-step through a chain of modifications:

  1. Each rule receives the decision variable value from the previous rule.
  2. Each rule outputs a modified version of the decision variable.
  3. The final decision value is determined by the last rule that executed.

This behavior is enabled by the Rules are applied in sequence policy, which introduces a computational state that rules can modify. This state consists solely of the decision variable's value and the values of its attributes. Other variables remain immutable: only the decision variable and its attributes can be modified.

The Rules are applied in sequence policy can be used to configure a complete camera system, including camera model and all lens models, within a single decision logic. The following decision diagram illustrates this approach:

Example of a decision diagram

This diagram eliminates the submodel previously used for selecting multiple lens models. In Task 7: Applying decision models to multi-valued variables, a submodel was invoked for each specific lens requirement, scoping the fixed focus lens and lens model nodes to that requirement.

When using a single decision logic to configure the entire camera system, this scoping is lost. Information about fixed focus lens and lens requirement must now be preserved within the lens model itself. The solution is to extend the data types to embed this contextual information:
  • lens model is replaced with lens model with details, which contains two attributes fixed focus lens and lens requirement.
  • camera system is replaced with camera system with details, which contains one attribute lens model with details of the new lens model with details type.
  • camera system can be renamed to camera system with details for consistency.

The decision logic consists of six rules executed in the following order:

  1. Init camera system: It initializes a new camera system with details with all attributes undefined. The value of the decision variable is now a camera system with undefined camera model and lens models with details.
  2. Choose camera: It selects the camera model and sets the camera model attribute depending on the weight limit, the sensor format, and whether it is equipped with a tilt screen or not, like in Task 8: Adding a final decision node.
  3. Create lenses: It initializes lens models for each requirement. For each requirement, it creates a new lens model with details and adds it to the lens models with details list. It sets fixed focus lens to false. Attributes for focal length and aperture are initialized with new objects of type range. Values for the minimum and maximum attributes are undefined.
  4. Choose fixed focus lens for portrait and professional: It sets the value of the fixed focus lens attribute for each lens model of the camera system to true if the level is professional photographer and the subject is portrait.
  5. Choose fixed focus lens for sports and super-telephoto lens: It sets the value of the fixed focus lens attribute for each lens model of the camera system to true if the lens model is a super telephoto lens and the subject is sports photography.
  6. Choose lens models: It determines the name, minimum and maximum focal length, and minimum and maximum aperture of each lens model of the camera system based on the lens type attribute of the lens model, sensor format, and the fixed focus lens attribute of the lens model. The decision table contains five custom action columns that set the values of the five attributes like the one defined in Task 8: Adding a final decision node.
The Rules are applied in sequence policy executes rules in their listed order, with each rule potentially modifying the computational state for subsequent rules. Since the first rule has no condition, it is always applicable in the initial state and executes immediately. This creates a new state where the decision variable is a camera system with details object. The second rule is a decision table containing multiple rows. Each row is executed in the current state if it is applicable in this very same state and the execution modifies this current state. The third rule is a quantified rule. It follows a specific execution pattern:
  • All instances of the quantified rule are created based on the current state.
  • New instances are not created after the first instance executes.
  • Each instance executes in order: the first instance evaluates applicability in the current state. If applicable, it executes and modifies the state. The second instance evaluates applicability in the modified state. If applicable, it executes and further modifies the state. This continues for all instances.
  • A rule instance's applicability is always evaluated in the state at the moment of execution, not in the initial state.

Exercise: Using the Rules are applied in sequence policy

  1. Duplicate the lens model data type and rename it to lens model with details.
  2. Add the following attributes to the lens model with details data type:
    • fixed focus length of type Boolean
    • lens type of type lens type
  3. Duplicate the camera system data type and rename it to camera system with details.
  4. Rename the lens model attribute to lens model with details and change its type to lens model with details.
  5. Create a decision model with the following nodes and define its nodes:
    1. Add the following input data nodes:
      • level of type level
      • subject of type subject
      • budget of type integer
      • requirement of type requirement
      • lens requirements of type lens type, multi-valued
    2. Add the following decision nodes:
      • sensor format of output type sensor format
      • camera system with details of output type camera system with details
    3. Draw links between the sensor format node and the level, subject, and budget nodes.
    4. Draw links between the camera system with details node and the sensor format, requirement, and lens requirements nodes.
  6. Add a decision table to the sensor format decision node:
    1. Click the decision node and open the Logic tab.
    2. Click Create rule artifact and select Decision table.
    3. Copy content from the decision table available in Task 4: Making intermediate decisions.
  7. Define the decision logic of the camera system with details decision node:
    1. Make sure the Rules are applied in sequence policy is selected.
    2. Implement the six rules described earlier.
  8. Go to the Run tab.
  9. Create a test data set with the following values:
    • level: professional
    • subject: sports
    • budget: 2000
    • weight limit: 1000
    • equipped with tilt screen: false
    • lens requirements: super-telephoto lens
  10. Click Run and note the lens model result.
  11. Go back to the camera system with details decision node and change the order of the rules by moving Choose lens models before the two rules that determine the fixed focus lens.
  12. Go back to the Run tab and run the data set again. Is the same lens model returned?

Lessons learned

A decision logic using the Rules are applied in sequence policy has three defining characteristics:

  1. Rules execute in order and may modify the decision variable or its components but no other variables.
  2. If no rule is applicable, the decision remains undefined.
  3. The value of the decision node is the value of the decision variable after the last rule executes.

Limitations

Determining composite values and their components within a single decision logic has several drawbacks:

  • Rules that depend on results from other rules must be ordered after those rules. For example, the decision table for determining lens models requires fixed focus lens information, so it must follow the rules that set this attribute. Incorrect ordering produces incorrect results.
  • Dependencies between intermediate computations are implicit rather than explicit in the model structure. This reduces visibility into the decision-making process and makes the logic harder to understand and maintain.
  • Composite values must be extended with attributes needed for intermediate computations, mixing concerns within a single type.