Skip to content

Commit bfe08dd

Browse files
frederikgethccoffrin
authored andcommitted
Remove unused functions in solution.jl (#638)
* clean up dead-code functions from v0.12 solution update. removes - get_solution - add_generator_power_setpoint - add_storage_setpoint - add_branch_flow_setpoint - add_dcline_flow_setpoint - add_generator_power_setpoint - add_storage_setpoint
1 parent 4090bc2 commit bfe08dd

File tree

4 files changed

+50
-76
lines changed

4 files changed

+50
-76
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PowerModels.jl Change Log
22
=========================
33

44
### Staged
5-
- nothing
5+
- Removal of unused functions in `solution.jl`: `get_solution`, `add_generator_power_setpoint`, `add_storage_setpoint`, `add_branch_flow_setpoint`, `add_dcline_flow_setpoint` (breaking) (#637)
66

77
### v0.13.1
88
- Added DCMPPowerModel for replication of Matpower's DC model (#612)

src/core/solution.jl

-58
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,6 @@ function _init_solution(pm::AbstractPowerModel)
5959
return Dict{String,Any}(key => pm.data[key] for key in data_keys)
6060
end
6161

62-
""
63-
function get_solution(pm::AbstractPowerModel, sol::Dict{String,<:Any})
64-
add_bus_voltage_setpoint(sol, pm)
65-
add_generator_power_setpoint(sol, pm)
66-
add_storage_setpoint(sol, pm)
67-
add_branch_flow_setpoint(sol, pm)
68-
add_dcline_flow_setpoint(sol, pm)
69-
70-
add_kcl_duals(sol, pm)
71-
add_sm_duals(sol, pm) # Adds the duals of the transmission lines' thermal limits.
72-
end
73-
74-
""
75-
function add_bus_voltage_setpoint(sol, pm::AbstractPowerModel)
76-
add_setpoint(sol, pm, "bus", "vm", :vm)
77-
add_setpoint(sol, pm, "bus", "va", :va)
78-
end
79-
8062
""
8163
function solution_opf!(pm::AbstractPowerModel, sol::Dict{String,<:Any})
8264
add_setpoint_bus_voltage!(sol, pm)
@@ -112,46 +94,6 @@ function add_dual_sm!(sol, pm::AbstractPowerModel)
11294
end
11395
end
11496

115-
""
116-
function add_generator_power_setpoint(sol, pm::AbstractPowerModel)
117-
add_setpoint(sol, pm, "gen", "pg", :pg)
118-
add_setpoint(sol, pm, "gen", "qg", :qg)
119-
end
120-
121-
""
122-
function add_generator_status_setpoint(sol, pm::AbstractPowerModel)
123-
add_setpoint(sol, pm, "gen", "gen_status", :z_gen; conductorless=true, default_value = (item) -> item["gen_status"]*1.0)
124-
end
125-
126-
""
127-
function add_storage_setpoint(sol, pm::AbstractPowerModel)
128-
add_setpoint(sol, pm, "storage", "ps", :ps)
129-
add_setpoint(sol, pm, "storage", "qs", :qs)
130-
add_setpoint(sol, pm, "storage", "se", :se, conductorless=true)
131-
# useful for model debugging
132-
#add_setpoint(sol, pm, "storage", "sc", :sc, conductorless=true)
133-
#add_setpoint(sol, pm, "storage", "sd", :sd, conductorless=true)
134-
end
135-
136-
""
137-
function add_branch_flow_setpoint(sol, pm::AbstractPowerModel)
138-
# check the branch flows were requested
139-
if haskey(pm.setting, "output") && haskey(pm.setting["output"], "branch_flows") && pm.setting["output"]["branch_flows"] == true
140-
add_setpoint(sol, pm, "branch", "pf", :p; extract_var = (var,idx,item) -> var[(idx, item["f_bus"], item["t_bus"])])
141-
add_setpoint(sol, pm, "branch", "qf", :q; extract_var = (var,idx,item) -> var[(idx, item["f_bus"], item["t_bus"])])
142-
add_setpoint(sol, pm, "branch", "pt", :p; extract_var = (var,idx,item) -> var[(idx, item["t_bus"], item["f_bus"])])
143-
add_setpoint(sol, pm, "branch", "qt", :q; extract_var = (var,idx,item) -> var[(idx, item["t_bus"], item["f_bus"])])
144-
end
145-
end
146-
147-
""
148-
function add_dcline_flow_setpoint(sol, pm::AbstractPowerModel)
149-
add_setpoint(sol, pm, "dcline", "pf", :p_dc; extract_var = (var,idx,item) -> var[(idx, item["f_bus"], item["t_bus"])])
150-
add_setpoint(sol, pm, "dcline", "qf", :q_dc; extract_var = (var,idx,item) -> var[(idx, item["f_bus"], item["t_bus"])])
151-
add_setpoint(sol, pm, "dcline", "pt", :p_dc; extract_var = (var,idx,item) -> var[(idx, item["t_bus"], item["f_bus"])])
152-
add_setpoint(sol, pm, "dcline", "qt", :q_dc; extract_var = (var,idx,item) -> var[(idx, item["t_bus"], item["f_bus"])])
153-
end
154-
15597
""
15698
function add_setpoint_generator_power!(sol, pm::AbstractPowerModel)
15799
add_setpoint!(sol, pm, "gen", "pg", :pg, status_name=pm_component_status["gen"])

src/form/apo.jl

+1-16
Original file line numberDiff line numberDiff line change
@@ -185,27 +185,13 @@ function constraint_storage_loss(pm::AbstractActivePowerModel, n::Int, i, bus, c
185185
sc = var(pm, n, :sc, i)
186186
sd = var(pm, n, :sd, i)
187187

188-
JuMP.@constraint(pm.model,
188+
JuMP.@constraint(pm.model,
189189
sum(ps[c] for c in conductors) + (sd - sc)
190190
==
191191
p_loss + sum(r[c]*ps[c]^2 for c in conductors)
192192
)
193193
end
194194

195-
196-
""
197-
function add_generator_power_setpoint(sol, pm::AbstractActivePowerModel)
198-
add_setpoint(sol, pm, "gen", "pg", :pg)
199-
add_setpoint_fixed(sol, pm, "gen", "qg")
200-
end
201-
202-
""
203-
function add_storage_setpoint(sol, pm::AbstractActivePowerModel)
204-
add_setpoint(sol, pm, "storage", "ps", :ps)
205-
add_setpoint_fixed(sol, pm, "storage", "qs")
206-
add_setpoint(sol, pm, "storage", "se", :se, conductorless=true)
207-
end
208-
209195
function constraint_storage_on_off(pm::AbstractActivePowerModel, n::Int, c::Int, i, pmin, pmax, qmin, qmax, charge_ub, discharge_ub)
210196
z_storage = var(pm, n, :z_storage, i)
211197
ps = var(pm, n, c, :ps, i)
@@ -220,4 +206,3 @@ function add_setpoint_switch_flow!(sol, pm::AbstractActivePowerModel)
220206
add_setpoint!(sol, pm, "switch", "psw", :psw, var_key = (idx,item) -> (idx, item["f_bus"], item["t_bus"]))
221207
add_setpoint_fixed!(sol, pm, "switch", "qsw")
222208
end
223-

test/output.jl

+48-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,53 @@ end
6969
@test isnan(branches["3"]["qf"])
7070
@test isnan(branches["3"]["qt"])
7171
end
72+
73+
@testset "24-bus rts case ac pf" begin
74+
result = run_pf("../test/data/matpower/case24.m", ACPPowerModel, ipopt_solver; setting = Dict("output" => Dict("branch_flows" => true)))
75+
76+
@test haskey(result, "optimizer") == true
77+
@test haskey(result, "termination_status") == true
78+
@test haskey(result, "primal_status") == true
79+
@test haskey(result, "dual_status") == true
80+
@test haskey(result, "objective") == true
81+
@test haskey(result, "objective_lb") == true
82+
@test haskey(result, "solve_time") == true
83+
@test haskey(result, "machine") == true
84+
@test haskey(result, "data") == true
85+
@test haskey(result, "solution") == true
86+
@test haskey(result["solution"], "branch") == true
87+
88+
@test length(result["solution"]["bus"]) == 24
89+
@test length(result["solution"]["gen"]) == 33
90+
@test length(result["solution"]["branch"]) == 38
91+
92+
branches = result["solution"]["branch"]
93+
94+
@test isapprox(branches["2"]["pf"], 0.2001; atol = 1e-3)
95+
@test isapprox(branches["2"]["pt"], -0.1980; atol = 1e-3)
96+
@test isapprox(branches["2"]["qf"], 0.0055; atol = 1e-3)
97+
@test isapprox(branches["2"]["qt"], -0.0571; atol = 1e-3)
98+
end
99+
100+
# A DCPPowerModel test is important because it does have variables for the reverse side of the branchs
101+
@testset "3-bus case dc pf" begin
102+
result = run_pf("../test/data/matpower/case3.m", DCPPowerModel, ipopt_solver; setting = Dict("output" => Dict("branch_flows" => true)))
103+
104+
@test haskey(result, "solution") == true
105+
@test haskey(result["solution"], "branch") == true
106+
107+
@test length(result["solution"]["bus"]) == 3
108+
@test length(result["solution"]["gen"]) == 3
109+
@test length(result["solution"]["branch"]) == 3
110+
@test length(result["solution"]["dcline"]) == 1
111+
112+
branches = result["solution"]["branch"]
113+
114+
@test isapprox(branches["3"]["pf"], -0.101419; atol = 1e-3)
115+
@test isapprox(branches["3"]["pt"], 0.101419; atol = 1e-3)
116+
@test isnan(branches["3"]["qf"])
117+
@test isnan(branches["3"]["qt"])
118+
end
72119
end
73120

74121

@@ -143,7 +190,7 @@ end
143190
end
144191

145192

146-
# recomended by @lroald
193+
# recommended by @lroald
147194
@testset "test solution feedback" begin
148195

149196
function solution_feedback(case, ac_opf_obj)

0 commit comments

Comments
 (0)