diff --git a/src/InfrastructureOptimizationModels.jl b/src/InfrastructureOptimizationModels.jl index d98a6fb..aa127c3 100644 --- a/src/InfrastructureOptimizationModels.jl +++ b/src/InfrastructureOptimizationModels.jl @@ -326,10 +326,15 @@ export OnStatusParameter # core folder exports # optimization_container.jl refactor -# add_param_container! -export add_param_container!, +# parameter container builders +export add_time_series_parameter_container!, + add_cost_function_parameter_container!, + add_variable_value_parameter_container!, + add_event_parameter_container!, add_param_container_split_axes!, add_param_container_shared_axes! +# Compatibility alias for the four builders above; see add_param_container_shims.jl (issue #147). +export add_param_container! export remove_undef! # Bulk-added: symbols used by POM but previously not exported @@ -344,6 +349,7 @@ export add_sparse_pwl_interpolation_variables! export JuMPOrFloat # Constraint helpers export add_range_constraints!, add_parameterized_upper_bound_range_constraints +export add_parameterized_lower_bound_range_constraints export add_reserve_bound_range_constraints!, add_commitment_bound_range_constraints! export add_semicontinuous_range_constraints!, add_semicontinuous_ramp_constraints! export add_slacked_range_constraints!, fill_slacked_range_constraints! @@ -638,9 +644,10 @@ include("bilinear_approximations/no_approx.jl") include("bilinear_approximations/hybs.jl") include("bilinear_approximations/nmdt.jl") -# add_param_container! wrappers — must come after piecewise_linear.jl +# parameter container builders — must come after piecewise_linear.jl # (which defines VariableValueParameter and FixValueParameter) include("common_models/add_param_container.jl") +include("common_models/add_param_container_shims.jl") include("operation/optimization_model_interface.jl") include("operation/decision_model_store.jl") diff --git a/src/common_models/add_param_container.jl b/src/common_models/add_param_container.jl index 930a4c8..d913279 100644 --- a/src/common_models/add_param_container.jl +++ b/src/common_models/add_param_container.jl @@ -1,8 +1,16 @@ """ -Thin wrappers around `add_param_container_split_axes!` and `add_param_container_shared_axes!` -that dispatch on concrete parameter supertypes to construct the correct `ParameterAttributes`. +Thin wrappers around `add_param_container_split_axes!` and `add_param_container_shared_axes!`. +Each one constructs one `ParameterAttributes` subtype and is named after it; the `T <: ...` +constraints are primarily sanity checks (each builder has a single method) rather than selecting +among multiple overloads of a single `add_param_container!` function. +Legacy `add_param_container!` shims live in `add_param_container_shims.jl`. """ -function add_param_container!( + +""" +Allocate a time-series parameter container (`TimeSeriesAttributes`). Parameter and multiplier +arrays may have different first axes, so this is the only builder using the split-axes allocator. +""" +function add_time_series_parameter_container!( container::OptimizationContainer, ::Type{T}, ::Type{U}, @@ -37,15 +45,21 @@ function add_param_container!( ) end -function add_param_container!( +""" +Allocate a cost-function parameter container (`CostFunctionAttributes`). + +Note that `data_type` sets both the attributes' type parameter and the parameter array's element +type, bypassing `get_param_eltype(container)`. +""" +function add_cost_function_parameter_container!( container::OptimizationContainer, ::Type{T}, ::Type{U}, variable_types::Tuple{Vararg{Type}}, + axs...; sos_variable::SOSStatusVariable = SOSStatusVariable.NO_VARIABLE, uses_compact_power::Bool = false, data_type::DataType = Float64, - axs...; sparse = false, meta = CONTAINER_KEY_EMPTY_META, ) where {T <: ObjectiveFunctionParameter, U <: IS.InfrastructureSystemsComponent} @@ -62,7 +76,11 @@ function add_param_container!( ) end -function add_param_container!( +""" +Allocate a parameter container fed by another container's values (`VariableValueAttributes`). +`source_key` is the variable/aux-variable key supplying those values. +""" +function add_variable_value_parameter_container!( container::OptimizationContainer, ::Type{T}, ::Type{U}, @@ -82,7 +100,11 @@ function add_param_container!( sparse = sparse) end -function add_param_container!( +""" +Allocate an event parameter container (`EventParametersAttributes`). `V` is the component type +whose instances the event affects. +""" +function add_event_parameter_container!( container::OptimizationContainer, ::Type{T}, ::Type{U}, @@ -101,23 +123,3 @@ function add_param_container!( container, param_key, attributes, get_param_eltype(container), axs...; sparse = sparse) end - -function add_param_container!( - container::OptimizationContainer, - ::Type{T}, - ::Type{U}, - source_key::V, - axs...; - sparse = false, - meta = CONTAINER_KEY_EMPTY_META, -) where { - T <: FixValueParameter, - U <: IS.InfrastructureSystemsComponent, - V <: OptimizationContainerKey, -} - param_key = ParameterKey(T, U, meta) - attributes = VariableValueAttributes(source_key) - return add_param_container_shared_axes!( - container, param_key, attributes, get_param_eltype(container), axs...; - sparse = sparse) -end diff --git a/src/common_models/add_param_container_shims.jl b/src/common_models/add_param_container_shims.jl new file mode 100644 index 0000000..bb3aae2 --- /dev/null +++ b/src/common_models/add_param_container_shims.jl @@ -0,0 +1,91 @@ +# Compatibility shims for the old `add_param_container!` name (issue #147). +# +# These forwarders exist only so downstream (POM, PowerSystemsInvestments) keeps working while +# it migrates. Delete this file once all downstream code has been updated to use the new names. + +add_param_container!( + container::OptimizationContainer, + ::Type{T}, + ::Type{U}, + ::Type{V}, + name::String, + param_axs, + multiplier_axs, + additional_axs, + time_steps::UnitRange{Int}; + sparse = false, + meta = CONTAINER_KEY_EMPTY_META, +) where { + T <: TimeSeriesParameter, + U <: IS.InfrastructureSystemsComponent, + V <: IS.TimeSeriesData, +} = add_time_series_parameter_container!( + container, + T, + U, + V, + name, + param_axs, + multiplier_axs, + additional_axs, + time_steps; + sparse = sparse, + meta = meta, +) + +add_param_container!( + container::OptimizationContainer, + ::Type{T}, + ::Type{U}, + variable_types::Tuple{Vararg{Type}}, + sos_variable::SOSStatusVariable = SOSStatusVariable.NO_VARIABLE, + uses_compact_power::Bool = false, + data_type::DataType = Float64, + axs...; + sparse = false, + meta = CONTAINER_KEY_EMPTY_META, +) where {T <: ObjectiveFunctionParameter, U <: IS.InfrastructureSystemsComponent} = + add_cost_function_parameter_container!( + container, + T, + U, + variable_types, + axs...; + sos_variable = sos_variable, + uses_compact_power = uses_compact_power, + data_type = data_type, + sparse = sparse, + meta = meta, + ) + +# Also covers the old `T <: FixValueParameter` method, which was byte-for-byte identical to the +# `VariableValueParameter` one (`FixValueParameter <: VariableValueParameter`). +add_param_container!( + container::OptimizationContainer, + ::Type{T}, + ::Type{U}, + source_key::V, + axs...; + sparse = false, + meta = CONTAINER_KEY_EMPTY_META, +) where { + T <: VariableValueParameter, + U <: IS.InfrastructureSystemsComponent, + V <: OptimizationContainerKey, +} = add_variable_value_parameter_container!( + container, T, U, source_key, axs...; sparse = sparse, meta = meta) + +add_param_container!( + container::OptimizationContainer, + ::Type{T}, + ::Type{U}, + ::Type{V}, + axs...; + sparse = false, + meta = CONTAINER_KEY_EMPTY_META, +) where { + T <: EventParameter, + U <: IS.InfrastructureSystemsComponent, + V <: IS.InfrastructureSystemsComponent, +} = add_event_parameter_container!( + container, T, U, V, axs...; sparse = sparse, meta = meta)