Skip to content

Commit

Permalink
Merge pull request #104 from ZhengLiu1119/develop
Browse files Browse the repository at this point in the history
add model and test for loading reduction
  • Loading branch information
ZhengLiu1119 committed Jan 18, 2023
2 parents b8cb4e4 + 25eced2 commit 4875844
Show file tree
Hide file tree
Showing 7 changed files with 1,197 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PandaModels"
uuid = "2dbab86a-7cbf-476f-9afe-75ffd3079e7c"
authors = ["e2nIEE"]
version = "0.7.1"
version = "0.7.2"

[deps]
Cbc = "9961bab8-2fa3-5c5a-9d89-47fab24efd76"
Expand Down
4 changes: 3 additions & 1 deletion src/PandaModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export run_powermodels_pf,
run_pandamodels_ploss,
run_pandamodels_vstab_test,
run_pandamodels_qflex_test,
run_pandamodels_ploss_test
run_pandamodels_ploss_test,
run_pandamodels_loading

include("input/pp_to_pm.jl")
include("input/tools.jl")
Expand All @@ -43,4 +44,5 @@ include("models/call_pandamodels.jl")
include("models/call_powermodels.jl")
include("models/run_pm_vstab_dev.jl")
include("models/run_pm_qflex_dev.jl")
include("models/loading.jl")
end
17 changes: 17 additions & 0 deletions src/models/call_pandamodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,20 @@ function run_pandamodels_ploss(json_path)
)
return result
end

function run_pandamodels_loading(json_path)
pm = load_pm_from_json(json_path)
active_powermodels_silence!(pm)
pm = check_powermodels_data!(pm)
model = get_model(pm["pm_model"])
solver = get_solver(pm)

result = _run_loading(
pm,
model,
solver,
setting = Dict("output" => Dict("branch_flows" => true)),
ext = extract_params!(pm),
)
return result
end
64 changes: 64 additions & 0 deletions src/models/loading.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
export _run_loading

"""
run optimization for loading reuduction
"""

function _run_loading(file, model_type::_PM.Type, optimizer; kwargs...)
return _PM.solve_model(file, model_type, optimizer, _build_loading; kwargs...)
end

"""
give a JuMP model with PowerModels network data structur and build opitmization model
"""

function _build_loading(pm::_PM.AbstractPowerModel)

_PM.variable_bus_voltage(pm)
_PM.variable_gen_power(pm)
_PM.variable_branch_power(pm)
_PM.variable_dcline_power(pm, bounded = false) # TODO: why false?

objective_loading(pm)

_PM.constraint_model_voltage(pm)

for i in _PM.ids(pm, :ref_buses)
_PM.constraint_theta_ref(pm, i)
end

for i in _PM.ids(pm, :bus)
_PM.constraint_power_balance(pm, i)
end

for (i, branch) in _PM.ref(pm, :branch)
_PM.constraint_ohms_yt_from(pm, i)
_PM.constraint_ohms_yt_to(pm, i)

_PM.constraint_thermal_limit_from(pm, i)
_PM.constraint_thermal_limit_to(pm, i)
end

for i in _PM.ids(pm, :dcline)
_PM.constraint_dcline_power_losses(pm, i)
end
end

function objective_loading(pm::_PM.AbstractPowerModel)

if haskey(pm.ext, :obj_factors)
if length(pm.ext[:obj_factors]) == 2
fac1 = pm.ext[:obj_factors]["fac_1"]
fac2 = pm.ext[:obj_factors]["fac_2"]
end
else
fac1 = 1.0
fac2 = 1-fac1
end

return JuMP.@objective(pm.model, Min,
fac1 * sum((var(pm, :p, (content["element_index"], content["f_bus"], content["t_bus"])))^2 +
(var(pm, :p, (content["element_index"], content["t_bus"], content["f_bus"])))^2 for (i, content) in pm.ext[:target_branch])
+
fac2 * sum((var(pm, :qg, content)-0)^2 for (i, content) in pm.ext[:gen_and_controllable_sgen]))
end
11 changes: 11 additions & 0 deletions test/call_pandamodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,15 @@
@test result["solve_time"] > 0.0
end


@testset "case_loading: cigre mv" begin
result = run_pandamodels_loading(case_loading)
pm = _PdM.load_pm_from_json(case_loading)
params = _PdM.extract_params!(pm)

@test string(result["termination_status"]) == "LOCALLY_SOLVED"
@test string(result["dual_status"]) == "FEASIBLE_POINT"
@test string(result["primal_status"]) == "FEASIBLE_POINT"
end

end
Loading

0 comments on commit 4875844

Please sign in to comment.