Problem
We need to help a manufacturer decide how much of each demanded product should be produced internally and how much should be sourced from outside. Whether a product is made inside or outside, it has an associated cost. A product can consume a given amount of internal resources that have limited capacities. The general objective is to minimize the total production cost while ensuring the company meets the demand exactly or with a certain tolerance. This DMCommunity challenge provides the following data samples with products, resources, and capacity requirements:

The manufacturer wants to consider various production decisions to choose the most suitable ones based on the long-term resource availability and uncertain future demand. This sample demonstrates how OpenRules Decision Playground can be used to find the best production decision.
Decision Model
The proper decision model is implemented as a simple project, “InsideOutsideProduction” coming with OpenRules Rule Solver. This example is based on the decision model “InsideOutsideProduction” located in “openrules.solver/ADVANCED”.
Here is the Glossary:

Here are two main methods, “Define” and “Solve”, that are pretty common for decision models utilizing Rule Solver:

The table “DefineProductVariables” for each product P in the input array “Products” defines the proper constrained decision variables with names like “InsideP1” or “OutsideP2” with possible values from 0 to the Demand of this particular product:

It also defines the demand variables like “DemandP1” that should be equal to the sum of variables “InsideP1” and “OutsideP1”. It adds the product variables to the arrays “InsideVariables” and “OutsideVariables” that will be needed to specify optimization objectives.
The table “PostDemandConstraints” for each product P in the input array “Products” posts a constraint that states that the proper demand decision variable should not be less than the required demand of this product:

The table “ConsumptionConstraints”

for each resource R in the array “Resources” does the following. First, it executes this table to define an array with all resource consumption variables for each consumption in the array “Consumptions”:

Then it executes this table to post the main consumption constraint for each resource:

To define optimization objectives, first we need to use temporary arrays “InsideCosts” and “OutsideCosts” that can be easily filled out by the regular OpenRules decision table “DefineInOutCosts”:

The following table defines all optimization objectives as new constrained decision variables:

The table “Solve” relies on the standard solving method “SolveWithOptions”. When a solution is found, this method automatically invokes the method “SaveSolution” if it exists. This decision model saves every solution using the following table:

Here are the execution results for the first test case:

We relied on the default solver which was Constrainer. The execution time took ~100 seconds. We can switch to a linear solver to make the execution much faster.
Switching Underlying Solvers
OpenRules Rule Solver utilizes the standard JSR-331 API that allows you to easily switch between different constraint solvers and linear or MIP solvers without changing a character in your decision model. You start Rule Solver using a simple batch file “test.bat” that looks as follows:

To instruct Rule Solver to use an alternative solver, simply uncomment the corresponding setting above. For example, you can modify the above settings as follows:

Upon restarting, the linear solver CLP or a similar open-source or commercial MIP solver will be used, resulting in a substantial performance gain for this decision model. An optimal solution will be produced within 1 second, compared to the previous 100 seconds.
Note. Not all decision models can use superfast linear or MIP solvers, as they may contain non-linear constraints. In these cases, you may rely on open-source constraint solvers such as “Constrainer” that are built into the OpenRules Rule Solver.


