Path: blob/main/notebooks/02/07-bim-demand-forecast.ipynb
663 views
2.7 BIM production using demand forecasts
Preamble: Install Pyomo and a solver
The following cell sets and verifies a global SOLVER for the notebook. If run on Google Colab, the cell installs Pyomo and the HiGHS solver, while, if run elsewhere, it assumes Pyomo and HiGHS have been previously installed. It then sets to use HiGHS as solver via the appsi module and a test is performed to verify that it is available. The solver interface is stored in a global object SOLVER for later use.
The problem: Optimal material acquisition and production planning using demand forecasts
This example is a continuation of the BIM chip production problem illustrated here. Recall hat BIM produces logic and memory chips using copper, silicon, germanium, and plastic and that each chip requires the following quantities of raw materials:
| chip | copper | silicon | germanium | plastic |
|---|---|---|---|---|
| logic | 0.4 | 1 | - | 1 |
| memory | 0.2 | - | 1 | 1 |
BIM needs to carefully manage the acquisition and inventory of these raw materials based on the forecasted demand for the chips. Data analysis led to the following prediction of monthly demands:
| chip | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| logic | 88 | 125 | 260 | 217 | 238 | 286 | 248 | 238 | 265 | 293 | 259 | 244 |
| memory | 47 | 62 | 81 | 65 | 95 | 118 | 86 | 89 | 82 | 82 | 84 | 66 |
At the beginning of the year, BIM has the following stock:
| copper | silicon | germanium | plastic |
|---|---|---|---|
| 480 | 1000 | 1500 | 1750 |
The company would like to have at least the following stock at the end of the year:
| copper | silicon | germanium | plastic |
|---|---|---|---|
| 200 | 500 | 500 | 1000 |
Each raw material can be acquired at each month, but the unit prices vary month by month as follows:
| product | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| copper | 1 | 1 | 1 | 2 | 2 | 3 | 3 | 2 | 2 | 1 | 1 | 2 |
| silicon | 4 | 3 | 3 | 3 | 5 | 5 | 6 | 5 | 4 | 3 | 3 | 5 |
| germanium | 5 | 5 | 5 | 3 | 3 | 3 | 3 | 2 | 3 | 4 | 5 | 6 |
| plastic | 0.1 | 0.1 | 0.1 | 0.1 | 0.1 | 0.1 | 0.1 | 0.1 | 0.1 | 0.1 | 0.1 | 0.1 |
The inventory is limited by a capacity of a total of 9000 units per month, regardless of the type of material of products in stock. The holding costs of the inventory are 0.05 per unit per month regardless of the material type. Due to budget constraints, BIM cannot spend more than 5000 per month on acquisition.
BIM aims at minimizing the acquisition and holding costs of the materials while meeting the required quantities for production. The production is made to order, meaning that no inventory of chips is kept.
Let us model the material acquisition planning and solve it optimally based on the chip demand forecasted above. First import both the price and forecast chip demand as Pandas dataframes.
We can also add a small dataframe with the consumptions and obtain the monthly demand for each raw material using a simple matrix multiplication.
The optimization model
Define the set of raw material and the set of the months of the year. Let
be the variable describing the amount of raw material acquired in month ;
be the variable describing the amount of raw material left in stock at the end of month . Note that these values are uniquely determined by the variables, but we keep these additional variables to ease the modeling.
The total cost is the objective function of our optimal acquisition and production problem. If is the unit price of product in month and the unit holding costs (which happen to be constant) we can express the total cost as:
Let us now focus on the constraints. If denotes the monthly acquisition budget, the budget constraint can be expressed as:
Further, we constrain the inventory to be always the storage capacity using:
Next, we add another constraint to fix the value of the variables by balancing the acquired amounts with the previous inventory and the demand which for each month is implied by the total demand for the chips of both types. Note that is defined as the initial stock when is the first period, that is \texttt{January}. This can be obtained with additional variables made equal to those values or with a rule that specializes, as in the code below.
Finally, we capture the required minimum inventory levels in December with the constraint.
where is the vector with the desired end inventories.
Here is the Pyomo implementation of this linear problem.
We now can create an instance of the model using the provided data and solve it.
Here is a different solution corresponding to the situation where the budget is much lower, namely 2000.
Looking at the two optimal solutions corresponding to different budgets, we can note that:
The budget is not limitative;
With the initial budget of 5000 the solution remains integer;
Lowering the budget to 2000 forces acquiring fractional quantities;
Lower values of the budget end up making the problem infeasible.
A more parsimonious model
We can create a more parsimonious model with fewer variabels by getting rid of the auxiliary variables . Here is the corresponding implementation in Pyomo: