Task 6: Applying a decision logic to many values

You learn about implementing multi-valued decisions.

Complex decision-making problems often involve an arbitrary number of components, each requiring an individual decision. This document explains how to handle such scenarios efficiently by using multi-valued nodes and quantifiers.

Consider a camera recommendation system where customers can purchase various lens types:

  • Customer A wants a standard lens and a telephoto lens.
  • Customer B wants a standard lens, a super-telephoto lens, and a wide-angle lens.
  • Customer C wants a super wide-angle lens.

Each lens type requires selecting a specific lens model based on the lens type and the camera's sensor format.

A basic implementation creates one input data node and one decision node per lens type, replicating the decision logic across all nodes. This implementation would lead to the following scalability issues:

  • Five lens types would require ten nodes total, making the diagram too large.
  • The same decision logic would be copied multiple times.
  • Any change to the decision logic would require updating all copies, which is error-prone.
  • Adding Len types would require even more nodes and duplication.

An elegant and scalable solution for problems with an arbitrary number of components is possible when two conditions are met:

Component independence
Each component decision must be independent. Other components are ignored when deciding for a particular component. If you take the camera model example, each wanted lens type defines a subproblem that consists of:
  • The required lens type.
  • The lens model chosen for the lens type.
  • The decision logic that is defined according to the lens model that is chosen.

In addition, each subproblem takes the sensor format of the camera into consideration. For example, if you introduce three lens types, three subproblems of the same structure are generated. Each subproblem contains a node that specifies a lens type, a node that specifies a sensor format, and a node for choosing the lens model:

  • Subproblem 1 consists in choosing lensModel1 for lensRequirement1 and sensor format.
  • Subproblem 2 consists in choosing lensModel2 for lensRequirement2 and sensor format.
  • Subproblem 3 consists in choosing lensModel3 for lensRequirement3 and sensor format.
Uniform decision logic
All subproblems must apply the same decision logic to different nodes. For example, the three subproblems can all use the same rule that chooses a lens model with a focal length of 14:42 and an aperture of 3.5:5.6:
  • If lensRequirement1 is a standard lens and sensor format is Micro Four Thirds then lensModel1 has a focal length of 14:42 and an aperture of 3.5:5.6.
  • If lensRequirement2 is a standard lens and sensor format is Micro Four Thirds then lensModel2 has a focal length of 14:42 and an aperture of 3.5:5.6.
  • If lensRequirement3 is a standard lens and sensor format is Micro Four Thirds then lensModel3 has a focal length of 14:42 and an aperture of 3.5:5.6.

Each rule checks whether the lens type is standard lens and the sensor format is Micro Four Thirds. When both conditions are met, the rule assigns a lens model with focal length 14:42 and aperture 3.5:5.6 to the corresponding subproblem. Since all three rules share identical conditions and actions, differing only in which nodes they reference, they can be consolidated into a single universal rule:

For each subproblem x: if the lens requirement of x is standard lens and the sensor format is Micro Four Thirds then the lens model of x has a focal length of 14:42 and an aperture of 3.5:5.6.

Decision Designer provides a compact way to represent multiple subproblem versions. Instead of creating separate input data nodes for each lens type, you can use a single multi-valued input data node called lens requirements. This node can hold multiple lens types simultaneously:

  • Customer A requests a standard lens and a telephoto lens: the node contains two values.
  • Customer B requests a standard lens, a super-telephoto lens, and a wide-angle lens: the node contains three values.

Decision Designer supports two node cardinalities:

Type Description
Single-valued Contains exactly one value
Multi-valued Contains zero, one, or multiple values

The node or attribute type determines the type of values that it contains.

You could replace the multiple single-valued nodes that are used so far with:

  • One multi-valued input data node named lens requirements that contains all requested lens types.
  • One multi-valued decision node named lenses that collects all recommended lens models.

Rather than setting the value of this decision variable, you can use the add <value> to <decision> ; action to append values to multi-valued nodes. In this example, each added value is a lens model with focal length and aperture specifications. Both specifications can use the range composite type, which contains a minimum and a maximum value. The decision is made by using the following action:

add a new lens model where
    the focal length is a new range where 
        the minimum is 14 , 
        the maximum is 42 ,
    the aperture is a new range where 
        the minimum is 3.5 , 
        the maximum is 5.6
 to decision;

Decision Designer also provides a simple way to execute universal rules: quantifiers. Quantifiers apply logic to each value independently:

for each lens type called 'x', in 'lens requirements' 
    <some logic>

This construct iterates through each lens type and applies the logic to it individually, ignoring all other lens types. The logic within the quantified statement processes only one subproblem at a time, making sure that each subproblem is evaluated independently.

The universal rule that is given in the previous section can be expressed by using a quantifier:

for each lens type called 'x', in 'lens requirements'
    if x is standard lens and 'sensor format' is Micro Four Thirds
    then add a new lens model where
            the focal length is a new range where 
                the minimum is 14 , 
                the maximum is 42 ,
            the aperture is a new range where 
                the minimum is 3.5 , 
                the maximum is 5.6
         to decision;
Note: The solution for the following exercises are available through the New decision service wizard under Practice tutorials. For more information about importing samples, see Building decision services.

Exercise 1: Single-valued implementation

You create a traditional implementation by using single-valued nodes:

  1. Go to the data model and define the following data types:
    • An enumeration type named lens type with the following values: standard lens, super-telephoto lens, super wide-angle lens, telephoto lens, and wide-angle lens.
    • A composite type named range with two numeric attributes minimum and maximum.
    • A composite type named lens model with the following attributes: name of type string; focal length of type range, and aperture of type range.
  2. Create a decision model and add the following single-valued nodes:
    • Three input data nodes of type lens type.
    • Three decision nodes of output type lens model.

    Each decision node must depend on one input node and the sensor format node, as shown in the following screenshot:

    An example of a decision diagram
  3. For each decision node, create a decision table:
    1. In the decision table creating wizard, select the appropriate lens requirement and sensor format as criteria.
    2. Right-click the top cell of the lens column and click Define column. Then, enter the following rule:
       set decision to a new lens model where
           the name is <name> , 
           the focal length is a new range where 
               the minimum is <a number> , 
               the maximum is <a number> ,
           the aperture is a new range where 
               the minimum is <a number> , 
               the maximum is <a number>
    3. Update the lens subcolumn labels to name, min focal length, max focal length, min aperture, and max aperture.
The following row suggests a lens of focus length 14:42 and aperture 3.5-5.6 as a standard lens for a Micro Four Thirds format:
A decision table with one row and four columns

Exercise 2: Multi-valued implementation

You refactor the decision model to replace single-valued nodes by using multi-valued nodes and quantifiers:

  1. Create new nodes:
    1. Create an input data node named lens requirements of type lens type. Then, click Output is a list to make it multi-valued.
    2. Create a decision node named lenses of type lens model. Then, click Output is a list to make it multi-valued.
    Make sure that the lenses decision node depends on the lens requirements and sensor nodes, as shown in the following screenshot:
    An example of a decision diagram
  2. Create a decision model that recommends lens models:
    1. In the decision table creating wizard, select lens requirement and sensor format as criteria.
    2. Click Edit preconditions in the decision table editor and enter the following rule:
      for each lens type called 'lens type' , in 'lens requirements'
    3. Right-click the top cell of the lens requirement column and click Define column. Then, enter the following rule:
      'lens type' is <a lens type>
      Then, update the column label to lens requirements.
    4. Right-click the top cell of the lens column and click Define column. Then, enter the following rule:
       add a new lens model where
           the name is <name> , 
           the focal length is a new range where 
               the minimum is <a number> , 
               the maximum is <a number> ,
           the aperture is a new range where 
               the minimum is <a number> , 
               the maximum is <a number>
       to decision
      Then, update the subcolumn labels to name, min focal length, max focal length, min aperture, and max aperture.
    5. Complete the decision table as done in exercise 1:
      An example of a decision table

Lessons learned

Multi-valued nodes with quantifiers enable compact decision logic when:
  • Each decision is made for a single component.
  • All decisions follow the same logic.

When these conditions are met, the decision logic can be expressed as universal rules applied to multi-valued node values. Decision Designer implements these rules by using quantifiers.

Limitations

This approach works when decision logic fits within a single decision table. More complex scenarios requiring multiple interconnected decision nodes need advanced techniques that are covered in the next task.