Skip to content

Commit

Permalink
add monotonicity check
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-lara committed Sep 28, 2024
1 parent a3a3f25 commit f617917
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ function _add_quadraticcurve_variable_cost!(
proportional_term_per_unit::Vector{Float64},
quadratic_term_per_unit::Vector{Float64},
) where {T <: VariableType}
lb, ub = PSY.get_active_power_limits(component)
for t in get_time_steps(container)
_check_quadratic_monotonicity(
PSY.get_name(component),
quadratic_term_per_unit[t],
proportional_term_per_unit[t],
lb,
ub,
)
_add_quadraticcurve_variable_term_to_model!(
container,
T(),
Expand All @@ -66,6 +74,13 @@ function _add_quadraticcurve_variable_cost!(
proportional_term_per_unit::Float64,
quadratic_term_per_unit::Float64,
) where {T <: VariableType}
lb, ub = PSY.get_active_power_limits(component)
_check_quadratic_monotonicity(PSY.get_name(component),
quadratic_term_per_unit,
proportional_term_per_unit,
lb,
ub,
)
for t in get_time_steps(container)
_add_quadraticcurve_variable_term_to_model!(
container,
Expand All @@ -79,6 +94,23 @@ function _add_quadraticcurve_variable_cost!(
return
end

function _check_quadratic_monotonicity(
name::String,
quad_term::Float64,
linear_term::Float64,
lb::Float64,
ub::Float64,
)
fp_lb = 2 * quad_term * lb + linear_term
fp_ub = 2 * quad_term * ub + linear_term

if fp_lb < 0 || fp_ub < 0
@warn "Cost function for component $name is not monotonically increasing in the range [$lb, $ub]. \
This can lead to unexpected results"
end
return
end

@doc raw"""
Adds to the cost function cost terms for sum of variables with common factor to be used for cost expression for optimization_container model.
Expand Down Expand Up @@ -149,7 +181,7 @@ function _add_variable_cost_to_objective!(
}
throw(
IS.ConflictingInputsError(
"Quadratic Cost Curves are not allowed for Compact formulations",
"Quadratic Cost Curves are not compatible with Compact formulations",
),
)
return
Expand Down

0 comments on commit f617917

Please sign in to comment.