-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding debuging models with power balance slack variables (#55)
- Loading branch information
Showing
13 changed files
with
396 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"a quadratic penalty for bus power slack variables" | ||
function objective_min_bus_power_slack(pm::GenericPowerModel) | ||
return @objective(pm.model, Min, | ||
sum( | ||
sum( | ||
sum( var(pm, n, c, :p_slack, i)^2 + var(pm, n, c, :q_slack, i)^2 for (i,bus) in nw_ref[:bus]) | ||
for c in conductor_ids(pm, n)) | ||
for (n, nw_ref) in nws(pm)) | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# These problem formulations are used to debug Three Phase datasets | ||
# that do not converge using the standard formulations | ||
|
||
export run_tp_opf_pbs, run_tp_pf_pbs | ||
|
||
"" | ||
function run_tp_opf_pbs(data::Dict{String,Any}, model_constructor, solver; kwargs...) | ||
return PMs.run_generic_model(data, model_constructor, solver, post_tp_opf_pbs; multiconductor=true, solution_builder = get_pbs_solution, kwargs...) | ||
end | ||
|
||
|
||
"" | ||
function run_tp_opf_pbs(file::String, model_constructor, solver; kwargs...) | ||
data = ThreePhasePowerModels.parse_file(file) | ||
return PMs.run_generic_model(data, model_constructor, solver, post_tp_opf_pbs; multiconductor=true, solution_builder = get_pbs_solution, kwargs...) | ||
end | ||
|
||
|
||
"" | ||
function post_tp_opf_pbs(pm::GenericPowerModel) | ||
for c in PMs.conductor_ids(pm) | ||
variable_tp_voltage(pm, cnd=c) | ||
variable_bus_power_slack(pm, cnd=c) | ||
PMs.variable_generation(pm, cnd=c) | ||
PMs.variable_branch_flow(pm, cnd=c) | ||
PMs.variable_dcline_flow(pm, cnd=c) | ||
end | ||
|
||
for c in PMs.conductor_ids(pm) | ||
constraint_tp_voltage(pm, cnd=c) | ||
|
||
for i in ids(pm, :ref_buses) | ||
constraint_tp_theta_ref(pm, i, cnd=c) | ||
end | ||
|
||
for i in ids(pm, :bus) | ||
constraint_kcl_shunt_slack(pm, i, cnd=c) | ||
end | ||
|
||
for i in ids(pm, :branch) | ||
constraint_ohms_tp_yt_from(pm, i, cnd=c) | ||
constraint_ohms_tp_yt_to(pm, i, cnd=c) | ||
|
||
PMs.constraint_voltage_angle_difference(pm, i, cnd=c) | ||
|
||
PMs.constraint_thermal_limit_from(pm, i, cnd=c) | ||
PMs.constraint_thermal_limit_to(pm, i, cnd=c) | ||
end | ||
|
||
for i in ids(pm, :dcline) | ||
PMs.constraint_dcline(pm, i, cnd=c) | ||
end | ||
end | ||
|
||
objective_min_bus_power_slack(pm) | ||
end | ||
|
||
|
||
|
||
"" | ||
function run_tp_pf_pbs(data::Dict{String,Any}, model_constructor, solver; kwargs...) | ||
return PMs.run_generic_model(data, model_constructor, solver, post_tp_pf_pbs; multiconductor=true, solution_builder = get_pbs_solution, kwargs...) | ||
end | ||
|
||
|
||
"" | ||
function run_tp_pf_pbs(file::String, model_constructor, solver; kwargs...) | ||
data = ThreePhasePowerModels.parse_file(file) | ||
return PMs.run_generic_model(data, model_constructor, solver, post_tp_pf_pbs; multiconductor=true, solution_builder = get_pbs_solution, kwargs...) | ||
end | ||
|
||
"" | ||
function post_tp_pf_pbs(pm::GenericPowerModel) | ||
for c in PMs.conductor_ids(pm) | ||
variable_tp_voltage(pm, bounded=false, cnd=c) | ||
variable_bus_power_slack(pm, cnd=c) | ||
PMs.variable_generation(pm, bounded=false, cnd=c) | ||
PMs.variable_branch_flow(pm, bounded=false, cnd=c) | ||
PMs.variable_dcline_flow(pm, bounded=false, cnd=c) | ||
end | ||
|
||
for c in PMs.conductor_ids(pm) | ||
constraint_tp_voltage(pm, cnd=c) | ||
|
||
for (i,bus) in ref(pm, :ref_buses) | ||
@assert bus["bus_type"] == 3 | ||
constraint_tp_theta_ref(pm, i, cnd=c) | ||
PMs.constraint_voltage_magnitude_setpoint(pm, i, cnd=c) | ||
end | ||
|
||
for (i,bus) in ref(pm, :bus) | ||
constraint_kcl_shunt_slack(pm, i, cnd=c) | ||
|
||
# PV Bus Constraints | ||
if length(ref(pm, :bus_gens, i)) > 0 && !(i in ids(pm,:ref_buses)) | ||
# this assumes inactive generators are filtered out of bus_gens | ||
@assert bus["bus_type"] == 2 | ||
|
||
PMs.constraint_voltage_magnitude_setpoint(pm, i, cnd=c) | ||
for j in ref(pm, :bus_gens, i) | ||
PMs.constraint_active_gen_setpoint(pm, j, cnd=c) | ||
end | ||
end | ||
end | ||
|
||
for i in ids(pm, :branch) | ||
constraint_ohms_tp_yt_from(pm, i, cnd=c) | ||
constraint_ohms_tp_yt_to(pm, i, cnd=c) | ||
end | ||
|
||
for (i,dcline) in ref(pm, :dcline) | ||
PMs.constraint_active_dcline_setpoint(pm, i, cnd=c) | ||
|
||
f_bus = ref(pm, :bus)[dcline["f_bus"]] | ||
if f_bus["bus_type"] == 1 | ||
PMs.constraint_voltage_magnitude_setpoint(pm, f_bus["index"], cnd=c) | ||
end | ||
|
||
t_bus = ref(pm, :bus)[dcline["t_bus"]] | ||
if t_bus["bus_type"] == 1 | ||
PMs.constraint_voltage_magnitude_setpoint(pm, t_bus["index"], cnd=c) | ||
end | ||
end | ||
|
||
end | ||
|
||
objective_min_bus_power_slack(pm) | ||
end | ||
|
||
|
||
"" | ||
function get_pbs_solution(pm::GenericPowerModel, sol::Dict{String,Any}) | ||
PMs.add_bus_voltage_setpoint(sol, pm) | ||
PMs.add_generator_power_setpoint(sol, pm) | ||
PMs.add_branch_flow_setpoint(sol, pm) | ||
add_bus_slack_setpoint(sol, pm) | ||
end | ||
|
||
|
||
"" | ||
function add_bus_slack_setpoint(sol, pm::GenericPowerModel) | ||
PMs.add_setpoint(sol, pm, "bus", "p_slack", :p_slack) | ||
PMs.add_setpoint(sol, pm, "bus", "q_slack", :q_slack) | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
% 3 Coupled meshed networks with off diagonal terms in branch Y | ||
% tests that opf_pbs model converges on an otherwise infeasible model | ||
|
||
function tppmc = case5_c_m_b | ||
tppmc.version = '1' | ||
|
||
tppmc.baseMVA = 100.0; | ||
tppmc.baseKV = 230.0; | ||
|
||
%% bus data | ||
% bus_i type vmin_1 vmax_1 vmin_2 vmax_2 vmin_3 vmax_3 vm_1 va_1 vm_2 va_2 vm_3 va_3 | ||
tppmc.bus = [ | ||
1 2 0.90 1.10 0.90 1.10 0.90 1.10 1.00000 2.80377 1.00000 2.80377 1.00000 2.80377; | ||
2 1 0.90 1.10 0.90 1.10 0.90 1.10 1.08407 -0.73465 1.08407 -0.73465 1.08407 -0.73465; | ||
3 2 0.90 1.10 0.90 1.10 0.90 1.10 1.00000 -0.55972 1.00000 -0.55972 1.00000 -0.55972; | ||
4 1 0.90 1.10 0.90 1.10 0.90 1.10 1.00000 0.00000 1.00000 0.00000 1.00000 0.00000; | ||
10 3 0.90 1.10 0.90 1.10 0.90 1.10 1.00000 3.59033 1.00000 3.59033 1.00000 3.59033; | ||
]; | ||
|
||
%% load data | ||
% load_bus pd_1 qd_1 pd_2 qd_2 pd_3 qd_3 status | ||
tppmc.load = [ | ||
2 850.0 100.0 300.0 100.0 300.0 100.0 1; | ||
3 300.0 100.0 300.0 300.0 300.0 500.0 1; | ||
4 400.0 130.0 1150.0 130.0 400.0 130.0 1; | ||
]; | ||
|
||
%% shunt data | ||
% shunt_bus gs_1 bs_1 gs_2 bs_2 gs_3 bs_3 status | ||
tppmc.shunt = [ | ||
4 2.0 50.0 2.0 50.0 2.0 50.0 1; | ||
10 1.0 25.0 1.0 25.0 1.0 25.0 1; | ||
]; | ||
|
||
%% generator data | ||
% gen_bus pmin_1 pmax_1 qmin_1 qmax_1 pmin_2 pmax_2 qmin_2 qmax_2 pmin_3 pmax_3 qmin_3 qmax_3 pg_1 qg_1 pg_2 qg_2 pg_3 qg_3 status | ||
tppmc.gen = [ | ||
1 0.0 40.0 -30.0 30.0 0.0 40.0 -30.0 30.0 0.0 40.0 -30.0 30.0 40.0 30.0 40.0 30.0 40.0 30.0 1; | ||
1 0.0 170.0 -127.5 127.5 0.0 170.0 -127.5 127.5 0.0 170.0 -127.5 127.5 170.0 127.5 170.0 127.5 170.0 127.5 1; | ||
3 0.0 520.0 -190.0 190.0 0.0 520.0 -190.0 190.0 0.0 520.0 -190.0 190.0 325.0 390.0 325.0 390.0 325.0 390.0 1; | ||
10 0.0 600.0 -450.0 450.0 0.0 600.0 -450.0 450.0 0.0 600.0 -450.0 450.0 470.0 -165.0 470.0 -165.0 470.0 -165.0 1; | ||
]; | ||
|
||
%% generator cost data | ||
% 2 startup shutdown n c(n-1) ... c0 | ||
tppmc.gencost = [ | ||
2 0.0 0.0 3 0.0 14.0 0.0; | ||
2 0.0 0.0 3 0.0 15.0 0.0; | ||
2 0.0 0.0 3 0.0 30.0 0.0; | ||
2 0.0 0.0 3 0.0 10.0 0.0; | ||
]; | ||
|
||
%% branch data | ||
% f_bus t_bus r_11 x_11 r_12 x_12 r_13 x_13 r_22 x_22 r_23 x_23 r_33 x_33 b_1 b_2 b_3 rate_a rate_b rate_c angmin angmax status | ||
tppmc.branch = [ | ||
1 2 0.00281 0.0281 0.0001 0.0002 0.0001 0.0002 0.00581 0.0281 0.0001 0.0002 0.00281 0.0281 0.0 0.0 0.0 400 400 400 -30.0 30.0 1; | ||
1 4 0.00304 0.0304 0.0001 0.0002 0.0001 0.0002 0.01004 0.0304 0.0001 0.0002 0.00304 0.0304 0.0 0.0 0.0 426 426 426 -30.0 30.0 1; | ||
1 10 0.00064 0.0064 0.0001 0.0002 0.0001 0.0002 0.00164 0.0064 0.0001 0.0002 0.00064 0.0064 0.0 0.0 0.0 426 426 426 -30.0 30.0 1; | ||
2 3 0.00108 0.0108 0.0001 0.0002 0.0001 0.0002 0.00208 0.0108 0.0001 0.0002 0.00108 0.0108 0.0 0.0 0.0 426 426 426 -30.0 30.0 1; | ||
4 3 0.00297 0.0297 0.0001 0.0002 0.0001 0.0002 0.00597 0.0297 0.0001 0.0002 0.00297 0.0297 0.0 0.0 0.0 426 426 426 -30.0 30.0 1; | ||
4 10 0.00297 0.0297 0.0001 0.0002 0.0001 0.0002 0.00497 0.0297 0.0001 0.0002 0.00297 0.0297 0.0 0.0 0.0 240 240 240 -30.0 30.0 1; | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.