Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

10. Sensitivity Analysis and Duality

What an optimal plan is worth to change: what one more hour of a scarce resource adds, how far that value holds, how far a price can move before the plan changes, and how to value a set of offers by re-solving the model.

Slides

Present full screen Download the PDF

Click or tap the slide to move forward, its left edge to go back; the arrow keys work too.

Reading

Sensitivity Analysis: What Is One More Hour Worth? takes last week’s kitchen plan (53,900 SAR a week) and asks what it is worth to change it. It finds the shadow prices of the roaster (390 SAR an hour) and the staff (175 SAR), sweeps the hours to see where those prices stop holding, prices out the four products, solves the dual, and values four offers on the manager’s desk, alone and in all 16 combinations.

Lab 10: What-if app over a linear program

Four offers are on the kitchen manager’s desk for next month: a second roaster shift, staff overtime, hours on a neighbour’s oven and a House Blend campaign. Valued with the shadow prices, the overtime looks like the best deal. You check every shadow price by re-solving, sweep the staff hours to find where the overtime stops paying, test the branches’ proposal to cut the price of Saffron Cake, then write a Streamlit app in which the manager sets the hours, ticks the offers and reads the net gain.

Running the app

Colab cannot display a Streamlit page, so the lab tests the app with Streamlit’s AppTest. To see it in a browser:

  1. GitHub Codespaces (free with GitHub Education) or your own computer: open a terminal in the folder with the app, run pip install streamlit pandas "pulp[highs]>=4.3,<5", then streamlit run whatif_app.py. A browser tab opens at http://localhost:8501.

  2. Share it: push the app and a requirements.txt to a GitHub repository and deploy it on Streamlit Community Cloud, choosing the repository and the file. You get a public link.

The finished course version, with the hours, the contributions and demand limits, the offers, the plan with its reduced costs, the shadow prices, each offer valued alone and a sweep chart of any resource: app.py and its requirements.txt. In a clone of the course repository, run it with streamlit run week10/app/app.py.

Next week

Modeling patterns: multiperiod planning, blending, transportation and network flow models in PuLP.

→ Week 11: Modeling Patterns