Skip to content

Commit 568b97b

Browse files
authored
Name Updates for PowerModels v0.17 (#40)
* function name updates * remove unused variable_shunt_factor function * add reactive power control fix to storage devices
1 parent fa5c0b9 commit 568b97b

19 files changed

+262
-300
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
## Staged
44
- nothing
55

6+
## v0.5.0
7+
- Update to new function name convention of PowerModels v0.17 details in PR #40 (breaking)
8+
- Update to PowerModels v0.17 (breaking)
9+
610
## v0.4.0
711
- Update to PowerModels v0.16 (breaking)
812
- Add support for Memento v0.13, v1.0

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PowerModelsRestoration"
22
uuid = "23adbb12-a187-11e9-26a2-eb4d4e6e68fb"
33
authors = ["David M Fobes <[email protected]>", "Noah Rhodes"]
4-
version = "0.4.0"
4+
version = "0.5.0"
55

66
[deps]
77
InfrastructureModels = "2030c09a-7f63-5d83-885d-db604e0e9cc0"
@@ -11,11 +11,11 @@ Memento = "f28f55f0-a522-5efc-85c2-fe41dfb9b2d9"
1111
PowerModels = "c36e90e8-916a-50a6-bd94-075b64ef4655"
1212

1313
[compat]
14-
InfrastructureModels = "~0.4"
14+
InfrastructureModels = "~0.5"
1515
JuMP = "~0.19.1, ~0.20, ~0.21"
1616
MathOptInterface = "~0.8, ~0.9"
1717
Memento = "~0.10, ~0.11, ~0.12, ~0.13, ~1.0"
18-
PowerModels = "~0.16"
18+
PowerModels = "~0.17"
1919
julia = "^1"
2020

2121
[extras]

src/core/constraint.jl

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ function constraint_restoration_cardinality_ub(pm::_PM.AbstractPowerModel, n::In
66
z_bus = _PM.var(pm, n, :z_bus)
77

88
JuMP.@constraint(pm.model,
9-
sum(z_branch[i] for (i,branch) in _PM.ref(pm, n, :damaged_branch))
10-
+ sum(z_gen[i] for (i,gen) in _PM.ref(pm, n, :damaged_gen))
11-
+ sum(z_storage[i] for (i,storage) in _PM.ref(pm, n, :damaged_storage))
12-
+ sum(z_bus[i] for (i,bus) in _PM.ref(pm, n, :damaged_bus))
9+
sum(z_branch[i] for (i,branch) in _PM.ref(pm, n, :branch_damage))
10+
+ sum(z_gen[i] for (i,gen) in _PM.ref(pm, n, :gen_damage))
11+
+ sum(z_storage[i] for (i,storage) in _PM.ref(pm, n, :storage_damage))
12+
+ sum(z_bus[i] for (i,bus) in _PM.ref(pm, n, :bus_damage))
1313
<= cumulative_repairs
1414
)
1515
end
@@ -23,10 +23,10 @@ function constraint_restoration_cardinality_lb(pm::_PM.AbstractPowerModel, n::In
2323
z_bus = _PM.var(pm, n, :z_bus)
2424

2525
JuMP.@constraint(pm.model,
26-
sum(z_branch[i] for (i,branch) in _PM.ref(pm, n, :damaged_branch))
27-
+ sum(z_gen[i] for (i,gen) in _PM.ref(pm, n, :damaged_gen))
28-
+ sum(z_storage[i] for (i,storage) in _PM.ref(pm, n, :damaged_storage))
29-
+ sum(z_bus[i] for (i,bus) in _PM.ref(pm, n, :damaged_bus))
26+
sum(z_branch[i] for (i,branch) in _PM.ref(pm, n, :branch_damage))
27+
+ sum(z_gen[i] for (i,gen) in _PM.ref(pm, n, :gen_damage))
28+
+ sum(z_storage[i] for (i,storage) in _PM.ref(pm, n, :storage_damage))
29+
+ sum(z_bus[i] for (i,bus) in _PM.ref(pm, n, :bus_damage))
3030
>= cumulative_repairs
3131
)
3232
end
@@ -47,24 +47,24 @@ function constraint_restore_all_items(pm, n)
4747
JuMP.@constraint(pm.model, z_shunt[i] == 1)
4848
end
4949

50-
for (i,storage) in _PM.ref(pm, n, :damaged_storage)
50+
for (i,storage) in _PM.ref(pm, n, :storage_damage)
5151
JuMP.@constraint(pm.model, z_storage[i] == 1)
5252
end
53-
for (i,gen) in _PM.ref(pm, n, :damaged_gen)
53+
for (i,gen) in _PM.ref(pm, n, :gen_damage)
5454
JuMP.@constraint(pm.model, z_gen[i] == 1)
5555
end
56-
for (i,branch) in _PM.ref(pm, n, :damaged_branch)
56+
for (i,branch) in _PM.ref(pm, n, :branch_damage)
5757
JuMP.@constraint(pm.model, z_branch[i] == 1)
5858
end
59-
for (i,bus) in _PM.ref(pm, n, :damaged_bus)
59+
for (i,bus) in _PM.ref(pm, n, :bus_damage)
6060
JuMP.@constraint(pm.model, z_bus[i] == 1)
6161
end
6262
end
6363

6464

6565
""
66-
function constraint_active_gen(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
67-
if haskey(_PM.ref(pm, nw_1, :damaged_gen), i)
66+
function constraint_gen_energized(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
67+
if haskey(_PM.ref(pm, nw_1, :gen_damage), i)
6868
z_gen_1 = _PM.var(pm, nw_1, :z_gen, i)
6969
z_gen_2 = _PM.var(pm, nw_2, :z_gen, i)
7070

@@ -73,8 +73,8 @@ function constraint_active_gen(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, n
7373
end
7474

7575
""
76-
function constraint_active_bus(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
77-
if haskey(_PM.ref(pm, nw_1, :damaged_gen), i)
76+
function constraint_bus_energized(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
77+
if haskey(_PM.ref(pm, nw_1, :gen_damage), i)
7878
z_bus_1 = _PM.var(pm, nw_1, :z_bus, i)
7979
z_bus_2 = _PM.var(pm, nw_2, :z_bus, i)
8080

@@ -84,8 +84,8 @@ end
8484

8585

8686
""
87-
function constraint_active_storage(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
88-
if haskey(_PM.ref(pm, nw_1, :damaged_storage), i)
87+
function constraint_storage_energized(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
88+
if haskey(_PM.ref(pm, nw_1, :storage_damage), i)
8989
z_storage_1 = _PM.var(pm, nw_1, :z_storage, i)
9090
z_storage_2 = _PM.var(pm, nw_2, :z_storage, i)
9191

@@ -95,8 +95,8 @@ end
9595

9696

9797
""
98-
function constraint_active_branch(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
99-
if haskey(_PM.ref(pm, nw_1, :damaged_branch), i)
98+
function constraint_branch_energized(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
99+
if haskey(_PM.ref(pm, nw_1, :branch_damage), i)
100100
z_branch_1 = _PM.var(pm, nw_1, :z_branch, i)
101101
z_branch_2 = _PM.var(pm, nw_2, :z_branch, i)
102102

@@ -106,7 +106,7 @@ end
106106

107107

108108
"Load delivered at each node must be greater than or equal the previous time period"
109-
function constraint_increasing_load(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
109+
function constraint_load_increasing(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
110110

111111
z_demand_1 = _PM.var(pm, nw_1, :z_demand, i)
112112
z_demand_2 = _PM.var(pm, nw_2, :z_demand, i)

src/core/constraint_template.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ end
2222

2323

2424
""
25-
function constraint_generation_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw)
25+
function constraint_gen_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw)
2626
gen = _PM.ref(pm, nw, :gen, i)
2727

28-
gen_damaged = haskey(_PM.ref(pm, nw, :damaged_gen), i)
29-
bus_damaged = haskey(_PM.ref(pm, nw, :damaged_bus), gen["gen_bus"])
28+
gen_damaged = haskey(_PM.ref(pm, nw, :gen_damage), i)
29+
bus_damaged = haskey(_PM.ref(pm, nw, :bus_damage), gen["gen_bus"])
3030

3131
if gen_damaged
32-
_PM.constraint_generation_on_off(pm, nw, i, gen["pmin"], gen["pmax"], gen["qmin"], gen["qmax"])
32+
_PM.constraint_gen_power_on_off(pm, nw, i, gen["pmin"], gen["pmax"], gen["qmin"], gen["qmax"])
3333
if bus_damaged
3434
constraint_gen_bus_connection(pm, nw, i, gen["gen_bus"])
3535
end
@@ -45,7 +45,7 @@ function constraint_load_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.c
4545
if haskey(_PM.ref(pm, nw, :load), i)
4646
load = _PM.ref(pm, nw, :load, i)
4747

48-
bus_damaged = haskey(_PM.ref(pm, nw, :damaged_bus), load["load_bus"])
48+
bus_damaged = haskey(_PM.ref(pm, nw, :bus_damage), load["load_bus"])
4949

5050
if bus_damaged
5151
constraint_load_bus_connection(pm, nw, i, load["load_bus"])
@@ -58,7 +58,7 @@ end
5858
function constraint_shunt_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw)
5959
if haskey(_PM.ref(pm, nw, :shunt), i)
6060
shunt = _PM.ref(pm, nw, :shunt, i)
61-
bus_damaged = haskey(_PM.ref(pm, nw, :damaged_bus), shunt["shunt_bus"])
61+
bus_damaged = haskey(_PM.ref(pm, nw, :bus_damage), shunt["shunt_bus"])
6262

6363
if bus_damaged
6464
constraint_shunt_bus_connection(pm, nw, i, shunt["shunt_bus"])
@@ -71,9 +71,9 @@ end
7171
function constraint_branch_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw)
7272
branch = _PM.ref(pm, nw, :branch, i)
7373

74-
branch_damaged = haskey(_PM.ref(pm, nw, :damaged_branch), i)
75-
bus_fr_damaged = haskey(_PM.ref(pm, nw, :damaged_bus), branch["f_bus"])
76-
bus_to_damaged = haskey(_PM.ref(pm, nw, :damaged_bus), branch["t_bus"])
74+
branch_damaged = haskey(_PM.ref(pm, nw, :branch_damage), i)
75+
bus_fr_damaged = haskey(_PM.ref(pm, nw, :bus_damage), branch["f_bus"])
76+
bus_to_damaged = haskey(_PM.ref(pm, nw, :bus_damage), branch["t_bus"])
7777

7878
if branch_damaged
7979
if bus_fr_damaged
@@ -109,7 +109,7 @@ function constraint_ohms_yt_from_damage(pm::_PM.AbstractPowerModel, i::Int; nw::
109109
# TODO make indexing of :wi,:wr standardized
110110
## Because :wi, :wr are indexed by bus_id or bus_pairs depending on if the value is on_off or
111111
# standard, there are indexing issues. Temporary solution: always call *_on_off variant
112-
if haskey(_PM.ref(pm, nw, :damaged_branch), i)
112+
if haskey(_PM.ref(pm, nw, :branch_damage), i)
113113
vad_min = _PM.ref(pm, nw, :off_angmin)
114114
vad_max = _PM.ref(pm, nw, :off_angmax)
115115
_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)
@@ -139,7 +139,7 @@ function constraint_ohms_yt_to_damage(pm::_PM.AbstractPowerModel, i::Int; nw::In
139139
# TODO make indexing of :wi,:wr standardized
140140
## Because :wi, :wr are indexed by bus_id or bus_pairs depending on if the value is on_off or
141141
# standard, there are indexing issues. Temporary solution: always call *_on_off variant
142-
if haskey(_PM.ref(pm, nw, :damaged_branch), i)
142+
if haskey(_PM.ref(pm, nw, :branch_damage), i)
143143
vad_min = _PM.ref(pm, nw, :off_angmin)
144144
vad_max = _PM.ref(pm, nw, :off_angmax)
145145

@@ -161,7 +161,7 @@ function constraint_voltage_angle_difference_damage(pm::_PM.AbstractPowerModel,
161161
# TODO make indexing of :wi,:wr standardized
162162
# Because :wi, :wr are indexed by bus_id or bus_pairs depending on if the value is on_off or
163163
# standard, there are indexing issues. Temporary solution: always call *_on_off variant
164-
if haskey(_PM.ref(pm, nw, :damaged_branch), i)
164+
if haskey(_PM.ref(pm, nw, :branch_damage), i)
165165

166166
vad_min = _PM.ref(pm, nw, :off_angmin)
167167
vad_max = _PM.ref(pm, nw, :off_angmax)
@@ -190,7 +190,7 @@ function constraint_thermal_limit_from_damage(pm::_PM.AbstractPowerModel, i::Int
190190
t_bus = branch["t_bus"]
191191
f_idx = (i, f_bus, t_bus)
192192

193-
if haskey(_PM.ref(pm, nw, :damaged_branch), i)
193+
if haskey(_PM.ref(pm, nw, :branch_damage), i)
194194
_PM.constraint_thermal_limit_from_on_off(pm, nw, i, f_idx, branch["rate_a"])
195195
else
196196
if !haskey(_PM.con(pm, nw), :sm_fr)
@@ -208,7 +208,7 @@ function constraint_thermal_limit_to_damage(pm::_PM.AbstractPowerModel, i::Int;
208208
t_bus = branch["t_bus"]
209209
t_idx = (i, t_bus, f_bus)
210210

211-
if haskey(_PM.ref(pm, nw, :damaged_branch), i)
211+
if haskey(_PM.ref(pm, nw, :branch_damage), i)
212212
_PM.constraint_thermal_limit_to_on_off(pm, nw, i, t_idx, branch["rate_a"])
213213
else
214214
if !haskey(_PM.con(pm, nw), :sm_to)
@@ -223,8 +223,8 @@ end
223223
function constraint_storage_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw)
224224
storage = _PM.ref(pm, nw, :storage, i)
225225

226-
storage_damaged = haskey(_PM.ref(pm, nw, :damaged_storage), i)
227-
bus_damaged = haskey(_PM.ref(pm, nw, :damaged_bus), storage["storage_bus"])
226+
storage_damaged = haskey(_PM.ref(pm, nw, :storage_damage), i)
227+
bus_damaged = haskey(_PM.ref(pm, nw, :bus_damage), storage["storage_bus"])
228228

229229

230230
if storage_damaged
@@ -248,18 +248,18 @@ function constraint_storage_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=p
248248
end
249249

250250
""
251-
function constraint_bus_voltage_violation_damage(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw)
251+
function constraint_bus_damage_soft(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw)
252252
bus = _PM.ref(pm, nw, :bus, i)
253253

254-
constraint_bus_voltage_violation_damage(pm, nw, i, bus["vmin"], bus["vmax"])
254+
constraint_bus_damage_soft(pm, nw, i, bus["vmin"], bus["vmax"])
255255
end
256256

257257

258258
""
259-
function constraint_bus_voltage_violation(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw)
259+
function constraint_voltage_magnitude_bounds_soft(pm::_PM.AbstractPowerModel, i::Int; nw::Int=pm.cnw)
260260
bus = _PM.ref(pm, nw, :bus, i)
261261

262-
constraint_bus_voltage_violation(pm, nw, i, bus["vmin"], bus["vmax"])
262+
constraint_voltage_magnitude_bounds_soft(pm, nw, i, bus["vmin"], bus["vmax"])
263263
end
264264

265265

src/core/ref.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ function ref_add_damaged_gens!(ref::Dict{Symbol,<:Any}, data::Dict{String,<:Any}
1818
damaged_gen[i]=gen
1919
end
2020
end
21-
nw_ref[:damaged_gen] = damaged_gen
21+
nw_ref[:gen_damage] = damaged_gen
2222
end
23-
#_PM.ref(pm,:damaged_gen)
2423
end
2524

2625
""
@@ -32,7 +31,7 @@ function ref_add_damaged_buses!(ref::Dict{Symbol,<:Any}, data::Dict{String,<:Any
3231
damaged_bus[i]=bus
3332
end
3433
end
35-
nw_ref[:damaged_bus] = damaged_bus
34+
nw_ref[:bus_damage] = damaged_bus
3635
end
3736
end
3837

@@ -46,7 +45,7 @@ function ref_add_damaged_branches!(ref::Dict{Symbol,<:Any}, data::Dict{String,<:
4645
damaged_branch[i]=branch
4746
end
4847
end
49-
nw_ref[:damaged_branch] = damaged_branch
48+
nw_ref[:branch_damage] = damaged_branch
5049
end
5150
end
5251

@@ -60,6 +59,6 @@ function ref_add_damaged_storage!(ref::Dict{Symbol,<:Any}, data::Dict{String,<:A
6059
damaged_storage[i]=storage
6160
end
6261
end
63-
nw_ref[:damaged_storage] = damaged_storage
62+
nw_ref[:storage_damage] = damaged_storage
6463
end
6564
end

0 commit comments

Comments
 (0)