OpenRules offers two open source products to support an integrated use of “Business Decision Modeling with Rule Engines and CP/LP Solvers“:
- OpenRules – for business decision models
- Java Solver – for optimization models.
In this post I will describe how you can deploy decision optimization models as AWS Decision Microservices without programming or complex configuration.
Of course, we can deploy a JavaSolver-based program as a AWS Lambda function as we can do with any other Java program. For instance, we may follow a path similar to the one described here:
- Put them into SpringBoot Environment
- Add several Java classes required by Spring for the service configuration
- Configure the service using AWS Lambda and AWS Gateway.
However, what I really wanted to do is to be able to deploy optimization models as AWS Lambdas with ONE CLICK and no additional programming! We already achieved this for pure rules-based decision services. Now I will be glad to share how it can be done. The basic idea is very simple:
- As usual, describe your Business Problem using regular business rules in Excel in the OpenRules format
- Write a Java class called Optimization Problem (inherited from JavaSolver) to define your optimization problem
- Create an Excel-based table “SolveOptimizationProblem” of the OpenRules type “Method”
- Use the standard “deployLambda.bat” to deploy the integrated model as AWS Lambda microservice.
The 3rd step is the most interesting one. It allows us to treat a Java-based Optimization Problem as a part of the rules-based decision model, and thus utilize the standard OpenRules deployment mechanism! Similarly we can deploy optimization models using RESTfull web services or Docker containers. While JavaSolver allows you to choose different off-the-shelf constraint or linear solvers, there is nothing that prevent us of integrating OpenRules directly with other Java-based solvers.
Below I will describe a specific example that explains in details how to deploy the decision model “Advanced Vacation Days” with an optimization component as an AWS Lambda. This problem was offered as the DMCommunity Nov-2018 Challenge :
Every employee receives vacation days according to the following rules:
- Every employee receives at least 22 vacation days.
- Employees younger than 18 or at least 60 years, or employees with at least 30 years of service can receive extra 5 days.
- Employees with at least 30 years of service and also employees of age 60 or more, can receive extra 3 days, on top of possible additional days already given
- If an employee has at least 15 but less than 30 years of service, extra 2 days can be given. These 2 days can also be provided for employees of age 45 or more.
- A college student is eligible to 1 extra vacation day.
- If an employee is a veteran, 2 extra days can be given.
- The total number of vacation days cannot exceed 29.
The objective: give an employee as many vacation days as s/he is eligible to while satisfying all 7 rules. The rule 7 explicitly specifies the maximum of 29 vacation days that cannot be exceeded.
My new solution is implemented in the project “VacationDaysOptimization” that will be included in the standard OpenRules Decision Manager installation. This decision model consists of two parts:
- A pure business part that specifies employee eligibility to all types of vacation days
- A more technical optimization part that deals with the Rule 7 and search of an optimal solution.
Business Data. Let’s start with the test data. We will need an information about the company that should include:
- Vacation Benefit Types
- Vacation Benefit Days (for each type)
- Max Vacation days (29)
Here is the proper Data table:
We also may define the corresponding Java class Company:
The following table describes test-employees:
And here is the corresponding Java class:
Each employee contains an array of eligibilities of this type:
Business Part. The following decision table defines eligibility of one employee to different vacation benefits:
To execute this table for all types of vacation benefits, we will use the following table:
Optimization Part. We will use JavaSolver to represent optimization logic in the Java class “OptimizationProblem”:
To invoke this problem from Excel we define the following method:
And finally our decision model may use the following table to execute both business and optimization parts:
To test and deploy this integrated decision model we need to specify the file “project.properties”:
As you can see, it already contains AWS Lambda deployment properties. So, it’s enough to double-click to the standard OpenRules file “deployLambda.bat” and it will generate all necessary Java files and will deploy this integrated Rule+Optimization decision model as AWS Lambda microservice:
If we run the generated “testLambda.bat” it will execute all out tests with an average execution time (including optimization!) withing 100 milliseconds!