# Application: unit commitment with valve-point costs Unit commitment decides which thermal generators run in each hour of a horizon and how much each one produces, so that demand and a spinning reserve are met at the least fuel and start-up cost. With the valve-point effect, each unit's fuel cost carries a term $\lvert d_u \sin(e_u (P_u^{\min} - P)) \rvert$, non-convex and non-smooth in the dispatch, which CP-SAT cannot state. This page solves the formulation and instances of Pedroso, Kubo and Viana, [*Unit commitment with valve-point loading effect*](https://arxiv.org/abs/1404.4944) (2014). % Drawn by figures/make_schedule.py from a cbls solve; one copy per colour mode. ```{figure} figures/schedule-light.svg :figclass: only-light :align: center :width: 560px :alt: Bands of generator output stacked hour by hour, rising to a midday peak and falling again, under a dashed step line of committed capacity. The unit commitment cbls finds for Pedroso et al.'s `ucp13` over 24 hours. Each band is one generator's output, stacked to meet the hourly demand exactly. The dashed line is the committed capacity, which must also cover a spinning reserve. ``` ```{figure} figures/schedule-dark.svg :figclass: only-dark :align: center :width: 560px :alt: Bands of generator output stacked hour by hour, rising to a midday peak and falling again, under a dashed step line of committed capacity. The unit commitment cbls finds for Pedroso et al.'s `ucp13` over 24 hours. Each band is one generator's output, stacked to meet the hourly demand exactly. The dashed line is the committed capacity, which must also cover a spinning reserve. ``` ## The problem Units $u \in \mathcal{U}$, periods $t \in \mathcal{T} = \{1, \ldots, T\}$. The commitment $y_{u,t}$ and the dispatch $p_{u,t}$ are the decisions: $$ \begin{aligned} \min\ & \sum_{u \in \mathcal{U}} \sum_{t \in \mathcal{T}} \big[\, y_{u,t}\, F_u(p_{u,t}) + SC_{u,t} \,\big] \\ \text{s.t.}\ & \textstyle\sum_{u} p_{u,t} = D_t, && t \in \mathcal{T}, \\ & \textstyle\sum_{u} P_u^{\max}\, y_{u,t} \geq D_t + R_t, && t \in \mathcal{T}, \\ & P_u^{\min}\, y_{u,t} \leq p_{u,t} \leq P_u^{\max}\, y_{u,t}, && u \in \mathcal{U},\ t \in \mathcal{T}, \\ & y_{u,t} - y_{u,t-1} \leq y_{u,\tau}, && u \in \mathcal{U},\ t, \tau \in \mathcal{T},\ t < \tau < t + UT_u, \\ & y_{u,t-1} - y_{u,t} \leq 1 - y_{u,\tau}, && u \in \mathcal{U},\ t, \tau \in \mathcal{T},\ t < \tau < t + DT_u, \\ & y_{u,t} = y_{u,0}, && u \in \mathcal{U},\ t \in \mathcal{T},\ t \leq L_u, \\ & y_{u,t} \in \{0, 1\},\ p_{u,t} \geq 0, && u \in \mathcal{U},\ t \in \mathcal{T}, \end{aligned} $$ with the fuel and start-up costs $$ \begin{aligned} F_u(P) &= a_u + b_u P + c_u P^2 + \left| d_u \sin\big(e_u (P_u^{\min} - P)\big) \right|, \\ SC_{u,t} &= \max(0,\ y_{u,t} - y_{u,t-1}) \cdot \begin{cases} A_u^{\text{hot}} & \text{if } y_{u,\tau} = 1 \text{ for some } t - \tau_u^{\text{cold}} \leq \tau < t, \\ A_u^{\text{cold}} & \text{otherwise.} \end{cases} \end{aligned} $$ The data: demand $D_t$ and reserve $R_t$ per period; per unit, the output limits $P_u^{\min}$ and $P_u^{\max}$, the fuel coefficients $a_u, \ldots, e_u$, the hot and cold start-up costs $A_u^{\text{hot}}$ and $A_u^{\text{cold}}$, the cold-start time $\tau_u^{\text{cold}}$, the minimum up and down times $UT_u$ and $DT_u$, and the state $y_{u,0}$ the unit has held for $n_u$ periods before the horizon. - **Objective:** fuel while a unit is committed, plus start-ups. The valve-point term $\lvert d_u \sin(\cdot) \rvert$ makes each unit's fuel cost non-convex and non-smooth in its dispatch. - **Demand:** the units' output meets each period's demand $D_t$ exactly. The runner's default is $\geq$, a relaxation (with a valve-point cost, producing more can cost less); `--demand-equality` solves the $=$, as the published rows do. - **Spinning reserve:** the *committed capacity*, not the dispatch, covers demand plus the reserve $R_t$. - **Dispatch limits:** a committed unit runs between $P_u^{\min}$ and $P_u^{\max}$; a unit that is off produces nothing. - **Minimum up and down times:** a unit that starts stays on for $UT_u$ periods, and one that stops stays off for $DT_u$, up to the horizon's end. A unit keeps its state before the horizon for what it still owes: $L_u = UT_u - n_u$ periods if it was on, $DT_u - n_u$ if it was off (none if negative). - **Start-up cost:** hot if the unit ran within its last $\tau_u^{\text{cold}}$ periods, cold otherwise; every start-up on these instances is cold. - There are no ramp rates, in the source or here. | Instance | Units | Periods | Source | |---|---:|---:|---| | `ucp13` | 13 | 1, 3, 6, 12, 24 | Pedroso et al.'s data, checked field by field | | `ucp40` | 40 | 1, 3, 6, 12, 24 | Pedroso et al.'s data, checked field by field | | `ucp100` | 100 | 1, 3, 6, 12, 24, 48, 168 | constructed from `ucp40` | | `ucp200` | 200 | 1, 3, 6, 12, 24, 48, 168 | constructed from `ucp40` | Pedroso et al. publish bounds for `ucp13` and `ucp40` only; the runner restates them as cited rows in its `comparison.csv`. How `ucp100` and `ucp200` are built is in the [developer notes](https://github.com/spoorendonk/cbls/blob/main/dev/benchmarks.md#uc-chped), and every runner flag in `cbls_uc_chped --help`. In cbls, each $y_{u,t}$ is a `Bool` and each $p_{u,t}$ a `Float`; the fuel cost is an expression over `sin` and `abs`, the start-up price an `if_then_else` over a `max` of past commitments ([`uc_model.h`](https://github.com/spoorendonk/cbls/blob/main/benchmarks/uc-chped/uc_model.h)). ## A problem-specific inner solver The engine knows nothing about unit commitment. A C++ subclass of `InnerSolverHook` adds what it knows, as a plugin the search calls on its points ([C++ reference](cpp.md#inner-solver-hooks)). The runner ships one, [`uc_hook.h`](https://github.com/spoorendonk/cbls/blob/main/benchmarks/uc-chped/uc_hook.h). It reads the commitment $y$ and dispatch $p$ at the search's point. It acts only on a commitment that meets the minimum up and down times and the initial state and can be dispatched in every period: committed $\sum P_u^{\max}$ covers $D_t + R_t$ and committed $\sum P_u^{\min}$ does not exceed $D_t$. With `--uc-repair` it first tries to repair one that does not, mainly by switching units on; a commitment that still fails, or any failing one without the flag, is skipped. It then works in two layers. **Dispatch.** For a fixed commitment the cost separates by period, and each period is an economic dispatch over the units that are on, balanced to $D_t$ exactly whatever demand row the model uses: $$ ED_t(y) = \min_{p} \sum_{u : y_{u,t} = 1} F_u(p_u) \quad \text{s.t.} \quad \sum_{u : y_{u,t} = 1} p_u = D_t, \qquad P_u^{\min} \leq p_u \leq P_u^{\max}. $$ The $\lvert \sin \rvert$ term is zero, a kink of $F_u$, at the valve points $P_u^{\min} + k\pi / e_u$, $k = 0, 1, \ldots$; these and $P_u^{\max}$ are each unit's candidate outputs. The fast dispatch solves the quadratic part by $\lambda$-dispatch ($b_u + 2 c_u p_u = \lambda$, clamped to the limits, with $\lambda$ set so the output meets $D_t$), snaps each unit to its nearest candidate and rebalances by whole steps between candidates; one unit closes the remaining residual where it can, else units are filled to their limits in turn. The polish, at most 4 sweeps, moves one unit onto another candidate while a second unit absorbs the difference, when that lowers the cost. **Commitment.** With `full`, over such commitments it minimises $$ C(y) = \sum_{t} ED_t(y) + \sum_{u,t} SC_{u,t}(y), $$ each $ED_t$ priced by the fast dispatch (by default), by first-improvement descent: per unit, drop, shrink or extend a block of on periods, fill a gap between two blocks, or add a block of $UT_u$ periods (cut at the horizon) at a few sampled off periods; then switch a block of one unit off and an idle unit on over the same periods. A move re-dispatches only the periods it changes. Optionally, an iterated local search kicks the commitment with random moves and descends again, keeping the better. The polish then runs on the final commitment's dispatch. The hook writes $(y, p)$ back only if the model finds it feasible and cheaper than the point it read; at an infeasible point (if asked to run there), cheaper than the best it has seen, or any feasible one before it has seen one. Otherwise it restores the point. `--uc-hook ed` runs the dispatch only; `--uc-hook full` adds the commitment search. The hook is off by default, and the results below are without it. ## Results At equal time and threads, cbls has the lowest primal integral on most rows: it reaches good solutions first. Pedroso et al.'s method ends with the best final gap on most. The setup and the counts are on the [results page](results.md#uc-chped). Row by row: the primal integral (PI; 0 if the best known is found at once, up to 2 if nothing is found) and the final gap in % to the row's reference, the lowest objective any method or the source reached. For cbls, the PI is the median over its seeds and the gap the median over the seeds that found a solution; `pwl` is Pedroso et al.'s method and `exact` SCIP's MINLP, one run each. In bold: the strictly lowest PI, and every gap tied for lowest at 0.01 %; `-` is no solution in the budget. | Row | Budget (s) | PI cbls | PI pwl | PI exact | Gap % cbls | Gap % pwl | Gap % exact | |---|---:|---:|---:|---:|---:|---:|---:| | `ucp13` T=1 | 10 | **0.0002** | 0.0184 | 0.0315 | **0.00** | **0.00** | **0.00** | | `ucp13` T=3 | 30 | **0.0014** | 0.0131 | 0.0173 | **0.00** | **0.00** | **0.00** | | `ucp13` T=6 | 60 | **0.0055** | 0.0092 | 0.0168 | 0.32 | **0.00** | 0.14 | | `ucp13` T=12 | 120 | **0.0056** | 0.0083 | 0.1294 | 0.42 | **0.00** | 0.37 | | `ucp13` T=24 | 300 | **0.0085** | 0.0123 | 0.5273 | 0.60 | **0.00** | 0.57 | | `ucp40` T=1 | 10 | **0.0040** | 0.0313 | 0.0523 | **0.00** | **0.00** | **0.00** | | `ucp40` T=3 | 30 | 0.0214 | **0.0210** | 0.0677 | 1.80 | **0.00** | 0.08 | | `ucp40` T=6 | 60 | **0.0118** | 0.0248 | 0.1503 | 0.96 | **0.05** | 0.36 | | `ucp40` T=12 | 120 | **0.0177** | 0.0181 | 0.3688 | 1.30 | **0.00** | 10.04 | | `ucp40` T=24 | 300 | **0.0307** | 0.0364 | 0.4129 | 2.46 | **0.00** | 8.12 | | `ucp100` T=1 | 10 | **0.0224** | 0.0484 | 0.2510 | 1.13 | **0.00** | 0.10 | | `ucp100` T=3 | 30 | **0.0262** | 0.0389 | 0.3770 | 2.39 | **0.00** | 0.45 | | `ucp100` T=6 | 60 | **0.0155** | 0.0677 | 0.6931 | 1.24 | **0.00** | 0.61 | | `ucp100` T=12 | 120 | **0.0299** | 0.2276 | 0.9962 | 2.51 | **0.00** | 0.89 | | `ucp100` T=24 | 300 | **0.0516** | 0.4058 | 0.6230 | 4.29 | **0.00** | 0.88 | | `ucp100-48p` | 600 | **0.0645** | 1.9715 | 0.4995 | 5.95 | **0.00** | 12.37 | | `ucp100-168p` | 600 | **0.0024** | 0.5494 | 2.0000 | **0.00** | 2.66 | - | | `ucp200` T=1 | 10 | **0.0581** | 0.1606 | 0.1580 | 4.57 | **0.00** | 0.41 | | `ucp200` T=3 | 30 | **0.0351** | 0.1366 | 0.5173 | 3.05 | **0.00** | 1.75 | | `ucp200` T=6 | 60 | **0.0226** | 0.2307 | 0.9627 | 1.66 | **0.00** | 17.49 | | `ucp200` T=12 | 120 | **0.0425** | 0.7539 | 0.6402 | 3.36 | **0.00** | 0.74 | | `ucp200` T=24 | 300 | **0.0699** | 0.8342 | 1.0674 | 6.04 | **0.00** | 0.77 | | `ucp200-48p` | 600 | **0.0029** | 2.0000 | 2.0000 | **0.00** | - | - | | `ucp200-168p` | 600 | **0.0079** | 2.0000 | 2.0000 | **0.00** | - | - | On `ucp100-168p`, `ucp200-48p` and `ucp200-168p` the reference is cbls's own best final result, so its best seed's gap there is 0 by construction. ## How to run it Build the runner from the repository root, after `cmake -B build`: ```bash cmake --build build --target cbls_uc_chped ``` Solve `ucp13` over 3 periods for 2 s with the source's equality demand, verify it, and write the row and the solution to a temporary directory: ```bash out=$(mktemp -d) ./build/cbls_uc_chped benchmarks/instances/uc-chped --instance ucp13 --periods 3 \ --time-limit 2 --seed 1 --demand-equality --verify \ --out "$out/ucp13.csv" --solution-out "$out/ucp13.jsonl" ``` Check each solution independently of the engine, from the instance file alone, against Pedroso et al.'s `=` model at 1e-6 (prints `OK` per solution): ```bash .venv/bin/python benchmarks/uc-chped/check_solutions.py benchmarks/instances/uc-chped "$out/ucp13.jsonl" ``` - Without `--instance`, `--periods` and `--time-limit`, the runner solves the whole roster at its per-horizon budgets (10 s at 1 period up to 600 s at 168). - `--threads N` runs the parallel portfolio; `cbls_uc_chped --help` lists every flag. - The SCIP references, Pedroso et al.'s Algorithm 1 ported to SCIP (`pwl`) and SCIP's MINLP with the true valve-point term (`exact`), are in [`benchmarks/uc-chped/pedroso/`](https://github.com/spoorendonk/cbls/blob/main/benchmarks/uc-chped/pedroso/README.md) (GPL-3.0-or-later).