From 2564473668823a2ceb0e714ebd10c60b41cd0642 Mon Sep 17 00:00:00 2001 From: Aleksandr Kazachkov Date: Fri, 23 Jul 2021 20:07:48 -0400 Subject: [PATCH] Fix failing tests due to use of non-binary value and improper invocation of variable --- src/model/formulations/ArrCon2000/ramp.jl | 6 +++-- src/model/formulations/base/unit.jl | 33 ++++++++++++----------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/model/formulations/ArrCon2000/ramp.jl b/src/model/formulations/ArrCon2000/ramp.jl index 9afc7b7..b725892 100644 --- a/src/model/formulations/ArrCon2000/ramp.jl +++ b/src/model/formulations/ArrCon2000/ramp.jl @@ -40,10 +40,12 @@ function _add_ramp_eqs!( switch_off = model[:switch_off] switch_on = model[:switch_on] + is_initially_on = _is_initially_on(g) > 0 + for t in 1:model[:instance].time # Ramp up limit if t == 1 - if _is_initially_on(g) + if is_initially_on # min power is _not_ multiplied by is_on because if !is_on, then ramp up is irrelevant eq_ramp_up[gn, t] = @constraint( model, @@ -74,7 +76,7 @@ function _add_ramp_eqs!( # Ramp down limit if t == 1 - if _is_initially_on(g) + if is_initially_on # TODO If RD < SD, or more specifically if # min_power + RD < initial_power < SD # then the generator should be able to shut down at time t = 1, diff --git a/src/model/formulations/base/unit.jl b/src/model/formulations/base/unit.jl index 4d8254b..eaf7326 100644 --- a/src/model/formulations/base/unit.jl +++ b/src/model/formulations/base/unit.jl @@ -45,7 +45,7 @@ function _add_unit!(model::JuMP.Model, g::Unit, formulation::Formulation) ) _add_startup_cost_eqs!(model, g, formulation.startup_costs) _add_shutdown_cost_eqs!(model, g) - _add_startup_shutdown_limit_eqs!(model, g) + _add_startup_shutdown_limit_eqs!(model, g, formulation.status_vars, formulation.prod_vars) _add_status_eqs!(model, g, formulation.status_vars) return end @@ -105,27 +105,28 @@ end """ _add_startup_shutdown_limit_eqs!(model::JuMP.Model, g::Unit)::Nothing -Variables ---- -* :is_on -* :prod_above -* :reserve -* :switch_on -* :switch_off +Creates startup/shutdown limit constraints below based on variables `Gar1962.StatusVars`, `prod_above` from `Gar1962.ProdVars`, and `reserve`. Constraints --- * :eq_startup_limit * :eq_shutdown_limit """ -function _add_startup_shutdown_limit_eqs!(model::JuMP.Model, g::Unit)::Nothing +function _add_startup_shutdown_limit_eqs!( + model::JuMP.Model, + g::Unit, + formulation_status_vars::Gar1962.StatusVars, + formulation_prod_vars::Gar1962.ProdVars +)::Nothing eq_shutdown_limit = _init(model, :eq_shutdown_limit) eq_startup_limit = _init(model, :eq_startup_limit) + is_on = model[:is_on] - prod_above = model[:prod_above] - reserve = model[:reserve] switch_off = model[:switch_off] switch_on = model[:switch_on] + prod_above = model[:prod_above] + reserve = model[:reserve] + T = model[:instance].time for t in 1:T # Startup limit @@ -140,10 +141,11 @@ function _add_startup_shutdown_limit_eqs!(model::JuMP.Model, g::Unit)::Nothing # TODO check what happens with these variables when exporting the model # Generator producing too much to be turned off in the first time period # (can a binary variable have bounds x = 0?) - #eqs.shutdown_limit[gi, 0] = @constraint(mip, vars.switch_off[gi, 1] <= 0) - fix(model.vars.switch_off[gi, 1], 0.0; force = true) - #eq_shutdown_limit[g.name, 0] = - #@constraint(model, switch_off[g.name, 1] <= 0) + if formulation_status_vars.fix_vars_via_constraint + eq_shutdown_limit[g.name, 0] = @constraint(model, model[:switch_off][g.name, 1] <= 0.0) + else + fix(model[:switch_off][g.name, 1], 0.0; force = true) + end end if t < T eq_shutdown_limit[g.name, t] = @constraint( @@ -243,7 +245,6 @@ Variables * `switch_off` * `switch_on` - Constraints --- * `eq_min_uptime`