Advanced DMN™ Modeling Techniques¶
Introduction¶
After mastering the basics of DMN, you're ready to explore more advanced modeling techniques. This guide builds on your foundation to help you create sophisticated decision models that can handle complex business scenarios.
We'll cover advanced features like Business Knowledge Models (BKMs), complex data types, list operations, and context expressions. Throughout this guide, we'll use a travel insurance pricing example to illustrate these concepts.
Working with Complex Data Types¶
Real-world decisions often require more complex data than simple numbers or strings. DMN allows you to define custom data structures to model your business domain accurately. In this case we're going to build a DMN model for a travel insurance situation for someone building an itinerary to travel to potentially multiple countries and we want to determine how much it will cost to give that person a travel insurance policy. The factors that will be discussed in the next section focused on Creating Custom Data Types.
Creating Custom Data Types¶
In our travel insurance example we are going to be looking at building a both a traveler and the trip details as complex data objects:
-
A Traveler with:
- Age
- Claim history
- Medical conditions
-
Trip Details with:
- Countries to visit
- Start date
- End date
Here's how to create these data structures:
- Navigate to Aletyx Playground in your browser
- From the landing page, click New Decision to create a new DMN model
- You'll be presented with an empty DMN model editor. This is where we'll design our decision model
- First, change the name of the model from "Untitled" to "travelPremium"
- In Aletyx Playground, open the properties panel (press "i" with nothing selected)
- Click on "Data Types"
- Click "Add" to create a new data type
For the Traveler:
| Property | Type | Is Collection |
|---|---|---|
| age | number | no |
| claim history | Claim | yes |
| medical conditions | string | yes |
| tDate | date | no |
For the Claim structure:
| Property | Type | Is Collection | Allowed Values |
|---|---|---|---|
| total claim amount | number | no | |
| status | string | no | Approved, Denied, Pending |
| tDate | date | no |
For the Trip Details:
| Property | Type | Is Collection |
|---|---|---|
| country | string | yes |
| start date | date | no |
| end date | date | no |
Using Complex Types in Decision Models¶
Once defined, you can use these types for Input Data nodes:
- Create an Input Data node named "Traveler"
- Set its data type to "Traveler"
- Create an Input Data node named "Trip Details"
- Set its data type to "Trip Details"
Now your decisions can reference properties of these complex types using dot notation:
Traveler.ageTraveler.medical conditionsTrip Details.country
Working with Lists and Collections¶
DMN provides powerful capabilities for working with collections of values. In our travel insurance example, we need to:
- Evaluate multiple medical conditions
- Assess risk across multiple countries
- Analyze claim history
Iterating Over Collections¶
To check if any medical condition is high-risk:
some condition in Traveler.medical conditions
satisfies list contains(["heart disease", "cancer"], condition)
This FEEL expression:
- Iterates through each item in the "medical conditions" list
- Checks if the condition is in the high-risk list
- Returns true if any condition matches
Filtering Collections¶
To count approved claims:
This expression:
- Filters the claim history to only include approved claims
- Counts the resulting filtered list
Collection Functions¶
DMN includes built-in functions for collections:
count(list): Returns the number of items in a listsum(list): Adds all numeric values in a listmin(list)/max(list): Returns the smallest/largest valuemean(list): Calculates the average of numeric valueslist contains(list, element): Checks if an element is in a list
Business Knowledge Models (BKMs)¶
Business Knowledge Models (BKMs) are reusable decision logic components that can be invoked from multiple places in your model. They're perfect for encapsulating complex logic or reference data.
Creating a BKM for Country Risk Assessment¶
In our travel insurance example, we'll create a BKM to evaluate country risk levels:
- Add a Business Knowledge Model node to your diagram
- Name it "Country Risk Level"
- Edit the node and set its logic type to "Function"
- Define a parameter named "country" of type "string"
- Return type should be "string"
Create a decision table within the function:
| country | Country Risk Level | Annotation |
|---|---|---|
| "Iraq" | "High" | War zone |
| "Syria" | "High" | Civil unrest |
| "Brazil" | "Medium" | Crime rates |
| "Mexico" | "Medium" | Border areas |
| - | "Low" | Default |
Invoking a BKM¶
To use the BKM in a decision:
This will return "Medium" based on our decision table.
Context Expressions¶
Contexts in DMN allow you to create local variables and build complex expressions step by step. They're excellent for breaking down complex logic.
Using Context for Destination Risk Factor¶
For our travel insurance example, we'll calculate a risk factor based on destinations:
- Create a decision named "Destination Risk Factor"
- Set the expression type to "Context"
- Create context entries:
| ContextEntry | Type | Expression | Content |
|---|---|---|---|
| "Highest Risk" | (String) | FEEL | See: Risk Context Entry |
| "Risk Factor" | (number) | Decision Table | See: Decision Table Context Highest Risk |
FEEL Expression: Highest Risk Context Entry¶
if
some country in Trip Details.country
satisfies Country Risk Level(country) = "High"
then "High"
else if
some country in Trip Details.country
satisfies Country Risk Level(country) = "Medium"
then "Medium"
else "Low"
Decision Table: Highest Risk Context Entry¶
The best part about the DMN editor for Decision Tables is you can copy the contents of the three rows and directly paste them into your decision table!
| Highest Risk (String) | Risk Factor (Number) | Annotations |
|---|---|---|
| "High" | 1.6 | // High Risk Factor |
| "Medium" | 1.4 | // Medium Risk Factor |
| "Low" | 1 | // Low Risk Factor |
The result of the context is the last entry (Risk Factor).
Advanced Hit Policies¶
DMN provides various hit policies for decision tables to handle different evaluation requirements.
Collect Hit Policy with Custom Aggregation¶
For our medical condition assessment:
- Create a decision table with hit policy "Collect"
- Select "MAX" aggregation to get the highest risk factor
| Traveler.medical conditions (string) | Medical Condition Assessment | Annotation |
|---|---|---|
| some condition in ? satisfies list contains(["heart disease", "cancer"], condition) | 2.0 | High risk |
| some condition in ? satisfies list contains(["diabetes", "asthma"], condition) | 1.5 | Medium risk |
| some condition in ? satisfies list contains(["high blood pressure"], condition) | 1.2 | Low risk |
| - | 1.0 | No risk |
Rule Order Hit Policy¶
When you need to evaluate rules in a specific sequence:
- Set hit policy to "R" (Rule order)
- Rules are evaluated from top to bottom
- The first matching rule provides the result
This is useful when rules have priorities or dependencies.
Handling Dates and Time¶
DMN includes robust support for date and time operations, essential for time-sensitive decisions.
Date Comparisons¶
To calculate the trip duration:
Date Arithmetic¶
To check if a claim is recent:
This filters claims made within the last year.
Combining Multiple Decision Models¶
Complex applications often require multiple decision models working together.
Importing Models¶
To reuse logic from another model:
- In the DRD, click the "Import" button
- Select the DMN file you want to import
- Reference imported decisions and BKMs in your model
Decision Services¶
Decision Services define a public interface for your DMN model:
- Add a Decision Service node to your diagram
- Drag the decisions you want to expose into the node
- Specify input data and decisions
This creates a well-defined API for your decision model.
Testing Advanced DMN Models¶
Thorough testing is crucial for complex decision models.
Test Scenarios¶
Create comprehensive test scenarios:
{
"Traveler": {
"age": 42,
"claim history": [
{
"total claim amount": 1200,
"status": "Approved",
"tDate": "2023-05-15"
}
],
"medical conditions": ["asthma", "high blood pressure"]
},
"Trip Details": {
"country": ["France", "Germany", "Brazil"],
"start date": "2024-06-01",
"end date": "2024-06-15"
}
}
Debugging Techniques¶
When debugging complex models:
- Use the DMN Runner to execute with sample data
- Add intermediate decisions to expose internal calculations
- Review the execution trace to understand evaluation paths
- Test boundary cases for each decision component
Performance Considerations¶
As your models grow in complexity, consider these performance tips:
- Limit Collection Size: Large collections can impact performance
- Optimize Decision Order: Structure decisions to minimize redundant calculations
- Use BKMs Judiciously: They add overhead for simple logic
- Consider Caching: For frequently accessed reference data
- Test with Realistic Volumes: Validate performance with production-like data
Best Practices for Advanced DMN¶
- Maintain a Clear Hierarchy: Structure your decisions logically
- Document Your Models: Add annotations to explain complex logic
- Create Reusable Components: Use BKMs for shared logic
- Validate with Business Experts: Ensure the model aligns with business intent
- Iterate and Refine: Complex models benefit from continuous improvement
Conclusion¶
You now have a toolbox of advanced DMN techniques to tackle complex decision requirements. By leveraging these features, you can create sophisticated, maintainable decision models that accurately capture your business logic.
In our next guide, Advanced Deployment Options, we'll explore how to deploy these complex models in production environments.