Shadow price sensitivity analysis
1. Shadow price sensitivity analysis
In this lesson we are going to discuss sensitivity analysis of constraints, including calculating shadow prices and slack, and identifying binding constraints.2. Define shadow price
When modeling we often need to estimate values of the input data for constraints, such as the maximum number of parts that can be produced in an hour. Therefore, if our estimates are poor and the input for our constraint change, will that also change our solution? Shadow prices can help us with this issue. The shadow price is the change in optimal value of the objective function per unit increase in the right-hand-side for a constraint, given everything else remain unchanged. An example will help to make this clearer.3. Resource planning example
In this example we are resource planning for a glass manufacture. We are planning to produce cases of 3 different products. Each of these products require a different number of hours for production, and amount of room in the warehouse. Also, the profit they earn is different. There are 3 constraints, the plant's production capacity of 60 hours, the warehouse capacity of 150 square feet, and the max production for product A is capped at 8 cases.4. Code example
We have reviewed in previous lessons how to model this in PuLP and find a valid solution.5. Example solution
After running our PuLP model we find the optimal solution of how many cases to make of products A through C, and the value of our objective which is the profit.6. Review constraints
Let's quickly review our constraints again. If we look at our first constraint and we increased our production capacity by one to 61 from 60 hours, the shadow price will tell us how much the objective value will change.7. Print shadow price
Here we show code to print the shadow price. In particular, the PuLP model contains a dictionary with all the constraints which we can loop through using the items method. Each constraint has a pi attribute which is its shadow price. We are using list comprehension to create a list of dictionaries which we turn into a Pandas DataFrame.8. Shadow prices explained
Returning to our example, here are the shadow prices. For our first constraint if we increased the production capacity to 61 hours, and re-solve the model, our new model solution will see an increase in profit by about $78. Notice, that our last constraint has a shadow price of 0. Recall that our optimal solution suggests making only 6-point-667 cases of A which is less than our constraint of 8 max. Therefore, even if we set the constraint max to 9 from 8 and re-solve the model without changing anything else the new optimal solution will still say make only 6-point-667 cases of A. Therefore, there is no change in profit.9. Constraint slack
Closely related to the shadow price, we can compute the slack of a constraint. The slack is the amount of a resource that is unused. Each constraint in the PuLP model also has a slack attribute that we can print by modifying our code slightly.10. Constraint slack explained
In our example, our first two constraints show zero for the slack value. Our model's solution is fully utilizing the production hours and warehouse space. These are called binding constraints, because any changes to those constraints will change our solution. However, our third constraint has slack and is not binding. We have slack here because we are making 6-point-667 cases of A, but we can make up to 8.11. Summary
In summary, we reviewed how to compute the shadow price and slack of a constraint and used that info to determine which constraints were binding.12. Try it out!
Your turn!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.