Deciding before the uncertainty resolves: stochastic and robust optimization
Size an electrolyzer before anyone knows how much wind gets built: plan for the average, hedge across the branches, or guard the worst case
One electrolyzer, sized before the wind is built (illustrative)
| Plan | Size | None built | Half built | All built | Expected |
|---|---|---|---|---|---|
| Worst case (robust) | 380 MW | $703.40M | $688.66M | $652.32M | $683.26M |
| Stochastic program | 845 MW | $731.49M | $663.09M | $626.74M | $671.10M |
| Least regret | 942.3 MW | $739.28M | $662.99M | $621.39M | $671.66M |
| Plan for the average | 1,300 MW | $767.89M | $662.63M | $601.72M | $673.72M |
- Wait and see, one plan per branch: 380 MW (none built), 1,300 MW (half built), 2,220 MW (all built).
- Value of the stochastic solution: $673.72M − $671.10M = $2.62M a year.
- Expected value of perfect information: $671.10M − $653.54M = $17.56M a year.
With JavaScript on, you solve each plan yourself, step by step, with a solver in your browser.
- Toy: a fictional windy zone with 3,000 MW of wind and 4,000 MW planned; its lines take 1,000 MW. Chances, costs and demand are illustrative round numbers in 2025 dollars.
- Wind blocks: the 8,760 hours of 2025 sorted by output and cut into five blocks: SPP's hourly wind shape (EIA-930) scaled to 33.8%, U.S. wind's 2025 capacity factor (EIA, Table 6.07.B).
- Electrolyzer: it uses electricity to make hydrogen from water. $80,000 per MW a year; 18 kg of hydrogen per MWh; it runs only on surplus wind.
- Hydrogen: industry takes 54,000 kg an hour; gas reformers, which make hydrogen from natural gas and steam, supply the rest at $1.50 per kg.
About 45 guided minutes in eleven steps. Solver: HiGHS (open source), loaded on your first solve (about 3.5 MB, once).
Build it in Python · notebook lab, about 60 minutes, then 90 minutes of practice
The same two-stage program in scipy.optimize.linprog(method="highs"): assert cells check your plans, the value of the stochastic solution and the value of perfect information against the page, then you grow the tree to nine branches.
- Download the notebook and the data files into one folder (in Colab, upload the data with the folder icon).
- Open it in Google Colab (File → Upload notebook) or locally with Python 3, NumPy and SciPy 1.9 or later.
- Run all cells (a few seconds), then try the practice tasks at the end.
What you just did, as diagrams
- Here and now, then recourse
- The size is chosen before the build-out is known; the operation in each branch is chosen after.
- Wait and see
- Each branch's own best plan: 380, 1,300 or 2,220 MW. No single plan is best in every branch.
- Plan for the average
- 1,300 MW, sized for 5,000 MW of wind; it expects $662.63M a year but costs $673.72M over the branches.
- Stochastic program
- 845 MW, the lowest expected cost: $671.10M a year.
- Two values
- Value of the stochastic solution $2.62M a year; expected value of perfect information $17.56M a year.
- Robust plans
- Worst case 380 MW (worst cost $703.40M); least regret 942.3 MW (largest regret $35.87M). Neither uses the chances.
Go deeper · ModelerThe extensive form in algebra, and the order of the costs
For branches \(s \in \{\text{none}, \text{half}, \text{all}\}\) and wind blocks \(b = 1 \dots 5\), one linear program holds the size and every branch’s operation (the extensive form, also called the deterministic equivalent):
\[\min_{x,\,e,\,r}\; c\,x + \sum_s p_s \sum_b h_b\, c_r\, r_{s,b}\]
\[ \begin{aligned} k\,e_{s,b} + r_{s,b} &= H && \text{(hydrogen, every branch and block)}\\ e_{s,b} &\le x && \text{(the size links the stages)}\\ 0 \le e_{s,b} &\le \sigma_{s,b} = \max(0,\; W_s f_b - A), \quad r_{s,b} \ge 0,\; x \ge 0 \end{aligned} \]
| Symbol | Meaning | Value |
|---|---|---|
| \(x\) | electrolyzer size, chosen here and now | MW |
| \(c\) | yearly cost of a MW of electrolyzer | $80,000 |
| \(p_s\) | chance of branch \(s\) | 0.25, 0.5, 0.25 |
| \(h_b\), \(f_b\) | hours a year and wind capacity factor of block \(b\) | 500 to 3,760 h; 0.571 to 0.194 |
| \(e_{s,b}\), \(r_{s,b}\) | electrolyzer power (MW) and reformer hydrogen (kg an hour): recourse | |
| \(k\), \(H\), \(c_r\) | 18 kg per MWh; 54,000 kg an hour; $1.50 per kg | |
| \(W_s\), \(A\) | wind built in branch \(s\); what the lines take | 3,000, 5,000, 7,000 MW; 1,000 MW |
- Size. 31 columns and 30 rows; with \(n\) branches it has \(1 + 10n\) columns, so it grows with every branch you add.
- The order of the costs. WS ≤ RP ≤ EEV: here $653.54M ≤ $671.10M ≤ $673.72M. So EVPI = RP − WS and VSS = EEV − RP are both zero or more (Birge and Louveaux, ch. 4).
- Robust plans. Add a free variable \(z\) and minimise it, with \(z \ge \text{cost}_s(x)\) in every branch (worst case), or \(z \ge \text{cost}_s(x) - \text{WS}_s\) (least regret). Neither row uses \(p_s\).
Go deeper · ModelerWhy 845 MW: the critical-hours rule
- One more MW. It costs $80,000 a year and saves $1.50 × 18 = $27 for every hour it runs on surplus. It pays while it runs more than $80,000 ÷ $27 = 2,963 hours a year.
- In each branch. Just below its own best size, 380 MW (none built), 1,300 MW (half) or 2,220 MW (all), an extra MW runs 3,000 hours; just above, 1,500. Each wait-and-see plan sits where its count falls below 2,963.
- Over the branches. Weighted by the chances, an extra MW just below 845 MW runs 3,750 hours; just above, 2,750. The stochastic plan sits where the expected count crosses 2,963.
- When the rule stops. With one size, no storage and one zone, it finds the plan by hand. A tank, several zones or pipelines couple the blocks and sizes; that needs a coupled model, here a linear program.
Go deeperWhat this toy leaves out
- Risk: the stochastic plan weighs only expected cost. A planner who fears the bad branches can add a risk measure, such as the expected cost of the worst 10% of outcomes.
- Later decisions: here the size is chosen once. A multi-stage program lets the planner build more after part of the uncertainty resolves.
- Where the branches come from: three hand-picked branches with judged chances. More branches drawn by sampling bring sampling error, as in M7.
- Time: five blocks of a duration curve, so no storage and no hour-to-hour links. Representative periods with storage are M3's subject.
- Space: one zone, no pipelines, steady hydrogen demand and a fixed price for reformer hydrogen.
Check yourself, then try it
Myth or fact? “Planning for the average future gives you the average cost.”
- Myth
- Fact
Answer
Myth. Here the plan for 5,000 MW of wind expects $662.63M a year; priced in the three branches with their chances, it costs $673.72M.
Myth or fact? “A robust plan is the best plan by every yardstick.”
- Myth
- Fact
Answer
Myth. The worst-case plan has the lowest worst cost, $703.40M, but it costs $12.16M a year more in expectation than the stochastic plan.
Myth or fact? “The expected value of perfect information is what a real forecast of the build-out is worth.”
- Myth
- Fact
Answer
Myth. It is the most a perfect forecast is worth, under these chances, to a planner who weighs only expected cost. A forecast that can be wrong is worth less.
The plan for the average costs $50M in expectation, the stochastic plan $48M, and the wait-and-see plans $45M weighted by their chances. VSS and EVPI?
- VSS $2M, EVPI $3M
- VSS $3M, EVPI $2M
- VSS $5M, EVPI $3M
- VSS $2M, EVPI $5M
Answer
VSS = $50M − $48M = $2M; EVPI = $48M − $45M = $3M.
You change the branches' chances. Which plan stays the same?
- The stochastic plan
- The plan for the average
- The worst-case plan
- All three move
Answer
The worst-case plan: it uses the set of build-outs, not their chances. Here it stays at 380 MW.
Try it yourself with open code
Optional, about 30 minutes; needs Python 3.10 or later (lesson B2).
- Install the repository (its README's quick start), then run
python examples/minimal.py: an invented four-zone region over three days, with a nine-branch tree. - Plan for one future: give
build_instancethe treeScenarioTree((Level("M", 1.0, 1.0),), (Level("M", 0.3, 1.0),)). Which sizes change against the nine-branch plan? - Its objective is what that plan expects in its one future, as in step 4, not its cost across the nine branches.
txh2-ercot-hydrogen: public example repository · MIT licence · synthetic data.
Numbers, sources and what’s next
Numbers to remember
| Number | What it means | Source |
|---|---|---|
| $2.62M a year | The toy's value of the stochastic solution: what planning with the three branches saves, in expectation, against planning for their average. | This lesson's model (illustrative) |
| $17.56M a year | The toy's expected value of perfect information: the most a perfect forecast of the build-out is worth here. | This lesson's model (illustrative) |
| WS ≤ RP ≤ EEV | Wait-and-see cost, the stochastic program's cost, the average plan's expected cost. The order holds whenever the average's plan can run in every branch, as here. | Birge and Louveaux (2011), ch. 4 |
Keep going
Where this came up in research
A two-stage stochastic linear program sized electrolyzers, hydrogen tanks and fuel cells once in each of ERCOT's eight weather zones, with hydrogen pipelines between neighbouring zones, then scheduled the system hour by hour over a full year in nine scenarios: three completion rates of planned renewable capacity by three electricity-demand levels.
Hydrogen equipment is sized once, then operated hour by hour in nine scenarios; the sizes minimize expected cost over all nine scenarios instead of fitting a single forecast.
The completion rate of planned renewable capacity was 0% (probability 0.1), 30% (0.7) or 80% (0.2); electricity demand was ERCOT's 2030 projection (0.5), 2% lower (0.2) or 2% higher (0.3).
Inputs reflect 2022–2023 conditions; post-2023 federal hydrogen credit rules are not modeled.
This page's toy is one zone with round numbers, not the study's inputs, equations or results. The whole case: CF3, where hydrogen should go when nobody knows how much wind will be built.
Sources and further reading
- Dantzig, G. B. (1955). Linear Programming under Uncertainty. Management Science, 1(3–4), 197–206.
- Birge, J. R., and Louveaux, F. (2011). Introduction to Stochastic Programming, 2nd ed. Springer. Chapter 4, The Value of Information and the Stochastic Solution, pp. 163–177.
- Birge, J. R. (1982). The value of the stochastic solution in stochastic linear programs with fixed recourse. Mathematical Programming, 24, 314–325.
- Ben-Tal, A., El Ghaoui, L., and Nemirovski, A. (2009). Robust Optimization. Princeton University Press.
- Savage, L. J. (1951). The Theory of Statistical Decision. Journal of the American Statistical Association, 46(253), 55–67. The regret rule.
- Marchau, V. A. W. J., Walker, W. E., Bloemen, P. J. T. M., and Popper, S. W. (eds.) (2019). Decision Making under Deep Uncertainty. Springer, open access.
- Li et al. (2025). Hydrogen’s role in expanding renewable energy and reducing carbon emissions in Texas. International Journal of Hydrogen Energy 113, 77–89.
- txh2-ercot-hydrogen on GitHub, version 1.0.2 (30 October 2026).
- EIA, Hourly Electric Grid Monitor (Form EIA-930), Southwest Power Pool, 2025, and Electric Power Monthly, Table 6.07.B (accessed 2 November 2026).
- Earlier lessons: M3 (what to build, on representative periods), M7 (scenarios and sampling), K5 (expected value).
Spotted an error, or stuck? Write to hlli@ksu.edu. Corrections are made in place and dated here.
Text licensed CC BY 4.0, code MIT: teachers and students may reuse and adapt it, with credit to Honglin Li.