Red Hat Training

A Red Hat training course is available for Red Hat Decision Manager

Chapter 2. Decision Model and Notation (DMN)

Decision Model and Notation (DMN) is a standard established by the Object Management Group (OMG) for describing and modeling operational decisions. DMN defines an XML schema that enables DMN models to be shared between DMN-compliant platforms and across organizations so that business analysts and business rules developers can collaborate in designing and implementing DMN decision services. The DMN standard is similar to and can be used together with the Business Process Model and Notation (BPMN) standard for designing and modeling business processes.

For more information about the background and applications of DMN, see the OMG Decision Model and Notation specification.

2.1. Creating the traffic violations DMN decision requirements diagram (DRD)

A decision requirements diagram (DRD) is a visual representation of your DMN model. Use the DMN designer in Business Central to design the DRD for the traffic violations project and to define the decision logic of the DRD components.

Figure 2.1. DRD for the Traffic Violations example

dmn traffic violations drd

Prerequisite

  • You have created the traffic violations project in Business Central.

Procedure

  1. On the traffic-violation project’s home screen, click Add Asset to open the Add Asset screen.
  2. Click DMN to open the Create new DMN dialog.

    1. Enter Traffic Violation in the Name field.
    2. From the Package list, select org.kie.example.traffic.traffic_violations.
    3. Click Ok to open the DMN asset in the DMN designer.
  3. In the DMN designer canvas, drag two input nodes to the canvas. Double-click the input nodes and rename them as Driver and Violation.
  4. Drag a decision node to the canvas. Double-click and rename it as Fine.
  5. Click the Violation input node and select the Create DMN Information Requirement option to connect to the Fine decision node.
  6. Drag another decision node to the canvas and double-click and rename it as Should the driver be suspended?.
  7. Click the Driver input node and select the Create DMN Information Requirement option to connect to the Should the driver be suspended? decision node.
  8. Click the Fine decision node and select the Create DMN Information Requirement option to connect to the Should the driver be suspended? decision node.
  9. Click Save to open the Confirm Save dialog box and click Save again.

2.2. Creating the traffic violations DMN custom data types

DMN data types determine the structure of the data that you use within a table, column, or field in a DMN boxed expression for defining decision logic. You can use default DMN data types (such as string, number, or boolean) or you can create custom data types to specify additional fields and constraints that you want to implement for the boxed expression values. Use the DMN designer’s Data Types tab in Business Central to define the custom data types for the traffic violations project.

Figure 2.2. The custom data types tab

dmn custom datatypes tab

Alternately, you can also access the Data Types tab from the Diagram properties tab on the right. From the Diagram properties tab, click Manage from Output data types under Information item.

Figure 2.3. Diagram properties tab

dmn diagram properties tab

The following tables list the Violation, Driver, and Fine custom data types that you will create for this project.

Table 2.1. Driver custom data types

NameType

tDriver

Structure

Name

string

Age

number

State

string

City

string

Points

number

Table 2.2. Violation custom data types

NameType

tViolation

Structure

Code

string

Date

date

Type

string

Speed Limit

number

Actual Speed

number

Table 2.3. Fine custom data types

NameType

tFine

Structure

Amount

number

Points

number

Prerequisite

  • You have created the traffic violations DMN decision requirements diagram (DRDs) in Business Central.

Procedure

  1. From the Data Types tab, click Add.
  2. First, create the tDriver custom data type. Enter tDriver as the Name and select Structure as the Type. Click Save for each data type that you add.

    Figure 2.4. The tDriver custom data type

    dmn tDriver custom datatype
  3. Next to the tDriver data type, click the three vertical dots, select Insert nested field, and add the following nested data types. Click Save for each data type that you add.

    • Name (string)
    • Age (number)
    • State (string)
    • City (string)
    • Points (number)
  4. Next, create the tViolation data type. From the Data Types tab, click Add.

    Figure 2.5. The tViolation custom data type

    dmn tViolation custom datatype
  5. Enter tViolation as the Name and select Structure as the Type. Click Save to save the data type.
  6. Next to the tViolation data type, click the three vertical dots, select Insert nested field, and add the following nested data types. Click Save for each data type that you add.

    • Code (string)
    • Date (date)
    • Type (string)
    • Speed Limit (number)
    • Actual Speed (number)
  7. For the nested Type data type that you created, click EditConstraintsEnumeration and add the following constraints. Click the check icon dmn datatype constraints tickmark to save each enumeration constraint that you add.

    • "speed"
    • "parking"
    • "Driving under the influence?"
  8. Finally, create the tFine data type. From the Data Types tab, click Add.

    Figure 2.6. The tFine custom data type

    dmn tFine custom datatype
  9. Enter tFine as the Name and select Structure as the Type. Click Save to save the data type.
  10. Next to the tFine data type, click the three vertical dots, select Insert nested field, and add the following nested data types. Click Save for each data type that you add.

    • Amount (number)
    • Points (number)
  11. Once all the three custom data types are created, click Save to open the Confirm Save dialog box and click Save again.

2.3. Assigning custom data types to the DRD input and decision nodes

After you create the DMN custom data types, assign them to the appropriate DMN Input Data and DMN Decision nodes in the traffic violations DRD.

Prerequisite

  • You have created the traffic violations DMN custom data types in Business Central.

Procedure

  1. Click the Model tab on the DMN designer and click Diagram properties in the top-right corner of the DMN designer to expose the DRD properties.
  2. In the DRD, select the Driver input data node and in the Diagram properties panel, set Output data type to tDriver.
  3. Select the Violation input data node and set the Output data type to tViolation.
  4. Select the Fine input data node and set the Output data type to tFine.
  5. Select the Should the driver be suspended? decision node and set the following properties:

    • Output data type: string
    • Question: Should the driver be suspended due to points on his driver license?
    • Allowed Answers: "Yes","No"
  6. Click Save to open the Confirm Save dialog box and click Save again.

You have assigned the custom data types to your DRD’s input and decision nodes.

2.4. Defining the traffic violations DMN decision logic

To calculate the fine and to decide whether the driver is to be suspended or not, you can define the traffic violations DMN decision logic using a DMN decision table and context boxed expression.

Figure 2.7. Fine decision table

dmn gs fine decision table

Figure 2.8. Should the driver be suspended? context boxed expression

dmn gs context table

Prerequisite

  • You have assigned the DMN custom data types to the appropriate decision and input nodes in the traffic violations DRD in Business Central.

Procedure

  1. To calculate fine, in the DMN designer canvas, select the Fine decision node and click the Edit icon to open the DMN boxed expression designer.
  2. Click Select expressionDecision Table.
  3. For the Violation.Date, Violation.Code, and Violation.Speed Limit parameter fields, right-click and select Delete Input Clause for each field.
  4. Click the Violation.Actual Speed column header and enter the expression Violation.Actual Speed - Violation.Speed Limit in the Name field.
  5. Right-click the Fine parameter field and select either Insert Output Clause left or Insert Output Clause right.
  6. Click the output-2 column sub-header, enter Amount in the Name field, and select number from the Data Type field.
  7. Similarly, click the output-1 column sub-header, enter Points in the Name field, and select number from the Data Type field.
  8. Next, enter the following values in the first row of the decision table:

    • Violation.Type: "speed"
    • Violation.Actual Speed - Violation.Speed Limit: [10..30]
    • Amount: 500
    • Points: 3

      Right-click the first row and select Insert rule below to add another row.

  9. Enter the following values in the second row of the decision table:

    • Violation.Type: "speed"
    • Violation.Actual Speed - Violation.Speed Limit: > 30
    • Amount: 1000
    • Points: 7

      Right-click the second row and select Insert rule below to add another row.

  10. Enter the following values in the third row of the decision table:

    • Violation.Type: "parking"
    • Violation.Actual Speed - Violation.Speed Limit: -
    • Amount: 100
    • Points: 1

      Right-click the third row and select Insert rule below to add another row.

  11. Enter the following values in the fourth row of the decision table:

    • Violation.Type: "driving under the influence"
    • Violation.Actual Speed - Violation.Speed Limit: -
    • Amount: 1000
    • Points: 5
  12. Click Save to open the Confirm Save dialog box and click Save again.
  13. To define the driver suspension rule, return to the DMN designer canvas, select the Should the driver be suspended? decision node, and click the Edit icon to open the DMN boxed expression designer.
  14. Click Select expressionContext.
  15. Click ContextEntry-1, enter Total Points as the Name, and select number as the Data Type.
  16. Click the cell next to Total Points, select Literal Expression from the context menu, and enter Driver.Points + Fine.Points as the expression.
  17. In the cell below Driver.Points + Fine.Points, select Literal Expression from the context menu, and enter if Total Points >= 20 then "Yes" else "No".
  18. Click Save to open the Confirm Save dialog box and click Save again.

    You have defined how to calculate the fine and the context for deciding when to suspend the driver. You can navigate to the traffic-violation project page and click Build to build the example project and address any errors noted in the Alerts panel.