From b71ef311d22b2acc19b188d80a296c1d300df24c Mon Sep 17 00:00:00 2001 From: odow Date: Wed, 26 Apr 2023 17:02:32 +1200 Subject: [PATCH] Update --- src/core/objective.jl | 43 ++++++------------------------------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/src/core/objective.jl b/src/core/objective.jl index aca4167d..638ab604 100644 --- a/src/core/objective.jl +++ b/src/core/objective.jl @@ -123,37 +123,6 @@ function objective_min_fuel_and_flow_cost_polynomial(pm::AbstractPowerModel; kwa end end -""" - _pow(x, i) - -A type-unstable version of `x^i` becaues using the base `x^i` for JuMP variables -has some unusual behavior: - -```julia -julia> model = Model(); - -julia> @variable(model, x) -x - -julia> typeof(x^1) -QuadExpr (alias for GenericQuadExpr{Float64, VariableRef}) - -julia> typeof(x^1.0) -NonlinearExpr -``` -""" -function _pow(x, i) - if i == 0 - return 1 - elseif i == 1 - return x - elseif i == 2 - return x^2 - else - return x^Float64(i) - end -end - "" function _objective_min_fuel_and_flow_cost_polynomial_linquad(pm::AbstractPowerModel; report::Bool=true) @@ -165,7 +134,7 @@ function _objective_min_fuel_and_flow_cost_polynomial_linquad(pm::AbstractPowerM pg = sum( var(pm, n, :pg, i)[c] for c in conductor_ids(pm, n) ) gen_cost[(n, i)] = JuMP.@expression( pm.model, - sum(v * _pow(pg, d - 1) for (d, v) in enumerate(reverse(gen["cost"]))), + sum(v * pg^(d-1) for (d, v) in enumerate(reverse(gen["cost"]))), ) end @@ -174,7 +143,7 @@ function _objective_min_fuel_and_flow_cost_polynomial_linquad(pm::AbstractPowerM p_dc = sum( var(pm, n, :p_dc, from_idx[i])[c] for c in conductor_ids(pm, n) ) dcline_cost[(n, i)] = JuMP.@expression( pm.model, - sum(v * _pow(p_dc, d - 1) for (d, v) in enumerate(reverse(dcline["cost"]))), + sum(v * p_dc^(d-1) for (d, v) in enumerate(reverse(dcline["cost"]))), ) end end @@ -295,7 +264,7 @@ function _objective_min_fuel_and_flow_cost_polynomial_nl(pm::AbstractPowerModel; pg = sum( var(pm, n, :pg, i)[c] for c in conductor_ids(pm, n)) gen_cost[(n,i)] = JuMP.@expression( pm.model, - sum(v * _pow(pg, d-1) for (d, v) in enumerate(reverse(gen["cost"]))), + sum(v * pg^(d-1) for (d, v) in enumerate(reverse(gen["cost"]))), ) end @@ -305,7 +274,7 @@ function _objective_min_fuel_and_flow_cost_polynomial_nl(pm::AbstractPowerModel; p_dc = sum( var(pm, n, :p_dc, from_idx[i])[c] for c in conductor_ids(pm, n)) dcline_cost[(n,i)] = JuMP.@expression( pm.model, - sum(v * _pow(p_dc, d - 1) for (d, v) in enumerate(reverse(dcline["cost"]))), + sum(v * p_dc^(d-1) for (d, v) in enumerate(reverse(dcline["cost"]))), ) end end @@ -338,7 +307,7 @@ function _objective_min_fuel_cost_polynomial_linquad(pm::AbstractPowerModel; rep pg = sum( var(pm, n, :pg, i)[c] for c in conductor_ids(pm, n) ) gen_cost[(n, i)] = JuMP.@expression( pm.model, - sum(v * _pow(pg, d - 1) for (d, v) in enumerate(reverse(gen["cost"]))), + sum(v * pg^(d-1) for (d, v) in enumerate(reverse(gen["cost"]))), ) end end @@ -359,7 +328,7 @@ function _objective_min_fuel_cost_polynomial_nl(pm::AbstractPowerModel; report:: pg = sum( var(pm, n, :pg, i)[c] for c in conductor_ids(pm, n)) gen_cost[(n,i)] = JuMP.@expression( pm.model, - sum(v * _pow(pg, d - 1) for (d, v) in enumerate(reverse(gen["cost"]))), + sum(v * pg^(d-1) for (d, v) in enumerate(reverse(gen["cost"]))), ) end end