| """ |
| set_power_trajectories(instance, curves; clear_unselected = true) |
| |
| Return a deep-copied instance with startup/shutdown curves assigned to the |
| selected thermal units. |
| |
| `curves` must be a dictionary like: |
| Dict( |
| "g1" => (startup = [75.035, 150.07], shutdown = [150.07, 75.035]), |
| "g3" => (startup = [128.76, 257.52], shutdown = [257.52, 128.76]), |
| ) |
| """ |
| function set_power_trajectories( |
| instance::UnitCommitmentInstance, |
| curves::AbstractDict{<:AbstractString,<:Any}; |
| clear_unselected::Bool = true, |
| )::UnitCommitmentInstance |
| modified = deepcopy(instance) |
| set_power_trajectories!(modified, curves; clear_unselected = clear_unselected) |
| return modified |
| end |
|
|
| function set_power_trajectories!( |
| instance::UnitCommitmentInstance, |
| curves::AbstractDict{<:AbstractString,<:Any}; |
| clear_unselected::Bool = true, |
| )::Nothing |
| normalized = Dict{ |
| String, |
| NamedTuple{(:startup, :shutdown),Tuple{Vector{Float64},Vector{Float64}}}, |
| }() |
|
|
| for (name, spec) in curves |
| startup, shutdown = _normalize_curve_spec(String(name), spec) |
| normalized[String(name)] = (startup = startup, shutdown = shutdown) |
| end |
|
|
| selected = Set(keys(normalized)) |
|
|
| for sc in instance.scenarios |
| missing = [name for name in selected if !haskey(sc.thermal_units_by_name, name)] |
| isempty(missing) || error( |
| "Unknown thermal units in scenario $(sc.name): $(join(sort!(missing), ", "))", |
| ) |
|
|
| for (name, spec) in normalized |
| g = sc.thermal_units_by_name[name] |
| g.startup_curve = copy(spec.startup) |
| g.shutdown_curve = copy(spec.shutdown) |
| end |
|
|
| if clear_unselected |
| for g in sc.thermal_units |
| if !(g.name in selected) |
| g.startup_curve = Float64[] |
| g.shutdown_curve = Float64[] |
| end |
| end |
| end |
| end |
|
|
| return |
| end |
|
|
| function clear_power_trajectories!(instance::UnitCommitmentInstance)::Nothing |
| for sc in instance.scenarios |
| for g in sc.thermal_units |
| g.startup_curve = Float64[] |
| g.shutdown_curve = Float64[] |
| end |
| end |
| return |
| end |
|
|
| function _normalize_curve_spec( |
| name::String, |
| spec, |
| )::Tuple{Vector{Float64},Vector{Float64}} |
| spec isa NamedTuple || error( |
| "Curve spec for unit $name must be a named tuple with `startup` and `shutdown`.", |
| ) |
| (:startup in keys(spec) && :shutdown in keys(spec)) || error( |
| "Curve spec for unit $name must contain `startup` and `shutdown`.", |
| ) |
|
|
| startup = Float64.(collect(spec.startup)) |
| shutdown = Float64.(collect(spec.shutdown)) |
|
|
| isempty(startup) && |
| error("startup curve for unit $name cannot be empty") |
| isempty(shutdown) && |
| error("shutdown curve for unit $name cannot be empty") |
|
|
| all(isfinite, startup) || error( |
| "startup curve for unit $name contains non-finite values", |
| ) |
| all(isfinite, shutdown) || error( |
| "shutdown curve for unit $name contains non-finite values", |
| ) |
|
|
| return startup, shutdown |
| end |
|
|