|
|
@ -5,15 +5,14 @@
|
|
|
|
using JuMP, MathOptInterface, DataStructures
|
|
|
|
using JuMP, MathOptInterface, DataStructures
|
|
|
|
import JuMP: value, fix, set_name
|
|
|
|
import JuMP: value, fix, set_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Extend some JuMP functions so that decision variables can be safely replaced by
|
|
|
|
# Extend some JuMP functions so that decision variables can be safely replaced by
|
|
|
|
# (constant) floating point numbers.
|
|
|
|
# (constant) floating point numbers.
|
|
|
|
function value(x::Float64)
|
|
|
|
function value(x::Float64)
|
|
|
|
x
|
|
|
|
return x
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function fix(x::Float64, v::Float64; force)
|
|
|
|
function fix(x::Float64, v::Float64; force)
|
|
|
|
abs(x - v) < 1e-6 || error("Value mismatch: $x != $v")
|
|
|
|
return abs(x - v) < 1e-6 || error("Value mismatch: $x != $v")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function set_name(x::Float64, n::String)
|
|
|
|
function set_name(x::Float64, n::String)
|
|
|
@ -21,20 +20,19 @@ function set_name(x::Float64, n::String)
|
|
|
|
end
|
|
|
|
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{Matrix{Float64}, Nothing}=nothing,
|
|
|
|
isf::Union{Matrix{Float64},Nothing} = nothing,
|
|
|
|
lodf::Union{Matrix{Float64}, 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,
|
|
|
|
variable_names::Bool=false,
|
|
|
|
variable_names::Bool = false,
|
|
|
|
)::JuMP.Model
|
|
|
|
)::JuMP.Model
|
|
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if filename !== nothing
|
|
|
|
if filename !== nothing
|
|
|
|
@info "Reading: $(filename)"
|
|
|
|
@info "Reading: $(filename)"
|
|
|
|
time_read = @elapsed begin
|
|
|
|
time_read = @elapsed begin
|
|
|
@ -42,7 +40,7 @@ function build_model(;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@info @sprintf("Read problem in %.2f seconds", time_read)
|
|
|
|
@info @sprintf("Read problem in %.2f seconds", time_read)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if length(instance.buses) == 1
|
|
|
|
if length(instance.buses) == 1
|
|
|
|
isf = zeros(0, 0)
|
|
|
|
isf = zeros(0, 0)
|
|
|
|
lodf = zeros(0, 0)
|
|
|
|
lodf = zeros(0, 0)
|
|
|
@ -51,25 +49,29 @@ function build_model(;
|
|
|
|
@info "Computing injection shift factors..."
|
|
|
|
@info "Computing injection shift factors..."
|
|
|
|
time_isf = @elapsed begin
|
|
|
|
time_isf = @elapsed begin
|
|
|
|
isf = UnitCommitment._injection_shift_factors(
|
|
|
|
isf = UnitCommitment._injection_shift_factors(
|
|
|
|
lines=instance.lines,
|
|
|
|
lines = instance.lines,
|
|
|
|
buses=instance.buses,
|
|
|
|
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(
|
|
|
|
lodf = UnitCommitment._line_outage_factors(
|
|
|
|
lines=instance.lines,
|
|
|
|
lines = instance.lines,
|
|
|
|
buses=instance.buses,
|
|
|
|
buses = instance.buses,
|
|
|
|
isf=isf,
|
|
|
|
isf = isf,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@info @sprintf("Computed LODF in %.2f seconds", time_lodf)
|
|
|
|
@info @sprintf("Computed LODF in %.2f seconds", time_lodf)
|
|
|
|
|
|
|
|
|
|
|
|
@info @sprintf("Applying PTDF and LODF cutoffs (%.5f, %.5f)", isf_cutoff, lodf_cutoff)
|
|
|
|
@info @sprintf(
|
|
|
|
isf[abs.(isf) .< isf_cutoff] .= 0
|
|
|
|
"Applying PTDF and LODF cutoffs (%.5f, %.5f)",
|
|
|
|
lodf[abs.(lodf) .< lodf_cutoff] .= 0
|
|
|
|
isf_cutoff,
|
|
|
|
|
|
|
|
lodf_cutoff
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
isf[abs.(isf).<isf_cutoff] .= 0
|
|
|
|
|
|
|
|
lodf[abs.(lodf).<lodf_cutoff] .= 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -138,21 +140,19 @@ function build_model(;
|
|
|
|
if variable_names
|
|
|
|
if variable_names
|
|
|
|
_set_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)
|
|
|
|
obj, T = model[:obj], model[:instance].time
|
|
|
|
obj, T = model[:obj], model[:instance].time
|
|
|
|
overflow = model[:overflow]
|
|
|
|
overflow = model[:overflow]
|
|
|
|
for t in 1:T
|
|
|
|
for t in 1:T
|
|
|
|
v = overflow[lm.name, t] = @variable(model, lower_bound=0)
|
|
|
|
v = overflow[lm.name, t] = @variable(model, lower_bound = 0)
|
|
|
|
add_to_expression!(obj, v, lm.flow_limit_penalty[t])
|
|
|
|
add_to_expression!(obj, v, lm.flow_limit_penalty[t])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _add_bus!(model::JuMP.Model, b::Bus)
|
|
|
|
function _add_bus!(model::JuMP.Model, b::Bus)
|
|
|
|
mip = model
|
|
|
|
mip = model
|
|
|
|
net_injection = model[:expr_net_injection]
|
|
|
|
net_injection = model[:expr_net_injection]
|
|
|
@ -161,12 +161,13 @@ function _add_bus!(model::JuMP.Model, b::Bus)
|
|
|
|
for t in 1:model[:instance].time
|
|
|
|
for t in 1:model[:instance].time
|
|
|
|
# Fixed load
|
|
|
|
# Fixed load
|
|
|
|
net_injection[b.name, t] = AffExpr(-b.load[t])
|
|
|
|
net_injection[b.name, t] = AffExpr(-b.load[t])
|
|
|
|
|
|
|
|
|
|
|
|
# Reserves
|
|
|
|
# Reserves
|
|
|
|
reserve[b.name, t] = AffExpr()
|
|
|
|
reserve[b.name, t] = AffExpr()
|
|
|
|
|
|
|
|
|
|
|
|
# Load curtailment
|
|
|
|
# Load curtailment
|
|
|
|
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!(net_injection[b.name, t], curtail[b.name, t], 1.0)
|
|
|
|
add_to_expression!(net_injection[b.name, t], curtail[b.name, t], 1.0)
|
|
|
|
add_to_expression!(
|
|
|
|
add_to_expression!(
|
|
|
|
model[:obj],
|
|
|
|
model[:obj],
|
|
|
@ -176,24 +177,27 @@ function _add_bus!(model::JuMP.Model, b::Bus)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _add_price_sensitive_load!(model::JuMP.Model, ps::PriceSensitiveLoad)
|
|
|
|
function _add_price_sensitive_load!(model::JuMP.Model, ps::PriceSensitiveLoad)
|
|
|
|
mip = model
|
|
|
|
mip = model
|
|
|
|
loads = model[:loads]
|
|
|
|
loads = model[:loads]
|
|
|
|
net_injection = model[:expr_net_injection]
|
|
|
|
net_injection = model[:expr_net_injection]
|
|
|
|
for t in 1:model[:instance].time
|
|
|
|
for t in 1:model[:instance].time
|
|
|
|
# Decision variable
|
|
|
|
# Decision variable
|
|
|
|
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], 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!(net_injection[ps.bus.name, t], 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::JuMP.Model, g::Unit)
|
|
|
|
function _add_unit!(model::JuMP.Model, g::Unit)
|
|
|
|
mip, T = model, 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)
|
|
|
@ -207,11 +211,11 @@ function _add_unit!(model::JuMP.Model, g::Unit)
|
|
|
|
switch_off = model[:switch_off]
|
|
|
|
switch_off = model[:switch_off]
|
|
|
|
expr_net_injection = model[:expr_net_injection]
|
|
|
|
expr_net_injection = model[:expr_net_injection]
|
|
|
|
expr_reserve = model[:expr_reserve]
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
if g.initial_power === nothing || g.initial_status === nothing
|
|
|
|
if g.initial_power === nothing || g.initial_status === nothing
|
|
|
|
error("Initial conditions for $(g.name) must be provided")
|
|
|
|
error("Initial conditions for $(g.name) must be provided")
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -221,25 +225,25 @@ function _add_unit!(model::JuMP.Model, 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
|
|
|
|
segprod[gi, t, k] = @variable(model, lower_bound=0)
|
|
|
|
segprod[gi, t, k] = @variable(model, lower_bound = 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
prod_above[gi, t] = @variable(model, lower_bound=0)
|
|
|
|
prod_above[gi, t] = @variable(model, lower_bound = 0)
|
|
|
|
if g.provides_spinning_reserves[t]
|
|
|
|
if g.provides_spinning_reserves[t]
|
|
|
|
reserve[gi, t] = @variable(model, lower_bound=0)
|
|
|
|
reserve[gi, t] = @variable(model, lower_bound = 0)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
reserve[gi, t] = 0.0
|
|
|
|
reserve[gi, t] = 0.0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for s in 1:S
|
|
|
|
for s in 1:S
|
|
|
|
startup[gi, t, s] = @variable(model, binary=true)
|
|
|
|
startup[gi, t, s] = @variable(model, binary = true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if g.must_run[t]
|
|
|
|
if g.must_run[t]
|
|
|
|
is_on[gi, t] = 1.0
|
|
|
|
is_on[gi, t] = 1.0
|
|
|
|
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)
|
|
|
|
switch_off[gi, t] = 0.0
|
|
|
|
switch_off[gi, t] = 0.0
|
|
|
|
else
|
|
|
|
else
|
|
|
|
is_on[gi, t] = @variable(model, binary=true)
|
|
|
|
is_on[gi, t] = @variable(model, binary = true)
|
|
|
|
switch_on[gi, t] = @variable(model, binary=true)
|
|
|
|
switch_on[gi, t] = @variable(model, binary = true)
|
|
|
|
switch_off[gi, t] = @variable(model, binary=true)
|
|
|
|
switch_off[gi, t] = @variable(model, binary = true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -247,19 +251,28 @@ function _add_unit!(model::JuMP.Model, 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
|
|
|
|
model[:eq_startup_choose][gi, t, s] =
|
|
|
|
model[:eq_startup_choose][gi, t, s] = @constraint(
|
|
|
|
@constraint(mip, switch_on[gi, t] == sum(startup[gi, t, s] for s in 1:S))
|
|
|
|
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_start = t - g.startup_categories[s+1].delay + 1
|
|
|
|
initial_sum = (g.initial_status < 0 && (g.initial_status + 1 in range) ? 1.0 : 0.0)
|
|
|
|
range_end = t - g.startup_categories[s].delay
|
|
|
|
model[:eq_startup_restrict][gi, t, s] =
|
|
|
|
range = (range_start:range_end)
|
|
|
|
@constraint(mip, startup[gi, t, s]
|
|
|
|
initial_sum = (
|
|
|
|
<= initial_sum + sum(switch_off[gi, i] for i in range if i >= 1))
|
|
|
|
g.initial_status < 0 && (g.initial_status + 1 in range) ? 1.0 : 0.0
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
model[:eq_startup_restrict][gi, t, s] = @constraint(
|
|
|
|
|
|
|
|
mip,
|
|
|
|
|
|
|
|
startup[gi, t, s] <=
|
|
|
|
|
|
|
|
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!(
|
|
|
|
add_to_expression!(
|
|
|
|
model[:obj],
|
|
|
|
model[:obj],
|
|
|
@ -267,142 +280,171 @@ function _add_unit!(model::JuMP.Model, g::Unit)
|
|
|
|
g.startup_categories[s].cost,
|
|
|
|
g.startup_categories[s].cost,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Objective function terms for production costs
|
|
|
|
# Objective function terms for production costs
|
|
|
|
add_to_expression!(model[:obj], 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], 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
|
|
|
|
model[:eq_segprod_limit][gi, t, k] =
|
|
|
|
model[:eq_segprod_limit][gi, t, k] = @constraint(
|
|
|
|
@constraint(mip, segprod[gi, t, k] <= g.cost_segments[k].mw[t] * is_on[gi, t])
|
|
|
|
mip,
|
|
|
|
|
|
|
|
segprod[gi, t, k] <= g.cost_segments[k].mw[t] * is_on[gi, t]
|
|
|
|
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Definition of production
|
|
|
|
# Definition of production
|
|
|
|
model[:eq_prod_above_def][gi, t] =
|
|
|
|
model[:eq_prod_above_def][gi, t] = @constraint(
|
|
|
|
@constraint(mip, prod_above[gi, t] == sum(segprod[gi, t, k] for k in 1:K))
|
|
|
|
mip,
|
|
|
|
|
|
|
|
prod_above[gi, t] == sum(segprod[gi, t, k] for k in 1:K)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Production limit
|
|
|
|
# Production limit
|
|
|
|
model[:eq_prod_limit][gi, t] =
|
|
|
|
model[:eq_prod_limit][gi, t] = @constraint(
|
|
|
|
@constraint(mip,
|
|
|
|
mip,
|
|
|
|
prod_above[gi, t] + reserve[gi, t]
|
|
|
|
prod_above[gi, t] + reserve[gi, t] <=
|
|
|
|
<= (g.max_power[t] - g.min_power[t]) * 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
|
|
|
|
model[:eq_binary_link][gi, t] =
|
|
|
|
model[:eq_binary_link][gi, t] = @constraint(
|
|
|
|
@constraint(mip,
|
|
|
|
mip,
|
|
|
|
is_on[gi, t] - is_initially_on ==
|
|
|
|
is_on[gi, t] - is_initially_on ==
|
|
|
|
switch_on[gi, t] - switch_off[gi, t])
|
|
|
|
switch_on[gi, t] - switch_off[gi, t]
|
|
|
|
|
|
|
|
)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
model[:eq_binary_link][gi, t] =
|
|
|
|
model[:eq_binary_link][gi, t] = @constraint(
|
|
|
|
@constraint(mip,
|
|
|
|
mip,
|
|
|
|
is_on[gi, t] - is_on[gi, t-1] ==
|
|
|
|
is_on[gi, t] - is_on[gi, t-1] ==
|
|
|
|
switch_on[gi, t] - 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
|
|
|
|
model[:eq_switch_on_off][gi, t] =
|
|
|
|
model[:eq_switch_on_off][gi, t] =
|
|
|
|
@constraint(mip, switch_on[gi, t] + 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
|
|
|
|
model[:eq_ramp_up][gi, t] =
|
|
|
|
model[:eq_ramp_up][gi, t] = @constraint(
|
|
|
|
@constraint(mip,
|
|
|
|
mip,
|
|
|
|
prod_above[gi, t] + 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
|
|
|
|
model[:eq_ramp_up][gi, t] =
|
|
|
|
model[:eq_ramp_up][gi, t] = @constraint(
|
|
|
|
@constraint(mip,
|
|
|
|
mip,
|
|
|
|
prod_above[gi, t] + reserve[gi, t] <=
|
|
|
|
prod_above[gi, t] + reserve[gi, t] <=
|
|
|
|
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
|
|
|
|
model[:eq_ramp_down][gi, t] =
|
|
|
|
model[:eq_ramp_down][gi, t] = @constraint(
|
|
|
|
@constraint(mip,
|
|
|
|
mip,
|
|
|
|
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
|
|
|
|
model[:eq_ramp_down][gi, t] =
|
|
|
|
model[:eq_ramp_down][gi, t] = @constraint(
|
|
|
|
@constraint(mip,
|
|
|
|
mip,
|
|
|
|
prod_above[gi, t] >=
|
|
|
|
prod_above[gi, t] >= prod_above[gi, t-1] - g.ramp_down_limit
|
|
|
|
prod_above[gi, t-1] - g.ramp_down_limit)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Startup limit
|
|
|
|
# Startup limit
|
|
|
|
model[:eq_startup_limit][gi, t] =
|
|
|
|
model[:eq_startup_limit][gi, t] = @constraint(
|
|
|
|
@constraint(mip,
|
|
|
|
mip,
|
|
|
|
prod_above[gi, t] + reserve[gi, t] <=
|
|
|
|
prod_above[gi, t] + reserve[gi, t] <=
|
|
|
|
(g.max_power[t] - g.min_power[t]) * 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) * 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
|
|
|
|
model[:eq_shutdown_limit][gi, 0] =
|
|
|
|
model[:eq_shutdown_limit][gi, 0] =
|
|
|
|
@constraint(mip, switch_off[gi, 1] <= 0)
|
|
|
|
@constraint(mip, switch_off[gi, 1] <= 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if t < T
|
|
|
|
if t < T
|
|
|
|
model[:eq_shutdown_limit][gi, t] =
|
|
|
|
model[:eq_shutdown_limit][gi, t] = @constraint(
|
|
|
|
@constraint(mip,
|
|
|
|
mip,
|
|
|
|
prod_above[gi, t] <=
|
|
|
|
prod_above[gi, t] <=
|
|
|
|
(g.max_power[t] - g.min_power[t]) * 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) * 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
|
|
|
|
model[:eq_min_uptime][gi, t] =
|
|
|
|
model[:eq_min_uptime][gi, t] = @constraint(
|
|
|
|
@constraint(mip,
|
|
|
|
mip,
|
|
|
|
sum(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
|
|
|
|
is_on[gi, t]
|
|
|
|
) <= is_on[gi, t])
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# # Minimum down-time
|
|
|
|
# # Minimum down-time
|
|
|
|
model[:eq_min_downtime][gi, t] =
|
|
|
|
model[:eq_min_downtime][gi, t] = @constraint(
|
|
|
|
@constraint(mip,
|
|
|
|
mip,
|
|
|
|
sum(switch_off[gi, i]
|
|
|
|
sum(switch_off[gi, i] for i in (t-g.min_downtime+1):t if i >= 1) <= 1 - is_on[gi, t]
|
|
|
|
for i in (t - g.min_downtime + 1):t if i >= 1
|
|
|
|
)
|
|
|
|
) <= 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
|
|
|
|
model[:eq_min_uptime][gi, 0] =
|
|
|
|
model[:eq_min_uptime][gi, 0] = @constraint(
|
|
|
|
@constraint(mip, sum(switch_off[gi, i]
|
|
|
|
mip,
|
|
|
|
for i in 1:(g.min_uptime - g.initial_status) if i <= T) == 0)
|
|
|
|
sum(
|
|
|
|
|
|
|
|
switch_off[gi, i] for
|
|
|
|
|
|
|
|
i in 1:(g.min_uptime-g.initial_status) if i <= T
|
|
|
|
|
|
|
|
) == 0
|
|
|
|
|
|
|
|
)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
model[:eq_min_downtime][gi, 0] =
|
|
|
|
model[:eq_min_downtime][gi, 0] = @constraint(
|
|
|
|
@constraint(mip, sum(switch_on[gi, i]
|
|
|
|
mip,
|
|
|
|
for i in 1:(g.min_downtime + g.initial_status) if i <= T) == 0)
|
|
|
|
sum(
|
|
|
|
|
|
|
|
switch_on[gi, i] 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!(expr_net_injection[g.bus.name, t], prod_above[g.name, t], 1.0)
|
|
|
|
add_to_expression!(
|
|
|
|
add_to_expression!(expr_net_injection[g.bus.name, t], is_on[g.name, t], g.min_power[t])
|
|
|
|
expr_net_injection[g.bus.name, t],
|
|
|
|
|
|
|
|
prod_above[g.name, t],
|
|
|
|
|
|
|
|
1.0,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
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!(expr_reserve[g.bus.name, t], 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::JuMP.Model)
|
|
|
|
function _build_obj_function!(model::JuMP.Model)
|
|
|
|
@objective(model, Min, model[:obj])
|
|
|
|
@objective(model, Min, model[:obj])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _build_net_injection_eqs!(model::JuMP.Model)
|
|
|
|
function _build_net_injection_eqs!(model::JuMP.Model)
|
|
|
|
T = model[:instance].time
|
|
|
|
T = model[:instance].time
|
|
|
|
net_injection = model[:net_injection]
|
|
|
|
net_injection = model[:net_injection]
|
|
|
@ -412,45 +454,36 @@ function _build_net_injection_eqs!(model::JuMP.Model)
|
|
|
|
@constraint(model, n == model[:expr_net_injection][b.name, t])
|
|
|
|
@constraint(model, n == model[:expr_net_injection][b.name, t])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for t in 1:T
|
|
|
|
for t in 1:T
|
|
|
|
model[:eq_power_balance][t] =
|
|
|
|
model[:eq_power_balance][t] = @constraint(
|
|
|
|
@constraint(
|
|
|
|
model,
|
|
|
|
model,
|
|
|
|
sum(net_injection[b.name, t] for b in model[:instance].buses) == 0
|
|
|
|
sum(
|
|
|
|
)
|
|
|
|
net_injection[b.name, t]
|
|
|
|
|
|
|
|
for b in model[:instance].buses
|
|
|
|
|
|
|
|
) == 0
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _build_reserve_eqs!(model::JuMP.Model)
|
|
|
|
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[:eq_min_reserve][t] =
|
|
|
|
model[:eq_min_reserve][t] = @constraint(
|
|
|
|
@constraint(
|
|
|
|
model,
|
|
|
|
model,
|
|
|
|
sum(
|
|
|
|
sum(
|
|
|
|
model[:expr_reserve][b.name, t] for b in model[:instance].buses
|
|
|
|
model[:expr_reserve][b.name, t]
|
|
|
|
) >= reserves.spinning[t]
|
|
|
|
for b in model[:instance].buses
|
|
|
|
)
|
|
|
|
) >= reserves.spinning[t]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _enforce_transmission(;
|
|
|
|
function _enforce_transmission(
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
model::JuMP.Model,
|
|
|
|
model::JuMP.Model,
|
|
|
|
violation::Violation,
|
|
|
|
violation::Violation,
|
|
|
|
isf::Matrix{Float64},
|
|
|
|
isf::Matrix{Float64},
|
|
|
|
lodf::Matrix{Float64},
|
|
|
|
lodf::Matrix{Float64},
|
|
|
|
)::Nothing
|
|
|
|
)::Nothing
|
|
|
|
instance = model[:instance]
|
|
|
|
instance = model[:instance]
|
|
|
|
limit::Float64 = 0.0
|
|
|
|
limit::Float64 = 0.0
|
|
|
|
overflow = model[:overflow]
|
|
|
|
overflow = model[:overflow]
|
|
|
|
net_injection = model[:net_injection]
|
|
|
|
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(
|
|
|
|
@info @sprintf(
|
|
|
@ -469,34 +502,42 @@ function _enforce_transmission(
|
|
|
|
violation.outage_line.name,
|
|
|
|
violation.outage_line.name,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
fm = violation.monitored_line.name
|
|
|
|
fm = violation.monitored_line.name
|
|
|
|
t = violation.time
|
|
|
|
t = violation.time
|
|
|
|
flow = @variable(model, base_name="flow[$fm,$t]")
|
|
|
|
flow = @variable(model, base_name = "flow[$fm,$t]")
|
|
|
|
|
|
|
|
|
|
|
|
v = overflow[violation.monitored_line.name, violation.time]
|
|
|
|
v = overflow[violation.monitored_line.name, violation.time]
|
|
|
|
@constraint(model, flow <= limit + v)
|
|
|
|
@constraint(model, flow <= limit + v)
|
|
|
|
@constraint(model, -flow <= limit + v)
|
|
|
|
@constraint(model, -flow <= limit + v)
|
|
|
|
|
|
|
|
|
|
|
|
if violation.outage_line === nothing
|
|
|
|
if violation.outage_line === nothing
|
|
|
|
@constraint(model, flow == sum(net_injection[b.name, violation.time] *
|
|
|
|
@constraint(
|
|
|
|
isf[violation.monitored_line.offset, b.offset]
|
|
|
|
model,
|
|
|
|
for b in instance.buses
|
|
|
|
flow == sum(
|
|
|
|
if b.offset > 0))
|
|
|
|
net_injection[b.name, violation.time] *
|
|
|
|
|
|
|
|
isf[violation.monitored_line.offset, b.offset] for
|
|
|
|
|
|
|
|
b in instance.buses if b.offset > 0
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
@constraint(model, flow == sum(net_injection[b.name, violation.time] * (
|
|
|
|
@constraint(
|
|
|
|
isf[violation.monitored_line.offset, b.offset] + (
|
|
|
|
model,
|
|
|
|
lodf[violation.monitored_line.offset, violation.outage_line.offset] *
|
|
|
|
flow == sum(
|
|
|
|
isf[violation.outage_line.offset, b.offset]
|
|
|
|
net_injection[b.name, violation.time] * (
|
|
|
|
)
|
|
|
|
isf[violation.monitored_line.offset, b.offset] + (
|
|
|
|
)
|
|
|
|
lodf[
|
|
|
|
for b in instance.buses
|
|
|
|
violation.monitored_line.offset,
|
|
|
|
if b.offset > 0))
|
|
|
|
violation.outage_line.offset,
|
|
|
|
end
|
|
|
|
] * isf[violation.outage_line.offset, b.offset]
|
|
|
|
nothing
|
|
|
|
)
|
|
|
|
|
|
|
|
) for b in instance.buses if b.offset > 0
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return nothing
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _set_names!(model::JuMP.Model)
|
|
|
|
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
|
|
|
@ -505,7 +546,6 @@ function _set_names!(model::JuMP.Model)
|
|
|
|
@info @sprintf("Set names in %.2f seconds", time_varnames)
|
|
|
|
@info @sprintf("Set names in %.2f seconds", time_varnames)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _set_names!(dict::Dict)
|
|
|
|
function _set_names!(dict::Dict)
|
|
|
|
for name in keys(dict)
|
|
|
|
for name in keys(dict)
|
|
|
|
dict[name] isa AbstractDict || continue
|
|
|
|
dict[name] isa AbstractDict || continue
|
|
|
@ -519,72 +559,75 @@ function _set_names!(dict::Dict)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function solution(model::JuMP.Model)
|
|
|
|
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(
|
|
|
|
return OrderedDict(
|
|
|
|
b.name => [round(value(vars[b.name, t]), digits=5) for t in 1:T]
|
|
|
|
b.name => [round(value(vars[b.name, t]), digits = 5) for t in 1:T]
|
|
|
|
for b in collection
|
|
|
|
for b in collection
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
function production_cost(g)
|
|
|
|
function production_cost(g)
|
|
|
|
return [
|
|
|
|
return [
|
|
|
|
value(model[:is_on][g.name, t]) * g.min_power_cost[t] +
|
|
|
|
value(model[:is_on][g.name, t]) * g.min_power_cost[t] + sum(
|
|
|
|
sum(
|
|
|
|
|
|
|
|
Float64[
|
|
|
|
Float64[
|
|
|
|
value(model[:segprod][g.name, t, k]) * g.cost_segments[k].cost[t]
|
|
|
|
value(model[:segprod][g.name, t, k]) *
|
|
|
|
for k in 1:length(g.cost_segments)
|
|
|
|
g.cost_segments[k].cost[t] for
|
|
|
|
]
|
|
|
|
k in 1:length(g.cost_segments)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
for t in 1:T
|
|
|
|
) for t in 1:T
|
|
|
|
]
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
function production(g)
|
|
|
|
function production(g)
|
|
|
|
return [
|
|
|
|
return [
|
|
|
|
value(model[:is_on][g.name, t]) * g.min_power[t] +
|
|
|
|
value(model[:is_on][g.name, t]) * g.min_power[t] + sum(
|
|
|
|
sum(
|
|
|
|
|
|
|
|
Float64[
|
|
|
|
Float64[
|
|
|
|
value(model[:segprod][g.name, t, k])
|
|
|
|
value(model[:segprod][g.name, t, k]) for
|
|
|
|
for k in 1:length(g.cost_segments)
|
|
|
|
k in 1:length(g.cost_segments)
|
|
|
|
]
|
|
|
|
],
|
|
|
|
)
|
|
|
|
) for t in 1:T
|
|
|
|
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[:startup][g.name, t, s])
|
|
|
|
return [
|
|
|
|
for s in 1:S)
|
|
|
|
sum(
|
|
|
|
for t in 1:T]
|
|
|
|
g.startup_categories[s].cost *
|
|
|
|
|
|
|
|
value(model[:startup][g.name, t, s]) for s in 1:S
|
|
|
|
|
|
|
|
) for t in 1:T
|
|
|
|
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
sol = OrderedDict()
|
|
|
|
sol = OrderedDict()
|
|
|
|
sol["Production (MW)"] = OrderedDict(g.name => production(g) for g in instance.units)
|
|
|
|
sol["Production (MW)"] =
|
|
|
|
sol["Production cost (\$)"] = OrderedDict(g.name => production_cost(g) for g in instance.units)
|
|
|
|
OrderedDict(g.name => production(g) for g in instance.units)
|
|
|
|
sol["Startup cost (\$)"] = OrderedDict(g.name => startup_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["Is on"] = timeseries(model[:is_on], instance.units)
|
|
|
|
sol["Is on"] = timeseries(model[:is_on], instance.units)
|
|
|
|
sol["Switch on"] = timeseries(model[:switch_on], instance.units)
|
|
|
|
sol["Switch on"] = timeseries(model[:switch_on], instance.units)
|
|
|
|
sol["Switch off"] = timeseries(model[:switch_off], instance.units)
|
|
|
|
sol["Switch off"] = timeseries(model[:switch_off], instance.units)
|
|
|
|
sol["Reserve (MW)"] = timeseries(model[:reserve], instance.units)
|
|
|
|
sol["Reserve (MW)"] = timeseries(model[:reserve], instance.units)
|
|
|
|
sol["Net injection (MW)"] = timeseries(model[:net_injection], instance.buses)
|
|
|
|
sol["Net injection (MW)"] =
|
|
|
|
|
|
|
|
timeseries(model[:net_injection], instance.buses)
|
|
|
|
sol["Load curtail (MW)"] = timeseries(model[: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[: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[: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 write(filename::AbstractString, solution::AbstractDict)::Nothing
|
|
|
|
function write(filename::AbstractString, solution::AbstractDict)::Nothing
|
|
|
|
open(filename, "w") do file
|
|
|
|
open(filename, "w") do file
|
|
|
|
JSON.print(file, solution, 2)
|
|
|
|
return JSON.print(file, solution, 2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function fix!(model::JuMP.Model, solution::AbstractDict)::Nothing
|
|
|
|
function fix!(model::JuMP.Model, solution::AbstractDict)::Nothing
|
|
|
|
instance, T = model[:instance], model[:instance].time
|
|
|
|
instance, T = model[:instance], model[:instance].time
|
|
|
|
is_on = model[:is_on]
|
|
|
|
is_on = model[:is_on]
|
|
|
@ -593,20 +636,22 @@ function fix!(model::JuMP.Model, solution::AbstractDict)::Nothing
|
|
|
|
for g in instance.units
|
|
|
|
for g in instance.units
|
|
|
|
for t in 1:T
|
|
|
|
for t in 1:T
|
|
|
|
is_on_value = round(solution["Is on"][g.name][t])
|
|
|
|
is_on_value = round(solution["Is on"][g.name][t])
|
|
|
|
production_value = round(solution["Production (MW)"][g.name][t], digits=5)
|
|
|
|
production_value =
|
|
|
|
reserve_value = round(solution["Reserve (MW)"][g.name][t], digits=5)
|
|
|
|
round(solution["Production (MW)"][g.name][t], digits = 5)
|
|
|
|
JuMP.fix(is_on[g.name, t], is_on_value, force=true)
|
|
|
|
reserve_value =
|
|
|
|
|
|
|
|
round(solution["Reserve (MW)"][g.name][t], digits = 5)
|
|
|
|
|
|
|
|
JuMP.fix(is_on[g.name, t], is_on_value, force = true)
|
|
|
|
JuMP.fix(
|
|
|
|
JuMP.fix(
|
|
|
|
prod_above[g.name, t],
|
|
|
|
prod_above[g.name, t],
|
|
|
|
production_value - is_on_value * g.min_power[t],
|
|
|
|
production_value - is_on_value * g.min_power[t],
|
|
|
|
force=true,
|
|
|
|
force = true,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
JuMP.fix(reserve[g.name, t], reserve_value, force=true)
|
|
|
|
JuMP.fix(reserve[g.name, t], reserve_value, force = true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function set_warm_start!(model::JuMP.Model, solution::AbstractDict)::Nothing
|
|
|
|
function set_warm_start!(model::JuMP.Model, solution::AbstractDict)::Nothing
|
|
|
|
instance, T = model[:instance], model[:instance].time
|
|
|
|
instance, T = model[:instance], model[:instance].time
|
|
|
|
is_on = model[:is_on]
|
|
|
|
is_on = model[:is_on]
|
|
|
@ -615,20 +660,25 @@ function set_warm_start!(model::JuMP.Model, solution::AbstractDict)::Nothing
|
|
|
|
for g in instance.units
|
|
|
|
for g in instance.units
|
|
|
|
for t in 1:T
|
|
|
|
for t in 1:T
|
|
|
|
JuMP.set_start_value(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(switch_on[g.name, t], solution["Switch on"][g.name][t])
|
|
|
|
JuMP.set_start_value(
|
|
|
|
JuMP.set_start_value(switch_off[g.name, t], solution["Switch off"][g.name][t])
|
|
|
|
switch_on[g.name, t],
|
|
|
|
|
|
|
|
solution["Switch on"][g.name][t],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
JuMP.set_start_value(
|
|
|
|
|
|
|
|
switch_off[g.name, t],
|
|
|
|
|
|
|
|
solution["Switch off"][g.name][t],
|
|
|
|
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function optimize!(
|
|
|
|
function optimize!(
|
|
|
|
model::JuMP.Model;
|
|
|
|
model::JuMP.Model;
|
|
|
|
time_limit=3600,
|
|
|
|
time_limit = 3600,
|
|
|
|
gap_limit=1e-4,
|
|
|
|
gap_limit = 1e-4,
|
|
|
|
two_phase_gap=true,
|
|
|
|
two_phase_gap = true,
|
|
|
|
)::Nothing
|
|
|
|
)::Nothing
|
|
|
|
|
|
|
|
|
|
|
|
function set_gap(gap)
|
|
|
|
function set_gap(gap)
|
|
|
|
try
|
|
|
|
try
|
|
|
|
JuMP.set_optimizer_attribute(model, "MIPGap", gap)
|
|
|
|
JuMP.set_optimizer_attribute(model, "MIPGap", gap)
|
|
|
@ -637,20 +687,20 @@ function optimize!(
|
|
|
|
@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)
|
|
|
|
large_gap = true
|
|
|
|
large_gap = true
|
|
|
|
else
|
|
|
|
else
|
|
|
|
set_gap(gap_limit)
|
|
|
|
set_gap(gap_limit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
while true
|
|
|
|
while true
|
|
|
|
time_elapsed = time() - initial_time
|
|
|
|
time_elapsed = time() - initial_time
|
|
|
|
time_remaining = time_limit - time_elapsed
|
|
|
|
time_remaining = time_limit - time_elapsed
|
|
|
@ -658,18 +708,21 @@ function optimize!(
|
|
|
|
@info "Time limit exceeded"
|
|
|
|
@info "Time limit exceeded"
|
|
|
|
break
|
|
|
|
break
|
|
|
|
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, time_remaining)
|
|
|
|
JuMP.set_time_limit_sec(model, time_remaining)
|
|
|
|
|
|
|
|
|
|
|
|
@info "Solving MILP..."
|
|
|
|
@info "Solving MILP..."
|
|
|
|
JuMP.optimize!(model)
|
|
|
|
JuMP.optimize!(model)
|
|
|
|
|
|
|
|
|
|
|
|
has_transmission || break
|
|
|
|
has_transmission || break
|
|
|
|
|
|
|
|
|
|
|
|
violations = _find_violations(model)
|
|
|
|
violations = _find_violations(model)
|
|
|
|
if isempty(violations)
|
|
|
|
if isempty(violations)
|
|
|
|
@info "No violations found"
|
|
|
|
@info "No violations found"
|
|
|
|
if large_gap
|
|
|
|
if large_gap
|
|
|
|
large_gap = false
|
|
|
|
large_gap = false
|
|
|
|
set_gap(gap_limit)
|
|
|
|
set_gap(gap_limit)
|
|
|
@ -680,10 +733,9 @@ function optimize!(
|
|
|
|
_enforce_transmission(model, violations)
|
|
|
|
_enforce_transmission(model, violations)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
nothing
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function _find_violations(model::JuMP.Model)
|
|
|
|
function _find_violations(model::JuMP.Model)
|
|
|
|
instance = model[:instance]
|
|
|
|
instance = model[:instance]
|
|
|
@ -695,36 +747,38 @@ function _find_violations(model::JuMP.Model)
|
|
|
|
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_injection_values = [
|
|
|
|
net_injection_values = [
|
|
|
|
value(net_injection[b.name, t])
|
|
|
|
value(net_injection[b.name, t]) for b in non_slack_buses,
|
|
|
|
for b in non_slack_buses, t in 1:instance.time
|
|
|
|
t in 1:instance.time
|
|
|
|
]
|
|
|
|
]
|
|
|
|
overflow_values = [
|
|
|
|
overflow_values = [
|
|
|
|
value(overflow[lm.name, t])
|
|
|
|
value(overflow[lm.name, t]) for lm in instance.lines,
|
|
|
|
for lm in instance.lines, t in 1:instance.time
|
|
|
|
t in 1:instance.time
|
|
|
|
]
|
|
|
|
]
|
|
|
|
violations = UnitCommitment._find_violations(
|
|
|
|
violations = UnitCommitment._find_violations(
|
|
|
|
instance=instance,
|
|
|
|
instance = instance,
|
|
|
|
net_injections=net_injection_values,
|
|
|
|
net_injections = net_injection_values,
|
|
|
|
overflow=overflow_values,
|
|
|
|
overflow = overflow_values,
|
|
|
|
isf=model[:isf],
|
|
|
|
isf = model[:isf],
|
|
|
|
lodf=model[:lodf],
|
|
|
|
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(
|
|
|
|
function _enforce_transmission(
|
|
|
|
model::JuMP.Model,
|
|
|
|
model::JuMP.Model,
|
|
|
|
violations::Vector{Violation},
|
|
|
|
violations::Vector{Violation},
|
|
|
|
)::Nothing
|
|
|
|
)::Nothing
|
|
|
|
for v in violations
|
|
|
|
for v in violations
|
|
|
|
_enforce_transmission(
|
|
|
|
_enforce_transmission(
|
|
|
|
model=model,
|
|
|
|
model = model,
|
|
|
|
violation=v,
|
|
|
|
violation = v,
|
|
|
|
isf=model[:isf],
|
|
|
|
isf = model[:isf],
|
|
|
|
lodf=model[:lodf],
|
|
|
|
lodf = model[:lodf],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return
|
|
|
|
return
|
|
|
|