Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Apr 26, 2023
1 parent e319a7b commit b71ef31
Showing 1 changed file with 6 additions and 37 deletions.
43 changes: 6 additions & 37 deletions src/core/objective.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b71ef31

Please sign in to comment.