Skip to content

Commit 3334ffb

Browse files
committed
fix support for data without an explicit switch section
1 parent 5d05175 commit 3334ffb

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ PowerModels.jl Change Log
22
=========================
33

44
### Staged
5+
- Fixed support for data without an explicit switch section
56
- Fixed support for single values in add_setpoint! and add_dual!
67

78
### v0.12.3

src/core/base.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ end
324324
function _ref_add_core!(nw_refs::Dict)
325325
for (nw, ref) in nw_refs
326326

327+
if !haskey(ref, :switch)
328+
ref[:switch] = Dict{Int,Any}()
329+
end
330+
327331
### filter out inactive components ###
328332
ref[:bus] = Dict(x for x in ref[:bus] if (x.second["bus_type"] != pm_component_status_inactive["bus"]))
329333
ref[:load] = Dict(x for x in ref[:load] if (x.second["status"] != pm_component_status_inactive["load"] && x.second["load_bus"] in keys(ref[:bus])))

src/core/data.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,13 +1288,15 @@ function check_connectivity(data::Dict{String,<:Any})
12881288
end
12891289
end
12901290

1291-
for (i, switch) in data["switch"]
1292-
if !(switch["f_bus"] in bus_ids)
1293-
Memento.error(_LOGGER, "from bus $(switch["f_bus"]) in switch $(i) is not defined")
1294-
end
1291+
if haskey(data, "switch")
1292+
for (i, switch) in data["switch"]
1293+
if !(switch["f_bus"] in bus_ids)
1294+
Memento.error(_LOGGER, "from bus $(switch["f_bus"]) in switch $(i) is not defined")
1295+
end
12951296

1296-
if !(switch["t_bus"] in bus_ids)
1297-
Memento.error(_LOGGER, "to bus $(switch["t_bus"]) in switch $(i) is not defined")
1297+
if !(switch["t_bus"] in bus_ids)
1298+
Memento.error(_LOGGER, "to bus $(switch["t_bus"]) in switch $(i) is not defined")
1299+
end
12981300
end
12991301
end
13001302

src/core/solution.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,17 @@ end
139139

140140
""
141141
function add_setpoint_switch_flow!(sol, pm::GenericPowerModel)
142-
add_setpoint!(sol, pm, "switch", "psw", :psw, var_key = (idx,item) -> (idx, item["f_bus"], item["t_bus"]))
143-
add_setpoint!(sol, pm, "switch", "qsw", :qsw, var_key = (idx,item) -> (idx, item["f_bus"], item["t_bus"]))
142+
if haskey(pm.data, "swtich")
143+
add_setpoint!(sol, pm, "switch", "psw", :psw, var_key = (idx,item) -> (idx, item["f_bus"], item["t_bus"]))
144+
add_setpoint!(sol, pm, "switch", "qsw", :qsw, var_key = (idx,item) -> (idx, item["f_bus"], item["t_bus"]))
145+
end
144146
end
145147

146148
""
147149
function add_setpoint_switch_status!(sol, pm::GenericPowerModel)
148-
add_setpoint!(sol, pm, "switch", "status", :z_switch, conductorless=true, default_value = (item) -> item["status"]*1.0)
150+
if haskey(pm.data, "swtich")
151+
add_setpoint!(sol, pm, "switch", "status", :z_switch, conductorless=true, default_value = (item) -> item["status"]*1.0)
152+
end
149153
end
150154

151155

src/form/apo.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ end
155155

156156
""
157157
function add_setpoint_switch_flow!(sol, pm::GenericPowerModel{T}) where T <: AbstractActivePowerFormulation
158-
add_setpoint!(sol, pm, "switch", "psw", :psw, var_key = (idx,item) -> (idx, item["f_bus"], item["t_bus"]))
159-
add_setpoint_fixed!(sol, pm, "switch", "qsw")
158+
if haskey(pm.data, "swtich")
159+
add_setpoint!(sol, pm, "switch", "psw", :psw, var_key = (idx,item) -> (idx, item["f_bus"], item["t_bus"]))
160+
add_setpoint_fixed!(sol, pm, "switch", "qsw")
161+
end
160162
end
161163

0 commit comments

Comments
 (0)