Unit Commitment

Unit commitment decides not only how much an asset produces, but which individual units are operating. It is useful when a generator has a minimum stable output, a no-load cost, minimum up and down times, or a maximum time it can stay on.

In this tutorial you will:

  1. Compare none, basic, and 3var unit commitment on one hourly week.
  2. Inspect units_on, start_up, and shut_down.
  3. Limit how long the units can stay on with a maximum up time.
  4. Coarsen the resolution of unit commitment variables and measure the resulting size and accuracy tradeoff.

For the formulation, see Unit Commitment Constraints. The configuration parameters are described in Unit Commitment constraints, and the resolution details are covered in Flexible Time Resolution in the Unit Commitment and Ramping Constraints.

The energy system

This case is based on the energy system from the Basics tutorial, with a single 168-hour week selected from the original hourly profiles.

AssetUnitsCapacity per unitMinimum operating pointUC method
ccgt4200 MW40%3var
ocgt250 MW20%3var
wind, solar, ens1Existing capacities0%none

The ccgt and ocgt capacities are unchanged in aggregate: four 200 MW units provide 800 MW and two 50 MW units provide 100 MW. Their units_on_cost values represent the cost of keeping one unit online for one hour.

import TulipaIO as TIO
import TulipaEnergyModel as TEM
using DuckDB
using DataFrames
using JuMP
using Plots

input_dir = joinpath(@__DIR__, "my-awesome-energy-system/tutorial-uc")

function load_uc_connection()
    connection = DBInterface.connect(DuckDB.DB)
    TIO.read_csv_folder(connection, input_dir)
    return connection
end

connection = load_uc_connection()
asset_data = TIO.get_table(connection, "asset")
select(
    asset_data,
    :asset,
    :type,
    :capacity,
    :unit_commitment,
    :min_operating_point,
    :minimum_down_time,
    :minimum_up_time,
    :maximum_up_time,
)
9×8 DataFrame
Rowassettypecapacityunit_commitmentmin_operating_pointminimum_down_timeminimum_up_timemaximum_up_time
StringStringFloat64StringFloat64Int64Int64String?
1ccgtproducer200.03var0.4812missing
2e_demandconsumer0.0none0.011missing
3ensproducer1000.0none0.011missing
4ocgtproducer50.03var0.211missing
5solarproducer500.0none0.011missing
6windproducer400.0none0.011missing
7electrolizerconversion100.0none0.011missing
8h2_demandconsumer100.0none0.011missing
9smr_ccsproducer100.0none0.011missing

The default data contains the 3-variable formulation for the 'ccgt', 'ocgt'. These two thermal assets are the only assets with unit commitment. The maximum_up_time column is empty, so the units can stay on for as long as needed.

For the unit commitment modelling it is also important to consider different cost components, such as the units_on_cost, shut_down_cost, and start_up_cost, which influence the optimal commitment schedule of the thermal units. Let's have a look at these cost parameters in the asset milestone file.

asset_milestone = filter(
    row -> row.asset in ("ccgt", "ocgt"),
    TIO.get_table(connection, "asset_milestone"),
)
select(
    asset_milestone,
    :asset,
    :milestone_year,
    :units_on_cost,
    :shut_down_cost,
    :start_up_cost
)
2×5 DataFrame
Rowassetmilestone_yearunits_on_costshut_down_coststart_up_cost
StringInt64Float64Float64?Float64?
1ccgt20302000.0100.0200.0
2ocgt2030300.070.0160.0

Part 1: hourly unit commitment

The helper below creates a fresh model for each comparison. Fresh connections are important because run_scenario creates internal tables and writes solution values into the connection.

function run_uc_case(
    unit_commitment;
    minimum_up_time = nothing,
    minimum_down_time = nothing,
    maximum_up_time = nothing,
    asset_partition = 1,
    flow_partition = nothing,
)
    connection = load_uc_connection()
    DuckDB.query(connection, """
        UPDATE asset
        SET unit_commitment = '$unit_commitment'
        WHERE asset IN ('ccgt', 'ocgt')
    """)
    if !isnothing(minimum_up_time)
        DuckDB.query(connection, """
            UPDATE asset
            SET minimum_up_time = $minimum_up_time
            WHERE asset IN ('ccgt', 'ocgt')
        """)
    end

    if !isnothing(minimum_down_time)
        DuckDB.query(connection, """
            UPDATE asset
            SET minimum_down_time = $minimum_down_time
            WHERE asset IN ('ccgt', 'ocgt')
        """)
    end

    if !isnothing(maximum_up_time)
        DuckDB.query(connection, """
            UPDATE asset
            SET maximum_up_time = $maximum_up_time
            WHERE asset IN ('ccgt', 'ocgt')
        """)
    end

    if unit_commitment == "none"
        DuckDB.query(connection, """
            UPDATE asset
            SET min_operating_point = 0.0,
            WHERE asset IN ('ccgt', 'ocgt')
        """)
    end

    if unit_commitment in ("none", "basic")
        DuckDB.query(connection, """
            UPDATE asset_milestone
            SET shut_down_cost = NULL,
                start_up_cost = NULL
            WHERE asset IN ('ccgt', 'ocgt')
        """)
    end

    if asset_partition > 1
        DuckDB.query(connection, """
            CREATE OR REPLACE TABLE assets_rep_periods_partitions AS
            SELECT * FROM (VALUES
                ('ccgt', 2030, 1, '$asset_partition', 'uniform'),
                ('ocgt', 2030, 1, '$asset_partition', 'uniform')
            ) AS partitions(asset, milestone_year, rep_period, partition, specification)
        """)
    end

    if !isnothing(flow_partition)
        DuckDB.query(connection, """
            CREATE OR REPLACE TABLE flows_rep_periods_partitions AS
            SELECT * FROM (VALUES
                ('ccgt', 'e_demand', 2030, 1, '$flow_partition', 'uniform'),
                ('ocgt', 'e_demand', 2030, 1, '$flow_partition', 'uniform')
            ) AS partitions(from_asset, to_asset, milestone_year, rep_period, partition, specification)
        """)
    end

    TEM.populate_with_defaults!(connection)
    energy_problem = nothing
    model_build_time = @elapsed begin
        energy_problem = TEM.EnergyProblem(connection; show_log = :none)
        TEM.create_model!(energy_problem; show_log = :none)
    end
    TEM.solve_model!(energy_problem)
    solver_time = JuMP.solve_time(energy_problem.model)
    TEM.save_solution!(energy_problem)
    timings = (; model_build_time, solver_time)
    return connection, energy_problem, timings
end

function plot_ccgt_dispatch_and_commitment(connection; show_commitment = true)
    ccgt_flow = filter(
        row -> row.from_asset == "ccgt" && row.to_asset == "e_demand",
        TIO.get_table(connection, "var_flow"),
    )
    p = plot(
        ccgt_flow.time_block_start,
        ccgt_flow.solution;
        label = "ccgt output",
        xlabel = "Hour",
        ylabel = "MW",
        xlims = (1, 168),
        legend = :topright,
    )

    if show_commitment
        ccgt_units_on = filter(
            row -> row.asset == "ccgt",
            TIO.get_table(connection, "var_units_on"),
        )
        plot!(
            p,
            ccgt_units_on.time_block_start,
            200 .* ccgt_units_on.solution;
            fillrange = 0.4 .* 200 .* ccgt_units_on.solution,
            fillalpha = 0.2,
            label = "ccgt capacity band",
        )
    end

    return p
end
plot_ccgt_dispatch_and_commitment (generic function with 1 method)

No unit commitment

With unit_commitment = "none", the model dispatches the available capacity economically. It does not create units_on, start_up, or shut_down variables.

none_connection, none_problem, _ = run_uc_case("none")
(none_objective = none_problem.objective_value,
 variables = JuMP.num_variables(none_problem.model),
 constraints = JuMP.num_constraints(none_problem.model; count_variable_in_set_constraints = false))
(none_objective = 3.345813503392154e6, variables = 1344, constraints = 1680)

Let's have a look at the dispatch and commitment of the ccgt units without unit commitment variables and constraints.

plot_ccgt_dispatch_and_commitment(none_connection; show_commitment = false)
Example block output

There is no unit-commitment, so there is no units_on, start_up, or shut_down variables, just the output flow of the ccgt units.

Must-run assets

none can still be combined with a positive min_operating_point to represent a must-run asset. That creates a minimum-output constraint, but it does not create commitment variables.

Basic unit commitment

The basic formulation adds units_on. Output is bounded below by the minimum operating point and above by the capacity of the units that are on.

basic_connection, basic_problem, _ = run_uc_case("basic")
(basic_objective = basic_problem.objective_value,
 variables = JuMP.num_variables(basic_problem.model),
 constraints = JuMP.num_constraints(basic_problem.model; count_variable_in_set_constraints = false))
(basic_objective = 4.048014636861077e6, variables = 1680, constraints = 2688)

By adding the units_on variables, the model can now represent the commitment state of each unit explicitly and the cost of being online through the parameter units_on_cost. Therefore the cost and number of variables and constraints increase compared to the none formulation.

The ccgt output and its commitment state can be plotted together. The shaded interval is the feasible output band for the committed units.

plot_ccgt_dispatch_and_commitment(basic_connection)
Example block output

Three-variable unit commitment

The 3var formulation adds start_up and shut_down and links them to changes in units_on. It also enforces minimum up and down times.

First use one-hour minimum times. This isolates the difference between the variable sets: the objective is higher since the model now accounts for start-up and shut-down costs.

threevar_hourly_connection, threevar_hourly_problem, _ = run_uc_case(
    "3var";
    minimum_up_time = 1,
    minimum_down_time = 1,
)
(threevar_hourly_objective = threevar_hourly_problem.objective_value,
 variables = JuMP.num_variables(threevar_hourly_problem.model),
 constraints = JuMP.num_constraints(threevar_hourly_problem.model; count_variable_in_set_constraints = false)
)
(threevar_hourly_objective = 4.060019405664692e6, variables = 2352, constraints = 3696)

The cost increases when accounting for start-up and shut-down costs, as reflected in the higher objective value for the 3var formulation compared to the basic formulation. The number of variables and constraints also increases due to the additional transition variables and minimum up/down-time constraints.

Let's have a look at the dispatch and commitment of the ccgt units again in this case:

plot_ccgt_dispatch_and_commitment(threevar_hourly_connection)
Example block output

Since there is a cost on start-up and shut-down, the model will try to minimize the number of transitions, leading to fewer on/off cycles for the ccgt units.

Now use the tutorial defaults: ccgt has a 12-hour minimum up time and 8-hour minimum down time, while ocgt keeps 1-hour limits:

threevar_connection, threevar_problem, _ = run_uc_case(
    "3var";
)
(threevar_objective = threevar_problem.objective_value,
 variables = JuMP.num_variables(threevar_problem.model),
 constraints = JuMP.num_constraints(threevar_problem.model; count_variable_in_set_constraints = false)
)
(threevar_objective = 4.074890963479154e6, variables = 2352, constraints = 3696)

Once again, the model tries to minimize the number of transitions while respecting the minimum up and down times. but, due to the minimum-time restrictions, it may not always be able to switch units exactly when it would be optimal if the units were allowed to switch freely.

Let's check again the dispatch and commitment of the ccgt units under the new minimum up and down time constraints.

plot_ccgt_dispatch_and_commitment(threevar_connection)
Example block output

The minimum-time restrictions reduce the number of switching opportunities. Compare the commitment and transition variables:

start_up = TIO.get_table(threevar_connection, "var_start_up")
shut_down = TIO.get_table(threevar_connection, "var_shut_down")
ccgt_units_on = filter(row -> row.asset == "ccgt", TIO.get_table(threevar_connection, "var_units_on"))
ccgt_start_up = filter(row -> row.asset == "ccgt", start_up)
ccgt_shut_down = filter(row -> row.asset == "ccgt", shut_down)

plot(
    ccgt_units_on.time_block_start,
    ccgt_units_on.solution;
    seriestype = :steppost,
    label = "units on",
    xlabel = "Hour",
    ylabel = "Units",
    xlims = (1, 168),
)
scatter!(
    ccgt_start_up.time_block_start,
    ccgt_start_up.solution;
    label = "start-up",
    marker = :utriangle,
)
scatter!(
    ccgt_shut_down.time_block_start,
    ccgt_shut_down.solution;
    label = "shut-down",
    marker = :dtriangle,
)
Example block output

Maximum up time

The optional maximum_up_time parameter limits how long a unit can stay on after it starts: a unit can only be on if it started within the last maximum_up_time hours. Since the column is empty in the tutorial data, the previous models do not have any maximum up time constraints:

length(threevar_problem.model[:maximum_up_time])
0

Now limit both thermal assets to 24 hours of continuous operation. The value must be greater than or equal to the minimum up time, which is 12 hours for ccgt; otherwise the data validation fails.

maxup_connection, maxup_problem, _ = run_uc_case(
    "3var";
    maximum_up_time = 24,
)
(maxup_objective = maxup_problem.objective_value,
 maximum_up_time_constraints = length(maxup_problem.model[:maximum_up_time]),
 variables = JuMP.num_variables(maxup_problem.model),
 constraints = JuMP.num_constraints(maxup_problem.model; count_variable_in_set_constraints = false)
)
(maxup_objective = 4.0805812440126156e6, maximum_up_time_constraints = 336, variables = 2352, constraints = 4032)

The model has the same variables and one extra constraint for each hourly block of ccgt and ocgt. The objective increases because units that ran for more than a day must now be shut down and started again. Compare the number of ccgt start-ups with and without the limit:

ccgt_units_on_maxup = filter(row -> row.asset == "ccgt", TIO.get_table(maxup_connection, "var_units_on"))
ccgt_start_up_maxup = filter(row -> row.asset == "ccgt", TIO.get_table(maxup_connection, "var_start_up"))
(start_ups_without_limit = round(Int, sum(ccgt_start_up.solution)),
 start_ups_with_24h_limit = round(Int, sum(ccgt_start_up_maxup.solution)))
(start_ups_without_limit = 9, start_ups_with_24h_limit = 18)

The number of units on changes only slightly, because the model can keep the same number of units on by shutting down one unit and starting another one. The constraint limits how long each unit stays on, not how many units are on:

plot(
    ccgt_units_on.time_block_start,
    ccgt_units_on.solution;
    seriestype = :steppost,
    label = "units on (no maximum up time)",
    xlabel = "Hour",
    ylabel = "Units",
    xlims = (1, 168),
)
plot!(
    ccgt_units_on_maxup.time_block_start,
    ccgt_units_on_maxup.solution;
    seriestype = :steppost,
    label = "units on (24 h maximum up time)",
)
scatter!(
    ccgt_start_up_maxup.time_block_start,
    ccgt_start_up_maxup.solution;
    label = "start-up (24 h maximum up time)",
    marker = :utriangle,
)
Example block output
Maximum up time with several units

The ccgt asset has four units, so the constraint applies to the total number of start-ups and units on rather than tracking individual units. The single-unit convex-hull result concerns the isolated temporal commitment constraints, not the full model with dispatch, ramping, or investment decisions. See the maximum up time constraint for the assumptions.

The unit commitment cases can be compared using the objective and model size:

comparison = DataFrame(
    mode = ["none", "basic", "3var (1h up/down)", "3var (tutorial defaults)", "3var (24h maximum up time)"],
    objective = [
        none_problem.objective_value,
        basic_problem.objective_value,
        threevar_hourly_problem.objective_value,
        threevar_problem.objective_value,
        maxup_problem.objective_value,
    ],
    variables = [
        JuMP.num_variables(none_problem.model),
        JuMP.num_variables(basic_problem.model),
        JuMP.num_variables(threevar_hourly_problem.model),
        JuMP.num_variables(threevar_problem.model),
        JuMP.num_variables(maxup_problem.model),
    ],
    structural_constraints = [
        JuMP.num_constraints(p.model; count_variable_in_set_constraints = false) for p in
        (none_problem, basic_problem, threevar_hourly_problem, threevar_problem, maxup_problem)
    ],
)
comparison
5×4 DataFrame
Rowmodeobjectivevariablesstructural_constraints
StringFloat64Int64Int64
1none3.34581e613441680
2basic4.04801e616802688
33var (1h up/down)4.06002e623523696
43var (tutorial defaults)4.07489e623523696
53var (24h maximum up time)4.08058e623524032

none is the least restrictive model. basic adds commitment and minimum-output logic, while 3var adds transition variables and minimum up/down-time logic. The maximum up time adds constraints, but no variables, to the 3var model.

Part 2: coarser commitment resolution

The resolution of units_on, start_up, and shut_down is controlled by assets_rep_periods_partitions. A partition of 4 means that one commitment variable represents a four-hour block. This can reduce the number of integer variables substantially.

The output-flow resolution is separate. If the flow remains hourly, the model can still dispatch hourly while the commitment state changes only every four hours. Coarsening both the commitment variables and the thermal output flows reduces the model further, but can change the dispatch more noticeably.

We use the hourly 3var case as the reference and measure the objective gap:

hourly_reference = threevar_problem.objective_value
partitions = [1, 2, 3, 4]

function partition_sweep(; coarsen_flows = false)
    rows = NamedTuple[]
    for partition in partitions
        connection, problem, timings = run_uc_case(
            "3var";
            asset_partition = partition,
            flow_partition = coarsen_flows ? partition : nothing,
        )
        push!(rows, (
            partition,
            objective = problem.objective_value,
            objective_gap = 100 * (problem.objective_value / hourly_reference - 1),
            variables = JuMP.num_variables(problem.model),
            structural_constraints = JuMP.num_constraints(
                problem.model;
                count_variable_in_set_constraints = false,
            ),
            units_on_rows = DataFrames.nrow(TIO.get_table(connection, "var_units_on")),
            model_build_time = timings.model_build_time,
            solver_time = timings.solver_time,
        ))
    end
    return DataFrame(rows)
end

asset_partition_results = partition_sweep()
flow_partition_results = partition_sweep(; coarsen_flows = true)
4×8 DataFrame
Rowpartitionobjectiveobjective_gapvariablesstructural_constraintsunits_on_rowsmodel_build_timesolver_time
Int64Float64Float64Int64Int64Int64Float64Float64
114.07489e60.0235236963360.8531130.531233
224.22792e63.75544168025201680.8098430.505654
334.3197e66.00781145621281120.8116280.39829
444.44194e69.0075413441932840.8026590.238407

The first sweep changes only the commitment resolution. The second also coarsens the two thermal output flows. Compare the results:

rename(copy(asset_partition_results), :objective_gap => Symbol("objective gap (%)"))
4×8 DataFrame
Rowpartitionobjectiveobjective gap (%)variablesstructural_constraintsunits_on_rowsmodel_build_timesolver_time
Int64Float64Float64Int64Int64Int64Float64Float64
114.07489e60.0235236963360.7859370.458434
224.09135e60.403897184830241680.767250.344777
334.11836e61.06665168028001120.7697610.265261
444.12777e61.2976615962688840.9908160.291656
rename(copy(flow_partition_results), :objective_gap => Symbol("objective gap (%)"))
4×8 DataFrame
Rowpartitionobjectiveobjective gap (%)variablesstructural_constraintsunits_on_rowsmodel_build_timesolver_time
Int64Float64Float64Int64Int64Int64Float64Float64
114.07489e60.0235236963360.8531130.531233
224.22792e63.75544168025201680.8098430.505654
334.3197e66.00781145621281120.8116280.39829
444.44194e69.0075413441932840.8026590.238407

Select the largest partition whose objective gap remains below 1%:

acceptable = filter(:objective_gap => gap -> gap <= 1.0, asset_partition_results)
selected_partition = maximum(acceptable.partition)
selected_partition
2

For this case, the asset-only sweep selects partition 2. The exact value is data-dependent: a partition that is acceptable for one demand and availability profile may be too coarse for another.

plot(
    asset_partition_results.partition,
    asset_partition_results.objective_gap;
    marker = :circle,
    label = "Output flows: hourly",
    xlabel = "Partition (hours)",
    ylabel = "Objective gap (%)",
)
plot!(
    flow_partition_results.partition,
    flow_partition_results.objective_gap;
    marker = :diamond,
    label = "Output flows: same as UC partition",
)
hline!([1.0]; linestyle = :dash, label = "1% objective gap vs fully hourly model")
Example block output

A coarser partition reduces integer variables and structural constraints, but it restricts when a unit can change state. Always compare against a sufficiently resolved reference and choose the coarsest partition that preserves the accuracy needed for the study.

The same sweep also illustrates the scalability trade-off. Model-build time measures the creation of EnergyProblem and the JuMP model. Solver time is reported by the optimizer and excludes model creation and solution extraction.

timing_plot = plot(; layout = (2, 1), size = (800, 700), link = :x)
for (results, label, marker) in (
    (asset_partition_results, "Output flows: hourly", :circle),
    (flow_partition_results, "Output flows: same as UC partition", :diamond),
)
    plot!(
        timing_plot[1],
        results.partition,
        results.model_build_time;
        marker,
        label,
        ylabel = "Model-build time (s)",
    )
    plot!(
        timing_plot[2],
        results.partition,
        results.solver_time;
        marker,
        label,
        xlabel = "Partition (hours)",
        ylabel = "Solver time (s)",
    )
end
timing_plot
Example block output

These timings are illustrative and machine-dependent. The earlier examples warm up the model-building code before the sweep, while JuMP.solve_time reports time inside the optimizer and excludes Julia compilation.

Tip

The 1% objective-gap threshold is measured against the fully hourly model and is a decision criterion for this tutorial case, not a universal guarantee. Validate the selected resolution for the scenarios, assets, and objective components in your own model.

Try it yourself
  1. Change minimum_up_time and minimum_down_time and repeat the partition sweep.
  2. Set unit_commitment_integer = false for the thermal assets and compare the relaxed model size and objective.
  3. Add ramping and inspect how the flow resolution affects the ramping constraints.
  4. Run run_uc_case("3var"; maximum_up_time = 6) and read the data validation error: the maximum up time of ccgt is lower than its minimum up time.
  5. Combine maximum_up_time with a coarser asset_partition and check how the maximum up time window is rounded up to whole commitment blocks.