Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPD: JuMP v1.15 #459

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "PowerModelsDistribution"
uuid = "d7431456-977f-11e9-2de3-97ff7677985e"
authors = ["David M Fobes <dfobes@lanl.gov>", "Carleton Coffrin"]
repo = "https://github.com/lanl-ansi/PowerModelsDistribution.jl.git"
version = "0.15.2"
version = "0.16.0"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand All @@ -29,7 +29,7 @@ Graphs = "1"
InfrastructureModels = "0.7.3, 0.7.5"
Ipopt = "0.9, 1.0.2, 1.1"
JSON = "0.18, 0.19, 0.20, 0.21"
JuMP = "0.22, 0.23, 1"
JuMP = "1.15"
LoggingExtras = "0.4.7, 1"
PolyhedralRelaxations = "0.3.5"
SCS = "0.9, 1.0, 1.1"
Expand Down
1 change: 0 additions & 1 deletion docs/src/reference/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ nw_ids
## Helper functions

```@docs
@smart_constraint
set_lower_bound
set_upper_bound
comp_start_value
Expand Down
16 changes: 0 additions & 16 deletions src/core/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,6 @@ function _check_var_keys(vars, keys, var_name, comp_name)
end


"""
@smart_constraint model::JuMP.Model vars::Vector expr::JuMP.Expression

Detection of whether a constraint should be NL or not"
"""
macro smart_constraint(model, vars, expr)
esc(quote
if _has_nl_expression($vars)
JuMP.@NLconstraint($model, $expr)
else
JuMP.@constraint($model, $expr)
end
end)
end


"""
function set_lower_bound(
x::JuMP.VariableRef,
Expand Down
25 changes: 0 additions & 25 deletions src/core/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -811,31 +811,6 @@ function _make_full_matrix_variable(diag::Vector{T}, lowertriangle::Vector{T}, u
return matrix
end

# TODO refactor into several functions
"helper to determine if expession has any Nonlinear terms"
function _has_nl_expression(x)::Bool
if isa(x, JuMP.NonlinearExpression)
return true
elseif isa(x, Array)
if any(_has_nl_expression.(x))
return true
end
elseif isa(x, Dict)
for i in values(x)
if _has_nl_expression(i)
return true
end
end
elseif isa(x, JuMP.Containers.DenseAxisArray)
for i in values(x.data)
if _has_nl_expression(i)
return true
end
end
end
return false
end


"""
correct_mc_voltage_angle_differences!(data::Dict{String,<:Any}, default_pad::Real=deg2rad(10.0))
Expand Down
34 changes: 17 additions & 17 deletions src/core/objective.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ end

"gen connections adaptation of min fuel cost polynomial linquad objective"
function _objective_mc_min_fuel_cost_polynomial_linquad(pm::AbstractUnbalancedPowerModel; report::Bool=true)
pg_contains_nl_exp = any(x<:JuMP.NonlinearExpression for x in vcat([typeof.(isa(pg, JuMP.Containers.DenseAxisArray) ? pg.data : pg) for nw in nw_ids(pm) for (id,pg) in var(pm, nw, :pg)]...))
pg_contains_nl_exp = any(x<:JuMP.NonlinearExpr for x in vcat([typeof.(isa(pg, JuMP.Containers.DenseAxisArray) ? pg.data : pg) for nw in nw_ids(pm) for (id,pg) in var(pm, nw, :pg)]...))
gen_cost = Dict()

if !pg_contains_nl_exp
Expand Down Expand Up @@ -285,16 +285,16 @@ function _objective_mc_min_fuel_cost_polynomial_linquad(pm::AbstractUnbalancedPo
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[i] for i in 1:int_dim) + gen["cost"][2])
gen_cost[(n,i)] = JuMP.@expression(pm.model, -gen["cost"][1]*sum(-pg[i] for i in 1:int_dim) + gen["cost"][2])
elseif length(gen["cost"]) == 3
gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, gen["cost"][1]*sum(pg[i] for i in 1:int_dim)^2 + gen["cost"][2]*sum(pg[i] for i in 1:int_dim) + gen["cost"][3])
gen_cost[(n,i)] = JuMP.@expression(pm.model, gen["cost"][1]*sum(pg[i] for i in 1:int_dim)^2 + -gen["cost"][2]*sum(-pg[i] for i in 1:int_dim) + gen["cost"][3])
else
gen_cost[(n,i)] = 0.0
end
end
end

return JuMP.@NLobjective(pm.model, Min,
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))
Expand Down Expand Up @@ -375,21 +375,21 @@ function _objective_mc_min_fuel_cost_polynomial_nl(pm::AbstractUnbalancedPowerMo

cost_rev = reverse(gen["cost"])
if length(cost_rev) == 1
gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1])
gen_cost[(n,i)] = JuMP.@expression(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)
gen_cost[(n,i)] = JuMP.@expression(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)
gen_cost[(n,i)] = JuMP.@expression(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)) )
gen_cost[(n,i)] = JuMP.@expression(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)
gen_cost[(n,i)] = JuMP.@expression(pm.model, 0.0)
end
end
end

return JuMP.@NLobjective(pm.model, Min,
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))
Expand All @@ -406,21 +406,21 @@ function _objective_mc_min_fuel_cost_polynomial_nl_switch(pm::AbstractUnbalanced

cost_rev = reverse(gen["cost"])
if length(cost_rev) == 1
gen_cost[(n,i)] = JuMP.@NLexpression(pm.model, cost_rev[1])
gen_cost[(n,i)] = JuMP.@expression(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)
gen_cost[(n,i)] = JuMP.@expression(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)
gen_cost[(n,i)] = JuMP.@expression(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)) )
gen_cost[(n,i)] = JuMP.@expression(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)
gen_cost[(n,i)] = JuMP.@expression(pm.model, 0.0)
end
end
end

return JuMP.@NLobjective(pm.model, Min,
return JuMP.@objective(pm.model, Min,
sum(
sum( gen_cost[(n,i)] for (i,gen) in nw_ref[:gen] ) +
sum( var(pm, n, :switch_state, l) for l in ids(pm, n, :switch_dispatchable))
Expand Down Expand Up @@ -448,7 +448,7 @@ function objective_variable_pg_cost(pm::AbstractUnbalancedIVRModel; report::Bool
for (i, gen) in nw_ref[:gen]
pg = var(pm, n, :pg, i)
for line in gen_lines[i]
JuMP.@NLconstraint(pm.model, pg_cost[i] >= line.slope*sum(pg[c] for c in gen["connections"]) + line.intercept)
JuMP.@constraint(pm.model, pg_cost[i] >= -line.slope*sum(-pg[c] for c in gen["connections"]) + line.intercept)
end
end
end
Expand Down
18 changes: 3 additions & 15 deletions src/core/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,9 @@ function _IM.solution_preprocessor(pm::AbstractUnbalancedPowerModel, solution::D
end


"custom `build_solution_values` for multiconductor (vector) variables"
function _IM.build_solution_values(var::JuMP.Containers.DenseAxisArray{<:JuMP.VariableRef,1})
return JuMP.value.(var.data)
end


"custom `build_solution_values` for multiconductor (vector) nonlinear expressions"
function _IM.build_solution_values(var::JuMP.Containers.DenseAxisArray{<:JuMP.NonlinearExpression,1})
return JuMP.value.(var.data)
end


"custom `build_solution_values` for multiconductor (vector) generic affine expressions"
function _IM.build_solution_values(var::JuMP.Containers.DenseAxisArray{<:JuMP.GenericAffExpr,1})
return JuMP.value.(var.data)
"custom `build_solution_values` for multiconductor (vector) JuMP expressions"
function _IM.build_solution_values(var::JuMP.AbstractJuMPScalar)
return JuMP.value(var)
end


Expand Down
Loading
Loading