mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-07 00:38:51 -06:00
Compare commits
15 Commits
feature/fi
...
feature/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b429bc664 | ||
|
|
2d48c84f1a | ||
|
|
718d6af96b | ||
|
|
56c9e28495 | ||
|
|
3d252c55a3 | ||
|
|
f44d7bcfdf | ||
| c64b76d6d1 | |||
| f514ace560 | |||
|
|
97b8611fcc | ||
| 209c3a72e9 | |||
| fe3066f2b5 | |||
|
|
92221bcaa4 | ||
|
|
2cdf8874fb | ||
|
|
ea35c3ffcc | ||
|
|
7a03f4bbb0 |
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@@ -9,8 +9,8 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
julia-version: ['1.4', '1.5', '1.6']
|
julia-version: ['1.3', '1.4', '1.5', '1.6']
|
||||||
julia-arch: [x64]
|
julia-arch: [x64, x86]
|
||||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||||
exclude:
|
exclude:
|
||||||
- os: macOS-latest
|
- os: macOS-latest
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ name = "UnitCommitment"
|
|||||||
uuid = "64606440-39ea-11e9-0f29-3303a1d3d877"
|
uuid = "64606440-39ea-11e9-0f29-3303a1d3d877"
|
||||||
authors = ["Santos Xavier, Alinson <axavier@anl.gov>"]
|
authors = ["Santos Xavier, Alinson <axavier@anl.gov>"]
|
||||||
repo = "https://github.com/ANL-CEEESA/UnitCommitment.jl"
|
repo = "https://github.com/ANL-CEEESA/UnitCommitment.jl"
|
||||||
version = "0.2.2"
|
version = "0.2.3"
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
|
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
|
||||||
|
|||||||
@@ -2,12 +2,6 @@
|
|||||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
# 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!(
|
function _add_status_vars!(
|
||||||
model::JuMP.Model,
|
model::JuMP.Model,
|
||||||
g::Unit,
|
g::Unit,
|
||||||
@@ -16,93 +10,15 @@ function _add_status_vars!(
|
|||||||
is_on = _init(model, :is_on)
|
is_on = _init(model, :is_on)
|
||||||
switch_on = _init(model, :switch_on)
|
switch_on = _init(model, :switch_on)
|
||||||
switch_off = _init(model, :switch_off)
|
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
|
for t in 1:model[:instance].time
|
||||||
is_on[g.name, t] = @variable(model, binary = true)
|
if g.must_run[t]
|
||||||
switch_on[g.name, t] = @variable(model, binary = true)
|
is_on[g.name, t] = 1.0
|
||||||
switch_off[g.name, t] = @variable(model, binary = true)
|
switch_on[g.name, t] = (t == 1 ? 1.0 - _is_initially_on(g) : 0.0)
|
||||||
|
switch_off[g.name, t] = 0.0
|
||||||
# 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
|
else
|
||||||
# Add explicit constraint if !FIX_VARS
|
is_on[g.name, t] = @variable(model, binary = true)
|
||||||
if g.must_run[t]
|
switch_on[g.name, t] = @variable(model, binary = true)
|
||||||
is_on[g.name, t] = 1.0
|
switch_off[g.name, t] = @variable(model, binary = true)
|
||||||
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
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -17,53 +17,8 @@ import ..PiecewiseLinearCostsFormulation
|
|||||||
import ..ProductionVarsFormulation
|
import ..ProductionVarsFormulation
|
||||||
import ..StatusVarsFormulation
|
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 ProdVars <: ProductionVarsFormulation end
|
||||||
|
|
||||||
struct PwlCosts <: PiecewiseLinearCostsFormulation end
|
struct PwlCosts <: PiecewiseLinearCostsFormulation end
|
||||||
|
struct StatusVars <: StatusVarsFormulation 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
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,15 +2,6 @@
|
|||||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
# 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)
|
function _add_unit!(model::JuMP.Model, g::Unit, formulation::Formulation)
|
||||||
if !all(g.must_run) && any(g.must_run)
|
if !all(g.must_run) && any(g.must_run)
|
||||||
error("Partially must-run units are not currently supported")
|
error("Partially must-run units are not currently supported")
|
||||||
@@ -44,12 +35,7 @@ function _add_unit!(model::JuMP.Model, g::Unit, formulation::Formulation)
|
|||||||
formulation.status_vars,
|
formulation.status_vars,
|
||||||
)
|
)
|
||||||
_add_startup_cost_eqs!(model, g, formulation.startup_costs)
|
_add_startup_cost_eqs!(model, g, formulation.startup_costs)
|
||||||
_add_startup_shutdown_limit_eqs!(
|
_add_startup_shutdown_limit_eqs!(model, g)
|
||||||
model,
|
|
||||||
g,
|
|
||||||
formulation.status_vars,
|
|
||||||
formulation.prod_vars,
|
|
||||||
)
|
|
||||||
_add_status_eqs!(model, g, formulation.status_vars)
|
_add_status_eqs!(model, g, formulation.status_vars)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -90,22 +76,7 @@ function _add_startup_shutdown_vars!(model::JuMP.Model, g::Unit)::Nothing
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
"""
|
function _add_startup_shutdown_limit_eqs!(model::JuMP.Model, g::Unit)::Nothing
|
||||||
_add_startup_shutdown_limit_eqs!(model::JuMP.Model, g::Unit)::Nothing
|
|
||||||
|
|
||||||
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,
|
|
||||||
formulation_status_vars::Gar1962.StatusVars,
|
|
||||||
formulation_prod_vars::Gar1962.ProdVars,
|
|
||||||
)::Nothing
|
|
||||||
eq_shutdown_limit = _init(model, :eq_shutdown_limit)
|
eq_shutdown_limit = _init(model, :eq_shutdown_limit)
|
||||||
eq_startup_limit = _init(model, :eq_startup_limit)
|
eq_startup_limit = _init(model, :eq_startup_limit)
|
||||||
is_on = model[:is_on]
|
is_on = model[:is_on]
|
||||||
@@ -124,15 +95,8 @@ function _add_startup_shutdown_limit_eqs!(
|
|||||||
)
|
)
|
||||||
# Shutdown limit
|
# Shutdown limit
|
||||||
if g.initial_power > g.shutdown_limit
|
if g.initial_power > g.shutdown_limit
|
||||||
# TODO check what happens with these variables when exporting the model
|
eq_shutdown_limit[g.name, 0] =
|
||||||
# Generator producing too much to be turned off in the first time period
|
@constraint(model, switch_off[g.name, 1] <= 0)
|
||||||
# (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
|
|
||||||
end
|
end
|
||||||
if t < T
|
if t < T
|
||||||
eq_shutdown_limit[g.name, t] = @constraint(
|
eq_shutdown_limit[g.name, t] = @constraint(
|
||||||
|
|||||||
Reference in New Issue
Block a user