Skip to content

Commit

Permalink
fix support for data without an explicit switch section
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoffrin committed Aug 17, 2019
1 parent 5d05175 commit 3334ffb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PowerModels.jl Change Log
=========================

### Staged
- Fixed support for data without an explicit switch section
- Fixed support for single values in add_setpoint! and add_dual!

### v0.12.3
Expand Down
4 changes: 4 additions & 0 deletions src/core/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ end
function _ref_add_core!(nw_refs::Dict)
for (nw, ref) in nw_refs

if !haskey(ref, :switch)
ref[:switch] = Dict{Int,Any}()
end

### filter out inactive components ###
ref[:bus] = Dict(x for x in ref[:bus] if (x.second["bus_type"] != pm_component_status_inactive["bus"]))
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])))
Expand Down
14 changes: 8 additions & 6 deletions src/core/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1288,13 +1288,15 @@ function check_connectivity(data::Dict{String,<:Any})
end
end

for (i, switch) in data["switch"]
if !(switch["f_bus"] in bus_ids)
Memento.error(_LOGGER, "from bus $(switch["f_bus"]) in switch $(i) is not defined")
end
if haskey(data, "switch")
for (i, switch) in data["switch"]
if !(switch["f_bus"] in bus_ids)
Memento.error(_LOGGER, "from bus $(switch["f_bus"]) in switch $(i) is not defined")
end

if !(switch["t_bus"] in bus_ids)
Memento.error(_LOGGER, "to bus $(switch["t_bus"]) in switch $(i) is not defined")
if !(switch["t_bus"] in bus_ids)
Memento.error(_LOGGER, "to bus $(switch["t_bus"]) in switch $(i) is not defined")
end
end
end

Expand Down
10 changes: 7 additions & 3 deletions src/core/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,17 @@ end

""
function add_setpoint_switch_flow!(sol, pm::GenericPowerModel)
add_setpoint!(sol, pm, "switch", "psw", :psw, var_key = (idx,item) -> (idx, item["f_bus"], item["t_bus"]))
add_setpoint!(sol, pm, "switch", "qsw", :qsw, var_key = (idx,item) -> (idx, item["f_bus"], item["t_bus"]))
if haskey(pm.data, "swtich")
add_setpoint!(sol, pm, "switch", "psw", :psw, var_key = (idx,item) -> (idx, item["f_bus"], item["t_bus"]))
add_setpoint!(sol, pm, "switch", "qsw", :qsw, var_key = (idx,item) -> (idx, item["f_bus"], item["t_bus"]))
end
end

""
function add_setpoint_switch_status!(sol, pm::GenericPowerModel)
add_setpoint!(sol, pm, "switch", "status", :z_switch, conductorless=true, default_value = (item) -> item["status"]*1.0)
if haskey(pm.data, "swtich")
add_setpoint!(sol, pm, "switch", "status", :z_switch, conductorless=true, default_value = (item) -> item["status"]*1.0)
end
end


Expand Down
6 changes: 4 additions & 2 deletions src/form/apo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ end

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

0 comments on commit 3334ffb

Please sign in to comment.