Decision Model “Permit Eligibility”

In this post we describe an OpenRules decision model that addresses DMCommunity.org Mar-2023 Challenge “Permit Eligibility”. The Challenge asks to implement this rule: “An applicant is eligible for a resident permit if the applicant has lived at an address while married and in that time period, they have shared the same address at least 7 of the last 10 years.” There is already 2 DMN-based solutions published by Bruce Silver who explained that this simply sounding rule requires to address several not so simple considerations. There is also an attempt to create a decision model with ChatGPT, which I analyzed and converted to a working Java code. I asked an OpenRules developer Alex Mirtsyn to look at this problem, and together we came up with a solution described in this post.

Building Test Cases

We started not with rules but with creation of test cases with manually defined results in accordance with the test-driven decision modeling approach. Each test has a DecisionTest table that looks as below:

Then we created in Excel 10 different test cases (see Test.xls) by defining 3 DecisionData tables used in the first 3 blue columns. Here are 3 test lists proposed in the Challenge “Permit Eligibility”:

It was not difficult to manually calculate that this applicant is NOT eligible for a resident permit because there are only 2 eligible periods:

  • [2013-03-04; 2015-12-31]  1032 days
  • [2021-01-01; 2023-03-04]    792 days

It means the total number of days within the last 10 years (starting from 2023-03-04) when the applicant and spouse lived at the same address while married is 1824 that is certainly less than 7 years.

We tried to cover different combinations of the above 3 lists, Application Date, and the expected Permit Eligibility. in out test cases. Building and manually evaluating these test cases allowed us to gain a good understanding of this business problem.

Defining Glossary

To run the above test cases even before we specified the rules, we only needed to create the Business Glossary. Here it is:

It was clear for us that along with the resulting “Permit Eligibility” (Eligible,Ineligible) we will need the explanations for such decisions. We also need to calculate “Number of Days in 7 Years” and “Application Date Minus 10 Years” that was done in this table:

Representing Business Rules

After considering different approaches for representation of the business logic, we decided to do it in 3 steps:

  1. Determine SharedResidencePeriods since “Application Date Minus 10 Years” when Applicant and Spouse lived at the same address
  2. Determine Shared Days in all intersections of SharedResidencePeriods and MarriagePeriods
  3. Determine Permit Eligibility

The first step can be implemented by two nested loops defines below:

They execute these rules:

The second and third rules in the single-hit decision table “CheckSharedPeriods” were added to exclude periods that could occur after Application Date (while it is probably almost impossible situations we decided to add these rules to support our test cases) .

The second step can be implemented by two nested loops defined below:

The third step can be implemented by the following decision table:

Decision Model Diagram

This decision model was visualized in OpenRules Explorer as the following diagram:

It was helpful to use OpenRules Debugger to iterate over nested loops, execute rules one-by-one, and analyze all related decision variables. It helped us to fix a few bugs and improve the decision model.

Execution Results

For the test case defined in the Challenge, we received the following results:

We successfully executed this decision model against ALL test cases mentioned above.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.