Skip to content

Commit

Permalink
Update objective.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Sep 4, 2023
1 parent 48f0460 commit a3dc120
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions src/core/objective.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,6 @@ function objective_min_fuel_and_flow_cost_polynomial(pm::AbstractPowerModel; kwa
end
end

"""
_pow(x, d::Int)
Compute `x^d` with special case handling for `d == 0` and `d == 1` to avoid
JuMP's default implementation which returns a quadratic for `d in {0, 1, 2}`.
"""
function _pow(x, d::Int)
if d == 0
return 1.0
elseif d == 1
return x
else
return x^d
end
end

""
function _objective_min_fuel_and_flow_cost_polynomial_linquad(pm::AbstractPowerModel; report::Bool=true)
gen_cost = Dict()
Expand All @@ -149,7 +133,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

Expand All @@ -158,7 +142,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
Expand Down Expand Up @@ -279,7 +263,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

Expand All @@ -289,7 +273,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
Expand Down Expand Up @@ -322,7 +306,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
Expand All @@ -343,7 +327,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
Expand Down

0 comments on commit a3dc120

Please sign in to comment.