Skip to content

07: buy now, rent later, the two-stage server farm - #7

Merged
yamierick merged 1 commit into
mainfrom
newsvendor/server-farm
Oct 27, 2026
Merged

yamierick merged 1 commit into
mainfrom
newsvendor/server-farm

Conversation

@yamierick

Copy link
Copy Markdown
Contributor

Stacked on #6. Its base is newsvendor/risk. Merge order: #4, #5, #6, then this.

Adds notebooks/07_stochastic_and_newsvendor/server_farm.ipynb and orteach.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 plan: buy 51 CPUs, 5 GPUs and 8 TPUs. Floor space is the limit that binds, not the budget.
  • Planning for average demand instead buys no GPUs. Costed against the 50 real scenarios it's 38.58 more expensive.

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

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>
@yamierick
yamierick changed the base branch from newsvendor/risk to main October 27, 2026 14:31
@yamierick
yamierick merged commit 9e2ace7 into main Oct 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant