diff --git a/src/operation/decision_model.jl b/src/operation/decision_model.jl index 8287346b53..a0cde57e3d 100644 --- a/src/operation/decision_model.jl +++ b/src/operation/decision_model.jl @@ -9,6 +9,15 @@ Generic PowerSimulations Operation Problem Type for unspecified models """ struct GenericOpProblem <: DefaultDecisionProblem end +mutable struct DecisionModel{M <: DecisionProblem} <: OperationModel + name::Symbol + template::ProblemTemplate + sys::PSY.System + internal::Union{Nothing, ModelInternal} + store::DecisionModelStore + ext::Dict{String, Any} +end + """ DecisionModel{M}( template::ProblemTemplate, @@ -51,40 +60,31 @@ template = ProblemTemplate(CopperPlatePowerModel, devices, branches, services) OpModel = DecisionModel(MockOperationProblem, template, system) ``` """ -mutable struct DecisionModel{M <: DecisionProblem} <: OperationModel - name::Symbol - template::ProblemTemplate - sys::PSY.System - internal::Union{Nothing, ModelInternal} - store::DecisionModelStore - ext::Dict{String, Any} - - function DecisionModel{M}( - template::ProblemTemplate, - sys::PSY.System, - settings::Settings, - jump_model::Union{Nothing, JuMP.Model} = nothing; - name = nothing, - ) where {M <: DecisionProblem} - if name === nothing - name = nameof(M) - elseif name isa String - name = Symbol(name) - end - internal = ModelInternal( - OptimizationContainer(sys, settings, jump_model, PSY.Deterministic), - ) - template_ = deepcopy(template) - finalize_template!(template_, sys) - return new{M}( - name, - template_, - sys, - internal, - DecisionModelStore(), - Dict{String, Any}(), - ) +function DecisionModel{M}( + template::ProblemTemplate, + sys::PSY.System, + settings::Settings, + jump_model::Union{Nothing, JuMP.Model} = nothing; + name = nothing, +) where {M <: DecisionProblem} + if name === nothing + name = nameof(M) + elseif name isa String + name = Symbol(name) end + internal = ModelInternal( + OptimizationContainer(sys, settings, jump_model, PSY.Deterministic), + ) + template_ = deepcopy(template) + finalize_template!(template_, sys) + return DecisionModel{M}( + name, + template_, + sys, + internal, + DecisionModelStore(), + Dict{String, Any}(), + ) end function DecisionModel{M}( diff --git a/src/operation/decision_model_store.jl b/src/operation/decision_model_store.jl index b8c2591164..686a5b9586 100644 --- a/src/operation/decision_model_store.jl +++ b/src/operation/decision_model_store.jl @@ -27,7 +27,7 @@ end function initialize_storage!( store::DecisionModelStore, - container::OptimizationContainer, + container::AbstractModelContainer, params::ModelStoreParams, ) num_of_executions = get_num_executions(params) diff --git a/src/operation/model_internal.jl b/src/operation/model_internal.jl index f00b690259..4753e6f648 100644 --- a/src/operation/model_internal.jl +++ b/src/operation/model_internal.jl @@ -12,9 +12,9 @@ mutable struct SimulationInfo sequence_uuid::Base.UUID end -mutable struct ModelInternal - container::OptimizationContainer - ic_model_container::Union{Nothing, OptimizationContainer} +mutable struct ModelInternal{T <: AbstractModelContainer} + container::T + ic_model_container::Union{Nothing, T} status::BuildStatus run_status::RunStatus base_conversion::Bool @@ -31,11 +31,11 @@ mutable struct ModelInternal end function ModelInternal( - container::OptimizationContainer; + container::T; ext = Dict{String, Any}(), recorders = [], -) - return ModelInternal( +) where {T <: AbstractModelContainer} + return ModelInternal{T}( container, nothing, BuildStatus.EMPTY, diff --git a/src/operation/operation_model_interface.jl b/src/operation/operation_model_interface.jl index 688f6013f7..9a1e01c0c0 100644 --- a/src/operation/operation_model_interface.jl +++ b/src/operation/operation_model_interface.jl @@ -10,7 +10,7 @@ get_execution_count(model::OperationModel) = get_internal(model).execution_count get_executions(model::OperationModel) = get_internal(model).executions get_initial_time(model::OperationModel) = get_initial_time(get_settings(model)) get_internal(model::OperationModel) = model.internal -get_jump_model(model::OperationModel) = get_internal(model).container.JuMPmodel +get_jump_model(model::OperationModel) = get_jump_model(get_internal(model).container) get_name(model::OperationModel) = model.name get_store(model::OperationModel) = model.store is_synchronized(model::OperationModel) = is_synchronized(get_optimization_container(model))