From e9072e3bc5155f8fef4109a54db55ef7774ec05e Mon Sep 17 00:00:00 2001 From: ccoffrin Date: Tue, 4 Feb 2020 11:36:03 -0700 Subject: [PATCH] fix bug in add_setpoint --- CHANGELOG.md | 3 +++ Project.toml | 2 +- src/core/solution.jl | 19 +++++++++++++++---- test/output.jl | 9 +++++++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32feb6819..3b62286cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Project.toml b/Project.toml index a3da2bde9..24be62231 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/core/solution.jl b/src/core/solution.jl index 0462235f1..9035c314a 100644 --- a/src/core/solution.jl +++ b/src/core/solution.jl @@ -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!( @@ -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)) @@ -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 diff --git a/test/output.jl b/test/output.jl index 8b40d8556..bab46bcd1 100644 --- a/test/output.jl +++ b/test/output.jl @@ -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