Skip to content

Commit

Permalink
Minor fixes to solution building (#675)
Browse files Browse the repository at this point in the history
* solution building bug fixes
* prep for release v0.15.2
  • Loading branch information
ccoffrin authored Feb 21, 2020
1 parent fd8ebf1 commit a74d0a5
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ PowerModels.jl Change Log
### Staged
- nothing

### v0.15.2
- Add support for on/off storage in SOCWRPowerModel
- Fixed multinetwork solution building bug
- Fixed solution building bug in variable_demand_factor

### v0.15.1
- Add support for JuMP v0.21

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.15.1"
version = "0.15.2"

[deps]
InfrastructureModels = "2030c09a-7f63-5d83-885d-db604e0e9cc0"
Expand Down
4 changes: 3 additions & 1 deletion src/core/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ function build_solution(pm::AbstractPowerModel; post_processors=[])
end
end

if !ismultinetwork(pm)
if ismultinetwork(pm)
sol["multinetwork"] = true
else
for (k,v) in sol["nw"]["$(pm.cnw)"]
sol[k] = v
end
Expand Down
3 changes: 2 additions & 1 deletion src/core/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ end
function variable_storage_mi_on_off(pm::AbstractPowerModel; kwargs...)
variable_active_storage_on_off(pm; kwargs...)
variable_reactive_storage_on_off(pm; kwargs...)
variable_current_storage(pm; kwargs...)
variable_storage_energy(pm; kwargs...)
variable_storage_charge(pm; kwargs...)
variable_storage_discharge(pm; kwargs...)
Expand Down Expand Up @@ -1251,7 +1252,7 @@ function variable_demand_factor(pm::AbstractPowerModel; nw::Int=pm.cnw, relax::B
sol_component_value(pm, nw, :load, :status, ids(pm, nw, :load), z_demand)
sol_pd = Dict(i => z_demand[i]*ref(pm, nw, :load, i)["pd"] for i in ids(pm, nw, :load))
sol_component_value(pm, nw, :load, :pd, ids(pm, nw, :load), sol_pd)
sol_qd = Dict(i => z_demand[i]*ref(pm, nw, :load, i)["pd"] for i in ids(pm, nw, :load))
sol_qd = Dict(i => z_demand[i]*ref(pm, nw, :load, i)["qd"] for i in ids(pm, nw, :load))
sol_component_value(pm, nw, :load, :qd, ids(pm, nw, :load), sol_qd)
end
end
Expand Down
13 changes: 13 additions & 0 deletions test/multinetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ TESTLOG = Memento.getlogger(PowerModels)
end
end


@testset "test multi-network solution" begin
# test case where generator status is 1 but the gen_bus status is 0
mn_data = build_mn_data("../test/data/matpower/case5.m")
result = PowerModels.run_mn_opf(mn_data, ACPPowerModel, ipopt_solver)

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

@test InfrastructureModels.ismultinetwork(mn_data) == InfrastructureModels.ismultinetwork(result["solution"])
end


@testset "2 period 5-bus asymmetric case" begin
mn_data = build_mn_data("../test/data/matpower/case5_asym.m")

Expand Down
46 changes: 46 additions & 0 deletions test/opf-var.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ end
@test isapprox(active_power_served(result), 10.0; atol = 1e-2)
@test all_loads_on(result)
@test all_shunts_on(result)

end
@testset "14-bus current" begin
result = PowerModels._run_mld("../test/data/matpower/case14.m", ACPPowerModel, ipopt_solver)
Expand All @@ -171,6 +172,12 @@ end
@test isapprox(active_power_served(result), 2.59; atol = 1e-2)
@test all_loads_on(result)
@test all_shunts_on(result)

@test isapprox(sum(load["pd"] for (i,load) in result["solution"]["load"]), 2.5900; atol = 1e-4)
@test isapprox(sum(load["qd"] for (i,load) in result["solution"]["load"]), 0.7349; atol = 1e-4)

@test isapprox(sum(shunt["bs"] for (i,shunt) in result["solution"]["shunt"]), 0.19; atol = 1e-4)
@test isapprox(sum(shunt["gs"] for (i,shunt) in result["solution"]["shunt"]), 0.00; atol = 1e-4)
end
end

Expand Down Expand Up @@ -336,6 +343,16 @@ end
end
end

@testset "test soc opf" begin
@testset "5-bus uc case" begin
result = PowerModels._run_ucopf("../test/data/matpower/case5_uc.m", SOCWRPowerModel, juniper_solver)

@test result["termination_status"] == LOCALLY_SOLVED
@test isapprox(result["objective"], 15057.09; atol = 1e0)
@test isapprox(result["solution"]["gen"]["4"]["gen_status"], 0.0, atol=1e-6)
end
end

@testset "test dc opf" begin
@testset "5-bus uc case" begin
result = PowerModels._run_ucopf("../test/data/matpower/case5_uc.m", DCPPowerModel, cbc_solver)
Expand All @@ -346,17 +363,46 @@ end
end
end


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

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

@test isapprox(result["solution"]["gen"]["4"]["gen_status"], 0.0, atol=1e-6)
@test isapprox(result["solution"]["storage"]["1"]["status"], 1.0, atol=1e-6)
@test isapprox(result["solution"]["storage"]["2"]["status"], 0.0, atol=1e-6)
end
end

@testset "test soc opf" begin
@testset "5-bus uc storage case" begin
result = PowerModels._run_ucopf("../test/data/matpower/case5_uc_strg.m", SOCWRPowerModel, juniper_solver)

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

@test isapprox(result["solution"]["gen"]["4"]["gen_status"], 0.0, atol=1e-6)
@test isapprox(result["solution"]["storage"]["1"]["status"], 1.0, atol=1e-6)
@test isapprox(result["solution"]["storage"]["2"]["status"], 0.0, atol=1e-6)
end
end

@testset "test dc opf" begin
@testset "5-bus uc storage case" begin
result = PowerModels._run_ucopf("../test/data/matpower/case5_uc_strg.m", DCPPowerModel, cbc_solver)

@test result["termination_status"] == OPTIMAL
@test isapprox(result["objective"], 16833.2; atol = 1e0)

@test isapprox(result["solution"]["gen"]["4"]["gen_status"], 0.0, atol=1e-6)
@test isapprox(result["solution"]["storage"]["1"]["status"], 1.0, atol=1e-6)
@test isapprox(result["solution"]["storage"]["2"]["status"], 1.0, atol=1e-6)
end
end

end


Expand Down

0 comments on commit a74d0a5

Please sign in to comment.