Skip to content

Commit

Permalink
drop support for multiconductor, closes #872
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoffrin committed Jan 1, 2024
1 parent e6b5a49 commit 8ebecd7
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 173 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PowerModels.jl Change Log
- 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)
- 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)
Expand Down
19 changes: 2 additions & 17 deletions src/core/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -30,20 +21,14 @@ 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"
data_type = _IM.ismultinetwork(data) ? "multi-network" : "single-network"
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)")
Expand Down Expand Up @@ -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
Expand Down
35 changes: 0 additions & 35 deletions src/core/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1045,41 +1045,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)
Expand Down
22 changes: 6 additions & 16 deletions src/core/objective.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,15 @@ function expression_pg_cost(pm::AbstractPowerModel; report::Bool=true)
pg_cost = var(pm, n)[:pg_cost] = Dict{Int,Any}()

for (i,gen) in ref(pm, n, :gen)
if isa(var(pm, n, :pg, i), Array)
pg_terms = [var(pm, n, :pg, i)[c] for c in conductor_ids(pm, n)]
else
pg_terms = [var(pm, n, :pg, i)]
end
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 = sum(gen["pmin"][c] for c in conductor_ids(pm, n))
pmax = sum(gen["pmax"][c] for c in conductor_ids(pm, n))
pmin = gen["pmin"]
pmax = gen["pmax"]
end

points = calc_pwl_points(gen["ncost"], gen["cost"], pmin, pmax)
Expand Down Expand Up @@ -236,19 +232,15 @@ function expression_p_dc_cost(pm::AbstractPowerModel; report::Bool=true)
for (i,dcline) in ref(pm, n, :dcline)
arc = (i, dcline["f_bus"], dcline["t_bus"])

if isa(var(pm, n, :pg, i), Array)
p_dc_terms = [var(pm, n, :p_dc, arc)[c] for c in conductor_ids(pm, n)]
else
p_dc_terms = [var(pm, n, :p_dc, arc)]
end
p_dc_terms = [var(pm, n, :p_dc, arc)]

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 = sum(dcline["pminf"][c] for c in conductor_ids(pm, n))
pmax = sum(dcline["pmaxf"][c] for c in conductor_ids(pm, n))
pmin = dcline["pminf"]
pmax = dcline["pmaxf"]
end

# note pmin/pmax may be different from dcline["pminf"]/dcline["pmaxf"] in the on/off case
Expand Down Expand Up @@ -386,8 +378,6 @@ 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)
Expand Down
23 changes: 5 additions & 18 deletions src/core/ref.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/core/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 4 additions & 12 deletions src/form/acp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -570,23 +570,15 @@ 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)
sc = var(pm, n, :sc, i)
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

15 changes: 3 additions & 12 deletions src/form/acr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,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)
Expand All @@ -226,17 +226,8 @@ 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


Expand Down
8 changes: 2 additions & 6 deletions src/form/apo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,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)
Expand Down
16 changes: 3 additions & 13 deletions src/form/bf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/form/dcp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
20 changes: 4 additions & 16 deletions src/form/shared.jl
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ function constraint_current_limit(pm::AbstractWModels, n::Int, f_idx, c_rating_a
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)
Expand All @@ -402,19 +402,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
1 change: 0 additions & 1 deletion src/io/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/io/json.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 1 addition & 3 deletions src/prob/tnep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion src/util/obbt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 8ebecd7

Please sign in to comment.