From 1331dc07da319887436d21794a8109a8fcfc9cd7 Mon Sep 17 00:00:00 2001 From: ccoffrin Date: Sun, 12 Apr 2020 21:47:41 -0600 Subject: [PATCH 1/2] updates for powermodels v0.16 --- Project.toml | 2 +- src/PowerModelsRestoration.jl | 4 +- src/core/constraint.jl | 142 ++++++++-------- src/core/constraint_template.jl | 214 +++++++++++------------ src/core/data.jl | 82 ++++----- src/core/objective.jl | 110 ++++++------ src/core/ref.jl | 28 +-- src/core/variable.jl | 260 ++++++++++++++-------------- src/form/acp.jl | 60 +++---- src/form/apo.jl | 4 +- src/form/dcp.jl | 96 +++++------ src/form/shared.jl | 56 +++--- src/form/wr.jl | 208 +++++++++++------------ src/form/wrm.jl | 42 ++--- src/prob/mld.jl | 264 ++++++++++++++--------------- src/prob/mrsp.jl | 56 +++--- src/prob/rop.jl | 60 +++---- src/prob/test.jl | 44 ++--- src/util/ac-mld-uc.jl | 34 ++-- src/util/iterative_restoration.jl | 116 ++++++------- src/util/restoration_redispatch.jl | 66 ++++---- test/mld_data.jl | 6 +- 22 files changed, 977 insertions(+), 977 deletions(-) diff --git a/Project.toml b/Project.toml index cb91317..5251afc 100644 --- a/Project.toml +++ b/Project.toml @@ -14,7 +14,7 @@ PowerModels = "c36e90e8-916a-50a6-bd94-075b64ef4655" InfrastructureModels = "~0.4" JuMP = "~0.19.1, ~0.20, ~0.21" MathOptInterface = "~0.8, ~0.9" -Memento = "~0.10, ~0.11, ~0.12" +Memento = "~0.10, ~0.11, ~0.12, ~0.13, ~1.0" PowerModels = "~0.15.2" julia = "^1" diff --git a/src/PowerModelsRestoration.jl b/src/PowerModelsRestoration.jl index a12f933..2f0986b 100644 --- a/src/PowerModelsRestoration.jl +++ b/src/PowerModelsRestoration.jl @@ -5,8 +5,8 @@ import InfrastructureModels import PowerModels import Memento -const _IMs = InfrastructureModels -const _PMs = PowerModels +const _IM = InfrastructureModels +const _PM = PowerModels include("core/variable.jl") include("core/data.jl") diff --git a/src/core/constraint.jl b/src/core/constraint.jl index ba91614..70c442d 100644 --- a/src/core/constraint.jl +++ b/src/core/constraint.jl @@ -1,82 +1,82 @@ "" -function constraint_restoration_cardinality_ub(pm::_PMs.AbstractPowerModel, n::Int, cumulative_repairs::Int) - z_storage = _PMs.var(pm, n, :z_storage) - z_gen = _PMs.var(pm, n, :z_gen) - z_branch = _PMs.var(pm, n, :z_branch) - z_bus = _PMs.var(pm, n, :z_bus) +function constraint_restoration_cardinality_ub(pm::_PM.AbstractPowerModel, n::Int, cumulative_repairs::Int) + z_storage = _PM.var(pm, n, :z_storage) + z_gen = _PM.var(pm, n, :z_gen) + z_branch = _PM.var(pm, n, :z_branch) + z_bus = _PM.var(pm, n, :z_bus) JuMP.@constraint(pm.model, - sum(z_branch[i] for (i,branch) in _PMs.ref(pm, n, :damaged_branch)) - + sum(z_gen[i] for (i,gen) in _PMs.ref(pm, n, :damaged_gen)) - + sum(z_storage[i] for (i,storage) in _PMs.ref(pm, n, :damaged_storage)) - + sum(z_bus[i] for (i,bus) in _PMs.ref(pm, n, :damaged_bus)) + sum(z_branch[i] for (i,branch) in _PM.ref(pm, n, :damaged_branch)) + + sum(z_gen[i] for (i,gen) in _PM.ref(pm, n, :damaged_gen)) + + sum(z_storage[i] for (i,storage) in _PM.ref(pm, n, :damaged_storage)) + + sum(z_bus[i] for (i,bus) in _PM.ref(pm, n, :damaged_bus)) <= cumulative_repairs ) end "" -function constraint_restoration_cardinality_lb(pm::_PMs.AbstractPowerModel, n::Int, cumulative_repairs::Int) - z_storage = _PMs.var(pm, n, :z_storage) - z_gen = _PMs.var(pm, n, :z_gen) - z_branch = _PMs.var(pm, n, :z_branch) - z_bus = _PMs.var(pm, n, :z_bus) +function constraint_restoration_cardinality_lb(pm::_PM.AbstractPowerModel, n::Int, cumulative_repairs::Int) + z_storage = _PM.var(pm, n, :z_storage) + z_gen = _PM.var(pm, n, :z_gen) + z_branch = _PM.var(pm, n, :z_branch) + z_bus = _PM.var(pm, n, :z_bus) JuMP.@constraint(pm.model, - sum(z_branch[i] for (i,branch) in _PMs.ref(pm, n, :damaged_branch)) - + sum(z_gen[i] for (i,gen) in _PMs.ref(pm, n, :damaged_gen)) - + sum(z_storage[i] for (i,storage) in _PMs.ref(pm, n, :damaged_storage)) - + sum(z_bus[i] for (i,bus) in _PMs.ref(pm, n, :damaged_bus)) + sum(z_branch[i] for (i,branch) in _PM.ref(pm, n, :damaged_branch)) + + sum(z_gen[i] for (i,gen) in _PM.ref(pm, n, :damaged_gen)) + + sum(z_storage[i] for (i,storage) in _PM.ref(pm, n, :damaged_storage)) + + sum(z_bus[i] for (i,bus) in _PM.ref(pm, n, :damaged_bus)) >= cumulative_repairs ) end function constraint_restore_all_items(pm, n) - z_demand = _PMs.var(pm, n, :z_demand) - z_shunt = _PMs.var(pm, n, :z_shunt) - z_storage = _PMs.var(pm, n, :z_storage) - z_gen = _PMs.var(pm, n, :z_gen) - z_branch = _PMs.var(pm, n, :z_branch) - z_bus = _PMs.var(pm, n, :z_bus) - - for (i,load) in _PMs.ref(pm, n, :load) + z_demand = _PM.var(pm, n, :z_demand) + z_shunt = _PM.var(pm, n, :z_shunt) + z_storage = _PM.var(pm, n, :z_storage) + z_gen = _PM.var(pm, n, :z_gen) + z_branch = _PM.var(pm, n, :z_branch) + z_bus = _PM.var(pm, n, :z_bus) + + for (i,load) in _PM.ref(pm, n, :load) JuMP.@constraint(pm.model, z_demand[i] == 1) end - for (i,shunt) in _PMs.ref(pm, n, :shunt) + for (i,shunt) in _PM.ref(pm, n, :shunt) JuMP.@constraint(pm.model, z_shunt[i] == 1) end - for (i,storage) in _PMs.ref(pm, n, :damaged_storage) + for (i,storage) in _PM.ref(pm, n, :damaged_storage) JuMP.@constraint(pm.model, z_storage[i] == 1) end - for (i,gen) in _PMs.ref(pm, n, :damaged_gen) + for (i,gen) in _PM.ref(pm, n, :damaged_gen) JuMP.@constraint(pm.model, z_gen[i] == 1) end - for (i,branch) in _PMs.ref(pm, n, :damaged_branch) + for (i,branch) in _PM.ref(pm, n, :damaged_branch) JuMP.@constraint(pm.model, z_branch[i] == 1) end - for (i,bus) in _PMs.ref(pm, n, :damaged_bus) + for (i,bus) in _PM.ref(pm, n, :damaged_bus) JuMP.@constraint(pm.model, z_bus[i] == 1) end end "" -function constraint_active_gen(pm::_PMs.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int) - if haskey(_PMs.ref(pm, nw_1, :damaged_gen), i) - z_gen_1 = _PMs.var(pm, nw_1, :z_gen, i) - z_gen_2 = _PMs.var(pm, nw_2, :z_gen, i) +function constraint_active_gen(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int) + if haskey(_PM.ref(pm, nw_1, :damaged_gen), i) + z_gen_1 = _PM.var(pm, nw_1, :z_gen, i) + z_gen_2 = _PM.var(pm, nw_2, :z_gen, i) JuMP.@constraint(pm.model, z_gen_2 >= z_gen_1) end end "" -function constraint_active_bus(pm::_PMs.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int) - if haskey(_PMs.ref(pm, nw_1, :damaged_gen), i) - z_bus_1 = _PMs.var(pm, nw_1, :z_bus, i) - z_bus_2 = _PMs.var(pm, nw_2, :z_bus, i) +function constraint_active_bus(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int) + if haskey(_PM.ref(pm, nw_1, :damaged_gen), i) + z_bus_1 = _PM.var(pm, nw_1, :z_bus, i) + z_bus_2 = _PM.var(pm, nw_2, :z_bus, i) JuMP.@constraint(pm.model, z_bus_2 >= z_bus_1) end @@ -84,10 +84,10 @@ end "" -function constraint_active_storage(pm::_PMs.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int) - if haskey(_PMs.ref(pm, nw_1, :damaged_storage), i) - z_storage_1 = _PMs.var(pm, nw_1, :z_storage, i) - z_storage_2 = _PMs.var(pm, nw_2, :z_storage, i) +function constraint_active_storage(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int) + if haskey(_PM.ref(pm, nw_1, :damaged_storage), i) + z_storage_1 = _PM.var(pm, nw_1, :z_storage, i) + z_storage_2 = _PM.var(pm, nw_2, :z_storage, i) JuMP.@constraint(pm.model, z_storage_2 >= z_storage_1) end @@ -95,10 +95,10 @@ end "" -function constraint_active_branch(pm::_PMs.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int) - if haskey(_PMs.ref(pm, nw_1, :damaged_branch), i) - z_branch_1 = _PMs.var(pm, nw_1, :z_branch, i) - z_branch_2 = _PMs.var(pm, nw_2, :z_branch, i) +function constraint_active_branch(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int) + if haskey(_PM.ref(pm, nw_1, :damaged_branch), i) + z_branch_1 = _PM.var(pm, nw_1, :z_branch, i) + z_branch_2 = _PM.var(pm, nw_2, :z_branch, i) JuMP.@constraint(pm.model, z_branch_2 >= z_branch_1) end @@ -106,70 +106,70 @@ end "Load delivered at each node must be greater than or equal the previous time period" -function constraint_increasing_load(pm::_PMs.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int) +function constraint_increasing_load(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int) - z_demand_1 = _PMs.var(pm, nw_1, :z_demand, i) - z_demand_2 = _PMs.var(pm, nw_2, :z_demand, i) + z_demand_1 = _PM.var(pm, nw_1, :z_demand, i) + z_demand_2 = _PM.var(pm, nw_2, :z_demand, i) JuMP.@constraint(pm.model, z_demand_2 >= z_demand_1) end "on/off constraint for storage connected to damaged buses" -function constraint_storage_bus_connection(pm::_PMs.AbstractPowerModel, n::Int, storage_id::Int, bus_id::Int) - z_storage = _PMs.var(pm, n, :z_storage, storage_id) - z_bus = _PMs.var(pm, n, :z_bus, bus_id) +function constraint_storage_bus_connection(pm::_PM.AbstractPowerModel, n::Int, storage_id::Int, bus_id::Int) + z_storage = _PM.var(pm, n, :z_storage, storage_id) + z_bus = _PM.var(pm, n, :z_bus, bus_id) JuMP.@constraint(pm.model, z_storage <= z_bus) end "on/off constraint for generators connected to damaged buses" -function constraint_gen_bus_connection(pm::_PMs.AbstractPowerModel, n::Int, gen_id::Int, bus_id::Int) - z_gen = _PMs.var(pm, n, :z_gen, gen_id) - z_bus = _PMs.var(pm, n, :z_bus, bus_id) +function constraint_gen_bus_connection(pm::_PM.AbstractPowerModel, n::Int, gen_id::Int, bus_id::Int) + z_gen = _PM.var(pm, n, :z_gen, gen_id) + z_bus = _PM.var(pm, n, :z_bus, bus_id) JuMP.@constraint(pm.model, z_gen <= z_bus) end "on/off constraint for loads connected to damaged buses" -function constraint_load_bus_connection(pm::_PMs.AbstractPowerModel, n::Int, load_id::Int, bus_id::Int) - z_demand = _PMs.var(pm, n, :z_demand, load_id) - z_bus = _PMs.var(pm, n, :z_bus, bus_id) +function constraint_load_bus_connection(pm::_PM.AbstractPowerModel, n::Int, load_id::Int, bus_id::Int) + z_demand = _PM.var(pm, n, :z_demand, load_id) + z_bus = _PM.var(pm, n, :z_bus, bus_id) JuMP.@constraint(pm.model, z_demand <= z_bus) end "on/off constraint for shunts connected to damaged buses" -function constraint_shunt_bus_connection(pm::_PMs.AbstractPowerModel, n::Int, shunt_id::Int, bus_id::Int) - z_shunt = _PMs.var(pm, n, :z_shunt, shunt_id) - z_bus = _PMs.var(pm, n, :z_bus, bus_id) +function constraint_shunt_bus_connection(pm::_PM.AbstractPowerModel, n::Int, shunt_id::Int, bus_id::Int) + z_shunt = _PM.var(pm, n, :z_shunt, shunt_id) + z_bus = _PM.var(pm, n, :z_bus, bus_id) JuMP.@constraint(pm.model, z_shunt <= z_bus) end "on/off constraint for branches connected to damaged buses" -function constraint_branch_bus_connection(pm::_PMs.AbstractPowerModel, n::Int, branch_id::Int, bus_id::Int) - z_branch = _PMs.var(pm, n, :z_branch, branch_id) - z_bus = _PMs.var(pm, n, :z_bus, bus_id) +function constraint_branch_bus_connection(pm::_PM.AbstractPowerModel, n::Int, branch_id::Int, bus_id::Int) + z_branch = _PM.var(pm, n, :z_branch, branch_id) + z_bus = _PM.var(pm, n, :z_bus, bus_id) JuMP.@constraint(pm.model, z_branch <= z_bus) end -function constraint_voltage_magnitude_on_off(pm::_PMs.AbstractPowerModel, n::Int, i::Int, vmin, vmax) - vm = _PMs.var(pm, n, :vm, i) - z_voltage = _PMs.var(pm, n, :z_voltage, i) +function constraint_voltage_magnitude_on_off(pm::_PM.AbstractPowerModel, n::Int, i::Int, vmin, vmax) + vm = _PM.var(pm, n, :vm, i) + z_voltage = _PM.var(pm, n, :z_voltage, i) JuMP.@constraint(pm.model, vm <= vmax*z_voltage) JuMP.@constraint(pm.model, vm >= vmin*z_voltage) end -function constraint_voltage_magnitude_sqr_on_off(pm::_PMs.AbstractPowerModel, n::Int, i::Int, vmin, vmax) - w = _PMs.var(pm, n, :w, i) - z_voltage = _PMs.var(pm, n, :z_voltage, i) +function constraint_voltage_magnitude_sqr_on_off(pm::_PM.AbstractPowerModel, n::Int, i::Int, vmin, vmax) + w = _PM.var(pm, n, :w, i) + z_voltage = _PM.var(pm, n, :z_voltage, i) JuMP.@constraint(pm.model, w <= vmax^2*z_voltage) JuMP.@constraint(pm.model, w >= vmin^2*z_voltage) diff --git a/src/core/constraint_template.jl b/src/core/constraint_template.jl index 68d4e0e..352bbf1 100644 --- a/src/core/constraint_template.jl +++ b/src/core/constraint_template.jl @@ -1,51 +1,51 @@ "" -function constraint_model_voltage_damage(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw) +function constraint_model_voltage_damage(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw) constraint_model_voltage_damage(pm, nw) end "Limit the maximum number of items restored in each time-step" -function constraint_restoration_cardinality_ub(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, cumulative_repairs=_PMs.ref(pm, nw, :repaired_total)) +function constraint_restoration_cardinality_ub(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, cumulative_repairs=_PM.ref(pm, nw, :repaired_total)) constraint_restoration_cardinality_ub(pm, nw, cumulative_repairs) end "Limit the minimum number of items restored in each time-step" -function constraint_restoration_cardinality_lb(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, cumulative_repairs=_PMs.ref(pm, nw, :repaired_total)) +function constraint_restoration_cardinality_lb(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, cumulative_repairs=_PM.ref(pm, nw, :repaired_total)) constraint_restoration_cardinality_lb(pm, nw, cumulative_repairs) end # # "Require all items restored in final time-step" -# function constraint_restore_all_items(pm::_PMs.AbstractPowerModel; nw::Int=maximum(_PMs.nw_ids(pm))) +# function constraint_restore_all_items(pm::_PM.AbstractPowerModel; nw::Int=maximum(_PM.nw_ids(pm))) # constraint_restore_all_items(pm, nw) # end "" -function constraint_generation_damage(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) - gen = _PMs.ref(pm, nw, :gen, i) +function constraint_generation_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + gen = _PM.ref(pm, nw, :gen, i) - gen_damaged = haskey(_PMs.ref(pm, nw, :damaged_gen), i) - bus_damaged = haskey(_PMs.ref(pm, nw, :damaged_bus), gen["gen_bus"]) + gen_damaged = haskey(_PM.ref(pm, nw, :damaged_gen), i) + bus_damaged = haskey(_PM.ref(pm, nw, :damaged_bus), gen["gen_bus"]) if gen_damaged - _PMs.constraint_generation_on_off(pm, nw, i, gen["pmin"], gen["pmax"], gen["qmin"], gen["qmax"]) + _PM.constraint_generation_on_off(pm, nw, i, gen["pmin"], gen["pmax"], gen["qmin"], gen["qmax"]) if bus_damaged constraint_gen_bus_connection(pm, nw, i, gen["gen_bus"]) end end if bus_damaged && !gen_damaged - Memento.error(_PMs._LOGGER, "non-damaged generator $(i) connected to damaged bus $(gen["gen_bus"])") + Memento.error(_PM._LOGGER, "non-damaged generator $(i) connected to damaged bus $(gen["gen_bus"])") end end "" -function constraint_load_damage(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) - if haskey(_PMs.ref(pm, nw, :load), i) - load = _PMs.ref(pm, nw, :load, i) +function constraint_load_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + if haskey(_PM.ref(pm, nw, :load), i) + load = _PM.ref(pm, nw, :load, i) - bus_damaged = haskey(_PMs.ref(pm, nw, :damaged_bus), load["load_bus"]) + bus_damaged = haskey(_PM.ref(pm, nw, :damaged_bus), load["load_bus"]) if bus_damaged constraint_load_bus_connection(pm, nw, i, load["load_bus"]) @@ -55,10 +55,10 @@ end "" -function constraint_shunt_damage(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) - if haskey(_PMs.ref(pm, nw, :shunt), i) - shunt = _PMs.ref(pm, nw, :shunt, i) - bus_damaged = haskey(_PMs.ref(pm, nw, :damaged_bus), shunt["shunt_bus"]) +function constraint_shunt_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + if haskey(_PM.ref(pm, nw, :shunt), i) + shunt = _PM.ref(pm, nw, :shunt, i) + bus_damaged = haskey(_PM.ref(pm, nw, :damaged_bus), shunt["shunt_bus"]) if bus_damaged constraint_shunt_bus_connection(pm, nw, i, shunt["shunt_bus"]) @@ -68,12 +68,12 @@ end "" -function constraint_branch_damage(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) - branch = _PMs.ref(pm, nw, :branch, i) +function constraint_branch_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + branch = _PM.ref(pm, nw, :branch, i) - branch_damaged = haskey(_PMs.ref(pm, nw, :damaged_branch), i) - bus_fr_damaged = haskey(_PMs.ref(pm, nw, :damaged_bus), branch["f_bus"]) - bus_to_damaged = haskey(_PMs.ref(pm, nw, :damaged_bus), branch["t_bus"]) + branch_damaged = haskey(_PM.ref(pm, nw, :damaged_branch), i) + bus_fr_damaged = haskey(_PM.ref(pm, nw, :damaged_bus), branch["f_bus"]) + bus_to_damaged = haskey(_PM.ref(pm, nw, :damaged_bus), branch["t_bus"]) if branch_damaged if bus_fr_damaged @@ -84,24 +84,24 @@ function constraint_branch_damage(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=p end end if bus_fr_damaged && !branch_damaged - Memento.error(_PMs._LOGGER, "non-damaged branch $(i) connected to damaged bus $(branch["f_bus"])") + Memento.error(_PM._LOGGER, "non-damaged branch $(i) connected to damaged bus $(branch["f_bus"])") end if bus_to_damaged && !branch_damaged - Memento.error(_PMs._LOGGER, "non-damaged branch $(i) connected to damaged bus $(branch["t_bus"])") + Memento.error(_PM._LOGGER, "non-damaged branch $(i) connected to damaged bus $(branch["t_bus"])") end end "" -function constraint_ohms_yt_from_damage(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) - branch = _PMs.ref(pm, nw, :branch, i) +function constraint_ohms_yt_from_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + branch = _PM.ref(pm, nw, :branch, i) f_bus = branch["f_bus"] t_bus = branch["t_bus"] f_idx = (i, f_bus, t_bus) t_idx = (i, t_bus, f_bus) - g, b = _PMs.calc_branch_y(branch) - tr, ti = _PMs.calc_branch_t(branch) + g, b = _PM.calc_branch_y(branch) + tr, ti = _PM.calc_branch_t(branch) g_fr = branch["g_fr"] b_fr = branch["b_fr"] tm = branch["tap"] @@ -109,29 +109,29 @@ function constraint_ohms_yt_from_damage(pm::_PMs.AbstractPowerModel, i::Int; nw: # TODO make indexing of :wi,:wr standardized ## Because :wi, :wr are indexed by bus_id or bus_pairs depending on if the value is on_off or # standard, there are indexing issues. Temporary solution: always call *_on_off variant - if haskey(_PMs.ref(pm, nw, :damaged_branch), i) - vad_min = _PMs.ref(pm, nw, :off_angmin) - vad_max = _PMs.ref(pm, nw, :off_angmax) - _PMs.constraint_ohms_yt_from_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm, vad_min, vad_max) + if haskey(_PM.ref(pm, nw, :damaged_branch), i) + vad_min = _PM.ref(pm, nw, :off_angmin) + vad_max = _PM.ref(pm, nw, :off_angmax) + _PM.constraint_ohms_yt_from_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm, vad_min, vad_max) else - #vad_min = _PMs.ref(pm, nw, :off_angmin) - #vad_max = _PMs.ref(pm, nw, :off_angmax) - #_PMs.constraint_ohms_yt_from_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm, vad_min, vad_max) - _PMs.constraint_ohms_yt_from(pm, nw, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm) + #vad_min = _PM.ref(pm, nw, :off_angmin) + #vad_max = _PM.ref(pm, nw, :off_angmax) + #_PM.constraint_ohms_yt_from_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm, vad_min, vad_max) + _PM.constraint_ohms_yt_from(pm, nw, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm) end end "" -function constraint_ohms_yt_to_damage(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) - branch = _PMs.ref(pm, nw, :branch, i) +function constraint_ohms_yt_to_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + branch = _PM.ref(pm, nw, :branch, i) f_bus = branch["f_bus"] t_bus = branch["t_bus"] f_idx = (i, f_bus, t_bus) t_idx = (i, t_bus, f_bus) - g, b = _PMs.calc_branch_y(branch) - tr, ti = _PMs.calc_branch_t(branch) + g, b = _PM.calc_branch_y(branch) + tr, ti = _PM.calc_branch_t(branch) g_to = branch["g_to"] b_to = branch["b_to"] tm = branch["tap"] @@ -139,39 +139,39 @@ function constraint_ohms_yt_to_damage(pm::_PMs.AbstractPowerModel, i::Int; nw::I # TODO make indexing of :wi,:wr standardized ## Because :wi, :wr are indexed by bus_id or bus_pairs depending on if the value is on_off or # standard, there are indexing issues. Temporary solution: always call *_on_off variant - if haskey(_PMs.ref(pm, nw, :damaged_branch), i) - vad_min = _PMs.ref(pm, nw, :off_angmin) - vad_max = _PMs.ref(pm, nw, :off_angmax) + if haskey(_PM.ref(pm, nw, :damaged_branch), i) + vad_min = _PM.ref(pm, nw, :off_angmin) + vad_max = _PM.ref(pm, nw, :off_angmax) - _PMs.constraint_ohms_yt_to_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm, vad_min, vad_max) + _PM.constraint_ohms_yt_to_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm, vad_min, vad_max) else - #vad_min = _PMs.ref(pm, nw, :off_angmin) - #vad_max = _PMs.ref(pm, nw, :off_angmax) - #_PMs.constraint_ohms_yt_to_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm, vad_min, vad_max) - _PMs.constraint_ohms_yt_to(pm, nw, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm) + #vad_min = _PM.ref(pm, nw, :off_angmin) + #vad_max = _PM.ref(pm, nw, :off_angmax) + #_PM.constraint_ohms_yt_to_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm, vad_min, vad_max) + _PM.constraint_ohms_yt_to(pm, nw, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm) end end "" -function constraint_voltage_angle_difference_damage(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) - branch = _PMs.ref(pm, nw, :branch, i) +function constraint_voltage_angle_difference_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + branch = _PM.ref(pm, nw, :branch, i) f_idx = (i, branch["f_bus"], branch["t_bus"]) # TODO make indexing of :wi,:wr standardized # Because :wi, :wr are indexed by bus_id or bus_pairs depending on if the value is on_off or # standard, there are indexing issues. Temporary solution: always call *_on_off variant - if haskey(_PMs.ref(pm, nw, :damaged_branch), i) + if haskey(_PM.ref(pm, nw, :damaged_branch), i) - vad_min = _PMs.ref(pm, nw, :off_angmin) - vad_max = _PMs.ref(pm, nw, :off_angmax) + vad_min = _PM.ref(pm, nw, :off_angmin) + vad_max = _PM.ref(pm, nw, :off_angmax) - _PMs.constraint_voltage_angle_difference_on_off(pm, nw, f_idx, branch["angmin"], branch["angmax"], vad_min, vad_max) + _PM.constraint_voltage_angle_difference_on_off(pm, nw, f_idx, branch["angmin"], branch["angmax"], vad_min, vad_max) else - vad_min = _PMs.ref(pm, nw, :off_angmin) - vad_max = _PMs.ref(pm, nw, :off_angmax) + vad_min = _PM.ref(pm, nw, :off_angmin) + vad_max = _PM.ref(pm, nw, :off_angmax) - _PMs.constraint_voltage_angle_difference_on_off(pm, nw, f_idx, branch["angmin"], branch["angmax"], vad_min, vad_max) + _PM.constraint_voltage_angle_difference_on_off(pm, nw, f_idx, branch["angmin"], branch["angmax"], vad_min, vad_max) end end @@ -183,126 +183,126 @@ end Adds the (upper and lower) thermal limit constraints for the desired branch to the PowerModel. """ -function constraint_thermal_limit_from_damage(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) - branch = _PMs.ref(pm, nw, :branch, i) +function constraint_thermal_limit_from_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + branch = _PM.ref(pm, nw, :branch, i) f_bus = branch["f_bus"] t_bus = branch["t_bus"] f_idx = (i, f_bus, t_bus) - if haskey(_PMs.ref(pm, nw, :damaged_branch), i) - _PMs.constraint_thermal_limit_from_on_off(pm, nw, i, f_idx, branch["rate_a"]) + if haskey(_PM.ref(pm, nw, :damaged_branch), i) + _PM.constraint_thermal_limit_from_on_off(pm, nw, i, f_idx, branch["rate_a"]) else - if !haskey(_PMs.con(pm, nw), :sm_fr) - _PMs.con(pm, nw)[:sm_fr] = Dict{Int,Any}() # note this can be a constraint or a variable bound + if !haskey(_PM.con(pm, nw), :sm_fr) + _PM.con(pm, nw)[:sm_fr] = Dict{Int,Any}() # note this can be a constraint or a variable bound end - _PMs.constraint_thermal_limit_from(pm, nw, f_idx, branch["rate_a"]) + _PM.constraint_thermal_limit_from(pm, nw, f_idx, branch["rate_a"]) end end "" -function constraint_thermal_limit_to_damage(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) - branch = _PMs.ref(pm, nw, :branch, i) +function constraint_thermal_limit_to_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + branch = _PM.ref(pm, nw, :branch, i) f_bus = branch["f_bus"] t_bus = branch["t_bus"] t_idx = (i, t_bus, f_bus) - if haskey(_PMs.ref(pm, nw, :damaged_branch), i) - _PMs.constraint_thermal_limit_to_on_off(pm, nw, i, t_idx, branch["rate_a"]) + if haskey(_PM.ref(pm, nw, :damaged_branch), i) + _PM.constraint_thermal_limit_to_on_off(pm, nw, i, t_idx, branch["rate_a"]) else - if !haskey(_PMs.con(pm, nw), :sm_to) - _PMs.con(pm, nw)[:sm_to] = Dict{Int,Any}() # note this can be a constraint or a variable bound + if !haskey(_PM.con(pm, nw), :sm_to) + _PM.con(pm, nw)[:sm_to] = Dict{Int,Any}() # note this can be a constraint or a variable bound end - _PMs.constraint_thermal_limit_to(pm, nw, t_idx, branch["rate_a"]) + _PM.constraint_thermal_limit_to(pm, nw, t_idx, branch["rate_a"]) end end "" -function constraint_storage_damage(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) - storage = _PMs.ref(pm, nw, :storage, i) +function constraint_storage_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + storage = _PM.ref(pm, nw, :storage, i) - storage_damaged = haskey(_PMs.ref(pm, nw, :damaged_storage), i) - bus_damaged = haskey(_PMs.ref(pm, nw, :damaged_bus), storage["storage_bus"]) + storage_damaged = haskey(_PM.ref(pm, nw, :damaged_storage), i) + bus_damaged = haskey(_PM.ref(pm, nw, :damaged_bus), storage["storage_bus"]) if storage_damaged charge_ub = storage["charge_rating"] discharge_ub = storage["discharge_rating"] - inj_lb, inj_ub = _PMs.ref_calc_storage_injection_bounds(_PMs.ref(pm, nw, :storage), _PMs.ref(pm, nw, :bus)) + inj_lb, inj_ub = _PM.ref_calc_storage_injection_bounds(_PM.ref(pm, nw, :storage), _PM.ref(pm, nw, :bus)) pmin = inj_lb[i] pmax = inj_ub[i] - qmin = max(inj_lb[i], _PMs.ref(pm, nw, :storage, i, "qmin")) - qmax = min(inj_ub[i], _PMs.ref(pm, nw, :storage, i, "qmax")) + qmin = max(inj_lb[i], _PM.ref(pm, nw, :storage, i, "qmin")) + qmax = min(inj_ub[i], _PM.ref(pm, nw, :storage, i, "qmax")) - _PMs.constraint_storage_on_off(pm, nw, i, pmin, pmax, qmin, qmax, charge_ub, discharge_ub) + _PM.constraint_storage_on_off(pm, nw, i, pmin, pmax, qmin, qmax, charge_ub, discharge_ub) if bus_damaged constraint_storage_bus_connection(pm, nw, i, storage["storage_bus"]) end end if bus_damaged && !storage_damaged - Memento.error(_PMs._LOGGER, "non-damaged storage $(i) connected to damaged bus $(storage["storage_bus"])") + Memento.error(_PM._LOGGER, "non-damaged storage $(i) connected to damaged bus $(storage["storage_bus"])") end end "" -function constraint_bus_voltage_violation_damage(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) - bus = _PMs.ref(pm, nw, :bus, i) +function constraint_bus_voltage_violation_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + bus = _PM.ref(pm, nw, :bus, i) constraint_bus_voltage_violation_damage(pm, nw, i, bus["vmin"], bus["vmax"]) end "" -function constraint_bus_voltage_violation(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) - bus = _PMs.ref(pm, nw, :bus, i) +function constraint_bus_voltage_violation(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + bus = _PM.ref(pm, nw, :bus, i) constraint_bus_voltage_violation(pm, nw, i, bus["vmin"], bus["vmax"]) end "" -function constraint_power_balance_shed(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) - if !haskey(_PMs.con(pm, nw), :kcl_p) - _PMs.con(pm, nw)[:kcl_p] = Dict{Int,JuMP.ConstraintRef}() +function constraint_power_balance_shed(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + if !haskey(_PM.con(pm, nw), :kcl_p) + _PM.con(pm, nw)[:kcl_p] = Dict{Int,JuMP.ConstraintRef}() end - if !haskey(_PMs.con(pm, nw), :kcl_q) - _PMs.con(pm, nw)[:kcl_q] = Dict{Int,JuMP.ConstraintRef}() + if !haskey(_PM.con(pm, nw), :kcl_q) + _PM.con(pm, nw)[:kcl_q] = Dict{Int,JuMP.ConstraintRef}() end - bus = _PMs.ref(pm, nw, :bus, i) - bus_arcs = _PMs.ref(pm, nw, :bus_arcs, i) - bus_arcs_dc = _PMs.ref(pm, nw, :bus_arcs_dc, i) - bus_arcs_sw = _PMs.ref(pm, nw, :bus_arcs_sw, i) - bus_gens = _PMs.ref(pm, nw, :bus_gens, i) - bus_loads = _PMs.ref(pm, nw, :bus_loads, i) - bus_shunts = _PMs.ref(pm, nw, :bus_shunts, i) - bus_storage = _PMs.ref(pm, nw, :bus_storage, i) + bus = _PM.ref(pm, nw, :bus, i) + bus_arcs = _PM.ref(pm, nw, :bus_arcs, i) + bus_arcs_dc = _PM.ref(pm, nw, :bus_arcs_dc, i) + bus_arcs_sw = _PM.ref(pm, nw, :bus_arcs_sw, i) + bus_gens = _PM.ref(pm, nw, :bus_gens, i) + bus_loads = _PM.ref(pm, nw, :bus_loads, i) + bus_shunts = _PM.ref(pm, nw, :bus_shunts, i) + bus_storage = _PM.ref(pm, nw, :bus_storage, i) - bus_pd = Dict(k => _PMs.ref(pm, nw, :load, k, "pd") for k in bus_loads) - bus_qd = Dict(k => _PMs.ref(pm, nw, :load, k, "qd") for k in bus_loads) + bus_pd = Dict(k => _PM.ref(pm, nw, :load, k, "pd") for k in bus_loads) + bus_qd = Dict(k => _PM.ref(pm, nw, :load, k, "qd") for k in bus_loads) - bus_gs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "gs") for k in bus_shunts) - bus_bs = Dict(k => _PMs.ref(pm, nw, :shunt, k, "bs") for k in bus_shunts) + bus_gs = Dict(k => _PM.ref(pm, nw, :shunt, k, "gs") for k in bus_shunts) + bus_bs = Dict(k => _PM.ref(pm, nw, :shunt, k, "bs") for k in bus_shunts) constraint_power_balance_shed(pm, nw, i, bus_arcs, bus_arcs_dc, bus_arcs_sw, bus_gens, bus_storage, bus_pd, bus_qd, bus_gs, bus_bs) end -constraint_bus_voltage_on_off(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, kwargs...) = constraint_bus_voltage_on_off(pm, nw; kwargs...) +constraint_bus_voltage_on_off(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, kwargs...) = constraint_bus_voltage_on_off(pm, nw; kwargs...) -function constraint_voltage_magnitude_on_off(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) - bus = _PMs.ref(pm, nw, :bus, i) +function constraint_voltage_magnitude_on_off(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + bus = _PM.ref(pm, nw, :bus, i) constraint_voltage_magnitude_on_off(pm, nw, i, bus["vmin"], bus["vmax"]) end -function constraint_voltage_magnitude_sqr_on_off(pm::_PMs.AbstractPowerModel, i::Int; nw::Int=pm.cnw) - bus = _PMs.ref(pm, nw, :bus, i) +function constraint_voltage_magnitude_sqr_on_off(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw) + bus = _PM.ref(pm, nw, :bus, i) constraint_voltage_magnitude_sqr_on_off(pm, nw, i, bus["vmin"], bus["vmax"]) end diff --git a/src/core/data.jl b/src/core/data.jl index e527a0a..6f8e40d 100644 --- a/src/core/data.jl +++ b/src/core/data.jl @@ -1,5 +1,5 @@ function count_repairable_items(network::Dict{String, Any}) - if _IMs.ismultinetwork(network) + if _IM.ismultinetwork(network) repairable_count = Dict{String,Any}("nw" => Dict{String,Any}()) repairable_set = get_repairable_items(network) repairable_count["nw"] = Dict{String,Any}(nw => sum(length(comp_ids) for (comp_type,comp_ids) in repariable_network) for (nw, repariable_network) in repairable_set["nw"] ) @@ -28,10 +28,10 @@ end "" function _get_repairable_items(network::Dict{String,Any}) repairs = Dict{String, Vector{String}}() - for (comp_name, status_key) in _PMs.pm_component_status + for (comp_name, status_key) in _PM.pm_component_status repairs[comp_name] = [] for (comp_id, comp) in get(network, comp_name, Dict()) - if haskey(comp, status_key) && comp[status_key] != _PMs.pm_component_status_inactive[comp_name] && haskey(comp, "damaged") && comp["damaged"] == 1 + if haskey(comp, status_key) && comp[status_key] != _PM.pm_component_status_inactive[comp_name] && haskey(comp, "damaged") && comp["damaged"] == 1 push!(repairs[comp_name], comp_id) end end @@ -58,7 +58,7 @@ end "Count the number of items with a key \"damaged\" == 1 in a network" function count_damaged_items(network::Dict{String, Any}) - if _IMs.ismultinetwork(network) + if _IM.ismultinetwork(network) damaged_count = Dict{String,Any}("nw" => Dict{String,Any}()) damaged_set = get_damaged_items(network) damaged_count["nw"] = Dict{String,Any}(nw => sum(length(comp_ids) for (comp_type,comp_ids) in damage_network) for (nw, damage_network) in damaged_set["nw"] ) @@ -72,7 +72,7 @@ end "" function get_damaged_items(data::Dict{String,Any}) - if _IMs.ismultinetwork(data) + if _IM.ismultinetwork(data) comp_list = Dict{String,Any}("nw" => Dict{String,Any}()) for (i, nw_data) in data["nw"] comp_list["nw"][i] = _get_damaged_items(nw_data) @@ -87,7 +87,7 @@ end "" function _get_damaged_items(network::Dict{String,Any}) comp_list = Dict{String, Array{String,1}}() - for (comp_type, comp_status) in _PMs.pm_component_status + for (comp_type, comp_status) in _PM.pm_component_status comp_list[comp_type] = [] for (comp_id, comp) in network[comp_type] if haskey(comp, "damaged") && comp["damaged"] == 1 @@ -101,7 +101,7 @@ end "" function get_isolated_load(data::Dict{String,Any}) - if _IMs.ismultinetwork(data) + if _IM.ismultinetwork(data) load_list = Dict{String,Any}("nw" => Dict{String,Any}()) for (i, nw_data) in data["nw"] load_list["nw"][i] = _get_isolated_load(nw_data) @@ -118,11 +118,11 @@ function _get_isolated_load(network::Dict{String,Any}) load_list = Dict{String, Array{String,1}}() load_list["load"] = [] - bus_status = _PMs.pm_component_status["bus"] - bus_inactive = _PMs.pm_component_status_inactive["bus"] + bus_status = _PM.pm_component_status["bus"] + bus_inactive = _PM.pm_component_status_inactive["bus"] - load_status = _PMs.pm_component_status["load"] - load_inactive = _PMs.pm_component_status_inactive["load"] + load_status = _PM.pm_component_status["load"] + load_inactive = _PM.pm_component_status_inactive["load"] for (load_id, load) in network["load"] if haskey(network["bus"]["$(load["load_bus"])"], bus_status) && network["bus"]["$(load["load_bus"])"][bus_status] == bus_inactive @@ -135,7 +135,7 @@ end "" function set_component_inactive!(data::Dict{String,Any}, comp_list::Dict{String, Array{String,1}}) - if _IMs.ismultinetwork(data) + if _IM.ismultinetwork(data) items = Dict{String,Any}("nw" => Dict{String,Any}()) for (i, nw_data) in data["nw"] _set_component_inactive!(nw_data, comp_list) @@ -151,7 +151,7 @@ end function _set_component_inactive!(network::Dict{String,Any}, comp_list::Dict{String, Array{String,1}}) for (comp_type, comp_ids) in comp_list for comp_id in comp_ids - network[comp_type][comp_id][_PMs.pm_component_status[comp_type]] = _PMs.pm_component_status_inactive[comp_type] + network[comp_type][comp_id][_PM.pm_component_status[comp_type]] = _PM.pm_component_status_inactive[comp_type] end end end @@ -159,7 +159,7 @@ end "Clear damage indicator and replace with status=0" function clear_damage_indicator!(data::Dict{String, Any}) - if _IMs.ismultinetwork(data) + if _IM.ismultinetwork(data) for (i, nw_data) in data["nw"] _clear_damage_indicator!(nw_data) end @@ -170,7 +170,7 @@ end function _clear_damage_indicator!(network::Dict{String,Any}) - for (comp_name, status_key) in _PMs.pm_component_status + for (comp_name, status_key) in _PM.pm_component_status for (i, comp) in get(network, comp_name, Dict()) if haskey(comp, "damaged") comp["damaged"] = 0 @@ -212,9 +212,9 @@ end "updates status in the data model with values from a sparse solution dict" function update_status!(data::Dict{String, Any}, solution::Dict{String, Any}) - @assert _IMs.ismultinetwork(data) == _IMs.ismultinetwork(solution) + @assert _IM.ismultinetwork(data) == _IM.ismultinetwork(solution) - if _IMs.ismultinetwork(solution) + if _IM.ismultinetwork(solution) for (i, nw_sol) in solution["nw"] nw_data = data["nw"][i] _update_status!(nw_data, nw_sol) @@ -225,7 +225,7 @@ function update_status!(data::Dict{String, Any}, solution::Dict{String, Any}) end function _update_status!(network::Dict{String,Any}, solution::Dict{String, Any}) - for (comp_name, status_key) in _PMs.pm_component_status + for (comp_name, status_key) in _PM.pm_component_status if haskey(solution, comp_name) && haskey(network, comp_name) nw_comps = network[comp_name] for (i, sol_comp) in solution[comp_name] @@ -291,7 +291,7 @@ end # Required because PowerModels assumes integral status values "Replace non-integer status codes for devices, maps bus status to bus_type" function clean_status!(data::Dict{String,Any}) - if _IMs.ismultinetwork(data) + if _IM.ismultinetwork(data) for (i, nw_data) in data["nw"] _clean_status!(nw_data) end @@ -309,7 +309,7 @@ function _clean_status!(network::Dict{String,Any}) elseif status == 1 bt = get(bus, "bus_type", 5) if bt == 4 - Memento.warn(_PMs._LOGGER, "bus $(i) given status 1 but the bus_type is 4") + Memento.warn(_PM._LOGGER, "bus $(i) given status 1 but the bus_type is 4") else bus["bus_type"] = bt end @@ -319,14 +319,14 @@ function _clean_status!(network::Dict{String,Any}) end end - for (comp_name, status_key) in _PMs.pm_component_status + for (comp_name, status_key) in _PM.pm_component_status for (i, comp) in get(network, comp_name, Dict()) if haskey(comp, status_key) - if isapprox(comp[status_key], _PMs.pm_component_status_inactive[comp_name], atol=1e-4) + if isapprox(comp[status_key], _PM.pm_component_status_inactive[comp_name], atol=1e-4) # i.e. status= 1.05e-9, then set status=0 # instead of rounding, which would cause a load with status "0.2" (80% of load shed) # to be set to status 0 instead. - comp[status_key] = _PMs.pm_component_status_inactive[comp_name] + comp[status_key] = _PM.pm_component_status_inactive[comp_name] elseif isapprox(comp[status_key], 1, atol=1e-4) comp[status_key] = 1 end @@ -338,15 +338,15 @@ end "Transforms a single network into a multinetwork with several deepcopies of the original network. Indexed from 0." function replicate_restoration_network(sn_data::Dict{String,<:Any}; count::Int=1, global_keys::Set{String}=Set{String}()) - return replicate_restoration_network(sn_data, count, union(global_keys, _PMs._pm_global_keys)) + return replicate_restoration_network(sn_data, count, union(global_keys, _PM._pm_global_keys)) end "Transforms a single network into a multinetwork with several deepcopies of the original network. Indexed from 0." function replicate_restoration_network(sn_data::Dict{String,<:Any}, count::Int, global_keys::Set{String}) @assert count > 0 - if _IMs.ismultinetwork(sn_data) - Memento.error(_PMs._LOGGER, "replicate_restoration_network can only be used on single networks") + if _IM.ismultinetwork(sn_data) + Memento.error(_PM._LOGGER, "replicate_restoration_network can only be used on single networks") end clean_status!(sn_data) @@ -373,7 +373,7 @@ function replicate_restoration_network(sn_data::Dict{String,<:Any}, count::Int, total_repairs = count_repairable_items(sn_data) if count > total_repairs - Memento.warn(_PMs._LOGGER, "More restoration steps than repairable components. Reducing restoration steps to $(total_repairs).") + Memento.warn(_PM._LOGGER, "More restoration steps than repairable components. Reducing restoration steps to $(total_repairs).") count = trunc(Int,total_repairs) end @@ -405,7 +405,7 @@ end "" function propagate_damage_status!(data::Dict{String,<:Any}) - if _IMs.ismultinetwork(data) + if _IM.ismultinetwork(data) for (i,nw_data) in data["nw"] _propagate_damage_status!(nw_data) end @@ -419,8 +419,8 @@ end function _propagate_damage_status!(data::Dict{String,<:Any}) buses = Dict(bus["bus_i"] => bus for (i,bus) in data["bus"]) - incident_gen = _PMs.bus_gen_lookup(data["gen"], data["bus"]) - incident_storage = _PMs.bus_storage_lookup(data["storage"], data["bus"]) + incident_gen = _PM.bus_gen_lookup(data["gen"], data["bus"]) + incident_storage = _PM.bus_storage_lookup(data["storage"], data["bus"]) incident_branch = Dict(bus["bus_i"] => [] for (i,bus) in data["bus"]) for (i,branch) in data["branch"] @@ -432,19 +432,19 @@ function _propagate_damage_status!(data::Dict{String,<:Any}) if haskey(bus, "damaged") && bus["damaged"] == 1 for gen in incident_gen[i] if !(haskey(gen, "damaged") && gen["damaged"] == 1) - Memento.info(_PMs._LOGGER, "damaging generator $(gen["index"]) due to damaged bus $(i)") + Memento.info(_PM._LOGGER, "damaging generator $(gen["index"]) due to damaged bus $(i)") gen["damaged"] = 1 end end for storage in incident_storage[i] if !(haskey(storage, "damaged") && storage["damaged"] == 1) - Memento.info(_PMs._LOGGER, "damaging storage $(storage["index"]) due to damaged bus $(i)") + Memento.info(_PM._LOGGER, "damaging storage $(storage["index"]) due to damaged bus $(i)") storage["damaged"] = 1 end end for branch in incident_branch[i] if !(haskey(branch, "damaged") && branch["damaged"] == 1) - Memento.info(_PMs._LOGGER, "damaging branch $(branch["index"]) due to damaged bus $(i)") + Memento.info(_PM._LOGGER, "damaging branch $(branch["index"]) due to damaged bus $(i)") branch["damaged"] = 1 end end @@ -465,12 +465,12 @@ end prints a summary of a restoration solution """ function summary_restoration(io::IO, data::Dict{String,<:Any}) - if !_IMs.ismultinetwork(data) - Memento.error(_PMs._LOGGER, "summary_restoration requires multinetwork data") + if !_IM.ismultinetwork(data) + Memento.error(_PM._LOGGER, "summary_restoration requires multinetwork data") end networks = sort(collect(keys(data["nw"])), by=x -> parse(Int, x)) - component_names = sort(collect(keys(_PMs.pm_component_status))) + component_names = sort(collect(keys(_PM.pm_component_status))) network = data["nw"][networks[1]] header = ["step", "pd", "qd"] @@ -496,7 +496,7 @@ function summary_restoration(io::IO, data::Dict{String,<:Any}) push!(summary_data, trunc(load_qd, sigdigits=5)) for comp_name in component_names - comp_status_name = _PMs.pm_component_status[comp_name] + comp_status_name = _PM.pm_component_status[comp_name] if haskey(network, comp_name) components = network[comp_name] comp_ids = sort(collect(keys(components)), by=x -> parse(Int, x)) @@ -520,7 +520,7 @@ end function add_load_weights!(data::Dict{String,<:Any}) if !haskey(data, "source_type") || data["source_type"] != "pti" - Memento.warn(_PMs._LOGGER, "add_load_weights! currently only supports networks from pti files") + Memento.warn(_PM._LOGGER, "add_load_weights! currently only supports networks from pti files") return end @@ -528,13 +528,13 @@ function add_load_weights!(data::Dict{String,<:Any}) @assert(haskey(load, "source_id") && length(load["source_id"]) == 3) load_ckt = lowercase(load["source_id"][3]) if startswith(load_ckt, 'l') - Memento.info(_PMs._LOGGER, "setting load $(i) to low priority") + Memento.info(_PM._LOGGER, "setting load $(i) to low priority") load["weight"] = 1.0 elseif startswith(load_ckt, 'm') - Memento.info(_PMs._LOGGER, "setting load $(i) to medium priority") + Memento.info(_PM._LOGGER, "setting load $(i) to medium priority") load["weight"] = 10.0 elseif startswith(load_ckt, 'h') - Memento.info(_PMs._LOGGER, "setting load $(i) to high priority") + Memento.info(_PM._LOGGER, "setting load $(i) to high priority") load["weight"] = 100.0 end end diff --git a/src/core/objective.jl b/src/core/objective.jl index f677d9c..e8ba782 100644 --- a/src/core/objective.jl +++ b/src/core/objective.jl @@ -1,36 +1,36 @@ -function objective_max_load_delivered(pm::_PMs.AbstractPowerModel) - nws = _PMs.nw_ids(pm) +function objective_max_load_delivered(pm::_PM.AbstractPowerModel) + nws = _PM.nw_ids(pm) - @assert all(!_PMs.ismulticonductor(pm, n) for n in nws) + @assert all(!_PM.ismulticonductor(pm, n) for n in nws) - z_demand = Dict(n => _PMs.var(pm, n, :z_demand) for n in nws) - time_elapsed = Dict(n => get(_PMs.ref(pm, n), :time_elapsed, 1.0) for n in nws) + z_demand = Dict(n => _PM.var(pm, n, :z_demand) for n in nws) + time_elapsed = Dict(n => get(_PM.ref(pm, n), :time_elapsed, 1.0) for n in nws) load_weight = Dict(n => - Dict(i => get(load, "weight", 1.0) for (i,load) in _PMs.ref(pm, n, :load)) + Dict(i => get(load, "weight", 1.0) for (i,load) in _PM.ref(pm, n, :load)) for n in nws) return JuMP.@objective(pm.model, Max, sum( time_elapsed[n]*( - sum(load_weight[n][i]*abs(load["pd"])*z_demand[n][i] for (i,load) in _PMs.ref(pm, n, :load)) + sum(load_weight[n][i]*abs(load["pd"])*z_demand[n][i] for (i,load) in _PM.ref(pm, n, :load)) ) for n in nws) ) end -function objective_max_load_delivered(pm::_PMs.AbstractACPModel) - nws = _PMs.nw_ids(pm) +function objective_max_load_delivered(pm::_PM.AbstractACPModel) + nws = _PM.nw_ids(pm) - @assert all(!_PMs.ismulticonductor(pm, n) for n in nws) + @assert all(!_PM.ismulticonductor(pm, n) for n in nws) - vm_vio = Dict(n => _PMs.var(pm, :vm_vio, nw=n) for n in nws) - z_demand = Dict(n => _PMs.var(pm, n, :z_demand) for n in nws) - time_elapsed = Dict(n => get(_PMs.ref(pm, n), :time_elapsed, 1.0) for n in nws) + vm_vio = Dict(n => _PM.var(pm, :vm_vio, nw=n) for n in nws) + z_demand = Dict(n => _PM.var(pm, n, :z_demand) for n in nws) + time_elapsed = Dict(n => get(_PM.ref(pm, n), :time_elapsed, 1.0) for n in nws) load_weight = Dict(n => - Dict(i => get(load, "weight", 1.0) for (i,load) in _PMs.ref(pm, n, :load)) + Dict(i => get(load, "weight", 1.0) for (i,load) in _PM.ref(pm, n, :load)) for n in nws) M = Dict() @@ -45,24 +45,24 @@ function objective_max_load_delivered(pm::_PMs.AbstractACPModel) return JuMP.@objective(pm.model, Max, sum( time_elapsed[n]*( - sum(-M[n]*vm_vio[n][i] for (i,bus) in _PMs.ref(pm, n, :bus)) + - sum(load_weight[n][i]*abs(load["pd"])*z_demand[n][i] for (i,load) in _PMs.ref(pm, n, :load)) + sum(-M[n]*vm_vio[n][i] for (i,bus) in _PM.ref(pm, n, :bus)) + + sum(load_weight[n][i]*abs(load["pd"])*z_demand[n][i] for (i,load) in _PM.ref(pm, n, :load)) ) for n in nws) ) end -function objective_max_load_delivered(pm::_PMs.AbstractWRModel) - nws = _PMs.nw_ids(pm) +function objective_max_load_delivered(pm::_PM.AbstractWRModel) + nws = _PM.nw_ids(pm) - @assert all(!_PMs.ismulticonductor(pm, n) for n in nws) + @assert all(!_PM.ismulticonductor(pm, n) for n in nws) - w_vio = Dict(n => _PMs.var(pm, :w_vio, nw=n) for n in nws) - z_demand = Dict(n => _PMs.var(pm, n, :z_demand) for n in nws) - time_elapsed = Dict(n => get(_PMs.ref(pm, n), :time_elapsed, 1.0) for n in nws) + w_vio = Dict(n => _PM.var(pm, :w_vio, nw=n) for n in nws) + z_demand = Dict(n => _PM.var(pm, n, :z_demand) for n in nws) + time_elapsed = Dict(n => get(_PM.ref(pm, n), :time_elapsed, 1.0) for n in nws) load_weight = Dict(n => - Dict(i => get(load, "weight", 1.0) for (i,load) in _PMs.ref(pm, n, :load)) + Dict(i => get(load, "weight", 1.0) for (i,load) in _PM.ref(pm, n, :load)) for n in nws) M = Dict() @@ -77,8 +77,8 @@ function objective_max_load_delivered(pm::_PMs.AbstractWRModel) return JuMP.@objective(pm.model, Max, sum( time_elapsed[n]*( - sum(-M[n]*w_vio[n][i] for (i,bus) in _PMs.ref(pm, n, :bus)) + - sum(load_weight[n][i]*abs(load["pd"])*z_demand[n][i] for (i,load) in _PMs.ref(pm, n, :load)) + sum(-M[n]*w_vio[n][i] for (i,bus) in _PM.ref(pm, n, :bus)) + + sum(load_weight[n][i]*abs(load["pd"])*z_demand[n][i] for (i,load) in _PM.ref(pm, n, :load)) ) for n in nws) ) @@ -86,33 +86,33 @@ end -function objective_max_loadability(pm::_PMs.AbstractPowerModel) - nws = _PMs.nw_ids(pm) +function objective_max_loadability(pm::_PM.AbstractPowerModel) + nws = _PM.nw_ids(pm) - @assert all(!_PMs.ismulticonductor(pm, n) for n in nws) + @assert all(!_PM.ismulticonductor(pm, n) for n in nws) - z_demand = Dict(n => _PMs.var(pm, n, :z_demand) for n in nws) - z_shunt = Dict(n => _PMs.var(pm, n, :z_shunt) for n in nws) - z_gen = Dict(n => _PMs.var(pm, n, :z_gen) for n in nws) - z_voltage = Dict(n => _PMs.var(pm, n, :z_voltage) for n in nws) - time_elapsed = Dict(n => get(_PMs.ref(pm, n), :time_elapsed, 1) for n in nws) + z_demand = Dict(n => _PM.var(pm, n, :z_demand) for n in nws) + z_shunt = Dict(n => _PM.var(pm, n, :z_shunt) for n in nws) + z_gen = Dict(n => _PM.var(pm, n, :z_gen) for n in nws) + z_voltage = Dict(n => _PM.var(pm, n, :z_voltage) for n in nws) + time_elapsed = Dict(n => get(_PM.ref(pm, n), :time_elapsed, 1) for n in nws) load_weight = Dict(n => - Dict(i => get(load, "weight", 1.0) for (i,load) in _PMs.ref(pm, n, :load)) + Dict(i => get(load, "weight", 1.0) for (i,load) in _PM.ref(pm, n, :load)) for n in nws) #println(load_weight) - M = Dict(n => 10*maximum([load_weight[n][i]*abs(load["pd"]) for (i,load) in _PMs.ref(pm, n, :load)]) for n in nws) + M = Dict(n => 10*maximum([load_weight[n][i]*abs(load["pd"]) for (i,load) in _PM.ref(pm, n, :load)]) for n in nws) return JuMP.@objective(pm.model, Max, sum( ( time_elapsed[n]*( - sum(M[n]*10*z_voltage[n][i] for (i,bus) in _PMs.ref(pm, n, :bus)) + - sum(M[n]*z_gen[n][i] for (i,gen) in _PMs.ref(pm, n, :gen)) + - sum(M[n]*z_shunt[n][i] for (i,shunt) in _PMs.ref(pm, n, :shunt)) + - sum(load_weight[n][i]*abs(load["pd"])*z_demand[n][i] for (i,load) in _PMs.ref(pm, n, :load)) + sum(M[n]*10*z_voltage[n][i] for (i,bus) in _PM.ref(pm, n, :bus)) + + sum(M[n]*z_gen[n][i] for (i,gen) in _PM.ref(pm, n, :gen)) + + sum(M[n]*z_shunt[n][i] for (i,shunt) in _PM.ref(pm, n, :shunt)) + + sum(load_weight[n][i]*abs(load["pd"])*z_demand[n][i] for (i,load) in _PM.ref(pm, n, :load)) ) ) for n in nws) @@ -128,35 +128,35 @@ function objective_max_loadability(pm::_PMs.AbstractPowerModel) end # can we just add storage to the regular max_loadability objective? # -function objective_max_loadability_strg(pm::_PMs.AbstractPowerModel) - nws = _PMs.nw_ids(pm) +function objective_max_loadability_strg(pm::_PM.AbstractPowerModel) + nws = _PM.nw_ids(pm) - @assert all(!_PMs.ismulticonductor(pm, n) for n in nws) + @assert all(!_PM.ismulticonductor(pm, n) for n in nws) - z_demand = Dict(n => _PMs.var(pm, n, :z_demand) for n in nws) - z_shunt = Dict(n => _PMs.var(pm, n, :z_shunt) for n in nws) - z_gen = Dict(n => _PMs.var(pm, n, :z_gen) for n in nws) - z_storage = Dict(n => _PMs.var(pm, n, :z_storage) for n in nws) - z_voltage = Dict(n => _PMs.var(pm, n, :z_voltage) for n in nws) - time_elapsed = Dict(n => get(_PMs.ref(pm, n), :time_elapsed, 1) for n in nws) + z_demand = Dict(n => _PM.var(pm, n, :z_demand) for n in nws) + z_shunt = Dict(n => _PM.var(pm, n, :z_shunt) for n in nws) + z_gen = Dict(n => _PM.var(pm, n, :z_gen) for n in nws) + z_storage = Dict(n => _PM.var(pm, n, :z_storage) for n in nws) + z_voltage = Dict(n => _PM.var(pm, n, :z_voltage) for n in nws) + time_elapsed = Dict(n => get(_PM.ref(pm, n), :time_elapsed, 1) for n in nws) load_weight = Dict(n => - Dict(i => get(load, "weight", 1.0) for (i,load) in _PMs.ref(pm, n, :load)) + Dict(i => get(load, "weight", 1.0) for (i,load) in _PM.ref(pm, n, :load)) for n in nws) #println(load_weight) - M = Dict(n => 10*maximum([load_weight[n][i]*abs(load["pd"]) for (i,load) in _PMs.ref(pm, n, :load)]) for n in nws) + M = Dict(n => 10*maximum([load_weight[n][i]*abs(load["pd"]) for (i,load) in _PM.ref(pm, n, :load)]) for n in nws) return JuMP.@objective(pm.model, Max, sum( ( time_elapsed[n]*( - sum(M[n]*10*z_voltage[n][i] for (i,bus) in _PMs.ref(pm, n, :bus)) + - sum(M[n]*z_gen[n][i] for (i,gen) in _PMs.ref(pm, n, :gen)) + - sum(M[n]*z_storage[n][i] for (i,storage) in _PMs.ref(pm, n, :storage)) + - sum(M[n]*z_shunt[n][i] for (i,shunt) in _PMs.ref(pm, n, :shunt)) + - sum(load_weight[n][i]*abs(load["pd"])*z_demand[n][i] for (i,load) in _PMs.ref(pm, n, :load)) + sum(M[n]*10*z_voltage[n][i] for (i,bus) in _PM.ref(pm, n, :bus)) + + sum(M[n]*z_gen[n][i] for (i,gen) in _PM.ref(pm, n, :gen)) + + sum(M[n]*z_storage[n][i] for (i,storage) in _PM.ref(pm, n, :storage)) + + sum(M[n]*z_shunt[n][i] for (i,shunt) in _PM.ref(pm, n, :shunt)) + + sum(load_weight[n][i]*abs(load["pd"])*z_demand[n][i] for (i,load) in _PM.ref(pm, n, :load)) ) ) for n in nws) diff --git a/src/core/ref.jl b/src/core/ref.jl index 6b89822..f9fe8c1 100644 --- a/src/core/ref.jl +++ b/src/core/ref.jl @@ -1,17 +1,17 @@ # tools for working with a PowerModels ref dict structures "" -function ref_add_damaged_items!(pm::_PMs.AbstractPowerModel) - ref_add_damaged_gens!(pm) - ref_add_damaged_branches!(pm) - ref_add_damaged_storage!(pm) - ref_add_damaged_buses!(pm) +function ref_add_damaged_items!(ref::Dict{Symbol,<:Any}, data::Dict{String,<:Any}) + ref_add_damaged_gens!(ref, data) + ref_add_damaged_branches!(ref, data) + ref_add_damaged_storage!(ref, data) + ref_add_damaged_buses!(ref, data) end "" -function ref_add_damaged_gens!(pm::_PMs.AbstractPowerModel) - for (nw, nw_ref) in pm.ref[:nw] +function ref_add_damaged_gens!(ref::Dict{Symbol,<:Any}, data::Dict{String,<:Any}) + for (nw, nw_ref) in ref[:nw] damaged_gen = Dict{Int,Any}() for (i,gen) in nw_ref[:gen] if haskey(gen, "damaged") && gen["damaged"] == 1 @@ -20,12 +20,12 @@ function ref_add_damaged_gens!(pm::_PMs.AbstractPowerModel) end nw_ref[:damaged_gen] = damaged_gen end - _PMs.ref(pm,:damaged_gen) + #_PM.ref(pm,:damaged_gen) end "" -function ref_add_damaged_buses!(pm::_PMs.AbstractPowerModel) - for (nw, nw_ref) in pm.ref[:nw] +function ref_add_damaged_buses!(ref::Dict{Symbol,<:Any}, data::Dict{String,<:Any}) + for (nw, nw_ref) in ref[:nw] damaged_bus = Dict{Int,Any}() for (i,bus) in nw_ref[:bus] if haskey(bus, "damaged") && bus["damaged"] == 1 @@ -38,8 +38,8 @@ end "" -function ref_add_damaged_branches!(pm::_PMs.AbstractPowerModel) - for (nw, nw_ref) in pm.ref[:nw] +function ref_add_damaged_branches!(ref::Dict{Symbol,<:Any}, data::Dict{String,<:Any}) + for (nw, nw_ref) in ref[:nw] damaged_branch = Dict{Int,Any}() for (i,branch) in nw_ref[:branch] if haskey(branch, "damaged") && branch["damaged"] == 1 @@ -52,8 +52,8 @@ end "" -function ref_add_damaged_storage!(pm::_PMs.AbstractPowerModel) - for (nw, nw_ref) in pm.ref[:nw] +function ref_add_damaged_storage!(ref::Dict{Symbol,<:Any}, data::Dict{String,<:Any}) + for (nw, nw_ref) in ref[:nw] damaged_storage = Dict{Int,Any}() for (i,storage) in nw_ref[:storage] if haskey(storage, "damaged") && storage["damaged"] == 1 diff --git a/src/core/variable.jl b/src/core/variable.jl index b38e996..e932ce1 100644 --- a/src/core/variable.jl +++ b/src/core/variable.jl @@ -2,250 +2,250 @@ function JuMP.value(x::Real) return x end "variable: `v[i]` for `i` in `bus`es" -function variable_voltage_magnitude_on_off(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, report::Bool=true) - vm = _PMs.var(pm, nw)[:vm] = JuMP.@variable(pm.model, - [i in _PMs.ids(pm, nw, :bus)], base_name="$(nw)_vm", +function variable_voltage_magnitude_on_off(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, report::Bool=true) + vm = _PM.var(pm, nw)[:vm] = JuMP.@variable(pm.model, + [i in _PM.ids(pm, nw, :bus)], base_name="$(nw)_vm", lower_bound = 0.0, - upper_bound = _PMs.ref(pm, nw, :bus, i, "vmax"), - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :bus, i), "vm_start", 1.0) + upper_bound = _PM.ref(pm, nw, :bus, i, "vmax"), + start = _PM.comp_start_value(_PM.ref(pm, nw, :bus, i), "vm_start", 1.0) ) - report && _PMs.sol_component_value(pm, nw, :bus, :vm, _PMs.ids(pm, nw, :bus), vm) + report && _IM.sol_component_value(pm, nw, :bus, :vm, _PM.ids(pm, nw, :bus), vm) end "variable: `v[i]` for `i` in `bus`es" -function variable_voltage_magnitude_violation(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, report::Bool=true) - vm_vio = _PMs.var(pm, nw)[:vm_vio] = JuMP.@variable(pm.model, - [i in _PMs.ids(pm, nw, :bus)], base_name="$(nw)_vm_vio", +function variable_voltage_magnitude_violation(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, report::Bool=true) + vm_vio = _PM.var(pm, nw)[:vm_vio] = JuMP.@variable(pm.model, + [i in _PM.ids(pm, nw, :bus)], base_name="$(nw)_vm_vio", lower_bound = 0.0, - upper_bound = _PMs.ref(pm, nw, :bus, i, "vmin"), - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :bus, i), "vm_vio_start") + upper_bound = _PM.ref(pm, nw, :bus, i, "vmin"), + start = _PM.comp_start_value(_PM.ref(pm, nw, :bus, i), "vm_vio_start") ) - report && _PMs.sol_component_value(pm, nw, :bus, :vm_vio, _PMs.ids(pm, nw, :bus), vm_vio) + report && _IM.sol_component_value(pm, nw, :bus, :vm_vio, _PM.ids(pm, nw, :bus), vm_vio) end "variable: `0 <= damage_gen[l] <= 1` for `l` in `gen`es" -function variable_generation_damage_indicator(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, relax::Bool=false, report::Bool=true) +function variable_generation_damage_indicator(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, relax::Bool=false, report::Bool=true) if relax == false z_gen_vars = JuMP.@variable(pm.model, - [l in _PMs.ids(pm, nw, :damaged_gen)], + [l in _PM.ids(pm, nw, :damaged_gen)], base_name="$(nw)_active_gen", binary = true, - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :gen, l), "gen_damage_start") + start = _PM.comp_start_value(_PM.ref(pm, nw, :gen, l), "gen_damage_start") ) else z_gen_vars = JuMP.@variable(pm.model, - [l in _PMs.ids(pm, nw, :damaged_gen)], + [l in _PM.ids(pm, nw, :damaged_gen)], base_name="$(nw)_active_gen", lower_bound = 0, upper_bound = 1, - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :gen, l), "gen_damage_start") + start = _PM.comp_start_value(_PM.ref(pm, nw, :gen, l), "gen_damage_start") ) end - z_gen = Dict(i => haskey(gen, "damaged") && gen["damaged"] == 1 && gen["gen_status"]==1 ? z_gen_vars[i] : gen["gen_status"] for (i,gen) in _PMs.ref(pm, nw, :gen)) - _PMs.var(pm, nw)[:z_gen] = z_gen + z_gen = Dict(i => haskey(gen, "damaged") && gen["damaged"] == 1 && gen["gen_status"]==1 ? z_gen_vars[i] : gen["gen_status"] for (i,gen) in _PM.ref(pm, nw, :gen)) + _PM.var(pm, nw)[:z_gen] = z_gen - report && _PMs.sol_component_value(pm, nw, :gen, :gen_status, _PMs.ids(pm, nw, :gen), z_gen) + report && _IM.sol_component_value(pm, nw, :gen, :gen_status, _PM.ids(pm, nw, :gen), z_gen) end "generates variables for both `active` and `reactive` generation" -function variable_generation_damage(pm::_PMs.AbstractPowerModel; kwargs...) +function variable_generation_damage(pm::_PM.AbstractPowerModel; kwargs...) variable_active_generation_damage(pm; kwargs...) variable_reactive_generation_damage(pm; kwargs...) end "variable: `pg[j]` for `j` in `gen`" -function variable_active_generation_damage(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, bounded::Bool=true, report::Bool=true) +function variable_active_generation_damage(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, bounded::Bool=true, report::Bool=true) if bounded - pg = _PMs.var(pm, nw)[:pg] = JuMP.@variable(pm.model, - [i in _PMs.ids(pm, nw, :gen)], base_name="$(nw)_pg_dmg", - lower_bound = _PMs.ref(pm, nw, :gen, i, "pmin"), - upper_bound = _PMs.ref(pm, nw, :gen, i, "pmax"), - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :gen, i), "pg_start") + pg = _PM.var(pm, nw)[:pg] = JuMP.@variable(pm.model, + [i in _PM.ids(pm, nw, :gen)], base_name="$(nw)_pg_dmg", + lower_bound = _PM.ref(pm, nw, :gen, i, "pmin"), + upper_bound = _PM.ref(pm, nw, :gen, i, "pmax"), + start = _PM.comp_start_value(_PM.ref(pm, nw, :gen, i), "pg_start") ) - for i in _PMs.ids(pm, nw, :gen) - if haskey(_PMs.ref(pm, nw, :gen, i), "damaged") && _PMs.ref(pm, nw, :gen,i)["damaged"] == 1 - JuMP.set_upper_bound(_PMs.var(pm, nw, :pg, i), max(0, _PMs.ref(pm, nw, :gen, i, "pmax"))) - JuMP.set_lower_bound(_PMs.var(pm, nw, :pg, i), min(0, _PMs.ref(pm, nw, :gen, i, "pmin"))) + for i in _PM.ids(pm, nw, :gen) + if haskey(_PM.ref(pm, nw, :gen, i), "damaged") && _PM.ref(pm, nw, :gen,i)["damaged"] == 1 + JuMP.set_upper_bound(_PM.var(pm, nw, :pg, i), max(0, _PM.ref(pm, nw, :gen, i, "pmax"))) + JuMP.set_lower_bound(_PM.var(pm, nw, :pg, i), min(0, _PM.ref(pm, nw, :gen, i, "pmin"))) end end else - pg = _PMs.var(pm, nw)[:pg] = JuMP.@variable(pm.model, - [i in _PMs.ids(pm, nw, :gen)], base_name="$(nw)_pg_dmg", - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :gen, i), "pg_start") + pg = _PM.var(pm, nw)[:pg] = JuMP.@variable(pm.model, + [i in _PM.ids(pm, nw, :gen)], base_name="$(nw)_pg_dmg", + start = _PM.comp_start_value(_PM.ref(pm, nw, :gen, i), "pg_start") ) end - report && _PMs.sol_component_value(pm, nw, :gen, :pg, _PMs.ids(pm, nw, :gen), pg) + report && _IM.sol_component_value(pm, nw, :gen, :pg, _PM.ids(pm, nw, :gen), pg) end "variable: `qq[j]` for `j` in `gen`" -function variable_reactive_generation_damage(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, bounded::Bool=true, report::Bool=true) +function variable_reactive_generation_damage(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, bounded::Bool=true, report::Bool=true) if bounded - qg = _PMs.var(pm, nw)[:qg] = JuMP.@variable(pm.model, - [i in _PMs.ids(pm, nw, :gen)], base_name="$(nw)_qg_dmg", - lower_bound = _PMs.ref(pm, nw, :gen, i, "qmin"), - upper_bound = _PMs.ref(pm, nw, :gen, i, "qmax"), - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :gen, i), "qg_start") + qg = _PM.var(pm, nw)[:qg] = JuMP.@variable(pm.model, + [i in _PM.ids(pm, nw, :gen)], base_name="$(nw)_qg_dmg", + lower_bound = _PM.ref(pm, nw, :gen, i, "qmin"), + upper_bound = _PM.ref(pm, nw, :gen, i, "qmax"), + start = _PM.comp_start_value(_PM.ref(pm, nw, :gen, i), "qg_start") ) else - qg = _PMs.var(pm, nw)[:qg] = JuMP.@variable(pm.model, - [i in _PMs.ids(pm, nw, :gen)], base_name="$(nw)_qg_dmg", - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :gen, i), "qg_start") + qg = _PM.var(pm, nw)[:qg] = JuMP.@variable(pm.model, + [i in _PM.ids(pm, nw, :gen)], base_name="$(nw)_qg_dmg", + start = _PM.comp_start_value(_PM.ref(pm, nw, :gen, i), "qg_start") ) end - for i in _PMs.ids(pm, nw, :gen) - if haskey(_PMs.ref(pm, nw, :gen, i), "damaged") && _PMs.ref(pm, nw, :gen,i)["damaged"] == 1 - JuMP.set_upper_bound(_PMs.var(pm, nw, :qg, i), max(0, _PMs.ref(pm, nw, :gen, i, "qmax"))) - JuMP.set_lower_bound(_PMs.var(pm, nw, :qg, i), min(0, _PMs.ref(pm, nw, :gen, i, "qmin"))) + for i in _PM.ids(pm, nw, :gen) + if haskey(_PM.ref(pm, nw, :gen, i), "damaged") && _PM.ref(pm, nw, :gen,i)["damaged"] == 1 + JuMP.set_upper_bound(_PM.var(pm, nw, :qg, i), max(0, _PM.ref(pm, nw, :gen, i, "qmax"))) + JuMP.set_lower_bound(_PM.var(pm, nw, :qg, i), min(0, _PM.ref(pm, nw, :gen, i, "qmin"))) end end - report && _PMs.sol_component_value(pm, nw, :gen, :qg, _PMs.ids(pm, nw, :gen), qg) + report && _IM.sol_component_value(pm, nw, :gen, :qg, _PM.ids(pm, nw, :gen), qg) end "variable: `0 <= damage_branch[l] <= 1` for `l` in `branch`es" -function variable_branch_damage_indicator(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, relax::Bool=false, report::Bool=true) +function variable_branch_damage_indicator(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, relax::Bool=false, report::Bool=true) if relax == false z_branch_vars = JuMP.@variable(pm.model, - [l in _PMs.ids(pm, nw, :damaged_branch)], + [l in _PM.ids(pm, nw, :damaged_branch)], base_name="$(nw)_active_branch", binary = true, - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :branch, l), "branch_damage_start") + start = _PM.comp_start_value(_PM.ref(pm, nw, :branch, l), "branch_damage_start") ) else z_branch_vars = JuMP.@variable(pm.model, - [l in _PMs.ids(pm, nw, :damaged_branch)], + [l in _PM.ids(pm, nw, :damaged_branch)], base_name="$(nw)_active_branch", lower_bound = 0, upper_bound = 1, - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :branch, l), "branch_damage_start") + start = _PM.comp_start_value(_PM.ref(pm, nw, :branch, l), "branch_damage_start") ) end - z_branch = Dict(i => haskey(branch, "damaged") && branch["damaged"] == 1 ? z_branch_vars[i] : branch["br_status"] for (i,branch) in _PMs.ref(pm, nw, :branch)) - _PMs.var(pm, nw)[:z_branch] = z_branch + z_branch = Dict(i => haskey(branch, "damaged") && branch["damaged"] == 1 ? z_branch_vars[i] : branch["br_status"] for (i,branch) in _PM.ref(pm, nw, :branch)) + _PM.var(pm, nw)[:z_branch] = z_branch - report && _PMs.sol_component_value(pm, nw, :branch, :br_status, _PMs.ids(pm, nw, :branch), z_branch) + report && _IM.sol_component_value(pm, nw, :branch, :br_status, _PM.ids(pm, nw, :branch), z_branch) end "variable: `0 <= damage_storage[l] <= 1` for `l` in `storage`es" -function variable_storage_damage_indicator(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, relax::Bool=false, report::Bool=true) +function variable_storage_damage_indicator(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, relax::Bool=false, report::Bool=true) if relax == false z_storage_vars = JuMP.@variable(pm.model, - [l in _PMs.ids(pm, nw, :damaged_storage)], + [l in _PM.ids(pm, nw, :damaged_storage)], base_name="$(nw)_active_storage", binary = true, - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :storage, l), "storage_damage_start") + start = _PM.comp_start_value(_PM.ref(pm, nw, :storage, l), "storage_damage_start") ) else z_storage_vars = JuMP.@variable(pm.model, - [l in _PMs.ids(pm, nw, :damaged_storage)], + [l in _PM.ids(pm, nw, :damaged_storage)], base_name="$(nw)_active_storage", lower_bound = 0, upper_bound = 1, - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :storage, l), "storage_damage_start") + start = _PM.comp_start_value(_PM.ref(pm, nw, :storage, l), "storage_damage_start") ) end - z_storage = Dict(i => haskey(storage, "damaged") && storage["damaged"] == 1 ? z_storage_vars[i] : storage["status"] for (i,storage) in _PMs.ref(pm, nw, :storage)) - _PMs.var(pm, nw)[:z_storage] = z_storage + z_storage = Dict(i => haskey(storage, "damaged") && storage["damaged"] == 1 ? z_storage_vars[i] : storage["status"] for (i,storage) in _PM.ref(pm, nw, :storage)) + _PM.var(pm, nw)[:z_storage] = z_storage - report && _PMs.sol_component_value(pm, nw, :storage, :status, _PMs.ids(pm, nw, :storage), z_storage) + report && _IM.sol_component_value(pm, nw, :storage, :status, _PM.ids(pm, nw, :storage), z_storage) end "" -function variable_storage_mi_damage(pm::_PMs.AbstractPowerModel; kwargs...) +function variable_storage_mi_damage(pm::_PM.AbstractPowerModel; kwargs...) variable_active_storage_damage(pm; kwargs...) variable_reactive_storage_damage(pm; kwargs...) variable_current_storage_damage(pm; kwargs...) - _PMs.variable_storage_energy(pm; kwargs...) - _PMs.variable_storage_charge(pm; kwargs...) - _PMs.variable_storage_discharge(pm; kwargs...) - _PMs.variable_storage_complementary_indicator(pm; kwargs...) + _PM.variable_storage_energy(pm; kwargs...) + _PM.variable_storage_charge(pm; kwargs...) + _PM.variable_storage_discharge(pm; kwargs...) + _PM.variable_storage_complementary_indicator(pm; kwargs...) end "do nothing by default but some formulations require this" -function variable_current_storage_damage(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, report::Bool=true) +function variable_current_storage_damage(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, report::Bool=true) end "" -function variable_active_storage_damage(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, report::Bool=true) - inj_lb, inj_ub = _PMs.ref_calc_storage_injection_bounds(_PMs.ref(pm, nw, :storage), _PMs.ref(pm, nw, :bus)) +function variable_active_storage_damage(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, report::Bool=true) + inj_lb, inj_ub = _PM.ref_calc_storage_injection_bounds(_PM.ref(pm, nw, :storage), _PM.ref(pm, nw, :bus)) - ps = _PMs.var(pm, nw)[:ps] = JuMP.@variable(pm.model, - [i in _PMs.ids(pm, nw, :storage)], base_name="$(nw)_ps_dmg", + ps = _PM.var(pm, nw)[:ps] = JuMP.@variable(pm.model, + [i in _PM.ids(pm, nw, :storage)], base_name="$(nw)_ps_dmg", lower_bound = inj_lb[i], upper_bound = inj_ub[i], - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :storage, i), "ps_start") + start = _PM.comp_start_value(_PM.ref(pm, nw, :storage, i), "ps_start") ) - for i in _PMs.ids(pm, nw, :storage) - if haskey(_PMs.ref(pm, nw, :storage, i), "damaged") && _PMs.ref(pm, nw, :storage, i)["damaged"] == 1 - JuMP.set_upper_bound(_PMs.var(pm, nw, :ps, i), max(0, inj_ub[i])) - JuMP.set_lower_bound(_PMs.var(pm, nw, :ps, i), min(0, inj_lb[i])) + for i in _PM.ids(pm, nw, :storage) + if haskey(_PM.ref(pm, nw, :storage, i), "damaged") && _PM.ref(pm, nw, :storage, i)["damaged"] == 1 + JuMP.set_upper_bound(_PM.var(pm, nw, :ps, i), max(0, inj_ub[i])) + JuMP.set_lower_bound(_PM.var(pm, nw, :ps, i), min(0, inj_lb[i])) end end - report && _PMs.sol_component_value(pm, nw, :storage, :ps, _PMs.ids(pm, nw, :storage), ps) + report && _IM.sol_component_value(pm, nw, :storage, :ps, _PM.ids(pm, nw, :storage), ps) end "" -function variable_reactive_storage_damage(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, report::Bool=true) - inj_lb, inj_ub = _PMs.ref_calc_storage_injection_bounds(_PMs.ref(pm, nw, :storage), _PMs.ref(pm, nw, :bus)) - - qs = _PMs.var(pm, nw)[:qs] = JuMP.@variable(pm.model, - [i in _PMs.ids(pm, nw, :storage)], base_name="$(nw)_qs_dmg", - lower_bound = max(inj_lb[i], _PMs.ref(pm, nw, :storage, i, "qmin")), - upper_bound = min(inj_ub[i], _PMs.ref(pm, nw, :storage, i, "qmax")), - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :storage, i), "qs_start") +function variable_reactive_storage_damage(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, report::Bool=true) + inj_lb, inj_ub = _PM.ref_calc_storage_injection_bounds(_PM.ref(pm, nw, :storage), _PM.ref(pm, nw, :bus)) + + qs = _PM.var(pm, nw)[:qs] = JuMP.@variable(pm.model, + [i in _PM.ids(pm, nw, :storage)], base_name="$(nw)_qs_dmg", + lower_bound = max(inj_lb[i], _PM.ref(pm, nw, :storage, i, "qmin")), + upper_bound = min(inj_ub[i], _PM.ref(pm, nw, :storage, i, "qmax")), + start = _PM.comp_start_value(_PM.ref(pm, nw, :storage, i), "qs_start") ) - for i in _PMs.ids(pm, nw, :storage) - if haskey(_PMs.ref(pm, nw, :storage, i), "damaged") && _PMs.ref(pm, nw, :storage, i)["damaged"] == 1 - JuMP.set_upper_bound(_PMs.var(pm, nw, :ps, i), max(0, min(inj_ub[i], _PMs.ref(pm, nw, :storage, i, "qmax")))) - JuMP.set_lower_bound(_PMs.var(pm, nw, :ps, i), min(0, max(inj_lb[i], _PMs.ref(pm, nw, :storage, i, "qmin")))) + for i in _PM.ids(pm, nw, :storage) + if haskey(_PM.ref(pm, nw, :storage, i), "damaged") && _PM.ref(pm, nw, :storage, i)["damaged"] == 1 + JuMP.set_upper_bound(_PM.var(pm, nw, :ps, i), max(0, min(inj_ub[i], _PM.ref(pm, nw, :storage, i, "qmax")))) + JuMP.set_lower_bound(_PM.var(pm, nw, :ps, i), min(0, max(inj_lb[i], _PM.ref(pm, nw, :storage, i, "qmin")))) end end - report && _PMs.sol_component_value(pm, nw, :storage, :qs, _PMs.ids(pm, nw, :storage), qs) + report && _IM.sol_component_value(pm, nw, :storage, :qs, _PM.ids(pm, nw, :storage), qs) end "variable: `0 <= damage_bus[l] <= 1` for `l` in `bus`es" -function variable_bus_damage_indicator(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, relax::Bool=false, report::Bool=true) +function variable_bus_damage_indicator(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, relax::Bool=false, report::Bool=true) if relax == false z_bus_vars = JuMP.@variable(pm.model, - [l in _PMs.ids(pm, nw, :damaged_bus)], + [l in _PM.ids(pm, nw, :damaged_bus)], base_name="$(nw)_active_bus", binary = true, - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :bus, l), "bus_damage_start") + start = _PM.comp_start_value(_PM.ref(pm, nw, :bus, l), "bus_damage_start") ) else z_bus_vars = JuMP.@variable(pm.model, - [l in _PMs.ids(pm, nw, :damaged_bus)], + [l in _PM.ids(pm, nw, :damaged_bus)], base_name="$(nw)_active_bus", lower_bound = 0, upper_bound = 1, - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :bus, l), "bus_damage_start") + start = _PM.comp_start_value(_PM.ref(pm, nw, :bus, l), "bus_damage_start") ) end - z_bus = Dict(i => haskey(bus, "damaged") && bus["damaged"] == 1 ? z_bus_vars[i] : bus["bus_type"]==4 ? 0 : 1 for (i,bus) in _PMs.ref(pm, nw, :bus)) - _PMs.var(pm, nw)[:z_bus] = z_bus + z_bus = Dict(i => haskey(bus, "damaged") && bus["damaged"] == 1 ? z_bus_vars[i] : bus["bus_type"]==4 ? 0 : 1 for (i,bus) in _PM.ref(pm, nw, :bus)) + _PM.var(pm, nw)[:z_bus] = z_bus - report && _PMs.sol_component_value(pm, nw, :bus, :status, _PMs.ids(pm, nw, :bus), z_bus) + report && _IM.sol_component_value(pm, nw, :bus, :status, _PM.ids(pm, nw, :bus), z_bus) end @@ -253,71 +253,71 @@ end # "" -# function variable_demand_factor(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, relax = false) +# function variable_demand_factor(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, relax = false) # if relax == true -# _PMs.var(pm, nw)[:z_demand] = JuMP.@variable(pm.model, -# [i in _PMs.ids(pm, nw, :load)], base_name="$(nw)_z_demand", +# _PM.var(pm, nw)[:z_demand] = JuMP.@variable(pm.model, +# [i in _PM.ids(pm, nw, :load)], base_name="$(nw)_z_demand", # upper_bound = 1, # lower_bound = 0, -# start = _PMs.comp_start_value(_PMs.ref(pm, nw, :load, i), "z_demand_on_start", 1.0) +# start = _PM.comp_start_value(_PM.ref(pm, nw, :load, i), "z_demand_on_start", 1.0) # ) # else -# _PMs.var(pm, nw)[:z_demand] = JuMP.@variable(pm.model, -# [i in _PMs.ids(pm, nw, :load)], base_name="$(nw)_z_demand", +# _PM.var(pm, nw)[:z_demand] = JuMP.@variable(pm.model, +# [i in _PM.ids(pm, nw, :load)], base_name="$(nw)_z_demand", # binary = true, -# start = _PMs.comp_start_value(_PMs.ref(pm, nw, :load, i), "z_demand_on_start", 1.0) +# start = _PM.comp_start_value(_PM.ref(pm, nw, :load, i), "z_demand_on_start", 1.0) # ) # end # end # "" -# function variable_shunt_factor(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, relax = false) +# function variable_shunt_factor(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, relax = false) # if relax == true -# _PMs.var(pm, nw)[:z_shunt] = JuMP.@variable(pm.model, -# [i in _PMs.ids(pm, nw, :shunt)], base_name="$(nw)_z_shunt", +# _PM.var(pm, nw)[:z_shunt] = JuMP.@variable(pm.model, +# [i in _PM.ids(pm, nw, :shunt)], base_name="$(nw)_z_shunt", # upper_bound = 1, # lower_bound = 0, -# start = _PMs.comp_start_value(_PMs.ref(pm, nw, :shunt, i), "z_shunt_on_start", 1.0) +# start = _PM.comp_start_value(_PM.ref(pm, nw, :shunt, i), "z_shunt_on_start", 1.0) # ) # else -# _PMs.var(pm, nw)[:z_shunt] = JuMP.@variable(pm.model, -# [i in _PMs.ids(pm, nw, :shunt)], base_name="$(nw)_z_shunt", +# _PM.var(pm, nw)[:z_shunt] = JuMP.@variable(pm.model, +# [i in _PM.ids(pm, nw, :shunt)], base_name="$(nw)_z_shunt", # binary = true, -# start = _PMs.comp_start_value(_PMs.ref(pm, nw, :shunt, i), "z_shunt_on_start", 1.0) +# start = _PM.comp_start_value(_PM.ref(pm, nw, :shunt, i), "z_shunt_on_start", 1.0) # ) # end # end -function variable_bus_voltage_indicator(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, relax::Bool=false, report::Bool=true) +function variable_bus_voltage_indicator(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, relax::Bool=false, report::Bool=true) if !relax - z_voltage = _PMs.var(pm, nw)[:z_voltage] = JuMP.@variable(pm.model, - [i in _PMs.ids(pm, nw, :bus)], base_name="$(nw)_z_voltage", + z_voltage = _PM.var(pm, nw)[:z_voltage] = JuMP.@variable(pm.model, + [i in _PM.ids(pm, nw, :bus)], base_name="$(nw)_z_voltage", binary = true, - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :bus, i), "z_voltage_start") + start = _PM.comp_start_value(_PM.ref(pm, nw, :bus, i), "z_voltage_start") ) else - z_voltage = _PMs.var(pm, nw)[:z_voltage] = JuMP.@variable(pm.model, - [i in _PMs.ids(pm, nw, :bus)], base_name="$(nw)_z_voltage", + z_voltage = _PM.var(pm, nw)[:z_voltage] = JuMP.@variable(pm.model, + [i in _PM.ids(pm, nw, :bus)], base_name="$(nw)_z_voltage", lower_bound = 0, upper_bound = 1, - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :bus, i), "z_voltage_start") + start = _PM.comp_start_value(_PM.ref(pm, nw, :bus, i), "z_voltage_start") ) end - report && _PMs.sol_component_value(pm, nw, :bus, :status, _PMs.ids(pm, nw, :bus), z_voltage) + report && _IM.sol_component_value(pm, nw, :bus, :status, _PM.ids(pm, nw, :bus), z_voltage) end "" -function variable_voltage_magnitude_sqr_on_off(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw, report::Bool=true) - w = _PMs.var(pm, nw)[:w] = JuMP.@variable(pm.model, - [i in _PMs.ids(pm, nw, :bus)], base_name="$(nw)_w", +function variable_voltage_magnitude_sqr_on_off(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw, report::Bool=true) + w = _PM.var(pm, nw)[:w] = JuMP.@variable(pm.model, + [i in _PM.ids(pm, nw, :bus)], base_name="$(nw)_w", lower_bound = 0, - upper_bound = _PMs.ref(pm, nw, :bus, i, "vmax")^2, - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :bus, i), "w_start", 1.001) + upper_bound = _PM.ref(pm, nw, :bus, i, "vmax")^2, + start = _PM.comp_start_value(_PM.ref(pm, nw, :bus, i), "w_start", 1.001) ) - report && _PMs.sol_component_value(pm, nw, :bus, :w, _PMs.ids(pm, nw, :bus), w) + report && _IM.sol_component_value(pm, nw, :bus, :w, _PM.ids(pm, nw, :bus), w) end diff --git a/src/form/acp.jl b/src/form/acp.jl index 871a430..febfff7 100644 --- a/src/form/acp.jl +++ b/src/form/acp.jl @@ -1,40 +1,40 @@ "" -function constraint_model_voltage_damage(pm::_PMs.AbstractACPModel, n::Int) +function constraint_model_voltage_damage(pm::_PM.AbstractACPModel, n::Int) end "" -function variable_voltage_damage(pm::_PMs.AbstractACPModel; kwargs...) - _PMs.variable_voltage_angle(pm; kwargs...) +function variable_voltage_damage(pm::_PM.AbstractACPModel; kwargs...) + _PM.variable_voltage_angle(pm; kwargs...) variable_voltage_magnitude_on_off(pm; kwargs...) variable_voltage_magnitude_violation(pm; kwargs...) end "" -function constraint_bus_voltage_violation_damage(pm::_PMs.AbstractACPModel, n::Int, i::Int, vm_min, vm_max) - vm = _PMs.var(pm, n, :vm, i) - vm_vio = _PMs.var(pm, n, :vm_vio, i) - z = _PMs.var(pm, n, :z_bus, i) +function constraint_bus_voltage_violation_damage(pm::_PM.AbstractACPModel, n::Int, i::Int, vm_min, vm_max) + vm = _PM.var(pm, n, :vm, i) + vm_vio = _PM.var(pm, n, :vm_vio, i) + z = _PM.var(pm, n, :z_bus, i) JuMP.@constraint(pm.model, vm <= z*vm_max) JuMP.@constraint(pm.model, vm >= z*vm_min - vm_vio) end "" -function constraint_bus_voltage_violation(pm::_PMs.AbstractACPModel, n::Int, i::Int, vm_min, vm_max) - vm = _PMs.var(pm, n, :vm, i) - vm_vio = _PMs.var(pm, n, :vm_vio, i) +function constraint_bus_voltage_violation(pm::_PM.AbstractACPModel, n::Int, i::Int, vm_min, vm_max) + vm = _PM.var(pm, n, :vm, i) + vm_vio = _PM.var(pm, n, :vm_vio, i) JuMP.@constraint(pm.model, vm <= vm_max) JuMP.@constraint(pm.model, vm >= vm_min - vm_vio) end -function variable_bus_voltage_on_off(pm::_PMs.AbstractACPModel; kwargs...) - _PMs.variable_voltage_angle(pm; kwargs...) +function variable_bus_voltage_on_off(pm::_PM.AbstractACPModel; kwargs...) + _PM.variable_voltage_angle(pm; kwargs...) variable_voltage_magnitude_on_off(pm; kwargs...) end -function constraint_bus_voltage_on_off(pm::_PMs.AbstractACPModel; nw::Int=pm.cnw, kwargs...) - for (i,bus) in _PMs.ref(pm, nw, :bus) +function constraint_bus_voltage_on_off(pm::_PM.AbstractACPModel; nw::Int=pm.cnw, kwargs...) + for (i,bus) in _PM.ref(pm, nw, :bus) # TODO turn off voltage angle too? constraint_voltage_magnitude_on_off(pm, i; nw=nw) end @@ -42,23 +42,23 @@ end "" -function constraint_power_balance_shed(pm::_PMs.AbstractACPModel, n::Int, i::Int, bus_arcs, bus_arcs_dc, bus_arcs_sw, bus_gens, bus_storage, bus_pd, bus_qd, bus_gs, bus_bs) - vm = _PMs.var(pm, n, :vm, i) - p = get(_PMs.var(pm, n), :p, Dict()); _PMs._check_var_keys(p, bus_arcs, "active power", "branch") - q = get(_PMs.var(pm, n), :q, Dict()); _PMs._check_var_keys(q, bus_arcs, "reactive power", "branch") - pg = get(_PMs.var(pm, n), :pg, Dict()); _PMs._check_var_keys(pg, bus_gens, "active power", "generator") - qg = get(_PMs.var(pm, n), :qg, Dict()); _PMs._check_var_keys(qg, bus_gens, "reactive power", "generator") - ps = get(_PMs.var(pm, n), :ps, Dict()); _PMs._check_var_keys(ps, bus_storage, "active power", "storage") - qs = get(_PMs.var(pm, n), :qs, Dict()); _PMs._check_var_keys(qs, bus_storage, "reactive power", "storage") - psw = get(_PMs.var(pm, n), :psw, Dict()); _PMs._check_var_keys(psw, bus_arcs_sw, "active power", "switch") - qsw = get(_PMs.var(pm, n), :qsw, Dict()); _PMs._check_var_keys(qsw, bus_arcs_sw, "reactive power", "switch") - p_dc = get(_PMs.var(pm, n), :p_dc, Dict()); _PMs._check_var_keys(p_dc, bus_arcs_dc, "active power", "dcline") - q_dc = get(_PMs.var(pm, n), :q_dc, Dict()); _PMs._check_var_keys(q_dc, bus_arcs_dc, "reactive power", "dcline") - z_demand = get(_PMs.var(pm, n), :z_demand, Dict()); _PMs._check_var_keys(z_demand, keys(bus_pd), "power factor scale", "load") - z_shunt = get(_PMs.var(pm, n), :z_shunt, Dict()); _PMs._check_var_keys(z_shunt, keys(bus_gs), "power factor scale", "shunt") +function constraint_power_balance_shed(pm::_PM.AbstractACPModel, n::Int, i::Int, bus_arcs, bus_arcs_dc, bus_arcs_sw, bus_gens, bus_storage, bus_pd, bus_qd, bus_gs, bus_bs) + vm = _PM.var(pm, n, :vm, i) + p = get(_PM.var(pm, n), :p, Dict()); _PM._check_var_keys(p, bus_arcs, "active power", "branch") + q = get(_PM.var(pm, n), :q, Dict()); _PM._check_var_keys(q, bus_arcs, "reactive power", "branch") + pg = get(_PM.var(pm, n), :pg, Dict()); _PM._check_var_keys(pg, bus_gens, "active power", "generator") + qg = get(_PM.var(pm, n), :qg, Dict()); _PM._check_var_keys(qg, bus_gens, "reactive power", "generator") + ps = get(_PM.var(pm, n), :ps, Dict()); _PM._check_var_keys(ps, bus_storage, "active power", "storage") + qs = get(_PM.var(pm, n), :qs, Dict()); _PM._check_var_keys(qs, bus_storage, "reactive power", "storage") + psw = get(_PM.var(pm, n), :psw, Dict()); _PM._check_var_keys(psw, bus_arcs_sw, "active power", "switch") + qsw = get(_PM.var(pm, n), :qsw, Dict()); _PM._check_var_keys(qsw, bus_arcs_sw, "reactive power", "switch") + p_dc = get(_PM.var(pm, n), :p_dc, Dict()); _PM._check_var_keys(p_dc, bus_arcs_dc, "active power", "dcline") + q_dc = get(_PM.var(pm, n), :q_dc, Dict()); _PM._check_var_keys(q_dc, bus_arcs_dc, "reactive power", "dcline") + z_demand = get(_PM.var(pm, n), :z_demand, Dict()); _PM._check_var_keys(z_demand, keys(bus_pd), "power factor scale", "load") + z_shunt = get(_PM.var(pm, n), :z_shunt, Dict()); _PM._check_var_keys(z_shunt, keys(bus_gs), "power factor scale", "shunt") - _PMs.con(pm, n, :kcl_p)[i] = JuMP.@NLconstraint(pm.model, + _PM.con(pm, n, :kcl_p)[i] = JuMP.@NLconstraint(pm.model, sum(p[a] for a in bus_arcs) + sum(p_dc[a_dc] for a_dc in bus_arcs_dc) + sum(psw[a_sw] for a_sw in bus_arcs_sw) @@ -68,7 +68,7 @@ function constraint_power_balance_shed(pm::_PMs.AbstractACPModel, n::Int, i::Int - sum(pd*z_demand[i] for (i,pd) in bus_pd) - sum(gs*vm^2*z_shunt[i] for (i,gs) in bus_gs) ) - _PMs.con(pm, n, :kcl_q)[i] = JuMP.@NLconstraint(pm.model, + _PM.con(pm, n, :kcl_q)[i] = JuMP.@NLconstraint(pm.model, sum(q[a] for a in bus_arcs) + sum(q_dc[a_dc] for a_dc in bus_arcs_dc) + sum(qsw[a_sw] for a_sw in bus_arcs_sw) diff --git a/src/form/apo.jl b/src/form/apo.jl index d15b989..1b3dc01 100644 --- a/src/form/apo.jl +++ b/src/form/apo.jl @@ -1,9 +1,9 @@ "apo models ignore reactive power flows" -function variable_reactive_generation_damage(pm::_PMs.AbstractActivePowerModel; kwargs...) +function variable_reactive_generation_damage(pm::_PM.AbstractActivePowerModel; kwargs...) end "apo models ignore reactive power flows" -function variable_reactive_storage_damage(pm::_PMs.AbstractActivePowerModel; kwargs...) +function variable_reactive_storage_damage(pm::_PM.AbstractActivePowerModel; kwargs...) end diff --git a/src/form/dcp.jl b/src/form/dcp.jl index 6b1948b..ad051ae 100644 --- a/src/form/dcp.jl +++ b/src/form/dcp.jl @@ -1,47 +1,47 @@ -function constraint_model_voltage_damage(pm::_PMs.AbstractDCPModel, n::Int) +function constraint_model_voltage_damage(pm::_PM.AbstractDCPModel, n::Int) end "" -function variable_voltage_damage(pm::_PMs.AbstractDCPModel; kwargs...) - _PMs.variable_voltage_angle(pm; kwargs...) +function variable_voltage_damage(pm::_PM.AbstractDCPModel; kwargs...) + _PM.variable_voltage_angle(pm; kwargs...) end # "no vm values to turn off" -# function constraint_bus_damage(pm::_PMs.AbstractDCPModel, n::Int, i::Int, vm_min, vm_max) +# function constraint_bus_damage(pm::_PM.AbstractDCPModel, n::Int, i::Int, vm_min, vm_max) # end -function variable_bus_voltage_indicator(pm::_PMs.AbstractDCPModel; nw::Int=pm.cnw, relax::Bool=false, report::Bool=true) - report && _PMs.sol_component_fixed(pm, nw, :bus, :status, _PMs.ids(pm, nw, :bus), 1.0) +function variable_bus_voltage_indicator(pm::_PM.AbstractDCPModel; nw::Int=pm.cnw, relax::Bool=false, report::Bool=true) + report && _IM.sol_component_fixed(pm, nw, :bus, :status, _PM.ids(pm, nw, :bus), 1.0) end -function variable_bus_voltage_on_off(pm::_PMs.AbstractDCPModel; kwargs...) - _PMs.variable_voltage_angle(pm; kwargs...) +function variable_bus_voltage_on_off(pm::_PM.AbstractDCPModel; kwargs...) + _PM.variable_voltage_angle(pm; kwargs...) variable_voltage_magnitude_on_off(pm; kwargs...) end -function variable_voltage_magnitude_on_off(pm::_PMs.AbstractDCPModel; nw::Int=pm.cnw, relax::Bool=false, report::Bool=true) - report && _PMs.sol_component_fixed(pm, nw, :bus, :vm, _PMs.ids(pm, nw, :bus), 1.0) +function variable_voltage_magnitude_on_off(pm::_PM.AbstractDCPModel; nw::Int=pm.cnw, relax::Bool=false, report::Bool=true) + report && _IM.sol_component_fixed(pm, nw, :bus, :vm, _PM.ids(pm, nw, :bus), 1.0) end -function constraint_bus_voltage_on_off(pm::_PMs.AbstractDCPModel; nw::Int=pm.cnw, kwargs...) +function constraint_bus_voltage_on_off(pm::_PM.AbstractDCPModel; nw::Int=pm.cnw, kwargs...) end "" -function constraint_power_balance_shed(pm::_PMs.AbstractDCPModel, n::Int, i::Int, bus_arcs, bus_arcs_dc, bus_arcs_sw, bus_gens, bus_storage, bus_pd, bus_qd, bus_gs, bus_bs) - p = get(_PMs.var(pm, n), :p, Dict()); _PMs._check_var_keys(p, bus_arcs, "active power", "branch") - pg = get(_PMs.var(pm, n), :pg, Dict()); _PMs._check_var_keys(pg, bus_gens, "active power", "generator") - ps = get(_PMs.var(pm, n), :ps, Dict()); _PMs._check_var_keys(ps, bus_storage, "active power", "storage") - psw = get(_PMs.var(pm, n), :psw, Dict()); _PMs._check_var_keys(psw, bus_arcs_sw, "active power", "switch") - p_dc = get(_PMs.var(pm, n), :p_dc, Dict()); _PMs._check_var_keys(p_dc, bus_arcs_dc, "active power", "dcline") - z_demand = get(_PMs.var(pm, n), :z_demand, Dict()); _PMs._check_var_keys(z_demand, keys(bus_pd), "power factor scale", "load") - z_shunt = get(_PMs.var(pm, n), :z_shunt, Dict()); _PMs._check_var_keys(z_shunt, keys(bus_gs), "power factor scale", "shunt") +function constraint_power_balance_shed(pm::_PM.AbstractDCPModel, n::Int, i::Int, bus_arcs, bus_arcs_dc, bus_arcs_sw, bus_gens, bus_storage, bus_pd, bus_qd, bus_gs, bus_bs) + p = get(_PM.var(pm, n), :p, Dict()); _PM._check_var_keys(p, bus_arcs, "active power", "branch") + pg = get(_PM.var(pm, n), :pg, Dict()); _PM._check_var_keys(pg, bus_gens, "active power", "generator") + ps = get(_PM.var(pm, n), :ps, Dict()); _PM._check_var_keys(ps, bus_storage, "active power", "storage") + psw = get(_PM.var(pm, n), :psw, Dict()); _PM._check_var_keys(psw, bus_arcs_sw, "active power", "switch") + p_dc = get(_PM.var(pm, n), :p_dc, Dict()); _PM._check_var_keys(p_dc, bus_arcs_dc, "active power", "dcline") + z_demand = get(_PM.var(pm, n), :z_demand, Dict()); _PM._check_var_keys(z_demand, keys(bus_pd), "power factor scale", "load") + z_shunt = get(_PM.var(pm, n), :z_shunt, Dict()); _PM._check_var_keys(z_shunt, keys(bus_gs), "power factor scale", "shunt") - _PMs.con(pm, n, :kcl_p)[i] = JuMP.@constraint(pm.model, + _PM.con(pm, n, :kcl_p)[i] = JuMP.@constraint(pm.model, sum(p[a] for a in bus_arcs) + sum(p_dc[a_dc] for a_dc in bus_arcs_dc) + sum(psw[a_sw] for a_sw in bus_arcs_sw) @@ -55,29 +55,29 @@ end # Needed becouse DC models do not have the z_voltage variable -function objective_max_loadability(pm::_PMs.AbstractDCPModel) - nws = _PMs.nw_ids(pm) +function objective_max_loadability(pm::_PM.AbstractDCPModel) + nws = _PM.nw_ids(pm) - @assert all(!_PMs.ismulticonductor(pm, n) for n in nws) + @assert all(!_PM.ismulticonductor(pm, n) for n in nws) - z_demand = Dict(n => _PMs.var(pm, n, :z_demand) for n in nws) - z_shunt = Dict(n => _PMs.var(pm, n, :z_shunt) for n in nws) - z_gen = Dict(n => _PMs.var(pm, n, :z_gen) for n in nws) - time_elapsed = Dict(n => get(_PMs.ref(pm, n), :time_elapsed, 1) for n in nws) + z_demand = Dict(n => _PM.var(pm, n, :z_demand) for n in nws) + z_shunt = Dict(n => _PM.var(pm, n, :z_shunt) for n in nws) + z_gen = Dict(n => _PM.var(pm, n, :z_gen) for n in nws) + time_elapsed = Dict(n => get(_PM.ref(pm, n), :time_elapsed, 1) for n in nws) load_weight = Dict(n => - Dict(i => get(load, "weight", 1.0) for (i,load) in _PMs.ref(pm, n, :load)) + Dict(i => get(load, "weight", 1.0) for (i,load) in _PM.ref(pm, n, :load)) for n in nws) - M = Dict(n => 10*maximum([load_weight[n][i]*abs(load["pd"]) for (i,load) in _PMs.ref(pm, n, :load)]) for n in nws) + M = Dict(n => 10*maximum([load_weight[n][i]*abs(load["pd"]) for (i,load) in _PM.ref(pm, n, :load)]) for n in nws) return JuMP.@objective(pm.model, Max, sum( ( time_elapsed[n]*( - sum(M[n]*z_gen[n][i] for (i,gen) in _PMs.ref(pm, n, :gen)) + - sum(M[n]*z_shunt[n][i] for (i,shunt) in _PMs.ref(pm, n, :shunt)) + - sum(load_weight[n][i]*abs(load["pd"])*z_demand[n][i] for (i,load) in _PMs.ref(pm, n, :load)) + sum(M[n]*z_gen[n][i] for (i,gen) in _PM.ref(pm, n, :gen)) + + sum(M[n]*z_shunt[n][i] for (i,shunt) in _PM.ref(pm, n, :shunt)) + + sum(load_weight[n][i]*abs(load["pd"])*z_demand[n][i] for (i,load) in _PM.ref(pm, n, :load)) ) ) for n in nws) @@ -85,31 +85,31 @@ function objective_max_loadability(pm::_PMs.AbstractDCPModel) end # can we just add storage to the regular max_loadability objective? # -function objective_max_loadability_strg(pm::_PMs.AbstractDCPModel) - nws = _PMs.nw_ids(pm) +function objective_max_loadability_strg(pm::_PM.AbstractDCPModel) + nws = _PM.nw_ids(pm) - @assert all(!_PMs.ismulticonductor(pm, n) for n in nws) + @assert all(!_PM.ismulticonductor(pm, n) for n in nws) - z_demand = Dict(n => _PMs.var(pm, n, :z_demand) for n in nws) - z_shunt = Dict(n => _PMs.var(pm, n, :z_shunt) for n in nws) - z_gen = Dict(n => _PMs.var(pm, n, :z_gen) for n in nws) - z_storage = Dict(n => _PMs.var(pm, n, :z_storage) for n in nws) - time_elapsed = Dict(n => get(_PMs.ref(pm, n), :time_elapsed, 1) for n in nws) + z_demand = Dict(n => _PM.var(pm, n, :z_demand) for n in nws) + z_shunt = Dict(n => _PM.var(pm, n, :z_shunt) for n in nws) + z_gen = Dict(n => _PM.var(pm, n, :z_gen) for n in nws) + z_storage = Dict(n => _PM.var(pm, n, :z_storage) for n in nws) + time_elapsed = Dict(n => get(_PM.ref(pm, n), :time_elapsed, 1) for n in nws) load_weight = Dict(n => - Dict(i => get(load, "weight", 1.0) for (i,load) in _PMs.ref(pm, n, :load)) + Dict(i => get(load, "weight", 1.0) for (i,load) in _PM.ref(pm, n, :load)) for n in nws) - M = Dict(n => 10*maximum([load_weight[n][i]*abs(load["pd"]) for (i,load) in _PMs.ref(pm, n, :load)]) for n in nws) + M = Dict(n => 10*maximum([load_weight[n][i]*abs(load["pd"]) for (i,load) in _PM.ref(pm, n, :load)]) for n in nws) return JuMP.@objective(pm.model, Max, sum( ( time_elapsed[n]*( - sum(M[n]*z_gen[n][i] for (i,gen) in _PMs.ref(pm, n, :gen)) + - sum(M[n]*z_storage[n][i] for (i,storage) in _PMs.ref(pm, n, :storage)) + - sum(M[n]*z_shunt[n][i] for (i,shunt) in _PMs.ref(pm, n, :shunt)) + - sum(load_weight[n][i]*abs(load["pd"])*z_demand[n][i] for (i,load) in _PMs.ref(pm, n, :load)) + sum(M[n]*z_gen[n][i] for (i,gen) in _PM.ref(pm, n, :gen)) + + sum(M[n]*z_storage[n][i] for (i,storage) in _PM.ref(pm, n, :storage)) + + sum(M[n]*z_shunt[n][i] for (i,shunt) in _PM.ref(pm, n, :shunt)) + + sum(load_weight[n][i]*abs(load["pd"])*z_demand[n][i] for (i,load) in _PM.ref(pm, n, :load)) ) ) for n in nws) @@ -119,9 +119,9 @@ end ### These are needed to overload the default behavior for reactive power ### "no vm values to turn off" -function constraint_bus_voltage_violation_damage(pm::_PMs.AbstractDCPModel, n::Int, i::Int, vm_min, vm_max) +function constraint_bus_voltage_violation_damage(pm::_PM.AbstractDCPModel, n::Int, i::Int, vm_min, vm_max) end "no vm values to turn off" -function constraint_bus_voltage_violation(pm::_PMs.AbstractDCPModel, n::Int, i::Int, vm_min, vm_max) +function constraint_bus_voltage_violation(pm::_PM.AbstractDCPModel, n::Int, i::Int, vm_min, vm_max) end diff --git a/src/form/shared.jl b/src/form/shared.jl index a4f8601..4268faa 100644 --- a/src/form/shared.jl +++ b/src/form/shared.jl @@ -1,49 +1,49 @@ # # same as AbstractWRForm "" -function variable_shunt_factor(pm::_PMs.AbstractWModels; nw::Int=pm.cnw, relax = false) +function variable_shunt_factor(pm::_PM.AbstractWModels; nw::Int=pm.cnw, relax = false) if relax == true - _PMs.var(pm, nw)[:z_shunt] = JuMP.@variable(pm.model, - [i in _PMs.ids(pm, nw, :shunt)], base_name="$(nw)_z_shunt", + _PM.var(pm, nw)[:z_shunt] = JuMP.@variable(pm.model, + [i in _PM.ids(pm, nw, :shunt)], base_name="$(nw)_z_shunt", upper_bound = 1, lower_bound = 0, - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :shunt, i), "z_shunt_on_start", 1.0) + start = _PM.comp_start_value(_PM.ref(pm, nw, :shunt, i), "z_shunt_on_start", 1.0) ) else - _PMs.var(pm, nw)[:z_shunt] = JuMP.@variable(pm.model, - [i in _PMs.ids(pm, nw, :shunt)], base_name="$(nw)_z_shunt", + _PM.var(pm, nw)[:z_shunt] = JuMP.@variable(pm.model, + [i in _PM.ids(pm, nw, :shunt)], base_name="$(nw)_z_shunt", binary = true, - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :shunt, i), "z_shunt_on_start", 1.0) + start = _PM.comp_start_value(_PM.ref(pm, nw, :shunt, i), "z_shunt_on_start", 1.0) ) end - _PMs.var(pm, nw)[:wz_shunt] = JuMP.@variable(pm.model, - [i in _PMs.ids(pm, nw, :shunt)], base_name="$(nw)_wz_shunt", + _PM.var(pm, nw)[:wz_shunt] = JuMP.@variable(pm.model, + [i in _PM.ids(pm, nw, :shunt)], base_name="$(nw)_wz_shunt", lower_bound = 0, - upper_bound = _PMs.ref(pm, nw, :bus)[_PMs.ref(pm, nw, :shunt, i)["shunt_bus"]]["vmax"]^2, - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :shunt, i), "wz_shunt_start", 1.001) + upper_bound = _PM.ref(pm, nw, :bus)[_PM.ref(pm, nw, :shunt, i)["shunt_bus"]]["vmax"]^2, + start = _PM.comp_start_value(_PM.ref(pm, nw, :shunt, i), "wz_shunt_start", 1.001) ) end "" -function constraint_power_balance_shed(pm::_PMs.AbstractWModels, n::Int, i::Int, bus_arcs, bus_arcs_dc, bus_arcs_sw, bus_gens, bus_storage, bus_pd, bus_qd, bus_gs, bus_bs) - w = _PMs.var(pm, n, :w, i) - p = get(_PMs.var(pm, n), :p, Dict()); _PMs._check_var_keys(p, bus_arcs, "active power", "branch") - q = get(_PMs.var(pm, n), :q, Dict()); _PMs._check_var_keys(q, bus_arcs, "reactive power", "branch") - pg = get(_PMs.var(pm, n), :pg, Dict()); _PMs._check_var_keys(pg, bus_gens, "active power", "generator") - qg = get(_PMs.var(pm, n), :qg, Dict()); _PMs._check_var_keys(qg, bus_gens, "reactive power", "generator") - ps = get(_PMs.var(pm, n), :ps, Dict()); _PMs._check_var_keys(ps, bus_storage, "active power", "storage") - qs = get(_PMs.var(pm, n), :qs, Dict()); _PMs._check_var_keys(qs, bus_storage, "reactive power", "storage") - psw = get(_PMs.var(pm, n), :psw, Dict()); _PMs._check_var_keys(psw, bus_arcs_sw, "active power", "switch") - qsw = get(_PMs.var(pm, n), :qsw, Dict()); _PMs._check_var_keys(qsw, bus_arcs_sw, "reactive power", "switch") - p_dc = get(_PMs.var(pm, n), :p_dc, Dict()); _PMs._check_var_keys(p_dc, bus_arcs_dc, "active power", "dcline") - q_dc = get(_PMs.var(pm, n), :q_dc, Dict()); _PMs._check_var_keys(q_dc, bus_arcs_dc, "reactive power", "dcline") - z_demand = get(_PMs.var(pm, n), :z_demand, Dict()); _PMs._check_var_keys(z_demand, keys(bus_pd), "power factor scale", "load") - z_shunt = get(_PMs.var(pm, n), :z_shunt, Dict()); _PMs._check_var_keys(z_shunt, keys(bus_gs), "power factor scale", "shunt") - wz_shunt = get(_PMs.var(pm, n), :wz_shunt, Dict()); _PMs._check_var_keys(wz_shunt, keys(bus_gs), "voltage square power factor scale", "shunt") +function constraint_power_balance_shed(pm::_PM.AbstractWModels, n::Int, i::Int, bus_arcs, bus_arcs_dc, bus_arcs_sw, bus_gens, bus_storage, bus_pd, bus_qd, bus_gs, bus_bs) + w = _PM.var(pm, n, :w, i) + p = get(_PM.var(pm, n), :p, Dict()); _PM._check_var_keys(p, bus_arcs, "active power", "branch") + q = get(_PM.var(pm, n), :q, Dict()); _PM._check_var_keys(q, bus_arcs, "reactive power", "branch") + pg = get(_PM.var(pm, n), :pg, Dict()); _PM._check_var_keys(pg, bus_gens, "active power", "generator") + qg = get(_PM.var(pm, n), :qg, Dict()); _PM._check_var_keys(qg, bus_gens, "reactive power", "generator") + ps = get(_PM.var(pm, n), :ps, Dict()); _PM._check_var_keys(ps, bus_storage, "active power", "storage") + qs = get(_PM.var(pm, n), :qs, Dict()); _PM._check_var_keys(qs, bus_storage, "reactive power", "storage") + psw = get(_PM.var(pm, n), :psw, Dict()); _PM._check_var_keys(psw, bus_arcs_sw, "active power", "switch") + qsw = get(_PM.var(pm, n), :qsw, Dict()); _PM._check_var_keys(qsw, bus_arcs_sw, "reactive power", "switch") + p_dc = get(_PM.var(pm, n), :p_dc, Dict()); _PM._check_var_keys(p_dc, bus_arcs_dc, "active power", "dcline") + q_dc = get(_PM.var(pm, n), :q_dc, Dict()); _PM._check_var_keys(q_dc, bus_arcs_dc, "reactive power", "dcline") + z_demand = get(_PM.var(pm, n), :z_demand, Dict()); _PM._check_var_keys(z_demand, keys(bus_pd), "power factor scale", "load") + z_shunt = get(_PM.var(pm, n), :z_shunt, Dict()); _PM._check_var_keys(z_shunt, keys(bus_gs), "power factor scale", "shunt") + wz_shunt = get(_PM.var(pm, n), :wz_shunt, Dict()); _PM._check_var_keys(wz_shunt, keys(bus_gs), "voltage square power factor scale", "shunt") - _PMs.con(pm, n, :kcl_p)[i] = JuMP.@constraint(pm.model, + _PM.con(pm, n, :kcl_p)[i] = JuMP.@constraint(pm.model, sum(p[a] for a in bus_arcs) + sum(p_dc[a_dc] for a_dc in bus_arcs_dc) + sum(psw[a_sw] for a_sw in bus_arcs_sw) @@ -53,7 +53,7 @@ function constraint_power_balance_shed(pm::_PMs.AbstractWModels, n::Int, i::Int, - sum(pd*z_demand[i] for (i,pd) in bus_pd) - sum(gs*wz_shunt[i] for (i,gs) in bus_gs) ) - _PMs.con(pm, n, :kcl_q)[i] = JuMP.@constraint(pm.model, + _PM.con(pm, n, :kcl_q)[i] = JuMP.@constraint(pm.model, sum(q[a] for a in bus_arcs) + sum(q_dc[a_dc] for a_dc in bus_arcs_dc) + sum(qsw[a_sw] for a_sw in bus_arcs_sw) diff --git a/src/form/wr.jl b/src/form/wr.jl index 0cb419f..aefd3be 100644 --- a/src/form/wr.jl +++ b/src/form/wr.jl @@ -1,19 +1,19 @@ "" -function variable_voltage_damage(pm::_PMs.AbstractWRModel; kwargs...) +function variable_voltage_damage(pm::_PM.AbstractWRModel; kwargs...) variable_voltage_magnitude_sqr_on_off(pm; kwargs...) variable_voltage_magnitude_sqr_violation(pm; kwargs...) - _PMs.variable_voltage_magnitude_sqr_from_on_off(pm; kwargs...) - _PMs.variable_voltage_magnitude_sqr_to_on_off(pm; kwargs...) + _PM.variable_voltage_magnitude_sqr_from_on_off(pm; kwargs...) + _PM.variable_voltage_magnitude_sqr_to_on_off(pm; kwargs...) - _PMs.variable_voltage_product_on_off(pm; kwargs...) + _PM.variable_voltage_product_on_off(pm; kwargs...) end "this is the same as non-damaged version becouse ccms includes zero" -function variable_current_storage_damage(pm::_PMs.AbstractWRModel; nw::Int=pm.cnw) - _PMs.variable_current_storage(pm, nw=nw) - # buses = _PMs.ref(pm, nw, :bus) +function variable_current_storage_damage(pm::_PM.AbstractWRModel; nw::Int=pm.cnw) + _PM.variable_current_storage(pm, nw=nw) + # buses = _PM.ref(pm, nw, :bus) # ub = Dict() - # for (i, storage) in _PMs.ref(pm, nw, :storage) + # for (i, storage) in _PM.ref(pm, nw, :storage) # if haskey(storage, "thermal_rating") # bus = buses[storage["storage_bus"]] # ub[i] = (storage["thermal_rating"]/bus["vmin"])^2 @@ -22,85 +22,85 @@ function variable_current_storage_damage(pm::_PMs.AbstractWRModel; nw::Int=pm.cn # end # end - # _PMs.var(pm, nw)[:ccms] = JuMP.@variable(pm.model, - # [i in _PMs.ids(pm, nw, :storage)], base_name="$(nw)_ccms", + # _PM.var(pm, nw)[:ccms] = JuMP.@variable(pm.model, + # [i in _PM.ids(pm, nw, :storage)], base_name="$(nw)_ccms", # lower_bound = 0.0, # upper_bound = ub[i], - # start = _PMs.variable_current_storage_damagecomp_start_value(_PMs.ref(pm, nw, :storage, i), "ccms_start") + # start = _PM.variable_current_storage_damagecomp_start_value(_PM.ref(pm, nw, :storage, i), "ccms_start") # ) end "" -function variable_voltage_magnitude_sqr_violation(pm::_PMs.AbstractPowerModel; nw::Int=pm.cnw) - _PMs.var(pm, nw)[:w_vio] = JuMP.@variable(pm.model, - [i in _PMs.ids(pm, nw, :bus)], base_name="$(nw)_w_vio", +function variable_voltage_magnitude_sqr_violation(pm::_PM.AbstractPowerModel; nw::Int=pm.cnw) + _PM.var(pm, nw)[:w_vio] = JuMP.@variable(pm.model, + [i in _PM.ids(pm, nw, :bus)], base_name="$(nw)_w_vio", lower_bound = 0.0, - upper_bound = _PMs.ref(pm, nw, :bus, i, "vmin")^2, - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :bus, i), "w_vio_start", 0.0) + upper_bound = _PM.ref(pm, nw, :bus, i, "vmin")^2, + start = _PM.comp_start_value(_PM.ref(pm, nw, :bus, i), "w_vio_start", 0.0) ) end "" -function constraint_model_voltage_damage(pm::_PMs.AbstractWRModel, n::Int) - w = _PMs.var(pm, n, :w) - wr = _PMs.var(pm, n, :wr) - wi = _PMs.var(pm, n, :wi) - z = _PMs.var(pm, n, :z_branch) +function constraint_model_voltage_damage(pm::_PM.AbstractWRModel, n::Int) + w = _PM.var(pm, n, :w) + wr = _PM.var(pm, n, :wr) + wi = _PM.var(pm, n, :wi) + z = _PM.var(pm, n, :z_branch) - w_fr = _PMs.var(pm, n, :w_fr) - w_to = _PMs.var(pm, n, :w_to) + w_fr = _PM.var(pm, n, :w_fr) + w_to = _PM.var(pm, n, :w_to) constraint_voltage_magnitude_sqr_from_damage(pm, n) constraint_voltage_magnitude_sqr_to_damage(pm, n) constraint_voltage_product_damage(pm, n) - for (l,i,j) in _PMs.ref(pm, n, :arcs_from) - _IMs.relaxation_complex_product_on_off(pm.model, w[i], w[j], wr[l], wi[l], z[l]) - _IMs.relaxation_equality_on_off(pm.model, w[i], w_fr[l], z[l]) - _IMs.relaxation_equality_on_off(pm.model, w[j], w_to[l], z[l]) + for (l,i,j) in _PM.ref(pm, n, :arcs_from) + _IM.relaxation_complex_product_on_off(pm.model, w[i], w[j], wr[l], wi[l], z[l]) + _IM.relaxation_equality_on_off(pm.model, w[i], w_fr[l], z[l]) + _IM.relaxation_equality_on_off(pm.model, w[j], w_to[l], z[l]) end end "" -function constraint_voltage_magnitude_sqr_from_damage(pm::_PMs.AbstractWRModel, n::Int) - buses = _PMs.ref(pm, n, :bus) - branches = _PMs.ref(pm, n, :branch) +function constraint_voltage_magnitude_sqr_from_damage(pm::_PM.AbstractWRModel, n::Int) + buses = _PM.ref(pm, n, :bus) + branches = _PM.ref(pm, n, :branch) - w_fr = _PMs.var(pm, n, :w_fr) - z = _PMs.var(pm, n, :z_branch) + w_fr = _PM.var(pm, n, :w_fr) + z = _PM.var(pm, n, :z_branch) - for (i, branch) in _PMs.ref(pm, n, :branch) + for (i, branch) in _PM.ref(pm, n, :branch) JuMP.@constraint(pm.model, w_fr[i] <= z[i]*buses[branch["f_bus"]]["vmax"]^2) end end "" -function constraint_voltage_magnitude_sqr_to_damage(pm::_PMs.AbstractWRModel, n::Int) - buses = _PMs.ref(pm, n, :bus) - branches = _PMs.ref(pm, n, :branch) +function constraint_voltage_magnitude_sqr_to_damage(pm::_PM.AbstractWRModel, n::Int) + buses = _PM.ref(pm, n, :bus) + branches = _PM.ref(pm, n, :branch) - w_to = _PMs.var(pm, n, :w_to) - z = _PMs.var(pm, n, :z_branch) + w_to = _PM.var(pm, n, :w_to) + z = _PM.var(pm, n, :z_branch) - for (i, branch) in _PMs.ref(pm, n, :branch) + for (i, branch) in _PM.ref(pm, n, :branch) JuMP.@constraint(pm.model, w_to[i] <= z[i]*buses[branch["t_bus"]]["vmax"]^2) end end "" -function constraint_voltage_product_damage(pm::_PMs.AbstractWRModel, n::Int) - wr_min, wr_max, wi_min, wi_max = _PMs.ref_calc_voltage_product_bounds(_PMs.ref(pm, n, :buspairs)) +function constraint_voltage_product_damage(pm::_PM.AbstractWRModel, n::Int) + wr_min, wr_max, wi_min, wi_max = _PM.ref_calc_voltage_product_bounds(_PM.ref(pm, n, :buspairs)) - bi_bp = Dict((i, (b["f_bus"], b["t_bus"])) for (i,b) in _PMs.ref(pm, n, :branch)) + bi_bp = Dict((i, (b["f_bus"], b["t_bus"])) for (i,b) in _PM.ref(pm, n, :branch)) - wr = _PMs.var(pm, n, :wr) - wi = _PMs.var(pm, n, :wi) - z = _PMs.var(pm, n, :z_branch) + wr = _PM.var(pm, n, :wr) + wi = _PM.var(pm, n, :wi) + z = _PM.var(pm, n, :z_branch) - for b in _PMs.ids(pm, n, :branch) + for b in _PM.ids(pm, n, :branch) JuMP.@constraint(pm.model, wr[b] <= z[b]*wr_max[bi_bp[b]]) JuMP.@constraint(pm.model, wi[b] <= z[b]*wi_max[bi_bp[b]]) end @@ -108,31 +108,31 @@ end "" -function constraint_bus_voltage_violation_damage(pm::_PMs.AbstractWRModel, n::Int, i::Int, vm_min, vm_max) - w = _PMs.var(pm, n, :w, i) - w_vio = _PMs.var(pm, n, :w_vio, i) - z = _PMs.var(pm, n, :z_bus, i) +function constraint_bus_voltage_violation_damage(pm::_PM.AbstractWRModel, n::Int, i::Int, vm_min, vm_max) + w = _PM.var(pm, n, :w, i) + w_vio = _PM.var(pm, n, :w_vio, i) + z = _PM.var(pm, n, :z_bus, i) JuMP.@constraint(pm.model, w <= z*vm_max^2) JuMP.@constraint(pm.model, w >= z*vm_min^2 - w_vio) end "" -function constraint_bus_voltage_violation(pm::_PMs.AbstractWRModel, n::Int, i::Int, vm_min, vm_max) - w = _PMs.var(pm, n, :w, i) - w_vio = _PMs.var(pm, n, :w_vio, i) +function constraint_bus_voltage_violation(pm::_PM.AbstractWRModel, n::Int, i::Int, vm_min, vm_max) + w = _PM.var(pm, n, :w, i) + w_vio = _PM.var(pm, n, :w_vio, i) JuMP.@constraint(pm.model, w <= vm_max^2) JuMP.@constraint(pm.model, w >= vm_min^2 - w_vio) end "`p[arc_from]^2 + q[arc_from]^2 <= w[f_bus]/tm*ccm[i]`" -function _PMs.constraint_power_magnitude_sqr_on_off(pm::_PMs.AbstractQCWRModel, n::Int, i, f_bus, arc_from, tm) - w = _PMs.var(pm, n, :w, f_bus) - p_fr = _PMs.var(pm, n, :p, arc_from) - q_fr = _PMs.var(pm, n, :q, arc_from) - ccm = _PMs.var(pm, n, :ccm, i) - z = _PMs.var(pm, n, :z_branch, i) +function _PM.constraint_power_magnitude_sqr_on_off(pm::_PM.AbstractQCWRModel, n::Int, i, f_bus, arc_from, tm) + w = _PM.var(pm, n, :w, f_bus) + p_fr = _PM.var(pm, n, :p, arc_from) + q_fr = _PM.var(pm, n, :q, arc_from) + ccm = _PM.var(pm, n, :ccm, i) + z = _PM.var(pm, n, :z_branch, i) # TODO see if there is a way to leverage relaxation_complex_product_on_off here w_lb, w_ub = InfrastructureModels.variable_domain(w) @@ -151,15 +151,15 @@ end "" -function constraint_ohms_yt_from_damage(pm::_PMs.AbstractWRModel, i::Int; nw::Int=pm.cnw) - branch = _PMs.ref(pm, nw, :branch, i) +function constraint_ohms_yt_from_damage(pm::_PM.AbstractWRModel, i::Int; nw::Int=pm.cnw) + branch = _PM.ref(pm, nw, :branch, i) f_bus = branch["f_bus"] t_bus = branch["t_bus"] f_idx = (i, f_bus, t_bus) t_idx = (i, t_bus, f_bus) - g, b = _PMs.calc_branch_y(branch) - tr, ti = _PMs.calc_branch_t(branch) + g, b = _PM.calc_branch_y(branch) + tr, ti = _PM.calc_branch_t(branch) g_fr = branch["g_fr"] b_fr = branch["b_fr"] tm = branch["tap"] @@ -167,29 +167,29 @@ function constraint_ohms_yt_from_damage(pm::_PMs.AbstractWRModel, i::Int; nw::In # TODO make indexing of :wi,:wr standardized ## Because :wi, :wr are indexed by bus_id or bus_pairs depending on if the value is on_off or # standard, there are indexing issues. Temporary solution: always call *_on_off variant - if haskey(_PMs.ref(pm, nw, :damaged_branch), i) - vad_min = _PMs.ref(pm, nw, :off_angmin) - vad_max = _PMs.ref(pm, nw, :off_angmax) - _PMs.constraint_ohms_yt_from_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm, vad_min, vad_max) + if haskey(_PM.ref(pm, nw, :damaged_branch), i) + vad_min = _PM.ref(pm, nw, :off_angmin) + vad_max = _PM.ref(pm, nw, :off_angmax) + _PM.constraint_ohms_yt_from_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm, vad_min, vad_max) else - vad_min = _PMs.ref(pm, nw, :off_angmin) - vad_max = _PMs.ref(pm, nw, :off_angmax) - _PMs.constraint_ohms_yt_from_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm, vad_min, vad_max) - #_PMs.constraint_ohms_yt_from(pm, nw, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm) + vad_min = _PM.ref(pm, nw, :off_angmin) + vad_max = _PM.ref(pm, nw, :off_angmax) + _PM.constraint_ohms_yt_from_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm, vad_min, vad_max) + #_PM.constraint_ohms_yt_from(pm, nw, f_bus, t_bus, f_idx, t_idx, g, b, g_fr, b_fr, tr, ti, tm) end end "" -function constraint_ohms_yt_to_damage(pm::_PMs.AbstractWRModel, i::Int; nw::Int=pm.cnw) - branch = _PMs.ref(pm, nw, :branch, i) +function constraint_ohms_yt_to_damage(pm::_PM.AbstractWRModel, i::Int; nw::Int=pm.cnw) + branch = _PM.ref(pm, nw, :branch, i) f_bus = branch["f_bus"] t_bus = branch["t_bus"] f_idx = (i, f_bus, t_bus) t_idx = (i, t_bus, f_bus) - g, b = _PMs.calc_branch_y(branch) - tr, ti = _PMs.calc_branch_t(branch) + g, b = _PM.calc_branch_y(branch) + tr, ti = _PM.calc_branch_t(branch) g_to = branch["g_to"] b_to = branch["b_to"] tm = branch["tap"] @@ -197,16 +197,16 @@ function constraint_ohms_yt_to_damage(pm::_PMs.AbstractWRModel, i::Int; nw::Int= # TODO make indexing of :wi,:wr standardized ## Because :wi, :wr are indexed by bus_id or bus_pairs depending on if the value is on_off or # standard, there are indexing issues. Temporary solution: always call *_on_off variant - if haskey(_PMs.ref(pm, nw, :damaged_branch), i) - vad_min = _PMs.ref(pm, nw, :off_angmin) - vad_max = _PMs.ref(pm, nw, :off_angmax) + if haskey(_PM.ref(pm, nw, :damaged_branch), i) + vad_min = _PM.ref(pm, nw, :off_angmin) + vad_max = _PM.ref(pm, nw, :off_angmax) - _PMs.constraint_ohms_yt_to_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm, vad_min, vad_max) + _PM.constraint_ohms_yt_to_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm, vad_min, vad_max) else - vad_min = _PMs.ref(pm, nw, :off_angmin) - vad_max = _PMs.ref(pm, nw, :off_angmax) - _PMs.constraint_ohms_yt_to_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm, vad_min, vad_max) - #_PMs.constraint_ohms_yt_to(pm, nw, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm) + vad_min = _PM.ref(pm, nw, :off_angmin) + vad_max = _PM.ref(pm, nw, :off_angmax) + _PM.constraint_ohms_yt_to_on_off(pm, nw, i, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm, vad_min, vad_max) + #_PM.constraint_ohms_yt_to(pm, nw, f_bus, t_bus, f_idx, t_idx, g, b, g_to, b_to, tr, ti, tm) end end @@ -214,39 +214,39 @@ end -function variable_bus_voltage_on_off(pm::_PMs.AbstractWRModel; kwargs...) +function variable_bus_voltage_on_off(pm::_PM.AbstractWRModel; kwargs...) variable_voltage_magnitude_sqr_on_off(pm; kwargs...) variable_bus_voltage_product_on_off(pm; kwargs...) end -function variable_bus_voltage_product_on_off(pm::_PMs.AbstractWRModel; nw::Int=pm.cnw) - wr_min, wr_max, wi_min, wi_max = _PMs.ref_calc_voltage_product_bounds(_PMs.ref(pm, nw, :buspairs)) +function variable_bus_voltage_product_on_off(pm::_PM.AbstractWRModel; nw::Int=pm.cnw) + wr_min, wr_max, wi_min, wi_max = _PM.ref_calc_voltage_product_bounds(_PM.ref(pm, nw, :buspairs)) - _PMs.var(pm, nw)[:wr] = JuMP.@variable(pm.model, - [bp in _PMs.ids(pm, nw, :buspairs)], base_name="$(nw)_wr", + _PM.var(pm, nw)[:wr] = JuMP.@variable(pm.model, + [bp in _PM.ids(pm, nw, :buspairs)], base_name="$(nw)_wr", lower_bound = min(0,wr_min[bp]), upper_bound = max(0,wr_max[bp]), - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :buspairs, bp), "wr_start", 1.0) + start = _PM.comp_start_value(_PM.ref(pm, nw, :buspairs, bp), "wr_start", 1.0) ) - _PMs.var(pm, nw)[:wi] = JuMP.@variable(pm.model, - [bp in _PMs.ids(pm, nw, :buspairs)], base_name="$(nw)_wi", + _PM.var(pm, nw)[:wi] = JuMP.@variable(pm.model, + [bp in _PM.ids(pm, nw, :buspairs)], base_name="$(nw)_wi", lower_bound = min(0,wi_min[bp]), upper_bound = max(0,wi_max[bp]), - start = _PMs.comp_start_value(_PMs.ref(pm, nw, :buspairs, bp), "wi_start") + start = _PM.comp_start_value(_PM.ref(pm, nw, :buspairs, bp), "wi_start") ) end -function constraint_bus_voltage_product_on_off(pm::_PMs.AbstractWRModels; nw::Int=pm.cnw) - wr_min, wr_max, wi_min, wi_max = _PMs.ref_calc_voltage_product_bounds(_PMs.ref(pm, nw, :buspairs)) +function constraint_bus_voltage_product_on_off(pm::_PM.AbstractWRModels; nw::Int=pm.cnw) + wr_min, wr_max, wi_min, wi_max = _PM.ref_calc_voltage_product_bounds(_PM.ref(pm, nw, :buspairs)) - wr = _PMs.var(pm, nw, :wr) - wi = _PMs.var(pm, nw, :wi) - z_voltage = _PMs.var(pm, nw, :z_voltage) + wr = _PM.var(pm, nw, :wr) + wi = _PM.var(pm, nw, :wi) + z_voltage = _PM.var(pm, nw, :z_voltage) - for bp in _PMs.ids(pm, nw, :buspairs) + for bp in _PM.ids(pm, nw, :buspairs) (i,j) = bp z_fr = z_voltage[i] z_to = z_voltage[j] @@ -264,18 +264,18 @@ function constraint_bus_voltage_product_on_off(pm::_PMs.AbstractWRModels; nw::In end -function constraint_bus_voltage_on_off(pm::_PMs.AbstractWRModels, n::Int; kwargs...) - for (i,bus) in _PMs.ref(pm, n, :bus) +function constraint_bus_voltage_on_off(pm::_PM.AbstractWRModels, n::Int; kwargs...) + for (i,bus) in _PM.ref(pm, n, :bus) constraint_voltage_magnitude_sqr_on_off(pm, i; nw=n) end constraint_bus_voltage_product_on_off(pm; nw=n) - w = _PMs.var(pm, n, :w) - wr = _PMs.var(pm, n, :wr) - wi = _PMs.var(pm, n, :wi) + w = _PM.var(pm, n, :w) + wr = _PM.var(pm, n, :wr) + wi = _PM.var(pm, n, :wi) - for (i,j) in _PMs.ids(pm, n, :buspairs) + for (i,j) in _PM.ids(pm, n, :buspairs) InfrastructureModels.relaxation_complex_product(pm.model, w[i], w[j], wr[(i,j)], wi[(i,j)]) end end diff --git a/src/form/wrm.jl b/src/form/wrm.jl index 6a90994..fe2a92f 100644 --- a/src/form/wrm.jl +++ b/src/form/wrm.jl @@ -1,17 +1,17 @@ -function variable_bus_voltage_on_off(pm::_PMs.AbstractWRMModel, nw::Int=pm.cnw; bounded = true, kwargs...) - wr_min, wr_max, wi_min, wi_max = _PMs.ref_calc_voltage_product_bounds(_PMs.ref(pm, nw, :buspairs)) +function variable_bus_voltage_on_off(pm::_PM.AbstractWRMModel, nw::Int=pm.cnw; bounded = true, kwargs...) + wr_min, wr_max, wi_min, wi_max = _PM.ref_calc_voltage_product_bounds(_PM.ref(pm, nw, :buspairs)) - bus_count = length(_PMs.ref(pm, nw, :bus)) + bus_count = length(_PM.ref(pm, nw, :bus)) w_index = 1:bus_count - lookup_w_index = Dict([(bi, i) for (i,bi) in enumerate(keys(_PMs.ref(pm, nw, :bus)))]) + lookup_w_index = Dict([(bi, i) for (i,bi) in enumerate(keys(_PM.ref(pm, nw, :bus)))]) - WR = _PMs.var(pm, nw)[:WR] = JuMP.@variable(pm.model, [1:bus_count, 1:bus_count], Symmetric, base_name="$(nw)_WR") - WI = _PMs.var(pm, nw)[:WI] = JuMP.@variable(pm.model, [1:bus_count, 1:bus_count], base_name="$(nw)_WI") + WR = _PM.var(pm, nw)[:WR] = JuMP.@variable(pm.model, [1:bus_count, 1:bus_count], Symmetric, base_name="$(nw)_WR") + WI = _PM.var(pm, nw)[:WI] = JuMP.@variable(pm.model, [1:bus_count, 1:bus_count], base_name="$(nw)_WI") # bounds on diagonal - for (i, bus) in _PMs.ref(pm, nw, :bus) + for (i, bus) in _PM.ref(pm, nw, :bus) w_idx = lookup_w_index[i] wr_ii = WR[w_idx,w_idx] wi_ii = WR[w_idx,w_idx] @@ -29,7 +29,7 @@ function variable_bus_voltage_on_off(pm::_PMs.AbstractWRMModel, nw::Int=pm.cnw; end # bounds on off-diagonal - for (i,j) in _PMs.ids(pm, nw, :buspairs) + for (i,j) in _PM.ids(pm, nw, :buspairs) wi_idx = lookup_w_index[i] wj_idx = lookup_w_index[j] @@ -42,32 +42,32 @@ function variable_bus_voltage_on_off(pm::_PMs.AbstractWRMModel, nw::Int=pm.cnw; end end - _PMs.var(pm, nw)[:w] = Dict{Int,Any}() - for (i, bus) in _PMs.ref(pm, nw, :bus) + _PM.var(pm, nw)[:w] = Dict{Int,Any}() + for (i, bus) in _PM.ref(pm, nw, :bus) w_idx = lookup_w_index[i] - _PMs.var(pm, nw, :w)[i] = WR[w_idx,w_idx] + _PM.var(pm, nw, :w)[i] = WR[w_idx,w_idx] end - _PMs.var(pm, nw)[:wr] = Dict{Tuple{Int,Int},Any}() - _PMs.var(pm, nw)[:wi] = Dict{Tuple{Int,Int},Any}() - for (i,j) in _PMs.ids(pm, nw, :buspairs) + _PM.var(pm, nw)[:wr] = Dict{Tuple{Int,Int},Any}() + _PM.var(pm, nw)[:wi] = Dict{Tuple{Int,Int},Any}() + for (i,j) in _PM.ids(pm, nw, :buspairs) w_fr_index = lookup_w_index[i] w_to_index = lookup_w_index[j] - _PMs.var(pm, nw, :wr)[(i,j)] = WR[w_fr_index, w_to_index] - _PMs.var(pm, nw, :wi)[(i,j)] = WI[w_fr_index, w_to_index] + _PM.var(pm, nw, :wr)[(i,j)] = WR[w_fr_index, w_to_index] + _PM.var(pm, nw, :wi)[(i,j)] = WI[w_fr_index, w_to_index] end end -function constraint_bus_voltage_on_off(pm::_PMs.AbstractWRMModel, n::Int) - WR = _PMs.var(pm, n, :WR) - WI = _PMs.var(pm, n, :WI) - z_voltage = _PMs.var(pm, n, :z_voltage) +function constraint_bus_voltage_on_off(pm::_PM.AbstractWRMModel, n::Int) + WR = _PM.var(pm, n, :WR) + WI = _PM.var(pm, n, :WI) + z_voltage = _PM.var(pm, n, :z_voltage) JuMP.@SDconstraint(pm.model, [WR WI; -WI WR] >= 0) - for (i,bus) in _PMs.ref(pm, n, :bus) + for (i,bus) in _PM.ref(pm, n, :bus) constraint_voltage_magnitude_sqr_on_off(pm, i; nw=n) end diff --git a/src/prob/mld.jl b/src/prob/mld.jl index 5a697d0..e70f3ef 100644 --- a/src/prob/mld.jl +++ b/src/prob/mld.jl @@ -1,50 +1,50 @@ # Maximum loadability with generator and bus participation relaxed function run_mld(file, model_constructor, solver; kwargs...) - return _PMs.run_model(file, model_constructor, solver, build_mld; kwargs...) + return _PM.run_model(file, model_constructor, solver, build_mld; kwargs...) end -function build_mld(pm::_PMs.AbstractPowerModel) +function build_mld(pm::_PM.AbstractPowerModel) variable_bus_voltage_indicator(pm, relax=true) variable_bus_voltage_on_off(pm) - _PMs.variable_generation_indicator(pm, relax=true) - _PMs.variable_generation_on_off(pm) + _PM.variable_generation_indicator(pm, relax=true) + _PM.variable_generation_on_off(pm) - _PMs.variable_branch_flow(pm) - _PMs.variable_dcline_flow(pm) + _PM.variable_branch_flow(pm) + _PM.variable_dcline_flow(pm) - _PMs.variable_demand_factor(pm, relax=true) - _PMs.variable_shunt_factor(pm, relax=true) + _PM.variable_demand_factor(pm, relax=true) + _PM.variable_shunt_factor(pm, relax=true) objective_max_loadability(pm) - for i in _PMs.ids(pm, :ref_buses) - _PMs.constraint_theta_ref(pm, i) + for i in _PM.ids(pm, :ref_buses) + _PM.constraint_theta_ref(pm, i) end constraint_bus_voltage_on_off(pm) - for i in _PMs.ids(pm, :gen) - _PMs.constraint_generation_on_off(pm, i) + for i in _PM.ids(pm, :gen) + _PM.constraint_generation_on_off(pm, i) end - for i in _PMs.ids(pm, :bus) + for i in _PM.ids(pm, :bus) constraint_power_balance_shed(pm, i) end - for i in _PMs.ids(pm, :branch) - _PMs.constraint_ohms_yt_from(pm, i) - _PMs.constraint_ohms_yt_to(pm, i) + for i in _PM.ids(pm, :branch) + _PM.constraint_ohms_yt_from(pm, i) + _PM.constraint_ohms_yt_to(pm, i) - _PMs.constraint_voltage_angle_difference(pm, i) + _PM.constraint_voltage_angle_difference(pm, i) - _PMs.constraint_thermal_limit_from(pm, i) - _PMs.constraint_thermal_limit_to(pm, i) + _PM.constraint_thermal_limit_from(pm, i) + _PM.constraint_thermal_limit_to(pm, i) end - for i in _PMs.ids(pm, :dcline) - _PMs.constraint_dcline(pm, i) + for i in _PM.ids(pm, :dcline) + _PM.constraint_dcline(pm, i) end end @@ -53,104 +53,104 @@ end # Maximum loadability with flexible generator participation fixed function run_mld_uc(file, model_constructor, solver; kwargs...) - return _PMs.run_model(file, model_constructor, solver, build_mld_uc; kwargs...) + return _PM.run_model(file, model_constructor, solver, build_mld_uc; kwargs...) end -function build_mld_uc(pm::_PMs.AbstractPowerModel) +function build_mld_uc(pm::_PM.AbstractPowerModel) variable_bus_voltage_indicator(pm) variable_bus_voltage_on_off(pm) - _PMs.variable_generation_indicator(pm) - _PMs.variable_generation_on_off(pm) + _PM.variable_generation_indicator(pm) + _PM.variable_generation_on_off(pm) - _PMs.variable_branch_flow(pm) - _PMs.variable_dcline_flow(pm) + _PM.variable_branch_flow(pm) + _PM.variable_dcline_flow(pm) - _PMs.variable_demand_factor(pm, relax=true) - _PMs.variable_shunt_factor(pm, relax=true) + _PM.variable_demand_factor(pm, relax=true) + _PM.variable_shunt_factor(pm, relax=true) objective_max_loadability(pm) - for i in _PMs.ids(pm, :ref_buses) - _PMs.constraint_theta_ref(pm, i) + for i in _PM.ids(pm, :ref_buses) + _PM.constraint_theta_ref(pm, i) end constraint_bus_voltage_on_off(pm) - for i in _PMs.ids(pm, :gen) - _PMs.constraint_generation_on_off(pm, i) + for i in _PM.ids(pm, :gen) + _PM.constraint_generation_on_off(pm, i) end - for i in _PMs.ids(pm, :bus) + for i in _PM.ids(pm, :bus) constraint_power_balance_shed(pm, i) end - for i in _PMs.ids(pm, :branch) - _PMs.constraint_ohms_yt_from(pm, i) - _PMs.constraint_ohms_yt_to(pm, i) + for i in _PM.ids(pm, :branch) + _PM.constraint_ohms_yt_from(pm, i) + _PM.constraint_ohms_yt_to(pm, i) - _PMs.constraint_voltage_angle_difference(pm, i) + _PM.constraint_voltage_angle_difference(pm, i) - _PMs.constraint_thermal_limit_from(pm, i) - _PMs.constraint_thermal_limit_to(pm, i) + _PM.constraint_thermal_limit_from(pm, i) + _PM.constraint_thermal_limit_to(pm, i) end - for i in _PMs.ids(pm, :dcline) - _PMs.constraint_dcline(pm, i) + for i in _PM.ids(pm, :dcline) + _PM.constraint_dcline(pm, i) end end # Maximum loadability with generator participation fixed function run_mld_smpl(file, model_constructor, solver; kwargs...) - return _PMs.run_model(file, model_constructor, solver, run_mld_smpl; kwargs...) + return _PM.run_model(file, model_constructor, solver, run_mld_smpl; kwargs...) end -function run_mld_smpl(pm::_PMs.AbstractPowerModel) - _PMs.variable_voltage(pm, bounded = false) - _PMs.variable_generation(pm, bounded = false) +function run_mld_smpl(pm::_PM.AbstractPowerModel) + _PM.variable_voltage(pm, bounded = false) + _PM.variable_generation(pm, bounded = false) - _PMs.variable_branch_flow(pm) - _PMs.variable_dcline_flow(pm) + _PM.variable_branch_flow(pm) + _PM.variable_dcline_flow(pm) - _PMs.variable_demand_factor(pm, relax=true) - _PMs.variable_shunt_factor(pm, relax=true) + _PM.variable_demand_factor(pm, relax=true) + _PM.variable_shunt_factor(pm, relax=true) - _PMs.var(pm)[:vm_vio] = JuMP.@variable(pm.model, vm_vio[i in _PMs.ids(pm, :bus)] >= 0) - _PMs.var(pm)[:pg_vio] = JuMP.@variable(pm.model, pg_vio[i in _PMs.ids(pm, :gen)] >= 0) - vm = _PMs.var(pm, :vm) - pg = _PMs.var(pm, :pg) - qg = _PMs.var(pm, :qg) + _PM.var(pm)[:vm_vio] = JuMP.@variable(pm.model, vm_vio[i in _PM.ids(pm, :bus)] >= 0) + _PM.var(pm)[:pg_vio] = JuMP.@variable(pm.model, pg_vio[i in _PM.ids(pm, :gen)] >= 0) + vm = _PM.var(pm, :vm) + pg = _PM.var(pm, :pg) + qg = _PM.var(pm, :qg) - z_demand = _PMs.var(pm, pm.cnw, :z_demand) - z_shunt = _PMs.var(pm, pm.cnw, :z_shunt) + z_demand = _PM.var(pm, pm.cnw, :z_demand) + z_shunt = _PM.var(pm, pm.cnw, :z_shunt) - load_weight = Dict(i => get(load, "weight", 1.0) for (i,load) in _PMs.ref(pm, :load)) + load_weight = Dict(i => get(load, "weight", 1.0) for (i,load) in _PM.ref(pm, :load)) - M = maximum(load_weight[i]*abs(load["pd"]) for (i,load) in _PMs.ref(pm, :load)) + M = maximum(load_weight[i]*abs(load["pd"]) for (i,load) in _PM.ref(pm, :load)) JuMP.@objective(pm.model, Max, - sum( -10*M*vm_vio[i] for (i, bus) in _PMs.ref(pm, :bus)) + - sum( -10*M*pg_vio[i] for i in _PMs.ids(pm, :gen) ) + - sum( M*z_shunt[i] for (i, shunt) in _PMs.ref(pm, :shunt)) + - sum( load_weight[i]*abs(load["pd"])*z_demand[i] for (i, load) in _PMs.ref(pm, :load)) + sum( -10*M*vm_vio[i] for (i, bus) in _PM.ref(pm, :bus)) + + sum( -10*M*pg_vio[i] for i in _PM.ids(pm, :gen) ) + + sum( M*z_shunt[i] for (i, shunt) in _PM.ref(pm, :shunt)) + + sum( load_weight[i]*abs(load["pd"])*z_demand[i] for (i, load) in _PM.ref(pm, :load)) ) - for i in _PMs.ids(pm, :ref_buses) - _PMs.constraint_theta_ref(pm, i) + for i in _PM.ids(pm, :ref_buses) + _PM.constraint_theta_ref(pm, i) end - _PMs.constraint_model_voltage(pm) + _PM.constraint_model_voltage(pm) - for (i, bus) in _PMs.ref(pm, :bus) + for (i, bus) in _PM.ref(pm, :bus) constraint_power_balance_shed(pm, i) JuMP.@constraint(pm.model, vm[i] <= bus["vmax"] + vm_vio[i]) JuMP.@constraint(pm.model, vm[i] >= bus["vmin"] - vm_vio[i]) end - for (i, gen) in _PMs.ref(pm, :gen) + for (i, gen) in _PM.ref(pm, :gen) JuMP.@constraint(pm.model, pg[i] <= gen["pmax"] + pg_vio[i]) JuMP.@constraint(pm.model, pg[i] >= gen["pmin"] - pg_vio[i]) @@ -158,137 +158,137 @@ function run_mld_smpl(pm::_PMs.AbstractPowerModel) JuMP.@constraint(pm.model, qg[i] >= gen["qmin"]) end - for i in _PMs.ids(pm, :branch) - _PMs.constraint_ohms_yt_from(pm, i) - _PMs.constraint_ohms_yt_to(pm, i) + for i in _PM.ids(pm, :branch) + _PM.constraint_ohms_yt_from(pm, i) + _PM.constraint_ohms_yt_to(pm, i) - _PMs.constraint_voltage_angle_difference(pm, i) + _PM.constraint_voltage_angle_difference(pm, i) - _PMs.constraint_thermal_limit_from(pm, i) - _PMs.constraint_thermal_limit_to(pm, i) + _PM.constraint_thermal_limit_from(pm, i) + _PM.constraint_thermal_limit_to(pm, i) end end # Maximum loadability with storage, generator and bus participation relaxed function run_mld_strg(file, model_constructor, solver; kwargs...) - return _PMs.run_model(file, model_constructor, solver, build_mld_strg; kwargs...) + return _PM.run_model(file, model_constructor, solver, build_mld_strg; kwargs...) end -function build_mld_strg(pm::_PMs.AbstractPowerModel) +function build_mld_strg(pm::_PM.AbstractPowerModel) variable_bus_voltage_indicator(pm, relax=true) variable_bus_voltage_on_off(pm) - _PMs.variable_generation_indicator(pm, relax=true) - _PMs.variable_generation_on_off(pm) + _PM.variable_generation_indicator(pm, relax=true) + _PM.variable_generation_on_off(pm) - _PMs.variable_storage_indicator(pm, relax = true) - _PMs.variable_storage_mi_on_off(pm) + _PM.variable_storage_indicator(pm, relax = true) + _PM.variable_storage_mi_on_off(pm) - _PMs.variable_branch_flow(pm) - _PMs.variable_dcline_flow(pm) + _PM.variable_branch_flow(pm) + _PM.variable_dcline_flow(pm) - _PMs.variable_demand_factor(pm, relax=true) - _PMs.variable_shunt_factor(pm, relax=true) + _PM.variable_demand_factor(pm, relax=true) + _PM.variable_shunt_factor(pm, relax=true) objective_max_loadability_strg(pm) - for i in _PMs.ids(pm, :ref_buses) - _PMs.constraint_theta_ref(pm, i) + for i in _PM.ids(pm, :ref_buses) + _PM.constraint_theta_ref(pm, i) end constraint_bus_voltage_on_off(pm) - for i in _PMs.ids(pm, :gen) - _PMs.constraint_generation_on_off(pm, i) + for i in _PM.ids(pm, :gen) + _PM.constraint_generation_on_off(pm, i) end - for i in _PMs.ids(pm, :bus) + for i in _PM.ids(pm, :bus) constraint_power_balance_shed(pm, i) end - for i in _PMs.ids(pm, :storage) - _PMs.constraint_storage_state(pm, i) - _PMs.constraint_storage_complementarity_mi(pm, i) - _PMs.constraint_storage_on_off(pm,i) - _PMs.constraint_storage_loss(pm, i) - _PMs.constraint_storage_thermal_limit(pm, i) + for i in _PM.ids(pm, :storage) + _PM.constraint_storage_state(pm, i) + _PM.constraint_storage_complementarity_mi(pm, i) + _PM.constraint_storage_on_off(pm,i) + _PM.constraint_storage_loss(pm, i) + _PM.constraint_storage_thermal_limit(pm, i) end - for i in _PMs.ids(pm, :branch) - _PMs.constraint_ohms_yt_from(pm, i) - _PMs.constraint_ohms_yt_to(pm, i) + for i in _PM.ids(pm, :branch) + _PM.constraint_ohms_yt_from(pm, i) + _PM.constraint_ohms_yt_to(pm, i) - _PMs.constraint_voltage_angle_difference(pm, i) + _PM.constraint_voltage_angle_difference(pm, i) - _PMs.constraint_thermal_limit_from(pm, i) - _PMs.constraint_thermal_limit_to(pm, i) + _PM.constraint_thermal_limit_from(pm, i) + _PM.constraint_thermal_limit_to(pm, i) end - for i in _PMs.ids(pm, :dcline) - _PMs.constraint_dcline(pm, i) + for i in _PM.ids(pm, :dcline) + _PM.constraint_dcline(pm, i) end end # Maximum loadability with storage and generator participated fixed, and bus participation relaxed function run_mld_strg_uc(file, model_constructor, solver; kwargs...) - return _PMs.run_model(file, model_constructor, solver, build_mld_strg_uc; kwargs...) + return _PM.run_model(file, model_constructor, solver, build_mld_strg_uc; kwargs...) end -function build_mld_strg_uc(pm::_PMs.AbstractPowerModel) +function build_mld_strg_uc(pm::_PM.AbstractPowerModel) variable_bus_voltage_indicator(pm, relax=true) variable_bus_voltage_on_off(pm) - _PMs.variable_generation_indicator(pm) - _PMs.variable_generation_on_off(pm) + _PM.variable_generation_indicator(pm) + _PM.variable_generation_on_off(pm) - _PMs.variable_storage_indicator(pm) - _PMs.variable_storage_mi_on_off(pm) + _PM.variable_storage_indicator(pm) + _PM.variable_storage_mi_on_off(pm) - _PMs.variable_branch_flow(pm) - _PMs.variable_dcline_flow(pm) + _PM.variable_branch_flow(pm) + _PM.variable_dcline_flow(pm) - _PMs.variable_demand_factor(pm, relax=true) - _PMs.variable_shunt_factor(pm, relax=true) + _PM.variable_demand_factor(pm, relax=true) + _PM.variable_shunt_factor(pm, relax=true) objective_max_loadability_strg(pm) - for i in _PMs.ids(pm, :ref_buses) - _PMs.constraint_theta_ref(pm, i) + for i in _PM.ids(pm, :ref_buses) + _PM.constraint_theta_ref(pm, i) end constraint_bus_voltage_on_off(pm) - for i in _PMs.ids(pm, :gen) - _PMs.constraint_generation_on_off(pm, i) + for i in _PM.ids(pm, :gen) + _PM.constraint_generation_on_off(pm, i) end - for i in _PMs.ids(pm, :bus) + for i in _PM.ids(pm, :bus) constraint_power_balance_shed(pm, i) end - for i in _PMs.ids(pm, :storage) - _PMs.constraint_storage_state(pm, i) - _PMs.constraint_storage_complementarity_mi(pm, i) - _PMs.constraint_storage_loss(pm, i) - _PMs.constraint_storage_thermal_limit(pm, i) - _PMs.constraint_storage_on_off(pm,i) + for i in _PM.ids(pm, :storage) + _PM.constraint_storage_state(pm, i) + _PM.constraint_storage_complementarity_mi(pm, i) + _PM.constraint_storage_loss(pm, i) + _PM.constraint_storage_thermal_limit(pm, i) + _PM.constraint_storage_on_off(pm,i) end - for i in _PMs.ids(pm, :branch) - _PMs.constraint_ohms_yt_from(pm, i) - _PMs.constraint_ohms_yt_to(pm, i) + for i in _PM.ids(pm, :branch) + _PM.constraint_ohms_yt_from(pm, i) + _PM.constraint_ohms_yt_to(pm, i) - _PMs.constraint_voltage_angle_difference(pm, i) + _PM.constraint_voltage_angle_difference(pm, i) - _PMs.constraint_thermal_limit_from(pm, i) - _PMs.constraint_thermal_limit_to(pm, i) + _PM.constraint_thermal_limit_from(pm, i) + _PM.constraint_thermal_limit_to(pm, i) end - for i in _PMs.ids(pm, :dcline) - _PMs.constraint_dcline(pm, i) + for i in _PM.ids(pm, :dcline) + _PM.constraint_dcline(pm, i) end end diff --git a/src/prob/mrsp.jl b/src/prob/mrsp.jl index 72d424b..4d225da 100644 --- a/src/prob/mrsp.jl +++ b/src/prob/mrsp.jl @@ -1,19 +1,19 @@ "" function run_mrsp(file, model_constructor, optimizer; kwargs...) - return _PMs.run_model(file, model_constructor, optimizer, build_mrsp; - ref_extensions=[_PMs.ref_add_on_off_va_bounds!, ref_add_damaged_items!], kwargs...) + return _PM.run_model(file, model_constructor, optimizer, build_mrsp; + ref_extensions=[_PM.ref_add_on_off_va_bounds!, ref_add_damaged_items!], kwargs...) end "" -function build_mrsp(pm::_PMs.AbstractPowerModel) +function build_mrsp(pm::_PM.AbstractPowerModel) variable_bus_damage_indicator(pm) variable_voltage_damage(pm) variable_branch_damage_indicator(pm) - _PMs.variable_branch_flow(pm) + _PM.variable_branch_flow(pm) - _PMs.variable_dcline_flow(pm) + _PM.variable_dcline_flow(pm) variable_storage_damage_indicator(pm) variable_storage_mi_damage(pm) @@ -21,22 +21,22 @@ function build_mrsp(pm::_PMs.AbstractPowerModel) variable_generation_damage_indicator(pm) variable_generation_damage(pm) - _PMs.constraint_model_voltage_on_off(pm) + _PM.constraint_model_voltage_on_off(pm) - for i in _PMs.ids(pm, :ref_buses) - _PMs.constraint_theta_ref(pm, i) + for i in _PM.ids(pm, :ref_buses) + _PM.constraint_theta_ref(pm, i) end - for i in _PMs.ids(pm, :bus) + for i in _PM.ids(pm, :bus) constraint_bus_voltage_violation_damage(pm, i) - _PMs.constraint_power_balance(pm, i) + _PM.constraint_power_balance(pm, i) end - for i in _PMs.ids(pm, :gen) + for i in _PM.ids(pm, :gen) constraint_generation_damage(pm, i) end - for i in _PMs.ids(pm, :branch) + for i in _PM.ids(pm, :branch) constraint_branch_damage(pm, i) constraint_ohms_yt_from_damage(pm, i) constraint_ohms_yt_to_damage(pm, i) @@ -47,15 +47,15 @@ function build_mrsp(pm::_PMs.AbstractPowerModel) constraint_thermal_limit_to_damage(pm, i) end - for i in _PMs.ids(pm, :dcline) - _PMs.constraint_dcline(pm, i) + for i in _PM.ids(pm, :dcline) + _PM.constraint_dcline(pm, i) end - for i in _PMs.ids(pm, :storage) + for i in _PM.ids(pm, :storage) constraint_storage_damage(pm, i) - _PMs.constraint_storage_state(pm, i) - _PMs.constraint_storage_complementarity_mi(pm, i) - _PMs.constraint_storage_loss(pm, i) + _PM.constraint_storage_state(pm, i) + _PM.constraint_storage_complementarity_mi(pm, i) + _PM.constraint_storage_loss(pm, i) end objective_min_restoration(pm) @@ -63,18 +63,18 @@ end "" -function objective_min_restoration(pm::_PMs.AbstractPowerModel) - @assert !_PMs.ismultinetwork(pm) - z_storage = _PMs.var(pm, pm.cnw, :z_storage) - z_gen = _PMs.var(pm, pm.cnw, :z_gen) - z_branch = _PMs.var(pm, pm.cnw, :z_branch) - z_bus = _PMs.var(pm, pm.cnw, :z_bus) +function objective_min_restoration(pm::_PM.AbstractPowerModel) + @assert !_IM.ismultinetwork(pm) + z_storage = _PM.var(pm, pm.cnw, :z_storage) + z_gen = _PM.var(pm, pm.cnw, :z_gen) + z_branch = _PM.var(pm, pm.cnw, :z_branch) + z_bus = _PM.var(pm, pm.cnw, :z_bus) JuMP.@objective(pm.model, Min, - sum(z_branch[i] for (i,branch) in _PMs.ref(pm, :damaged_branch)) - + sum(z_gen[i] for (i,gen) in _PMs.ref(pm, :damaged_gen)) - + sum(z_storage[i] for (i,storage) in _PMs.ref(pm, :damaged_storage)) - + sum(z_bus[i] for (i,bus) in _PMs.ref(pm, :damaged_bus)) + sum(z_branch[i] for (i,branch) in _PM.ref(pm, :damaged_branch)) + + sum(z_gen[i] for (i,gen) in _PM.ref(pm, :damaged_gen)) + + sum(z_storage[i] for (i,storage) in _PM.ref(pm, :damaged_storage)) + + sum(z_bus[i] for (i,bus) in _PM.ref(pm, :damaged_bus)) ) end diff --git a/src/prob/rop.jl b/src/prob/rop.jl index 0b32fc0..ab37d4a 100644 --- a/src/prob/rop.jl +++ b/src/prob/rop.jl @@ -1,20 +1,20 @@ "" function run_rop(file, model_constructor, optimizer; kwargs...) - return _PMs.run_model(file, model_constructor, optimizer, build_rop; multinetwork=true, - ref_extensions=[_PMs.ref_add_on_off_va_bounds!, ref_add_damaged_items!], kwargs...) + return _PM.run_model(file, model_constructor, optimizer, build_rop; multinetwork=true, + ref_extensions=[_PM.ref_add_on_off_va_bounds!, ref_add_damaged_items!], kwargs...) end "" -function build_rop(pm::_PMs.AbstractPowerModel) - for (n, network) in _PMs.nws(pm) +function build_rop(pm::_PM.AbstractPowerModel) + for (n, network) in _PM.nws(pm) variable_bus_damage_indicator(pm, nw=n) variable_voltage_damage(pm, nw=n) variable_branch_damage_indicator(pm, nw=n) - _PMs.variable_branch_flow(pm, nw=n) + _PM.variable_branch_flow(pm, nw=n) - _PMs.variable_dcline_flow(pm, nw=n) + _PM.variable_dcline_flow(pm, nw=n) variable_storage_damage_indicator(pm, nw=n) variable_storage_mi_damage(pm, nw=n) @@ -22,35 +22,35 @@ function build_rop(pm::_PMs.AbstractPowerModel) variable_generation_damage_indicator(pm, nw=n) variable_generation_damage(pm, nw=n) - _PMs.variable_demand_factor(pm, nw=n, relax=true) - _PMs.variable_shunt_factor(pm, nw=n, relax=true) + _PM.variable_demand_factor(pm, nw=n, relax=true) + _PM.variable_shunt_factor(pm, nw=n, relax=true) constraint_restoration_cardinality_ub(pm, nw=n) constraint_model_voltage_damage(pm, nw=n) - for i in _PMs.ids(pm, :ref_buses, nw=n) - _PMs.constraint_theta_ref(pm, i, nw=n) + for i in _PM.ids(pm, :ref_buses, nw=n) + _PM.constraint_theta_ref(pm, i, nw=n) end - for i in _PMs.ids(pm, :bus, nw=n) + for i in _PM.ids(pm, :bus, nw=n) constraint_bus_voltage_violation_damage(pm, i, nw=n) constraint_power_balance_shed(pm, i, nw=n) end - for i in _PMs.ids(pm, :gen, nw=n) + for i in _PM.ids(pm, :gen, nw=n) constraint_generation_damage(pm, i, nw=n) end - for i in _PMs.ids(pm, :load, nw=n) + for i in _PM.ids(pm, :load, nw=n) constraint_load_damage(pm, i, nw=n) end - for i in _PMs.ids(pm, :shunt, nw=n) + for i in _PM.ids(pm, :shunt, nw=n) constraint_shunt_damage(pm, i, nw=n) end - for i in _PMs.ids(pm, :branch, nw=n) + for i in _PM.ids(pm, :branch, nw=n) constraint_branch_damage(pm, i, nw=n) constraint_ohms_yt_from_damage(pm, i, nw=n) constraint_ohms_yt_to_damage(pm, i, nw=n) @@ -61,41 +61,41 @@ function build_rop(pm::_PMs.AbstractPowerModel) constraint_thermal_limit_to_damage(pm, i, nw=n) end - for i in _PMs.ids(pm, :dcline, nw=n) - _PMs.constraint_dcline(pm, i, nw=n) + for i in _PM.ids(pm, :dcline, nw=n) + _PM.constraint_dcline(pm, i, nw=n) end - for i in _PMs.ids(pm, :storage, nw=n) + for i in _PM.ids(pm, :storage, nw=n) constraint_storage_damage(pm, i, nw=n) - _PMs.constraint_storage_complementarity_mi(pm, i, nw=n) - _PMs.constraint_storage_loss(pm, i, nw=n) + _PM.constraint_storage_complementarity_mi(pm, i, nw=n) + _PM.constraint_storage_loss(pm, i, nw=n) end end - network_ids = sort(collect(_PMs.nw_ids(pm))) + network_ids = sort(collect(_PM.nw_ids(pm))) n_1 = network_ids[1] - for i in _PMs.ids(pm, :storage, nw=n_1) - _PMs.constraint_storage_state(pm, i, nw=n_1) + for i in _PM.ids(pm, :storage, nw=n_1) + _PM.constraint_storage_state(pm, i, nw=n_1) end for n_2 in network_ids[2:end] - for i in _PMs.ids(pm, :storage, nw=n_2) - _PMs.constraint_storage_state(pm, i, n_1, n_2) + for i in _PM.ids(pm, :storage, nw=n_2) + _PM.constraint_storage_state(pm, i, n_1, n_2) end - for i in _PMs.ids(pm, :gen, nw=n_2) + for i in _PM.ids(pm, :gen, nw=n_2) constraint_active_gen(pm, i, n_1, n_2) end - for i in _PMs.ids(pm, :bus, nw=n_2) + for i in _PM.ids(pm, :bus, nw=n_2) constraint_active_bus(pm, i, n_1, n_2) end - for i in _PMs.ids(pm, :storage, nw=n_2) + for i in _PM.ids(pm, :storage, nw=n_2) constraint_active_storage(pm, i, n_1, n_2) end - for i in _PMs.ids(pm, :branch, nw=n_2) + for i in _PM.ids(pm, :branch, nw=n_2) constraint_active_branch(pm, i, n_1, n_2) end - for i in _PMs.ids(pm, :load, nw=n_2) + for i in _PM.ids(pm, :load, nw=n_2) constraint_increasing_load(pm, i, n_1, n_2) end n_1 = n_2 diff --git a/src/prob/test.jl b/src/prob/test.jl index b93ee9f..d9ffd65 100644 --- a/src/prob/test.jl +++ b/src/prob/test.jl @@ -1,51 +1,51 @@ # Maximum loadability with flexible generator participation fixed function _run_mld_discrete_load(file, model_constructor, solver; kwargs...) - return _PMs.run_model(file, model_constructor, solver, _build_mld_discrete_load; kwargs...) + return _PM.run_model(file, model_constructor, solver, _build_mld_discrete_load; kwargs...) end -function _build_mld_discrete_load(pm::_PMs.AbstractPowerModel) +function _build_mld_discrete_load(pm::_PM.AbstractPowerModel) variable_bus_voltage_indicator(pm) variable_bus_voltage_on_off(pm) - _PMs.variable_generation_indicator(pm) - _PMs.variable_generation_on_off(pm) + _PM.variable_generation_indicator(pm) + _PM.variable_generation_on_off(pm) - _PMs.variable_storage(pm) + _PM.variable_storage(pm) - _PMs.variable_branch_flow(pm) - _PMs.variable_dcline_flow(pm) + _PM.variable_branch_flow(pm) + _PM.variable_dcline_flow(pm) - _PMs.variable_demand_factor(pm) - _PMs.variable_shunt_factor(pm) + _PM.variable_demand_factor(pm) + _PM.variable_shunt_factor(pm) objective_max_loadability(pm) - for i in _PMs.ids(pm, :ref_buses) - _PMs.constraint_theta_ref(pm, i) + for i in _PM.ids(pm, :ref_buses) + _PM.constraint_theta_ref(pm, i) end constraint_bus_voltage_on_off(pm) - for i in _PMs.ids(pm, :gen) - _PMs.constraint_generation_on_off(pm, i) + for i in _PM.ids(pm, :gen) + _PM.constraint_generation_on_off(pm, i) end - for i in _PMs.ids(pm, :bus) + for i in _PM.ids(pm, :bus) constraint_power_balance_shed(pm, i) end - for i in _PMs.ids(pm, :branch) - _PMs.constraint_ohms_yt_from(pm, i) - _PMs.constraint_ohms_yt_to(pm, i) + for i in _PM.ids(pm, :branch) + _PM.constraint_ohms_yt_from(pm, i) + _PM.constraint_ohms_yt_to(pm, i) - _PMs.constraint_voltage_angle_difference(pm, i) + _PM.constraint_voltage_angle_difference(pm, i) - _PMs.constraint_thermal_limit_from(pm, i) - _PMs.constraint_thermal_limit_to(pm, i) + _PM.constraint_thermal_limit_from(pm, i) + _PM.constraint_thermal_limit_to(pm, i) end - for i in _PMs.ids(pm, :dcline) - _PMs.constraint_dcline(pm, i) + for i in _PM.ids(pm, :dcline) + _PM.constraint_dcline(pm, i) end end diff --git a/src/util/ac-mld-uc.jl b/src/util/ac-mld-uc.jl index 484495a..4bfb3b3 100644 --- a/src/util/ac-mld-uc.jl +++ b/src/util/ac-mld-uc.jl @@ -3,54 +3,54 @@ function run_ac_mld_uc(case::Dict{String,<:Any}, solver; modifications::Dict{String,<:Any}=Dict{String,Any}("per_unit" => case["per_unit"]), setting::Dict{String,<:Any}=Dict{String,Any}(), int_tol::Real=1e-6) base_case = case case = deepcopy(case) - _PMs.update_data!(case, modifications) + _PM.update_data!(case, modifications) - _PMs.propagate_topology_status!(case) - _PMs.select_largest_component!(case) - #_PMs.correct_refrence_buses!(case) + _PM.simplify_network!(case) + _PM.select_largest_component!(case) + #_PM.correct_refrence_buses!(case) if length(setting) != 0 - Memento.info(_PMs._LOGGER, "settings: $(setting)") + Memento.info(_PM._LOGGER, "settings: $(setting)") end - soc_result = run_mld(case, _PMs.SOCWRPowerModel, solver; setting=setting) + soc_result = run_mld(case, _PM.SOCWRPowerModel, solver; setting=setting) - @assert (soc_result["termination_status"] == _PMs.LOCALLY_SOLVED || soc_result["termination_status"] == _PMs.OPTIMAL) + @assert (soc_result["termination_status"] == _PM.LOCALLY_SOLVED || soc_result["termination_status"] == _PM.OPTIMAL) soc_sol = soc_result["solution"] soc_active_delivered = sum([if (case["load"][i]["status"] != 0) load["pd"] else 0.0 end for (i,load) in soc_sol["load"]]) soc_active_output = sum([if (isequal(gen["pg"], NaN) || gen["gen_status"] == 0) 0.0 else gen["pg"] end for (i,gen) in soc_sol["gen"]]) - Memento.info(_PMs._LOGGER, "soc active gen: $(soc_active_output)") - Memento.info(_PMs._LOGGER, "soc active demand: $(soc_active_delivered)") + Memento.info(_PM._LOGGER, "soc active gen: $(soc_active_output)") + Memento.info(_PM._LOGGER, "soc active demand: $(soc_active_delivered)") for (i,bus) in soc_sol["bus"] if case["bus"][i]["bus_type"] != 4 && bus["status"] <= 1-int_tol case["bus"][i]["bus_type"] = 4 - Memento.info(_PMs._LOGGER, "removing bus $i, $(bus["status"])") + Memento.info(_PM._LOGGER, "removing bus $i, $(bus["status"])") end end for (i,gen) in soc_sol["gen"] if case["gen"][i]["gen_status"] != 0 && gen["gen_status"] <= 1-int_tol case["gen"][i]["gen_status"] = 0 - Memento.info(_PMs._LOGGER, "removing gen $i, $(gen["gen_status"])") + Memento.info(_PM._LOGGER, "removing gen $i, $(gen["gen_status"])") end end - _PMs.propagate_topology_status!(case) + _PM.simplify_network!(case) bus_count = sum([if (case["bus"][i]["bus_type"] != 4) 1 else 0 end for (i,bus) in case["bus"]]) if bus_count <= 0 result = soc_result else - _PMs.select_largest_component!(case) + _PM.select_largest_component!(case) - ac_result = run_mld_smpl(case, _PMs.ACPPowerModel, solver; setting=setting) + ac_result = run_mld_smpl(case, _PM.ACPPowerModel, solver; setting=setting) ac_result["solve_time"] = ac_result["solve_time"] + soc_result["solve_time"] - _PMs.update_data!(soc_sol, ac_result["solution"]) + _PM.update_data!(soc_sol, ac_result["solution"]) ac_result["solution"] = soc_sol result = ac_result @@ -90,8 +90,8 @@ function run_ac_mld_uc(case::Dict{String,<:Any}, solver; modifications::Dict{Str active_delivered = sum(load["pd"] for (i,load) in sol["load"]) active_output = sum(gen["pg"] for (i,gen) in sol["gen"] if haskey(gen, "pg")) - Memento.info(_PMs._LOGGER, "ac active gen: $active_output") - Memento.info(_PMs._LOGGER, "ac active demand: $active_delivered") + Memento.info(_PM._LOGGER, "ac active gen: $active_output") + Memento.info(_PM._LOGGER, "ac active demand: $active_delivered") return result end diff --git a/src/util/iterative_restoration.jl b/src/util/iterative_restoration.jl index 90b75ef..09fffb6 100644 --- a/src/util/iterative_restoration.jl +++ b/src/util/iterative_restoration.jl @@ -12,31 +12,31 @@ "solve restoration using iterative period length" function run_iterative_restoration(network, model_constructor, optimizer; repair_periods=2, kwargs...) - if _IMs.ismultinetwork(network) - Memento.error(_PMs._LOGGER, "iterative restoration does not support multinetwork starting conditions") + if _IM.ismultinetwork(network) + Memento.error(_PM._LOGGER, "iterative restoration does not support multinetwork starting conditions") end - Memento.info(_PMs._LOGGER, "Iterative Restoration Algorithm starting...") + Memento.info(_PM._LOGGER, "Iterative Restoration Algorithm starting...") ## Run initial MLD problem - Memento.info(_PMs._LOGGER, "begin baseline Maximum Load Delivery") + Memento.info(_PM._LOGGER, "begin baseline Maximum Load Delivery") network_mld = deepcopy(network) propagate_damage_status!(network_mld) set_component_inactive!(network_mld, get_damaged_items(network_mld)) - _PMs.propagate_topology_status!(network_mld) + _PM.simplify_network!(network_mld) result_mld = run_mld_strg(network_mld, model_constructor, optimizer, kwargs...) clean_status!(result_mld["solution"]) ## Turn network into multinetwork solution to merge with solution_iterative - mn_network_mld = _PMs.replicate(result_mld["solution"], 1) + mn_network_mld = _PM.replicate(result_mld["solution"], 1) mn_network_mld["nw"]["0"] = mn_network_mld["nw"]["1"] delete!(mn_network_mld["nw"], "1") result_mld["solution"] = mn_network_mld - Memento.info(_PMs._LOGGER, "begin Iterative Restoration") + Memento.info(_PM._LOGGER, "begin Iterative Restoration") result_iterative = _run_iterative_sub_network(network, model_constructor, optimizer; repair_periods=repair_periods, kwargs...) merge_solution!(result_iterative, result_mld) @@ -109,7 +109,7 @@ function _run_iterative_sub_network(network, model_constructor, optimizer; repai restoration_solution = _run_rop_ir(restoration_network, model_constructor, optimizer, kwargs...) clean_status!(restoration_solution["solution"]) - _PMs.update_data!(restoration_network, restoration_solution["solution"]) # will update, loads, storage, etc.... + _PM.update_data!(restoration_network, restoration_solution["solution"]) # will update, loads, storage, etc.... update_damage_status!(restoration_network) #set status of items before/after repairs delete!(restoration_network["nw"],"0") @@ -118,9 +118,9 @@ function _run_iterative_sub_network(network, model_constructor, optimizer; repai for(nw_id, network) in sort(Dict{Int,Any}([(parse(Int, k), v) for (k,v) in restoration_network["nw"]])) if count_repairable_items(network) > 1 - Memento.info(_PMs._LOGGER, "sub_network $(nw_id) has $(count_damaged_items(network)) damaged items and $(count_repairable_items(network)) repairable items") + Memento.info(_PM._LOGGER, "sub_network $(nw_id) has $(count_damaged_items(network)) damaged items and $(count_repairable_items(network)) repairable items") - Memento.info(_PMs._LOGGER, "Starting sub network restoration") + Memento.info(_PM._LOGGER, "Starting sub network restoration") for k in keys(restoration_network) if k != "nw" network[k] = restoration_network[k] @@ -128,7 +128,7 @@ function _run_iterative_sub_network(network, model_constructor, optimizer; repai network["multinetwork"] = false end - Memento.info(_PMs._LOGGER, "Start recursive call") + Memento.info(_PM._LOGGER, "Start recursive call") subnet_solution = _run_iterative_sub_network(network, model_constructor, optimizer; repair_periods=repair_periods, kwargs...) ## Rename solution nw_ids appropriately @@ -147,8 +147,8 @@ function _run_iterative_sub_network(network, model_constructor, optimizer; repai last_network = isempty(subnet_solution_set["solution"]["nw"]) ? 0 : maximum(parse.(Int,keys(subnet_solution_set["solution"]["nw"]))) subnet_solution_set["solution"]["nw"]["$(last_network+1)"] = network - Memento.info(_PMs._LOGGER, "sub_network $(nw_id) has $(count_damaged_items(network)) damaged items and $(count_repairable_items(network)) repairable items") - Memento.info(_PMs._LOGGER, "sub_network does not need restoration sequencing") + Memento.info(_PM._LOGGER, "sub_network $(nw_id) has $(count_damaged_items(network)) damaged items and $(count_repairable_items(network)) repairable items") + Memento.info(_PM._LOGGER, "sub_network does not need restoration sequencing") end end @@ -158,7 +158,7 @@ end "Merge solution dictionaries and accumulate solvetime and objective" function merge_solution!(solution1, solution2) - Memento.info(_PMs._LOGGER, "networks $(keys(solution2["solution"]["nw"])) finished with status $(solution2["termination_status"])") + Memento.info(_PM._LOGGER, "networks $(keys(solution2["solution"]["nw"])) finished with status $(solution2["termination_status"])") solution1["termination_status"] = max(solution1["termination_status"],solution2["termination_status"]) solution1["primal_status"] = max(solution1["primal_status"],solution2["primal_status"]) @@ -174,16 +174,16 @@ end " Update damage status for each time period based on whether the device has already been repaired" function update_damage_status!(mn_data) - if _IMs.ismultinetwork(mn_data) + if _IM.ismultinetwork(mn_data) for (nw_id, network) in mn_data["nw"] - for (comp_type, comp_status) in _PMs.pm_component_status + for (comp_type, comp_status) in _PM.pm_component_status for (comp_id, comp) in network[comp_type] if nw_id != "0" #not items are repaired in "0", do not check in previous network for a change - if comp[comp_status] != _PMs.pm_component_status_inactive[comp_type] && # if comp is active - mn_data["nw"]["$(parse(Int,nw_id)-1)"][comp_type][comp_id][comp_status] != _PMs.pm_component_status_inactive[comp_type] # if comp was previously active + if comp[comp_status] != _PM.pm_component_status_inactive[comp_type] && # if comp is active + mn_data["nw"]["$(parse(Int,nw_id)-1)"][comp_type][comp_id][comp_status] != _PM.pm_component_status_inactive[comp_type] # if comp was previously active if haskey(comp,"damaged") && comp["damaged"] == 1 # therefore the comp was repaired in a former time_step, should be considered undamaged - Memento.info(_PMs._LOGGER, "$(comp_type) $(comp_id) was repaired before step $(nw_id). Setting damged state to 0.") + Memento.info(_PM._LOGGER, "$(comp_type) $(comp_id) was repaired before step $(nw_id). Setting damged state to 0.") comp["damaged"] = 0 end end @@ -192,27 +192,27 @@ function update_damage_status!(mn_data) end end else - Memento.error(_PMs._LOGGER, "update_damage_status required multinetwork to identify is a device has been previously repaired.") + Memento.error(_PM._LOGGER, "update_damage_status required multinetwork to identify is a device has been previously repaired.") end end "" function _run_rop_ir(file, model_constructor, optimizer; kwargs...) - return _PMs.run_model(file, model_constructor, optimizer, _build_rop_ir; multinetwork=true, - ref_extensions=[_PMs.ref_add_on_off_va_bounds!, ref_add_damaged_items!], kwargs...) + return _PM.run_model(file, model_constructor, optimizer, _build_rop_ir; multinetwork=true, + ref_extensions=[_PM.ref_add_on_off_va_bounds!, ref_add_damaged_items!], kwargs...) end "" -function _build_rop_ir(pm::_PMs.AbstractPowerModel) - for (n, network) in _PMs.nws(pm) +function _build_rop_ir(pm::_PM.AbstractPowerModel) + for (n, network) in _PM.nws(pm) variable_bus_damage_indicator(pm, nw=n) variable_voltage_damage(pm, nw=n) variable_branch_damage_indicator(pm, nw=n) - _PMs.variable_branch_flow(pm, nw=n) + _PM.variable_branch_flow(pm, nw=n) - _PMs.variable_dcline_flow(pm, nw=n) + _PM.variable_dcline_flow(pm, nw=n) variable_storage_damage_indicator(pm, nw=n) variable_storage_mi_damage(pm, nw=n) @@ -220,36 +220,36 @@ function _build_rop_ir(pm::_PMs.AbstractPowerModel) variable_generation_damage_indicator(pm, nw=n) variable_generation_damage(pm, nw=n) - _PMs.variable_demand_factor(pm, nw=n, relax=true) - _PMs.variable_shunt_factor(pm, nw=n, relax=true) + _PM.variable_demand_factor(pm, nw=n, relax=true) + _PM.variable_shunt_factor(pm, nw=n, relax=true) constraint_restoration_cardinality_ub(pm, nw=n) constraint_restoration_cardinality_lb(pm, nw=n) constraint_model_voltage_damage(pm, nw=n) - for i in _PMs.ids(pm, :ref_buses, nw=n) - _PMs.constraint_theta_ref(pm, i, nw=n) + for i in _PM.ids(pm, :ref_buses, nw=n) + _PM.constraint_theta_ref(pm, i, nw=n) end - for i in _PMs.ids(pm, :bus, nw=n) + for i in _PM.ids(pm, :bus, nw=n) constraint_bus_voltage_violation_damage(pm, i, nw=n) constraint_power_balance_shed(pm, i, nw=n) end - for i in _PMs.ids(pm, :gen, nw=n) + for i in _PM.ids(pm, :gen, nw=n) constraint_generation_damage(pm, i, nw=n) end - for i in _PMs.ids(pm, :load, nw=n) + for i in _PM.ids(pm, :load, nw=n) constraint_load_damage(pm, i, nw=n) end - for i in _PMs.ids(pm, :shunt, nw=n) + for i in _PM.ids(pm, :shunt, nw=n) constraint_shunt_damage(pm, i, nw=n) end - for i in _PMs.ids(pm, :branch, nw=n) + for i in _PM.ids(pm, :branch, nw=n) constraint_branch_damage(pm, i, nw=n) constraint_ohms_yt_from_damage(pm, i, nw=n) constraint_ohms_yt_to_damage(pm, i, nw=n) @@ -260,41 +260,41 @@ function _build_rop_ir(pm::_PMs.AbstractPowerModel) constraint_thermal_limit_to_damage(pm, i, nw=n) end - for i in _PMs.ids(pm, :dcline, nw=n) - _PMs.constraint_dcline(pm, i, nw=n) + for i in _PM.ids(pm, :dcline, nw=n) + _PM.constraint_dcline(pm, i, nw=n) end - for i in _PMs.ids(pm, :storage, nw=n) + for i in _PM.ids(pm, :storage, nw=n) constraint_storage_damage(pm, i, nw=n) - _PMs.constraint_storage_complementarity_mi(pm, i, nw=n) - _PMs.constraint_storage_loss(pm, i, nw=n) + _PM.constraint_storage_complementarity_mi(pm, i, nw=n) + _PM.constraint_storage_loss(pm, i, nw=n) end end - network_ids = sort(collect(_PMs.nw_ids(pm))) + network_ids = sort(collect(_PM.nw_ids(pm))) n_1 = network_ids[1] - for i in _PMs.ids(pm, :storage, nw=n_1) - _PMs.constraint_storage_state(pm, i, nw=n_1) + for i in _PM.ids(pm, :storage, nw=n_1) + _PM.constraint_storage_state(pm, i, nw=n_1) end for n_2 in network_ids[2:end] - for i in _PMs.ids(pm, :storage, nw=n_2) - _PMs.constraint_storage_state(pm, i, n_1, n_2) + for i in _PM.ids(pm, :storage, nw=n_2) + _PM.constraint_storage_state(pm, i, n_1, n_2) end - for i in _PMs.ids(pm, :gen, nw=n_2) + for i in _PM.ids(pm, :gen, nw=n_2) constraint_active_gen(pm, i, n_1, n_2) end - for i in _PMs.ids(pm, :bus, nw=n_2) + for i in _PM.ids(pm, :bus, nw=n_2) constraint_active_bus(pm, i, n_1, n_2) end - for i in _PMs.ids(pm, :storage, nw=n_2) + for i in _PM.ids(pm, :storage, nw=n_2) constraint_active_storage(pm, i, n_1, n_2) end - for i in _PMs.ids(pm, :branch, nw=n_2) + for i in _PM.ids(pm, :branch, nw=n_2) constraint_active_branch(pm, i, n_1, n_2) end - for i in _PMs.ids(pm, :load, nw=n_2) + for i in _PM.ids(pm, :load, nw=n_2) constraint_increasing_load(pm, i, n_1, n_2) end n_1 = n_2 @@ -307,21 +307,21 @@ function _build_rop_ir(pm::_PMs.AbstractPowerModel) end function constraint_restore_all_items_partial_load(pm, n) - z_storage = _PMs.var(pm, n, :z_storage) - z_gen = _PMs.var(pm, n, :z_gen) - z_branch = _PMs.var(pm, n, :z_branch) - z_bus = _PMs.var(pm, n, :z_bus) + z_storage = _PM.var(pm, n, :z_storage) + z_gen = _PM.var(pm, n, :z_gen) + z_branch = _PM.var(pm, n, :z_branch) + z_bus = _PM.var(pm, n, :z_bus) - for (i,storage) in _PMs.ref(pm, n, :damaged_storage) + for (i,storage) in _PM.ref(pm, n, :damaged_storage) JuMP.@constraint(pm.model, z_storage[i] == 1) end - for (i,gen) in _PMs.ref(pm, n, :damaged_gen) + for (i,gen) in _PM.ref(pm, n, :damaged_gen) JuMP.@constraint(pm.model, z_gen[i] == 1) end - for (i,branch) in _PMs.ref(pm, n, :damaged_branch) + for (i,branch) in _PM.ref(pm, n, :damaged_branch) JuMP.@constraint(pm.model, z_branch[i] == 1) end - for (i,bus) in _PMs.ref(pm, n, :damaged_bus) + for (i,bus) in _PM.ref(pm, n, :damaged_bus) JuMP.@constraint(pm.model, z_bus[i] == 1) end end diff --git a/src/util/restoration_redispatch.jl b/src/util/restoration_redispatch.jl index 3f36a44..6c03cbf 100644 --- a/src/util/restoration_redispatch.jl +++ b/src/util/restoration_redispatch.jl @@ -1,74 +1,74 @@ "Simulate a restoration sequence power flow" function run_restoration_redispatch(file::String, model_type::Type, optimizer; kwargs...) - data = _PMs.parse_file(file) + data = _PM.parse_file(file) return run_restoration_redispatch(data, model_type, optimizer; kwargs...) end "Simulate a restoration sequence power flow" function run_restoration_redispatch(data::Dict{String,Any}, model_type::Type, optimizer; kwargs...) clear_damage_indicator!(data) - return _PMs.run_model(data, model_type, optimizer, build_restoration_redispatch; multinetwork=true, - ref_extensions=[_PMs.ref_add_on_off_va_bounds!, ref_add_damaged_items!], kwargs...) + return _PM.run_model(data, model_type, optimizer, build_restoration_redispatch; multinetwork=true, + ref_extensions=[_PM.ref_add_on_off_va_bounds!, ref_add_damaged_items!], kwargs...) end "" -function build_restoration_redispatch(pm::_PMs.AbstractPowerModel) - for (n, network) in _PMs.nws(pm) - _PMs.variable_voltage(pm, nw=n) +function build_restoration_redispatch(pm::_PM.AbstractPowerModel) + for (n, network) in _PM.nws(pm) + _PM.variable_voltage(pm, nw=n) variable_voltage_magnitude_violation(pm; nw=n) - _PMs.variable_generation(pm, nw=n) - _PMs.variable_storage(pm, nw=n) - _PMs.variable_branch_flow(pm, nw=n) - _PMs.variable_dcline_flow(pm, nw=n) + _PM.variable_generation(pm, nw=n) + _PM.variable_storage(pm, nw=n) + _PM.variable_branch_flow(pm, nw=n) + _PM.variable_dcline_flow(pm, nw=n) - _PMs.variable_demand_factor(pm, nw=n, relax=true) - _PMs.variable_shunt_factor(pm, nw=n, relax=true) + _PM.variable_demand_factor(pm, nw=n, relax=true) + _PM.variable_shunt_factor(pm, nw=n, relax=true) - _PMs.constraint_model_voltage(pm, nw=n) + _PM.constraint_model_voltage(pm, nw=n) - for i in _PMs.ids(pm, :ref_buses, nw=n) - _PMs.constraint_theta_ref(pm, i, nw=n) + for i in _PM.ids(pm, :ref_buses, nw=n) + _PM.constraint_theta_ref(pm, i, nw=n) end - for i in _PMs.ids(pm, :bus, nw=n) + for i in _PM.ids(pm, :bus, nw=n) constraint_bus_voltage_violation(pm, i, nw=n) constraint_power_balance_shed(pm, i, nw=n) end - for i in _PMs.ids(pm, :storage, nw=n) - _PMs.constraint_storage_complementarity_nl(pm, i, nw=n) - _PMs.constraint_storage_loss(pm, i, nw=n) - _PMs.constraint_storage_thermal_limit(pm, i, nw=n) + for i in _PM.ids(pm, :storage, nw=n) + _PM.constraint_storage_complementarity_nl(pm, i, nw=n) + _PM.constraint_storage_loss(pm, i, nw=n) + _PM.constraint_storage_thermal_limit(pm, i, nw=n) end - for i in _PMs.ids(pm, :branch, nw=n) - _PMs.constraint_ohms_yt_from(pm, i, nw=n) - _PMs.constraint_ohms_yt_to(pm, i, nw=n) + for i in _PM.ids(pm, :branch, nw=n) + _PM.constraint_ohms_yt_from(pm, i, nw=n) + _PM.constraint_ohms_yt_to(pm, i, nw=n) - _PMs.constraint_voltage_angle_difference(pm, i, nw=n) + _PM.constraint_voltage_angle_difference(pm, i, nw=n) - _PMs.constraint_thermal_limit_from(pm, i, nw=n) - _PMs.constraint_thermal_limit_to(pm, i, nw=n) + _PM.constraint_thermal_limit_from(pm, i, nw=n) + _PM.constraint_thermal_limit_to(pm, i, nw=n) end - for i in _PMs.ids(pm, :dcline, nw=n) - _PMs.constraint_dcline(pm, i, nw=n) + for i in _PM.ids(pm, :dcline, nw=n) + _PM.constraint_dcline(pm, i, nw=n) end end - network_ids = sort(collect(_PMs.nw_ids(pm))) + network_ids = sort(collect(_PM.nw_ids(pm))) n_1 = network_ids[1] - for i in _PMs.ids(pm, :storage, nw=n_1) - _PMs.constraint_storage_state(pm, i, nw=n_1) + for i in _PM.ids(pm, :storage, nw=n_1) + _PM.constraint_storage_state(pm, i, nw=n_1) end for n_2 in network_ids[2:end] - for i in _PMs.ids(pm, :storage, nw=n_2) - _PMs.constraint_storage_state(pm, i, n_1, n_2) + for i in _PM.ids(pm, :storage, nw=n_2) + _PM.constraint_storage_state(pm, i, n_1, n_2) end n_1 = n_2 end diff --git a/test/mld_data.jl b/test/mld_data.jl index 94b7843..23b5b85 100644 --- a/test/mld_data.jl +++ b/test/mld_data.jl @@ -6,7 +6,7 @@ data_initial = PowerModels.parse_file("../test/data/case5_mld_ft.m") data = PowerModels.parse_file("../test/data/case5_mld_ft.m") - PowerModels.propagate_topology_status!(data) + PowerModels.simplify_network!(data) @test length(data_initial["bus"]) == length(data["bus"]) @test length(data_initial["gen"]) == length(data["gen"]) @@ -38,7 +38,7 @@ data_initial = PowerModels.parse_file("../test/data/case5_mld_ft.m") data = PowerModels.parse_file("../test/data/case5_mld_ft.m") - PowerModels.propagate_topology_status!(data) + PowerModels.simplify_network!(data) PowerModels.select_largest_component!(data) @test length(data_initial["bus"]) == length(data["bus"]) @@ -69,7 +69,7 @@ @testset "output values" begin data = PowerModels.parse_file("../test/data/case5_mld_ft.m") - PowerModels.propagate_topology_status!(data) + PowerModels.simplify_network!(data) result = run_mld(data, PowerModels.ACPPowerModel, ipopt_solver) solution = result["solution"] From 5c7dcf82ed9b23d680c3496606ba4b0eebffcc30 Mon Sep 17 00:00:00 2001 From: ccoffrin Date: Mon, 13 Apr 2020 08:41:20 -0600 Subject: [PATCH 2/2] prep for release --- CHANGELOG.md | 6 +++++- Project.toml | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 179cf96..571f730 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,12 @@ ## Staged - nothing +## v0.4.0 +- Update to PowerModels v0.16 (breaking) +- Add support for Memento v0.13, v1.0 + ## v0.3.0 -- Update to PowerModels v0.15 +- Update to PowerModels v0.15 (breaking) ## v0.2.1 - Minor fix to result building in run_iterative_restoration diff --git a/Project.toml b/Project.toml index 5251afc..41d26a0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PowerModelsRestoration" uuid = "23adbb12-a187-11e9-26a2-eb4d4e6e68fb" authors = ["David M Fobes ", "Noah Rhodes"] -version = "0.3.0" +version = "0.4.0" [deps] InfrastructureModels = "2030c09a-7f63-5d83-885d-db604e0e9cc0" @@ -15,7 +15,7 @@ InfrastructureModels = "~0.4" JuMP = "~0.19.1, ~0.20, ~0.21" MathOptInterface = "~0.8, ~0.9" Memento = "~0.10, ~0.11, ~0.12, ~0.13, ~1.0" -PowerModels = "~0.15.2" +PowerModels = "~0.16" julia = "^1" [extras]