Vacation Days Advanced

This decision model demonstrates how to apply Rule Solver to the business decision model “Vacation Days Advanced” that requires optimization. We will follow this implementation steps:

  1. Problem Description and Analysis
  2. Test Cases and Glossary
  3. Business Logic Implementation
  4. Testing
  5. Deployment as AWS Lambda.

Problem Description and Analysis. This problem was defined in the DMCommunity Challenge. Every employee receives vacation days according to the following rules:

The objective of this problem is to give an employee as many vacation days as s/he is eligible to while satisfying all 7 rules. Rule 7 explicitly specifies the maximum of 29 vacation days that could be given to any employee. However, now not only Rule 2 and 4 can take us above the 29 days limit but many other combinations of extra days can do it as well. If we apply traditional rules-based approach such as DMN, we would need to consider ALL possible combinations of extra days that would lead us to unmaintainable rules. So, it’s much more practical to apply an integrated business rules and optimization approach within the same decision model.

Test Data. Before jumping to the implementation, we should define test data for our future decision model. The following Excel table in the OpenRules format describes a Company “ABC” with its 6 Vacation Benefit Types and the corresponding Vacation Benefit Days. It also includes the “Max Vacation Days” limit of 29 days:

The following table describes different employees of the company XYZ that will be used for testing of our decision model:

And we will define various test cases with expected results in the column “Total Vacation Days” in this table:

We will keep these tables in the Excel file “rules/Test.xls”

Glossary. We will define the corresponding glossary as follows:

Business Logic Implementation. Our business logic should define Solver’s decision variables (unknowns of the problem) that represent employee eligibility to all benefit types of the Company’s vacation days using the above rules from 1 to 6. 

The first row of this table will create an array of constrained variables called “Eligibility Variables” using the predefined method “NewVariables“. For each element of the input array “Vacation Benefit Types” (defined inside “Company” in the glossary) it will add a constrained variable named by the proper benefit type with possible values 0 or 1. All these constrained variables will be added to the array “Eligibility Variables”.

The second row of this table will create an constrained variable “Total Vacation Days” equal to the scalar product of just created array of constrained variables “Eligibility Variables” and the input array “Vacation Benefit Days” (defined inside “Company” in the glossary) with some already known integer values. Here we used the predefined method “ScalarProduct“.

To implement the limitations expressed in the rules 1-7, we need to post the proper constraints. The table “DefineEligibilities”

iterates through all “Vacation Benefit Types” (defined inside “Company” in the glossary) and based on the current value of the “BenefitType” post constraint “Eligible” or “Not Eligible”. To do that it uses the predefined column “SolverPostConstraints” and the method “VarOperValue“. For example for the “Basic” benefit type it will force the corresponding constrained variable (with the unique name “Basic”) to be equal to 1. Similarly, for the benefit type “StudentBenefit” it will set the corresponding constrained variable to 0 if the employee is not a student.

And to complete the problem definition we will limit the “Total Vacation Days” to “Max Vacation Days” (defined as 29) using the following table:

Finally, we use the following tables “Define” and “Solve” to Define and Solve the problem:

The table “Solve” uses the predefine column “SolverOptimize” to express that problem objective that is maximize the “Total Vacation Days” using all combinations of eligible benefits.

Testing Decision Model. To execute this decision model against the above test cases we can double-click on the standard batch file “test.bat”:

Here are the execution results for the first test:

Deployment as AWS Lambda. To deploy the tested decision model as a decision microservice, we can use the standard OpenRules one-click AWS Lambda deployment mechanism.

Now we can simply double-click on the standard file “deployLambda.bat”. We also can test a newly created AWS Lambda function using the generated file “testLambda.bat” (it includes the invoke  URL).  The execution protocol shows the automatically generated JSON for every test. Then we can use it to test the same Lambda function from the POSTMAN. Here is the execution request and response:

More examples of optimization decision models with all sources are included in the standard Rule Solver’s installation.

THE END