Stochastic & Robust Optimization
Decision-Making Under Uncertainty
A comprehensive collection of optimization problems that address uncertainty in data, parameters, and outcomes. From classical newsvendor models and stochastic programming to distributionally robust optimization, these formulations capture the spectrum of approaches for making optimal decisions when the future is unknown.
View Source on GitHubProblem Overview
Three paradigms of optimization under uncertainty
Newsvendor
Single-period inventory under demand uncertainty with critical fractile solution.
13 testsTwo-Stage SP
First-stage decisions before uncertainty, second-stage recourse after.
10 testsRobust Shortest Path
Shortest path minimizing worst-case cost or regret across scenarios.
13 testsStochastic Knapsack
Item selection with random weights and chance constraints on feasibility.
11 testsChance-Constrained FL
Facility location with stochastic demands and probabilistic capacity constraints.
11 testsRobust Portfolio
Markowitz mean-variance with ellipsoidal uncertainty on expected returns.
14 testsStochastic VRP
Vehicle routing with random customer demands and recourse for overflow.
13 testsRobust Scheduling
Single machine scheduling minimizing worst-case regret under uncertain processing times.
13 testsDistributionally Robust
Optimize against worst-case distribution within an ambiguity set.
12 testsOptimization Paradigms
Three approaches to handling uncertainty in optimization
Known Distributions
Assumes probability distributions of uncertain parameters are known. Optimizes the expected value of the objective, possibly with chance constraints.
Two-Stage SP
Stochastic Knapsack
Chance-Constrained FL
Stochastic VRP
Worst-Case Scenarios
Makes no distributional assumptions. Protects against worst-case realizations within an uncertainty set, minimizing regret or cost.
Robust Portfolio
Robust Scheduling
Ambiguity Sets
Bridges stochastic and robust: optimizes against the worst-case distribution within an ambiguity set defined by distance or moment constraints.
Moment-Based DRO
When to Use Each Paradigm
Three fundamental quantities measure the value of modeling uncertainty:
- WS (Wait-and-See) — Expected cost if we could know each scenario before deciding. Unachievable lower bound.
- RP (Recourse Problem) — Expected cost of the optimal here-and-now stochastic solution.
- EEV (Expected result of EV solution) — Expected cost when using the deterministic mean-scenario decision.
EVPI = RP − WS
(value of perfect information — how much you would pay for an oracle)
VSS = EEV − RP
(value of the stochastic solution — benefit of modeling uncertainty vs. using averages)
Problem Details
Mathematical formulations, algorithms, and complexity analysis
Quick Navigation
Newsvendor Problem
A retailer orders Q units of a perishable product before uncertain demand D is realized. Overage cost co = c - v for excess inventory; underage cost cu = p - c for lost sales. The optimal order quantity satisfies the critical fractile condition.
Applications: Retail inventory, fashion goods, seasonal products, airline overbooking, event ticketing.
Optimal: Q* = F-1(cu / (cu + co)) // Critical fractile
| Algorithm | Type | Complexity | Reference | Description |
|---|---|---|---|---|
| Critical Fractile | Exact | O(S log S) | Arrow et al. (1951) | Sort scenarios, scan empirical CDF to find optimal quantile |
| Grid Search | Heuristic | O(S × G) | — | Discretized evaluation over demand range grid; approximate unless grid contains optimum |
| Marginal Allocation | Heuristic | O(n × Qmax) | Fox (1966) | Greedy marginal analysis for multi-product with budget constraint |
| Independent + Scale | Heuristic | O(n × S log S) | — | Solve independently per product, scale to fit budget |
Try It Yourself
co (overage) = c - v = 5
Critical fractile = cu / (cu + co) = 0.750
| Metric | Value |
|---|---|
| No results yet | |
Interested in Stochastic Optimization?
Explore the full implementation with critical fractile, grid search, multi-product heuristics, and 13 comprehensive tests.
Two-Stage Stochastic Programming
First-stage decisions x are made before uncertainty is revealed. After observing scenario s, second-stage recourse decisions y(s) compensate for any constraint violations. The goal is to minimize the sum of first-stage cost and expected second-stage recourse cost.
Applications: Capacity planning, supply chain design, energy systems, financial planning, network design.
where Q(x, s) = miny { q(s)Ty : Wy = h(s) - T(s)x, y ≥ 0 }
| Algorithm | Type | Complexity | Reference | Description |
|---|---|---|---|---|
| Deterministic Equivalent LP | Exact | O(S × LP) | Dantzig (1955) | Extensive form expanding all scenarios into a single LP (HiGHS solver) |
| L-Shaped Method | Exact | Iterative | Van Slyke & Wets (1969) | Benders decomposition for two-stage SP; generates optimality cuts iteratively |
| Expected Value (EV) Solution | Heuristic | O(LP) | Birge & Louveaux (2011) | Solve on mean scenario; yields EEV when evaluated stochastically. VSS = EEV − RP measures stochastic solution value |
| Sample Average Approximation | Approximation | O(R × S' × LP) | Kleywegt et al. (2002) | Sampling-based approximation; solve on random scenario subsets with replications for confidence bounds |
| Progressive Hedging | Approximation | Iterative | Rockafellar & Wets (1991) | Scenario decomposition with augmented Lagrangian; enforces non-anticipativity via penalty terms |
For a minimization two-stage SP: WS ≤ RP ≤ EEV. The gap EVPI = RP − WS tells you how much perfect foresight is worth. The gap VSS = EEV − RP tells you the benefit of modeling uncertainty explicitly versus using deterministic averages. If VSS is small, the deterministic model suffices; if EVPI is large, invest in better forecasting.
Two-Stage Recourse Explorer
| Method | Capacity (x) | Expected Cost | Interpretation |
|---|---|---|---|
| No results yet | |||
Robust Shortest Path
Find a path from source to target that performs well across all possible edge-weight scenarios. Two criteria: minimize the worst-case path cost (min-max cost), or minimize the worst-case deviation from the scenario-optimal path (min-max regret).
Applications: Transportation under weather uncertainty, evacuation routing, military logistics, network reliability.
minP maxs ∈ S Σ(i,j) ∈ P wij(s)
Min-Max Regret:
minP maxs ∈ S [ cost(P, s) - cost(P*s, s) ]
| Algorithm | Type | Complexity | Reference | Description |
|---|---|---|---|---|
| Label-Setting | Exact | O(S × (V+E) log V) | Yu & Yang (1998) | Multi-objective Dijkstra with dominance pruning for min-max cost |
| Scenario Enumeration | Exact | O(S × (V+E) log V) | Kouvelis & Yu (1997) | Dijkstra per scenario, cross-evaluate all candidate paths |
| Regret Enumeration | Heuristic | O(S² × V) | Kouvelis & Yu (1997) | Evaluate candidate paths against per-scenario optima for regret |
| Midpoint | Heuristic | O((V+E) log V) | — | Shortest path on mean-weight graph; robust approximation for scenario-based uncertainty |
The scenario-based approach above considers discrete scenarios. An influential alternative is budgeted uncertainty: each edge weight lies in an interval [w̄ij, w̄ij + d̂ij], and at most Γ edges deviate simultaneously. The parameter Γ controls the price of robustness — the trade-off between solution quality and protection level. At Γ = 0 the solution is nominal; at Γ = |E| it is fully worst-case. This framework applies broadly to robust network, scheduling, and combinatorial optimization problems.
Stochastic Knapsack
Select items with deterministic values but random weights to maximize total value. The total weight must satisfy the capacity constraint with probability at least 1 - α (chance constraint). Combines combinatorial optimization with probabilistic feasibility.
Applications: Project selection under cost uncertainty, resource allocation, investment planning.
s.t. P(Σi w̃i xi ≤ W) ≥ 1 - α
xi ∈ {0, 1}
| Algorithm | Type | Complexity | Reference | Description |
|---|---|---|---|---|
| Greedy (Mean Weight) | Heuristic | O(n log n) | — | Value-density ranking using expected weights as deterministic proxy |
| Chance-Constrained Greedy | Heuristic | O(n² × S) | Kleinberg et al. (2000) | Add items greedily while maintaining P(feasible) ≥ 1 - α |
| Simulated Annealing | Varies | — | Flip-bit neighborhood with infeasibility penalty in objective |
Chance-Constrained Facility Location
Open facilities and assign customers to minimize total fixed and assignment cost, subject to a probabilistic capacity constraint: the probability that demand assigned to each open facility exceeds its capacity must be at most α.
Applications: Warehouse location, hospital planning, disaster relief depot siting, cell tower placement.
s.t. P(Σj d̃j xij ≤ Qi) ≥ 1 - α ∀ i
| Algorithm | Type | Complexity | Reference | Description |
|---|---|---|---|---|
| Greedy Open | Heuristic | O(m × n × S) | — | Iteratively open most cost-reducing facility with chance constraint checks |
| Mean-Demand Greedy | Heuristic | O(m × n) | — | Deterministic proxy using expected demands for capacity planning |
| Simulated Annealing | Varies | — | Toggle/swap moves with Boltzmann acceptance and violation penalty |
Robust Portfolio Optimization
Markowitz mean-variance portfolio optimization extended with ellipsoidal uncertainty on expected returns. The robust formulation penalizes exposure to estimation error in mean returns, producing portfolios that are less sensitive to input misspecification. Reduces to a second-order cone program (SOCP).
Applications: Asset allocation, pension fund management, hedge fund strategy, index tracking.
s.t. Σi wi = 1, wi ≥ 0
| Algorithm | Type | Complexity | Reference | Description |
|---|---|---|---|---|
| QP Solver (Mean-Variance) | Exact | O(n³) | Markowitz (1952) | SLSQP on classical Markowitz objective without robustness |
| QP Solver (Robust SOCP) | Exact | O(n³) | Goldfarb & Iyengar (2003) | SLSQP on SOCP-representable objective with ellipsoidal uncertainty penalty (general NLP solver, not dedicated conic) |
| Equal Weight (1/n) | Heuristic | O(1) | DeMiguel et al. (2009) | Naive diversification; surprisingly competitive baseline |
| Minimum Variance | Heuristic | O(n³) | — | Σ-11 (normalized) closed-form; minimizes portfolio variance regardless of return |
| Maximum Return | Heuristic | O(n) | — | Concentrate on asset with highest expected return |
Rockafellar & Uryasev (2000) showed that CVaR (expected loss beyond the α-quantile) can be minimized via linear programming, making it a tractable alternative to variance for measuring downside risk. The key insight: minimizing CVaR simultaneously yields the optimal VaR. For portfolio optimization, replacing variance with CVaR produces:
This is a convex LP for discrete scenarios, making it more computationally tractable than the robust SOCP above for large-scale problems. CVaR is a coherent risk measure (satisfying subadditivity, monotonicity, positive homogeneity, and translation invariance).
In the robust formulation above, δ controls the size of the ellipsoidal uncertainty set around the estimated mean return μ. Larger δ provides more protection against estimation error but sacrifices expected return. Setting δ = 0 recovers the classical Markowitz model. The parameter can be calibrated from data via cross-validation or set based on the number of historical observations (e.g., δ ≈ √(n) for n samples).
Efficient Frontier Explorer
| Strategy | Return | Risk (σ) | Weights |
|---|---|---|---|
| No results yet | |||
Stochastic Vehicle Routing
Capacitated vehicle routing where customer demands are random variables. Routes are designed a priori; when a vehicle's capacity is exceeded during service, a recourse action (e.g., return to depot to unload) is triggered. The objective includes both planned routing cost and expected recourse cost.
Applications: Delivery logistics, waste collection, fuel distribution, last-mile delivery.
s.t. P(Σi ∈ r d̃i ≤ Q) ≥ 1 - α ∀ route r
| Algorithm | Type | Complexity | Reference | Description |
|---|---|---|---|---|
| CC Clarke-Wright Savings | Heuristic | O(n² log n) | Laporte et al. (2002) | Chance-constrained savings-based merging with probabilistic route overflow check |
| Mean-Demand Savings | Heuristic | O(n² log n) | Clarke & Wright (1964) | Classical Clarke-Wright using expected demands as deterministic proxy |
| Simulated Annealing | Varies | — | Relocate/swap/2-opt with recourse penalty for constraint violations |
Robust Scheduling
Single machine scheduling where processing times are uncertain, specified as intervals [pjmin, pjmax] or discrete scenarios. The objective is to find a job sequence minimizing the worst-case regret of total weighted completion time compared to the optimal schedule for each scenario.
Applications: Manufacturing with variable task durations, operating room scheduling, maintenance planning.
where π*s = WSPT(s) // Optimal for each scenario
| Algorithm | Type | Complexity | Reference | Description |
|---|---|---|---|---|
| Midpoint WSPT | Heuristic | O(n log n) | Daniels & Kouvelis (1995) | WSPT on mean processing times as robust approximation |
| Scenario Enumeration | Heuristic | O(S × n log n) | Kouvelis & Yu (1997) | WSPT per scenario, cross-evaluate regret, select minimum |
| Worst-Case WSPT | Heuristic | O(n log n) | — | WSPT using maximum processing times for conservative schedule |
| Simulated Annealing | Varies | — | Swap/insertion neighborhood to minimize max regret across scenarios |
Distributionally Robust Optimization
Optimize against the worst-case probability distribution within an ambiguity set. This bridges stochastic optimization (known distribution) and robust optimization (worst-case over uncertainty set) by considering families of distributions defined via Wasserstein distance or moment constraints.
Applications: Supply chain under distributional ambiguity, data-driven decision-making, machine learning robustness, risk management.
minx maxP : W(P, P̂) ≤ ε EP[f(x, ξ)]
Moment-Based DRO:
minx maxP : E[ξ] = μ, Cov[ξ] ⪯ Σ EP[f(x, ξ)]
| Algorithm | Type | Complexity | Reference | Description |
|---|---|---|---|---|
| Wasserstein DRO LP | Exact | O(S × LP) | Mohajerin Esfahani & Kuhn (2018) | LP reformulation with L1-norm regularization for 1-Wasserstein ambiguity set |
| Nominal LP | Baseline | O(LP) | — | Standard LP without distributional robustness; comparison benchmark for DRO methods |
| Moment-Based DRO | Heuristic | O(G × S × LP) | Delage & Ye (2010) | Inner LP for worst-case distribution over moment ambiguity set, outer grid search over decisions |
Beyond Wasserstein and moment-based sets, a major family uses φ-divergence (Ben-Tal et al., 2013): the ambiguity set contains all distributions P such that Dφ(P || P̂) ≤ ρ, where Dφ is a divergence measure (KL divergence, χ²-distance, total variation, etc.). Key properties:
- KL-divergence DRO — Equivalent to entropic risk minimization; connects DRO to regularization in machine learning.
- χ²-divergence DRO — Yields SOCP reformulations for linear loss functions; tractable for large-scale problems.
- Total Variation — Bounds the maximum pointwise probability shift; useful when contamination is sparse.
The choice of ambiguity set reflects prior knowledge: Wasserstein is natural for metric spaces with limited data, φ-divergence for problems with a reliable reference distribution, and moment-based when only summary statistics are available.
Test Coverage
110 tests across 9 problem implementations
| Problem | Tests | Test Classes | Paradigm | Run Command |
|---|---|---|---|---|
| Newsvendor | 13 | 3 | Stochastic | pytest .../newsvendor/tests/ -v |
| Two-Stage SP | 10 | 4 | Stochastic | pytest .../two_stage_sp/tests/ -v |
| Robust Shortest Path | 13 | 4 | Robust | pytest .../robust_shortest_path/tests/ -v |
| Stochastic Knapsack | 11 | 3 | Stochastic | pytest .../stochastic_knapsack/tests/ -v |
| Chance-Constrained FL | 11 | 3 | Stochastic | pytest .../chance_constrained_fl/tests/ -v |
| Robust Portfolio | 14 | 3 | Robust | pytest .../robust_portfolio/tests/ -v |
| Stochastic VRP | 13 | 3 | Stochastic | pytest .../stochastic_vrp/tests/ -v |
| Robust Scheduling | 13 | 3 | Robust | pytest .../robust_scheduling/tests/ -v |
| DRO | 12 | 4 | DRO | pytest .../dro/tests/ -v |
| Total | 110 | 30 | pytest problems/9_uncertainty_modeling/ -v |