Simulation testing solution
1. Simulation testing solution
In this lesson we will review simulation testing our solutions.2. Caution
Before we begin, a warning. This technique has limited use for LP or IP problems that take a long time to solve. We will be repeatedly solving the model and the time can add up.3. Overall concept
This simulation technique mixes a Monte Carlo Simulation with Linear Programing. In general, we are trying to add random noise to key inputs to the model. This can include values in the objective function or constraints. After adding noise to the inputs, we repeatedly solve the LP model. Finally, we observe the distribution of the results, which might include values of the decision variables or objective.4. Why we might try
Again, inputs are often estimates and could be inaccurate. With this technique we can view how the model changes as inputs change. The sensitivity analysis that we reviewed in earlier lessons focuses on only changing one input at a time, with this technique we can change many at once.5. Context
To show how we might code this technique we start with an example. In this example of a glass manufacture, our goal is to determine how much of product A, B, or C we should produce to maximize total profits based on our constraints. We have estimates of how much profit is earned from each product, but we have some concern of their accuracy. If we model this as an LP problem we can add noise to our estimates of profits, which are inputs for the objective function.6. Code example - step 1
First, we start with PuLP code to solve this problem with no noise. We have reviewed many parts of this model in previous lessons. Here we initialize the class, define the decision variables, object function, and constraints.7. Code example - step 2
Now, we add noise to the different inputs we want to vary using normalvariate() from the Python random module. We store the noise values in the lowercase variables a, b, and c. Using the standard deviation of the function we can determine how much noise we want to add. Here we are adding random noise values from a normal distribution centered on 0 with a standard deviation of 25. Additionally, we modify the objective function to add the noise values. The random noise values can be either positive or negative which will either add to or subtract from our estimates of profits in the objective. Our model looks like this after adding these in.8. Code example - step 3
Now, we have wrapped our PuLP model in a function that returns the decision variables values and objective as a Python dictionary.9. Code example - step 4
Next, we create a simple loop to repeatedly call the function we just created and store the output by appending it to a list. Our loop will repeat for 100 iterations. Finally, using the list of dictionaries we can create a Pandas DataFrame stored in the variable df.10. Code example - step 5
Now, with the df variable we can use the function value_counts to print the results. In this particular set of running the random function 100 times, looking only at product A, 73 of those times the optimal value to produce was 6-point-66 units of A. For 14 of those runs producing 0 units of A was optimal. We see that the risk that 6-point-66 units of A is not the optimal value is small. We can also view the other results.11. Visualize as histogram
Finally, we could visualize our DataFrame data as histograms.12. Summary
In summary, this technique should not be used for problems with long run-times. We also reviewed the benefits and how you might code this technique.13. Try it out!
Now you try it out with a few exercises.Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.