|
|
@ -20,30 +20,16 @@ function set_name(x::Float64, n::String)
|
|
|
|
# nop
|
|
|
|
# nop
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mutable struct UnitCommitmentModel
|
|
|
|
|
|
|
|
mip::JuMP.Model
|
|
|
|
|
|
|
|
vars::DotDict
|
|
|
|
|
|
|
|
eqs::DotDict
|
|
|
|
|
|
|
|
exprs::DotDict
|
|
|
|
|
|
|
|
instance::UnitCommitmentInstance
|
|
|
|
|
|
|
|
isf::Matrix{Float64}
|
|
|
|
|
|
|
|
lodf::Matrix{Float64}
|
|
|
|
|
|
|
|
obj::AffExpr
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function build_model(;
|
|
|
|
function build_model(;
|
|
|
|
filename::Union{String, Nothing}=nothing,
|
|
|
|
filename::Union{String, Nothing}=nothing,
|
|
|
|
instance::Union{UnitCommitmentInstance, Nothing}=nothing,
|
|
|
|
instance::Union{UnitCommitmentInstance, Nothing}=nothing,
|
|
|
|
isf::Union{Array{Float64,2}, Nothing}=nothing,
|
|
|
|
isf::Union{Matrix{Float64}, Nothing}=nothing,
|
|
|
|
lodf::Union{Array{Float64,2}, Nothing}=nothing,
|
|
|
|
lodf::Union{Matrix{Float64}, Nothing}=nothing,
|
|
|
|
isf_cutoff::Float64=0.005,
|
|
|
|
isf_cutoff::Float64=0.005,
|
|
|
|
lodf_cutoff::Float64=0.001,
|
|
|
|
lodf_cutoff::Float64=0.001,
|
|
|
|
optimizer=nothing,
|
|
|
|
optimizer=nothing,
|
|
|
|
model=nothing,
|
|
|
|
variable_names::Bool=false,
|
|
|
|
variable_names::Bool=false,
|
|
|
|
)::JuMP.Model
|
|
|
|
) :: UnitCommitmentModel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (filename === nothing) && (instance === nothing)
|
|
|
|
if (filename === nothing) && (instance === nothing)
|
|
|
|
error("Either filename or instance must be specified")
|
|
|
|
error("Either filename or instance must be specified")
|
|
|
@ -64,16 +50,20 @@ function build_model(;
|
|
|
|
if isf === nothing
|
|
|
|
if isf === nothing
|
|
|
|
@info "Computing injection shift factors..."
|
|
|
|
@info "Computing injection shift factors..."
|
|
|
|
time_isf = @elapsed begin
|
|
|
|
time_isf = @elapsed begin
|
|
|
|
isf = UnitCommitment.injection_shift_factors(lines=instance.lines,
|
|
|
|
isf = UnitCommitment.injection_shift_factors(
|
|
|
|
buses=instance.buses)
|
|
|
|
lines=instance.lines,
|
|
|
|
|
|
|
|
buses=instance.buses,
|
|
|
|
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@info @sprintf("Computed ISF in %.2f seconds", time_isf)
|
|
|
|
@info @sprintf("Computed ISF in %.2f seconds", time_isf)
|
|
|
|
|
|
|
|
|
|
|
|
@info "Computing line outage factors..."
|
|
|
|
@info "Computing line outage factors..."
|
|
|
|
time_lodf = @elapsed begin
|
|
|
|
time_lodf = @elapsed begin
|
|
|
|
lodf = UnitCommitment.line_outage_factors(lines=instance.lines,
|
|
|
|
lodf = UnitCommitment.line_outage_factors(
|
|
|
|
buses=instance.buses,
|
|
|
|
lines=instance.lines,
|
|
|
|
isf=isf)
|
|
|
|
buses=instance.buses,
|
|
|
|
|
|
|
|
isf=isf,
|
|
|
|
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@info @sprintf("Computed LODF in %.2f seconds", time_lodf)
|
|
|
|
@info @sprintf("Computed LODF in %.2f seconds", time_lodf)
|
|
|
|
|
|
|
|
|
|
|
@ -85,110 +75,139 @@ function build_model(;
|
|
|
|
|
|
|
|
|
|
|
|
@info "Building model..."
|
|
|
|
@info "Building model..."
|
|
|
|
time_model = @elapsed begin
|
|
|
|
time_model = @elapsed begin
|
|
|
|
if model === nothing
|
|
|
|
model = Model()
|
|
|
|
if optimizer === nothing
|
|
|
|
if optimizer !== nothing
|
|
|
|
mip = Model()
|
|
|
|
set_optimizer(model, optimizer)
|
|
|
|
else
|
|
|
|
|
|
|
|
mip = Model(optimizer)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
mip = model
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
model = UnitCommitmentModel(mip,
|
|
|
|
|
|
|
|
DotDict(), # vars
|
|
|
|
|
|
|
|
DotDict(), # eqs
|
|
|
|
|
|
|
|
DotDict(), # exprs
|
|
|
|
|
|
|
|
instance,
|
|
|
|
|
|
|
|
isf,
|
|
|
|
|
|
|
|
lodf,
|
|
|
|
|
|
|
|
AffExpr(), # obj
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
for field in [:prod_above, :segprod, :reserve, :is_on, :switch_on, :switch_off,
|
|
|
|
|
|
|
|
:net_injection, :curtail, :overflow, :loads, :startup]
|
|
|
|
|
|
|
|
setproperty!(model.vars, field, OrderedDict())
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for field in [:startup_choose, :startup_restrict, :segprod_limit, :prod_above_def,
|
|
|
|
model[:obj] = AffExpr()
|
|
|
|
:prod_limit, :binary_link, :switch_on_off, :ramp_up, :ramp_down,
|
|
|
|
model[:instance] = instance
|
|
|
|
:startup_limit, :shutdown_limit, :min_uptime, :min_downtime, :power_balance,
|
|
|
|
model[:isf] = isf
|
|
|
|
:net_injection_def, :min_reserve]
|
|
|
|
model[:lodf] = lodf
|
|
|
|
setproperty!(model.eqs, field, OrderedDict())
|
|
|
|
for field in [
|
|
|
|
end
|
|
|
|
:prod_above,
|
|
|
|
for field in [:inj, :reserve, :net_injection]
|
|
|
|
:segprod,
|
|
|
|
setproperty!(model.exprs, field, OrderedDict())
|
|
|
|
:reserve,
|
|
|
|
|
|
|
|
:is_on,
|
|
|
|
|
|
|
|
:switch_on,
|
|
|
|
|
|
|
|
:switch_off,
|
|
|
|
|
|
|
|
:net_injection,
|
|
|
|
|
|
|
|
:curtail,
|
|
|
|
|
|
|
|
:overflow,
|
|
|
|
|
|
|
|
:loads,
|
|
|
|
|
|
|
|
:startup,
|
|
|
|
|
|
|
|
:eq_startup_choose,
|
|
|
|
|
|
|
|
:eq_startup_restrict,
|
|
|
|
|
|
|
|
:eq_segprod_limit,
|
|
|
|
|
|
|
|
:eq_prod_above_def,
|
|
|
|
|
|
|
|
:eq_prod_limit,
|
|
|
|
|
|
|
|
:eq_binary_link,
|
|
|
|
|
|
|
|
:eq_switch_on_off,
|
|
|
|
|
|
|
|
:eq_ramp_up,
|
|
|
|
|
|
|
|
:eq_ramp_down,
|
|
|
|
|
|
|
|
:eq_startup_limit,
|
|
|
|
|
|
|
|
:eq_shutdown_limit,
|
|
|
|
|
|
|
|
:eq_min_uptime,
|
|
|
|
|
|
|
|
:eq_min_downtime,
|
|
|
|
|
|
|
|
:eq_power_balance,
|
|
|
|
|
|
|
|
:eq_net_injection_def,
|
|
|
|
|
|
|
|
:eq_min_reserve,
|
|
|
|
|
|
|
|
:expr_inj,
|
|
|
|
|
|
|
|
:expr_reserve,
|
|
|
|
|
|
|
|
:expr_net_injection,
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
model[field] = OrderedDict()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for lm in instance.lines
|
|
|
|
for lm in instance.lines
|
|
|
|
add_transmission_line!(model, lm)
|
|
|
|
_add_transmission_line!(model, lm)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for b in instance.buses
|
|
|
|
for b in instance.buses
|
|
|
|
add_bus!(model, b)
|
|
|
|
_add_bus!(model, b)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for g in instance.units
|
|
|
|
for g in instance.units
|
|
|
|
add_unit!(model, g)
|
|
|
|
_add_unit!(model, g)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for ps in instance.price_sensitive_loads
|
|
|
|
for ps in instance.price_sensitive_loads
|
|
|
|
add_price_sensitive_load!(model, ps)
|
|
|
|
_add_price_sensitive_load!(model, ps)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
build_net_injection_eqs!(model)
|
|
|
|
_build_net_injection_eqs!(model)
|
|
|
|
build_reserve_eqs!(model)
|
|
|
|
_build_reserve_eqs!(model)
|
|
|
|
build_obj_function!(model)
|
|
|
|
_build_obj_function!(model)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@info @sprintf("Built model in %.2f seconds", time_model)
|
|
|
|
@info @sprintf("Built model in %.2f seconds", time_model)
|
|
|
|
|
|
|
|
|
|
|
|
if variable_names
|
|
|
|
if variable_names
|
|
|
|
set_variable_names!(model)
|
|
|
|
_set_names!(model)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return model
|
|
|
|
return model
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function add_transmission_line!(model, lm)
|
|
|
|
function _add_transmission_line!(model, lm)
|
|
|
|
vars, obj, T = model.vars, model.obj, model.instance.time
|
|
|
|
obj, T = model[:obj], model[:instance].time
|
|
|
|
|
|
|
|
overflow = model[:overflow]
|
|
|
|
for t in 1:T
|
|
|
|
for t in 1:T
|
|
|
|
overflow = vars.overflow[lm.name, t] = @variable(model.mip, lower_bound=0)
|
|
|
|
v = overflow[lm.name, t] = @variable(model, lower_bound=0)
|
|
|
|
add_to_expression!(obj, overflow, lm.flow_limit_penalty[t])
|
|
|
|
add_to_expression!(obj, v, lm.flow_limit_penalty[t])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function add_bus!(model::UnitCommitmentModel, b::Bus)
|
|
|
|
function _add_bus!(model::JuMP.Model, b::Bus)
|
|
|
|
mip, vars, exprs = model.mip, model.vars, model.exprs
|
|
|
|
mip = model
|
|
|
|
for t in 1:model.instance.time
|
|
|
|
net_injection = model[:expr_net_injection]
|
|
|
|
|
|
|
|
reserve = model[:expr_reserve]
|
|
|
|
|
|
|
|
curtail = model[:curtail]
|
|
|
|
|
|
|
|
for t in 1:model[:instance].time
|
|
|
|
# Fixed load
|
|
|
|
# Fixed load
|
|
|
|
exprs.net_injection[b.name, t] = AffExpr(-b.load[t])
|
|
|
|
net_injection[b.name, t] = AffExpr(-b.load[t])
|
|
|
|
|
|
|
|
|
|
|
|
# Reserves
|
|
|
|
# Reserves
|
|
|
|
exprs.reserve[b.name, t] = AffExpr()
|
|
|
|
reserve[b.name, t] = AffExpr()
|
|
|
|
|
|
|
|
|
|
|
|
# Load curtailment
|
|
|
|
# Load curtailment
|
|
|
|
vars.curtail[b.name, t] = @variable(mip, lower_bound=0, upper_bound=b.load[t])
|
|
|
|
curtail[b.name, t] = @variable(mip, lower_bound=0, upper_bound=b.load[t])
|
|
|
|
add_to_expression!(exprs.net_injection[b.name, t], vars.curtail[b.name, t], 1.0)
|
|
|
|
add_to_expression!(net_injection[b.name, t], curtail[b.name, t], 1.0)
|
|
|
|
add_to_expression!(model.obj,
|
|
|
|
add_to_expression!(
|
|
|
|
vars.curtail[b.name, t],
|
|
|
|
model[:obj],
|
|
|
|
model.instance.power_balance_penalty[t])
|
|
|
|
curtail[b.name, t],
|
|
|
|
|
|
|
|
model[:instance].power_balance_penalty[t],
|
|
|
|
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function add_price_sensitive_load!(model::UnitCommitmentModel, ps::PriceSensitiveLoad)
|
|
|
|
function _add_price_sensitive_load!(model::JuMP.Model, ps::PriceSensitiveLoad)
|
|
|
|
mip, vars = model.mip, model.vars
|
|
|
|
mip = model
|
|
|
|
for t in 1:model.instance.time
|
|
|
|
loads = model[:loads]
|
|
|
|
|
|
|
|
net_injection = model[:expr_net_injection]
|
|
|
|
|
|
|
|
for t in 1:model[:instance].time
|
|
|
|
# Decision variable
|
|
|
|
# Decision variable
|
|
|
|
vars.loads[ps.name, t] = @variable(mip, lower_bound=0, upper_bound=ps.demand[t])
|
|
|
|
loads[ps.name, t] = @variable(mip, lower_bound=0, upper_bound=ps.demand[t])
|
|
|
|
|
|
|
|
|
|
|
|
# Objective function terms
|
|
|
|
# Objective function terms
|
|
|
|
add_to_expression!(model.obj, vars.loads[ps.name, t], -ps.revenue[t])
|
|
|
|
add_to_expression!(model[:obj], loads[ps.name, t], -ps.revenue[t])
|
|
|
|
|
|
|
|
|
|
|
|
# Net injection
|
|
|
|
# Net injection
|
|
|
|
add_to_expression!(model.exprs.net_injection[ps.bus.name, t], vars.loads[ps.name, t], -1.0)
|
|
|
|
add_to_expression!(net_injection[ps.bus.name, t], loads[ps.name, t], -1.0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function add_unit!(model::UnitCommitmentModel, g::Unit)
|
|
|
|
function _add_unit!(model::JuMP.Model, g::Unit)
|
|
|
|
mip, vars, eqs, exprs, T = model.mip, model.vars, model.eqs, model.exprs, model.instance.time
|
|
|
|
mip, T = model, model[:instance].time
|
|
|
|
gi, K, S = g.name, length(g.cost_segments), length(g.startup_categories)
|
|
|
|
gi, K, S = g.name, length(g.cost_segments), length(g.startup_categories)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
segprod = model[:segprod]
|
|
|
|
|
|
|
|
prod_above = model[:prod_above]
|
|
|
|
|
|
|
|
reserve = model[:reserve]
|
|
|
|
|
|
|
|
startup = model[:startup]
|
|
|
|
|
|
|
|
is_on = model[:is_on]
|
|
|
|
|
|
|
|
switch_on = model[:switch_on]
|
|
|
|
|
|
|
|
switch_off = model[:switch_off]
|
|
|
|
|
|
|
|
expr_net_injection = model[:expr_net_injection]
|
|
|
|
|
|
|
|
expr_reserve = model[:expr_reserve]
|
|
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -202,25 +221,25 @@ function add_unit!(model::UnitCommitmentModel, g::Unit)
|
|
|
|
# Decision variables
|
|
|
|
# Decision variables
|
|
|
|
for t in 1:T
|
|
|
|
for t in 1:T
|
|
|
|
for k in 1:K
|
|
|
|
for k in 1:K
|
|
|
|
model.vars.segprod[gi, t, k] = @variable(model.mip, lower_bound=0)
|
|
|
|
segprod[gi, t, k] = @variable(model, lower_bound=0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
model.vars.prod_above[gi, t] = @variable(model.mip, lower_bound=0)
|
|
|
|
prod_above[gi, t] = @variable(model, lower_bound=0)
|
|
|
|
if g.provides_spinning_reserves[t]
|
|
|
|
if g.provides_spinning_reserves[t]
|
|
|
|
model.vars.reserve[gi, t] = @variable(model.mip, lower_bound=0)
|
|
|
|
reserve[gi, t] = @variable(model, lower_bound=0)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
model.vars.reserve[gi, t] = 0.0
|
|
|
|
reserve[gi, t] = 0.0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for s in 1:S
|
|
|
|
for s in 1:S
|
|
|
|
model.vars.startup[gi, t, s] = @variable(model.mip, binary=true)
|
|
|
|
startup[gi, t, s] = @variable(model, binary=true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if g.must_run[t]
|
|
|
|
if g.must_run[t]
|
|
|
|
model.vars.is_on[gi, t] = 1.0
|
|
|
|
is_on[gi, t] = 1.0
|
|
|
|
model.vars.switch_on[gi, t] = (t == 1 ? 1.0 - is_initially_on : 0.0)
|
|
|
|
switch_on[gi, t] = (t == 1 ? 1.0 - is_initially_on : 0.0)
|
|
|
|
model.vars.switch_off[gi, t] = 0.0
|
|
|
|
switch_off[gi, t] = 0.0
|
|
|
|
else
|
|
|
|
else
|
|
|
|
model.vars.is_on[gi, t] = @variable(model.mip, binary=true)
|
|
|
|
is_on[gi, t] = @variable(model, binary=true)
|
|
|
|
model.vars.switch_on[gi, t] = @variable(model.mip, binary=true)
|
|
|
|
switch_on[gi, t] = @variable(model, binary=true)
|
|
|
|
model.vars.switch_off[gi, t] = @variable(model.mip, binary=true)
|
|
|
|
switch_off[gi, t] = @variable(model, binary=true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -228,224 +247,244 @@ function add_unit!(model::UnitCommitmentModel, g::Unit)
|
|
|
|
# Time-dependent start-up costs
|
|
|
|
# Time-dependent start-up costs
|
|
|
|
for s in 1:S
|
|
|
|
for s in 1:S
|
|
|
|
# If unit is switching on, we must choose a startup category
|
|
|
|
# If unit is switching on, we must choose a startup category
|
|
|
|
eqs.startup_choose[gi, t, s] =
|
|
|
|
model[:eq_startup_choose][gi, t, s] =
|
|
|
|
@constraint(mip, vars.switch_on[gi, t] == sum(vars.startup[gi, t, s] for s in 1:S))
|
|
|
|
@constraint(mip, switch_on[gi, t] == sum(startup[gi, t, s] for s in 1:S))
|
|
|
|
|
|
|
|
|
|
|
|
# If unit has not switched off in the last `delay` time periods, startup category is forbidden.
|
|
|
|
# If unit has not switched off in the last `delay` time periods, startup category is forbidden.
|
|
|
|
# The last startup category is always allowed.
|
|
|
|
# The last startup category is always allowed.
|
|
|
|
if s < S
|
|
|
|
if s < S
|
|
|
|
range = (t - g.startup_categories[s + 1].delay + 1):(t - g.startup_categories[s].delay)
|
|
|
|
range = (t - g.startup_categories[s + 1].delay + 1):(t - g.startup_categories[s].delay)
|
|
|
|
initial_sum = (g.initial_status < 0 && (g.initial_status + 1 in range) ? 1.0 : 0.0)
|
|
|
|
initial_sum = (g.initial_status < 0 && (g.initial_status + 1 in range) ? 1.0 : 0.0)
|
|
|
|
eqs.startup_restrict[gi, t, s] =
|
|
|
|
model[:eq_startup_restrict][gi, t, s] =
|
|
|
|
@constraint(mip, vars.startup[gi, t, s]
|
|
|
|
@constraint(mip, startup[gi, t, s]
|
|
|
|
<= initial_sum + sum(vars.switch_off[gi, i] for i in range if i >= 1))
|
|
|
|
<= initial_sum + sum(switch_off[gi, i] for i in range if i >= 1))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Objective function terms for start-up costs
|
|
|
|
# Objective function terms for start-up costs
|
|
|
|
add_to_expression!(model.obj,
|
|
|
|
add_to_expression!(
|
|
|
|
vars.startup[gi, t, s],
|
|
|
|
model[:obj],
|
|
|
|
g.startup_categories[s].cost)
|
|
|
|
startup[gi, t, s],
|
|
|
|
|
|
|
|
g.startup_categories[s].cost,
|
|
|
|
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Objective function terms for production costs
|
|
|
|
# Objective function terms for production costs
|
|
|
|
add_to_expression!(model.obj, vars.is_on[gi, t], g.min_power_cost[t])
|
|
|
|
add_to_expression!(model[:obj], is_on[gi, t], g.min_power_cost[t])
|
|
|
|
for k in 1:K
|
|
|
|
for k in 1:K
|
|
|
|
add_to_expression!(model.obj, vars.segprod[gi, t, k], g.cost_segments[k].cost[t])
|
|
|
|
add_to_expression!(model[:obj], segprod[gi, t, k], g.cost_segments[k].cost[t])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Production limits (piecewise-linear segments)
|
|
|
|
# Production limits (piecewise-linear segments)
|
|
|
|
for k in 1:K
|
|
|
|
for k in 1:K
|
|
|
|
eqs.segprod_limit[gi, t, k] =
|
|
|
|
model[:eq_segprod_limit][gi, t, k] =
|
|
|
|
@constraint(mip, vars.segprod[gi, t, k] <= g.cost_segments[k].mw[t] * vars.is_on[gi, t])
|
|
|
|
@constraint(mip, segprod[gi, t, k] <= g.cost_segments[k].mw[t] * is_on[gi, t])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Definition of production
|
|
|
|
# Definition of production
|
|
|
|
eqs.prod_above_def[gi, t] =
|
|
|
|
model[:eq_prod_above_def][gi, t] =
|
|
|
|
@constraint(mip, vars.prod_above[gi, t] == sum(vars.segprod[gi, t, k] for k in 1:K))
|
|
|
|
@constraint(mip, prod_above[gi, t] == sum(segprod[gi, t, k] for k in 1:K))
|
|
|
|
|
|
|
|
|
|
|
|
# Production limit
|
|
|
|
# Production limit
|
|
|
|
eqs.prod_limit[gi, t] =
|
|
|
|
model[:eq_prod_limit][gi, t] =
|
|
|
|
@constraint(mip,
|
|
|
|
@constraint(mip,
|
|
|
|
vars.prod_above[gi, t] + vars.reserve[gi, t]
|
|
|
|
prod_above[gi, t] + reserve[gi, t]
|
|
|
|
<= (g.max_power[t] - g.min_power[t]) * vars.is_on[gi, t])
|
|
|
|
<= (g.max_power[t] - g.min_power[t]) * is_on[gi, t])
|
|
|
|
|
|
|
|
|
|
|
|
# Binary variable equations for economic units
|
|
|
|
# Binary variable equations for economic units
|
|
|
|
if !g.must_run[t]
|
|
|
|
if !g.must_run[t]
|
|
|
|
|
|
|
|
|
|
|
|
# Link binary variables
|
|
|
|
# Link binary variables
|
|
|
|
if t == 1
|
|
|
|
if t == 1
|
|
|
|
eqs.binary_link[gi, t] =
|
|
|
|
model[:eq_binary_link][gi, t] =
|
|
|
|
@constraint(mip,
|
|
|
|
@constraint(mip,
|
|
|
|
vars.is_on[gi, t] - is_initially_on ==
|
|
|
|
is_on[gi, t] - is_initially_on ==
|
|
|
|
vars.switch_on[gi, t] - vars.switch_off[gi, t])
|
|
|
|
switch_on[gi, t] - switch_off[gi, t])
|
|
|
|
else
|
|
|
|
else
|
|
|
|
eqs.binary_link[gi, t] =
|
|
|
|
model[:eq_binary_link][gi, t] =
|
|
|
|
@constraint(mip,
|
|
|
|
@constraint(mip,
|
|
|
|
vars.is_on[gi, t] - vars.is_on[gi, t-1] ==
|
|
|
|
is_on[gi, t] - is_on[gi, t-1] ==
|
|
|
|
vars.switch_on[gi, t] - vars.switch_off[gi, t])
|
|
|
|
switch_on[gi, t] - switch_off[gi, t])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Cannot switch on and off at the same time
|
|
|
|
# Cannot switch on and off at the same time
|
|
|
|
eqs.switch_on_off[gi, t] =
|
|
|
|
model[:eq_switch_on_off][gi, t] =
|
|
|
|
@constraint(mip, vars.switch_on[gi, t] + vars.switch_off[gi, t] <= 1)
|
|
|
|
@constraint(mip, switch_on[gi, t] + switch_off[gi, t] <= 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Ramp up limit
|
|
|
|
# Ramp up limit
|
|
|
|
if t == 1
|
|
|
|
if t == 1
|
|
|
|
if is_initially_on == 1
|
|
|
|
if is_initially_on == 1
|
|
|
|
eqs.ramp_up[gi, t] =
|
|
|
|
model[:eq_ramp_up][gi, t] =
|
|
|
|
@constraint(mip,
|
|
|
|
@constraint(mip,
|
|
|
|
vars.prod_above[gi, t] + vars.reserve[gi, t] <=
|
|
|
|
prod_above[gi, t] + reserve[gi, t] <=
|
|
|
|
(g.initial_power - g.min_power[t]) + g.ramp_up_limit)
|
|
|
|
(g.initial_power - g.min_power[t]) + g.ramp_up_limit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
else
|
|
|
|
eqs.ramp_up[gi, t] =
|
|
|
|
model[:eq_ramp_up][gi, t] =
|
|
|
|
@constraint(mip,
|
|
|
|
@constraint(mip,
|
|
|
|
vars.prod_above[gi, t] + vars.reserve[gi, t] <=
|
|
|
|
prod_above[gi, t] + reserve[gi, t] <=
|
|
|
|
vars.prod_above[gi, t-1] + g.ramp_up_limit)
|
|
|
|
prod_above[gi, t-1] + g.ramp_up_limit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Ramp down limit
|
|
|
|
# Ramp down limit
|
|
|
|
if t == 1
|
|
|
|
if t == 1
|
|
|
|
if is_initially_on == 1
|
|
|
|
if is_initially_on == 1
|
|
|
|
eqs.ramp_down[gi, t] =
|
|
|
|
model[:eq_ramp_down][gi, t] =
|
|
|
|
@constraint(mip,
|
|
|
|
@constraint(mip,
|
|
|
|
vars.prod_above[gi, t] >=
|
|
|
|
prod_above[gi, t] >=
|
|
|
|
(g.initial_power - g.min_power[t]) - g.ramp_down_limit)
|
|
|
|
(g.initial_power - g.min_power[t]) - g.ramp_down_limit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
else
|
|
|
|
eqs.ramp_down[gi, t] =
|
|
|
|
model[:eq_ramp_down][gi, t] =
|
|
|
|
@constraint(mip,
|
|
|
|
@constraint(mip,
|
|
|
|
vars.prod_above[gi, t] >=
|
|
|
|
prod_above[gi, t] >=
|
|
|
|
vars.prod_above[gi, t-1] - g.ramp_down_limit)
|
|
|
|
prod_above[gi, t-1] - g.ramp_down_limit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Startup limit
|
|
|
|
# Startup limit
|
|
|
|
eqs.startup_limit[gi, t] =
|
|
|
|
model[:eq_startup_limit][gi, t] =
|
|
|
|
@constraint(mip,
|
|
|
|
@constraint(mip,
|
|
|
|
vars.prod_above[gi, t] + vars.reserve[gi, t] <=
|
|
|
|
prod_above[gi, t] + reserve[gi, t] <=
|
|
|
|
(g.max_power[t] - g.min_power[t]) * vars.is_on[gi, t]
|
|
|
|
(g.max_power[t] - g.min_power[t]) * is_on[gi, t]
|
|
|
|
- max(0, g.max_power[t] - g.startup_limit) * vars.switch_on[gi, t])
|
|
|
|
- max(0, g.max_power[t] - g.startup_limit) * switch_on[gi, t])
|
|
|
|
|
|
|
|
|
|
|
|
# Shutdown limit
|
|
|
|
# Shutdown limit
|
|
|
|
if g.initial_power > g.shutdown_limit
|
|
|
|
if g.initial_power > g.shutdown_limit
|
|
|
|
eqs.shutdown_limit[gi, 0] =
|
|
|
|
model[:eq_shutdown_limit][gi, 0] =
|
|
|
|
@constraint(mip, vars.switch_off[gi, 1] <= 0)
|
|
|
|
@constraint(mip, switch_off[gi, 1] <= 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if t < T
|
|
|
|
if t < T
|
|
|
|
eqs.shutdown_limit[gi, t] =
|
|
|
|
model[:eq_shutdown_limit][gi, t] =
|
|
|
|
@constraint(mip,
|
|
|
|
@constraint(mip,
|
|
|
|
vars.prod_above[gi, t] <=
|
|
|
|
prod_above[gi, t] <=
|
|
|
|
(g.max_power[t] - g.min_power[t]) * vars.is_on[gi, t]
|
|
|
|
(g.max_power[t] - g.min_power[t]) * is_on[gi, t]
|
|
|
|
- max(0, g.max_power[t] - g.shutdown_limit) * vars.switch_off[gi, t+1])
|
|
|
|
- max(0, g.max_power[t] - g.shutdown_limit) * switch_off[gi, t+1])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Minimum up-time
|
|
|
|
# Minimum up-time
|
|
|
|
eqs.min_uptime[gi, t] =
|
|
|
|
model[:eq_min_uptime][gi, t] =
|
|
|
|
@constraint(mip,
|
|
|
|
@constraint(mip,
|
|
|
|
sum(vars.switch_on[gi, i]
|
|
|
|
sum(switch_on[gi, i]
|
|
|
|
for i in (t - g.min_uptime + 1):t if i >= 1
|
|
|
|
for i in (t - g.min_uptime + 1):t if i >= 1
|
|
|
|
) <= vars.is_on[gi, t])
|
|
|
|
) <= is_on[gi, t])
|
|
|
|
|
|
|
|
|
|
|
|
# # Minimum down-time
|
|
|
|
# # Minimum down-time
|
|
|
|
eqs.min_downtime[gi, t] =
|
|
|
|
model[:eq_min_downtime][gi, t] =
|
|
|
|
@constraint(mip,
|
|
|
|
@constraint(mip,
|
|
|
|
sum(vars.switch_off[gi, i]
|
|
|
|
sum(switch_off[gi, i]
|
|
|
|
for i in (t - g.min_downtime + 1):t if i >= 1
|
|
|
|
for i in (t - g.min_downtime + 1):t if i >= 1
|
|
|
|
) <= 1 - vars.is_on[gi, t])
|
|
|
|
) <= 1 - is_on[gi, t])
|
|
|
|
|
|
|
|
|
|
|
|
# Minimum up/down-time for initial periods
|
|
|
|
# Minimum up/down-time for initial periods
|
|
|
|
if t == 1
|
|
|
|
if t == 1
|
|
|
|
if g.initial_status > 0
|
|
|
|
if g.initial_status > 0
|
|
|
|
eqs.min_uptime[gi, 0] =
|
|
|
|
model[:eq_min_uptime][gi, 0] =
|
|
|
|
@constraint(mip, sum(vars.switch_off[gi, i]
|
|
|
|
@constraint(mip, sum(switch_off[gi, i]
|
|
|
|
for i in 1:(g.min_uptime - g.initial_status) if i <= T) == 0)
|
|
|
|
for i in 1:(g.min_uptime - g.initial_status) if i <= T) == 0)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
eqs.min_downtime[gi, 0] =
|
|
|
|
model[:eq_min_downtime][gi, 0] =
|
|
|
|
@constraint(mip, sum(vars.switch_on[gi, i]
|
|
|
|
@constraint(mip, sum(switch_on[gi, i]
|
|
|
|
for i in 1:(g.min_downtime + g.initial_status) if i <= T) == 0)
|
|
|
|
for i in 1:(g.min_downtime + g.initial_status) if i <= T) == 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Add to net injection expression
|
|
|
|
# Add to net injection expression
|
|
|
|
add_to_expression!(exprs.net_injection[g.bus.name, t], vars.prod_above[g.name, t], 1.0)
|
|
|
|
add_to_expression!(expr_net_injection[g.bus.name, t], prod_above[g.name, t], 1.0)
|
|
|
|
add_to_expression!(exprs.net_injection[g.bus.name, t], vars.is_on[g.name, t], g.min_power[t])
|
|
|
|
add_to_expression!(expr_net_injection[g.bus.name, t], is_on[g.name, t], g.min_power[t])
|
|
|
|
|
|
|
|
|
|
|
|
# Add to reserves expression
|
|
|
|
# Add to reserves expression
|
|
|
|
add_to_expression!(exprs.reserve[g.bus.name, t], vars.reserve[gi, t], 1.0)
|
|
|
|
add_to_expression!(expr_reserve[g.bus.name, t], reserve[gi, t], 1.0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function build_obj_function!(model::UnitCommitmentModel)
|
|
|
|
function _build_obj_function!(model::JuMP.Model)
|
|
|
|
@objective(model.mip, Min, model.obj)
|
|
|
|
@objective(model, Min, model[:obj])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function build_net_injection_eqs!(model::UnitCommitmentModel)
|
|
|
|
function _build_net_injection_eqs!(model::JuMP.Model)
|
|
|
|
T = model.instance.time
|
|
|
|
T = model[:instance].time
|
|
|
|
for t in 1:T, b in model.instance.buses
|
|
|
|
net_injection = model[:net_injection]
|
|
|
|
net = model.vars.net_injection[b.name, t] = @variable(model.mip)
|
|
|
|
for t in 1:T, b in model[:instance].buses
|
|
|
|
model.eqs.net_injection_def[t, b.name] =
|
|
|
|
n = net_injection[b.name, t] = @variable(model)
|
|
|
|
@constraint(model.mip, net == model.exprs.net_injection[b.name, t])
|
|
|
|
model[:eq_net_injection_def][t, b.name] =
|
|
|
|
|
|
|
|
@constraint(model, n == model[:expr_net_injection][b.name, t])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for t in 1:T
|
|
|
|
for t in 1:T
|
|
|
|
model.eqs.power_balance[t] =
|
|
|
|
model[:eq_power_balance][t] =
|
|
|
|
@constraint(model.mip, sum(model.vars.net_injection[b.name, t]
|
|
|
|
@constraint(
|
|
|
|
for b in model.instance.buses) == 0)
|
|
|
|
model,
|
|
|
|
|
|
|
|
sum(
|
|
|
|
|
|
|
|
net_injection[b.name, t]
|
|
|
|
|
|
|
|
for b in model[:instance].buses
|
|
|
|
|
|
|
|
) == 0
|
|
|
|
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function build_reserve_eqs!(model::UnitCommitmentModel)
|
|
|
|
function _build_reserve_eqs!(model::JuMP.Model)
|
|
|
|
reserves = model.instance.reserves
|
|
|
|
reserves = model[:instance].reserves
|
|
|
|
for t in 1:model.instance.time
|
|
|
|
for t in 1:model[:instance].time
|
|
|
|
model.eqs.min_reserve[t] =
|
|
|
|
model[:eq_min_reserve][t] =
|
|
|
|
@constraint(model.mip, sum(model.exprs.reserve[b.name, t]
|
|
|
|
@constraint(
|
|
|
|
for b in model.instance.buses) >= reserves.spinning[t])
|
|
|
|
model,
|
|
|
|
|
|
|
|
sum(
|
|
|
|
|
|
|
|
model[:expr_reserve][b.name, t]
|
|
|
|
|
|
|
|
for b in model[:instance].buses
|
|
|
|
|
|
|
|
) >= reserves.spinning[t]
|
|
|
|
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function enforce_transmission(;
|
|
|
|
function enforce_transmission(
|
|
|
|
model::UnitCommitmentModel,
|
|
|
|
;
|
|
|
|
violation::Violation,
|
|
|
|
model::JuMP.Model,
|
|
|
|
isf::Matrix{Float64},
|
|
|
|
violation::Violation,
|
|
|
|
lodf::Matrix{Float64})::Nothing
|
|
|
|
isf::Matrix{Float64},
|
|
|
|
|
|
|
|
lodf::Matrix{Float64},
|
|
|
|
instance, mip, vars = model.instance, model.mip, model.vars
|
|
|
|
)::Nothing
|
|
|
|
|
|
|
|
instance = model[:instance]
|
|
|
|
limit::Float64 = 0.0
|
|
|
|
limit::Float64 = 0.0
|
|
|
|
|
|
|
|
overflow = model[:overflow]
|
|
|
|
|
|
|
|
net_injection = model[:net_injection]
|
|
|
|
|
|
|
|
|
|
|
|
if violation.outage_line === nothing
|
|
|
|
if violation.outage_line === nothing
|
|
|
|
limit = violation.monitored_line.normal_flow_limit[violation.time]
|
|
|
|
limit = violation.monitored_line.normal_flow_limit[violation.time]
|
|
|
|
@info @sprintf(" %8.3f MW overflow in %-5s time %3d (pre-contingency)",
|
|
|
|
@info @sprintf(
|
|
|
|
violation.amount,
|
|
|
|
" %8.3f MW overflow in %-5s time %3d (pre-contingency)",
|
|
|
|
violation.monitored_line.name,
|
|
|
|
violation.amount,
|
|
|
|
violation.time)
|
|
|
|
violation.monitored_line.name,
|
|
|
|
|
|
|
|
violation.time,
|
|
|
|
|
|
|
|
)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
limit = violation.monitored_line.emergency_flow_limit[violation.time]
|
|
|
|
limit = violation.monitored_line.emergency_flow_limit[violation.time]
|
|
|
|
@info @sprintf(" %8.3f MW overflow in %-5s time %3d (outage: line %s)",
|
|
|
|
@info @sprintf(
|
|
|
|
violation.amount,
|
|
|
|
" %8.3f MW overflow in %-5s time %3d (outage: line %s)",
|
|
|
|
violation.monitored_line.name,
|
|
|
|
violation.amount,
|
|
|
|
violation.time,
|
|
|
|
violation.monitored_line.name,
|
|
|
|
violation.outage_line.name)
|
|
|
|
violation.time,
|
|
|
|
|
|
|
|
violation.outage_line.name,
|
|
|
|
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
fm = violation.monitored_line.name
|
|
|
|
fm = violation.monitored_line.name
|
|
|
|
t = violation.time
|
|
|
|
t = violation.time
|
|
|
|
flow = @variable(mip, base_name="flow[$fm,$t]")
|
|
|
|
flow = @variable(model, base_name="flow[$fm,$t]")
|
|
|
|
|
|
|
|
|
|
|
|
overflow = vars.overflow[violation.monitored_line.name, violation.time]
|
|
|
|
v = overflow[violation.monitored_line.name, violation.time]
|
|
|
|
@constraint(mip, flow <= limit + overflow)
|
|
|
|
@constraint(model, flow <= limit + v)
|
|
|
|
@constraint(mip, -flow <= limit + overflow)
|
|
|
|
@constraint(model, -flow <= limit + v)
|
|
|
|
|
|
|
|
|
|
|
|
if violation.outage_line === nothing
|
|
|
|
if violation.outage_line === nothing
|
|
|
|
@constraint(mip, flow == sum(vars.net_injection[b.name, violation.time] *
|
|
|
|
@constraint(model, flow == sum(net_injection[b.name, violation.time] *
|
|
|
|
isf[violation.monitored_line.offset, b.offset]
|
|
|
|
isf[violation.monitored_line.offset, b.offset]
|
|
|
|
for b in instance.buses
|
|
|
|
for b in instance.buses
|
|
|
|
if b.offset > 0))
|
|
|
|
if b.offset > 0))
|
|
|
|
else
|
|
|
|
else
|
|
|
|
@constraint(mip, flow == sum(vars.net_injection[b.name, violation.time] * (
|
|
|
|
@constraint(model, flow == sum(net_injection[b.name, violation.time] * (
|
|
|
|
isf[violation.monitored_line.offset, b.offset] + (
|
|
|
|
isf[violation.monitored_line.offset, b.offset] + (
|
|
|
|
lodf[violation.monitored_line.offset, violation.outage_line.offset] *
|
|
|
|
lodf[violation.monitored_line.offset, violation.outage_line.offset] *
|
|
|
|
isf[violation.outage_line.offset, b.offset]
|
|
|
|
isf[violation.outage_line.offset, b.offset]
|
|
|
@ -458,19 +497,22 @@ function enforce_transmission(;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function set_variable_names!(model::UnitCommitmentModel)
|
|
|
|
function _set_names!(model::JuMP.Model)
|
|
|
|
@info "Setting variable and constraint names..."
|
|
|
|
@info "Setting variable and constraint names..."
|
|
|
|
time_varnames = @elapsed begin
|
|
|
|
time_varnames = @elapsed begin
|
|
|
|
set_jump_names!(model.vars)
|
|
|
|
_set_names!(object_dictionary(model))
|
|
|
|
set_jump_names!(model.eqs)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@info @sprintf("Set names in %.2f seconds", time_varnames)
|
|
|
|
@info @sprintf("Set names in %.2f seconds", time_varnames)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function set_jump_names!(dict)
|
|
|
|
function _set_names!(dict::Dict)
|
|
|
|
for name in keys(dict)
|
|
|
|
for name in keys(dict)
|
|
|
|
|
|
|
|
dict[name] isa AbstractDict || continue
|
|
|
|
for idx in keys(dict[name])
|
|
|
|
for idx in keys(dict[name])
|
|
|
|
|
|
|
|
if dict[name][idx] isa AffExpr
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
end
|
|
|
|
idx_str = join(map(string, idx), ",")
|
|
|
|
idx_str = join(map(string, idx), ",")
|
|
|
|
set_name(dict[name][idx], "$name[$idx_str]")
|
|
|
|
set_name(dict[name][idx], "$name[$idx_str]")
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -478,27 +520,41 @@ function set_jump_names!(dict)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function get_solution(model::UnitCommitmentModel)
|
|
|
|
function solution(model::JuMP.Model)
|
|
|
|
instance, T = model.instance, model.instance.time
|
|
|
|
instance, T = model[:instance], model[:instance].time
|
|
|
|
function timeseries(vars, collection)
|
|
|
|
function timeseries(vars, collection)
|
|
|
|
return OrderedDict(b.name => [round(value(vars[b.name, t]), digits=5) for t in 1:T]
|
|
|
|
return OrderedDict(
|
|
|
|
for b in collection)
|
|
|
|
b.name => [round(value(vars[b.name, t]), digits=5) for t in 1:T]
|
|
|
|
|
|
|
|
for b in collection
|
|
|
|
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
function production_cost(g)
|
|
|
|
function production_cost(g)
|
|
|
|
return [value(model.vars.is_on[g.name, t]) * g.min_power_cost[t] +
|
|
|
|
return [
|
|
|
|
sum(Float64[value(model.vars.segprod[g.name, t, k]) * g.cost_segments[k].cost[t]
|
|
|
|
value(model[:is_on][g.name, t]) * g.min_power_cost[t] +
|
|
|
|
for k in 1:length(g.cost_segments)])
|
|
|
|
sum(
|
|
|
|
for t in 1:T]
|
|
|
|
Float64[
|
|
|
|
|
|
|
|
value(model[:segprod][g.name, t, k]) * g.cost_segments[k].cost[t]
|
|
|
|
|
|
|
|
for k in 1:length(g.cost_segments)
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
for t in 1:T
|
|
|
|
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
function production(g)
|
|
|
|
function production(g)
|
|
|
|
return [value(model.vars.is_on[g.name, t]) * g.min_power[t] +
|
|
|
|
return [
|
|
|
|
sum(Float64[value(model.vars.segprod[g.name, t, k])
|
|
|
|
value(model[:is_on][g.name, t]) * g.min_power[t] +
|
|
|
|
for k in 1:length(g.cost_segments)])
|
|
|
|
sum(
|
|
|
|
for t in 1:T]
|
|
|
|
Float64[
|
|
|
|
|
|
|
|
value(model[:segprod][g.name, t, k])
|
|
|
|
|
|
|
|
for k in 1:length(g.cost_segments)
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
for t in 1:T
|
|
|
|
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
function startup_cost(g)
|
|
|
|
function startup_cost(g)
|
|
|
|
S = length(g.startup_categories)
|
|
|
|
S = length(g.startup_categories)
|
|
|
|
return [sum(g.startup_categories[s].cost * value(model.vars.startup[g.name, t, s])
|
|
|
|
return [sum(g.startup_categories[s].cost * value(model[:startup][g.name, t, s])
|
|
|
|
for s in 1:S)
|
|
|
|
for s in 1:S)
|
|
|
|
for t in 1:T]
|
|
|
|
for t in 1:T]
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -506,69 +562,80 @@ function get_solution(model::UnitCommitmentModel)
|
|
|
|
sol["Production (MW)"] = OrderedDict(g.name => production(g) for g in instance.units)
|
|
|
|
sol["Production (MW)"] = OrderedDict(g.name => production(g) for g in instance.units)
|
|
|
|
sol["Production cost (\$)"] = OrderedDict(g.name => production_cost(g) for g in instance.units)
|
|
|
|
sol["Production cost (\$)"] = OrderedDict(g.name => production_cost(g) for g in instance.units)
|
|
|
|
sol["Startup cost (\$)"] = OrderedDict(g.name => startup_cost(g) for g in instance.units)
|
|
|
|
sol["Startup cost (\$)"] = OrderedDict(g.name => startup_cost(g) for g in instance.units)
|
|
|
|
sol["Is on"] = timeseries(model.vars.is_on, instance.units)
|
|
|
|
sol["Is on"] = timeseries(model[:is_on], instance.units)
|
|
|
|
sol["Switch on"] = timeseries(model.vars.switch_on, instance.units)
|
|
|
|
sol["Switch on"] = timeseries(model[:switch_on], instance.units)
|
|
|
|
sol["Switch off"] = timeseries(model.vars.switch_off, instance.units)
|
|
|
|
sol["Switch off"] = timeseries(model[:switch_off], instance.units)
|
|
|
|
sol["Reserve (MW)"] = timeseries(model.vars.reserve, instance.units)
|
|
|
|
sol["Reserve (MW)"] = timeseries(model[:reserve], instance.units)
|
|
|
|
sol["Net injection (MW)"] = timeseries(model.vars.net_injection, instance.buses)
|
|
|
|
sol["Net injection (MW)"] = timeseries(model[:net_injection], instance.buses)
|
|
|
|
sol["Load curtail (MW)"] = timeseries(model.vars.curtail, instance.buses)
|
|
|
|
sol["Load curtail (MW)"] = timeseries(model[:curtail], instance.buses)
|
|
|
|
if !isempty(instance.lines)
|
|
|
|
if !isempty(instance.lines)
|
|
|
|
sol["Line overflow (MW)"] = timeseries(model.vars.overflow, instance.lines)
|
|
|
|
sol["Line overflow (MW)"] = timeseries(model[:overflow], instance.lines)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if !isempty(instance.price_sensitive_loads)
|
|
|
|
if !isempty(instance.price_sensitive_loads)
|
|
|
|
sol["Price-sensitive loads (MW)"] = timeseries(model.vars.loads, instance.price_sensitive_loads)
|
|
|
|
sol["Price-sensitive loads (MW)"] = timeseries(model[:loads], instance.price_sensitive_loads)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return sol
|
|
|
|
return sol
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function fix!(model::UnitCommitmentModel, solution)::Nothing
|
|
|
|
function fix!(model::JuMP.Model, solution)::Nothing
|
|
|
|
vars, instance, T = model.vars, model.instance, model.instance.time
|
|
|
|
instance, T = model[:instance], model[:instance].time
|
|
|
|
|
|
|
|
is_on = model[:is_on]
|
|
|
|
|
|
|
|
prod_above = model[:prod_above]
|
|
|
|
|
|
|
|
reserve = model[:reserve]
|
|
|
|
for g in instance.units
|
|
|
|
for g in instance.units
|
|
|
|
for t in 1:T
|
|
|
|
for t in 1:T
|
|
|
|
is_on = round(solution["Is on"][g.name][t])
|
|
|
|
is_on_value = round(solution["Is on"][g.name][t])
|
|
|
|
production = round(solution["Production (MW)"][g.name][t], digits=5)
|
|
|
|
production_value = round(solution["Production (MW)"][g.name][t], digits=5)
|
|
|
|
reserve = round(solution["Reserve (MW)"][g.name][t], digits=5)
|
|
|
|
reserve_value = round(solution["Reserve (MW)"][g.name][t], digits=5)
|
|
|
|
JuMP.fix(vars.is_on[g.name, t], is_on, force=true)
|
|
|
|
JuMP.fix(is_on[g.name, t], is_on_value, force=true)
|
|
|
|
JuMP.fix(vars.prod_above[g.name, t], production - is_on * g.min_power[t], force=true)
|
|
|
|
JuMP.fix(
|
|
|
|
JuMP.fix(vars.reserve[g.name, t], reserve, force=true)
|
|
|
|
prod_above[g.name, t],
|
|
|
|
|
|
|
|
production_value - is_on_value * g.min_power[t],
|
|
|
|
|
|
|
|
force=true,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
JuMP.fix(reserve[g.name, t], reserve_value, force=true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function set_warm_start!(model::UnitCommitmentModel, solution)::Nothing
|
|
|
|
function set_warm_start!(model::JuMP.Model, solution)::Nothing
|
|
|
|
vars, instance, T = model.vars, model.instance, model.instance.time
|
|
|
|
instance, T = model[:instance], model[:instance].time
|
|
|
|
|
|
|
|
is_on = model[:is_on]
|
|
|
|
|
|
|
|
prod_above = model[:prod_above]
|
|
|
|
|
|
|
|
reserve = model[:reserve]
|
|
|
|
for g in instance.units
|
|
|
|
for g in instance.units
|
|
|
|
for t in 1:T
|
|
|
|
for t in 1:T
|
|
|
|
JuMP.set_start_value(vars.is_on[g.name, t], solution["Is on"][g.name][t])
|
|
|
|
JuMP.set_start_value(is_on[g.name, t], solution["Is on"][g.name][t])
|
|
|
|
JuMP.set_start_value(vars.switch_on[g.name, t], solution["Switch on"][g.name][t])
|
|
|
|
JuMP.set_start_value(switch_on[g.name, t], solution["Switch on"][g.name][t])
|
|
|
|
JuMP.set_start_value(vars.switch_off[g.name, t], solution["Switch off"][g.name][t])
|
|
|
|
JuMP.set_start_value(switch_off[g.name, t], solution["Switch off"][g.name][t])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function optimize!(model::UnitCommitmentModel;
|
|
|
|
function optimize!(
|
|
|
|
time_limit=3600,
|
|
|
|
model::JuMP.Model;
|
|
|
|
gap_limit=1e-4,
|
|
|
|
time_limit=3600,
|
|
|
|
two_phase_gap=true,
|
|
|
|
gap_limit=1e-4,
|
|
|
|
)::Nothing
|
|
|
|
two_phase_gap=true,
|
|
|
|
|
|
|
|
)::Nothing
|
|
|
|
|
|
|
|
|
|
|
|
function set_gap(gap)
|
|
|
|
function set_gap(gap)
|
|
|
|
try
|
|
|
|
try
|
|
|
|
JuMP.set_optimizer_attribute(model.mip, "MIPGap", gap)
|
|
|
|
JuMP.set_optimizer_attribute(model, "MIPGap", gap)
|
|
|
|
@info @sprintf("MIP gap tolerance set to %f", gap)
|
|
|
|
@info @sprintf("MIP gap tolerance set to %f", gap)
|
|
|
|
catch
|
|
|
|
catch
|
|
|
|
@warn "Could not change MIP gap tolerance"
|
|
|
|
@warn "Could not change MIP gap tolerance"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
instance = model.instance
|
|
|
|
instance = model[:instance]
|
|
|
|
initial_time = time()
|
|
|
|
initial_time = time()
|
|
|
|
|
|
|
|
|
|
|
|
large_gap = false
|
|
|
|
large_gap = false
|
|
|
|
has_transmission = (length(model.isf) > 0)
|
|
|
|
has_transmission = (length(model[:isf]) > 0)
|
|
|
|
|
|
|
|
|
|
|
|
if has_transmission && two_phase_gap
|
|
|
|
if has_transmission && two_phase_gap
|
|
|
|
set_gap(1e-2)
|
|
|
|
set_gap(1e-2)
|
|
|
@ -586,10 +653,10 @@ function optimize!(model::UnitCommitmentModel;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
@info @sprintf("Setting MILP time limit to %.2f seconds", time_remaining)
|
|
|
|
@info @sprintf("Setting MILP time limit to %.2f seconds", time_remaining)
|
|
|
|
JuMP.set_time_limit_sec(model.mip, time_remaining)
|
|
|
|
JuMP.set_time_limit_sec(model, time_remaining)
|
|
|
|
|
|
|
|
|
|
|
|
@info "Solving MILP..."
|
|
|
|
@info "Solving MILP..."
|
|
|
|
JuMP.optimize!(model.mip)
|
|
|
|
JuMP.optimize!(model)
|
|
|
|
|
|
|
|
|
|
|
|
has_transmission || break
|
|
|
|
has_transmission || break
|
|
|
|
|
|
|
|
|
|
|
@ -611,36 +678,49 @@ function optimize!(model::UnitCommitmentModel;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function find_violations(model::UnitCommitmentModel)
|
|
|
|
function find_violations(model::JuMP.Model)
|
|
|
|
instance, vars = model.instance, model.vars
|
|
|
|
instance = model[:instance]
|
|
|
|
|
|
|
|
net_injection = model[:net_injection]
|
|
|
|
|
|
|
|
overflow = model[:overflow]
|
|
|
|
length(instance.buses) > 1 || return []
|
|
|
|
length(instance.buses) > 1 || return []
|
|
|
|
violations = []
|
|
|
|
violations = []
|
|
|
|
@info "Verifying transmission limits..."
|
|
|
|
@info "Verifying transmission limits..."
|
|
|
|
time_screening = @elapsed begin
|
|
|
|
time_screening = @elapsed begin
|
|
|
|
non_slack_buses = [b for b in instance.buses if b.offset > 0]
|
|
|
|
non_slack_buses = [b for b in instance.buses if b.offset > 0]
|
|
|
|
net_injections = [value(vars.net_injection[b.name, t])
|
|
|
|
net_injection_values = [
|
|
|
|
for b in non_slack_buses, t in 1:instance.time]
|
|
|
|
value(net_injection[b.name, t])
|
|
|
|
overflow = [value(vars.overflow[lm.name, t])
|
|
|
|
for b in non_slack_buses, t in 1:instance.time
|
|
|
|
for lm in instance.lines, t in 1:instance.time]
|
|
|
|
]
|
|
|
|
violations = UnitCommitment.find_violations(instance=instance,
|
|
|
|
overflow_values = [
|
|
|
|
net_injections=net_injections,
|
|
|
|
value(overflow[lm.name, t])
|
|
|
|
overflow=overflow,
|
|
|
|
for lm in instance.lines, t in 1:instance.time
|
|
|
|
isf=model.isf,
|
|
|
|
]
|
|
|
|
lodf=model.lodf)
|
|
|
|
violations = UnitCommitment.find_violations(
|
|
|
|
|
|
|
|
instance=instance,
|
|
|
|
|
|
|
|
net_injections=net_injection_values,
|
|
|
|
|
|
|
|
overflow=overflow_values,
|
|
|
|
|
|
|
|
isf=model[:isf],
|
|
|
|
|
|
|
|
lodf=model[:lodf],
|
|
|
|
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@info @sprintf("Verified transmission limits in %.2f seconds", time_screening)
|
|
|
|
@info @sprintf("Verified transmission limits in %.2f seconds", time_screening)
|
|
|
|
return violations
|
|
|
|
return violations
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function enforce_transmission(model::UnitCommitmentModel, violations::Array{Violation, 1})
|
|
|
|
function enforce_transmission(
|
|
|
|
|
|
|
|
model::JuMP.Model,
|
|
|
|
|
|
|
|
violations::Vector{Violation},
|
|
|
|
|
|
|
|
)::Nothing
|
|
|
|
for v in violations
|
|
|
|
for v in violations
|
|
|
|
enforce_transmission(model=model,
|
|
|
|
enforce_transmission(
|
|
|
|
violation=v,
|
|
|
|
model=model,
|
|
|
|
isf=model.isf,
|
|
|
|
violation=v,
|
|
|
|
lodf=model.lodf)
|
|
|
|
isf=model[:isf],
|
|
|
|
end
|
|
|
|
lodf=model[:lodf],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export build_model
|
|
|
|
export UnitCommitmentModel, build_model, get_solution, optimize!
|
|
|
|
|