Skip to content

Commit

Permalink
Using demote_formulation on-demand during ModelView wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
coroa committed Jun 19, 2019
1 parent 1119c42 commit 888000f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/components/components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ function addto! end
function addto!(jm::JuMP.AbstractModel, m::EnergyModel, c::Component)
addto!(ModelView(jm, c), m, c)
end
function addto!(jm::JuMP.AbstractModel, m::EnergyModel, d::Device)
addto!(ModelView(jm, d), m, demote_formulation(m, d))
end

include("energymodel.jl")
include("subnetwork.jl")
Expand Down
11 changes: 8 additions & 3 deletions src/formulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ struct UnitCommittmentModel <: DispatchModel end
abstract type ExpansionModel <: ModelType end

# If nothing else is said, let's say it's fine
demote_formulation(::Type{ExpansionModel}, DF::Type{ExpansionForm}) = DF
demote_formulation(::Type{DispatchModel}, DF::Type{DispatchForm}) = DF
demote_formulation(::Type{ExpansionModel}, ::Type{DF}) where DF <: ExpansionForm = DF
demote_formulation(::Type{DispatchModel}, ::Type{DF}) where DF <: DispatchForm = DF

# An expansion form should demote to its respective DispatchForm
demote_formulation(MT::Type{DispatchModel}, ::Type{ExpansionForm{DDF}}) where DDF <: DispatchForm = demote_formulation(MT, DDF)
demote_formulation(::Type{MT}, ::Type{DF}) where {MT <: DispatchModel, DDF, DF <: ExpansionForm{DDF}} = demote_formulation(MT, DDF)

# We demote UnitCommittment to LinearDispatch in a LinearDispatchModel
demote_formulation(::Type{LinearDispatchModel}, ::Type{UnitCommittmentForm}) = LinearDispatchForm

function demote_formulation(m::EnergyModel{MT}, d::Device{DF}) where {MT <: ModelType, DF <: DeviceFormulation}
# TODO test whether conditionally changing the type would be faster!
with_formulation(d, demote_formulation(MT, DF))
end

with_formulation(d::T, ::Type{DF}) where {T <: Device, DF <: DeviceFormulation} = T(d, DF)

0 comments on commit 888000f

Please sign in to comment.