Revealing Robustness in Linear Optimization Problems using Monte Carlo Simulation in Python | by Tellef Solberg | Towards Data Science

We will do the following:> Construct a deterministic linear programming problem using PuLP> Apply Monte Carlo simulations on the problem> Interpret the results using data visualization
The linear programming problem we are going to solve is the following:
A manufacturer of specialized industrial windows has three products in its product line, and these are called ‘Small’, ‘Medium’ and ‘Large’. We get the following data:
1. The associated operating profits pr. product is 12, 12.5 and 12 respectively. 2. The working hours needed pr. product is 2.5, 3 and 8 respectively with a total of 1000 hours available for production.3. The square feet needed pr. product is 18, 18 and 19 respectively with a total of 1500 square feet available at the plant4. A delivery contract forces production of at least 8 Large windows
Using the data above, determine the profit-maximizing production plan for the manufacturer:
Let's implement this in python with the linear programming package, PuLP. PuLP can easily be installed by writing the following text in the cmd-line:
pip install pulp
The implementation of the linear program goes as follows:
The optimized objective function and decision variables gives the following:
Objective Function = 1021.00
Production of Large = 8Production of Medium = 74Production of Small = 0
Thus, no other production plan will give higher profits than this exact combination. It seems that ‘Medium’ is profitable and also does not consume too much of the constraints, so a big allocation to this product seems valid. However, what if the demand for Medium sized windows is quite volatile? Do we still risk a production of as much as 74?
Let's assume that the profits of ‘Medium’ windows follow a normal distribution of N(0,2) based on historical figures.
We make these alterations to the objective function and set a seed of choice. These changes can be found on lines 3,6,7 and 18. All else is kept equal:
The slightly changed optimization program now gives us the following results:
Objective Function = 984.00
Production of ‘Large’ = 8Production of ‘Medium’ = 0Production of ‘Small’ = 74
Note that the new optimized production plan sets production of medium sized windows to zero! As we clearly can see, exposing the deterministic model to randomness can truly reveal the robustness of the production plan. When inspecting the objective function further, we can see that for this particular simulation experiment, the profit of ‘Medium’ is set to 10.5 (this can be done by printing the model variable). This obviously favors more production of the small sized windows as the profits are higher relative to ‘Medium’ and it also consumes less working hours.
However, we should not be satisfied with just one experiment. Therefore, let's conduct 1000 Monte Carlo simulations on this optimization problem and interpret the results in histograms:
The code above generates the following histograms of optimized decision variables:
From the 1000 simulation runs, there are several interesting insights. Firstly, and obviously not shockingly, the production of Large windows will always remain at 8. This is due to the working hours consumption of 8 hours pr. unit which is significantly more than for the other two. Secondly, we see that the optimal choice of ‘Small’ and ‘Medium’ shifts between 0 and 74 with no observations in between. Since ‘Medium’ initially has a better profit than ‘Small’ by 0.5, it is optimal to max out production on the product in 600 simulation runs. And likewise, production of 74 small windows is optimal in 40% of the simulation runs. As a production planner, this is very valuable information, and strategies should be put in place to mitigate the risk of committing to the wrong production plan. It seems that trusting deterministic models such as the initial one might have dramatic consequences.
To conclude, one should be very careful to follow the output of deterministic optimization models. Running simulations and exposing it to randomness (even in the slightest) should reveal how well the optimal proposition was in the first place.
A good analogy i like to use is: a soldier is working on his optimal shooting position in order to keep a steady aim. When the sergeant comes by and tries to disturb the solider slightly, we get a good sense of how the soldiers aim and shooting position really is. Here, Aiming is optimization and getting disturbed is simulation.