Skip to content

Commit a74d0a5

Browse files
authored
Minor fixes to solution building (#675)
* solution building bug fixes * prep for release v0.15.2
1 parent fd8ebf1 commit a74d0a5

File tree

6 files changed

+70
-3
lines changed

6 files changed

+70
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ PowerModels.jl Change Log
44
### Staged
55
- nothing
66

7+
### v0.15.2
8+
- Add support for on/off storage in SOCWRPowerModel
9+
- Fixed multinetwork solution building bug
10+
- Fixed solution building bug in variable_demand_factor
11+
712
### v0.15.1
813
- Add support for JuMP v0.21
914

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "PowerModels"
22
uuid = "c36e90e8-916a-50a6-bd94-075b64ef4655"
33
authors = ["Carleton Coffrin"]
44
repo = "https://github.com/lanl-ansi/PowerModels.jl"
5-
version = "0.15.1"
5+
version = "0.15.2"
66

77
[deps]
88
InfrastructureModels = "2030c09a-7f63-5d83-885d-db604e0e9cc0"

src/core/solution.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ function build_solution(pm::AbstractPowerModel; post_processors=[])
9393
end
9494
end
9595

96-
if !ismultinetwork(pm)
96+
if ismultinetwork(pm)
97+
sol["multinetwork"] = true
98+
else
9799
for (k,v) in sol["nw"]["$(pm.cnw)"]
98100
sol[k] = v
99101
end

src/core/variable.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ end
10731073
function variable_storage_mi_on_off(pm::AbstractPowerModel; kwargs...)
10741074
variable_active_storage_on_off(pm; kwargs...)
10751075
variable_reactive_storage_on_off(pm; kwargs...)
1076+
variable_current_storage(pm; kwargs...)
10761077
variable_storage_energy(pm; kwargs...)
10771078
variable_storage_charge(pm; kwargs...)
10781079
variable_storage_discharge(pm; kwargs...)
@@ -1251,7 +1252,7 @@ function variable_demand_factor(pm::AbstractPowerModel; nw::Int=pm.cnw, relax::B
12511252
sol_component_value(pm, nw, :load, :status, ids(pm, nw, :load), z_demand)
12521253
sol_pd = Dict(i => z_demand[i]*ref(pm, nw, :load, i)["pd"] for i in ids(pm, nw, :load))
12531254
sol_component_value(pm, nw, :load, :pd, ids(pm, nw, :load), sol_pd)
1254-
sol_qd = Dict(i => z_demand[i]*ref(pm, nw, :load, i)["pd"] for i in ids(pm, nw, :load))
1255+
sol_qd = Dict(i => z_demand[i]*ref(pm, nw, :load, i)["qd"] for i in ids(pm, nw, :load))
12551256
sol_component_value(pm, nw, :load, :qd, ids(pm, nw, :load), sol_qd)
12561257
end
12571258
end

test/multinetwork.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ TESTLOG = Memento.getlogger(PowerModels)
108108
end
109109
end
110110

111+
112+
@testset "test multi-network solution" begin
113+
# test case where generator status is 1 but the gen_bus status is 0
114+
mn_data = build_mn_data("../test/data/matpower/case5.m")
115+
result = PowerModels.run_mn_opf(mn_data, ACPPowerModel, ipopt_solver)
116+
117+
@test result["termination_status"] == LOCALLY_SOLVED
118+
@test isapprox(result["objective"], 36538.2; atol = 1e0)
119+
120+
@test InfrastructureModels.ismultinetwork(mn_data) == InfrastructureModels.ismultinetwork(result["solution"])
121+
end
122+
123+
111124
@testset "2 period 5-bus asymmetric case" begin
112125
mn_data = build_mn_data("../test/data/matpower/case5_asym.m")
113126

test/opf-var.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ end
162162
@test isapprox(active_power_served(result), 10.0; atol = 1e-2)
163163
@test all_loads_on(result)
164164
@test all_shunts_on(result)
165+
165166
end
166167
@testset "14-bus current" begin
167168
result = PowerModels._run_mld("../test/data/matpower/case14.m", ACPPowerModel, ipopt_solver)
@@ -171,6 +172,12 @@ end
171172
@test isapprox(active_power_served(result), 2.59; atol = 1e-2)
172173
@test all_loads_on(result)
173174
@test all_shunts_on(result)
175+
176+
@test isapprox(sum(load["pd"] for (i,load) in result["solution"]["load"]), 2.5900; atol = 1e-4)
177+
@test isapprox(sum(load["qd"] for (i,load) in result["solution"]["load"]), 0.7349; atol = 1e-4)
178+
179+
@test isapprox(sum(shunt["bs"] for (i,shunt) in result["solution"]["shunt"]), 0.19; atol = 1e-4)
180+
@test isapprox(sum(shunt["gs"] for (i,shunt) in result["solution"]["shunt"]), 0.00; atol = 1e-4)
174181
end
175182
end
176183

@@ -336,6 +343,16 @@ end
336343
end
337344
end
338345

346+
@testset "test soc opf" begin
347+
@testset "5-bus uc case" begin
348+
result = PowerModels._run_ucopf("../test/data/matpower/case5_uc.m", SOCWRPowerModel, juniper_solver)
349+
350+
@test result["termination_status"] == LOCALLY_SOLVED
351+
@test isapprox(result["objective"], 15057.09; atol = 1e0)
352+
@test isapprox(result["solution"]["gen"]["4"]["gen_status"], 0.0, atol=1e-6)
353+
end
354+
end
355+
339356
@testset "test dc opf" begin
340357
@testset "5-bus uc case" begin
341358
result = PowerModels._run_ucopf("../test/data/matpower/case5_uc.m", DCPPowerModel, cbc_solver)
@@ -346,17 +363,46 @@ end
346363
end
347364
end
348365

366+
349367
@testset "test ac opf" begin
350368
@testset "5-bus uc storage case" begin
351369
result = PowerModels._run_ucopf("../test/data/matpower/case5_uc_strg.m", ACPPowerModel, juniper_solver)
352370

353371
@test result["termination_status"] == LOCALLY_SOLVED
354372
@test isapprox(result["objective"], 17740.9; atol = 1e0)
373+
374+
@test isapprox(result["solution"]["gen"]["4"]["gen_status"], 0.0, atol=1e-6)
355375
@test isapprox(result["solution"]["storage"]["1"]["status"], 1.0, atol=1e-6)
356376
@test isapprox(result["solution"]["storage"]["2"]["status"], 0.0, atol=1e-6)
357377
end
358378
end
359379

380+
@testset "test soc opf" begin
381+
@testset "5-bus uc storage case" begin
382+
result = PowerModels._run_ucopf("../test/data/matpower/case5_uc_strg.m", SOCWRPowerModel, juniper_solver)
383+
384+
@test result["termination_status"] == LOCALLY_SOLVED
385+
@test isapprox(result["objective"], 14525.0; atol = 1e0)
386+
387+
@test isapprox(result["solution"]["gen"]["4"]["gen_status"], 0.0, atol=1e-6)
388+
@test isapprox(result["solution"]["storage"]["1"]["status"], 1.0, atol=1e-6)
389+
@test isapprox(result["solution"]["storage"]["2"]["status"], 0.0, atol=1e-6)
390+
end
391+
end
392+
393+
@testset "test dc opf" begin
394+
@testset "5-bus uc storage case" begin
395+
result = PowerModels._run_ucopf("../test/data/matpower/case5_uc_strg.m", DCPPowerModel, cbc_solver)
396+
397+
@test result["termination_status"] == OPTIMAL
398+
@test isapprox(result["objective"], 16833.2; atol = 1e0)
399+
400+
@test isapprox(result["solution"]["gen"]["4"]["gen_status"], 0.0, atol=1e-6)
401+
@test isapprox(result["solution"]["storage"]["1"]["status"], 1.0, atol=1e-6)
402+
@test isapprox(result["solution"]["storage"]["2"]["status"], 1.0, atol=1e-6)
403+
end
404+
end
405+
360406
end
361407

362408

0 commit comments

Comments
 (0)