diff --git a/CHANGELOG.md b/CHANGELOG.md index 06b3f94b8..327a057fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ PowerModels.jl Change Log ### Staged - nothing +### v0.20.0 +- Add support for models with mixtures of PWL and polynomial cost functions (#829) +- Revised models to use two-sided constraints (#819) (breaking) +- Rewrite code for building objective functions (#778) (breaking) +- Made current limit modeling consistent with thermal limit modeling (#625) (breaking) +- Drop support for multiple conductors (#872) (breaking) +- Drop support for `run_*` functions (#878) (breaking) +- Drop support for JuMP v0.22 and v0.23 (breaking) +- Drop support for JSON v0.18, v0.19, v0.20 (breaking) + ### v0.19.10 - Add support for ACP and DCP formulation in OPF with PST variables (#543,#875) - Fix implementation of `calc_theta_delta_bounds` when conductor parameter is used (#870) @@ -33,6 +43,13 @@ PowerModels.jl Change Log - Add support for JuMP v1.0 - Update `correct_cost_functions!` to support PWL costs with a constant power value +### v0.20.0 +- Added conversion of impedance and current loads from PSSE raw files into constant power loads (#792) +- Made case name recovery optional in PTI parsing + +### Staged +- nothing + ### v0.19.4 - Fix `sol_component_value_edge` implementation and usage (#811) diff --git a/Project.toml b/Project.toml index 7affbdaf8..54c6df88c 100644 --- a/Project.toml +++ b/Project.toml @@ -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.19.10" +version = "0.20.0" [deps] InfrastructureModels = "2030c09a-7f63-5d83-885d-db604e0e9cc0" @@ -14,12 +14,12 @@ NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [compat] -HiGHS = "~0.3, ~1" +HiGHS = "~1" InfrastructureModels = "~0.6, ~0.7" -Ipopt = "~0.8, ~0.9, ~1" -JSON = "~0.18, ~0.19, ~0.20, ~0.21" -JuMP = "~0.22, ~0.23, 1" -Juniper = "~0.8, ~0.9" +Ipopt = "~1" +JSON = "~0.21" +JuMP = "1" +Juniper = "~0.9" Memento = "~1.0, ~1.1, ~1.2, ~1.3, ~1.4" NLsolve = "4.0" SCS = "~0.9, ~1.0, ~2.0" diff --git a/src/PowerModels.jl b/src/PowerModels.jl index 95d053c28..5dc13458d 100644 --- a/src/PowerModels.jl +++ b/src/PowerModels.jl @@ -85,115 +85,6 @@ include("prob/test.jl") include("util/obbt.jl") include("util/flow_limit_cuts.jl") - -# function deprecation warnings -# can be removed in a breaking release after 09/01/2022 -function run_model(args...; kwargs...) - @warn("the function run_model has been replaced with solve_model", maxlog=1) - solve_model(args...; kwargs...) -end - -function run_pf(args...; kwargs...) - @warn("the function run_pf has been replaced with solve_pf", maxlog=1) - solve_pf(args...; kwargs...) -end -function run_ac_pf(args...; kwargs...) - @warn("the function run_ac_pf has been replaced with solve_ac_pf", maxlog=1) - solve_ac_pf(args...; kwargs...) -end -function run_dc_pf(args...; kwargs...) - @warn("the function run_dc_pf has been replaced with solve_dc_pf", maxlog=1) - solve_dc_pf(args...; kwargs...) -end -function run_pf_bf(args...; kwargs...) - @warn("the function run_pf_bf has been replaced with solve_pf_bf", maxlog=1) - solve_pf_bf(args...; kwargs...) -end -function run_pf_iv(args...; kwargs...) - @warn("the function run_pf_iv has been replaced with solve_pf_iv", maxlog=1) - solve_pf_iv(args...; kwargs...) -end - - -function run_opf(args...; kwargs...) - @warn("the function run_opf has been replaced with solve_opf", maxlog=1) - solve_opf(args...; kwargs...) -end -function run_ac_opf(args...; kwargs...) - @warn("the function run_ac_opf has been replaced with solve_ac_opf", maxlog=1) - solve_ac_opf(args...; kwargs...) -end -function run_dc_opf(args...; kwargs...) - @warn("the function run_dc_opf has been replaced with solve_dc_opf", maxlog=1) - solve_dc_opf(args...; kwargs...) -end - -function run_mn_opf(args...; kwargs...) - @warn("the function run_mn_opf has been replaced with solve_mn_opf", maxlog=1) - solve_mn_opf(args...; kwargs...) -end -function run_mn_opf_strg(args...; kwargs...) - @warn("the function run_mn_opf_strg has been replaced with solve_mn_opf_strg", maxlog=1) - solve_mn_opf_strg(args...; kwargs...) -end -function run_opf_ptdf(args...; kwargs...) - @warn("the function run_opf_ptdf has been replaced with solve_opf_ptdf", maxlog=1) - solve_opf_ptdf(args...; kwargs...) -end - -function run_opf_bf(args...; kwargs...) - @warn("the function run_opf_bf has been replaced with solve_opf_bf", maxlog=1) - solve_opf_bf(args...; kwargs...) -end -function run_mn_opf_bf_strg(args...; kwargs...) - @warn("the function run_mn_opf_bf_strg has been replaced with solve_mn_opf_bf_strg", maxlog=1) - solve_mn_opf_bf_strg(args...; kwargs...) -end -function run_opf_iv(args...; kwargs...) - @warn("the function run_opf_iv has been replaced with solve_opf_iv", maxlog=1) - solve_opf_iv(args...; kwargs...) -end - -function run_opb(args...; kwargs...) - @warn("the function run_opb has been replaced with solve_opb", maxlog=1) - solve_opb(args...; kwargs...) -end -function run_nfa_opb(args...; kwargs...) - @warn("the function run_nfa_opb has been replaced with solve_nfa_opb", maxlog=1) - solve_nfa_opb(args...; kwargs...) -end - -function run_ots(args...; kwargs...) - @warn("the function run_ots has been replaced with solve_ots", maxlog=1) - solve_ots(args...; kwargs...) -end -function run_tnep(args...; kwargs...) - @warn("the function run_tnep has been replaced with solve_tnep", maxlog=1) - solve_tnep(args...; kwargs...) -end - -function run_opf_branch_power_cuts(args...; kwargs...) - @warn("the function run_opf_branch_power_cuts has been replaced with solve_opf_branch_power_cuts", maxlog=1) - solve_opf_branch_power_cuts(args...; kwargs...) -end -function run_opf_branch_power_cuts!(args...; kwargs...) - @warn("the function run_opf_branch_power_cuts! has been replaced with solve_opf_branch_power_cuts!", maxlog=1) - solve_opf_branch_power_cuts!(args...; kwargs...) -end -function run_opf_ptdf_branch_power_cuts(args...; kwargs...) - @warn("the function run_opf_ptdf_branch_power_cuts has been replaced with solve_opf_ptdf_branch_power_cuts", maxlog=1) - solve_opf_ptdf_branch_power_cuts(args...; kwargs...) -end -function run_opf_ptdf_branch_power_cuts!(args...; kwargs...) - @warn("the function run_opf_ptdf_branch_power_cuts! has been replaced with solve_opf_ptdf_branch_power_cuts!", maxlog=1) - solve_opf_ptdf_branch_power_cuts!(args...; kwargs...) -end -function run_obbt_opf!(args...; kwargs...) - @warn("the function run_obbt_opf! has been replaced with solve_obbt_opf!", maxlog=1) - solve_obbt_opf!(args...; kwargs...) -end - - # this must come last to support automated export include("core/export.jl") diff --git a/src/core/base.jl b/src/core/base.jl index 7dcbfdb04..bd5605e8f 100644 --- a/src/core/base.jl +++ b/src/core/base.jl @@ -12,15 +12,6 @@ _IM.@def pm_fields begin end -"" -ismulticonductor(pm::AbstractPowerModel, nw::Int) = haskey(pm.ref[:it][pm_it_sym][:nw][nw], :conductors) -ismulticonductor(pm::AbstractPowerModel; nw::Int=nw_id_default) = haskey(pm.ref[:it][pm_it_sym][:nw][nw], :conductors) - -"" -conductor_ids(pm::AbstractPowerModel, nw::Int) = pm.ref[:it][pm_it_sym][:nw][nw][:conductor_ids] -conductor_ids(pm::AbstractPowerModel; nw::Int=nw_id_default) = pm.ref[:it][pm_it_sym][:nw][nw][:conductor_ids] - - "" function solve_model(file::String, model_type::Type, optimizer, build_method; kwargs...) data = PowerModels.parse_file(file) @@ -30,7 +21,7 @@ end "" function solve_model(data::Dict{String,<:Any}, model_type::Type, optimizer, build_method; ref_extensions=[], solution_processors=[], relax_integrality=false, - multinetwork=false, multiconductor=false, kwargs...) + multinetwork=false, kwargs...) if multinetwork != _IM.ismultinetwork(data) model_requirement = multinetwork ? "multi-network" : "single-network" @@ -38,12 +29,6 @@ function solve_model(data::Dict{String,<:Any}, model_type::Type, optimizer, buil Memento.error(_LOGGER, "attempted to build a $(model_requirement) model with $(data_type) data") end - if multiconductor != ismulticonductor(data) - model_requirement = multiconductor ? "multi-conductor" : "single-conductor" - data_type = ismulticonductor(data) ? "multi-conductor" : "single-conductor" - Memento.error(_LOGGER, "attempted to build a $(model_requirement) model with $(data_type) data") - end - start_time = time() pm = instantiate_model(data, model_type, build_method; ref_extensions=ref_extensions, kwargs...) Memento.debug(_LOGGER, "pm model build time: $(time() - start_time)") @@ -199,7 +184,7 @@ function ref_add_core!(ref::Dict{Symbol,Any}) ### aggregate info for pairs of connected buses ### if !haskey(nw_ref, :buspairs) - nw_ref[:buspairs] = calc_buspair_parameters(nw_ref[:bus], nw_ref[:branch], nw_ref[:conductor_ids], haskey(nw_ref, :conductors)) + nw_ref[:buspairs] = calc_buspair_parameters(nw_ref[:bus], nw_ref[:branch]) end end end diff --git a/src/core/constraint_template.jl b/src/core/constraint_template.jl index 96c298e9c..cff827727 100644 --- a/src/core/constraint_template.jl +++ b/src/core/constraint_template.jl @@ -697,17 +697,27 @@ end ### Branch - Current Limit Constraints ### -""" -Adds a current magnitude limit constraint for the desired branch to the PowerModel. -""" -function constraint_current_limit(pm::AbstractPowerModel, i::Int; nw::Int=nw_id_default) +"" +function constraint_current_limit_from(pm::AbstractPowerModel, i::Int; nw::Int=nw_id_default) branch = ref(pm, nw, :branch, i) f_bus = branch["f_bus"] t_bus = branch["t_bus"] f_idx = (i, f_bus, t_bus) if haskey(branch, "c_rating_a") - constraint_current_limit(pm, nw, f_idx, branch["c_rating_a"]) + constraint_current_limit_from(pm, nw, f_idx, branch["c_rating_a"]) + end +end + +"" +function constraint_current_limit_to(pm::AbstractPowerModel, i::Int; nw::Int=nw_id_default) + branch = ref(pm, nw, :branch, i) + f_bus = branch["f_bus"] + t_bus = branch["t_bus"] + t_idx = (i, t_bus, f_bus) + + if haskey(branch, "c_rating_a") + constraint_current_limit_to(pm, nw, t_idx, branch["c_rating_a"]) end end diff --git a/src/core/data.jl b/src/core/data.jl index a13998e18..3cd74f039 100644 --- a/src/core/data.jl +++ b/src/core/data.jl @@ -44,39 +44,13 @@ function calc_theta_delta_bounds(data::Dict{String,<:Any}) angle_min = Real[] angle_max = Real[] - conductors = 1 - if haskey(data, "conductors") - conductors = data["conductors"] - end - conductor_ids = 1:conductors - - for c in conductor_ids - angle_mins = [branch["angmin"][c] for branch in branches] - angle_maxs = [branch["angmax"][c] for branch in branches] - - sort!(angle_mins) - sort!(angle_maxs, rev=true) - - if length(angle_mins) > 1 - # note that, this can occur when dclines are present - angle_count = min(bus_count-1, length(branches)) + angle_mins = [branch["angmin"] for branch in branches] + angle_maxs = [branch["angmax"] for branch in branches] - angle_min_val = sum(angle_mins[1:angle_count]) - angle_max_val = sum(angle_maxs[1:angle_count]) - else - angle_min_val = angle_mins[1] - angle_max_val = angle_maxs[1] - end - - push!(angle_min, angle_min_val) - push!(angle_max, angle_max_val) - end + sort!(angle_mins) + sort!(angle_maxs, rev=true) - if haskey(data, "conductors") - return angle_min, angle_max - else - return angle_min[1], angle_max[1] - end + return angle_mins[1], angle_maxs[1] end @@ -224,15 +198,6 @@ component_table(data::Dict{String,<:Any}, component::String, args...) = _IM.comp "recursively applies new_data to data, overwriting information" function update_data!(data::Dict{String,<:Any}, new_data::Dict{String,<:Any}) - if haskey(data, "conductors") && haskey(new_data, "conductors") - if data["conductors"] != new_data["conductors"] - Memento.error(_LOGGER, "update_data requires datasets with the same number of conductors") - end - else - if (haskey(data, "conductors") && !haskey(new_data, "conductors")) || (!haskey(data, "conductors") && haskey(new_data, "conductors")) - Memento.warn(_LOGGER, "running update_data with missing onductors fields, conductors may be incorrect") - end - end _IM.update_data!(data, new_data) end @@ -582,7 +547,6 @@ function calc_gen_cost(data::Dict{String,<:Any}) pm_data = get_pm_data(data) @assert("per_unit" in keys(pm_data) && pm_data["per_unit"]) - @assert(!haskey(pm_data, "conductors")) if _IM.ismultinetwork(pm_data) nw_costs = Dict{String, Any}() @@ -623,7 +587,6 @@ function calc_dcline_cost(data::Dict{String,<:Any}) pm_data = get_pm_data(data) @assert("per_unit" in keys(pm_data) && pm_data["per_unit"]) - @assert(!haskey(pm_data, "conductors")) if _IM.ismultinetwork(pm_data) nw_costs = Dict{String,Any}() @@ -689,6 +652,9 @@ function _calc_comp_lines(component::Dict{String,<:Any}) y2 = points[i+1] m = (y2 - y1)/(x2 - x1) + if isapprox(x1,x2) + m = 0.0 + end b = y1 - m * x1 push!(line_data, (slope=m, intercept=b)) @@ -756,7 +722,6 @@ function calc_branch_flow_ac(data::Dict{String,<:Any}) pm_data = get_pm_data(data) @assert("per_unit" in keys(pm_data) && pm_data["per_unit"]) - @assert(!haskey(pm_data, "conductors")) if _IM.ismultinetwork(pm_data) nws = Dict{String,Any}() @@ -835,7 +800,6 @@ function calc_branch_flow_dc(data::Dict{String,<:Any}) pm_data = get_pm_data(data) @assert("per_unit" in keys(pm_data) && pm_data["per_unit"]) - @assert(!haskey(pm_data, "conductors")) if _IM.ismultinetwork(pm_data) nws = Dict{String,Any}() @@ -895,7 +859,6 @@ function calc_power_balance(data::Dict{String,<:Any}) pm_data = get_pm_data(data) @assert("per_unit" in keys(pm_data) && pm_data["per_unit"]) # may not be strictly required - @assert(!haskey(pm_data, "conductors")) if _IM.ismultinetwork(pm_data) nws = Dict{String,Any}() @@ -1042,41 +1005,6 @@ function _calc_power_balance(data::Dict{String,<:Any}) end - - - -"" -function ismulticonductor(data::Dict{String,<:Any}) - pm_data = get_pm_data(data) - - if _IM.ismultinetwork(pm_data) - return all(_ismulticonductor(pm_nw_data) for (i, pm_nw_data) in pm_data["nw"]) - else - return _ismulticonductor(pm_data) - end -end - -function _ismulticonductor(data::Dict{String,<:Any}) - return haskey(data, "conductors") -end - - -"" -function check_conductors(data::Dict{String,<:Any}) - apply_pm!(_check_conductors, data) -end - - -"" -function _check_conductors(data::Dict{String,<:Any}) - if haskey(data, "conductors") && data["conductors"] < 1 - Memento.error(_LOGGER, "conductor values must be positive integers, given $(data["conductors"])") - end -end - - - - "checks that voltage angle differences are within 90 deg., if not tightens" function correct_voltage_angle_differences!(data::Dict{String,<:Any}, default_pad = 1.0472) pm_data = get_pm_data(data) @@ -1088,40 +1016,24 @@ function correct_voltage_angle_differences!(data::Dict{String,<:Any}, default_pa @assert("per_unit" in keys(pm_data) && pm_data["per_unit"]) default_pad_deg = round(rad2deg(default_pad), digits=2) - for c in 1:get(pm_data, "conductors", 1) - cnd_str = haskey(pm_data, "conductors") ? ", conductor $(c)" : "" - for (i, branch) in pm_data["branch"] - angmin = branch["angmin"][c] - angmax = branch["angmax"][c] + for (i, branch) in pm_data["branch"] + angmin = branch["angmin"] + angmax = branch["angmax"] - if angmin <= -pi/2 - Memento.warn(_LOGGER, "this code only supports angmin values in -90 deg. to 90 deg., tightening the value on branch $i$(cnd_str) from $(rad2deg(angmin)) to -$(default_pad_deg) deg.") - if haskey(pm_data, "conductors") - branch["angmin"][c] = -default_pad - else - branch["angmin"] = -default_pad - end - end + if angmin <= -pi/2 + Memento.warn(_LOGGER, "this code only supports angmin values in -90 deg. to 90 deg., tightening the value on branch $i from $(rad2deg(angmin)) to -$(default_pad_deg) deg.") + branch["angmin"] = -default_pad + end - if angmax >= pi/2 - Memento.warn(_LOGGER, "this code only supports angmax values in -90 deg. to 90 deg., tightening the value on branch $i$(cnd_str) from $(rad2deg(angmax)) to $(default_pad_deg) deg.") - if haskey(pm_data, "conductors") - branch["angmax"][c] = default_pad - else - branch["angmax"] = default_pad - end - end + if angmax >= pi/2 + Memento.warn(_LOGGER, "this code only supports angmax values in -90 deg. to 90 deg., tightening the value on branch $i from $(rad2deg(angmax)) to $(default_pad_deg) deg.") + branch["angmax"] = default_pad + end - if angmin == 0.0 && angmax == 0.0 - Memento.warn(_LOGGER, "angmin and angmax values are 0, widening these values on branch $i$(cnd_str) to +/- $(default_pad_deg) deg.") - if haskey(pm_data, "conductors") - branch["angmin"][c] = -default_pad - branch["angmax"][c] = default_pad - else - branch["angmin"] = -default_pad - branch["angmax"] = default_pad - end - end + if angmin == 0.0 && angmax == 0.0 + Memento.warn(_LOGGER, "angmin and angmax values are 0, widening these values on branch $i to +/- $(default_pad_deg) deg.") + branch["angmin"] = -default_pad + branch["angmax"] = default_pad end end @@ -1141,18 +1053,14 @@ function _correct_thermal_limits!(pm_data::Dict{String,<:Any}) append!(branches, values(pm_data["ne_branch"])) end - conductors = 1:get(pm_data, "conductors", 1) - for branch in branches for rate_key in ["rate_a", "rate_b", "rate_c"] if haskey(branch, rate_key) rate_value = branch[rate_key] - for c in conductors - if rate_value[c] < 0.0 - Memento.error(_LOGGER, "negative $(rate_key) value on branch $(branch["index"]), this code only supports non-negative $(rate_key) values") - end + if rate_value < 0.0 + Memento.error(_LOGGER, "negative $(rate_key) value on branch $(branch["index"]), this code only supports non-negative $(rate_key) values") end - if all(isapprox(rate_value[c], 0.0) for c in conductors) + if isapprox(rate_value, 0.0) delete!(branch, rate_key) Memento.warn(_LOGGER, "removing zero $(rate_key) limit on branch $(branch["index"])") end @@ -1184,44 +1092,32 @@ function _calc_thermal_limits!(pm_data::Dict{String,<:Any}) for branch in branches if !haskey(branch, "rate_a") - if haskey(pm_data, "conductors") - branch["rate_a"] = [0.0 for i in 1:pm_data["conductors"]] - else - branch["rate_a"] = 0.0 - end + branch["rate_a"] = 0.0 end - for c in 1:get(pm_data, "conductors", 1) - cnd_str = haskey(pm_data, "conductors") ? ", conductor $(c)" : "" - if branch["rate_a"][c] <= 0.0 - theta_max = max(abs(branch["angmin"][c]), abs(branch["angmax"][c])) + if branch["rate_a"] <= 0.0 + theta_max = max(abs(branch["angmin"]), abs(branch["angmax"])) - r = branch["br_r"] - x = branch["br_x"] - z = r + im * x - y = pinv(z) - y_mag = abs.(y[c,c]) + r = branch["br_r"] + x = branch["br_x"] + z = r + im * x + y = pinv(z) + y_mag = abs.(y) - fr_vmax = pm_data["bus"][string(branch["f_bus"])]["vmax"][c] - to_vmax = pm_data["bus"][string(branch["t_bus"])]["vmax"][c] - m_vmax = max(fr_vmax, to_vmax) + fr_vmax = pm_data["bus"][string(branch["f_bus"])]["vmax"] + to_vmax = pm_data["bus"][string(branch["t_bus"])]["vmax"] + m_vmax = max(fr_vmax, to_vmax) - c_max = sqrt(fr_vmax^2 + to_vmax^2 - 2*fr_vmax*to_vmax*cos(theta_max)) - - new_rate = y_mag*m_vmax*c_max - - if haskey(branch, "c_rating_a") && branch["c_rating_a"][c] > 0.0 - new_rate = min(new_rate, branch["c_rating_a"][c]*m_vmax) - end + c_max = sqrt(fr_vmax^2 + to_vmax^2 - 2*fr_vmax*to_vmax*cos(theta_max)) - Memento.warn(_LOGGER, "this code only supports positive rate_a values, changing the value on branch $(branch["index"])$(cnd_str) to $(round(mva_base*new_rate, digits=4))") + new_rate = y_mag*m_vmax*c_max - if haskey(pm_data, "conductors") - branch["rate_a"][c] = new_rate - else - branch["rate_a"] = new_rate - end + if haskey(branch, "c_rating_a") && branch["c_rating_a"] > 0.0 + new_rate = min(new_rate, branch["c_rating_a"]*m_vmax) end + + Memento.warn(_LOGGER, "this code only supports positive rate_a values, changing the value on branch $(branch["index"]) to $(round(mva_base*new_rate, digits=4))") + branch["rate_a"] = new_rate end end @@ -1242,18 +1138,16 @@ function _correct_current_limits!(pm_data::Dict{String,<:Any}) append!(branches, values(pm_data["ne_branch"])) end - conductors = 1:get(pm_data, "conductors", 1) - for branch in branches for rate_key in ["c_rating_a", "c_rating_b", "c_rating_c"] if haskey(branch, rate_key) rate_value = branch[rate_key] - for c in conductors - if rate_value[c] < 0.0 - Memento.error(_LOGGER, "negative $(rate_key) value on branch $(branch["index"]), this code only supports non-negative $(rate_key) values") - end + + if rate_value < 0.0 + Memento.error(_LOGGER, "negative $(rate_key) value on branch $(branch["index"]), this code only supports non-negative $(rate_key) values") end - if all(isapprox(rate_value[c], 0.0) for c in conductors) + + if isapprox(rate_value, 0.0) delete!(branch, rate_key) Memento.warn(_LOGGER, "removing zero $(rate_key) limit on branch $(branch["index"])") end @@ -1283,46 +1177,34 @@ function _calc_current_limits!(pm_data::Dict{String,<:Any}) for branch in branches if !haskey(branch, "c_rating_a") - if haskey(pm_data, "conductors") - branch["c_rating_a"] = [0.0 for i in 1:pm_data["conductors"]] - else - branch["c_rating_a"] = 0.0 - end + branch["c_rating_a"] = 0.0 end - for c in 1:get(pm_data, "conductors", 1) - cnd_str = haskey(pm_data, "conductors") ? ", conductor $(c)" : "" - if branch["c_rating_a"][c] <= 0.0 - theta_max = max(abs(branch["angmin"][c]), abs(branch["angmax"][c])) - - r = branch["br_r"] - x = branch["br_x"] - z = r + im * x - y = pinv(z) - y_mag = abs.(y[c,c]) + if branch["c_rating_a"] <= 0.0 + theta_max = max(abs(branch["angmin"]), abs(branch["angmax"])) - fr_vmax = pm_data["bus"][string(branch["f_bus"])]["vmax"][c] - to_vmax = pm_data["bus"][string(branch["t_bus"])]["vmax"][c] - m_vmax = max(fr_vmax, to_vmax) + r = branch["br_r"] + x = branch["br_x"] + z = r + im * x + y = pinv(z) + y_mag = abs.(y) - new_c_rating = y_mag*sqrt(fr_vmax^2 + to_vmax^2 - 2*fr_vmax*to_vmax*cos(theta_max)) + fr_vmax = pm_data["bus"][string(branch["f_bus"])]["vmax"] + to_vmax = pm_data["bus"][string(branch["t_bus"])]["vmax"] + m_vmax = max(fr_vmax, to_vmax) - if haskey(branch, "rate_a") && branch["rate_a"][c] > 0.0 - fr_vmin = pm_data["bus"][string(branch["f_bus"])]["vmin"][c] - to_vmin = pm_data["bus"][string(branch["t_bus"])]["vmin"][c] - vm_min = min(fr_vmin, to_vmin) + new_c_rating = y_mag*sqrt(fr_vmax^2 + to_vmax^2 - 2*fr_vmax*to_vmax*cos(theta_max)) - new_c_rating = min(new_c_rating, branch["rate_a"]/vm_min) - end - - Memento.warn(_LOGGER, "this code only supports positive c_rating_a values, changing the value on branch $(branch["index"])$(cnd_str) to $(mva_base*new_c_rating)") - if haskey(pm_data, "conductors") - branch["c_rating_a"][c] = new_c_rating - else - branch["c_rating_a"] = new_c_rating - end + if haskey(branch, "rate_a") && branch["rate_a"] > 0.0 + fr_vmin = pm_data["bus"][string(branch["f_bus"])]["vmin"] + to_vmin = pm_data["bus"][string(branch["t_bus"])]["vmin"] + vm_min = min(fr_vmin, to_vmin) + new_c_rating = min(new_c_rating, branch["rate_a"]/vm_min) end + + Memento.warn(_LOGGER, "this code only supports positive c_rating_a values, changing the value on branch $(branch["index"]) to $(mva_base*new_c_rating)") + branch["c_rating_a"] = new_c_rating end end @@ -1564,31 +1446,16 @@ function _correct_transformer_parameters!(pm_data::Dict{String,<:Any}) for (i, branch) in pm_data["branch"] if !haskey(branch, "tap") Memento.warn(_LOGGER, "branch found without tap value, setting a tap to 1.0") - if haskey(pm_data, "conductors") - branch["tap"] = [1.0 for i in 1:pm_data["conductors"]] - else - branch["tap"] = 1.0 - end + branch["tap"] = 1.0 else - for c in 1:get(pm_data, "conductors", 1) - cnd_str = haskey(pm_data, "conductors") ? " on conductor $(c)" : "" - if branch["tap"][c] <= 0.0 - Memento.warn(_LOGGER, "branch found with non-positive tap value of $(branch["tap"][c]), setting a tap to 1.0$(cnd_str)") - if haskey(pm_data, "conductors") - branch["tap"][c] = 1.0 - else - branch["tap"] = 1.0 - end - end + if branch["tap"] <= 0.0 + Memento.warn(_LOGGER, "branch found with non-positive tap value of $(branch["tap"]), setting a tap to 1.0") + branch["tap"] = 1.0 end end if !haskey(branch, "shift") Memento.warn(_LOGGER, "branch found without shift value, setting a shift to 0.0") - if haskey(pm_data, "conductors") - branch["shift"] = [0.0 for i in 1:pm_data["conductors"]] - else - branch["shift"] = 0.0 - end + branch["shift"] = 0.0 end end @@ -1617,19 +1484,17 @@ function _check_storage_parameters(data::Dict{String,<:Any}) Memento.error(_LOGGER, "storage unit $(strg["index"]) has a non-positive discharge rating $(strg["energy_rating"])") end - for c in 1:get(data, "conductors", 1) - if strg["r"][c] < 0.0 - Memento.error(_LOGGER, "storage unit $(strg["index"]) has a non-positive resistance $(strg["r"][c])") - end - if strg["x"][c] < 0.0 - Memento.error(_LOGGER, "storage unit $(strg["index"]) has a non-positive reactance $(strg["x"][c])") - end - if haskey(strg, "thermal_rating") && strg["thermal_rating"][c] < 0.0 - Memento.error(_LOGGER, "storage unit $(strg["index"]) has a non-positive thermal rating $(strg["thermal_rating"][c])") - end - if haskey(strg, "current_rating") && strg["current_rating"][c] < 0.0 - Memento.error(_LOGGER, "storage unit $(strg["index"]) has a non-positive current rating $(strg["thermal_rating"][c])") - end + if strg["r"] < 0.0 + Memento.error(_LOGGER, "storage unit $(strg["index"]) has a non-positive resistance $(strg["r"])") + end + if strg["x"] < 0.0 + Memento.error(_LOGGER, "storage unit $(strg["index"]) has a non-positive reactance $(strg["x"])") + end + if haskey(strg, "thermal_rating") && strg["thermal_rating"] < 0.0 + Memento.error(_LOGGER, "storage unit $(strg["index"]) has a non-positive thermal rating $(strg["thermal_rating"])") + end + if haskey(strg, "current_rating") && strg["current_rating"] < 0.0 + Memento.error(_LOGGER, "storage unit $(strg["index"]) has a non-positive current rating $(strg["thermal_rating"])") end if strg["charge_efficiency"] < 0.0 @@ -1787,54 +1652,33 @@ end function _correct_dcline_limits!(pm_data::Dict{String,<:Any}) mva_base = pm_data["baseMVA"] - for c in 1:get(pm_data, "conductors", 1) - cnd_str = haskey(pm_data, "conductors") ? ", conductor $(c)" : "" - for (i, dcline) in pm_data["dcline"] - if dcline["loss0"][c] < 0.0 - new_rate = 0.0 - Memento.warn(_LOGGER, "this code only supports positive loss0 values, changing the value on dcline $(dcline["index"])$(cnd_str) from $(mva_base*dcline["loss0"][c]) to $(mva_base*new_rate)") - if haskey(pm_data, "conductors") - dcline["loss0"][c] = new_rate - else - dcline["loss0"] = new_rate - end - end + for (i, dcline) in pm_data["dcline"] + if dcline["loss0"] < 0.0 + new_rate = 0.0 + Memento.warn(_LOGGER, "this code only supports positive loss0 values, changing the value on dcline $(dcline["index"]) from $(mva_base*dcline["loss0"]) to $(mva_base*new_rate)") + dcline["loss0"] = new_rate + end - if dcline["loss0"][c] >= dcline["pmaxf"][c]*(1-dcline["loss1"][c] )+ dcline["pmaxt"][c] - new_rate = 0.0 - Memento.warn(_LOGGER, "this code only supports loss0 values which are consistent with the line flow bounds, changing the value on dcline $(dcline["index"])$(cnd_str) from $(mva_base*dcline["loss0"][c]) to $(mva_base*new_rate)") - if haskey(pm_data, "conductors") - dcline["loss0"][c] = new_rate - else - dcline["loss0"] = new_rate - end - end + if dcline["loss0"] >= dcline["pmaxf"]*(1-dcline["loss1"] )+ dcline["pmaxt"] + new_rate = 0.0 + Memento.warn(_LOGGER, "this code only supports loss0 values which are consistent with the line flow bounds, changing the value on dcline $(dcline["index"]) from $(mva_base*dcline["loss0"]) to $(mva_base*new_rate)") + dcline["loss0"] = new_rate + end - if dcline["loss1"][c] < 0.0 - new_rate = 0.0 - Memento.warn(_LOGGER, "this code only supports positive loss1 values, changing the value on dcline $(dcline["index"])$(cnd_str) from $(dcline["loss1"][c]) to $(new_rate)") - if haskey(pm_data, "conductors") - dcline["loss1"][c] = new_rate - else - dcline["loss1"] = new_rate - end - end + if dcline["loss1"] < 0.0 + new_rate = 0.0 + Memento.warn(_LOGGER, "this code only supports positive loss1 values, changing the value on dcline $(dcline["index"]) from $(dcline["loss1"]) to $(new_rate)") + dcline["loss1"] = new_rate + end - if dcline["loss1"][c] >= 1.0 - new_rate = 0.0 - Memento.warn(_LOGGER, "this code only supports loss1 values < 1, changing the value on dcline $(dcline["index"])$(cnd_str) from $(dcline["loss1"][c]) to $(new_rate)") - if haskey(pm_data, "conductors") - dcline["loss1"][c] = new_rate - else - dcline["loss1"] = new_rate - end - end + if dcline["loss1"] >= 1.0 + new_rate = 0.0 + Memento.warn(_LOGGER, "this code only supports loss1 values < 1, changing the value on dcline $(dcline["index"]) from $(dcline["loss1"]) to $(new_rate)") + dcline["loss1"] = new_rate + end - if dcline["pmint"][c] <0.0 && dcline["loss1"][c] > 0.0 - #new_rate = 0.0 - Memento.warn(_LOGGER, "the dc line model is not meant to be used bi-directionally when loss1 > 0, be careful interpreting the results as the dc line losses can now be negative. change loss1 to 0 to avoid this warning") - #dcline["loss0"] = new_rate - end + if dcline["pmint"] <0.0 && dcline["loss1"] > 0.0 + Memento.warn(_LOGGER, "the dc line model is not meant to be used bi-directionally when loss1 > 0, be careful interpreting the results as the dc line losses can now be negative. change loss1 to 0 to avoid this warning") end end @@ -1849,30 +1693,27 @@ end "" function _check_voltage_setpoints(data::Dict{String,<:Any}) - for c in 1:get(data, "conductors", 1) - cnd_str = haskey(data, "conductors") ? "conductor $(c) " : "" - for (i,gen) in data["gen"] - bus_id = gen["gen_bus"] - bus = data["bus"]["$(bus_id)"] - if gen["vg"][c] != bus["vm"][c] - Memento.warn(_LOGGER, "the $(cnd_str)voltage setpoint on generator $(i) does not match the value at bus $(bus_id)") - end + for (i,gen) in data["gen"] + bus_id = gen["gen_bus"] + bus = data["bus"]["$(bus_id)"] + if gen["vg"] != bus["vm"] + Memento.warn(_LOGGER, "the voltage setpoint on generator $(i) does not match the value at bus $(bus_id)") end + end - for (i, dcline) in data["dcline"] - bus_fr_id = dcline["f_bus"] - bus_to_id = dcline["t_bus"] + for (i, dcline) in data["dcline"] + bus_fr_id = dcline["f_bus"] + bus_to_id = dcline["t_bus"] - bus_fr = data["bus"]["$(bus_fr_id)"] - bus_to = data["bus"]["$(bus_to_id)"] + bus_fr = data["bus"]["$(bus_fr_id)"] + bus_to = data["bus"]["$(bus_to_id)"] - if dcline["vf"][c] != bus_fr["vm"][c] - Memento.warn(_LOGGER, "the $(cnd_str)from bus voltage setpoint on dc line $(i) does not match the value at bus $(bus_fr_id)") - end + if dcline["vf"] != bus_fr["vm"] + Memento.warn(_LOGGER, "the from bus voltage setpoint on dc line $(i) does not match the value at bus $(bus_fr_id)") + end - if dcline["vt"][c] != bus_to["vm"][c] - Memento.warn(_LOGGER, "the $(cnd_str)to bus voltage setpoint on dc line $(i) does not match the value at bus $(bus_to_id)") - end + if dcline["vt"] != bus_to["vm"] + Memento.warn(_LOGGER, "the to bus voltage setpoint on dc line $(i) does not match the value at bus $(bus_to_id)") end end end diff --git a/src/core/objective.jl b/src/core/objective.jl index 77aedf1a2..c62c81e5e 100644 --- a/src/core/objective.jl +++ b/src/core/objective.jl @@ -1,390 +1,103 @@ -################################################################################ -# This file is to defines commonly used constraints for power flow models -# This will hopefully make everything more compositional -################################################################################ - -# enables support for v[1] -Base.getindex(v::JuMP.VariableRef, i::Int) = v - - """ -Checks that all cost models are of the same type +Checks if any generator cost model will require a JuMP nonlinear expression """ -function check_cost_models(pm::AbstractPowerModel) - gen_model = check_gen_cost_models(pm) - dcline_model = check_dcline_cost_models(pm) - - if dcline_model == nothing - return gen_model - end - - if gen_model == nothing - return dcline_model - end - - if gen_model != dcline_model - Memento.error(_LOGGER, "generator and dcline cost models are inconsistent, the generator model is $(gen_model) however dcline model $(dcline_model)") - end - - return gen_model -end - - -""" -Checks that all generator cost models are of the same type -""" -function check_gen_cost_models(pm::AbstractPowerModel) - model = nothing - +function check_nl_gen_cost_models(pm::AbstractPowerModel) for (n, nw_ref) in nws(pm) for (i,gen) in nw_ref[:gen] if haskey(gen, "cost") - if model == nothing - model = gen["model"] - else - if gen["model"] != model - Memento.error(_LOGGER, "cost models are inconsistent, the typical model is $(model) however model $(gen["model"]) is given on generator $(i)") - end + if gen["model"] == 2 && length(gen["cost"]) > 3 + return true end - else - Memento.error(_LOGGER, "no cost given for generator $(i)") end end end - - return model + return false end - """ -Checks that all dcline cost models are of the same type +Checks if any dcline cost model will require a JuMP nonlinear expression """ -function check_dcline_cost_models(pm::AbstractPowerModel) - model = nothing - +function check_nl_dcline_cost_models(pm::AbstractPowerModel) for (n, nw_ref) in nws(pm) for (i,dcline) in nw_ref[:dcline] - if haskey(dcline, "model") - if model == nothing - model = dcline["model"] - else - if dcline["model"] != model - Memento.error(_LOGGER, "cost models are inconsistent, the typical model is $(model) however model $(dcline["model"]) is given on dcline $(i)") - end + if haskey(dcline, "cost") + if dcline["model"] == 2 && length(dcline["cost"]) > 3 + return true end - else - Memento.error(_LOGGER, "no cost given for dcline $(i)") end end end - - return model + return false end "" function objective_min_fuel_and_flow_cost(pm::AbstractPowerModel; kwargs...) - model = check_cost_models(pm) + nl_gen = check_nl_gen_cost_models(pm) + nl_dc = check_nl_dcline_cost_models(pm) - if model == 1 - return objective_min_fuel_and_flow_cost_pwl(pm; kwargs...) - elseif model == 2 - return objective_min_fuel_and_flow_cost_polynomial(pm; kwargs...) - else - Memento.error(_LOGGER, "Only cost models of types 1 and 2 are supported at this time, given cost model type of $(model)") - end + nl = nl_gen || nl_dc || typeof(pm) <: AbstractIVRModel -end + expression_pg_cost(pm; kwargs...) + expression_p_dc_cost(pm; kwargs...) - -"" -function objective_min_fuel_cost(pm::AbstractPowerModel; kwargs...) - model = check_gen_cost_models(pm) - - if model == 1 - return objective_min_fuel_cost_pwl(pm; kwargs...) - elseif model == 2 - return objective_min_fuel_cost_polynomial(pm; kwargs...) - else - Memento.error(_LOGGER, "Only cost models of types 1 and 2 are supported at this time, given cost model type of $(model)") - end - -end - - -"" -function objective_min_fuel_and_flow_cost_polynomial(pm::AbstractPowerModel; kwargs...) - order = calc_max_cost_index(pm.data)-1 - - if order <= 2 - return _objective_min_fuel_and_flow_cost_polynomial_linquad(pm; kwargs...) + if !nl + return JuMP.@objective(pm.model, Min, + sum( + sum( var(pm, n, :pg_cost, i) for (i,gen) in nw_ref[:gen]) + + sum( var(pm, n, :p_dc_cost, i) for (i,dcline) in nw_ref[:dcline]) + for (n, nw_ref) in nws(pm)) + ) else - return _objective_min_fuel_and_flow_cost_polynomial_nl(pm; kwargs...) - end -end - -"" -function _objective_min_fuel_and_flow_cost_polynomial_linquad(pm::AbstractPowerModel; report::Bool=true) - gen_cost = Dict() - dcline_cost = Dict() - - for (n, nw_ref) in nws(pm) - for (i,gen) in nw_ref[:gen] - pg = sum( var(pm, n, :pg, i)[c] for c in conductor_ids(pm, n) ) - - if length(gen["cost"]) == 1 - gen_cost[(n,i)] = gen["cost"][1] - elseif length(gen["cost"]) == 2 - gen_cost[(n,i)] = gen["cost"][1]*pg + gen["cost"][2] - elseif length(gen["cost"]) == 3 - gen_cost[(n,i)] = gen["cost"][1]*pg^2 + gen["cost"][2]*pg + gen["cost"][3] - else - gen_cost[(n,i)] = 0.0 - end - end - - from_idx = Dict(arc[1] => arc for arc in nw_ref[:arcs_from_dc]) - for (i,dcline) in nw_ref[:dcline] - p_dc = sum( var(pm, n, :p_dc, from_idx[i])[c] for c in conductor_ids(pm, n) ) - - if length(dcline["cost"]) == 1 - dcline_cost[(n,i)] = dcline["cost"][1] - elseif length(dcline["cost"]) == 2 - dcline_cost[(n,i)] = dcline["cost"][1]*p_dc + dcline["cost"][2] - elseif length(dcline["cost"]) == 3 - dcline_cost[(n,i)] = dcline["cost"][1]*p_dc^2 + dcline["cost"][2]*p_dc + dcline["cost"][3] - else - dcline_cost[(n,i)] = 0.0 + pg_cost = Dict() + p_dc_cost = Dict() + for (n, nw_ref) in nws(pm) + for (i,gen) in nw_ref[:gen] + pg_cost[(n,i)] = var(pm, n, :pg_cost, i) end - end - end - - return JuMP.@objective(pm.model, Min, - sum( - sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen] ) + - sum( dcline_cost[(n,i)] for (i,dcline) in nw_ref[:dcline] ) - for (n, nw_ref) in nws(pm)) - ) -end - - -"Adds lifted variables to turn a quadatic objective into a linear one; needed for conic solvers that only support linear objectives" -function _objective_min_fuel_and_flow_cost_polynomial_linquad(pm::AbstractConicModels, report::Bool=true) - gen_cost = Dict() - dcline_cost = Dict() - - for (n, nw_ref) in nws(pm) - - var(pm, n)[:pg_sqr] = Dict() - for (i,gen) in nw_ref[:gen] - pg = sum( var(pm, n, :pg, i)[c] for c in conductor_ids(pm, n) ) - - if length(gen["cost"]) == 1 - gen_cost[(n,i)] = gen["cost"][1] - elseif length(gen["cost"]) == 2 - gen_cost[(n,i)] = gen["cost"][1]*pg + gen["cost"][2] - elseif length(gen["cost"]) == 3 - pmin = sum(gen["pmin"][c] for c in conductor_ids(pm, n)) - pmax = sum(gen["pmax"][c] for c in conductor_ids(pm, n)) - - pg_sqr_ub = max(pmin^2, pmax^2) - pg_sqr_lb = 0.0 - if pmin > 0.0 - pg_sqr_lb = pmin^2 - end - if pmax < 0.0 - pg_sqr_lb = pmax^2 - end - - pg_sqr = var(pm, n, :pg_sqr)[i] = JuMP.@variable(pm.model, - base_name="$(n)_pg_sqr_$(i)", - lower_bound = pg_sqr_lb, - upper_bound = pg_sqr_ub, - start = 0.0 - ) - if report - sol(pm, n, :gen, i)[:pg_sqr] = pg_sqr - end - - JuMP.@constraint(pm.model, [0.5, pg_sqr, pg] in JuMP.RotatedSecondOrderCone()) - - gen_cost[(n,i)] = gen["cost"][1]*pg_sqr + gen["cost"][2]*pg + gen["cost"][3] - else - gen_cost[(n,i)] = 0.0 + for (i,dcline) in nw_ref[:dcline] + p_dc_cost[(n,i)] = var(pm, n, :p_dc_cost, i) end end - from_idx = Dict(arc[1] => arc for arc in nw_ref[:arcs_from_dc]) - - var(pm, n)[:p_dc_sqr] = Dict() - for (i,dcline) in nw_ref[:dcline] - p_dc = sum( var(pm, n, :p_dc, from_idx[i])[c] for c in conductor_ids(pm, n) ) - - if length(dcline["cost"]) == 1 - dcline_cost[(n,i)] = dcline["cost"][1] - elseif length(dcline["cost"]) == 2 - dcline_cost[(n,i)] = dcline["cost"][1]*p_dc + dcline["cost"][2] - elseif length(dcline["cost"]) == 3 - pmin = sum(dcline["pminf"][c] for c in conductor_ids(pm, n)) - pmax = sum(dcline["pmaxf"][c] for c in conductor_ids(pm, n)) - - p_dc_sqr_ub = max(pmin^2, pmax^2) - p_dc_sqr_lb = 0.0 - if pmin > 0.0 - p_dc_sqr_lb = pmin^2 - end - if pmax < 0.0 - p_dc_sqr_lb = pmax^2 - end - - p_dc_sqr = var(pm, n, :p_dc_sqr)[i] = JuMP.@variable(pm.model, - base_name="$(n)_p_dc_sqr_$(i)", - lower_bound = p_dc_sqr_lb, - upper_bound = p_dc_sqr_ub, - start = 0.0 - ) - if report - sol(pm, n, :gen, i)[:p_dc_sqr] = p_dc_sqr - end - - JuMP.@constraint(pm.model, [0.5, p_dc_sqr, p_dc] in JuMP.RotatedSecondOrderCone()) - - dcline_cost[(n,i)] = dcline["cost"][1]*p_dc_sqr + dcline["cost"][2]*p_dc + dcline["cost"][3] - else - dcline_cost[(n,i)] = 0.0 - end - end + return JuMP.@NLobjective(pm.model, Min, + sum( + sum( pg_cost[n,i] for (i,gen) in nw_ref[:gen]) + + sum( p_dc_cost[n,i] for (i,dcline) in nw_ref[:dcline]) + for (n, nw_ref) in nws(pm)) + ) end - - return JuMP.@objective(pm.model, Min, - sum( - sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen] ) + - sum( dcline_cost[(n,i)] for (i,dcline) in nw_ref[:dcline] ) - for (n, nw_ref) in nws(pm)) - ) end "" -function _objective_min_fuel_and_flow_cost_polynomial_nl(pm::AbstractPowerModel; report::Bool=true) - gen_cost = Dict() - dcline_cost = Dict() - - for (n, nw_ref) in nws(pm) - for (i,gen) in nw_ref[:gen] - pg = sum( var(pm, n, :pg, i)[c] for c in conductor_ids(pm, n)) - - cost_rev = reverse(gen["cost"]) - if length(cost_rev) == 1 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1]) - elseif length(cost_rev) == 2 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg) - elseif length(cost_rev) == 3 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2) - elseif length(cost_rev) >= 4 - cost_rev_nl = cost_rev[4:end] - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2 + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) ) - else - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, 0.0) - end - end - - from_idx = Dict(arc[1] => arc for arc in nw_ref[:arcs_from_dc]) - - for (i,dcline) in nw_ref[:dcline] - p_dc = sum( var(pm, n, :p_dc, from_idx[i])[c] for c in conductor_ids(pm, n)) - - cost_rev = reverse(dcline["cost"]) - if length(cost_rev) == 1 - dcline_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1]) - elseif length(cost_rev) == 2 - dcline_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*p_dc) - elseif length(cost_rev) == 3 - dcline_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*p_dc + cost_rev[3]*p_dc^2) - elseif length(cost_rev) >= 4 - cost_rev_nl = cost_rev[4:end] - dcline_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*p_dc + cost_rev[3]*p_dc^2 + sum( v*p_dc^(d+2) for (d,v) in enumerate(cost_rev_nl)) ) - else - dcline_cost[(n,i)] = JuMP.@NLexpression(pm.model, 0.0) - end - end - end - - return JuMP.@NLobjective(pm.model, Min, - sum( - sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen]) + - sum( dcline_cost[(n,i)] for (i,dcline) in nw_ref[:dcline]) - for (n, nw_ref) in nws(pm)) - ) -end +function objective_min_fuel_cost(pm::AbstractPowerModel; kwargs...) + nl_gen = check_nl_gen_cost_models(pm) + nl = nl_gen || typeof(pm) <: AbstractIVRModel -"" -function objective_min_fuel_cost_polynomial(pm::AbstractPowerModel; kwargs...) - order = calc_max_cost_index(pm.data)-1 + expression_pg_cost(pm; kwargs...) - if order <= 2 - return _objective_min_fuel_cost_polynomial_linquad(pm; kwargs...) + if !nl + return JuMP.@objective(pm.model, Min, + sum( + sum( var(pm, n, :pg_cost, i) for (i,gen) in nw_ref[:gen]) + for (n, nw_ref) in nws(pm)) + ) else - return _objective_min_fuel_cost_polynomial_nl(pm; kwargs...) - end -end - -"" -function _objective_min_fuel_cost_polynomial_linquad(pm::AbstractPowerModel; report::Bool=true) - gen_cost = Dict() - for (n, nw_ref) in nws(pm) - for (i,gen) in nw_ref[:gen] - pg = sum( var(pm, n, :pg, i)[c] for c in conductor_ids(pm, n) ) - - if length(gen["cost"]) == 1 - gen_cost[(n,i)] = gen["cost"][1] - elseif length(gen["cost"]) == 2 - gen_cost[(n,i)] = gen["cost"][1]*pg + gen["cost"][2] - elseif length(gen["cost"]) == 3 - gen_cost[(n,i)] = gen["cost"][1]*pg^2 + gen["cost"][2]*pg + gen["cost"][3] - else - gen_cost[(n,i)] = 0.0 + pg_cost = Dict() + for (n, nw_ref) in nws(pm) + for (i,gen) in nw_ref[:gen] + pg_cost[(n,i)] = var(pm, n, :pg_cost, i) end end - end - return JuMP.@objective(pm.model, Min, - sum( - sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen] ) - for (n, nw_ref) in nws(pm)) - ) -end - - -"" -function _objective_min_fuel_cost_polynomial_nl(pm::AbstractPowerModel; report::Bool=true) - gen_cost = Dict() - for (n, nw_ref) in nws(pm) - for (i,gen) in nw_ref[:gen] - pg = sum( var(pm, n, :pg, i)[c] for c in conductor_ids(pm, n)) - - cost_rev = reverse(gen["cost"]) - if length(cost_rev) == 1 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1]) - elseif length(cost_rev) == 2 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg) - elseif length(cost_rev) == 3 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2) - elseif length(cost_rev) >= 4 - cost_rev_nl = cost_rev[4:end] - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1] + cost_rev[2]*pg + cost_rev[3]*pg^2 + sum( v*pg^(d+2) for (d,v) in enumerate(cost_rev_nl)) ) - else - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, 0.0) - end - end + return JuMP.@NLobjective(pm.model, Min, + sum( + sum( pg_cost[n,i] for (i,gen) in nw_ref[:gen]) + for (n, nw_ref) in nws(pm)) + ) end - - return JuMP.@NLobjective(pm.model, Min, - sum( - sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen] ) - for (n, nw_ref) in nws(pm)) - ) end @@ -392,7 +105,7 @@ end cleans up raw pwl cost points in preparation for building a mathamatical model. The key mathematical properties, -- the first and last points are strickly outside of the pmin-to-pmax range +- the first and last points are strictly outside of the pmin-to-pmax range - pmin and pmax occur in the first and last line segments. """ function calc_pwl_points(ncost::Int, cost::Vector{<:Real}, pmin::Real, pmax::Real; tolerance=1e-2) @@ -476,34 +189,34 @@ function calc_pwl_points(ncost::Int, cost::Vector{<:Real}, pmin::Real, pmax::Rea end + "adds pg_cost variables and constraints" -function objective_variable_pg_cost(pm::AbstractPowerModel, report::Bool=true) +function expression_pg_cost(pm::AbstractPowerModel; report::Bool=true) for (n, nw_ref) in nws(pm) pg_cost = var(pm, n)[:pg_cost] = Dict{Int,Any}() for (i,gen) in ref(pm, n, :gen) - pg_vars = [var(pm, n, :pg, i)[c] for c in conductor_ids(pm, n)] - pmin = sum(JuMP.lower_bound.(pg_vars)) - pmax = sum(JuMP.upper_bound.(pg_vars)) + pg_terms = [var(pm, n, :pg, i)] + + if gen["model"] == 1 + if isa(pg_terms, Array{JuMP.VariableRef}) + pmin = sum(JuMP.lower_bound.(pg_terms)) + pmax = sum(JuMP.upper_bound.(pg_terms)) + else + pmin = gen["pmin"] + pmax = gen["pmax"] + end - # note pmin/pmax may be different from gen["pmin"]/gen["pmax"] in the on/off case - points = calc_pwl_points(gen["ncost"], gen["cost"], pmin, pmax) + points = calc_pwl_points(gen["ncost"], gen["cost"], pmin, pmax) + pg_cost[i] = _pwl_cost_expression(pm, pg_terms, points, nw=n, id=i, var_name="pg") - pg_cost_lambda = JuMP.@variable(pm.model, - [i in 1:length(points)], base_name="$(n)_pg_cost_lambda", - lower_bound = 0.0, - upper_bound = 1.0 - ) - JuMP.@constraint(pm.model, sum(pg_cost_lambda) == 1.0) + elseif gen["model"] == 2 + cost_rev = reverse(gen["cost"]) - pg_expr = 0.0 - pg_cost_expr = 0.0 - for (i,point) in enumerate(points) - pg_expr += point.mw*pg_cost_lambda[i] - pg_cost_expr += point.cost*pg_cost_lambda[i] + pg_cost[i] = _polynomial_cost_expression(pm, pg_terms, cost_rev, nw=n, id=i, var_name="pg") + else + Memento.error(_LOGGER, "Only cost models of types 1 and 2 are supported at this time, given cost model type of $(model) on generator $(i)") end - JuMP.@constraint(pm.model, pg_expr == sum(pg_vars)) - pg_cost[i] = pg_cost_expr end report && sol_component_value(pm, n, :gen, :pg_cost, ids(pm, n, :gen), pg_cost) @@ -512,35 +225,34 @@ end "adds p_dc_cost variables and constraints" -function objective_variable_dc_cost(pm::AbstractPowerModel, report::Bool=true) +function expression_p_dc_cost(pm::AbstractPowerModel; report::Bool=true) for (n, nw_ref) in nws(pm) p_dc_cost = var(pm, n)[:p_dc_cost] = Dict{Int,Any}() for (i,dcline) in ref(pm, n, :dcline) arc = (i, dcline["f_bus"], dcline["t_bus"]) - p_dc_vars = [var(pm, n, :p_dc)[arc][c] for c in conductor_ids(pm, n)] - pmin = sum(JuMP.lower_bound.(p_dc_vars)) - pmax = sum(JuMP.upper_bound.(p_dc_vars)) - # note pmin/pmax may be different from dcline["pminf"]/dcline["pmaxf"] in the on/off case - points = calc_pwl_points(dcline["ncost"], dcline["cost"], pmin, pmax) + p_dc_terms = [var(pm, n, :p_dc, arc)] - dc_p_cost_lambda = JuMP.@variable(pm.model, - [i in 1:length(points)], base_name="$(n)_dc_p_cost_lambda", - lower_bound = 0.0, - upper_bound = 1.0 - ) - JuMP.@constraint(pm.model, sum(dc_p_cost_lambda) == 1.0) + if dcline["model"] == 1 + if isa(p_dc_terms, Array{JuMP.VariableRef}) + pmin = sum(JuMP.lower_bound.(p_dc_terms)) + pmax = sum(JuMP.upper_bound.(p_dc_terms)) + else + pmin = dcline["pminf"] + pmax = dcline["pmaxf"] + end - dc_p_expr = 0.0 - dc_p_cost_expr = 0.0 - for (i,point) in enumerate(points) - dc_p_expr += point.mw*dc_p_cost_lambda[i] - dc_p_cost_expr += point.cost*dc_p_cost_lambda[i] - end + # note pmin/pmax may be different from dcline["pminf"]/dcline["pmaxf"] in the on/off case + points = calc_pwl_points(dcline["ncost"], dcline["cost"], pmin, pmax) + p_dc_cost[i] = _pwl_cost_expression(pm, p_dc_terms, points, nw=n, id=i, var_name="dc_p") - JuMP.@constraint(pm.model, dc_p_expr == sum(p_dc_vars)) - p_dc_cost[i] = dc_p_cost_expr + elseif dcline["model"] == 2 + cost_rev = reverse(dcline["cost"]) + p_dc_cost[i] = _polynomial_cost_expression(pm, p_dc_terms, cost_rev, nw=n, id=i, var_name="dc_p") + else + Memento.error(_LOGGER, "only cost models of types 1 and 2 are supported at this time, given cost model type of $(model) on dcline $(i)") + end end report && sol_component_value(pm, n, :dcline, :p_dc_cost, ids(pm, n, :dcline), p_dc_cost) @@ -548,38 +260,124 @@ function objective_variable_dc_cost(pm::AbstractPowerModel, report::Bool=true) end -"" -function objective_min_fuel_and_flow_cost_pwl(pm::AbstractPowerModel; kwargs...) - objective_variable_pg_cost(pm; kwargs...) - objective_variable_dc_cost(pm; kwargs...) - - return JuMP.@objective(pm.model, Min, - sum( - sum( var(pm, n, :pg_cost, i) for (i,gen) in nw_ref[:gen]) + - sum( var(pm, n, :p_dc_cost, i) for (i,dcline) in nw_ref[:dcline]) - for (n, nw_ref) in nws(pm)) +function _pwl_cost_expression(pm::AbstractPowerModel, x_list::Array{JuMP.VariableRef}, points; nw=0, id=1, var_name="x") + cost_lambda = JuMP.@variable(pm.model, + [i in 1:length(points)], base_name="$(nw)_$(var_name)_cost_lambda_$(id)", + lower_bound = 0.0, + upper_bound = 1.0 ) -end + JuMP.@constraint(pm.model, sum(cost_lambda) == 1.0) + expr = 0.0 + cost_expr = 0.0 + for (i,point) in enumerate(points) + expr += point.mw*cost_lambda[i] + cost_expr += point.cost*cost_lambda[i] + end + JuMP.@constraint(pm.model, expr == sum(x_list)) -"" -function objective_min_fuel_cost_pwl(pm::AbstractPowerModel; kwargs...) - objective_variable_pg_cost(pm; kwargs...) + return cost_expr +end - return JuMP.@objective(pm.model, Min, - sum( - sum( var(pm, n, :pg_cost, i) for (i,gen) in nw_ref[:gen]) - for (n, nw_ref) in nws(pm)) +function _pwl_cost_expression(pm::AbstractPowerModel, x_list, points; nw=0, id=1, var_name="x") + cost_lambda = JuMP.@variable(pm.model, + [i in 1:length(points)], base_name="$(nw)_$(var_name)_cost_lambda_$(id)", + lower_bound = 0.0, + upper_bound = 1.0 ) + JuMP.@constraint(pm.model, sum(cost_lambda) == 1.0) + + expr = 0.0 + cost_expr = 0.0 + for (i,point) in enumerate(points) + expr += point.mw*cost_lambda[i] + cost_expr += point.cost*cost_lambda[i] + end + JuMP.@NLconstraint(pm.model, expr == sum(x for x in x_list)) + + return cost_expr end +# note that `cost_terms` should be providing in ascending order (the reverse of the Matpower spec.) +function _polynomial_cost_expression(pm::AbstractPowerModel, x_list::Array{JuMP.VariableRef}, cost_terms; nw=0, id=1, var_name="x") + x = sum(x_list) + if length(cost_terms) == 0 + return 0.0 + elseif length(cost_terms) == 1 + return cost_terms[1] + elseif length(cost_terms) == 2 + return cost_terms[1] + cost_terms[2]*x + elseif length(cost_terms) == 3 + return cost_terms[1] + cost_terms[2]*x + cost_terms[3]*x^2 + else # length(cost_terms) >= 4 + cost_nl = cost_terms[4:end] + return JuMP.@NLexpression(pm.model, cost_terms[1] + cost_terms[2]*x + cost_terms[3]*x^2 + sum( v*x^(d+2) for (d,v) in enumerate(cost_nl)) ) + end +end + +# note that `cost_terms` should be providing in ascending order (the reverse of the Matpower spec.) +function _polynomial_cost_expression(pm::AbstractConicModels, x_list::Array{JuMP.VariableRef}, cost_terms; nw=0, id=1, var_name="x") + x = sum(x_list) + if length(cost_terms) == 0 + return 0.0 + elseif length(cost_terms) == 1 + return cost_terms[1] + elseif length(cost_terms) == 2 + return cost_terms[1] + cost_terms[2]*x + elseif length(cost_terms) == 3 + x_lb = sum(JuMP.lower_bound.(x_list)) + x_ub = sum(JuMP.upper_bound.(x_list)) + + x_sqr_lb = 0.0 + x_sqr_ub = max(x_lb^2, x_ub^2) + if x_lb > 0.0 + x_sqr_lb = x_lb^2 + end + if x_ub < 0.0 + x_sqr_lb = x_ub^2 + end + + x_sqr = JuMP.@variable(pm.model, + base_name="$(nw)_$(var_name)_sqr_$(id)", + lower_bound = x_sqr_lb, + upper_bound = x_sqr_ub, + start = 0.0 + ) + JuMP.@constraint(pm.model, [0.5, x_sqr, x] in JuMP.RotatedSecondOrderCone()) + + return cost_terms[1] + cost_terms[2]*x + cost_terms[3]*x_sqr + else # length(cost_terms) >= 4 + Memento.error(_LOGGER, "the network cost data features a polynomial cost function that is not compatible with conic mathematical programs.") + end +end + +# note that `cost_terms` should be providing in ascending order (the reverse of the Matpower spec.) +function _polynomial_cost_expression(pm::AbstractPowerModel, x_list, cost_terms; nw=0, id=1, var_name="x") + x = JuMP.@NLexpression(pm.model, sum(x for x in x_list)) + if length(cost_terms) == 0 + return 0.0 + elseif length(cost_terms) == 1 + return cost_terms[1] + elseif length(cost_terms) == 2 + return JuMP.@NLexpression(pm.model, cost_terms[1] + cost_terms[2]*x) + elseif length(cost_terms) == 3 + return JuMP.@NLexpression(pm.model, cost_terms[1] + cost_terms[2]*x + cost_terms[3]*x^2) + else # length(cost_terms) >= 4 + cost_nl = cost_terms[4:end] + return JuMP.@NLexpression(pm.model, cost_terms[1] + cost_terms[2]*x + cost_terms[3]*x^2 + sum( v*x^(d+2) for (d,v) in enumerate(cost_nl)) ) + end +end + + + + + + function objective_max_loadability(pm::AbstractPowerModel) nws = nw_ids(pm) - @assert all(!ismulticonductor(pm, n) for n in nws) - z_demand = Dict(n => var(pm, n, :z_demand) for n in nws) z_shunt = Dict(n => var(pm, n, :z_shunt) for n in nws) time_elapsed = Dict(n => get(ref(pm, n), :time_elapsed, 1) for n in nws) diff --git a/src/core/ref.jl b/src/core/ref.jl index 536d47164..c75513a28 100644 --- a/src/core/ref.jl +++ b/src/core/ref.jl @@ -8,7 +8,7 @@ end "compute bus pair level data, can be run on data or ref data structures" -function calc_buspair_parameters(buses, branches, conductor_ids, ismulticondcutor) +function calc_buspair_parameters(buses, branches) bus_lookup = Dict(bus["index"] => bus for (i,bus) in buses if bus["bus_type"] != 4) branch_lookup = Dict(branch["index"] => branch for (i,branch) in branches if branch["br_status"] == 1 && haskey(bus_lookup, branch["f_bus"]) && haskey(bus_lookup, branch["t_bus"])) @@ -17,28 +17,15 @@ function calc_buspair_parameters(buses, branches, conductor_ids, ismulticondcuto bp_branch = Dict((bp, typemax(Int)) for bp in buspair_indexes) - if ismulticondcutor - bp_angmin = Dict((bp, [-Inf for c in conductor_ids]) for bp in buspair_indexes) - bp_angmax = Dict((bp, [ Inf for c in conductor_ids]) for bp in buspair_indexes) - else - @assert(length(conductor_ids) == 1) - bp_angmin = Dict((bp, -Inf) for bp in buspair_indexes) - bp_angmax = Dict((bp, Inf) for bp in buspair_indexes) - end + bp_angmin = Dict((bp, -Inf) for bp in buspair_indexes) + bp_angmax = Dict((bp, Inf) for bp in buspair_indexes) for (l,branch) in branch_lookup i = branch["f_bus"] j = branch["t_bus"] - if ismulticondcutor - for c in conductor_ids - bp_angmin[(i,j)][c] = max(bp_angmin[(i,j)][c], branch["angmin"][c]) - bp_angmax[(i,j)][c] = min(bp_angmax[(i,j)][c], branch["angmax"][c]) - end - else - bp_angmin[(i,j)] = max(bp_angmin[(i,j)], branch["angmin"]) - bp_angmax[(i,j)] = min(bp_angmax[(i,j)], branch["angmax"]) - end + bp_angmin[(i,j)] = max(bp_angmin[(i,j)], branch["angmin"]) + bp_angmax[(i,j)] = min(bp_angmax[(i,j)], branch["angmax"]) bp_branch[(i,j)] = min(bp_branch[(i,j)], l) end diff --git a/src/core/solution.jl b/src/core/solution.jl index e67add962..3d8064485 100644 --- a/src/core/solution.jl +++ b/src/core/solution.jl @@ -4,10 +4,6 @@ function _IM.solution_preprocessor(pm::AbstractPowerModel, solution::Dict) for (nw_id, nw_ref) in nws(pm) solution["it"][pm_it_name]["nw"]["$(nw_id)"]["baseMVA"] = nw_ref[:baseMVA] - - if ismulticonductor(pm, nw_id) - solution["it"][pm_it_name]["nw"]["$(nw_id)"]["conductors"] = nw_ref[:conductors] - end end end diff --git a/src/form/acp.jl b/src/form/acp.jl index 2d9820e96..7b5313053 100644 --- a/src/form/acp.jl +++ b/src/form/acp.jl @@ -28,16 +28,20 @@ function constraint_voltage_magnitude_setpoint(pm::AbstractACPModel, n::Int, i:: end -function constraint_current_limit(pm::AbstractACPModel, n::Int, f_idx, c_rating_a) +function constraint_current_limit_from(pm::AbstractACPModel, n::Int, f_idx, c_rating_a) l,i,j = f_idx - t_idx = (l,j,i) vm_fr = var(pm, n, :vm, i) - vm_to = var(pm, n, :vm, j) p_fr = var(pm, n, :p, f_idx) q_fr = var(pm, n, :q, f_idx) JuMP.@constraint(pm.model, p_fr^2 + q_fr^2 <= vm_fr^2*c_rating_a^2) +end + +function constraint_current_limit_to(pm::AbstractACPModel, n::Int, t_idx, c_rating_a) + l,j,i = t_idx + + vm_to = var(pm, n, :vm, j) p_to = var(pm, n, :p, t_idx) q_to = var(pm, n, :q, t_idx) @@ -533,8 +537,7 @@ function constraint_ne_voltage_angle_difference(pm::AbstractACPModel, n::Int, f_ va_to = var(pm, n, :va, t_bus) z = var(pm, n, :branch_ne, i) - JuMP.@constraint(pm.model, z*(va_fr - va_to) <= angmax) - JuMP.@constraint(pm.model, z*(va_fr - va_to) >= angmin) + JuMP.@constraint(pm.model, angmin <= z*(va_fr - va_to) <= angmax) end """ @@ -571,7 +574,7 @@ end "" -function constraint_storage_losses(pm::AbstractACPModel, n::Int, i, bus, r, x, p_loss, q_loss; conductors=[1]) +function constraint_storage_losses(pm::AbstractACPModel, n::Int, i, bus, r, x, p_loss, q_loss) vm = var(pm, n, :vm, bus) ps = var(pm, n, :ps, i) qs = var(pm, n, :qs, i) @@ -579,15 +582,7 @@ function constraint_storage_losses(pm::AbstractACPModel, n::Int, i, bus, r, x, p sd = var(pm, n, :sd, i) qsc = var(pm, n, :qsc, i) - JuMP.@NLconstraint(pm.model, - sum(ps[c] for c in conductors) + (sd - sc) - == - p_loss + sum(r[c]*(ps[c]^2 + qs[c]^2)/vm[c]^2 for c in conductors) - ) - - JuMP.@NLconstraint(pm.model, - sum(qs[c] for c in conductors) - == - qsc + q_loss + sum(x[c]*(ps[c]^2 + qs[c]^2)/vm[c]^2 for c in conductors) - ) + JuMP.@NLconstraint(pm.model, ps + (sd - sc) == p_loss + r*(ps^2 + qs^2)/vm^2) + JuMP.@NLconstraint(pm.model, qs == qsc + q_loss + x*(ps^2 + qs^2)/vm^2) end + diff --git a/src/form/acr.jl b/src/form/acr.jl index 2c6a93b10..57cff7dea 100644 --- a/src/form/acr.jl +++ b/src/form/acr.jl @@ -30,8 +30,7 @@ function constraint_voltage_magnitude_bounds(pm::AbstractACRModel, n::Int, i, vm vr = var(pm, n, :vr, i) vi = var(pm, n, :vi, i) - JuMP.@constraint(pm.model, vmin^2 <= (vr^2 + vi^2)) - JuMP.@constraint(pm.model, vmax^2 >= (vr^2 + vi^2)) + JuMP.@constraint(pm.model, vmin^2 <= (vr^2 + vi^2) <= vmax^2) end "`v[i] == vm`" @@ -218,7 +217,7 @@ end "" -function constraint_storage_losses(pm::AbstractACRModel, n::Int, i, bus, r, x, p_loss, q_loss; conductors=[1]) +function constraint_storage_losses(pm::AbstractACRModel, n::Int, i, bus, r, x, p_loss, q_loss) vr = var(pm, n, :vr, bus) vi = var(pm, n, :vi, bus) ps = var(pm, n, :ps, i) @@ -227,32 +226,27 @@ function constraint_storage_losses(pm::AbstractACRModel, n::Int, i, bus, r, x, p sd = var(pm, n, :sd, i) qsc = var(pm, n, :qsc, i) - JuMP.@NLconstraint(pm.model, - sum(ps[c] for c in conductors) + (sd - sc) - == - p_loss + sum(r[c]*(ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for c in conductors) - ) - - JuMP.@NLconstraint(pm.model, - sum(qs[c] for c in conductors) - == - qsc + q_loss + sum(x[c]*(ps[c]^2 + qs[c]^2)/(vr[c]^2 + vi[c]^2) for c in conductors) - ) + JuMP.@NLconstraint(pm.model, ps + (sd - sc) == p_loss + r*(ps^2 + qs^2)/(vr^2 + vi^2)) + JuMP.@NLconstraint(pm.model, qs == qsc + q_loss + x*(ps^2 + qs^2)/(vr^2 + vi^2)) end -function constraint_current_limit(pm::AbstractACRModel, n::Int, f_idx, c_rating_a) +function constraint_current_limit_from(pm::AbstractACRModel, n::Int, f_idx, c_rating_a) l,i,j = f_idx - t_idx = (l,j,i) vr_fr = var(pm, n, :vr, i) - vr_to = var(pm, n, :vr, j) vi_fr = var(pm, n, :vi, i) - vi_to = var(pm, n, :vi, j) p_fr = var(pm, n, :p, f_idx) q_fr = var(pm, n, :q, f_idx) JuMP.@constraint(pm.model, p_fr^2 + q_fr^2 <= (vr_fr^2 + vi_fr^2)*c_rating_a^2) +end + +function constraint_current_limit_to(pm::AbstractACRModel, n::Int, t_idx, c_rating_a) + l,j,i = t_idx + + vr_to = var(pm, n, :vr, j) + vi_to = var(pm, n, :vi, j) p_to = var(pm, n, :p, t_idx) q_to = var(pm, n, :q, t_idx) diff --git a/src/form/act.jl b/src/form/act.jl index 5124c2e92..ddac3cd00 100644 --- a/src/form/act.jl +++ b/src/form/act.jl @@ -84,6 +84,5 @@ function constraint_voltage_angle_difference(pm::AbstractACTModel, n::Int, f_idx va_fr = var(pm, n, :va)[f_bus] va_to = var(pm, n, :va)[t_bus] - JuMP.@constraint(pm.model, va_fr - va_to <= angmax) - JuMP.@constraint(pm.model, va_fr - va_to >= angmin) + JuMP.@constraint(pm.model, angmin <= va_fr - va_to <= angmax) end diff --git a/src/form/apo.jl b/src/form/apo.jl index 821b543aa..1f07cd994 100644 --- a/src/form/apo.jl +++ b/src/form/apo.jl @@ -202,15 +202,35 @@ function constraint_thermal_limit_to(pm::AbstractActivePowerModel, n::Int, t_idx end end + "" -function constraint_current_limit(pm::AbstractActivePowerModel, n::Int, f_idx, c_rating_a) +function constraint_current_limit_from(pm::AbstractActivePowerModel, n::Int, f_idx, c_rating_a) p_fr = var(pm, n, :p, f_idx) + if isa(p_fr, JuMP.VariableRef) && JuMP.has_lower_bound(p_fr) + JuMP.lower_bound(p_fr) < -c_rating_a && JuMP.set_lower_bound(p_fr, -c_rating_a) + if JuMP.has_upper_bound(p_fr) + JuMP.upper_bound(p_fr) > c_rating_a && JuMP.set_upper_bound(p_fr, c_rating_a) + end + else + JuMP.@constraint(pm.model, p_fr <= c_rating_a) + end +end - JuMP.lower_bound(p_fr) < -c_rating_a && JuMP.set_lower_bound(p_fr, -c_rating_a) - JuMP.upper_bound(p_fr) > c_rating_a && JuMP.set_upper_bound(p_fr, c_rating_a) +"" +function constraint_current_limit_to(pm::AbstractActivePowerModel, n::Int, t_idx, c_rating_a) + p_to = var(pm, n, :p, t_idx) + if isa(p_to, JuMP.VariableRef) && JuMP.has_lower_bound(p_to) + JuMP.lower_bound(p_to) < -c_rating_a && JuMP.set_lower_bound(p_to, -c_rating_a) + if JuMP.has_upper_bound(p_to) + JuMP.upper_bound(p_to) > c_rating_a && JuMP.set_upper_bound(p_to, c_rating_a) + end + else + JuMP.@constraint(pm.model, p_to <= c_rating_a) + end end + "" function constraint_thermal_limit_from_on_off(pm::AbstractActivePowerModel, n::Int, i, f_idx, rate_a) p_fr = var(pm, n, :p, f_idx) @@ -276,16 +296,12 @@ function constraint_storage_current_limit(pm::AbstractActivePowerModel, n::Int, end "" -function constraint_storage_losses(pm::AbstractActivePowerModel, n::Int, i, bus, r, x, p_loss, q_loss; conductors=[1]) +function constraint_storage_losses(pm::AbstractActivePowerModel, n::Int, i, bus, r, x, p_loss, q_loss) ps = var(pm, n, :ps, i) sc = var(pm, n, :sc, i) sd = var(pm, n, :sd, i) - JuMP.@constraint(pm.model, - sum(ps[c] for c in conductors) + (sd - sc) - == - p_loss + sum(r[c]*ps[c]^2 for c in conductors) - ) + JuMP.@constraint(pm.model, ps + (sd - sc) == p_loss + r*ps^2) end function constraint_storage_on_off(pm::AbstractActivePowerModel, n::Int, i, pmin, pmax, qmin, qmax, charge_ub, discharge_ub) diff --git a/src/form/bf.jl b/src/form/bf.jl index cde93e9af..fbbd9df7f 100644 --- a/src/form/bf.jl +++ b/src/form/bf.jl @@ -192,23 +192,13 @@ end "Neglects the active and reactive loss terms associated with the squared current magnitude." -function constraint_storage_losses(pm::AbstractBFAModel, n::Int, i, bus, r, x, p_loss, q_loss; conductors=[1]) +function constraint_storage_losses(pm::AbstractBFAModel, n::Int, i, bus, r, x, p_loss, q_loss) ps = var(pm, n, :ps, i) qs = var(pm, n, :qs, i) sc = var(pm, n, :sc, i) sd = var(pm, n, :sd, i) qsc = var(pm, n, :qsc, i) - - JuMP.@constraint(pm.model, - sum(ps[c] for c in conductors) + (sd - sc) - == - p_loss - ) - - JuMP.@constraint(pm.model, - sum(qs[c] for c in conductors) - == - qsc + q_loss - ) + JuMP.@constraint(pm.model, ps + (sd - sc) == p_loss) + JuMP.@constraint(pm.model, qs == qsc + q_loss) end diff --git a/src/form/dcp.jl b/src/form/dcp.jl index 6fd1520ce..146237a66 100644 --- a/src/form/dcp.jl +++ b/src/form/dcp.jl @@ -365,12 +365,12 @@ function constraint_storage_on_off(pm::AbstractAPLossLessModels, n::Int, i, pmin end "" -function constraint_storage_losses(pm::AbstractAPLossLessModels, n::Int, i, bus, r, x, p_loss, q_loss; conductors=[1]) +function constraint_storage_losses(pm::AbstractAPLossLessModels, n::Int, i, bus, r, x, p_loss, q_loss) ps = var(pm, n, :ps, i) sc = var(pm, n, :sc, i) sd = var(pm, n, :sd, i) - JuMP.@constraint(pm.model, sum(ps[c] for c in conductors) + (sd - sc) == p_loss) + JuMP.@constraint(pm.model, ps + (sd - sc) == p_loss) end diff --git a/src/form/iv.jl b/src/form/iv.jl index ca49d5bf2..bb4fa7c2b 100644 --- a/src/form/iv.jl +++ b/src/form/iv.jl @@ -169,8 +169,8 @@ function constraint_voltage_angle_difference(pm::AbstractIVRModel, n::Int, f_idx vvr = vr_fr*vr_to + vi_fr*vi_to vvi = vi_fr*vr_to - vr_fr*vi_to - JuMP.@constraint(pm.model, tan(angmin)*vvr <= vvi) - JuMP.@constraint(pm.model, tan(angmax)*vvr >= vvi) + JuMP.@constraint(pm.model, vvi <= tan(angmax)*vvr) + JuMP.@constraint(pm.model, vvi >= tan(angmin)*vvr) end """ @@ -230,24 +230,26 @@ function constraint_thermal_limit_to(pm::AbstractIVRModel, n::Int, t_idx, rate_a end """ -Bounds the current magnitude at both from and to side of a branch -`cr[f_idx]^2 + ci[f_idx]^2 <= c_rating^2` -`cr[t_idx]^2 + ci[t_idx]^2 <= c_rating^2` +Bounds the current magnitude at the from side of a branch """ -function constraint_current_limit(pm::AbstractIVRModel, n::Int, f_idx, c_rating) - (l, f_bus, t_bus) = f_idx - t_idx = (l, t_bus, f_bus) - +function constraint_current_limit_from(pm::AbstractIVRModel, n::Int, f_idx, c_rating) crf = var(pm, n, :cr, f_idx) cif = var(pm, n, :ci, f_idx) + JuMP.@constraint(pm.model, crf^2 + cif^2 <= c_rating^2) +end + +""" +Bounds the current magnitude at the to side of a branch +""" +function constraint_current_limit_to(pm::AbstractIVRModel, n::Int, t_idx, c_rating) crt = var(pm, n, :cr, t_idx) cit = var(pm, n, :ci, t_idx) - JuMP.@constraint(pm.model, crf^2 + cif^2 <= c_rating^2) JuMP.@constraint(pm.model, crt^2 + cit^2 <= c_rating^2) end + """ `pmin <= Re(v*cg') <= pmax` """ @@ -259,8 +261,7 @@ function constraint_gen_active_bounds(pm::AbstractIVRModel, n::Int, i, bus, pmax cr = var(pm, n, :crg, i) ci = var(pm, n, :cig, i) - JuMP.@constraint(pm.model, pmin <= vr*cr + vi*ci) - JuMP.@constraint(pm.model, pmax >= vr*cr + vi*ci) + JuMP.@constraint(pm.model, pmin <= vr*cr + vi*ci <= pmax) end """ @@ -274,8 +275,7 @@ function constraint_gen_reactive_bounds(pm::AbstractIVRModel, n::Int, i, bus, qm cr = var(pm, n, :crg, i) ci = var(pm, n, :cig, i) - JuMP.@constraint(pm.model, qmin <= vi*cr - vr*ci) - JuMP.@constraint(pm.model, qmax >= vi*cr - vr*ci) + JuMP.@constraint(pm.model, qmin <= vi*cr - vr*ci <= qmax) end "`pg[i] == pg`" @@ -332,11 +332,8 @@ function constraint_dcline_power_fr_bounds(pm::AbstractIVRModel, n::Int, i, f_bu p_fr = vr_fr*crdc_fr + vi_fr*cidc_fr q_fr = vi_fr*crdc_fr - vr_fr*cidc_fr - JuMP.@constraint(pm.model, pmax >= p_fr) - JuMP.@constraint(pm.model, pmin <= p_fr) - - JuMP.@constraint(pm.model, qmax >= q_fr) - JuMP.@constraint(pm.model, qmin <= q_fr) + JuMP.@constraint(pm.model, pmin <= p_fr <= pmax) + JuMP.@constraint(pm.model, qmin <= q_fr <= qmax) end @@ -351,11 +348,8 @@ function constraint_dcline_power_to_bounds(pm::AbstractIVRModel, n::Int, i, t_bu p_to = vr_to*crdc_to + vi_to*cidc_to q_to = vi_to*crdc_to - vr_to*cidc_to - JuMP.@constraint(pm.model, pmax >= p_to) - JuMP.@constraint(pm.model, pmin <= p_to) - - JuMP.@constraint(pm.model, qmax >= q_to) - JuMP.@constraint(pm.model, qmin <= q_to) + JuMP.@constraint(pm.model, pmin <= p_to <= pmax) + JuMP.@constraint(pm.model, qmin <= q_to <= qmax) end "`p_fr[i] == pref_fr, p_to[i] == pref_to`" @@ -378,100 +372,3 @@ function constraint_dcline_setpoint_active(pm::AbstractIVRModel, n::Int, f_idx, end -function _objective_min_fuel_and_flow_cost_polynomial_linquad(pm::AbstractIVRModel; report::Bool=true) - gen_cost = Dict() - dcline_cost = Dict() - - for (n, nw_ref) in nws(pm) - for (i,gen) in nw_ref[:gen] - bus = gen["gen_bus"] - - #to avoid function calls inside of @NLconstraint: - pg = [var(pm, n, :pg, i) for c in conductor_ids(pm, n)] - nc = length(conductor_ids(pm, n)) - if length(gen["cost"]) == 1 - gen_cost[(n,i)] = gen["cost"][1] - elseif length(gen["cost"]) == 2 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, gen["cost"][1]*sum(pg[c] for c in 1:nc) + gen["cost"][2]) - elseif length(gen["cost"]) == 3 - gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, gen["cost"][1]*sum(pg[c] for c in 1:nc)^2 + gen["cost"][2]*sum(pg[c] for c in 1:nc) + gen["cost"][3]) - else - gen_cost[(n,i)] = 0.0 - end - end - - from_idx = Dict(arc[1] => arc for arc in nw_ref[:arcs_from_dc]) - for (i,dcline) in nw_ref[:dcline] - bus = dcline["f_bus"] - #to avoid function calls inside of @NLconstraint: - p_dc = [var(pm, n, :p_dc, from_idx[i]) for c in conductor_ids(pm, n)] - nc = length(conductor_ids(pm, n)) - - if length(dcline["cost"]) == 1 - dcline_cost[(n,i)] = dcline["cost"][1] - elseif length(dcline["cost"]) == 2 - dcline_cost[(n,i)] = JuMP.@NLexpression(pm.model, dcline["cost"][1]*sum(p_dc[c] for c in 1:nc) + dcline["cost"][2]) - elseif length(dcline["cost"]) == 3 - dcline_cost[(n,i)] = JuMP.@NLexpression(pm.model, dcline["cost"][1]*sum(p_dc[c] for c in 1:nc)^2 + dcline["cost"][2]*sum(p_dc[c] for c in 1:nc) + dcline["cost"][3]) - else - dcline_cost[(n,i)] = 0.0 - end - end - end - - return JuMP.@NLobjective(pm.model, Min, - sum( - sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen] ) - + sum( dcline_cost[(n,i)] for (i,dcline) in nw_ref[:dcline] ) - for (n, nw_ref) in nws(pm)) - ) -end - - -"adds pg_cost variables and constraints" -function objective_variable_pg_cost(pm::AbstractIVRModel; report::Bool=true) - for (n, nw_ref) in nws(pm) - gen_lines = calc_cost_pwl_lines(nw_ref[:gen]) - - #to avoid function calls inside of @NLconstraint - pg_cost = var(pm, n)[:pg_cost] = JuMP.@variable(pm.model, - [i in ids(pm, n, :gen)], base_name="$(n)_pg_cost", - ) - report && sol_component_value(pm, n, :gen, :pg_cost, ids(pm, n, :gen), pg_cost) - - nc = length(conductor_ids(pm, n)) - - # gen pwl cost - for (i, gen) in nw_ref[:gen] - pg = [var(pm, n, :pg, i) for c in conductor_ids(pm, n)] - for line in gen_lines[i] - JuMP.@NLconstraint(pm.model, pg_cost[i] >= line.slope*sum(pg[c] for c in 1:nc) + line.intercept) - end - end - end -end - - -"adds p_dc_cost variables and constraints" -function objective_variable_dc_cost(pm::AbstractIVRModel; report::Bool=true) - for (n, nw_ref) in nws(pm) - dcline_lines = calc_cost_pwl_lines(nw_ref[:dcline]) - - dc_p_cost = var(pm, n)[:p_dc_cost] = JuMP.@variable(pm.model, - [i in ids(pm, n, :dcline)], base_name="$(n)_dc_p_cost", - ) - report && sol_component_value(pm, n, :dcline, :p_dc_cost, ids(pm, n, :dcline), dc_p_cost) - - #to avoid function calls inside of @NLconstraint: - nc = length(conductor_ids(pm, n)) - # dcline pwl cost - for (i, dcline) in nw_ref[:dcline] - arc = (i, dcline["f_bus"], dcline["t_bus"]) - for line in dcline_lines[i] - #to avoid function calls inside of @NLconstraint: - p_dc = [var(pm, n, :p_dc, arc) for c in conductor_ids(pm, n)] - JuMP.@NLconstraint(pm.model, dc_p_cost[i] >= line.slope*sum(p_dc[c] for c in 1:nc) + line.intercept) - end - end - end -end diff --git a/src/form/shared.jl b/src/form/shared.jl index dbfd65171..1c4f14b45 100644 --- a/src/form/shared.jl +++ b/src/form/shared.jl @@ -66,25 +66,17 @@ function variable_storage_current(pm::AbstractWConvexModels; nw::Int=nw_id_defau end -"`t[ref_bus] == 0`" function constraint_theta_ref(pm::AbstractPolarModels, n::Int, i::Int) JuMP.@constraint(pm.model, var(pm, n, :va)[i] == 0) end -""" -``` -t[f_bus] - t[t_bus] <= angmax -t[f_bus] - t[t_bus] >= angmin -``` -""" function constraint_voltage_angle_difference(pm::AbstractPolarModels, n::Int, f_idx, angmin, angmax) i, f_bus, t_bus = f_idx va_fr = var(pm, n, :va, f_bus) va_to = var(pm, n, :va, t_bus) - JuMP.@constraint(pm.model, va_fr - va_to <= angmax) - JuMP.@constraint(pm.model, va_fr - va_to >= angmin) + JuMP.@constraint(pm.model, angmin <= va_fr - va_to <= angmax) end @@ -335,6 +327,7 @@ function constraint_voltage_angle_difference(pm::AbstractWModels, n::Int, f_idx, JuMP.@constraint(pm.model, wi <= tan(angmax)*wr) JuMP.@constraint(pm.model, wi >= tan(angmin)*wr) + cut_complex_product_and_angle_difference(pm.model, w_fr, w_to, wr, wi, angmin, angmax) end @@ -381,26 +374,31 @@ function constraint_switch_voltage_on_off(pm::AbstractWModels, n::Int, i, f_bus, end - "" -function constraint_current_limit(pm::AbstractWModels, n::Int, f_idx, c_rating_a) +function constraint_current_limit_from(pm::AbstractWModels, n::Int, f_idx, c_rating_a) l,i,j = f_idx - t_idx = (l,j,i) w_fr = var(pm, n, :w, i) - w_to = var(pm, n, :w, j) p_fr = var(pm, n, :p, f_idx) q_fr = var(pm, n, :q, f_idx) JuMP.@constraint(pm.model, p_fr^2 + q_fr^2 <= w_fr*c_rating_a^2) +end + +"" +function constraint_current_limit_to(pm::AbstractWModels, n::Int, t_idx, c_rating_a) + l,j,i = t_idx + + w_to = var(pm, n, :w, j) p_to = var(pm, n, :p, t_idx) q_to = var(pm, n, :q, t_idx) JuMP.@constraint(pm.model, p_to^2 + q_to^2 <= w_to*c_rating_a^2) end + "" -function constraint_storage_losses(pm::AbstractWConvexModels, n::Int, i, bus, r, x, p_loss, q_loss; conductors=[1]) +function constraint_storage_losses(pm::AbstractWConvexModels, n::Int, i, bus, r, x, p_loss, q_loss) w = var(pm, n, :w, bus) ccms = var(pm, n, :ccms, i) ps = var(pm, n, :ps, i) @@ -409,19 +407,7 @@ function constraint_storage_losses(pm::AbstractWConvexModels, n::Int, i, bus, r, sd = var(pm, n, :sd, i) qsc = var(pm, n, :qsc, i) - for c in conductors - JuMP.@constraint(pm.model, ps[c]^2 + qs[c]^2 <= w[c]*ccms[c]) - end - - JuMP.@constraint(pm.model, - sum(ps[c] for c in conductors) + (sd - sc) - == - p_loss + sum(r[c]*ccms[c] for c in conductors) - ) - - JuMP.@constraint(pm.model, - sum(qs[c] for c in conductors) - == - qsc + q_loss + sum(x[c]*ccms[c] for c in conductors) - ) + JuMP.@constraint(pm.model, ps^2 + qs^2 <= w*ccms) + JuMP.@constraint(pm.model, ps + (sd - sc) == p_loss + r*ccms) + JuMP.@constraint(pm.model, qs == qsc + q_loss + x*ccms) end diff --git a/src/form/wrm.jl b/src/form/wrm.jl index d488690e1..ec60600b4 100644 --- a/src/form/wrm.jl +++ b/src/form/wrm.jl @@ -2,17 +2,23 @@ import LinearAlgebra: Hermitian, cholesky, Symmetric, diag, I import SparseArrays: SparseMatrixCSC, sparse, spdiagm, findnz, spzeros, nonzeros + "" -function constraint_current_limit(pm::AbstractWRMModel, n::Int, f_idx, c_rating_a) +function constraint_current_limit_from(pm::AbstractWRMModel, n::Int, f_idx, c_rating_a) l,i,j = f_idx - t_idx = (l,j,i) w_fr = var(pm, n, :w, i) - w_to = var(pm, n, :w, j) p_fr = var(pm, n, :p, f_idx) q_fr = var(pm, n, :q, f_idx) JuMP.@constraint(pm.model, [w_fr*c_rating_a^2+1, 2*p_fr, 2*q_fr, w_fr*c_rating_a^2-1] in JuMP.SecondOrderCone()) +end + +"" +function constraint_current_limit_to(pm::AbstractWRMModel, n::Int, t_idx, c_rating_a) + l,j,i = t_idx + + w_to = var(pm, n, :w, j) p_to = var(pm, n, :p, t_idx) q_to = var(pm, n, :q, t_idx) @@ -21,6 +27,7 @@ end + "" function constraint_model_voltage(pm::AbstractWRMModel, n::Int) _check_missing_keys(var(pm, n), [:WR,:WI], typeof(pm)) diff --git a/src/io/common.jl b/src/io/common.jl index a2ca21235..58a13130a 100644 --- a/src/io/common.jl +++ b/src/io/common.jl @@ -95,7 +95,6 @@ Runs various data quality checks on a PowerModels data dictionary. Applies modifications in some cases. Reports modified component ids. """ function correct_network_data!(data::Dict{String,<:Any}) - check_conductors(data) check_connectivity(data) check_status(data) check_reference_bus(data) diff --git a/src/io/json.jl b/src/io/json.jl index 432d3236d..06590d2f4 100644 --- a/src/io/json.jl +++ b/src/io/json.jl @@ -1,5 +1,4 @@ # Parse PowerModels data from JSON exports of PowerModels data structures. -# Necessary in order to support MultiConductorValues function _jsonver2juliaver!(pm_data) if haskey(pm_data, "source_version") && isa(pm_data["source_version"], Dict) diff --git a/src/io/psse.jl b/src/io/psse.jl index 9e96053f8..f377a0b6c 100644 --- a/src/io/psse.jl +++ b/src/io/psse.jl @@ -276,7 +276,6 @@ function _psse2pm_bus!(pm_data::Dict, pti_data::Dict, import_all::Bool) end end - """ _psse2pm_load!(pm_data, pti_data) @@ -285,18 +284,42 @@ by `["I", "ID"]` in the PSS(R)E Load specification. """ function _psse2pm_load!(pm_data::Dict, pti_data::Dict, import_all::Bool) pm_data["load"] = [] + bus_lookup = Dict{Int, Any}() if haskey(pti_data, "LOAD") for load in pti_data["LOAD"] sub_data = Dict{String,Any}() - sub_data["load_bus"] = pop!(load, "I") sub_data["pd"] = pop!(load, "PL") sub_data["qd"] = pop!(load, "QL") - sub_data["status"] = pop!(load, "STATUS") - sub_data["source_id"] = ["load", sub_data["load_bus"], pop!(load, "ID")] + sub_data["status"] = pop!(load, "STATUS") sub_data["index"] = length(pm_data["load"]) + 1 + # Only build lookup once if necessary + if (load["IP"] != 0.0) || (load["IQ"] != 0.0) || (load["YP"] != 0.0) || (load["YQ"] != 0.0) + if isempty(bus_lookup) + bus_lookup = Dict(bus["index"] => bus for bus in pm_data["bus"]) + end + + bus_vm = bus_lookup[sub_data["load_bus"]]["vm"] + if (load["IP"] != 0.0) || (load["IQ"] != 0.0) + # Uses matpower transformation instead of pd = real(V*I) and qd = imag(V*I) + # where I and V are in vector form. + sub_data["pd"] += bus_vm*load["IP"] + sub_data["qd"] += bus_vm*load["IQ"] + Memento.warn(_LOGGER, "Load id = $(sub_data["index"]) detected as I Load IP = $(load["IP"]) IQ = $(load["IQ"]). Converting to Power Load Pd = $(bus_vm*load["IP"]) Qd = $(bus_vm*load["IQ"]) using Vm = $(bus_vm)") + end + if (load["YP"] != 0.0) || (load["YQ"] != 0.0) + # Uses matpower transformation instead of pd = real(V*(V*Y)^*) and qd = imag(V*(V*Y)^*) + # where Y and V are in vector form. + sub_data["pd"] += bus_vm^2*load["YP"] + # NOTE: In PSSe reactive power in constant admittance loads is negative for inductive loads and positive for capacitive loads + sub_data["qd"] -= bus_vm^2*load["YQ"] + Memento.warn(_LOGGER, "Load id = $(sub_data["index"]) detected as Z Load YP = $(load["YP"]) YQ = $(load["YQ"]). Converting to Power Load Pd = $(bus_vm^2*load["YP"]) Qd = $(-1*bus_vm^2*load["YQ"]) using Vm = $(bus_vm)") + end + + end + if import_all _import_remaining_keys!(sub_data, load) end @@ -609,7 +632,7 @@ function _psse2pm_transformer!(pm_data::Dict, pti_data::Dict, import_all::Bool) sub_data["index"] = length(pm_data["branch"]) + 1 if import_all - _import_remaining_keys!(sub_data, transformer; + _import_remaining_keys!(sub_data, transformer; exclude=["I", "J", "K", "CZ", "CW", "R1-2", "R2-3", "R3-1", "X1-2", "X2-3", "X3-1", "SBASE1-2", "SBASE2-3", "CKT", "SBASE3-1", "MAG1", "MAG2", "STAT","NOMV1", "NOMV2", diff --git a/src/prob/test.jl b/src/prob/test.jl index 11aa5bbec..35a77381d 100644 --- a/src/prob/test.jl +++ b/src/prob/test.jl @@ -36,7 +36,8 @@ function _build_opf_cl(pm::AbstractPowerModel) constraint_voltage_angle_difference(pm, i) - constraint_current_limit(pm, i) + constraint_current_limit_from(pm, i) + constraint_current_limit_to(pm, i) end for i in ids(pm, :dcline) @@ -262,7 +263,7 @@ function _build_mld(pm::AbstractPowerModel) end -"opf with unit commitment, tests constraint_current_limit" +"opf with unit commitment" function _solve_ucopf(file, model_type::Type, solver; kwargs...) return solve_model(file, model_type, solver, _build_ucopf; kwargs...) end diff --git a/src/prob/tnep.jl b/src/prob/tnep.jl index 53b4d6097..7036f1983 100644 --- a/src/prob/tnep.jl +++ b/src/prob/tnep.jl @@ -92,8 +92,6 @@ function _ref_add_ne_branch!(ref::Dict{Symbol,<:Any}, data::Dict{String,<:Any}) ref[:ne_bus_arcs] = ne_bus_arcs if !haskey(ref, :ne_buspairs) - ismc = haskey(ref, :conductors) - cid = ref[:conductor_ids] - ref[:ne_buspairs] = calc_buspair_parameters(ref[:bus], ref[:ne_branch], cid, ismc) + ref[:ne_buspairs] = calc_buspair_parameters(ref[:bus], ref[:ne_branch]) end end diff --git a/src/util/obbt.jl b/src/util/obbt.jl index 0b2e4741c..a6cfa388e 100644 --- a/src/util/obbt.jl +++ b/src/util/obbt.jl @@ -85,7 +85,6 @@ function solve_obbt_opf!(data::Dict{String,<:Any}, optimizer; model_relaxation = instantiate_model(data, model_type, PowerModels.build_opf) (_IM.ismultinetwork(model_relaxation, pm_it_sym)) && (Memento.error(_LOGGER, "OBBT is not supported for multi-networks")) - (ismulticonductor(model_relaxation)) && (Memento.error(_LOGGER, "OBBT is not supported for multi-conductor networks")) # check for model_type compatability with OBBT _check_variables(model_relaxation) @@ -406,7 +405,37 @@ end function _constraint_obj_bound(pm::AbstractPowerModel, bound) - model = PowerModels.check_cost_models(pm) + + model = nothing + for (n, nw_ref) in nws(pm) + for (i,gen) in nw_ref[:gen] + if haskey(gen, "cost") + if model == nothing + model = gen["model"] + else + if gen["model"] != model + Memento.error(_LOGGER, "cost models are inconsistent, the typical model is $(model) however model $(gen["model"]) is given on generator $(i)") + end + end + else + Memento.error(_LOGGER, "no cost given for generator $(i)") + end + end + for (i,dcline) in nw_ref[:dcline] + if haskey(dcline, "model") + if model == nothing + model = dcline["model"] + else + if dcline["model"] != model + Memento.error(_LOGGER, "cost models are inconsistent, the typical model is $(model) however model $(dcline["model"]) is given on dcline $(i)") + end + end + else + Memento.error(_LOGGER, "no cost given for dcline $(i)") + end + end + end + if model != 2 Memento.error(_LOGGER, "Only cost models of type 2 is supported at this time, given cost model type $(model)") end diff --git a/test/data-basic.jl b/test/data-basic.jl index 48cc86180..47f6bcab1 100644 --- a/test/data-basic.jl +++ b/test/data-basic.jl @@ -15,7 +15,7 @@ @test length(data["switch"]) == 0 @test length(data["storage"]) == 0 - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) @test isapprox(result["objective"], 1036.52; atol=1e0) end @@ -31,7 +31,7 @@ @test length(data["switch"]) == 0 @test length(data["storage"]) == 0 - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) @test isapprox(result["objective"], 16551.7; atol=1e0) end @@ -43,7 +43,7 @@ end @testset "basic bus injection" begin data = make_basic_network(PowerModels.parse_file("../test/data/matpower/case14.m")) - result = run_opf(data, DCPPowerModel, nlp_solver) + result = solve_opf(data, DCPPowerModel, nlp_solver) update_data!(data, result["solution"]) bi = calc_basic_bus_injection(data) @@ -51,7 +51,7 @@ end @test isapprox(real(sum(bi)), 0.0; atol=1e-6) - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) update_data!(data, result["solution"]) bi = calc_basic_bus_injection(data) @@ -95,7 +95,7 @@ end @test isapprox(SM_1, SM_2; atol=1e-6) - result = run_opf(data, DCPPowerModel, nlp_solver) + result = solve_opf(data, DCPPowerModel, nlp_solver) update_data!(data, result["solution"]) va = angle.(calc_basic_bus_voltage(data)) @@ -155,7 +155,7 @@ end @test isapprox(sum(P), 0.9894736; atol=1e-6) - result = run_opf(data, DCPPowerModel, nlp_solver) + result = solve_opf(data, DCPPowerModel, nlp_solver) update_data!(data, result["solution"]) bi = real(calc_basic_bus_injection(data)) diff --git a/test/data-mc.jl b/test/data-mc.jl deleted file mode 100644 index ec8cf1bfb..000000000 --- a/test/data-mc.jl +++ /dev/null @@ -1,13 +0,0 @@ -@testset "test multiconductor data" begin - - @testset "multiconductor calc_theta_delta_bounds" begin - data = PowerModels.parse_file("../test/data/matpower/case5.m") - data["conductors"] = 1 - - theta_lb, theta_ub = calc_theta_delta_bounds(data) - - @test theta_lb[1] <= -2.0 - @test theta_ub[1] >= 2.0 - end - -end \ No newline at end of file diff --git a/test/data.jl b/test/data.jl index 7cf6d999d..006f43799 100644 --- a/test/data.jl +++ b/test/data.jl @@ -30,7 +30,7 @@ TESTLOG = Memento.getlogger(PowerModels) end @testset "5-bus solution summary from dict" begin - result = run_ac_opf("../test/data/matpower/case5.m", nlp_solver) + result = solve_ac_opf("../test/data/matpower/case5.m", nlp_solver) output = sprint(PowerModels.summary, result["solution"]) line_count = count(c -> c == '\n', output) @@ -128,7 +128,7 @@ end @testset "3-bus case solution" begin - result = run_ac_opf("../test/data/matpower/case3.m", nlp_solver) + result = solve_ac_opf("../test/data/matpower/case3.m", nlp_solver) result_base = deepcopy(result) PowerModels.make_mixed_units!(result["solution"]) @@ -137,7 +137,7 @@ end @test InfrastructureModels.compare_dict(result, result_base) end @testset "5-bus case solution" begin - result = run_ac_opf("../test/data/matpower/case5_asym.m", nlp_solver) + result = solve_ac_opf("../test/data/matpower/case5_asym.m", nlp_solver) result_base = deepcopy(result) PowerModels.make_mixed_units!(result["solution"]) @@ -146,7 +146,7 @@ end @test InfrastructureModels.compare_dict(result, result_base) end @testset "24-bus case solution" begin - result = run_ac_opf("../test/data/matpower/case24.m", nlp_solver) + result = solve_ac_opf("../test/data/matpower/case24.m", nlp_solver) result_base = deepcopy(result) PowerModels.make_mixed_units!(result["solution"]) @@ -157,7 +157,7 @@ end @testset "5-bus case solution with duals" begin - result = run_dc_opf("../test/data/matpower/case5.m", nlp_solver, setting = Dict("output" => Dict("duals" => true))) + result = solve_dc_opf("../test/data/matpower/case5.m", nlp_solver, setting = Dict("output" => Dict("duals" => true))) result_base = deepcopy(result) PowerModels.make_mixed_units!(result["solution"]) @@ -437,7 +437,7 @@ end @testset "output values" begin data = PowerModels.parse_file("../test/data/matpower/case7_tplgy.m") PowerModels.simplify_network!(data) - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 1778; atol = 1e0) @@ -593,8 +593,8 @@ end @testset "5-bus test" begin data = PowerModels.parse_file("../test/data/matpower/case5.m") data["branch"]["4"]["br_status"] = 0 - data["buspairs"] = PowerModels.calc_buspair_parameters(data["bus"], data["branch"], 1:1, false) - result = run_opf(data, ACPPowerModel, nlp_solver) + data["buspairs"] = PowerModels.calc_buspair_parameters(data["bus"], data["branch"]) + result = solve_opf(data, ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 16642; atol = 1e0) @@ -608,7 +608,7 @@ end @testset "5-bus ac polar flow" begin data = PowerModels.parse_file("../test/data/matpower/case5.m") data["branch"]["4"]["br_status"] = 0 - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) PowerModels.update_data!(data, result["solution"]) ac_flows = PowerModels.calc_branch_flow_ac(data) @@ -626,7 +626,7 @@ end @testset "5-bus ac rect flow" begin data = PowerModels.parse_file("../test/data/matpower/case5.m") data["branch"]["4"]["br_status"] = 0 - result = run_opf(data, ACRPowerModel, nlp_solver, solution_processors=[sol_data_model!]) + result = solve_opf(data, ACRPowerModel, nlp_solver, solution_processors=[sol_data_model!]) PowerModels.update_data!(data, result["solution"]) ac_flows = PowerModels.calc_branch_flow_ac(data) @@ -644,7 +644,7 @@ end @testset "5-bus dc flow" begin data = PowerModels.parse_file("../test/data/matpower/case5.m") data["branch"]["4"]["br_status"] = 0 - result = run_opf(data, DCPPowerModel, nlp_solver) + result = solve_opf(data, DCPPowerModel, nlp_solver) PowerModels.update_data!(data, result["solution"]) dc_flows = PowerModels.calc_branch_flow_dc(data) @@ -666,7 +666,7 @@ end @testset "5-bus polynomial gen cost" begin data = PowerModels.parse_file("../test/data/matpower/case5.m") - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) PowerModels.update_data!(data, result["solution"]) gen_cost = PowerModels.calc_gen_cost(data) @@ -681,7 +681,7 @@ end @test isa(gen["ncost"], Int) end - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) PowerModels.update_data!(data, result["solution"]) gen_cost = PowerModels.calc_gen_cost(data) @@ -691,7 +691,7 @@ end @testset "5-bus polynomial gen and dcline cost" begin data = PowerModels.parse_file("../test/data/matpower/case5_dc.m") - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) PowerModels.update_data!(data, result["solution"]) gen_cost = PowerModels.calc_gen_cost(data) @@ -704,7 +704,7 @@ end data["gen"]["1"]["gen_status"] = 0 data["dcline"]["1"]["br_status"] = 0 - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) PowerModels.update_data!(data, result["solution"]) gen_cost = PowerModels.calc_gen_cost(data) @@ -720,7 +720,7 @@ end @testset "5-bus ac polar balance" begin data = PowerModels.parse_file("../test/data/matpower/case5_dc.m") data["branch"]["4"]["br_status"] = 0 - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) PowerModels.update_data!(data, result["solution"]) balance = PowerModels.calc_power_balance(data) @@ -734,7 +734,7 @@ end @testset "5-bus dc balance" begin data = PowerModels.parse_file("../test/data/matpower/case5_dc.m") data["branch"]["4"]["br_status"] = 0 - result = run_opf(data, DCPPowerModel, nlp_solver) + result = solve_opf(data, DCPPowerModel, nlp_solver) PowerModels.update_data!(data, result["solution"]) balance = PowerModels.calc_power_balance(data) @@ -778,7 +778,7 @@ end @testset "5-bus balance from flow ac" begin data = PowerModels.parse_file("../test/data/matpower/case5_dc.m") data["branch"]["4"]["br_status"] = 0 - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) PowerModels.update_data!(data, result["solution"]) flows = PowerModels.calc_branch_flow_ac(data) @@ -795,7 +795,7 @@ end @testset "5-bus balance from flow dc" begin data = PowerModels.parse_file("../test/data/matpower/case5_dc.m") data["branch"]["4"]["br_status"] = 0 - result = run_opf(data, DCPPowerModel, nlp_solver) + result = solve_opf(data, DCPPowerModel, nlp_solver) PowerModels.update_data!(data, result["solution"]) flows = PowerModels.calc_branch_flow_dc(data) @@ -816,11 +816,11 @@ end @testset "test renumber bus ids" begin @testset "5-bus with dcline" begin data = PowerModels.parse_file("../test/data/matpower/case5_dc.m") - result_1 = run_opf(data, ACPPowerModel, nlp_solver) + result_1 = solve_opf(data, ACPPowerModel, nlp_solver) update_bus_ids!(data, Dict(1 => 10, 2=>20, 3=>30, 4=>40, 5=>50)) - result_2 = run_opf(data, ACPPowerModel, nlp_solver) + result_2 = solve_opf(data, ACPPowerModel, nlp_solver) @test isapprox(result_1["objective"], result_2["objective"]; atol=1e-6) end @@ -845,7 +845,7 @@ end @test length(data["switch"]) == 0 @test length(data["bus"]) == 4 - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) @test isapprox(result["objective"], 16641.20; atol=1e0) end diff --git a/test/data/matpower/case5_pwlc.m b/test/data/matpower/case5_pwlc.m index 413825ee5..baf133485 100755 --- a/test/data/matpower/case5_pwlc.m +++ b/test/data/matpower/case5_pwlc.m @@ -17,11 +17,12 @@ %% generator data % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin mpc.gen = [ - 1 40.0 30.0 30.0 -30.0 1.07762 100.0 1 40.0 0.0; - 1 170.0 127.5 127.5 -127.5 1.07762 100.0 1 170.0 50.0; - 3 324.498 390.0 390.0 -390.0 1.1 100.0 1 520.0 100.0; - 4 0.0 -10.802 150.0 -150.0 1.06414 100.0 1 200.0 50.0; - 10 470.694 -165.039 450.0 -450.0 1.06907 100.0 1 600.0 60.0; + 1 40.0 30.0 30.0 -30.0 1.07762 100.0 1 40.0 0.0; + 1 170.0 127.5 127.5 -127.5 1.07762 100.0 1 170.0 50.0; + 3 324.0 0.0 0.0 0.0 1.10000 100.0 1 520.0 100.0; + 3 0.0 390.0 390.0 -390.0 1.10000 100.0 1 0.0 0.0; + 4 0.0 -10.8 150.0 -150.0 1.06414 100.0 1 200.0 50.0; + 10 470.0 -165.0 450.0 -450.0 1.06907 100.0 1 600.0 60.0; ]; %% generator cost data @@ -30,6 +31,7 @@ 1 0.0 0.0 4 -0.1 0.0 0.0 0.0 0.1 0.0 0.2 0.0 2.0; % tests zero cost 1 0.0 0.0 4 0.0 841.0 20.0 841.0 100.0 841.0 150.0 841.0 2.0; % tests constant cost 1 0.0 0.0 4.0 170.0 4772.0 231.0 6203.0 293.0 7855.0 355.0 9738.0 2.0; % tests poorly typed ncost value + 1 0.0 0.0 4 0.0 10.0 0.0 10.0 0.0 10.0 0.0 10.0 2.0; % tests zero constant cost, no active power domain 1 0.0 0.0 4 22.0 1122.0 33.0 1417.0 44.0 1742.0 55.0 2075.0 2.0; 1 0.0 0.0 4 7.0 897.0 7.0 897.0 9.0 1479.0 10.0 1791.0 2.0; ]; diff --git a/test/data/pti/parser_test_k.raw b/test/data/pti/parser_test_k.raw new file mode 100644 index 000000000..65cf860b7 --- /dev/null +++ b/test/data/pti/parser_test_k.raw @@ -0,0 +1,35 @@ +0, 100.00, 33, 0, 0, 60.00 / PSS(R)E 33 RAW created by rawd33 TUE, JUL 21 2020 17:55 + + + 101,'BUS 1', 138.0000,3, 1, 1, 1,1.05000, 0.0000,1.10000,0.90000,1.10000,0.90000 + 102,'BUS 2', 138.0000,2, 1, 1, 1,1.02000, -0.9440,1.10000,0.90000,1.10000,0.90000 + 103,'BUS 3', 138.0000,1, 1, 1, 1,0.99341, -8.7697,1.10000,0.90000,1.10000,0.90000 + 0 /End of Bus data, Begin Load data + 103,'1 ',1, 1, 1, 250.000, 30.000, 0.000, 0.000, 0.000, 0.000, 1,1,0 + 103,'2 ',1, 1, 1, 0.000, 0.000, 250.000, 30.000, 0.000, 0.000, 1,1,0 + 103,'3 ',1, 1, 1, 0.000, 0.000, 0.000, 0.000, 250.000, -30.000, 1,1,0 + 103,'4 ',1, 1, 1, 250.000, 30.000, 250.000, 0.000, 0.000, -30.000, 1,1,0 + 0 /End of Load data, Begin Fixed shunt data + 0 /End of Fixed shunt data, Begin Generator data + 101,'1 ', 153.335, 73.271, 100.000, -100.000,1.05000, 0, 100.000, 0.00000E+0, 1.00000E-5, 0.00000E+0, 0.00000E+0,1.00000,1, 100.0, 318.000, 0.000, 1,1.0000 + 102,'1 ', 100.000, -3.247, 100.000, -100.000,1.02000, 0, 100.000, 0.00000E+0, 2.500E-1, 0.00000E+0, 0.00000E+0,1.00000,1, 100.0, 318.000, 0.000, 1,1.0000 + 0 /End of Generator data, Begin Branch data + 101, 102,'1 ', 1.00000E-2, 1.20000E-1, 0.00000, 250.00, 250.00, 250.00, 0.00000, 0.00000, 0.00000, 0.00000,1,1, 0.00, 1,1.0000 + 101, 103,'1 ', 1.00000E-2, 1.20000E-1, 0.00000, 250.00, 250.00, 250.00, 0.00000, 0.00000, 0.00000, 0.00000,1,1, 0.00, 1,1.0000 + 102, 103,'1 ', 1.00000E-2, 1.20000E-1, 0.00000, 250.00, 250.00, 250.00, 0.00000, 0.00000, 0.00000, 0.00000,1,1, 0.00, 1,1.0000 + 0 /End of Branch data, Begin Transformer data + 0 /End of Transformer data, Begin Area interchange data + 0 /End of Area interchange data, Begin Two-terminal dc line data + 0 /End of Two-terminal dc line data, Begin VSC dc line data + 0 /End of VSC dc line data, Begin Impedance correction table data + 0 /End of Impedance correction table data, Begin Multi-terminal dc line data + 0 /End of Multi-terminal dc line data, Begin Multi-section line data + 0 /End of Multi-section line data, Begin Zone data + 0 /End of Zone data, Begin Inter-area transfer data + 0 /End of Inter-area transfer data, Begin Owner data + 0 /End of Owner data, Begin FACTS device data + 0 /End of FACTS device data, Begin Switched shunt data + 0 /End of Switched shunt data, Begin GNE device data + 0 /End of GNE device data, Begin Induction machine data + 0 /End of Induction machine data +Q diff --git a/test/docs.jl b/test/docs.jl index 9e4c1810b..f15e4d638 100644 --- a/test/docs.jl +++ b/test/docs.jl @@ -10,7 +10,7 @@ @testset "README.md - Modifying Network Data" begin network_data = PowerModels.parse_file("../test/data/matpower/case3.m") - result = run_opf(network_data, ACPPowerModel, JuMP.optimizer_with_attributes(Ipopt.Optimizer, "print_level"=>0)) + result = solve_opf(network_data, ACPPowerModel, JuMP.optimizer_with_attributes(Ipopt.Optimizer, "print_level"=>0)) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5906.88; atol = 1e0) @@ -18,7 +18,7 @@ network_data["load"]["3"]["pd"] = 0.0 network_data["load"]["3"]["qd"] = 0.0 - result = run_opf(network_data, ACPPowerModel, JuMP.optimizer_with_attributes(Ipopt.Optimizer, "print_level"=>0)) + result = solve_opf(network_data, ACPPowerModel, JuMP.optimizer_with_attributes(Ipopt.Optimizer, "print_level"=>0)) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 2937.16; atol = 1e0) @@ -30,7 +30,7 @@ #pretty print the model to the terminal #print(pm.model) - @test num_nonlinear_constraints(pm.model) == 12 + @test JuMP.num_nonlinear_constraints(pm.model) == 12 @test JuMP.num_variables(pm.model) == 28 result = optimize_model!(pm, optimizer=JuMP.optimizer_with_attributes(Ipopt.Optimizer, "print_level"=>0)) diff --git a/test/matpower.jl b/test/matpower.jl index 7ebaffc71..8b1e47dcd 100644 --- a/test/matpower.jl +++ b/test/matpower.jl @@ -1,6 +1,6 @@ @testset "test matpower parser" begin @testset "30-bus case file" begin - result = run_opf("../test/data/matpower/case30.m", ACPPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case30.m", ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 204.96; atol = 1e-1) @@ -10,7 +10,7 @@ data = PowerModels.parse_file("../test/data/matpower/case30.m") @test isa(JSON.json(data), String) - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 204.96; atol = 1e-1) @@ -20,7 +20,7 @@ data = PowerModels.parse_matpower("../test/data/matpower/case30.m") @test isa(JSON.json(data), String) - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 204.96; atol = 1e-1) @@ -31,7 +31,7 @@ data = PowerModels.parse_matpower(f) @test isa(JSON.json(data), String) - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 204.96; atol = 1e-1) @@ -57,7 +57,7 @@ end @testset "2-bus case file with spaces" begin - result = run_pf("../test/data/matpower/case2.m", ACPPowerModel, nlp_solver) + result = solve_pf("../test/data/matpower/case2.m", ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0.0; atol = 1e-1) @@ -76,20 +76,20 @@ end @testset "test matpower data coercion" begin @testset "ACP Model" begin - result = run_opf("../test/data/matpower/case14.m", ACPPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case14.m", ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 8081.5; atol = 1e0) #@test result["status"] = bus_name end @testset "DC Model" begin - result = run_opf("../test/data/matpower/case14.m", DCPPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case14.m", DCPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 7642.6; atol = 1e0) end @testset "QC Model" begin - result = run_opf("../test/data/matpower/case14.m", QCRMPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case14.m", QCRMPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 8075.1; atol = 1e0) diff --git a/test/model.jl b/test/model.jl index 608eb52d3..1f2d952d3 100644 --- a/test/model.jl +++ b/test/model.jl @@ -3,7 +3,7 @@ @testset "run with user provided JuMP model" begin m = JuMP.Model() x = JuMP.@variable(m, my_var >= 0, start=0.0) - result = run_ac_opf("../test/data/matpower/case5.m", nlp_solver, jump_model=m) + result = solve_ac_opf("../test/data/matpower/case5.m", nlp_solver, jump_model=m) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 18269; atol = 1e0) @@ -15,7 +15,7 @@ x = JuMP.@variable(m, my_var >= 0, start=0.0) pm = instantiate_model("../test/data/matpower/case5.m", ACPPowerModel, PowerModels.build_opf, jump_model=m) - @test num_nonlinear_constraints(pm.model) == 28 + @test JuMP.num_nonlinear_constraints(pm.model) == 28 @test JuMP.num_variables(pm.model) == 49 @test pm.model[:my_var] == x @@ -25,7 +25,7 @@ @testset "run with user provided JuMP model in direct mode" begin m = JuMP.direct_model(HiGHS.Optimizer()) JuMP.set_optimizer_attribute(m, "output_flag", false) - result = run_dc_opf("../test/data/matpower/case5.m", milp_solver, jump_model=m) + result = solve_dc_opf("../test/data/matpower/case5.m", milp_solver, jump_model=m) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 17613; atol = 1e0) @@ -36,7 +36,7 @@ end @testset "exports for usablity" begin @testset "optimizer_with_attributes and NLP status" begin - result = run_opf("../test/data/matpower/case5.m", ACPPowerModel, optimizer_with_attributes(Ipopt.Optimizer, "print_level"=>0)) + result = solve_opf("../test/data/matpower/case5.m", ACPPowerModel, optimizer_with_attributes(Ipopt.Optimizer, "print_level"=>0)) @test result["termination_status"] == LOCALLY_SOLVED @test result["primal_status"] == FEASIBLE_POINT @@ -45,7 +45,7 @@ end end @testset "optimizer_with_attributes and LP status" begin - result = run_opf("../test/data/matpower/case5.m", DCPPowerModel, optimizer_with_attributes(HiGHS.Optimizer, "output_flag"=>false)) + result = solve_opf("../test/data/matpower/case5.m", DCPPowerModel, optimizer_with_attributes(HiGHS.Optimizer, "output_flag"=>false)) @test result["termination_status"] == OPTIMAL @test result["primal_status"] == FEASIBLE_POINT @@ -58,17 +58,17 @@ end @testset "relax integrality" begin @testset "relax OTS model" begin - result = run_ots("../test/data/matpower/case5.m", DCPPowerModel, nlp_solver, relax_integrality=true) + result = solve_ots("../test/data/matpower/case5.m", DCPPowerModel, nlp_solver, relax_integrality=true) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 14810.0; atol = 1e0) br_status_total = sum(branch["br_status"] for (i,branch) in result["solution"]["branch"]) - @test isapprox(br_status_total, 5.100; atol = 1e-2) + @test (br_status_total >= 5.100) end @testset "relax TNEP model" begin - result = run_tnep("../test/data/matpower/case5_tnep.m", SOCWRPowerModel, nlp_solver, relax_integrality=true) + result = solve_tnep("../test/data/matpower/case5_tnep.m", SOCWRPowerModel, nlp_solver, relax_integrality=true) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0.1236; atol = 1e-2) diff --git a/test/modify.jl b/test/modify.jl index 8554514e7..10b3adfa3 100644 --- a/test/modify.jl +++ b/test/modify.jl @@ -4,26 +4,26 @@ @testset "30-bus case file incremental" begin data = PowerModels.parse_file("../test/data/matpower/case30.m") - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 204.96; atol = 1e-1) data["branch"]["6"]["br_status"] = 0 - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 195.25; atol = 1e-1) data["gen"]["6"]["gen_status"] = 0 - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 195.896; atol = 1e-1) data["load"]["4"]["pd"] = 0 data["load"]["4"]["qd"] = 0 - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 104.428; atol = 1e-1) end @@ -53,7 +53,7 @@ PowerModels.update_data!(data, data_delta) - result = run_opf(data, ACPPowerModel, nlp_solver) + result = solve_opf(data, ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 104.428; atol = 1e-1) end diff --git a/test/multinetwork.jl b/test/multinetwork.jl index f61268e1d..d9ecd5147 100644 --- a/test/multinetwork.jl +++ b/test/multinetwork.jl @@ -109,19 +109,19 @@ TESTLOG = Memento.getlogger(PowerModels) end - @testset "test run_opf with multinetwork data" begin + @testset "test solve_opf with multinetwork data" begin mn_data = build_mn_data("../test/data/matpower/case5.m") - @test_throws(TESTLOG, ErrorException, PowerModels.run_opf(mn_data, ACPPowerModel, nlp_solver)) + @test_throws(TESTLOG, ErrorException, PowerModels.solve_opf(mn_data, ACPPowerModel, nlp_solver)) end - @testset "test run_mn_opf with single-network data" begin - @test_throws(TESTLOG, ErrorException, PowerModels.run_mn_opf("../test/data/matpower/case5.m", ACPPowerModel, nlp_solver)) + @testset "test solve_mn_opf with single-network data" begin + @test_throws(TESTLOG, ErrorException, PowerModels.solve_mn_opf("../test/data/matpower/case5.m", ACPPowerModel, nlp_solver)) 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, nlp_solver) + result = PowerModels.solve_mn_opf(mn_data, ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 36538.2; atol = 1e0) @@ -141,7 +141,7 @@ TESTLOG = Memento.getlogger(PowerModels) ) mn_data = make_multinetwork(data) - result = PowerModels.run_mn_opf(mn_data, ACPPowerModel, nlp_solver) + result = PowerModels.solve_mn_opf(mn_data, ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 57977.3; atol = 1e0) @@ -172,7 +172,7 @@ TESTLOG = Memento.getlogger(PowerModels) @testset "test ac polar opf" begin - result = PowerModels.run_mn_opf(mn_data, ACPPowerModel, nlp_solver) + result = PowerModels.solve_mn_opf(mn_data, ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 35103.8; atol = 1e0) @@ -189,7 +189,7 @@ TESTLOG = Memento.getlogger(PowerModels) end @testset "test dc polar opf" begin - result = PowerModels.run_mn_opf(mn_data, DCPPowerModel, nlp_solver) + result = PowerModels.solve_mn_opf(mn_data, DCPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 34959.8; atol = 1e0) @@ -206,7 +206,7 @@ TESTLOG = Memento.getlogger(PowerModels) end @testset "test soc opf" begin - result = PowerModels.run_mn_opf(mn_data, SOCWRPowerModel, nlp_solver) + result = PowerModels.solve_mn_opf(mn_data, SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 29999.4; atol = 1e0) @@ -223,7 +223,7 @@ TESTLOG = Memento.getlogger(PowerModels) end @testset "test sdp with constraint decomposition opf" begin - result = PowerModels.run_mn_opf(mn_data, SparseSDPWRMPowerModel, sdp_solver) + result = PowerModels.solve_mn_opf(mn_data, SparseSDPWRMPowerModel, sdp_solver) # hits iteration limit in SCS v0.9, sense ALMOST_OPTIMAL @test result["termination_status"] == OPTIMAL || result["termination_status"] == ALMOST_OPTIMAL @@ -242,7 +242,7 @@ TESTLOG = Memento.getlogger(PowerModels) end @testset "test nfa opf" begin - result = PowerModels.run_mn_opf(mn_data, NFAPowerModel, nlp_solver) + result = PowerModels.solve_mn_opf(mn_data, NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 29620.0; atol = 1e0) @@ -263,7 +263,7 @@ TESTLOG = Memento.getlogger(PowerModels) mn_data = build_mn_data("../test/data/matpower/case5.m") @testset "test dc polar opf" begin - result = PowerModels.run_mn_opf(mn_data, DCPPowerModel, nlp_solver, setting = Dict("output" => Dict("duals" => true))) + result = PowerModels.solve_mn_opf(mn_data, DCPPowerModel, nlp_solver, setting = Dict("output" => Dict("duals" => true))) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 35226.4; atol = 1e0) @@ -290,21 +290,21 @@ TESTLOG = Memento.getlogger(PowerModels) mn_data = PowerModels.parse_files("../test/data/matpower/case14.m", "../test/data/matpower/case24.m") @testset "test ac polar opf" begin - result = PowerModels.run_mn_opf(mn_data, ACPPowerModel, nlp_solver) + result = PowerModels.solve_mn_opf(mn_data, ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 87886.5; atol = 1e0) end @testset "test ac rectangular opf" begin - result = PowerModels.run_mn_opf(mn_data, ACRPowerModel, nlp_solver) + result = PowerModels.solve_mn_opf(mn_data, ACRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 87886.5; atol = 1e0) end @testset "test soc opf" begin - result = PowerModels.run_mn_opf(mn_data, SOCWRPowerModel, nlp_solver) + result = PowerModels.solve_mn_opf(mn_data, SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 78765.8; atol = 1e0) @@ -316,7 +316,7 @@ TESTLOG = Memento.getlogger(PowerModels) mn_data = build_mn_data("../test/data/matpower/case5_strg.m", replicates=4) @testset "test ac polar opf" begin - result = PowerModels.run_mn_opf_strg(mn_data, PowerModels.ACPPowerModel, minlp_solver) + result = PowerModels.solve_mn_opf_strg(mn_data, PowerModels.ACPPowerModel, minlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 70435.5; atol = 1e0) @@ -345,7 +345,7 @@ TESTLOG = Memento.getlogger(PowerModels) end @testset "test soc opf" begin - result = PowerModels.run_mn_opf_strg(mn_data, PowerModels.SOCWRPowerModel, minlp_solver) + result = PowerModels.solve_mn_opf_strg(mn_data, PowerModels.SOCWRPowerModel, minlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 58853.5; atol = 1e0) @@ -372,7 +372,7 @@ TESTLOG = Memento.getlogger(PowerModels) end @testset "test soc bf opf" begin - result = PowerModels.run_mn_opf_bf_strg(mn_data, PowerModels.SOCBFPowerModel, minlp_solver) + result = PowerModels.solve_mn_opf_bf_strg(mn_data, PowerModels.SOCBFPowerModel, minlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 58826.36; atol = 1e0) @@ -399,7 +399,7 @@ TESTLOG = Memento.getlogger(PowerModels) end @testset "test linear bf opf" begin - result = PowerModels.run_mn_opf_bf_strg(mn_data, PowerModels.BFAPowerModel, minlp_solver) + result = PowerModels.solve_mn_opf_bf_strg(mn_data, PowerModels.BFAPowerModel, minlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 57980.0; atol = 1e0) @@ -440,7 +440,7 @@ TESTLOG = Memento.getlogger(PowerModels) end end - result = PowerModels.run_mn_opf_strg(mn_data, PowerModels.DCPPowerModel, minlp_solver) + result = PowerModels.solve_mn_opf_strg(mn_data, PowerModels.DCPPowerModel, minlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 69703.10; atol = 1e0) @@ -457,7 +457,7 @@ TESTLOG = Memento.getlogger(PowerModels) mn_data["nw"]["1"]["storage"]["1"]["status"] = 0 # verify that storage activation does not cause error Memento.setlevel!(TESTLOG, "warn") - @test_warn(TESTLOG, "network data should specify time_elapsed, using 1.0 as a default", PowerModels.run_mn_opf_strg(mn_data, PowerModels.ACPPowerModel, minlp_solver)) + @test_warn(TESTLOG, "network data should specify time_elapsed, using 1.0 as a default", PowerModels.solve_mn_opf_strg(mn_data, PowerModels.ACPPowerModel, minlp_solver)) Memento.setlevel!(TESTLOG, "error") end end @@ -466,7 +466,7 @@ TESTLOG = Memento.getlogger(PowerModels) @testset "test solution feedback" begin mn_data = build_mn_data("../test/data/matpower/case5_asym.m") - opf_result = PowerModels.run_mn_opf(mn_data, ACPPowerModel, nlp_solver) + opf_result = PowerModels.solve_mn_opf(mn_data, ACPPowerModel, nlp_solver) @test opf_result["termination_status"] == LOCALLY_SOLVED @test isapprox(opf_result["objective"], 35103.8; atol = 1e0) diff --git a/test/opb.jl b/test/opb.jl index 2a4f34879..2e6ca1104 100644 --- a/test/opb.jl +++ b/test/opb.jl @@ -2,67 +2,67 @@ @testset "test nfa opb" begin @testset "3-bus case" begin - result = run_opb("../test/data/matpower/case3.m", NFAPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case3.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5638.97; atol = 1e0) end @testset "5-bus tranformer swap case" begin - result = run_opb("../test/data/matpower/case5.m", NFAPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case5.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 14810.0; atol = 1e0) end @testset "5-bus asymmetric case" begin - result = run_opb("../test/data/matpower/case5_asym.m", NFAPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case5_asym.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 14810.0; atol = 1e0) end @testset "5-bus gap case" begin - result = run_opb("../test/data/matpower/case5_gap.m", NFAPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case5_gap.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -27410.0; atol = 1e0) end @testset "5-bus with dcline costs" begin - result = run_opb("../test/data/matpower/case5_dc.m", NFAPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case5_dc.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 14810.0; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_opb("../test/data/pti/case5_alc.raw", NFAPowerModel, nlp_solver) + result = solve_opb("../test/data/pti/case5_alc.raw", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 1000.0; atol = 1e0) end @testset "5-bus with negative generators" begin - result = run_opb("../test/data/matpower/case5_npg.m", NFAPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case5_npg.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -6844.0; atol = 1e0) end @testset "5-bus with only current limit data" begin - result = run_opb("../test/data/matpower/case5_clm.m", NFAPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case5_clm.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 14810.0; atol = 1e0) end @testset "5-bus with pwl costs" begin - result = run_opb("../test/data/matpower/case5_pwlc.m", NFAPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case5_pwlc.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42565.8; atol = 1e0) + @test isapprox(result["objective"], 42575.8; atol = 1e0) end @testset "6-bus case" begin - result = run_opb("../test/data/matpower/case6.m", NFAPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case6.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11277.9; atol = 1e0) end @testset "24-bus rts case" begin - result = run_opb("../test/data/matpower/case24.m", NFAPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case24.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 61001.2; atol = 1e0) @@ -72,25 +72,25 @@ end @testset "test dcp opb" begin @testset "3-bus case" begin - result = run_opb("../test/data/matpower/case3.m", DCPPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case3.m", DCPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5638.97; atol = 1e0) end @testset "5-bus with pwl costs" begin - result = run_opb("../test/data/matpower/case5_pwlc.m", DCPPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case5_pwlc.m", DCPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42565.8; atol = 1e0) + @test isapprox(result["objective"], 42575.8; atol = 1e0) end @testset "6-bus case" begin - result = run_opb("../test/data/matpower/case6.m", DCPPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case6.m", DCPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11277.9; atol = 1e0) end @testset "24-bus case" begin - result = run_opb("../test/data/matpower/case24.m", DCPPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case24.m", DCPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 61001.2; atol = 1e0) @@ -100,25 +100,25 @@ end @testset "test soc wr opb" begin @testset "3-bus case" begin - result = run_opb("../test/data/matpower/case3.m", SOCWRPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case3.m", SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5638.97; atol = 1e0) end @testset "5-bus with pwl costs" begin - result = run_opb("../test/data/matpower/case5_pwlc.m", SOCWRPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case5_pwlc.m", SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42565.7; atol = 1e0) + @test isapprox(result["objective"], 42575.7; atol = 1e0) end @testset "6-bus case" begin - result = run_opb("../test/data/matpower/case6.m", SOCWRPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case6.m", SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11277.9; atol = 1e0) end @testset "24-bus case" begin - result = run_opb("../test/data/matpower/case24.m", SOCWRPowerModel, nlp_solver) + result = solve_opb("../test/data/matpower/case24.m", SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 61001.2; atol = 1e0) diff --git a/test/opf-obj.jl b/test/opf-obj.jl index 76f3c33fb..296e5d87e 100644 --- a/test/opf-obj.jl +++ b/test/opf-obj.jl @@ -12,21 +12,21 @@ end @testset "nlp solver" begin - result = run_ac_opf(data, nlp_solver) + result = solve_ac_opf(data, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5420.3; atol = 1e0) end @testset "conic solver" begin - result = run_opf(data, SOCWRConicPowerModel, sdp_solver) + result = solve_opf(data, SOCWRConicPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 3095.88; atol = 1e0) end @testset "lp solver" begin - result = run_dc_opf(data, milp_solver) + result = solve_dc_opf(data, milp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 4679.05; atol = 1e0) @@ -45,14 +45,14 @@ end end @testset "nlp solver" begin - result = run_ac_opf(data, nlp_solver) + result = solve_ac_opf(data, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5420.46; atol = 1e0) end @testset "conic solver" begin - result = run_opf(data, SOCWRConicPowerModel, sdp_solver) + result = solve_opf(data, SOCWRConicPowerModel, sdp_solver) # ALMOST_OPTIMAL only required for Julia 1.0 on Linux @test result["termination_status"] == OPTIMAL || result["termination_status"] == ALMOST_OPTIMAL @@ -76,14 +76,14 @@ end end @testset "opf objective" begin - result = run_ac_opf(data, nlp_solver) + result = solve_ac_opf(data, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 19005.9; atol = 1e0) end @testset "opb objective" begin - result = run_opb(data, SOCWRPowerModel, nlp_solver) + result = solve_opb(data, SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 18911.70; atol = 1e0) @@ -95,17 +95,17 @@ end data = PowerModels.parse_file("data/matpower/case5_pwlc.m") @testset "opf objective" begin - result = run_ac_opf(data, nlp_solver) + result = solve_ac_opf(data, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42895; atol = 1e0) + @test isapprox(result["objective"], 42905; atol = 1e0) end @testset "opb objective" begin - result = run_opb(data, SOCWRPowerModel, nlp_solver) + result = solve_opb(data, SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42565; atol = 1e0) + @test isapprox(result["objective"], 42575; atol = 1e0) end end @@ -116,7 +116,7 @@ end @testset "nlp objective" begin data["dcline"]["1"]["cost"] = [100.0, 300.0, 4000.0, 1.0] - result = run_ac_opf(data, nlp_solver) + result = solve_ac_opf(data, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 18160.3; atol = 1e0) @@ -124,7 +124,7 @@ end @testset "qp objective" begin data["dcline"]["1"]["cost"] = [1.0, 4000.0, 1.0] - result = run_ac_opf(data, nlp_solver) + result = solve_ac_opf(data, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 18157.2; atol = 1e0) @@ -132,7 +132,7 @@ end @testset "linear objective" begin data["dcline"]["1"]["cost"] = [4000.0, 1.0] - result = run_ac_opf(data, nlp_solver) + result = solve_ac_opf(data, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 18157.2; atol = 1e0) @@ -140,7 +140,7 @@ end @testset "constant objective" begin data["dcline"]["1"]["cost"] = [1.0] - result = run_ac_opf(data, nlp_solver) + result = solve_ac_opf(data, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 17757.2; atol = 1e0) @@ -148,7 +148,7 @@ end @testset "empty objective" begin data["dcline"]["1"]["cost"] = [] - result = run_ac_opf(data, nlp_solver) + result = solve_ac_opf(data, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 17756.2; atol = 1e0) @@ -160,9 +160,9 @@ end data["dcline"]["1"]["model"] = 1 data["dcline"]["1"]["ncost"] = 4 data["dcline"]["1"]["cost"] = [0.0, 10.0, 20.0, 15.0, 100.0, 50.0, 150.0, 800.0] - result = run_ac_opf(data, nlp_solver) + result = solve_ac_opf(data, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42905; atol = 1e0) + @test isapprox(result["objective"], 42915; atol = 1e0) end end diff --git a/test/opf-ptdf.jl b/test/opf-ptdf.jl index c72129ae1..ada57b645 100644 --- a/test/opf-ptdf.jl +++ b/test/opf-ptdf.jl @@ -4,8 +4,8 @@ TESTLOG = Memento.getlogger(PowerModels) @testset "test ptdf-based dc opf" begin @testset "5-bus case, LP solver" begin data = PowerModels.parse_file("../test/data/matpower/case5.m") - result_va = PowerModels.run_opf(data, DCPPowerModel, milp_solver) - result_pg = PowerModels.run_opf_ptdf(data, DCPPowerModel, milp_solver) + result_va = PowerModels.solve_opf(data, DCPPowerModel, milp_solver) + result_pg = PowerModels.solve_opf_ptdf(data, DCPPowerModel, milp_solver) @test result_va["termination_status"] == OPTIMAL @test result_pg["termination_status"] == OPTIMAL @@ -16,8 +16,8 @@ TESTLOG = Memento.getlogger(PowerModels) end @testset "5-bus gap case" begin data = PowerModels.parse_file("../test/data/matpower/case5_gap.m") - result_va = PowerModels.run_opf(data, DCPPowerModel, nlp_solver) - result_pg = PowerModels.run_opf_ptdf(data, DCPPowerModel, nlp_solver) + result_va = PowerModels.solve_opf(data, DCPPowerModel, nlp_solver) + result_pg = PowerModels.solve_opf_ptdf(data, DCPPowerModel, nlp_solver) @test result_va["termination_status"] == LOCALLY_SOLVED @test result_pg["termination_status"] == LOCALLY_SOLVED @@ -29,8 +29,8 @@ TESTLOG = Memento.getlogger(PowerModels) @testset "5-bus with pwl costs" begin data = PowerModels.parse_file("../test/data/matpower/case5_pwlc.m") data["dcline"] = Dict() - result_va = PowerModels.run_opf(data, DCPPowerModel, nlp_solver) - result_pg = PowerModels.run_opf_ptdf(data, DCPPowerModel, nlp_solver) + result_va = PowerModels.solve_opf(data, DCPPowerModel, nlp_solver) + result_pg = PowerModels.solve_opf_ptdf(data, DCPPowerModel, nlp_solver) @test result_va["termination_status"] == LOCALLY_SOLVED @test result_pg["termination_status"] == LOCALLY_SOLVED @@ -41,8 +41,8 @@ TESTLOG = Memento.getlogger(PowerModels) end @testset "14-bus case" begin data = PowerModels.parse_file("../test/data/matpower/case14.m") - result_va = PowerModels.run_opf(data, DCPPowerModel, nlp_solver) - result_pg = PowerModels.run_opf_ptdf(data, DCPPowerModel, nlp_solver) + result_va = PowerModels.solve_opf(data, DCPPowerModel, nlp_solver) + result_pg = PowerModels.solve_opf_ptdf(data, DCPPowerModel, nlp_solver) @test result_va["termination_status"] == LOCALLY_SOLVED @test result_pg["termination_status"] == LOCALLY_SOLVED @@ -55,19 +55,19 @@ TESTLOG = Memento.getlogger(PowerModels) @testset "no support for zero reference buses" begin data = PowerModels.parse_file("../test/data/matpower/case5.m") data["bus"]["4"]["bus_type"] = 2 - @test_throws(TESTLOG, ErrorException, PowerModels.run_opf_ptdf(data, DCPPowerModel, nlp_solver)) + @test_throws(TESTLOG, ErrorException, PowerModels.solve_opf_ptdf(data, DCPPowerModel, nlp_solver)) end @testset "no support for multiple connected components" begin - @test_throws(TESTLOG, ErrorException, PowerModels.run_opf_ptdf("../test/data/matpower/case6.m", DCPPowerModel, nlp_solver)) + @test_throws(TESTLOG, ErrorException, PowerModels.solve_opf_ptdf("../test/data/matpower/case6.m", DCPPowerModel, nlp_solver)) end @testset "no support for dclines" begin - @test_throws(TESTLOG, ErrorException, PowerModels.run_opf_ptdf("../test/data/matpower/case3.m", DCPPowerModel, nlp_solver)) + @test_throws(TESTLOG, ErrorException, PowerModels.solve_opf_ptdf("../test/data/matpower/case3.m", DCPPowerModel, nlp_solver)) end @testset "no support for switches" begin - @test_throws(TESTLOG, ErrorException, PowerModels.run_opf_ptdf("../test/data/matpower/case5_sw.m", DCPPowerModel, nlp_solver)) + @test_throws(TESTLOG, ErrorException, PowerModels.solve_opf_ptdf("../test/data/matpower/case5_sw.m", DCPPowerModel, nlp_solver)) end end diff --git a/test/opf-var.jl b/test/opf-var.jl index 154fdfcce..52f9bbdd2 100644 --- a/test/opf-var.jl +++ b/test/opf-var.jl @@ -93,7 +93,7 @@ end result = PowerModels._solve_opf_cl(data, DCPLLPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 16282.6; atol = 1e0) + @test isapprox(result["objective"], 16394.2; atol = 1e0) end @testset "14-bus no limits case" begin data = build_current_data("../test/data/matpower/case14.m") @@ -317,7 +317,7 @@ end @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 10.0; atol = 1e-2) @test isapprox(active_power_served(result), 10.0; atol = 1e-2) - @test all_loads_on(result, atol=5e-3) + @test all_loads_on(result; atol=5e-3) @test all_shunts_on(result) end @testset "14-bus case" begin @@ -416,7 +416,7 @@ end result = PowerModels._solve_ucopf(data, DCPPowerModel, milp_solver) @test result["termination_status"] == OPTIMAL - @test isapprox(result["objective"], 8008.0; atol = 1e0) + @test isapprox(result["objective"], 8018.0; atol = 1e0) @test isapprox(result["solution"]["gen"]["4"]["gen_status"], 0.0) @test isapprox(result["solution"]["gen"]["5"]["gen_status"], 0.0) end @@ -584,7 +584,7 @@ end @test isapprox(result["objective"], 15141.2; atol = 1e0) switch_status_total = sum(switch["status"] for (i,switch) in result["solution"]["switch"]) - @test switch_status_total <= 12.000 && switch_status_total >= 10.000 # two to four swtiches off + @test switch_status_total <= 12.001 && switch_status_total >= 10.000 # two to four swtiches off end end @@ -849,31 +849,31 @@ end end @testset "3-bus case" begin - result = run_model("../test/data/matpower/case3.m", ACPPowerModel, nlp_solver, build_opf_var) + result = solve_model("../test/data/matpower/case3.m", ACPPowerModel, nlp_solver, build_opf_var) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5907; atol = 1e0) end @testset "5-bus asymmetric case" begin - result = run_model("../test/data/matpower/case5_asym.m", ACPPowerModel, nlp_solver, build_opf_var) + result = solve_model("../test/data/matpower/case5_asym.m", ACPPowerModel, nlp_solver, build_opf_var) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 17551; atol = 1e0) end @testset "5-bus gap case" begin - result = run_model("../test/data/matpower/case5_gap.m", ACPPowerModel, nlp_solver, build_opf_var) + result = solve_model("../test/data/matpower/case5_gap.m", ACPPowerModel, nlp_solver, build_opf_var) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -27497.7; atol = 1e0) end @testset "5-bus with dcline costs" begin - result = run_model("../test/data/matpower/case5_dc.m", ACPPowerModel, nlp_solver, build_opf_var) + result = solve_model("../test/data/matpower/case5_dc.m", ACPPowerModel, nlp_solver, build_opf_var) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 18156.2; atol = 1e0) end @testset "6-bus case" begin - result = run_model("../test/data/matpower/case6.m", ACPPowerModel, nlp_solver, build_opf_var) + result = solve_model("../test/data/matpower/case6.m", ACPPowerModel, nlp_solver, build_opf_var) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11625.3; atol = 1e0) @@ -881,7 +881,7 @@ end @test isapprox(result["solution"]["bus"]["4"]["va"], 0.0; atol = 1e-4) end @testset "24-bus rts case" begin - result = run_model("../test/data/matpower/case24.m", ACPPowerModel, nlp_solver, build_opf_var) + result = solve_model("../test/data/matpower/case24.m", ACPPowerModel, nlp_solver, build_opf_var) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 79805; atol = 1e0) @@ -970,7 +970,7 @@ end @testset "3-bus case with fixed phase shift / tap" begin file = "../test/data/matpower/case3_oltc_pst.m" data = PowerModels.parse_file(file) - result = PowerModels.run_opf(data, ACPPowerModel, nlp_solver) + result = PowerModels.solve_opf(data, ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5820.1; atol = 1e0) diff --git a/test/opf.jl b/test/opf.jl index ed24811d1..3fa1e3a12 100644 --- a/test/opf.jl +++ b/test/opf.jl @@ -2,43 +2,43 @@ @testset "test ac polar opf" begin @testset "3-bus case" begin - result = run_ac_opf("../test/data/matpower/case3.m", nlp_solver) + result = solve_ac_opf("../test/data/matpower/case3.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5907; atol = 1e0) end @testset "5-bus tranformer swap case" begin - result = run_ac_opf("../test/data/matpower/case5.m", nlp_solver) + result = solve_ac_opf("../test/data/matpower/case5.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 18269; atol = 1e0) end @testset "5-bus asymmetric case" begin - result = run_ac_opf("../test/data/matpower/case5_asym.m", nlp_solver) + result = solve_ac_opf("../test/data/matpower/case5_asym.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 17551; atol = 1e0) end @testset "5-bus gap case" begin - result = run_ac_opf("../test/data/matpower/case5_gap.m", nlp_solver) + result = solve_ac_opf("../test/data/matpower/case5_gap.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -27497.7; atol = 1e0) end @testset "5-bus with dcline costs" begin - result = run_ac_opf("../test/data/matpower/case5_dc.m", nlp_solver) + result = solve_ac_opf("../test/data/matpower/case5_dc.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 18156.2; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_ac_opf("../test/data/pti/case5_alc.raw", nlp_solver) + result = solve_ac_opf("../test/data/pti/case5_alc.raw", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 1005.31; atol = 1e0) end @testset "5-bus with negative generators" begin - result = run_ac_opf("../test/data/matpower/case5_npg.m", nlp_solver) + result = solve_ac_opf("../test/data/matpower/case5_npg.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 8190.09; atol = 1e0) @@ -46,31 +46,31 @@ @testset "5-bus with only current limit data" begin data = PowerModels.parse_file("../test/data/matpower/case5_clm.m") calc_thermal_limits!(data) - result = run_ac_opf(data, nlp_solver) + result = solve_ac_opf(data, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 16513.6; atol = 1e0) end @testset "5-bus with pwl costs" begin - result = run_ac_opf("../test/data/matpower/case5_pwlc.m", nlp_solver) + result = solve_ac_opf("../test/data/matpower/case5_pwlc.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42895; atol = 1e0) + @test isapprox(result["objective"], 42905; atol = 1e0) end @testset "5-bus with gen lb" begin - result = run_ac_opf("../test/data/matpower/case5_uc.m", nlp_solver) + result = solve_ac_opf("../test/data/matpower/case5_uc.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 18742.2; atol = 1e0) end @testset "5-bus with dangling bus" begin - result = run_ac_opf("../test/data/matpower/case5_db.m", nlp_solver) + result = solve_ac_opf("../test/data/matpower/case5_db.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 16739.1; atol = 1e0) end @testset "6-bus case" begin - result = run_ac_opf("../test/data/matpower/case6.m", nlp_solver) + result = solve_ac_opf("../test/data/matpower/case6.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11625.3; atol = 1e0) @@ -78,7 +78,7 @@ @test isapprox(result["solution"]["bus"]["4"]["va"], 0.0; atol = 1e-4) end @testset "24-bus rts case" begin - result = run_opf("../test/data/matpower/case24.m", ACPPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case24.m", ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 79805; atol = 1e0) @@ -94,7 +94,7 @@ end #= # numerical issue @testset "3-bus case" begin - result = run_opf("../test/data/matpower/case3.m", ACRPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case3.m", ACRPowerModel, nlp_solver) #@test result["termination_status"] == LOCALLY_SOLVED #@test isapprox(result["objective"], 5812; atol = 1e0) @@ -102,31 +102,31 @@ end end =# @testset "5-bus asymmetric case" begin - result = run_opf("../test/data/matpower/case5_asym.m", ACRPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_asym.m", ACRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 17551; atol = 1e0) end @testset "5-bus gap case" begin - result = run_opf("../test/data/matpower/case5_gap.m", ACRPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_gap.m", ACRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -27497.7; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_opf("../test/data/pti/case5_alc.raw", ACRPowerModel, nlp_solver) + result = solve_opf("../test/data/pti/case5_alc.raw", ACRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 1005.31; atol = 1e0) end @testset "5-bus with pwl costs" begin - result = run_ac_opf("../test/data/matpower/case5_pwlc.m", nlp_solver) + result = solve_ac_opf("../test/data/matpower/case5_pwlc.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42895; atol = 1e0) + @test isapprox(result["objective"], 42905; atol = 1e0) end @testset "6-bus case" begin - result = run_opf("../test/data/matpower/case6.m", ACRPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case6.m", ACRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11625.3; atol = 1e0) @@ -134,7 +134,7 @@ end @test isapprox(result["solution"]["bus"]["4"]["vi"], 0.0; atol = 1e-4) end @testset "24-bus rts case" begin - result = run_opf("../test/data/matpower/case24.m", ACRPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case24.m", ACRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 79805; atol = 1e0) @@ -148,37 +148,37 @@ end @testset "test ac tan opf" begin @testset "3-bus case" begin - result = run_opf("../test/data/matpower/case3.m", ACTPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case3.m", ACTPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5907; atol = 1e0) end @testset "5-bus asymmetric case" begin - result = run_opf("../test/data/matpower/case5_asym.m", ACTPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_asym.m", ACTPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 17551; atol = 1e0) end @testset "5-bus gap case" begin - result = run_opf("../test/data/matpower/case5_gap.m", ACTPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_gap.m", ACTPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -27438.7; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_opf("../test/data/pti/case5_alc.raw", ACTPowerModel, nlp_solver) + result = solve_opf("../test/data/pti/case5_alc.raw", ACTPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 1005.31; atol = 1e0) end @testset "5-bus with pwl costs" begin - result = run_opf("../test/data/matpower/case5_pwlc.m", ACTPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_pwlc.m", ACTPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42895; atol = 1e0) + @test isapprox(result["objective"], 42905; atol = 1e0) end @testset "6-bus case" begin - result = run_opf("../test/data/matpower/case6.m", ACTPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case6.m", ACTPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11625.3; atol = 1e0) @@ -186,7 +186,7 @@ end @test isapprox(result["solution"]["bus"]["4"]["va"], 0.0; atol = 1e-4) end @testset "24-bus rts case" begin - result = run_opf("../test/data/matpower/case24.m", ACTPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case24.m", ACTPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 79804; atol = 1e0) @@ -200,38 +200,38 @@ end @testset "test iv opf" begin @testset "3-bus case" begin - result = run_opf_iv("../test/data/matpower/case3.m", IVRPowerModel, nlp_solver) + result = solve_opf_iv("../test/data/matpower/case3.m", IVRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5907; atol = 1e0) end @testset "5-bus asymmetric case" begin - result = run_opf_iv("../test/data/matpower/case5_asym.m", IVRPowerModel, nlp_solver) + result = solve_opf_iv("../test/data/matpower/case5_asym.m", IVRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 17551; atol = 1e0) end @testset "5-bus gap case" begin - result = run_opf_iv("../test/data/matpower/case5_gap.m", IVRPowerModel, nlp_solver) + result = solve_opf_iv("../test/data/matpower/case5_gap.m", IVRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -27497.7; atol = 1e2) #numerically challenging , returns 27438.7 end @testset "5-bus with asymmetric line charge" begin - result = run_opf_iv("../test/data/pti/case5_alc.raw", IVRPowerModel, nlp_solver) + result = solve_opf_iv("../test/data/pti/case5_alc.raw", IVRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 1005.31; atol = 1e0) end @testset "5-bus with pwl costs" begin - result = run_opf_iv("../test/data/matpower/case5_pwlc.m", IVRPowerModel, nlp_solver) + result = solve_opf_iv("../test/data/matpower/case5_pwlc.m", IVRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42895; atol = 1e0) + @test isapprox(result["objective"], 42905; atol = 1e0) end @testset "6-bus case" begin - result = run_opf_iv("../test/data/matpower/case6.m", IVRPowerModel, nlp_solver) + result = solve_opf_iv("../test/data/matpower/case6.m", IVRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11625.3; atol = 1e0) @@ -239,7 +239,7 @@ end @test isapprox(result["solution"]["bus"]["4"]["vi"], 0.0; atol = 1e-4) end @testset "24-bus rts case" begin - result = run_opf_iv("../test/data/matpower/case24.m", IVRPowerModel, nlp_solver) + result = solve_opf_iv("../test/data/matpower/case24.m", IVRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 79804; atol = 1e0) @@ -254,55 +254,55 @@ end @testset "test dc opf" begin @testset "3-bus case" begin - result = run_dc_opf("../test/data/matpower/case3.m", nlp_solver) + result = solve_dc_opf("../test/data/matpower/case3.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5782; atol = 1e0) end @testset "5-bus case, LP solver" begin - result = run_dc_opf("../test/data/matpower/case5.m", milp_solver) + result = solve_dc_opf("../test/data/matpower/case5.m", milp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 17613; atol = 1e0) end @testset "5-bus asymmetric case" begin - result = run_dc_opf("../test/data/matpower/case5_asym.m", nlp_solver) + result = solve_dc_opf("../test/data/matpower/case5_asym.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 17479; atol = 1e0) end @testset "5-bus gap case" begin - result = run_dc_opf("../test/data/matpower/case5_gap.m", nlp_solver) + result = solve_dc_opf("../test/data/matpower/case5_gap.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -27410.0; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_dc_opf("../test/data/pti/case5_alc.raw", nlp_solver) + result = solve_dc_opf("../test/data/pti/case5_alc.raw", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 1000.0; atol = 1e0) end @testset "5-bus with pwl costs" begin - result = run_dc_opf("../test/data/matpower/case5_pwlc.m", nlp_solver) + result = solve_dc_opf("../test/data/matpower/case5_pwlc.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42565; atol = 1e0) + @test isapprox(result["objective"], 42575; atol = 1e0) end @testset "5-bus with gen lb" begin - result = run_dc_opf("../test/data/matpower/case5_uc.m", nlp_solver) + result = solve_dc_opf("../test/data/matpower/case5_uc.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 18064.5; atol = 1e0) end @testset "5-bus with dangling bus" begin - result = run_dc_opf("../test/data/matpower/case5_db.m", nlp_solver) + result = solve_dc_opf("../test/data/matpower/case5_db.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 16710.0; atol = 1e0) end @testset "6-bus case" begin - result = run_dc_opf("../test/data/matpower/case6.m", nlp_solver) + result = solve_dc_opf("../test/data/matpower/case6.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11391.8; atol = 1e0) @@ -311,7 +311,7 @@ end end # TODO verify this is really infeasible #@testset "24-bus rts case" begin - # result = run_opf("../test/data/matpower/case24.m", DCPPowerModel, nlp_solver) + # result = solve_opf("../test/data/matpower/case24.m", DCPPowerModel, nlp_solver) # @test result["termination_status"] == LOCALLY_SOLVED # @test isapprox(result["objective"], 79804; atol = 1e0) @@ -325,7 +325,7 @@ end @testset "test matpower dc opf" begin @testset "5-bus case with matpower DCMP model" begin - result = run_opf("../test/data/matpower/case5.m", DCMPPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5.m", DCMPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @@ -340,43 +340,43 @@ end @testset "test nfa opf" begin @testset "3-bus case" begin - result = run_opf("../test/data/matpower/case3.m", NFAPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case3.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5638.97; atol = 1e0) end @testset "5-bus asymmetric case" begin - result = run_opf("../test/data/matpower/case5_asym.m", NFAPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_asym.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 14810.0; atol = 1e0) end @testset "5-bus gap case" begin - result = run_opf("../test/data/matpower/case5_gap.m", NFAPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_gap.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -27410.0; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_opf("../test/data/pti/case5_alc.raw", NFAPowerModel, nlp_solver) + result = solve_opf("../test/data/pti/case5_alc.raw", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 1000.0; atol = 1e0) end @testset "5-bus with pwl costs" begin - result = run_opf("../test/data/matpower/case5_pwlc.m", NFAPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_pwlc.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42565.8; atol = 1e0) + @test isapprox(result["objective"], 42575.8; atol = 1e0) end @testset "6-bus case" begin - result = run_opf("../test/data/matpower/case6.m", NFAPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case6.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11277.9; atol = 1e0) end @testset "24-bus rts case" begin - result = run_opf("../test/data/matpower/case24.m", NFAPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case24.m", NFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 61001.2; atol = 1e0) @@ -389,37 +389,37 @@ end @testset "test dc+ll opf" begin @testset "3-bus case" begin - result = run_opf("../test/data/matpower/case3.m", DCPLLPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case3.m", DCPLLPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5885; atol = 1e0) end @testset "5-bus asymmetric case" begin - result = run_opf("../test/data/matpower/case5_asym.m", DCPLLPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_asym.m", DCPLLPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 17693; atol = 1e0) end @testset "5-bus gap case" begin - result = run_opf("../test/data/matpower/case5_gap.m", DCPLLPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_gap.m", DCPLLPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -32710.0; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_opf("../test/data/pti/case5_alc.raw", DCPLLPowerModel, nlp_solver) + result = solve_opf("../test/data/pti/case5_alc.raw", DCPLLPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 1001.17; atol = 1e0) end @testset "5-bus with pwl costs" begin - result = run_opf("../test/data/matpower/case5_pwlc.m", DCPLLPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_pwlc.m", DCPLLPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42937; atol = 1e0) + @test isapprox(result["objective"], 42947; atol = 1e0) end @testset "6-bus case" begin - result = run_opf("../test/data/matpower/case6.m", DCPLLPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case6.m", DCPLLPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11574.3; atol = 1e0) @@ -427,7 +427,7 @@ end @test isapprox(result["solution"]["bus"]["4"]["va"], 0.0; atol = 1e-4) end @testset "24-bus rts case" begin - result = run_opf("../test/data/matpower/case24.m", DCPLLPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case24.m", DCPLLPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 82240; atol = 1e0) @@ -441,43 +441,43 @@ end @testset "test lpac-c opf" begin @testset "3-bus case" begin - result = run_opf("../test/data/matpower/case3.m", LPACCPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case3.m", LPACCPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5908.98; atol = 1e0) end @testset "5-bus tranformer swap case" begin - result = run_opf("../test/data/matpower/case5.m", LPACCPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5.m", LPACCPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 18288.1; atol = 1e0) end @testset "5-bus asymmetric case" begin - result = run_opf("../test/data/matpower/case5_asym.m", LPACCPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_asym.m", LPACCPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 17645.6; atol = 1e0) end @testset "5-bus gap case" begin - result = run_opf("../test/data/matpower/case5_gap.m", LPACCPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_gap.m", LPACCPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -27554.5; atol = 1e0) end @testset "5-bus with dcline costs" begin - result = run_opf("../test/data/matpower/case5_dc.m", LPACCPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_dc.m", LPACCPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 18253.0; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_opf("../test/data/pti/case5_alc.raw", LPACCPowerModel, nlp_solver) + result = solve_opf("../test/data/pti/case5_alc.raw", LPACCPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 1004.58; atol = 1e0) end @testset "5-bus with negative generators" begin - result = run_opf("../test/data/matpower/case5_npg.m", LPACCPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_npg.m", LPACCPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 8082.54; atol = 1e0) @@ -485,19 +485,19 @@ end @testset "5-bus with only current limit data" begin data = PowerModels.parse_file("../test/data/matpower/case5_clm.m") calc_thermal_limits!(data) - result = run_opf(data, LPACCPowerModel, nlp_solver) + result = solve_opf(data, LPACCPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 16559.3; atol = 1e0) end @testset "5-bus with pwl costs" begin - result = run_opf("../test/data/matpower/case5_pwlc.m", LPACCPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_pwlc.m", LPACCPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42853.4; atol = 1e0) + @test isapprox(result["objective"], 42863.4; atol = 1e0) end @testset "6-bus case" begin - result = run_opf("../test/data/matpower/case6.m", LPACCPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case6.m", LPACCPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11615.1; atol = 1e0) @@ -506,7 +506,7 @@ end end # TODO uderstand why this is infeasible #@testset "24-bus rts case" begin - # result = run_opf("../test/data/matpower/case24.m", LPACCPowerModel, nlp_solver) + # result = solve_opf("../test/data/matpower/case24.m", LPACCPowerModel, nlp_solver) # @test result["termination_status"] == LOCALLY_SOLVED # @test isapprox(result["objective"], 79805; atol = 1e0) @@ -520,61 +520,61 @@ end @testset "test soc (BIM) opf" begin @testset "3-bus case" begin - result = run_opf("../test/data/matpower/case3.m", SOCWRPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case3.m", SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5746.7; atol = 1e0) end @testset "5-bus transformer swap case" begin - result = run_opf("../test/data/matpower/case5.m", SOCWRPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5.m", SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 15051; atol = 1e0) end @testset "5-bus asymmetric case" begin - result = run_opf("../test/data/matpower/case5_asym.m", SOCWRPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_asym.m", SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 14999; atol = 1e0) end @testset "5-bus gap case" begin - result = run_opf("../test/data/matpower/case5_gap.m", SOCWRPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_gap.m", SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -28237.3; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_opf("../test/data/pti/case5_alc.raw", SOCWRPowerModel, nlp_solver) + result = solve_opf("../test/data/pti/case5_alc.raw", SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 1005.27; atol = 1e0) end @testset "5-bus with negative generators" begin - result = run_opf("../test/data/matpower/case5_npg.m", SOCWRPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_npg.m", SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 3603.91; atol = 1e0) end @testset "5-bus with pwl costs" begin - result = run_opf("../test/data/matpower/case5_pwlc.m", SOCWRPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_pwlc.m", SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42895; atol = 1e0) + @test isapprox(result["objective"], 42905; atol = 1e0) end @testset "5-bus with dangling bus" begin - result = run_opf("../test/data/matpower/case5_db.m", SOCWRPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_db.m", SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 16739.1; atol = 1e0) end @testset "6-bus case" begin - result = run_opf("../test/data/matpower/case6.m", SOCWRPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case6.m", SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11472.3; atol = 1e0) end @testset "24-bus rts case" begin - result = run_opf("../test/data/matpower/case24.m", SOCWRPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case24.m", SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 70690.7; atol = 1e0) @@ -587,52 +587,53 @@ end @testset "test soc conic form opf" begin @testset "3-bus case" begin - result = run_opf("../test/data/matpower/case3.m", SOCWRConicPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case3.m", SOCWRConicPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL #@test isapprox(result["objective"], 5736.94; atol = 2e0) @test isapprox(result["objective"], 5747.37; atol = 2e0) end @testset "5-bus transformer swap case" begin - result = run_opf("../test/data/matpower/case5.m", SOCWRConicPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case5.m", SOCWRConicPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 15051.4; atol = 1e1) end @testset "5-bus asymmetric case" begin - result = run_opf("../test/data/matpower/case5_asym.m", SOCWRConicPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case5_asym.m", SOCWRConicPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 14999.7; atol = 1e0) end @testset "5-bus gap case" begin - result = run_opf("../test/data/matpower/case5_gap.m", SOCWRConicPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case5_gap.m", SOCWRConicPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], -28236.8; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_opf("../test/data/pti/case5_alc.raw", SOCWRConicPowerModel, sdp_solver) + result = solve_opf("../test/data/pti/case5_alc.raw", SOCWRConicPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 1005.27; atol = 1e0) end @testset "5-bus with negative generators" begin - result = run_opf("../test/data/matpower/case5_npg.m", SOCWRConicPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case5_npg.m", SOCWRConicPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL #@test isapprox(result["objective"], 3551.71; atol = 40) @test isapprox(result["objective"], 3602.11; atol = 40) end @testset "5-bus with pwl costs" begin - result = run_opf("../test/data/matpower/case5_pwlc.m", SOCWRConicPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case5_pwlc.m", SOCWRConicPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL #@test isapprox(result["objective"], 42889; atol = 1e0) - @test isapprox(result["objective"], 42906; atol = 1e0) + #@test isapprox(result["objective"], 42906; atol = 1e0) + @test isapprox(result["objective"], 42908; atol = 1e0) end @testset "6-bus case" begin - result = run_opf("../test/data/matpower/case6.m", SOCWRConicPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case6.m", SOCWRConicPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL #@test isapprox(result["objective"], 11472.2; atol = 3e0) @@ -640,7 +641,7 @@ end @test isapprox(result["objective"], 11473.4; atol = 3e0) end @testset "24-bus rts case" begin - result = run_opf("../test/data/matpower/case24.m", SOCWRConicPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case24.m", SOCWRConicPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL #@test isapprox(result["objective"], 70693.9; atol = 1e0) @@ -655,49 +656,49 @@ end @testset "test soc distflow opf_bf" begin @testset "3-bus case" begin - result = run_opf_bf("../test/data/matpower/case3.m", SOCBFPowerModel, nlp_solver) + result = solve_opf_bf("../test/data/matpower/case3.m", SOCBFPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5746.7; atol = 1e0) end @testset "5-bus transformer swap case" begin - result = run_opf_bf("../test/data/matpower/case5.m", SOCBFPowerModel, nlp_solver) + result = solve_opf_bf("../test/data/matpower/case5.m", SOCBFPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 15051; atol = 1e0) end @testset "5-bus asymmetric case" begin - result = run_opf_bf("../test/data/matpower/case5_asym.m", SOCBFPowerModel, nlp_solver) + result = solve_opf_bf("../test/data/matpower/case5_asym.m", SOCBFPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 14999; atol = 1e0) end @testset "5-bus gap case" begin - result = run_opf_bf("../test/data/matpower/case5_gap.m", SOCBFPowerModel, nlp_solver) + result = solve_opf_bf("../test/data/matpower/case5_gap.m", SOCBFPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -27659.8; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_opf_bf("../test/data/pti/case5_alc.raw", SOCBFPowerModel, nlp_solver) + result = solve_opf_bf("../test/data/pti/case5_alc.raw", SOCBFPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 1005.27; atol = 1e0) end @testset "5-bus with pwl costs" begin - result = run_opf_bf("../test/data/matpower/case5_pwlc.m", SOCBFPowerModel, nlp_solver) + result = solve_opf_bf("../test/data/matpower/case5_pwlc.m", SOCBFPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42895; atol = 1e0) + @test isapprox(result["objective"], 42905; atol = 1e0) end @testset "6-bus case" begin - result = run_opf_bf("../test/data/matpower/case6.m", SOCBFPowerModel, nlp_solver) + result = solve_opf_bf("../test/data/matpower/case6.m", SOCBFPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11472.3; atol = 1e0) end @testset "24-bus rts case" begin - result = run_opf_bf("../test/data/matpower/case24.m", SOCBFPowerModel, nlp_solver) + result = solve_opf_bf("../test/data/matpower/case24.m", SOCBFPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 70690.7; atol = 1e0) @@ -705,7 +706,7 @@ end @testset "3-bus case w/ r,x=0 on branch" begin mp_data = PowerModels.parse_file("../test/data/matpower/case3.m") mp_data["branch"]["1"]["br_r"] = mp_data["branch"]["1"]["br_x"] = 0.0 - result = run_opf_bf(mp_data, SOCBFPowerModel, nlp_solver) + result = solve_opf_bf(mp_data, SOCBFPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED end @testset "14-bus variable bounds" begin @@ -716,25 +717,25 @@ end @testset "test soc conic distflow opf_bf" begin @testset "3-bus case" begin - result = run_opf_bf("../test/data/matpower/case3.m", SOCBFConicPowerModel, sdp_solver) + result = solve_opf_bf("../test/data/matpower/case3.m", SOCBFConicPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 5746.7; atol = 5e1) end @testset "5-bus transformer swap case" begin - result = run_opf_bf("../test/data/matpower/case5.m", SOCBFConicPowerModel, sdp_solver) + result = solve_opf_bf("../test/data/matpower/case5.m", SOCBFConicPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 15051; atol = 1e1) end @testset "5-bus asymmetric case" begin - result = run_opf_bf("../test/data/matpower/case5_asym.m", SOCBFConicPowerModel, sdp_solver) + result = solve_opf_bf("../test/data/matpower/case5_asym.m", SOCBFConicPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 14999; atol = 1e1) end @testset "5-bus with negative generators" begin - result = run_opf_bf("../test/data/matpower/case5_npg.m", SOCBFConicPowerModel, sdp_solver) + result = solve_opf_bf("../test/data/matpower/case5_npg.m", SOCBFConicPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 3593.0; atol = 1e1) @@ -747,14 +748,14 @@ end @testset "test linear distflow opf_bf" begin @testset "3-bus case" begin - result = run_opf_bf("../test/data/matpower/case3.m", BFAPowerModel, nlp_solver) + result = solve_opf_bf("../test/data/matpower/case3.m", BFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5638.97; atol = 1e0) end @testset "5-bus transformer swap case" begin data = PowerModels.parse_file("../test/data/matpower/case5.m") - result = run_opf_bf(data, BFAPowerModel, nlp_solver) + result = solve_opf_bf(data, BFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 14810; atol = 1e0) @@ -763,37 +764,37 @@ end atol = 1e-3) end @testset "5-bus asymmetric case" begin - result = run_opf_bf("../test/data/matpower/case5_asym.m", BFAPowerModel, nlp_solver) + result = solve_opf_bf("../test/data/matpower/case5_asym.m", BFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 14810; atol = 1e0) end @testset "5-bus gap case" begin - result = run_opf_bf("../test/data/matpower/case5_gap.m", BFAPowerModel, nlp_solver) + result = solve_opf_bf("../test/data/matpower/case5_gap.m", BFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -27410.0; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_opf_bf("../test/data/pti/case5_alc.raw", BFAPowerModel, nlp_solver) + result = solve_opf_bf("../test/data/pti/case5_alc.raw", BFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 1002.46; atol = 1e0) end @testset "5-bus with pwl costs" begin - result = run_opf_bf("../test/data/matpower/case5_pwlc.m", BFAPowerModel, nlp_solver) + result = solve_opf_bf("../test/data/matpower/case5_pwlc.m", BFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42565.8; atol = 1e0) + @test isapprox(result["objective"], 42575.8; atol = 1e0) end @testset "6-bus case" begin - result = run_opf_bf("../test/data/matpower/case6.m", BFAPowerModel, nlp_solver) + result = solve_opf_bf("../test/data/matpower/case6.m", BFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11277.9; atol = 1e0) end # @testset "24-bus rts case" begin - # result = run_opf_bf("../test/data/matpower/case24.m", BFAPowerModel, nlp_solver) + # result = solve_opf_bf("../test/data/matpower/case24.m", BFAPowerModel, nlp_solver) # # @test result["termination_status"] == LOCALLY_SOLVED # @test isapprox(result["objective"], 70690.7; atol = 1e0) @@ -801,7 +802,7 @@ end @testset "3-bus case w/ r,x=0 on branch" begin mp_data = PowerModels.parse_file("../test/data/matpower/case3.m") mp_data["branch"]["1"]["br_r"] = mp_data["branch"]["1"]["br_x"] = 0.0 - result = run_opf_bf(mp_data, BFAPowerModel, nlp_solver) + result = solve_opf_bf(mp_data, BFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED end @testset "14-bus variable bounds" begin @@ -812,37 +813,37 @@ end @testset "test qc opf" begin @testset "3-bus case" begin - result = run_opf("../test/data/matpower/case3.m", QCRMPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case3.m", QCRMPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5780; atol = 1e0) end @testset "5-bus asymmetric case" begin - result = run_opf("../test/data/matpower/case5_asym.m", QCRMPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_asym.m", QCRMPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 15921; atol = 1e0) end @testset "5-bus gap case" begin - result = run_opf("../test/data/matpower/case5_gap.m", QCRMPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_gap.m", QCRMPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -27659.8; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_opf("../test/data/pti/case5_alc.raw", QCRMPowerModel, nlp_solver) + result = solve_opf("../test/data/pti/case5_alc.raw", QCRMPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 1005.27; atol = 1e0) end @testset "5-bus with pwl costs" begin - result = run_opf("../test/data/matpower/case5_pwlc.m", QCRMPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_pwlc.m", QCRMPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED - @test isapprox(result["objective"], 42895; atol = 1e0) + @test isapprox(result["objective"], 42905; atol = 1e0) end @testset "6-bus case" begin - result = run_opf("../test/data/matpower/case6.m", QCRMPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case6.m", QCRMPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11484.2; atol = 1e0) @@ -850,7 +851,7 @@ end @test isapprox(result["solution"]["bus"]["4"]["va"], 0.0; atol = 1e-4) end @testset "24-bus rts case" begin - result = run_opf("../test/data/matpower/case24.m", QCRMPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case24.m", QCRMPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 76599.9; atol = 1e0) @@ -863,25 +864,25 @@ end @testset "test qc opf with trilinear convexhull relaxation" begin @testset "3-bus case" begin - result = run_opf("../test/data/matpower/case3.m", QCLSPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case3.m", QCLSPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 5817.91; atol = 1e0) end @testset "5-bus asymmetric case" begin - result = run_opf("../test/data/matpower/case5_asym.m", QCLSPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_asym.m", QCLSPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 15929.2; atol = 1e0) end @testset "5-bus gap case" begin - result = run_opf("../test/data/matpower/case5_gap.m", QCLSPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case5_gap.m", QCLSPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], -27659.8; atol = 1e0) end @testset "6-bus case" begin - result = run_opf("../test/data/matpower/case6.m", QCLSPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case6.m", QCLSPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 11512.9; atol = 1e0) @@ -889,7 +890,7 @@ end @test isapprox(result["solution"]["bus"]["4"]["va"], 0.0; atol = 1e-4) end @testset "24-bus rts case" begin - result = run_opf("../test/data/matpower/case24.m", QCLSPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case24.m", QCLSPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 76785.4; atol = 1e0) @@ -903,7 +904,7 @@ end @testset "test sdp opf" begin @testset "3-bus case" begin - result = run_opf("../test/data/matpower/case3.m", SDPWRMPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case3.m", SDPWRMPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL #@test isapprox(result["objective"], 5818.00; atol = 1e1) @@ -918,25 +919,25 @@ end @test isapprox(result["solution"]["branch"]["1"]["wi"], 0.284, atol = 1e-2) end @testset "5-bus asymmetric case" begin - result = run_opf("../test/data/matpower/case5_asym.m", SDPWRMPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case5_asym.m", SDPWRMPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 16662.0; atol = 1e1) end @testset "5-bus gap case" begin - result = run_opf("../test/data/matpower/case5_gap.m", SDPWRMPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case5_gap.m", SDPWRMPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], -28236.1; atol = 1e1) end @testset "5-bus with asymmetric line charge" begin - result = run_opf("../test/data/pti/case5_alc.raw", SDPWRMPowerModel, sdp_solver) + result = solve_opf("../test/data/pti/case5_alc.raw", SDPWRMPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 1005.31; atol = 1e0) end @testset "5-bus with negative generators" begin - result = run_opf("../test/data/matpower/case5_npg.m", SDPWRMPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case5_npg.m", SDPWRMPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL #@test isapprox(result["objective"], 6827.34; atol = 1e0) @@ -945,13 +946,13 @@ end end # too slow for unit tests # @testset "14-bus case" begin - # result = run_opf("../test/data/matpower/case14.m", SDPWRMPowerModel, sdp_solver) + # result = solve_opf("../test/data/matpower/case14.m", SDPWRMPowerModel, sdp_solver) # @test result["termination_status"] == OPTIMAL # @test isapprox(result["objective"], 8081.52; atol = 1e0) # end @testset "6-bus case" begin - result = run_opf("../test/data/matpower/case6.m", SDPWRMPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case6.m", SDPWRMPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL #@test isapprox(result["objective"], 11580.8; atol = 1e1) @@ -967,7 +968,7 @@ end @testset "test sdp opf with constraint decomposition" begin @testset "3-bus case" begin - result = run_opf("../test/data/matpower/case3.m", SparseSDPWRMPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case3.m", SparseSDPWRMPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL #@test isapprox(result["objective"], 5851.23; atol = 1e1) @@ -983,26 +984,26 @@ end @test isapprox(result["solution"]["branch"]["1"]["wi"], 0.284, atol = 1e-2) end @testset "5-bus with asymmetric line charge" begin - result = run_opf("../test/data/pti/case5_alc.raw", SparseSDPWRMPowerModel, sdp_solver) + result = solve_opf("../test/data/pti/case5_alc.raw", SparseSDPWRMPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 1005.31; atol = 1e0) end @testset "9-bus cholesky PosDefException" begin - result = run_opf("../test/data/matpower/case9.m", SparseSDPWRMPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case9.m", SparseSDPWRMPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 347.746; atol = 1e0) end @testset "14-bus case" begin - result = run_opf("../test/data/matpower/case14.m", SparseSDPWRMPowerModel, sdp_solver) + result = solve_opf("../test/data/matpower/case14.m", SparseSDPWRMPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 8081.5; atol = 1e0) end # multiple components are not currently supported by this form # @testset "6-bus case" begin - # result = run_opf("../test/data/matpower/case6.m", SparseSDPWRMPowerModel, sdp_solver) + # result = solve_opf("../test/data/matpower/case6.m", SparseSDPWRMPowerModel, sdp_solver) # @test result["termination_status"] == OPTIMAL # @test isapprox(result["objective"], 11578.8; atol = 1e0) diff --git a/test/ots.jl b/test/ots.jl index 1a2b5fdf9..2cffa0f79 100644 --- a/test/ots.jl +++ b/test/ots.jl @@ -13,7 +13,7 @@ end @testset "test ac ots" begin @testset "3-bus case" begin - result = run_ots("../test/data/matpower/case3.m", ACPPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case3.m", ACPPowerModel, minlp_solver) check_br_status(result["solution"], 3, 3) @@ -24,7 +24,7 @@ end #= # remove due to linux stability issue @testset "5-bus case" begin - result = run_ots("../test/data/matpower/case5.m", ACPPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case5.m", ACPPowerModel, minlp_solver) check_br_status(result["solution"], 0, 0) @@ -35,7 +35,7 @@ end end =# @testset "5-bus with negative branch reactance case" begin - result = run_ots("../test/data/matpower/case5_ext.m", ACPPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case5_ext.m", ACPPowerModel, minlp_solver) check_br_status(result["solution"], 5, 5) @@ -45,7 +45,7 @@ end #@test result["objective"] < 16600 end @testset "5-bus with asymmetric line charge" begin - result = run_ots("../test/data/pti/case5_alc.raw", ACPPowerModel, minlp_solver) + result = solve_ots("../test/data/pti/case5_alc.raw", ACPPowerModel, minlp_solver) check_br_status(result["solution"], 4, 4) @@ -54,7 +54,7 @@ end end #Omitting this test, returns local infeasible #@testset "6-bus case" begin - # result = run_ots("../test/data/matpower/case6.m", ACPPowerModel, minlp_solver) + # result = solve_ots("../test/data/matpower/case6.m", ACPPowerModel, minlp_solver) # check_br_status(result["solution"], 0, 0) @@ -67,7 +67,7 @@ end @testset "test dc ots" begin @testset "3-bus case" begin - result = run_ots("../test/data/matpower/case3.m", DCPPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case3.m", DCPPowerModel, minlp_solver) check_br_status(result["solution"], 3, 3) @@ -75,7 +75,7 @@ end @test isapprox(result["objective"], 5782.0; atol = 1e0) end @testset "5-bus case" begin - result = run_ots("../test/data/matpower/case5.m", DCPPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case5.m", DCPPowerModel, minlp_solver) check_br_status(result["solution"], 5, 5) @@ -83,7 +83,7 @@ end @test isapprox(result["objective"], 14991.2; atol = 1e0) end @testset "5-bus case, MIP solver" begin - result = run_ots("../test/data/matpower/case5.m", DCPPowerModel, milp_solver) + result = solve_ots("../test/data/matpower/case5.m", DCPPowerModel, milp_solver) check_br_status(result["solution"], 5, 5) @@ -91,7 +91,7 @@ end @test isapprox(result["objective"], 14991.3; atol = 1e0) end @testset "5-bus with negative branch reactance case" begin - result = run_ots("../test/data/matpower/case5_ext.m", DCPPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case5_ext.m", DCPPowerModel, minlp_solver) check_br_status(result["solution"], 5, 5) @@ -99,7 +99,7 @@ end @test isapprox(result["objective"], 14991.2; atol = 1e0) end @testset "6-bus case" begin - result = run_ots("../test/data/matpower/case6.m", DCPPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case6.m", DCPPowerModel, minlp_solver) check_br_status(result["solution"], 6, 6) @@ -111,7 +111,7 @@ end @testset "test dc+ll ots" begin @testset "3-bus case" begin - result = run_ots("../test/data/matpower/case3.m", DCPLLPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case3.m", DCPLLPowerModel, minlp_solver) check_br_status(result["solution"], 3, 3) @@ -119,7 +119,7 @@ end @test isapprox(result["objective"], 5885.2; atol = 1e0) end @testset "5-bus case" begin - result = run_ots("../test/data/matpower/case5.m", DCPLLPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case5.m", DCPLLPowerModel, minlp_solver) check_br_status(result["solution"], 5, 5) @@ -127,7 +127,7 @@ end @test isapprox(result["objective"], 15275.2; atol = 1e0) end @testset "5-bus with negative branch reactance case" begin - result = run_ots("../test/data/matpower/case5_ext.m", DCPLLPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case5_ext.m", DCPLLPowerModel, minlp_solver) check_br_status(result["solution"], 5, 5) @@ -135,7 +135,7 @@ end @test isapprox(result["objective"], 15275.2; atol = 1e0) end @testset "6-bus case" begin - result = run_ots("../test/data/matpower/case6.m", DCPLLPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case6.m", DCPLLPowerModel, minlp_solver) check_br_status(result["solution"], 6, 6) @@ -147,7 +147,7 @@ end @testset "test soc ots" begin @testset "3-bus case" begin - result = run_ots("../test/data/matpower/case3.m", SOCWRPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case3.m", SOCWRPowerModel, minlp_solver) check_br_status(result["solution"], 3, 3) @@ -155,7 +155,7 @@ end @test isapprox(result["objective"], 5746.7; atol = 1e0) end @testset "5-bus case" begin - result = run_ots("../test/data/matpower/case5.m", SOCWRPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case5.m", SOCWRPowerModel, minlp_solver) check_br_status(result["solution"], 5, 5) @@ -163,7 +163,7 @@ end @test isapprox(result["objective"], 15051.4; atol = 5e1) end @testset "5-bus with negative branch reactance case" begin - result = run_ots("../test/data/matpower/case5_ext.m", SOCWRPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case5_ext.m", SOCWRPowerModel, minlp_solver) check_br_status(result["solution"], 5, 5) @@ -171,7 +171,7 @@ end @test isapprox(result["objective"], 15009.9; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_ots("../test/data/pti/case5_alc.raw", SOCWRPowerModel, minlp_solver) + result = solve_ots("../test/data/pti/case5_alc.raw", SOCWRPowerModel, minlp_solver) check_br_status(result["solution"], 4, 4) @@ -179,7 +179,7 @@ end @test isapprox(result["objective"], 1004.8; atol = 5e0) end @testset "6-bus case" begin - result = run_ots("../test/data/matpower/case6.m", SOCWRPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case6.m", SOCWRPowerModel, minlp_solver) check_br_status(result["solution"], 6, 6) @@ -191,7 +191,7 @@ end @testset "test qc ots" begin @testset "3-bus case" begin - result = run_ots("../test/data/matpower/case3.m", QCRMPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case3.m", QCRMPowerModel, minlp_solver) check_br_status(result["solution"], 3, 3) @@ -199,7 +199,7 @@ end @test isapprox(result["objective"], 5748.0; atol = 1e0) end @testset "5-bus case" begin - result = run_ots("../test/data/matpower/case5.m", QCRMPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case5.m", QCRMPowerModel, minlp_solver) check_br_status(result["solution"], 5, 5) @@ -207,7 +207,7 @@ end @test isapprox(result["objective"], 15051.4; atol = 5e1) end @testset "5-bus with negative branch reactance case" begin - result = run_ots("../test/data/matpower/case5_ext.m", QCRMPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case5_ext.m", QCRMPowerModel, minlp_solver) check_br_status(result["solution"], 5, 5) @@ -215,7 +215,7 @@ end @test isapprox(result["objective"], 15010.0; atol = 1e0) end @testset "5-bus asymmetric case" begin - result = run_ots("../test/data/matpower/case5_asym.m", QCRMPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case5_asym.m", QCRMPowerModel, minlp_solver) check_br_status(result["solution"], 6, 6) @@ -223,7 +223,7 @@ end @test isapprox(result["objective"], 15036.9; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_ots("../test/data/pti/case5_alc.raw", QCRMPowerModel, minlp_solver) + result = solve_ots("../test/data/pti/case5_alc.raw", QCRMPowerModel, minlp_solver) # updated ub to 5 on 04/21/2021 to fix cross platform stability check_br_status(result["solution"], 4, 5) @@ -232,7 +232,7 @@ end @test isapprox(result["objective"], 1003.97; atol = 5e0) end @testset "6-bus case" begin - result = run_ots("../test/data/matpower/case6.m", QCRMPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case6.m", QCRMPowerModel, minlp_solver) check_br_status(result["solution"], 6, 6) @@ -244,7 +244,7 @@ end @testset "test lpac ots" begin @testset "3-bus case" begin - result = run_ots("../test/data/matpower/case3.m", LPACCPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case3.m", LPACCPowerModel, minlp_solver) check_br_status(result["solution"], 3, 3) @@ -252,7 +252,7 @@ end @test isapprox(result["objective"], 5908.98; atol = 1e0) end @testset "5-bus case" begin - result = run_ots("../test/data/matpower/case5.m", LPACCPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case5.m", LPACCPowerModel, minlp_solver) check_br_status(result["solution"], 5, 5) @@ -260,7 +260,7 @@ end @test isapprox(result["objective"], 15241.4; atol = 5e1) end @testset "5-bus with negative branch reactance case" begin - result = run_ots("../test/data/matpower/case5_ext.m", LPACCPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case5_ext.m", LPACCPowerModel, minlp_solver) check_br_status(result["solution"], 5, 5) @@ -268,7 +268,7 @@ end @test isapprox(result["objective"], 15241.4; atol = 1e0) end @testset "5-bus asymmetric case" begin - result = run_ots("../test/data/matpower/case5_asym.m", LPACCPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case5_asym.m", LPACCPowerModel, minlp_solver) check_br_status(result["solution"], 5, 5) @@ -276,7 +276,7 @@ end @test isapprox(result["objective"], 15246.9; atol = 1e0) end @testset "5-bus with asymmetric line charge" begin - result = run_ots("../test/data/pti/case5_alc.raw", LPACCPowerModel, minlp_solver) + result = solve_ots("../test/data/pti/case5_alc.raw", LPACCPowerModel, minlp_solver) check_br_status(result["solution"], 4, 4) @@ -284,7 +284,7 @@ end @test isapprox(result["objective"], 998.4; atol = 5e0) end @testset "6-bus case" begin - result = run_ots("../test/data/matpower/case6.m", LPACCPowerModel, minlp_solver) + result = solve_ots("../test/data/matpower/case6.m", LPACCPowerModel, minlp_solver) check_br_status(result["solution"], 6, 6) diff --git a/test/output.jl b/test/output.jl index 10b8dc0e2..9aa4f000b 100644 --- a/test/output.jl +++ b/test/output.jl @@ -1,7 +1,7 @@ @testset "test output api" begin @testset "24-bus rts case" begin - result = run_opf("../test/data/matpower/case24.m", ACPPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case24.m", ACPPowerModel, nlp_solver) @test haskey(result, "optimizer") == true @test haskey(result, "termination_status") == true @@ -31,7 +31,7 @@ gen["cost"] = gen["cost"][length(gen["cost"])-1:end] end end - result = run_opf(data, DCPPowerModel, milp_solver) + result = solve_opf(data, DCPPowerModel, milp_solver) @test haskey(result, "optimizer") @test haskey(result, "termination_status") @@ -47,7 +47,7 @@ end @testset "test branch flow output" begin @testset "24-bus rts case ac opf" begin - result = run_opf("../test/data/matpower/case24.m", ACPPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case24.m", ACPPowerModel, nlp_solver) @test haskey(result, "optimizer") == true @test haskey(result, "termination_status") == true @@ -73,7 +73,7 @@ end # A DCPPowerModel test is important because it does have variables for the reverse side of the branchs @testset "3-bus case dc opf" begin - result = run_opf("../test/data/matpower/case3.m", DCPPowerModel, nlp_solver) + result = solve_opf("../test/data/matpower/case3.m", DCPPowerModel, nlp_solver) @test haskey(result, "solution") == true @test haskey(result["solution"], "branch") == true @@ -92,7 +92,7 @@ end end @testset "24-bus rts case ac pf" begin - result = run_pf("../test/data/matpower/case24.m", ACPPowerModel, nlp_solver) + result = solve_pf("../test/data/matpower/case24.m", ACPPowerModel, nlp_solver) @test haskey(result, "optimizer") == true @test haskey(result, "termination_status") == true @@ -118,7 +118,7 @@ end # A DCPPowerModel test is important because it does have variables for the reverse side of the branchs @testset "3-bus case dc pf" begin - result = run_pf("../test/data/matpower/case3.m", DCPPowerModel, nlp_solver) + result = solve_pf("../test/data/matpower/case3.m", DCPPowerModel, nlp_solver) @test haskey(result, "solution") == true @test haskey(result["solution"], "branch") == false @@ -141,7 +141,7 @@ end settings = Dict("output" => Dict("duals" => true)) data = PowerModels.parse_file("../test/data/matpower/case14.m") calc_thermal_limits!(data) - result = run_dc_opf(data, nlp_solver, setting = settings) + result = solve_dc_opf(data, nlp_solver, setting = settings) PowerModels.make_mixed_units!(result["solution"]) @testset "14 bus - kcl duals" begin @@ -161,7 +161,7 @@ end end - result = run_dc_opf("../test/data/matpower/case5.m", nlp_solver, setting = settings) + result = solve_dc_opf("../test/data/matpower/case5.m", nlp_solver, setting = settings) PowerModels.make_mixed_units!(result["solution"]) @testset "5 bus - kcl duals" begin @@ -183,7 +183,7 @@ end end - result = run_opf("../test/data/matpower/case5.m", SOCWRPowerModel, nlp_solver, setting = settings) + result = solve_opf("../test/data/matpower/case5.m", SOCWRPowerModel, nlp_solver, setting = settings) @testset "5 bus - kcl duals soc qp" begin for (i, bus) in result["solution"]["bus"] @test bus["lam_kcl_r"] <= -2900.00 @@ -193,7 +193,7 @@ end end end - result = run_opf("../test/data/matpower/case5.m", SOCWRConicPowerModel, sdp_solver, setting = settings) + result = solve_opf("../test/data/matpower/case5.m", SOCWRConicPowerModel, sdp_solver, setting = settings) @testset "5 bus - kcl duals soc conic" begin for (i, bus) in result["solution"]["bus"] @test bus["lam_kcl_r"] <= -2900.00 @@ -203,7 +203,7 @@ end end end - result = run_opf("../test/data/matpower/case5.m", ACPPowerModel, nlp_solver, setting = settings) + result = solve_opf("../test/data/matpower/case5.m", ACPPowerModel, nlp_solver, setting = settings) @testset "5 bus - kcl duals acp" begin for (i, bus) in result["solution"]["bus"] @test bus["lam_kcl_r"] <= -1000.00 @@ -213,7 +213,7 @@ end end end - result = run_opf("../test/data/matpower/case5.m", ACRPowerModel, nlp_solver, setting = settings) + result = solve_opf("../test/data/matpower/case5.m", ACRPowerModel, nlp_solver, setting = settings) @testset "5 bus - kcl duals acr" begin for (i, bus) in result["solution"]["bus"] @test bus["lam_kcl_r"] <= -1000.00 @@ -223,7 +223,7 @@ end end end - result = run_opf("../test/data/matpower/case5.m", ACTPowerModel, nlp_solver, setting = settings) + result = solve_opf("../test/data/matpower/case5.m", ACTPowerModel, nlp_solver, setting = settings) @testset "5 bus - kcl duals act" begin for (i, bus) in result["solution"]["bus"] @test bus["lam_kcl_r"] <= -1000.00 @@ -240,7 +240,7 @@ end # test case where generator status is 1 but the gen_bus status is 0 data = parse_file("../test/data/matpower/case5.m") data["bus"]["4"]["bus_type"] = 4 - result = run_ac_opf(data, nlp_solver) + result = solve_ac_opf(data, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 10128.6; atol = 1e0) @@ -249,7 +249,7 @@ end @testset "test solution processors" begin @testset "sol_vr_to_vp" begin - result = run_opf("../test/data/matpower/case5.m", ACRPowerModel, nlp_solver, solution_processors=[sol_data_model!]) + result = solve_opf("../test/data/matpower/case5.m", ACRPowerModel, nlp_solver, solution_processors=[sol_data_model!]) for (i,bus) in result["solution"]["bus"] @test haskey(bus, "vm") && haskey(bus, "va") @@ -257,7 +257,7 @@ end end @testset "sol_w_to_vm" begin - result = run_opf("../test/data/matpower/case5.m", SOCWRPowerModel, nlp_solver, solution_processors=[sol_data_model!]) + result = solve_opf("../test/data/matpower/case5.m", SOCWRPowerModel, nlp_solver, solution_processors=[sol_data_model!]) for (i,bus) in result["solution"]["bus"] @test haskey(bus, "vm") @@ -266,7 +266,7 @@ end end @testset "sol_phi_to_vm" begin - result = run_opf("../test/data/matpower/case5.m", LPACCPowerModel, nlp_solver, solution_processors=[sol_data_model!]) + result = solve_opf("../test/data/matpower/case5.m", LPACCPowerModel, nlp_solver, solution_processors=[sol_data_model!]) for (i,bus) in result["solution"]["bus"] @test haskey(bus, "vm") @@ -281,13 +281,13 @@ end function solution_feedback(case, ac_opf_obj) data = PowerModels.parse_file(case) - opf_result = run_ac_opf(data, nlp_solver) + opf_result = solve_ac_opf(data, nlp_solver) @test opf_result["termination_status"] == LOCALLY_SOLVED @test isapprox(opf_result["objective"], ac_opf_obj; atol = 1e0) PowerModels.update_data!(data, opf_result["solution"]) - pf_result = run_ac_pf(data, nlp_solver) + pf_result = solve_ac_pf(data, nlp_solver) @test pf_result["termination_status"] == LOCALLY_SOLVED @test isapprox(pf_result["objective"], 0.0; atol = 1e-3) diff --git a/test/pf-native.jl b/test/pf-native.jl index d81758a2a..503656e81 100644 --- a/test/pf-native.jl +++ b/test/pf-native.jl @@ -2,7 +2,7 @@ # degenerate due to no slack bus # @testset "3-bus case" begin # data = PowerModels.parse_file("../test/data/matpower/case3.m") - # result = run_dc_pf(data, nlp_solver) + # result = solve_dc_pf(data, nlp_solver) # native = compute_dc_pf(data) # for (i,bus) in data["bus"] @@ -13,7 +13,7 @@ # end @testset "5-bus case" begin data = PowerModels.parse_file("../test/data/matpower/case5.m") - result = run_dc_pf(data, nlp_solver) + result = solve_dc_pf(data, nlp_solver) native = compute_dc_pf(data) @test length(native) >= 5 @@ -30,7 +30,7 @@ end @testset "5-bus asymmetric case" begin data = PowerModels.parse_file("../test/data/matpower/case5_asym.m") - result = run_dc_pf(data, nlp_solver) + result = solve_dc_pf(data, nlp_solver) native = compute_dc_pf(data) for (i,bus) in data["bus"] @@ -41,7 +41,7 @@ end @testset "5-bus multiple slack gens case" begin data = PowerModels.parse_file("../test/data/matpower/case5_ext.m") - result = run_dc_pf(data, nlp_solver) + result = solve_dc_pf(data, nlp_solver) native = compute_dc_pf(data) for (i,bus) in data["bus"] @@ -55,7 +55,7 @@ # compute_dc_pf does not yet support multiple slack buses # @testset "6-bus case" begin # data = PowerModels.parse_file("../test/data/matpower/case6.m") - # result = run_dc_pf(data, nlp_solver) + # result = solve_dc_pf(data, nlp_solver) # native = compute_dc_pf(data) # for (i,bus) in data["bus"] @@ -66,7 +66,7 @@ # end @testset "24-bus rts case" begin data = PowerModels.parse_file("../test/data/matpower/case24.m") - result = run_dc_pf(data, nlp_solver) + result = solve_dc_pf(data, nlp_solver) native = compute_dc_pf(data) for (i,bus) in data["bus"] @@ -84,7 +84,7 @@ end # requires dc line support in ac solver # @testset "3-bus case" begin # data = PowerModels.parse_file("../test/data/matpower/case3.m") - # result = run_dc_pf(data, nlp_solver) + # result = solve_dc_pf(data, nlp_solver) # native = compute_dc_pf(data) # @test result["termination_status"] == LOCALLY_SOLVED @@ -105,7 +105,7 @@ end # end @testset "5-bus case" begin data = PowerModels.parse_file("../test/data/matpower/case5.m") - result = run_ac_pf(data, nlp_solver) + result = solve_ac_pf(data, nlp_solver) native = compute_ac_pf(data) @test result["termination_status"] == LOCALLY_SOLVED @@ -132,7 +132,7 @@ end end @testset "5-bus asymmetric case" begin data = PowerModels.parse_file("../test/data/matpower/case5_asym.m") - result = run_ac_pf(data, nlp_solver) + result = solve_ac_pf(data, nlp_solver) native = compute_ac_pf(data) @test result["termination_status"] == LOCALLY_SOLVED @@ -154,7 +154,7 @@ end end @testset "5-bus multiple slack gens case" begin data = PowerModels.parse_file("../test/data/matpower/case5_ext.m") - result = run_ac_pf(data, nlp_solver) + result = solve_ac_pf(data, nlp_solver) native = compute_ac_pf(data) @test result["termination_status"] == LOCALLY_SOLVED @@ -180,7 +180,7 @@ end # compute_ac_pf does not yet support multiple slack buses # @testset "6-bus case" begin # data = PowerModels.parse_file("../test/data/matpower/case6.m") - # result = run_ac_pf(data, nlp_solver) + # result = solve_ac_pf(data, nlp_solver) # native = compute_ac_pf(data) # @test result["termination_status"] == LOCALLY_SOLVED @@ -201,7 +201,7 @@ end # end @testset "14-bus case, vm fixed non-1.0 value" begin data = PowerModels.parse_file("../test/data/matpower/case14.m") - result = run_ac_pf(data, nlp_solver) + result = solve_ac_pf(data, nlp_solver) native = compute_ac_pf(data) @test result["termination_status"] == LOCALLY_SOLVED @@ -223,7 +223,7 @@ end end @testset "24-bus rts case" begin data = PowerModels.parse_file("../test/data/matpower/case24.m") - result = run_ac_pf(data, nlp_solver) + result = solve_ac_pf(data, nlp_solver) native = compute_ac_pf(data) @test result["termination_status"] == LOCALLY_SOLVED @@ -370,15 +370,15 @@ end # TODO extract number of iterations and test there is a reduction # Ipopt log can be used for manual verification, for now data = PowerModels.parse_file("../test/data/matpower/case24.m") - result = run_ac_pf(data, nlp_solver) - #result = run_ac_pf(data, JuMP.optimizer_with_attributes(Ipopt.Optimizer, "tol"=>1e-6)) + result = solve_ac_pf(data, nlp_solver) + #result = solve_ac_pf(data, JuMP.optimizer_with_attributes(Ipopt.Optimizer, "tol"=>1e-6)) @test result["termination_status"] == LOCALLY_SOLVED update_data!(data, result["solution"]) set_ac_pf_start_values!(data) - result_ws = run_ac_pf(data, nlp_solver) - #result_ws = run_ac_pf(data, JuMP.optimizer_with_attributes(Ipopt.Optimizer, "tol"=>1e-6)) + result_ws = solve_ac_pf(data, nlp_solver) + #result_ws = solve_ac_pf(data, JuMP.optimizer_with_attributes(Ipopt.Optimizer, "tol"=>1e-6)) @test result_ws["termination_status"] == LOCALLY_SOLVED bus_pg_ini = bus_gen_values(data, result["solution"], "pg") @@ -431,7 +431,7 @@ end @testset "test native ac pf solver options" begin @testset "5-bus case, finite_differencing" begin data = PowerModels.parse_file("../test/data/matpower/case5.m") - result = run_ac_pf(data, nlp_solver) + result = solve_ac_pf(data, nlp_solver) native = compute_ac_pf("../test/data/matpower/case5.m", finite_differencing=true) @test result["termination_status"] == LOCALLY_SOLVED @@ -453,7 +453,7 @@ end end @testset "5-bus case, flat_start" begin data = PowerModels.parse_file("../test/data/matpower/case5.m") - result = run_ac_pf(data, nlp_solver) + result = solve_ac_pf(data, nlp_solver) native = compute_ac_pf("../test/data/matpower/case5.m", flat_start=true) @test result["termination_status"] == LOCALLY_SOLVED diff --git a/test/pf.jl b/test/pf.jl index c853ce172..439a9497c 100644 --- a/test/pf.jl +++ b/test/pf.jl @@ -1,6 +1,6 @@ @testset "test ac polar pf" begin @testset "3-bus case" begin - result = run_ac_pf("../test/data/matpower/case3.m", nlp_solver) + result = solve_ac_pf("../test/data/matpower/case3.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -21,19 +21,19 @@ #@test isapprox(result["solution"]["dcline"]["1"]["qt"], 0.0647562; atol = 1e-5) end @testset "5-bus transformer swap case" begin - result = run_pf("../test/data/matpower/case5.m", ACPPowerModel, nlp_solver) + result = solve_pf("../test/data/matpower/case5.m", ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) end @testset "5-bus asymmetric case" begin - result = run_pf("../test/data/matpower/case5_asym.m", ACPPowerModel, nlp_solver) + result = solve_pf("../test/data/matpower/case5_asym.m", ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) end @testset "5-bus multiple slack gens case" begin - result = run_pf("../test/data/matpower/case5_ext.m", ACPPowerModel, nlp_solver) + result = solve_pf("../test/data/matpower/case5_ext.m", ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -42,7 +42,7 @@ @test isapprox(result["solution"]["gen"]["1"]["qg"], 0.30; atol = 1e-3) end @testset "5-bus case with hvdc line" begin - result = run_ac_pf("../test/data/matpower/case5_dc.m", nlp_solver) + result = solve_ac_pf("../test/data/matpower/case5_dc.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -61,7 +61,7 @@ @test isapprox(result["solution"]["dcline"]["1"]["pt"], -0.089; atol = 1e-5) end @testset "6-bus case" begin - result = run_pf("../test/data/matpower/case6.m", ACPPowerModel, nlp_solver) + result = solve_pf("../test/data/matpower/case6.m", ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -71,7 +71,7 @@ @test isapprox(result["solution"]["bus"]["4"]["va"], 0.00000; atol = 1e-3) end @testset "24-bus rts case" begin - result = run_pf("../test/data/matpower/case24.m", ACPPowerModel, nlp_solver) + result = solve_pf("../test/data/matpower/case24.m", ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -81,7 +81,7 @@ end @testset "test ac rect pf" begin @testset "5-bus asymmetric case" begin - result = run_pf("../test/data/matpower/case5_asym.m", ACRPowerModel, nlp_solver) + result = solve_pf("../test/data/matpower/case5_asym.m", ACRPowerModel, nlp_solver) if VERSION >= v"1.9" && Sys.iswindows() # Some numerical issue on Windows with Julia 1.9? @test result["termination_status"] in (LOCALLY_SOLVED, ITERATION_LIMIT) @@ -93,7 +93,7 @@ end #= # numerical issues with ipopt, likely div. by zero issue in jacobian @testset "5-bus case with hvdc line" begin - result = run_pf("../test/data/matpower/case5_dc.m", ACRPowerModel, nlp_solver) + result = solve_pf("../test/data/matpower/case5_dc.m", ACRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -118,13 +118,13 @@ end @testset "test ac tan pf" begin # removed for cross platform compat (julia v1.6, linux) # @testset "5-bus asymmetric case" begin - # result = run_pf("../test/data/matpower/case5_asym.m", ACTPowerModel, nlp_solver) + # result = solve_pf("../test/data/matpower/case5_asym.m", ACTPowerModel, nlp_solver) # @test result["termination_status"] == LOCALLY_SOLVED # @test isapprox(result["objective"], 0; atol = 1e-2) # end @testset "5-bus case with hvdc line" begin - result = run_pf("../test/data/matpower/case5_dc.m", ACTPowerModel, nlp_solver, solution_processors=[sol_data_model!]) + result = solve_pf("../test/data/matpower/case5_dc.m", ACTPowerModel, nlp_solver, solution_processors=[sol_data_model!]) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -148,7 +148,7 @@ end @testset "test iv pf" begin @testset "3-bus case" begin - result = run_pf_iv("../test/data/matpower/case3.m", IVRPowerModel, nlp_solver, solution_processors=[sol_data_model!]) + result = solve_pf_iv("../test/data/matpower/case3.m", IVRPowerModel, nlp_solver, solution_processors=[sol_data_model!]) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -167,7 +167,7 @@ end # @test isapprox(result["solution"]["dcline"]["1"]["qt"], 0.0647562; atol = 1e-5) #no reason to expect this is unique end @testset "5-bus case with hvdc line" begin - result = run_pf_iv("../test/data/matpower/case5_dc.m", IVRPowerModel, nlp_solver, solution_processors=[sol_data_model!]) + result = solve_pf_iv("../test/data/matpower/case5_dc.m", IVRPowerModel, nlp_solver, solution_processors=[sol_data_model!]) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -190,7 +190,7 @@ end @testset "test dc pf" begin @testset "3-bus case" begin - result = run_dc_pf("../test/data/matpower/case3.m", nlp_solver) + result = solve_dc_pf("../test/data/matpower/case3.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -202,13 +202,13 @@ end @test isapprox(result["solution"]["bus"]["3"]["va"], -0.28291891895; atol = 1e-5) end @testset "5-bus asymmetric case" begin - result = run_dc_pf("../test/data/matpower/case5_asym.m", nlp_solver) + result = solve_dc_pf("../test/data/matpower/case5_asym.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) end @testset "5-bus multiple slack gens case" begin - result = run_dc_pf("../test/data/matpower/case5_ext.m", nlp_solver) + result = solve_dc_pf("../test/data/matpower/case5_ext.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -216,7 +216,7 @@ end @test isapprox(result["solution"]["gen"]["1"]["pg"], 0.40; atol = 1e-3) end @testset "6-bus case" begin - result = run_dc_pf("../test/data/matpower/case6.m", nlp_solver) + result = solve_dc_pf("../test/data/matpower/case6.m", nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -224,7 +224,7 @@ end @test isapprox(result["solution"]["bus"]["4"]["va"], 0.00000; atol = 1e-5) end @testset "24-bus rts case" begin - result = run_pf("../test/data/matpower/case24.m", DCPPowerModel, nlp_solver) + result = solve_pf("../test/data/matpower/case24.m", DCPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -234,7 +234,7 @@ end @testset "test matpower dc pf" begin @testset "5-bus case with matpower DCMP model" begin - result = run_pf("../test/data/matpower/case5.m", DCMPPowerModel, nlp_solver) + result = solve_pf("../test/data/matpower/case5.m", DCMPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @@ -249,7 +249,7 @@ end @testset "test soc pf" begin # started failing 05/22/2020 when ipopt moved to jll artifacts # @testset "3-bus case" begin - # result = run_pf("../test/data/matpower/case3.m", SOCWRPowerModel, nlp_solver, solution_processors=[sol_data_model!]) + # result = solve_pf("../test/data/matpower/case3.m", SOCWRPowerModel, nlp_solver, solution_processors=[sol_data_model!]) # @test result["termination_status"] == LOCALLY_SOLVED # @test isapprox(result["objective"], 0; atol = 1e-2) @@ -268,13 +268,13 @@ end # end # started failing 05/22/2020 when ipopt moved to jll artifacts (only on travis) # @testset "5-bus asymmetric case" begin - # result = run_pf("../test/data/matpower/case5_asym.m", SOCWRPowerModel, nlp_solver) + # result = solve_pf("../test/data/matpower/case5_asym.m", SOCWRPowerModel, nlp_solver) # @test result["termination_status"] == LOCALLY_SOLVED # @test isapprox(result["objective"], 0; atol = 1e-2) # end @testset "6-bus case" begin - result = run_pf("../test/data/matpower/case6.m", SOCWRPowerModel, nlp_solver, solution_processors=[sol_data_model!]) + result = solve_pf("../test/data/matpower/case6.m", SOCWRPowerModel, nlp_solver, solution_processors=[sol_data_model!]) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -282,7 +282,7 @@ end @test isapprox(result["solution"]["bus"]["4"]["vm"], 1.09999; atol = 1e-3) end @testset "24-bus rts case" begin - result = run_pf("../test/data/matpower/case24.m", SOCWRPowerModel, nlp_solver) + result = solve_pf("../test/data/matpower/case24.m", SOCWRPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -293,7 +293,7 @@ end @testset "test soc distflow pf_bf" begin @testset "3-bus case" begin - result = run_pf_bf("../test/data/matpower/case3.m", SOCBFPowerModel, nlp_solver, solution_processors=[sol_data_model!]) + result = solve_pf_bf("../test/data/matpower/case3.m", SOCBFPowerModel, nlp_solver, solution_processors=[sol_data_model!]) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -312,19 +312,19 @@ end end # removed due to windows instability in Julia v1.9 # @testset "5-bus asymmetric case" begin - # result = run_pf_bf("../test/data/matpower/case5_asym.m", SOCBFPowerModel, nlp_solver) + # result = solve_pf_bf("../test/data/matpower/case5_asym.m", SOCBFPowerModel, nlp_solver) # @test result["termination_status"] == LOCALLY_SOLVED # @test isapprox(result["objective"], 0; atol = 1e-2) # end @testset "5-bus case with hvdc line" begin - result = run_pf_bf("../test/data/matpower/case5_dc.m", SOCBFPowerModel, nlp_solver) + result = solve_pf_bf("../test/data/matpower/case5_dc.m", SOCBFPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) end @testset "6-bus case" begin - result = run_pf_bf("../test/data/matpower/case6.m", SOCBFPowerModel, nlp_solver, solution_processors=[sol_data_model!]) + result = solve_pf_bf("../test/data/matpower/case6.m", SOCBFPowerModel, nlp_solver, solution_processors=[sol_data_model!]) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -332,7 +332,7 @@ end @test isapprox(result["solution"]["bus"]["4"]["vm"], 1.09999; atol = 1e-3) end @testset "24-bus rts case" begin - result = run_pf_bf("../test/data/matpower/case24.m", SOCBFPowerModel, nlp_solver) + result = solve_pf_bf("../test/data/matpower/case24.m", SOCBFPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -342,7 +342,7 @@ end @testset "test linear distflow pf_bf" begin @testset "3-bus case" begin - result = run_pf_bf("../test/data/matpower/case3.m", BFAPowerModel, nlp_solver, solution_processors=[sol_data_model!]) + result = solve_pf_bf("../test/data/matpower/case3.m", BFAPowerModel, nlp_solver, solution_processors=[sol_data_model!]) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -360,19 +360,19 @@ end @test isapprox(result["solution"]["dcline"]["1"]["pt"], -0.10; atol = 1e-4) end @testset "5-bus asymmetric case" begin - result = run_pf_bf("../test/data/matpower/case5_asym.m", BFAPowerModel, nlp_solver) + result = solve_pf_bf("../test/data/matpower/case5_asym.m", BFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) end @testset "5-bus case with hvdc line" begin - result = run_pf_bf("../test/data/matpower/case5_dc.m", BFAPowerModel, nlp_solver) + result = solve_pf_bf("../test/data/matpower/case5_dc.m", BFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) end @testset "6-bus case" begin - result = run_pf_bf("../test/data/matpower/case6.m", BFAPowerModel, nlp_solver, solution_processors=[sol_data_model!]) + result = solve_pf_bf("../test/data/matpower/case6.m", BFAPowerModel, nlp_solver, solution_processors=[sol_data_model!]) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -381,7 +381,7 @@ end end @testset "24-bus rts case" begin data = parse_file("../test/data/matpower/case24.m") - result = run_pf_bf(data, BFAPowerModel, nlp_solver) + result = solve_pf_bf(data, BFAPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 0; atol = 1e-2) @@ -395,7 +395,7 @@ end @testset "test sdp pf" begin # note: may have issues on linux (04/02/18) @testset "3-bus case" begin - result = run_pf("../test/data/matpower/case3.m", SDPWRMPowerModel, sdp_solver, solution_processors=[sol_data_model!]) + result = solve_pf("../test/data/matpower/case3.m", SDPWRMPowerModel, sdp_solver, solution_processors=[sol_data_model!]) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 0; atol = 1e-2) @@ -414,13 +414,13 @@ end end # note: may have issues on os x (05/07/18) @testset "5-bus asymmetric case" begin - result = run_pf("../test/data/matpower/case5_asym.m", SDPWRMPowerModel, sdp_solver) + result = solve_pf("../test/data/matpower/case5_asym.m", SDPWRMPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 0; atol = 1e-2) end @testset "6-bus case" begin - result = run_pf("../test/data/matpower/case6.m", SDPWRMPowerModel, sdp_solver, solution_processors=[sol_data_model!]) + result = solve_pf("../test/data/matpower/case6.m", SDPWRMPowerModel, sdp_solver, solution_processors=[sol_data_model!]) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 0; atol = 1e-2) @@ -428,7 +428,7 @@ end @test isapprox(result["solution"]["bus"]["4"]["vm"], 1.09999; atol = 1e-3) end @testset "24-bus rts case" begin - result = run_pf("../test/data/matpower/case24.m", SDPWRMPowerModel, sdp_solver) + result = solve_pf("../test/data/matpower/case24.m", SDPWRMPowerModel, sdp_solver) @test result["termination_status"] == OPTIMAL @test isapprox(result["objective"], 0; atol = 1e-2) diff --git a/test/psse.jl b/test/psse.jl index e355f4a04..6c4ddbe09 100644 --- a/test/psse.jl +++ b/test/psse.jl @@ -28,8 +28,8 @@ end set_costs!(data_mp) - result_pti = PowerModels.run_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) - result_mp = PowerModels.run_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) + result_pti = PowerModels.solve_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_mp = PowerModels.solve_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) @test result_pti["termination_status"] == LOCALLY_SOLVED @test result_mp["termination_status"] == LOCALLY_SOLVED @@ -42,8 +42,8 @@ end set_costs!(data_mp) - result_pti = PowerModels.run_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) - result_mp = PowerModels.run_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) + result_pti = PowerModels.solve_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_mp = PowerModels.solve_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) @test result_pti["termination_status"] == LOCALLY_SOLVED @test result_mp["termination_status"] == LOCALLY_SOLVED @@ -58,8 +58,8 @@ end set_costs!(data_mp) - result_pti = PowerModels.run_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) - result_mp = PowerModels.run_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) + result_pti = PowerModels.solve_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_mp = PowerModels.solve_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) @test result_pti["termination_status"] == LOCALLY_SOLVED @test result_mp["termination_status"] == LOCALLY_SOLVED @@ -82,12 +82,12 @@ end end end - result_opf = PowerModels.run_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_opf = PowerModels.solve_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) @test result_opf["termination_status"] == LOCALLY_SOLVED @test isapprox(result_opf["objective"], 29.4043; atol=1e-4) - result_pf = PowerModels.run_pf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_pf = PowerModels.solve_pf(data_pti, PowerModels.ACPPowerModel, nlp_solver) for (bus, vm, va) in zip(["1002", "1005", "1008", "1009"], [1.0032721, 1.0199983, 1.0203627, 1.03], @@ -105,8 +105,8 @@ end set_costs!(data_mp) - result_pti = PowerModels.run_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) - result_mp = PowerModels.run_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) + result_pti = PowerModels.solve_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_mp = PowerModels.solve_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) @test result_pti["termination_status"] == LOCALLY_SOLVED @test result_mp["termination_status"] == LOCALLY_SOLVED @@ -123,8 +123,8 @@ end set_costs!(data_mp) - result_pti = PowerModels.run_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) - result_mp = PowerModels.run_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) + result_pti = PowerModels.solve_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_mp = PowerModels.solve_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) @test result_pti["termination_status"] == LOCALLY_SOLVED @test result_mp["termination_status"] == LOCALLY_SOLVED @@ -143,8 +143,8 @@ end set_costs!(data_mp) - result_pti = PowerModels.run_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) - result_mp = PowerModels.run_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) + result_pti = PowerModels.solve_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_mp = PowerModels.solve_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) @test result_pti["termination_status"] == LOCALLY_SOLVED @test result_mp["termination_status"] == LOCALLY_SOLVED @@ -161,8 +161,8 @@ end set_costs!(data_mp) - result_pti = PowerModels.run_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) - result_mp = PowerModels.run_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) + result_pti = PowerModels.solve_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_mp = PowerModels.solve_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) @test result_pti["termination_status"] == LOCALLY_SOLVED @test result_mp["termination_status"] == LOCALLY_SOLVED @@ -178,8 +178,8 @@ end set_costs!(data_mp) - result_pti = PowerModels.run_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) - result_mp = PowerModels.run_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) + result_pti = PowerModels.solve_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_mp = PowerModels.solve_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) @test result_pti["termination_status"] == LOCALLY_SOLVED @test result_mp["termination_status"] == LOCALLY_SOLVED @@ -196,8 +196,8 @@ end set_costs!(data_mp) - result_pti = PowerModels.run_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) - result_mp = PowerModels.run_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) + result_pti = PowerModels.solve_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_mp = PowerModels.solve_opf(data_mp, PowerModels.ACPPowerModel, nlp_solver) @test result_pti["termination_status"] == LOCALLY_SOLVED @test result_mp["termination_status"] == LOCALLY_SOLVED @@ -259,12 +259,12 @@ end @test length(data_pti["bus"]) == 8 @test length(data_pti["branch"]) == 15 - result_opf = PowerModels.run_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_opf = PowerModels.solve_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) @test result_opf["termination_status"] == LOCALLY_SOLVED @test isapprox(result_opf["objective"], 10.00027; atol=1e-5) - result_pf = PowerModels.run_pf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_pf = PowerModels.solve_pf(data_pti, PowerModels.ACPPowerModel, nlp_solver) bus_data = zip( ["1001", "1002", "1003", "10002", "10003", "10004"], @@ -303,12 +303,12 @@ end end - result_opf = PowerModels.run_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_opf = PowerModels.solve_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) @test result_opf["termination_status"] == LOCALLY_SOLVED @test isapprox(result_opf["objective"], 10.0; atol=1e-5) - result_pf = PowerModels.run_pf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_pf = PowerModels.solve_pf(data_pti, PowerModels.ACPPowerModel, nlp_solver) for (bus, vm, va) in zip(["1001", "1002", "1003", "10001"], [1.09, 1.0, 1.0, 0.997], [2.304, 0., 6.042244, 2.5901]) @test isapprox(result_pf["solution"]["bus"][bus]["vm"], vm; atol=1e-1) @@ -327,12 +327,12 @@ end @test isapprox(data_pti["branch"]["1"]["g_fr"], 5e-3; atol=1e-4) @test isapprox(data_pti["branch"]["1"]["b_fr"], 6.74e-3; atol=1e-4) - result_opf = PowerModels.run_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_opf = PowerModels.solve_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) @test result_opf["termination_status"] == LOCALLY_SOLVED @test isapprox(result_opf["objective"], 701.637157; atol=1e-5) - result_pf = PowerModels.run_pf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_pf = PowerModels.solve_pf(data_pti, PowerModels.ACPPowerModel, nlp_solver) @test result_pf["termination_status"] == LOCALLY_SOLVED @test result_pf["objective"] == 0.0 @@ -351,12 +351,12 @@ end @test isapprox(data_pti["branch"]["1"]["g_fr"], 5e-3; atol=1e-4) @test isapprox(data_pti["branch"]["1"]["b_fr"], 6.74e-3; atol=1e-4) - result_opf = PowerModels.run_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_opf = PowerModels.solve_opf(data_pti, PowerModels.ACPPowerModel, nlp_solver) @test result_opf["termination_status"] == LOCALLY_SOLVED @test isapprox(result_opf["objective"], 10.4001; atol=1e-2) - result_pf = PowerModels.run_pf(data_pti, PowerModels.ACPPowerModel, nlp_solver) + result_pf = PowerModels.solve_pf(data_pti, PowerModels.ACPPowerModel, nlp_solver) @test result_pf["termination_status"] == LOCALLY_SOLVED @test result_pf["objective"] == 0.0 @@ -412,7 +412,7 @@ end end end - result = PowerModels.run_opf(data, PowerModels.ACPPowerModel, nlp_solver) + result = PowerModels.solve_opf(data, PowerModels.ACPPowerModel, nlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["objective"], 297.878089; atol=1e-4) @@ -479,11 +479,11 @@ end @test length(data["dcline"]) == 1 @test length(data["dcline"]["1"]) == 26 - opf = PowerModels.run_opf(data, PowerModels.ACPPowerModel, nlp_solver) + opf = PowerModels.solve_opf(data, PowerModels.ACPPowerModel, nlp_solver) @test opf["termination_status"] == LOCALLY_SOLVED @test isapprox(opf["objective"], 10.5; atol=1e-3) - pf = PowerModels.run_pf(data, PowerModels.ACPPowerModel, nlp_solver) + pf = PowerModels.solve_pf(data, PowerModels.ACPPowerModel, nlp_solver) @test pf["termination_status"] == LOCALLY_SOLVED end @@ -493,11 +493,11 @@ end @test length(data["dcline"]) == 1 @test length(data["dcline"]["1"]) == 26 - opf = PowerModels.run_opf(data, PowerModels.ACPPowerModel, nlp_solver) + opf = PowerModels.solve_opf(data, PowerModels.ACPPowerModel, nlp_solver) @test opf["termination_status"] == LOCALLY_SOLVED @test isapprox(opf["objective"], 21.8842; atol=1e-3) - pf = PowerModels.run_pf(data, PowerModels.ACPPowerModel, nlp_solver) + pf = PowerModels.solve_pf(data, PowerModels.ACPPowerModel, nlp_solver) @test pf["termination_status"] == LOCALLY_SOLVED end end @@ -513,4 +513,18 @@ end end end end + + @testset "Impedance and Current Load Conversions" begin + data = PowerModels.parse_file("../test/data/pti//parser_test_k.raw") + Vm_load = data["bus"]["103"]["vm"] + # Test current load only + @test isapprox(data["load"]["2"]["pd"], 250*Vm_load/data["baseMVA"], atol = 1e-6) + @test isapprox(data["load"]["2"]["qd"], 30*Vm_load/data["baseMVA"], atol = 1e-6) + # Test current impedance load only + @test isapprox(data["load"]["3"]["pd"], 250*Vm_load^2/data["baseMVA"], atol = 1e-6) + @test isapprox(data["load"]["3"]["qd"], 30*Vm_load^2/data["baseMVA"], atol = 1e-6) + # Test mixed load types + @test isapprox(data["load"]["4"]["pd"], (250 + 250*Vm_load)/data["baseMVA"], atol = 1e-6) + @test isapprox(data["load"]["4"]["qd"], (30 + 30*Vm_load^2)/data["baseMVA"], atol = 1e-6) + end end diff --git a/test/pti.jl b/test/pti.jl index 242ef285e..0b662811c 100644 --- a/test/pti.jl +++ b/test/pti.jl @@ -344,12 +344,12 @@ end function compare_pf(filename::String) source_data = parse_file(filename) - source_solution = PowerModels.run_pf(source_data, ACPPowerModel, nlp_solver)["solution"] + source_solution = PowerModels.solve_pf(source_data, ACPPowerModel, nlp_solver)["solution"] file_tmp = "../test/data/tmp.raw" PowerModels.export_pti(file_tmp, source_data) destination_data = parse_file(file_tmp) - destination_solution = PowerModels.run_pf(destination_data, ACPPowerModel, nlp_solver)["solution"] + destination_solution = PowerModels.solve_pf(destination_data, ACPPowerModel, nlp_solver)["solution"] rm(file_tmp) @test InfrastructureModels.compare_dict(source_solution, destination_solution) diff --git a/test/runtests.jl b/test/runtests.jl index dcaa3b33e..f1dc0af1b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -19,15 +19,6 @@ import SparseArrays using Test -# compat for JuMP v0.22/v0.23 transition -# can be removed after dropping support for v0.22 -if !isdefined(JuMP, :num_nonlinear_constraints) - num_nonlinear_constraints = JuMP.num_nl_constraints -else - num_nonlinear_constraints = JuMP.num_nonlinear_constraints -end - - # default setup for solvers nlp_solver = JuMP.optimizer_with_attributes(Ipopt.Optimizer, "tol"=>1e-6, "print_level"=>0) nlp_ws_solver = JuMP.optimizer_with_attributes(Ipopt.Optimizer, "tol"=>1e-6, "mu_init"=>1e-4, "print_level"=>0) @@ -54,8 +45,6 @@ include("common.jl") include("data.jl") - include("data-mc.jl") - include("data-basic.jl") include("model.jl") diff --git a/test/tnep.jl b/test/tnep.jl index 19080f984..6924bc11b 100644 --- a/test/tnep.jl +++ b/test/tnep.jl @@ -18,7 +18,7 @@ end @testset "3-bus case" begin data = PowerModels.parse_file("../test/data/matpower/case3_tnep.m") calc_thermal_limits!(data) - result = run_tnep(data, ACPPowerModel, minlp_solver) + result = solve_tnep(data, ACPPowerModel, minlp_solver) check_tnep_status(result["solution"]) check_ne_branch_keys(result["solution"]) @@ -28,7 +28,7 @@ end end @testset "5-bus case" begin - result = run_tnep("../test/data/matpower/case5_tnep.m", ACPPowerModel, minlp_solver) + result = solve_tnep("../test/data/matpower/case5_tnep.m", ACPPowerModel, minlp_solver) check_tnep_status(result["solution"]) @@ -42,7 +42,7 @@ end @testset "3-bus case" begin data = PowerModels.parse_file("../test/data/matpower/case3_tnep.m") calc_thermal_limits!(data) - result = run_tnep(data, SOCWRPowerModel, minlp_solver) + result = solve_tnep(data, SOCWRPowerModel, minlp_solver) check_tnep_status(result["solution"]) check_ne_branch_keys(result["solution"]) @@ -52,7 +52,7 @@ end end @testset "5-bus rts case" begin - result = run_tnep("../test/data/matpower/case5_tnep.m", SOCWRPowerModel, minlp_solver) + result = solve_tnep("../test/data/matpower/case5_tnep.m", SOCWRPowerModel, minlp_solver) check_tnep_status(result["solution"]) @@ -67,7 +67,7 @@ end # @testset "3-bus case" begin # data = PowerModels.parse_file("../test/data/matpower/case3_tnep.m") # calc_thermal_limits!(data) -# result = run_tnep(data, QCRMPowerModel, minlp_solver) +# result = solve_tnep(data, QCRMPowerModel, minlp_solver) # check_tnep_status(result["solution"]) # check_ne_branch_keys(result["solution"]) @@ -77,7 +77,7 @@ end # end # @testset "5-bus rts case" begin -# result = run_tnep("../test/data/matpower/case5_tnep.m", QCRMPowerModel, minlp_solver) +# result = solve_tnep("../test/data/matpower/case5_tnep.m", QCRMPowerModel, minlp_solver) # check_tnep_status(result["solution"]) @@ -91,7 +91,7 @@ end @testset "3-bus case" begin data = PowerModels.parse_file("../test/data/matpower/case3_tnep.m") calc_thermal_limits!(data) - result = run_tnep(data, DCPPowerModel, minlp_solver) + result = solve_tnep(data, DCPPowerModel, minlp_solver) check_tnep_status(result["solution"]) check_ne_branch_keys(result["solution"]) @@ -101,7 +101,7 @@ end end @testset "5-bus case" begin - result = run_tnep("../test/data/matpower/case5_tnep.m", DCPPowerModel, minlp_solver) + result = solve_tnep("../test/data/matpower/case5_tnep.m", DCPPowerModel, minlp_solver) check_tnep_status(result["solution"]) @@ -113,7 +113,7 @@ end @testset "test matpower dc tnep" begin @testset "5-bus case with matpower DCMP model and TNEP" begin - result = run_tnep("../test/data/matpower/case5_tnep.m", DCMPPowerModel, minlp_solver) + result = solve_tnep("../test/data/matpower/case5_tnep.m", DCMPPowerModel, minlp_solver) @test result["termination_status"] == LOCALLY_SOLVED @test isapprox(result["solution"]["ne_branch"]["1"]["built"], 1.0; atol = 1e-5) @@ -128,7 +128,7 @@ end @testset "3-bus case" begin data = PowerModels.parse_file("../test/data/matpower/case3_tnep.m") calc_thermal_limits!(data) - result = run_tnep(data, DCPLLPowerModel, minlp_solver) + result = solve_tnep(data, DCPLLPowerModel, minlp_solver) check_tnep_status(result["solution"]) @@ -138,7 +138,7 @@ end =# @testset "5-bus case" begin - result = run_tnep("../test/data/matpower/case5_tnep.m", DCPLLPowerModel, minlp_solver) + result = solve_tnep("../test/data/matpower/case5_tnep.m", DCPLLPowerModel, minlp_solver) check_tnep_status(result["solution"]) check_ne_branch_keys(result["solution"]) @@ -152,7 +152,7 @@ end @testset "3-bus case" begin data = PowerModels.parse_file("../test/data/matpower/case3_tnep.m") calc_thermal_limits!(data) - result = run_tnep(data, LPACCPowerModel, minlp_solver) + result = solve_tnep(data, LPACCPowerModel, minlp_solver) check_tnep_status(result["solution"]) check_ne_branch_keys(result["solution"]) @@ -162,7 +162,7 @@ end end @testset "5-bus case" begin - result = run_tnep("../test/data/matpower/case5_tnep.m", LPACCPowerModel, minlp_solver) + result = solve_tnep("../test/data/matpower/case5_tnep.m", LPACCPowerModel, minlp_solver) check_tnep_status(result["solution"]) @@ -175,7 +175,7 @@ end @testset "3-bus case" begin data = PowerModels.parse_file("../test/data/matpower/case3_tnep.m") calc_thermal_limits!(data) - result = run_tnep(data, SOCWRPowerModel, minlp_solver) + result = solve_tnep(data, SOCWRPowerModel, minlp_solver) check_tnep_status(result["solution"]) diff --git a/test/util.jl b/test/util.jl index a9d916301..f6e3e8730 100644 --- a/test/util.jl +++ b/test/util.jl @@ -1,15 +1,15 @@ @testset "obbt with trilinear convex hull relaxation" begin @testset "3-bus case" begin - result_ac = run_ac_opf("../test/data/matpower/case3.m", nlp_solver); + result_ac = solve_ac_opf("../test/data/matpower/case3.m", nlp_solver); upper_bound = result_ac["objective"] - data, stats = run_obbt_opf!("../test/data/matpower/case3.m", nlp_solver, model_type=QCLSPowerModel); + data, stats = solve_obbt_opf!("../test/data/matpower/case3.m", nlp_solver, model_type=QCLSPowerModel); @test isapprox(stats["final_relaxation_objective"], 5901.96; atol=1e0) @test isnan(stats["final_rel_gap_from_ub"]) @test stats["iteration_count"] == 5 - data, stats = run_obbt_opf!("../test/data/matpower/case3.m", nlp_solver, + data, stats = solve_obbt_opf!("../test/data/matpower/case3.m", nlp_solver, model_type = QCLSPowerModel, upper_bound = upper_bound, upper_bound_constraint = true, @@ -23,15 +23,15 @@ end @testset "obbt with qc relaxation" begin @testset "3-bus case" begin - result_ac = run_ac_opf("../test/data/matpower/case3.m", nlp_solver); + result_ac = solve_ac_opf("../test/data/matpower/case3.m", nlp_solver); upper_bound = result_ac["objective"] - data, stats = run_obbt_opf!("../test/data/matpower/case3.m", nlp_solver, model_type=QCRMPowerModel); + data, stats = solve_obbt_opf!("../test/data/matpower/case3.m", nlp_solver, model_type=QCRMPowerModel); @test isapprox(stats["final_relaxation_objective"], 5900.04; atol=1e0) @test isnan(stats["final_rel_gap_from_ub"]) @test stats["iteration_count"] == 5 - data, stats = run_obbt_opf!("../test/data/matpower/case3.m", nlp_solver, + data, stats = solve_obbt_opf!("../test/data/matpower/case3.m", nlp_solver, model_type = QCRMPowerModel, upper_bound = upper_bound, upper_bound_constraint = true, @@ -47,10 +47,10 @@ end data["gen"]["1"]["cost"] = data["gen"]["1"]["cost"][2:3] data["gen"]["2"]["cost"] = data["gen"]["2"]["cost"][2:3] - result_ac = run_ac_opf(data, nlp_solver); + result_ac = solve_ac_opf(data, nlp_solver); upper_bound = result_ac["objective"] - data, stats = run_obbt_opf!(data, nlp_solver, + data, stats = solve_obbt_opf!(data, nlp_solver, model_type=QCRMPowerModel, upper_bound = upper_bound, upper_bound_constraint = true); @@ -63,8 +63,8 @@ end @testset "opf with flow cuts" begin @testset "ac 5-bus case" begin - result_base = run_opf("../test/data/matpower/case5.m", ACPPowerModel, nlp_solver) - result_cuts = run_opf_branch_power_cuts("../test/data/matpower/case5.m", ACPPowerModel, nlp_solver) + result_base = solve_opf("../test/data/matpower/case5.m", ACPPowerModel, nlp_solver) + result_cuts = solve_opf_branch_power_cuts("../test/data/matpower/case5.m", ACPPowerModel, nlp_solver) @test result_base["termination_status"] == LOCALLY_SOLVED @test result_cuts["termination_status"] == LOCALLY_SOLVED @@ -75,8 +75,8 @@ end end end @testset "ac 14-bus case" begin - result_base = run_opf("../test/data/matpower/case14.m", ACPPowerModel, nlp_solver) - result_cuts = run_opf_branch_power_cuts("../test/data/matpower/case14.m", ACPPowerModel, nlp_solver) + result_base = solve_opf("../test/data/matpower/case14.m", ACPPowerModel, nlp_solver) + result_cuts = solve_opf_branch_power_cuts("../test/data/matpower/case14.m", ACPPowerModel, nlp_solver) @test result_base["termination_status"] == LOCALLY_SOLVED @test result_cuts["termination_status"] == LOCALLY_SOLVED @@ -88,8 +88,8 @@ end end @testset "soc 5-bus case" begin - result_base = run_opf("../test/data/matpower/case5.m", SOCWRPowerModel, nlp_solver) - result_cuts = run_opf_branch_power_cuts("../test/data/matpower/case5.m", SOCWRPowerModel, nlp_solver) + result_base = solve_opf("../test/data/matpower/case5.m", SOCWRPowerModel, nlp_solver) + result_cuts = solve_opf_branch_power_cuts("../test/data/matpower/case5.m", SOCWRPowerModel, nlp_solver) @test result_base["termination_status"] == LOCALLY_SOLVED @test result_cuts["termination_status"] == LOCALLY_SOLVED @@ -99,8 +99,8 @@ end end end @testset "soc 14-bus case" begin - result_base = run_opf("../test/data/matpower/case14.m", SOCWRPowerModel, nlp_solver) - result_cuts = run_opf_branch_power_cuts("../test/data/matpower/case14.m", SOCWRPowerModel, nlp_solver) + result_base = solve_opf("../test/data/matpower/case14.m", SOCWRPowerModel, nlp_solver) + result_cuts = solve_opf_branch_power_cuts("../test/data/matpower/case14.m", SOCWRPowerModel, nlp_solver) @test result_base["termination_status"] == LOCALLY_SOLVED @test result_cuts["termination_status"] == LOCALLY_SOLVED @@ -111,8 +111,8 @@ end end @testset "dc 5-bus case" begin - result_base = run_opf("../test/data/matpower/case5.m", DCPPowerModel, milp_solver) - result_cuts = run_opf_branch_power_cuts("../test/data/matpower/case5.m", DCPPowerModel, milp_solver) + result_base = solve_opf("../test/data/matpower/case5.m", DCPPowerModel, milp_solver) + result_cuts = solve_opf_branch_power_cuts("../test/data/matpower/case5.m", DCPPowerModel, milp_solver) @test result_base["termination_status"] == OPTIMAL @test result_cuts["termination_status"] == OPTIMAL @@ -122,8 +122,8 @@ end end end @testset "dc 14-bus case" begin - result_base = run_opf("../test/data/matpower/case14.m", DCPPowerModel, nlp_solver) - result_cuts = run_opf_branch_power_cuts("../test/data/matpower/case14.m", DCPPowerModel, nlp_solver) + result_base = solve_opf("../test/data/matpower/case14.m", DCPPowerModel, nlp_solver) + result_cuts = solve_opf_branch_power_cuts("../test/data/matpower/case14.m", DCPPowerModel, nlp_solver) @test result_base["termination_status"] == LOCALLY_SOLVED @test result_cuts["termination_status"] == LOCALLY_SOLVED @@ -137,8 +137,8 @@ end @testset "ptdf opf with flow cuts" begin @testset "dc 5-bus case" begin - result_base = run_opf("../test/data/matpower/case5.m", DCPPowerModel, milp_solver) - result_cuts = run_opf_ptdf_branch_power_cuts("../test/data/matpower/case5.m", milp_solver) + result_base = solve_opf("../test/data/matpower/case5.m", DCPPowerModel, milp_solver) + result_cuts = solve_opf_ptdf_branch_power_cuts("../test/data/matpower/case5.m", milp_solver) @test result_base["termination_status"] == OPTIMAL @test result_cuts["termination_status"] == OPTIMAL @@ -148,8 +148,8 @@ end end end @testset "dc 5-bus ext case" begin - result_base = run_opf("../test/data/matpower/case5_ext.m", DCPPowerModel, milp_solver) - result_cuts = run_opf_ptdf_branch_power_cuts("../test/data/matpower/case5_ext.m", milp_solver) + result_base = solve_opf("../test/data/matpower/case5_ext.m", DCPPowerModel, milp_solver) + result_cuts = solve_opf_ptdf_branch_power_cuts("../test/data/matpower/case5_ext.m", milp_solver) @test result_base["termination_status"] == OPTIMAL @test result_cuts["termination_status"] == OPTIMAL @@ -159,8 +159,8 @@ end end end @testset "dc 14-bus case" begin - result_base = run_opf("../test/data/matpower/case14.m", DCPPowerModel, nlp_solver) - result_cuts = run_opf_ptdf_branch_power_cuts("../test/data/matpower/case14.m", nlp_solver) + result_base = solve_opf("../test/data/matpower/case14.m", DCPPowerModel, nlp_solver) + result_cuts = solve_opf_ptdf_branch_power_cuts("../test/data/matpower/case14.m", nlp_solver) @test result_base["termination_status"] == LOCALLY_SOLVED @test result_cuts["termination_status"] == LOCALLY_SOLVED diff --git a/test/warmstart.jl b/test/warmstart.jl index 3c0b450ef..24058f71e 100644 --- a/test/warmstart.jl +++ b/test/warmstart.jl @@ -40,32 +40,32 @@ end @testset "dc warm starts" begin @testset "5 bus case" begin data = PowerModels.parse_file("../test/data/matpower/case5.m") - result = run_dc_opf(data, nlp_solver) + result = solve_dc_opf(data, nlp_solver) PowerModels.update_data!(data, result["solution"]) # 14 iterations - result = run_dc_opf(data, nlp_solver); + result = solve_dc_opf(data, nlp_solver); set_dc_start!(data) # 6 iterations - result = run_dc_opf(data, nlp_ws_solver); + result = solve_dc_opf(data, nlp_ws_solver); end @testset "5 bus pwl case" begin data = PowerModels.parse_file("../test/data/matpower/case5_pwlc.m") - result = run_dc_opf(data, nlp_solver) + result = solve_dc_opf(data, nlp_solver) PowerModels.update_data!(data, result["solution"]) # 35 iterations - result = run_dc_opf(data, nlp_solver); + result = solve_dc_opf(data, nlp_solver); set_dc_start!(data) # 6 iterations - result = run_dc_opf(data, nlp_ws_solver); + result = solve_dc_opf(data, nlp_ws_solver); end end @@ -73,32 +73,32 @@ end @testset "ac warm starts" begin @testset "5 bus case" begin data = PowerModels.parse_file("../test/data/matpower/case5.m") - result = run_ac_opf(data, nlp_solver) + result = solve_ac_opf(data, nlp_solver) PowerModels.update_data!(data, result["solution"]) # 22 iterations - result = run_ac_opf(data, nlp_solver); + result = solve_ac_opf(data, nlp_solver); set_ac_start!(data) # 19 iterations - result = run_ac_opf(data, nlp_ws_solver); + result = solve_ac_opf(data, nlp_ws_solver); end @testset "5 bus pwl case" begin data = PowerModels.parse_file("../test/data/matpower/case5_pwlc.m") - result = run_ac_opf(data, nlp_solver) + result = solve_ac_opf(data, nlp_solver) PowerModels.update_data!(data, result["solution"]) # 40 iterations - result = run_ac_opf(data, nlp_solver); + result = solve_ac_opf(data, nlp_solver); set_ac_start!(data) # 12 iterations - result = run_ac_opf(data, nlp_ws_solver); + result = solve_ac_opf(data, nlp_ws_solver); end end