Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement build_priority for core components #13

Merged
merged 3 commits into from
Aug 20, 2024
Merged
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 .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
shell: julia --project=docs --color=yes {0}
run: |
using Pkg
Pkg.update()
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()
- uses: julia-actions/julia-buildpkg@v1
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Dates = "<0.0.1,1"
GLPK = "1.2.1"
Gurobi = "1.3.0"
HiGHS = "1.9"
IESoptLib = "0.1, 0.2, 0.3"
IESoptLib = "0.3"
Ipopt = "1.6.2"
JLD2 = "0.4"
JSON = "0.21"
Expand Down
12 changes: 4 additions & 8 deletions src/IESopt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,10 @@ function _build_model!(model::JuMP.Model; callbacks::Union{Nothing, Dict})

@info "Preparing components"

# Place Decisions first, since those need to be built before everything else.
corder = Vector{_CoreComponent}(
collect(component for component in values(_iesopt(model).model.components) if component isa Decision),
)
append!(
corder,
collect(component for component in values(_iesopt(model).model.components) if !(component isa Decision)),
)
# Sort components by their build priority.
# For instance, Decisions with a default build priority of 1000 are built before all other components
# with a default build priority of 0
corder = sort(collect(values(_iesopt(model).model.components)); by=_build_priority, rev=true)

@info "Start creating JuMP model"
components_with_addons = []
Expand Down
5 changes: 5 additions & 0 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@
_component_type(::Profile) = :Profile
_component_type(::Unit) = :Unit

_build_priority(cc::_CoreComponent) = _build_priority(cc.build_priority, 0.0)
_build_priority(::Nothing, default) = default
_build_priority(priority::Real, ::T) where {T} = convert(T, priority)
_build_priority(priority, ::Any) = @error "Unsupported build priority" priority

Check warning on line 184 in src/core.jl

View check run for this annotation

Codecov / codecov/patch

src/core.jl#L184

Added line #L184 was not covered by tests

function Base.getproperty(cc::_CoreComponent, field::Symbol)
try
(field == :var) && (return getfield(cc, :_ccoc).variables)
Expand Down
7 changes: 7 additions & 0 deletions src/core/connection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ A `Connection` is used to model arbitrary flows of energy between `Node`s. It al
pf_R::_OptionalScalarInput = nothing
pf_B::_OptionalScalarInput = nothing

raw"""```{"mandatory": "no", "values": "numeric", "unit": "-", "default": "`0`"}```
Priority for the build order of components. Components with higher build_priority are built before.
This can be useful for addons, that connect multiple components and rely on specific components being initialized
before others.
"""
build_priority::_OptionalScalarInput = nothing

# [Internal] =======================================================================================================
# -

Expand Down
9 changes: 9 additions & 0 deletions src/core/decision.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ component's settings, as well as have associated costs.
"""
sos::Vector{Dict{String, Float64}} = Vector()

raw"""```{"mandatory": "no", "values": "numeric", "unit": "-", "default": "`1000`"}```
Priority for the build order of components. Components with higher build_priority are built before.
This can be useful for addons, that connect multiple components and rely on specific components being initialized
before others.
"""
build_priority::_OptionalScalarInput = nothing

# [Internal] =======================================================================================================
# -

Expand Down Expand Up @@ -153,6 +160,8 @@ function _result(decision::Decision, mode::String, field::String; result::Int=1)
return nothing
end

_build_priority(decision::Decision) = _build_priority(decision.build_priority, 1000.0)

include("decision/con_fixed.jl")
include("decision/con_sos_value.jl")
include("decision/con_sos1.jl")
Expand Down
7 changes: 7 additions & 0 deletions src/core/node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ balance equation. This allows using `Node`s for various storage tasks (like batt
# Powerflow
pf_slack::Bool = false

raw"""```{"mandatory": "no", "values": "numeric", "unit": "-", "default": "`0`"}```
Priority for the build order of components. Components with higher build_priority are built before.
This can be useful for addons, that connect multiple components and rely on specific components being initialized
before others.
"""
build_priority::_OptionalScalarInput = nothing

# [Internal] =======================================================================================================
# -

Expand Down
7 changes: 7 additions & 0 deletions src/core/profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ Besides modelling fixed profiles, they also allow different ways to modify the v
allow_deviation::Symbol = :off
cost_deviation::_OptionalScalarInput = nothing

raw"""```{"mandatory": "no", "values": "numeric", "unit": "-", "default": "`0`"}```
Priority for the build order of components. Components with higher build_priority are built before.
This can be useful for addons, that connect multiple components and rely on specific components being initialized
before others.
"""
build_priority::_OptionalScalarInput = nothing

# [Internal] =======================================================================================================
# -

Expand Down
7 changes: 7 additions & 0 deletions src/core/unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ A `Unit` allows transforming one (or many) forms of energy into another one (or
"""
startup_cost::_OptionalScalarInput = nothing

raw"""```{"mandatory": "no", "values": "numeric", "unit": "-", "default": "`0`"}```
Priority for the build order of components. Components with higher build_priority are built before.
This can be useful for addons, that connect multiple components and rely on specific components being initialized
before others.
"""
build_priority::_OptionalScalarInput = nothing

# [Internal] =======================================================================================================
conversion_dict::Dict{Symbol, Dict{Carrier, _NumericalInput}} = Dict(:in => Dict(), :out => Dict())
conversion_at_min_dict::Dict{Symbol, Dict{Carrier, _NumericalInput}} = Dict(:in => Dict(), :out => Dict())
Expand Down