Skip to content

Commit

Permalink
fix bug in add_setpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoffrin committed Feb 4, 2020
1 parent a364b16 commit e9072e3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ PowerModels.jl Change Log
### Staged
- nothing

### v0.14.2
- Fixed solution reporting bug when component status did not match bus status

### v0.14.1
- Add support for constant power factor load and shunt decision variables
- Add basic support for OPF with OLTC and PST variables
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "PowerModels"
uuid = "c36e90e8-916a-50a6-bd94-075b64ef4655"
authors = ["Carleton Coffrin"]
repo = "https://github.com/lanl-ansi/PowerModels.jl"
version = "0.14.1"
version = "0.14.2"

[deps]
InfrastructureModels = "2030c09a-7f63-5d83-885d-db604e0e9cc0"
Expand Down
19 changes: 15 additions & 4 deletions src/core/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ function add_setpoint_dcline_status!(sol, pm::AbstractPowerModel)
add_setpoint!(sol, pm, "dcline", "br_status", :z_dcline, status_name=pm_component_status["dcline"], conductorless=true, default_value = (item) -> item["br_status"]*1.0)
end

function Base.haskey(cont::JuMP.Containers.DenseAxisArray, key)
return isassigned(cont,key)
end

"adds values based on JuMP variables"
function add_setpoint!(
Expand Down Expand Up @@ -259,15 +262,20 @@ function add_setpoint!(
if item[status_name] != inactive_status_value
var_id = var_key(idx, item)
variables = var(pm, pm.cnw, variable_symbol)
sol_item[param_name] = scale(JuMP.value(variables[var_id]), item, 1)
if haskey(variables, var_id)
v = JuMP.value(variables[var_id])
sol_item[param_name] = scale(v, item, 1)
end
end
elseif !mc
sol_item[param_name] = default_value(item)

if item[status_name] != inactive_status_value
var_id = var_key(idx, item)
variables = var(pm, variable_symbol)
sol_item[param_name] = scale(JuMP.value(variables[var_id]), item, 1)
if haskey(variables, var_id)
v = JuMP.value(variables[var_id])
sol_item[param_name] = scale(v, item, 1)
end
end
else
num_conductors = length(conductor_ids(pm))
Expand All @@ -278,7 +286,10 @@ function add_setpoint!(
for conductor in conductor_ids(pm)
var_id = var_key(idx, item)
variables = var(pm, variable_symbol, cnd=conductor)
sol_item[param_name][cnd_idx] = scale(JuMP.value(variables[var_id]), item, conductor)
if haskey(variables, var_id)
v = JuMP.value(variables[var_id])
sol_item[param_name][cnd_idx] = scale(v, item, conductor)
end
cnd_idx += 1
end
end
Expand Down
9 changes: 9 additions & 0 deletions test/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ end

end

@testset "test solution builder inconsistent status" begin
# test case where generator status is 1 but the gen_bus status is 0
data = parse_file("../test/data/matpower/case5.m")
data["bus"]["4"]["bus_type"] = 4
result = run_ac_opf(data, ipopt_solver)

@test result["termination_status"] == LOCALLY_SOLVED
@test isapprox(result["objective"], 10128.6; atol = 1e0)
end

# recommended by @lroald
@testset "test solution feedback" begin
Expand Down

0 comments on commit e9072e3

Please sign in to comment.