mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-06 08:18:51 -06:00
Compare commits
5 Commits
feature/fi
...
feature/st
| Author | SHA1 | Date | |
|---|---|---|---|
| d751c2af88 | |||
| 1397ae438e | |||
| 7308ff6477 | |||
|
|
8b6cbe8c1b | ||
|
|
c2557a64d1 |
@@ -2,12 +2,6 @@
|
||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
"""
|
||||
_add_status_vars!
|
||||
|
||||
Adds symbols identified by `Gar1962.StatusVars` to `model`.
|
||||
Fix variables if a certain generator _must_ run or based on initial conditions.
|
||||
"""
|
||||
function _add_status_vars!(
|
||||
model::JuMP.Model,
|
||||
g::Unit,
|
||||
@@ -16,93 +10,15 @@ function _add_status_vars!(
|
||||
is_on = _init(model, :is_on)
|
||||
switch_on = _init(model, :switch_on)
|
||||
switch_off = _init(model, :switch_off)
|
||||
FIX_VARS = !formulation_status_vars.fix_vars_via_constraint
|
||||
is_initially_on = _is_initially_on(g) > 0
|
||||
for t in 1:model[:instance].time
|
||||
if g.must_run[t]
|
||||
is_on[g.name, t] = 1.0
|
||||
switch_on[g.name, t] = (t == 1 ? 1.0 - _is_initially_on(g) : 0.0)
|
||||
switch_off[g.name, t] = 0.0
|
||||
else
|
||||
is_on[g.name, t] = @variable(model, binary = true)
|
||||
switch_on[g.name, t] = @variable(model, binary = true)
|
||||
switch_off[g.name, t] = @variable(model, binary = true)
|
||||
|
||||
# Use initial conditions and whether a unit must run to fix variables
|
||||
if FIX_VARS
|
||||
# Fix variables using fix function
|
||||
if g.must_run[t]
|
||||
# If the generator _must_ run, then it is obviously on and cannot be switched off
|
||||
# In the first time period, force unit to switch on if was off before
|
||||
# Otherwise, unit is on, and will never turn off, so will never need to turn on
|
||||
fix(is_on[g.name, t], 1.0; force = true)
|
||||
fix(
|
||||
switch_on[g.name, t],
|
||||
(t == 1 ? 1.0 - _is_initially_on(g) : 0.0);
|
||||
force = true,
|
||||
)
|
||||
fix(switch_off[g.name, t], 0.0; force = true)
|
||||
elseif t == 1
|
||||
if is_initially_on
|
||||
# Generator was on (for g.initial_status time periods),
|
||||
# so cannot be more switched on until the period after the first time it can be turned off
|
||||
fix(switch_on[g.name, 1], 0.0; force = true)
|
||||
else
|
||||
# Generator is initially off (for -g.initial_status time periods)
|
||||
# Cannot be switched off more
|
||||
fix(switch_off[g.name, 1], 0.0; force = true)
|
||||
end
|
||||
end
|
||||
else
|
||||
# Add explicit constraint if !FIX_VARS
|
||||
if g.must_run[t]
|
||||
is_on[g.name, t] = 1.0
|
||||
switch_on[g.name, t] =
|
||||
(t == 1 ? 1.0 - _is_initially_on(g) : 0.0)
|
||||
switch_off[g.name, t] = 0.0
|
||||
elseif t == 1
|
||||
if is_initially_on
|
||||
switch_on[g.name, t] = 0.0
|
||||
else
|
||||
switch_off[g.name, t] = 0.0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Use initial conditions and whether a unit must run to fix variables
|
||||
if FIX_VARS
|
||||
# Fix variables using fix function
|
||||
if g.must_run[t]
|
||||
# If the generator _must_ run, then it is obviously on and cannot be switched off
|
||||
# In the first time period, force unit to switch on if was off before
|
||||
# Otherwise, unit is on, and will never turn off, so will never need to turn on
|
||||
fix(is_on[g.name, t], 1.0; force = true)
|
||||
fix(
|
||||
switch_on[g.name, t],
|
||||
(t == 1 ? 1.0 - _is_initially_on(g) : 0.0);
|
||||
force = true,
|
||||
)
|
||||
fix(switch_off[g.name, t], 0.0; force = true)
|
||||
elseif t == 1
|
||||
if is_initially_on
|
||||
# Generator was on (for g.initial_status time periods),
|
||||
# so cannot be more switched on until the period after the first time it can be turned off
|
||||
fix(switch_on[g.name, 1], 0.0; force = true)
|
||||
else
|
||||
# Generator is initially off (for -g.initial_status time periods)
|
||||
# Cannot be switched off more
|
||||
fix(switch_off[g.name, 1], 0.0; force = true)
|
||||
end
|
||||
end
|
||||
else
|
||||
# Add explicit constraint if !FIX_VARS
|
||||
if g.must_run[t]
|
||||
is_on[g.name, t] = 1.0
|
||||
switch_on[g.name, t] =
|
||||
(t == 1 ? 1.0 - _is_initially_on(g) : 0.0)
|
||||
switch_off[g.name, t] = 0.0
|
||||
elseif t == 1
|
||||
if is_initially_on
|
||||
switch_on[g.name, t] = 0.0
|
||||
else
|
||||
switch_off[g.name, t] = 0.0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return
|
||||
|
||||
@@ -17,53 +17,8 @@ import ..PiecewiseLinearCostsFormulation
|
||||
import ..ProductionVarsFormulation
|
||||
import ..StatusVarsFormulation
|
||||
|
||||
"""
|
||||
Variables
|
||||
---
|
||||
* `prod_above`:
|
||||
[gen, t];
|
||||
*production above minimum required level*;
|
||||
lb: 0, ub: Inf.
|
||||
KnuOstWat2020: `p'_g(t)`
|
||||
* `segprod`:
|
||||
[gen, segment, t];
|
||||
*how much generator produces on cost segment in time t*;
|
||||
lb: 0, ub: Inf.
|
||||
KnuOstWat2020: `p_g^l(t)`
|
||||
"""
|
||||
struct ProdVars <: ProductionVarsFormulation end
|
||||
|
||||
struct PwlCosts <: PiecewiseLinearCostsFormulation end
|
||||
|
||||
"""
|
||||
Variables
|
||||
---
|
||||
* `is_on`:
|
||||
[gen, t];
|
||||
*is generator on at time t?*
|
||||
lb: 0, ub: 1, binary.
|
||||
KnuOstWat2020: `u_g(t)`
|
||||
* `switch_on`:
|
||||
[gen, t];
|
||||
*indicator that generator will be turned on at t*;
|
||||
lb: 0, ub: 1, binary.
|
||||
KnuOstWat2020: `v_g(t)`
|
||||
* `switch_off`: binary;
|
||||
[gen, t];
|
||||
*indicator that generator will be turned off at t*;
|
||||
lb: 0, ub: 1, binary.
|
||||
KnuOstWat2020: `w_g(t)`
|
||||
|
||||
Arguments
|
||||
---
|
||||
* `fix_vars_via_constraint`:
|
||||
indicator for whether to set vars to a constant using `fix` or by adding an explicit constraint
|
||||
(particulary useful for debugging purposes).
|
||||
"""
|
||||
struct StatusVars <: StatusVarsFormulation
|
||||
fix_vars_via_constraint::Bool
|
||||
|
||||
StatusVars() = new(false)
|
||||
end
|
||||
struct StatusVars <: StatusVarsFormulation end
|
||||
|
||||
end
|
||||
|
||||
96
src/model/formulations/GenMorRam2017/startstop.jl
Normal file
96
src/model/formulations/GenMorRam2017/startstop.jl
Normal file
@@ -0,0 +1,96 @@
|
||||
# UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
"""
|
||||
_add_startup_shutdown_limit_eqs!(model::JuMP.Model, g::Unit)::Nothing
|
||||
|
||||
Startup and shutdown limits from Gentile et al. (2017).
|
||||
Eqns. (20), (23a), and (23b) in Knueven et al. (2020).
|
||||
|
||||
Creates constraints `eq_startstop_limit`, `eq_startup_limit`, and `eq_shutdown_limit`
|
||||
using variables `Gar1962.StatusVars`, `prod_above` from `Gar1962.ProdVars`, and `reserve`.
|
||||
|
||||
Constraints
|
||||
---
|
||||
* `eq_startstop_limit`
|
||||
* `eq_startup_limit`
|
||||
* `eq_shutdown_limit`
|
||||
"""
|
||||
function _add_startup_shutdown_limit_eqs!(
|
||||
model::JuMP.Model,
|
||||
g::Unit,
|
||||
formulation_prod_vars::Gar1962.ProdVars,
|
||||
formulation_status_vars::Gar1962.StatusVars,
|
||||
)::Nothing
|
||||
# TODO: Move upper case constants to model[:instance]
|
||||
RESERVES_WHEN_START_UP = true
|
||||
RESERVES_WHEN_RAMP_UP = true
|
||||
RESERVES_WHEN_RAMP_DOWN = true
|
||||
RESERVES_WHEN_SHUT_DOWN = true
|
||||
|
||||
eq_startstop_limit = _init(model, :eq_startstop_limit)
|
||||
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]
|
||||
|
||||
T = model[:instance].time
|
||||
gi = g.name
|
||||
|
||||
if g.initial_power > g.shutdown_limit
|
||||
eqs.shutdown_limit[gi, 0] =
|
||||
@constraint(mip, vars.switch_off[gi, 1] <= 0)
|
||||
end
|
||||
|
||||
for t in 1:T
|
||||
## 2020-10-09 amk: added eqn (20) and check of g.min_uptime
|
||||
# Not present in (23) in Kneueven et al.
|
||||
if g.min_uptime > 1
|
||||
# Equation (20) in Knueven et al. (2020)
|
||||
eqs.startstop_limit[gi, t] = @constraint(
|
||||
model,
|
||||
prod_above[gi, t] + reserve[gi, t] <=
|
||||
(g.max_power[t] - g.min_power[t]) * is_on[gi, t] -
|
||||
max(0, g.max_power[t] - g.startup_limit) * switch_on[gi, t] - (
|
||||
t < T ?
|
||||
max(0, g.max_power[t] - g.shutdown_limit) *
|
||||
switch_off[gi, t+1] : 0.0
|
||||
)
|
||||
)
|
||||
else
|
||||
## Startup limits
|
||||
# Equation (23a) in Knueven et al. (2020)
|
||||
eqs.startup_limit[gi, t] = @constraint(
|
||||
model,
|
||||
prod_above[gi, t] + reserve[gi, t] <=
|
||||
(g.max_power[t] - g.min_power[t]) * is_on[gi, t] -
|
||||
max(0, g.max_power[t] - g.startup_limit) * switch_on[gi, t] - (
|
||||
t < T ?
|
||||
max(0, g.startup_limit - g.shutdown_limit) *
|
||||
switch_off[gi, t+1] : 0.0
|
||||
)
|
||||
)
|
||||
|
||||
## Shutdown limits
|
||||
if t < T
|
||||
# Equation (23b) in Knueven et al. (2020)
|
||||
eqs.shutdown_limit[gi, t] = @constraint(
|
||||
model,
|
||||
prod_above[gi, t] + reserve[gi, t] <=
|
||||
(g.max_power[t] - g.min_power[t]) * xis_on[gi, t] - (
|
||||
t < T ?
|
||||
max(0, g.max_power[t] - g.shutdown_limit) *
|
||||
switch_off[gi, t+1] : 0.0
|
||||
) -
|
||||
max(0, g.shutdown_limit - g.startup_limit) *
|
||||
switch_on[gi, t]
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
89
src/model/formulations/MorLatRam2013/startstop.jl
Normal file
89
src/model/formulations/MorLatRam2013/startstop.jl
Normal file
@@ -0,0 +1,89 @@
|
||||
# UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
"""
|
||||
_add_startup_shutdown_limit_eqs!(model::JuMP.Model, g::Unit)::Nothing
|
||||
|
||||
Startup and shutdown limits from Morales-España et al. (2013a).
|
||||
Eqns. (20), (21a), and (21b) in Knueven et al. (2020).
|
||||
|
||||
Uses variable `prod_above` from `Gar1962.ProdVars`, the variables in `Gar1962.StatusVars`, and `reserve`
|
||||
to generate constraints below.
|
||||
|
||||
Constraints
|
||||
---
|
||||
* :eq_startstop_limit
|
||||
* :eq_startup_limit
|
||||
* :eq_shutdown_limit
|
||||
"""
|
||||
function _add_startup_shutdown_limit_eqs!(
|
||||
model::JuMP.Model,
|
||||
g::Unit,
|
||||
formulation_prod_vars::Gar1962.ProdVars,
|
||||
formulation_status_vars::Gar1962.StatusVars,
|
||||
)::Nothing
|
||||
# TODO: Move upper case constants to model[:instance]
|
||||
RESERVES_WHEN_START_UP = true
|
||||
RESERVES_WHEN_RAMP_UP = true
|
||||
RESERVES_WHEN_RAMP_DOWN = true
|
||||
RESERVES_WHEN_SHUT_DOWN = true
|
||||
|
||||
eq_startstop_limit = _init(model, :eq_startstop_limit)
|
||||
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]
|
||||
|
||||
T = model[:instance].time
|
||||
gi = g.name
|
||||
for t in 1:T
|
||||
## 2020-10-09 amk: added eqn (20) and check of g.min_uptime
|
||||
if g.min_uptime > 1 && t < T
|
||||
# Equation (20) in Knueven et al. (2020)
|
||||
# UT > 1 required, to guarantee that vars.switch_on[gi, t] and vars.switch_off[gi, t+1] are not both = 1 at the same time
|
||||
eq_startstop_limit[gi, t] = @constraint(
|
||||
model,
|
||||
prod_above[gi, t] + reserve[gi, t] <=
|
||||
(g.max_power[t] - g.min_power[t]) * is_on[gi, t] -
|
||||
max(0, g.max_power[t] - g.startup_limit) * switch_on[gi, t] -
|
||||
max(0, g.max_power[t] - g.shutdown_limit) * switch_off[gi, t+1]
|
||||
)
|
||||
else
|
||||
## Startup limits
|
||||
# Equation (21a) in Knueven et al. (2020)
|
||||
# Proposed by Morales-España et al. (2013a)
|
||||
eqs_startup_limit[gi, t] = @constraint(
|
||||
model,
|
||||
prod_above[gi, t] + reserve[gi, t] <=
|
||||
(g.max_power[t] - g.min_power[t]) * is_on[gi, t] -
|
||||
max(0, g.max_power[t] - g.startup_limit) * switch_on[gi, t]
|
||||
)
|
||||
|
||||
## Shutdown limits
|
||||
if t < T
|
||||
# Equation (21b) in Knueven et al. (2020)
|
||||
# TODO different from what was in previous model, due to reserve variable
|
||||
# ax: ideally should have reserve_up and reserve_down variables
|
||||
# i.e., the generator should be able to increase/decrease production as specified
|
||||
# (this is a heuristic for a "robust" solution,
|
||||
# in case there is an outage or a surge, and flow has to be redirected)
|
||||
# amk: if shutdown_limit is the max prod of generator in time period before shutting down,
|
||||
# then it makes sense to count reserves, because otherwise, if reserves ≠ 0,
|
||||
# then the generator will actually produce more than the limit
|
||||
eqs.shutdown_limit[gi, t] = @constraint(
|
||||
model,
|
||||
prod_above[gi, t] +
|
||||
(RESERVES_WHEN_SHUT_DOWN ? reserve[gi, t] : 0.0) <=
|
||||
(g.max_power[t] - g.min_power[t]) * is_on[gi, t] -
|
||||
max(0, g.max_power[t] - g.shutdown_limit) *
|
||||
switch_off[gi, t+1]
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,15 +2,6 @@
|
||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
"""
|
||||
_add_unit!(model::JuMP.Model, g::Unit, formulation::Formulation)
|
||||
|
||||
Add production, reserve, startup, shutdown, and status variables,
|
||||
and constraints for min uptime/downtime, net injection, production, ramping, startup, shutdown, and status.
|
||||
|
||||
Fix variables if a certain generator _must_ run or if a generator provides spinning reserves.
|
||||
Also, add overflow penalty to objective for each transmission line.
|
||||
"""
|
||||
function _add_unit!(model::JuMP.Model, g::Unit, formulation::Formulation)
|
||||
if !all(g.must_run) && any(g.must_run)
|
||||
error("Partially must-run units are not currently supported")
|
||||
@@ -47,8 +38,8 @@ function _add_unit!(model::JuMP.Model, g::Unit, formulation::Formulation)
|
||||
_add_startup_shutdown_limit_eqs!(
|
||||
model,
|
||||
g,
|
||||
formulation.status_vars,
|
||||
formulation.prod_vars,
|
||||
formulation.status_vars,
|
||||
)
|
||||
_add_status_eqs!(model, g, formulation.status_vars)
|
||||
return
|
||||
@@ -103,8 +94,8 @@ Constraints
|
||||
function _add_startup_shutdown_limit_eqs!(
|
||||
model::JuMP.Model,
|
||||
g::Unit,
|
||||
formulation_status_vars::Gar1962.StatusVars,
|
||||
formulation_prod_vars::Gar1962.ProdVars,
|
||||
formulation_status_vars::Gar1962.StatusVars,
|
||||
)::Nothing
|
||||
eq_shutdown_limit = _init(model, :eq_shutdown_limit)
|
||||
eq_startup_limit = _init(model, :eq_startup_limit)
|
||||
@@ -124,15 +115,8 @@ function _add_startup_shutdown_limit_eqs!(
|
||||
)
|
||||
# Shutdown limit
|
||||
if g.initial_power > g.shutdown_limit
|
||||
# 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?)
|
||||
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
|
||||
@constraint(model, switch_off[g.name, 1] <= 0)
|
||||
end
|
||||
if t < T
|
||||
eq_shutdown_limit[g.name, t] = @constraint(
|
||||
|
||||
Reference in New Issue
Block a user