Repository navigation
07: buy now, rent later, the two-stage server farm - #7
Merged
Merged
Conversation
The server-farm two-stage program has been on this library's to-do list since the migration (StochasticLP, 14 copies); IE 5301 teaches it in 2026 as 03_Two_Stage_Server_Farm.ipynb. Buy CPUs, GPUs and TPUs now under a budget and floor space (integer, first stage); rent cloud compute per scenario to cover the shortfall (integer, recourse); minimise purchase plus mean cloud bill. The course generates demand with numpy at run time. Here it is a table, data/raw/server_farm_demand.csv: 50 scenarios from random.Random with the seed recorded in serverfarm.py, and a test that it regenerates exactly. The seed is deliberate: with it the optimal purchase is unique (test_the_optimal_plan_is_unique minimises and maximises each machine count over every optimal plan), so the agreement assertion compares whole plans. Seed 7 with 40 scenarios has ties, and the docstring says so. The notebook builds the model with addVars and asks before solving whether money or floor space runs out first: space binds (100 of 100), the budget does not (592 of 1000). Result: buy 51 CPU, 5 GPU, 8 TPU, expected cost 1000.54. The plan-for-the-average shortcut buys no GPUs, reports an objective of 1002.00, and costs 1039.12 against the real scenarios: VSS 38.58. The package holds the same model in matrix form (addMVar, the course's form), so the assertion also shows the two formulations agree, exactly. The recourse figure distinguishes owned from rented by hatch as well as colour, and prints one Figure line per panel. Gate: 207 passed; the server-farm tests pass on the size-limited licence too (153 integer variables); 20 notebooks and 14 seeds clean; ruff clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #6. Its base is
newsvendor/risk. Merge order: #4, #5, #6, then this.Adds
notebooks/07_stochastic_and_newsvendor/server_farm.ipynbandorteach.serverfarm: the two-stage server farm from IE 5301's 2026 code, which had been on this library's to-do list since the migration. You buy CPUs, GPUs and TPUs now, then rent cloud compute in each scenario to cover any shortfall.The demand scenarios are a table generated from a recorded seed, chosen so the optimal plan is unique; a test proves it. That lets the final check compare whole purchase plans. The package writes the same model in matrix form, so the check also confirms the two formulations agree.
🤖 Generated with Claude Code