Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/InfrastructureOptimizationModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ include("core/optimization_container_types.jl") # Abstract types (Variable
include("core/definitions.jl") # Aliases and enums (needs VariableType)
# SimulationInfo is defined in IS.Simulation
include("core/optimization_container_keys.jl") # Keys depend on types
include("core/optimization_container_utils.jl") # key <-> type <-> field correspondences
include("core/parameter_container.jl") # Parameter container infrastructure
include("core/abstract_model_store.jl") # Store depends on keys
include("core/optimizer_stats.jl") # Stats standalone
Expand Down
10 changes: 5 additions & 5 deletions src/common_models/add_pwl_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ function _add_generic_incremental_interpolation_constraint!(
# Retrieve all required variables from the optimization container
# Retrieve original variable for DCVoltage from the Bus
x_var = if (R <: DCVoltage)
get_variable(container, R(), PSY.DCBus) # Original variable (domain of function)
get_variable(container, R, PSY.DCBus) # Original variable (domain of function)
else
get_variable(container, R(), W) # Original variable (domain of function)
get_variable(container, R, W) # Original variable (domain of function)
end # Original variable (domain of function)
y_var = get_variable(container, S(), W) # Approximated variable (range of function)
δ_var = get_variable(container, T(), W) # Interpolation variables (weights for segments)
z_var = get_variable(container, U(), W) # Binary variables (ordering constraints)
y_var = get_variable(container, S, W) # Approximated variable (range of function)
δ_var = get_variable(container, T, W) # Interpolation variables (weights for segments)
z_var = get_variable(container, U, W) # Binary variables (ordering constraints)

# Create containers for the two main constraint types
# Container for variable interpolation constraints: x = x₁ + Σᵢ δᵢ(xᵢ₊₁ - xᵢ)
Expand Down
28 changes: 14 additions & 14 deletions src/common_models/range_constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function add_range_constraints!(
W <: AbstractDeviceFormulation,
X <: AbstractPowerModel,
}
array = get_variable(container, U(), V)
array = get_variable(container, U, V)
_add_bound_range_constraints_impl!(container, T, LowerBound(), array, devices, model)
_add_bound_range_constraints_impl!(container, T, UpperBound(), array, devices, model)
return
Expand All @@ -57,7 +57,7 @@ function add_range_constraints!(
W <: AbstractDeviceFormulation,
X <: AbstractPowerModel,
}
array = get_expression(container, U(), V)
array = get_expression(container, U, V)
_add_bound_range_constraints_impl!(container, T, LowerBound(), array, devices, model)
return
end
Expand All @@ -76,7 +76,7 @@ function add_range_constraints!(
W <: AbstractDeviceFormulation,
X <: AbstractPowerModel,
}
array = get_expression(container, U(), V)
array = get_expression(container, U, V)
_add_bound_range_constraints_impl!(container, T, UpperBound(), array, devices, model)
return
end
Expand Down Expand Up @@ -143,7 +143,7 @@ function add_semicontinuous_range_constraints!(
W <: AbstractDeviceFormulation,
X <: AbstractPowerModel,
}
array = get_variable(container, U(), V)
array = get_variable(container, U, V)
_add_semicontinuous_bound_range_constraints_impl!(
container, T, LowerBound(), array, devices, model)
_add_semicontinuous_bound_range_constraints_impl!(
Expand All @@ -165,7 +165,7 @@ function add_semicontinuous_range_constraints!(
W <: AbstractDeviceFormulation,
X <: AbstractPowerModel,
}
array = get_expression(container, U(), V)
array = get_expression(container, U, V)
_add_semicontinuous_bound_range_constraints_impl!(
container, T, LowerBound(), array, devices, model)
return
Expand All @@ -185,7 +185,7 @@ function add_semicontinuous_range_constraints!(
W <: AbstractDeviceFormulation,
X <: AbstractPowerModel,
}
array = get_expression(container, U(), V)
array = get_expression(container, U, V)
_add_semicontinuous_bound_range_constraints_impl!(
container, T, UpperBound(), array, devices, model)
return
Expand All @@ -205,7 +205,7 @@ function _add_semicontinuous_bound_range_constraints_impl!(
jump_model = get_jump_model(container)
con = add_constraints_container!(
container, T(), V, names, time_steps; meta = constraint_meta(dir))
varbin = get_variable(container, OnVariable(), V)
varbin = get_variable(container, OnVariable, V)

for device in devices, t in time_steps
ci_name = PSY.get_name(device)
Expand All @@ -231,7 +231,7 @@ function _add_semicontinuous_bound_range_constraints_impl!(
jump_model = get_jump_model(container)
con = add_constraints_container!(
container, T(), V, names, time_steps; meta = constraint_meta(dir))
varbin = get_variable(container, OnVariable(), V)
varbin = get_variable(container, OnVariable, V)

for device in devices
ci_name = PSY.get_name(device)
Expand Down Expand Up @@ -263,7 +263,7 @@ function add_reserve_bound_range_constraints!(

con = add_constraints_container!(
container, T(), V, names, time_steps; meta = constraint_meta(dir))
varbin = get_variable(container, ReservationVariable(), V)
varbin = get_variable(container, ReservationVariable, V)

for device in devices, t in time_steps
ci_name = PSY.get_name(device)
Expand Down Expand Up @@ -293,7 +293,7 @@ function add_parameterized_bound_range_constraints(
W <: AbstractDeviceFormulation,
X <: AbstractPowerModel,
}
array = get_expression(container, U(), V)
array = get_expression(container, U, V)
_add_parameterized_bound_range_constraints_impl!(
container, T, dir, array, P(), devices, model)
return
Expand All @@ -316,7 +316,7 @@ function add_parameterized_bound_range_constraints(
W <: AbstractDeviceFormulation,
X <: AbstractPowerModel,
}
array = get_variable(container, U(), V)
array = get_variable(container, U, V)
_add_parameterized_bound_range_constraints_impl!(
container, T, dir, array, P(), devices, model)
return
Expand Down Expand Up @@ -452,8 +452,8 @@ function _bound_range_with_parameter!(
devices::Union{Vector{V}, IS.FlattenIteratorWrapper{V}},
::DeviceModel{V, W},
) where {P <: ParameterType, V <: PSY.Component, W <: AbstractDeviceFormulation}
param_array = get_parameter_array(container, param, V)
param_multiplier = get_parameter_multiplier_array(container, P(), V)
param_array = get_parameter_array(container, P, V)
param_multiplier = get_parameter_multiplier_array(container, P, V)
jump_model = get_jump_model(container)
time_steps = axes(constraint_container)[2]
for device in devices, t in time_steps
Expand Down Expand Up @@ -502,7 +502,7 @@ function _bound_range_with_parameter!(
devices::Union{Vector{V}, IS.FlattenIteratorWrapper{V}},
model::DeviceModel{V, W},
) where {P <: TimeSeriesParameter, V <: PSY.Component, W <: AbstractDeviceFormulation}
param_container = get_parameter(container, param, V)
param_container = get_parameter(container, P, V)
mult = get_multiplier_array(param_container)
jump_model = get_jump_model(container)
time_steps = axes(constraint_container)[2]
Expand Down
34 changes: 17 additions & 17 deletions src/common_models/rateofchange_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ function _get_ramp_slack_vars(
t::Int,
) where {V <: PSY.Component, W <: AbstractDeviceFormulation}
if get_use_slacks(model)
slack_up = get_variable(container, RateofChangeConstraintSlackUp(), V)
slack_dn = get_variable(container, RateofChangeConstraintSlackDown(), V)
slack_up = get_variable(container, RateofChangeConstraintSlackUp, V)
slack_dn = get_variable(container, RateofChangeConstraintSlackDown, V)
return (up = slack_up[name, t], down = slack_dn[name, t])
else
return (up = 0.0, down = 0.0)
Expand Down Expand Up @@ -86,17 +86,17 @@ function add_linear_ramp_constraints!(
}
# common setup for all ramp constraints
time_steps = get_time_steps(container)
variable = get_variable(container, U(), V)
variable = get_variable(container, U, V)
ramp_devices = _get_ramp_constraint_devices(container, devices)
minutes_per_period = _get_minutes_per_period(container)
IC = _get_initial_condition_type(T, V, W)
initial_conditions_power = get_initial_condition(container, IC(), V)
initial_conditions_power = get_initial_condition(container, IC, V)
jump_model = get_jump_model(container)
device_name_set = PSY.get_name.(ramp_devices)
cons = add_updown_constraints_containers!(container, T, V, device_name_set, time_steps)

expr_dn = get_expression(container, ActivePowerRangeExpressionLB(), V)
expr_up = get_expression(container, ActivePowerRangeExpressionUB(), V)
expr_dn = get_expression(container, ActivePowerRangeExpressionLB, V)
expr_up = get_expression(container, ActivePowerRangeExpressionUB, V)

for ic in initial_conditions_power
name = get_component_name(ic)
Expand Down Expand Up @@ -135,11 +135,11 @@ function _add_linear_ramp_constraints_impl!(
) where {V <: PSY.Component, W <: AbstractDeviceFormulation}
# common setup for all ramp constraints
time_steps = get_time_steps(container)
variable = get_variable(container, U(), V)
variable = get_variable(container, U, V)
ramp_devices = _get_ramp_constraint_devices(container, devices)
minutes_per_period = _get_minutes_per_period(container)
IC = _get_initial_condition_type(T, V, W)
initial_conditions_power = get_initial_condition(container, IC(), V)
initial_conditions_power = get_initial_condition(container, IC, V)
jump_model = get_jump_model(container)
device_name_set = PSY.get_name.(ramp_devices)
cons = add_updown_constraints_containers!(container, T, V, device_name_set, time_steps)
Expand Down Expand Up @@ -203,17 +203,17 @@ function add_linear_ramp_constraints!(

# common setup for all ramp constraints
time_steps = get_time_steps(container)
variable = get_variable(container, U(), V)
variable = get_variable(container, U, V)
ramp_devices = _get_ramp_constraint_devices(container, devices)
minutes_per_period = _get_minutes_per_period(container)
IC = _get_initial_condition_type(T, V, W)
initial_conditions_power = get_initial_condition(container, IC(), V)
initial_conditions_power = get_initial_condition(container, IC, V)
jump_model = get_jump_model(container)
device_name_set = [PSY.get_name(r) for r in ramp_devices]
cons = add_updown_constraints_containers!(container, T, V, device_name_set, time_steps)

# Commitment path from UC as a PARAMETER (fixed 0/1)
on_param = get_parameter(container, OnStatusParameter(), V)
on_param = get_parameter(container, OnStatusParameter, V)
on_status = on_param.parameter_array # on_status[name, t] ∈ {0,1} (fixed)

for dev in ramp_devices
Expand Down Expand Up @@ -287,19 +287,19 @@ function add_semicontinuous_ramp_constraints!(
}
# common setup for all ramp constraints
time_steps = get_time_steps(container)
variable = get_variable(container, U(), V)
variable = get_variable(container, U, V)
ramp_devices = _get_ramp_constraint_devices(container, devices)
minutes_per_period = _get_minutes_per_period(container)
IC = _get_initial_condition_type(T, V, W)
initial_conditions_power = get_initial_condition(container, IC(), V)
initial_conditions_power = get_initial_condition(container, IC, V)
jump_model = get_jump_model(container)
device_name_set = PSY.get_name.(ramp_devices)
cons = add_updown_constraints_containers!(container, T, V, device_name_set, time_steps)

varstart = get_variable(container, StartVariable(), V)
varstop = get_variable(container, StopVariable(), V)
expr_dn = get_expression(container, ActivePowerRangeExpressionLB(), V)
expr_up = get_expression(container, ActivePowerRangeExpressionUB(), V)
varstart = get_variable(container, StartVariable, V)
varstop = get_variable(container, StopVariable, V)
expr_dn = get_expression(container, ActivePowerRangeExpressionLB, V)
expr_up = get_expression(container, ActivePowerRangeExpressionUB, V)

for ic in initial_conditions_power
name = get_component_name(ic)
Expand Down
2 changes: 1 addition & 1 deletion src/common_models/set_expression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function set_expression!(
time_period::Int,
) where {S <: CostExpressions, T <: PSY.Component}
if has_container_key(container, S, T)
device_cost_expression = get_expression(container, S(), T)
device_cost_expression = get_expression(container, S, T)
component_name = PSY.get_name(component)
device_cost_expression[component_name, time_period] = cost_expression
end
Expand Down
79 changes: 35 additions & 44 deletions src/core/abstract_model_store.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ const STORE_CONTAINERS = (
STORE_CONTAINER_AUX_VARIABLES,
STORE_CONTAINER_EXPRESSIONS,
)
const STORE_CONTAINER_TYPES = (
ConstraintType,
ParameterType,
VariableType,
AuxVariableType,
ExpressionType,
)

# Keep these in sync with the Symbols in src/core/definitions.
get_store_container_type(::AuxVarKey) = STORE_CONTAINER_AUX_VARIABLES
get_store_container_type(::ConstraintKey) = STORE_CONTAINER_DUALS
get_store_container_type(::ExpressionKey) = STORE_CONTAINER_EXPRESSIONS
get_store_container_type(::ParameterKey) = STORE_CONTAINER_PARAMETERS
get_store_container_type(::VariableKey) = STORE_CONTAINER_VARIABLES
# Derives from store_field_for_type in optimization_container_utils.jl
get_store_container_type(
::OptimizationContainerKey{T, U},
) where {T <: OptimizationKeyType, U <: InfrastructureSystemsType} = store_field_for_type(T)

abstract type AbstractModelStore end

Expand Down Expand Up @@ -46,6 +51,9 @@ function Base.empty!(store::T) where {T <: AbstractModelStore}
end
end

# FIXME getproperty allows for more customization than getfield, but we're not actually
# using that flexibility anywhere downstream...
# PERF symbols likely resolve at runtime. Would be better to do type and @generated.
get_data_field(store::AbstractModelStore, type::Symbol) = getproperty(store, type)

function Base.isempty(store::T) where {T <: AbstractModelStore}
Expand All @@ -62,51 +70,34 @@ function Base.isempty(store::T) where {T <: AbstractModelStore}
return true
end

function list_fields(store::AbstractModelStore, container_type::Symbol)
return keys(get_data_field(store, container_type))
end

function list_keys(store::AbstractModelStore, container_type::Symbol)
container = get_data_field(store, container_type)
return collect(keys(container))
end

function get_value(
store::AbstractModelStore,
::T,
::Type{U},
) where {T <: VariableType, U <: InfrastructureSystemsType}
return get_data_field(store, STORE_CONTAINER_VARIABLES)[VariableKey(T, U)]
end

function get_value(
@generated function list_fields(
store::AbstractModelStore,
::T,
::Type{U},
) where {T <: AuxVariableType, U <: InfrastructureSystemsType}
return get_data_field(store, STORE_CONTAINER_AUX_VARIABLES)[AuxVarKey(T, U)]
::Type{T},
) where {T <: OptimizationKeyType}
field = QuoteNode(store_field_for_type(T))
return :(return keys(getfield(store, $field)))
end

function get_value(
@generated function list_keys(
store::AbstractModelStore,
::T,
::Type{U},
) where {T <: ConstraintType, U <: InfrastructureSystemsType}
return get_data_field(store, STORE_CONTAINER_DUALS)[ConstraintKey(T, U)]
::Type{T},
) where {T <: OptimizationKeyType}
field = QuoteNode(store_field_for_type(T))
return :(return collect(keys(getfield(store, $field))))
end

function get_value(
@generated function get_value(
store::AbstractModelStore,
::T,
::Type{T},
::Type{U},
) where {T <: ParameterType, U <: InfrastructureSystemsType}
return get_data_field(store, STORE_CONTAINER_PARAMETERS)[ParameterKey(T, U)]
) where {T <: OptimizationKeyType, U <: InfrastructureSystemsType}
K = key_for_type(T)
field = QuoteNode(store_field_for_type(T))
return :(return getfield(store, $field)[$K(T, U)])
end

function get_value(
store::AbstractModelStore,
::T,
::Type{U},
) where {T <: ExpressionType, U <: InfrastructureSystemsType}
return get_data_field(store, STORE_CONTAINER_EXPRESSIONS)[ExpressionKey(T, U)]
end
# TODO: deprecate once POM is migrated to pass types (issue #18)
get_value(
store::AbstractModelStore, ::T, ::Type{U},
) where {T <: OptimizationKeyType, U <: InfrastructureSystemsType} =
get_value(store, T, U)
Loading
Loading