Rename formulation structs

bugfix/formulations
Alinson S. Xavier 4 years ago
parent 7db8d723f7
commit 67cef8b5cd

@ -10,7 +10,7 @@ include("model/formulations/base/structs.jl")
include("model/formulations/ArrCon00/structs.jl") include("model/formulations/ArrCon00/structs.jl")
include("model/formulations/DamKucRajAta16/structs.jl") include("model/formulations/DamKucRajAta16/structs.jl")
include("model/formulations/MorLatRam13/structs.jl") include("model/formulations/MorLatRam13/structs.jl")
include("solution/methods/XaQiWaTh19/structs.jl") include("solution/methods/XavQiuWanThi19/structs.jl")
include("import/egret.jl") include("import/egret.jl")
include("instance/read.jl") include("instance/read.jl")
@ -26,10 +26,10 @@ include("model/formulations/DamKucRajAta16/ramp.jl")
include("model/formulations/MorLatRam13/ramp.jl") include("model/formulations/MorLatRam13/ramp.jl")
include("model/jumpext.jl") include("model/jumpext.jl")
include("solution/fix.jl") include("solution/fix.jl")
include("solution/methods/XaQiWaTh19/enforce.jl") include("solution/methods/XavQiuWanThi19/enforce.jl")
include("solution/methods/XaQiWaTh19/filter.jl") include("solution/methods/XavQiuWanThi19/filter.jl")
include("solution/methods/XaQiWaTh19/find.jl") include("solution/methods/XavQiuWanThi19/find.jl")
include("solution/methods/XaQiWaTh19/optimize.jl") include("solution/methods/XavQiuWanThi19/optimize.jl")
include("solution/optimize.jl") include("solution/optimize.jl")
include("solution/solution.jl") include("solution/solution.jl")
include("solution/warmstart.jl") include("solution/warmstart.jl")

@ -33,8 +33,7 @@ function build_model(;
)::JuMP.Model )::JuMP.Model
return _build_model( return _build_model(
instance, instance,
_GeneratorFormulation(), Formulation(),
_ShiftFactorsFormulation(),
optimizer = optimizer, optimizer = optimizer,
variable_names = variable_names, variable_names = variable_names,
) )
@ -42,8 +41,7 @@ end
function _build_model( function _build_model(
instance::UnitCommitmentInstance, instance::UnitCommitmentInstance,
fg::_GeneratorFormulation, formulation::Formulation;
ft::_TransmissionFormulation;
optimizer = nothing, optimizer = nothing,
variable_names::Bool = false, variable_names::Bool = false,
)::JuMP.Model )::JuMP.Model
@ -55,15 +53,15 @@ function _build_model(
end end
model[:obj] = AffExpr() model[:obj] = AffExpr()
model[:instance] = instance model[:instance] = instance
_setup_transmission(model, ft) _setup_transmission(model, formulation.transmission)
for l in instance.lines for l in instance.lines
_add_transmission_line!(model, l, ft) _add_transmission_line!(model, l, formulation.transmission)
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, fg) _add_unit!(model, g, formulation)
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)

@ -5,7 +5,7 @@
function _add_ramp_eqs!( function _add_ramp_eqs!(
model::JuMP.Model, model::JuMP.Model,
g::Unit, g::Unit,
formulation::_ArrCon00, formulation::ArrCon00,
)::Nothing )::Nothing
# TODO: Move upper case constants to model[:instance] # TODO: Move upper case constants to model[:instance]
RESERVES_WHEN_START_UP = true RESERVES_WHEN_START_UP = true

@ -9,4 +9,4 @@ Formulation described in:
to an electricity spot market. IEEE Transactions on power systems, 15(3), to an electricity spot market. IEEE Transactions on power systems, 15(3),
1098-1104. 1098-1104.
""" """
mutable struct _ArrCon00 <: _RampingFormulation end struct ArrCon00 <: RampingFormulation end

@ -5,7 +5,7 @@
function _add_ramp_eqs!( function _add_ramp_eqs!(
model::JuMP.Model, model::JuMP.Model,
g::Unit, g::Unit,
formulation::_DamKucRajAta16, formulation::DamKucRajAta16,
)::Nothing )::Nothing
# TODO: Move upper case constants to model[:instance] # TODO: Move upper case constants to model[:instance]
RESERVES_WHEN_START_UP = true RESERVES_WHEN_START_UP = true
@ -31,15 +31,15 @@ function _add_ramp_eqs!(
time_invariant = time_invariant =
(t > 1) ? (abs(g.min_power[t] - g.min_power[t-1]) < 1e-7) : true (t > 1) ? (abs(g.min_power[t] - g.min_power[t-1]) < 1e-7) : true
if t > 1 && !time_invariant # if t > 1 && !time_invariant
warning( # @warn(
"Ramping according to Damcı-Kurt et al. (2016) requires " * # "Ramping according to Damcı-Kurt et al. (2016) requires " *
"time-invariant minimum power. This does not hold for " * # "time-invariant minimum power. This does not hold for " *
"generator $(gn): min_power[$t] = $(g.min_power[t]); " * # "generator $(gn): min_power[$t] = $(g.min_power[t]); " *
"min_power[$(t-1)] = $(g.min_power[t-1]). Reverting to " * # "min_power[$(t-1)] = $(g.min_power[t-1]). Reverting to " *
"Arroyo and Conejo (2000) formulation for this generator.", # "Arroyo and Conejo (2000) formulation for this generator.",
) # )
end # end
max_prod_this_period = max_prod_this_period =
prod_above[gn, t] + ( prod_above[gn, t] + (

@ -8,4 +8,4 @@ Formulation described in:
Damcı-Kurt, P., Küçükyavuz, S., Rajan, D., & Atamtürk, A. (2016). A polyhedral Damcı-Kurt, P., Küçükyavuz, S., Rajan, D., & Atamtürk, A. (2016). A polyhedral
study of production ramping. Mathematical Programming, 158(1), 175-205. study of production ramping. Mathematical Programming, 158(1), 175-205.
""" """
mutable struct _DamKucRajAta16 <: _RampingFormulation end struct DamKucRajAta16 <: RampingFormulation end

@ -5,7 +5,7 @@
function _add_ramp_eqs!( function _add_ramp_eqs!(
model::JuMP.Model, model::JuMP.Model,
g::Unit, g::Unit,
formulation::_MorLatRam13, formulation::MorLatRam13,
)::Nothing )::Nothing
# TODO: Move upper case constants to model[:instance] # TODO: Move upper case constants to model[:instance]
RESERVES_WHEN_START_UP = true RESERVES_WHEN_START_UP = true

@ -9,4 +9,4 @@ Formulation described in:
MILP formulation for the thermal unit commitment problem. IEEE Transactions MILP formulation for the thermal unit commitment problem. IEEE Transactions
on Power Systems, 28(4), 4897-4908. on Power Systems, 28(4), 4897-4908.
""" """
mutable struct _MorLatRam13 <: _RampingFormulation end struct MorLatRam13 <: RampingFormulation end

@ -5,7 +5,7 @@
function _add_transmission_line!( function _add_transmission_line!(
model::JuMP.Model, model::JuMP.Model,
lm::TransmissionLine, lm::TransmissionLine,
f::_TransmissionFormulation, f::ShiftFactorsFormulation,
)::Nothing )::Nothing
overflow = _init(model, :overflow) overflow = _init(model, :overflow)
for t in 1:model[:instance].time for t in 1:model[:instance].time
@ -21,7 +21,7 @@ end
function _setup_transmission( function _setup_transmission(
model::JuMP.Model, model::JuMP.Model,
formulation::_TransmissionFormulation, formulation::ShiftFactorsFormulation,
)::Nothing )::Nothing
instance = model[:instance] instance = model[:instance]
isf = formulation.precomputed_isf isf = formulation.precomputed_isf

@ -2,21 +2,23 @@
# 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.
abstract type _RampingFormulation end abstract type TransmissionFormulation end
abstract type _TransmissionFormulation end abstract type RampingFormulation end
struct _GeneratorFormulation struct Formulation
ramping::_RampingFormulation ramping::RampingFormulation
transmission::TransmissionFormulation
function _GeneratorFormulation( function Formulation(;
ramping::_RampingFormulation = _MorLatRam13(), ramping::RampingFormulation = MorLatRam13(),
transmission::TransmissionFormulation = ShiftFactorsFormulation(),
) )
return new(ramping) return new(ramping, transmission)
end end
end end
""" """
mutable struct _ShiftFactorsFormulation <: _TransmissionFormulation struct ShiftFactorsFormulation <: TransmissionFormulation
isf_cutoff::Float64 isf_cutoff::Float64
lodf_cutoff::Float64 lodf_cutoff::Float64
precomputed_isf::Union{Nothing,Matrix{Float64}} precomputed_isf::Union{Nothing,Matrix{Float64}}
@ -40,13 +42,13 @@ Arguments
the cutoff that should be applied to the LODF matrix. Entries with magnitude the cutoff that should be applied to the LODF matrix. Entries with magnitude
smaller than this value will be set to zero. smaller than this value will be set to zero.
""" """
mutable struct _ShiftFactorsFormulation <: _TransmissionFormulation struct ShiftFactorsFormulation <: TransmissionFormulation
isf_cutoff::Float64 isf_cutoff::Float64
lodf_cutoff::Float64 lodf_cutoff::Float64
precomputed_isf::Union{Nothing,Matrix{Float64}} precomputed_isf::Union{Nothing,Matrix{Float64}}
precomputed_lodf::Union{Nothing,Matrix{Float64}} precomputed_lodf::Union{Nothing,Matrix{Float64}}
function _ShiftFactorsFormulation(; function ShiftFactorsFormulation(;
isf_cutoff = 0.005, isf_cutoff = 0.005,
lodf_cutoff = 0.001, lodf_cutoff = 0.001,
precomputed_isf = nothing, precomputed_isf = nothing,

@ -2,7 +2,7 @@
# 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.
function _add_unit!(model::JuMP.Model, g::Unit, f::_GeneratorFormulation) function _add_unit!(model::JuMP.Model, g::Unit, f::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")
end end
@ -32,7 +32,7 @@ _is_initially_on(g::Unit)::Float64 = (g.initial_status > 0 ? 1.0 : 0.0)
function _add_production_vars!( function _add_production_vars!(
model::JuMP.Model, model::JuMP.Model,
g::Unit, g::Unit,
formulation::_GeneratorFormulation, formulation::Formulation,
)::Nothing )::Nothing
prod_above = _init(model, :prod_above) prod_above = _init(model, :prod_above)
segprod = _init(model, :segprod) segprod = _init(model, :segprod)
@ -48,7 +48,7 @@ end
function _add_production_eqs!( function _add_production_eqs!(
model::JuMP.Model, model::JuMP.Model,
g::Unit, g::Unit,
formulation::_GeneratorFormulation, formulation::Formulation,
)::Nothing )::Nothing
eq_prod_above_def = _init(model, :eq_prod_above_def) eq_prod_above_def = _init(model, :eq_prod_above_def)
eq_prod_limit = _init(model, :eq_prod_limit) eq_prod_limit = _init(model, :eq_prod_limit)
@ -94,7 +94,7 @@ end
function _add_reserve_vars!( function _add_reserve_vars!(
model::JuMP.Model, model::JuMP.Model,
g::Unit, g::Unit,
formulation::_GeneratorFormulation, formulation::Formulation,
)::Nothing )::Nothing
reserve = _init(model, :reserve) reserve = _init(model, :reserve)
for t in 1:model[:instance].time for t in 1:model[:instance].time
@ -110,7 +110,7 @@ end
function _add_reserve_eqs!( function _add_reserve_eqs!(
model::JuMP.Model, model::JuMP.Model,
g::Unit, g::Unit,
formulation::_GeneratorFormulation, formulation::Formulation,
)::Nothing )::Nothing
reserve = model[:reserve] reserve = model[:reserve]
for t in 1:model[:instance].time for t in 1:model[:instance].time
@ -122,7 +122,7 @@ end
function _add_startup_shutdown_vars!( function _add_startup_shutdown_vars!(
model::JuMP.Model, model::JuMP.Model,
g::Unit, g::Unit,
formulation::_GeneratorFormulation, formulation::Formulation,
)::Nothing )::Nothing
startup = _init(model, :startup) startup = _init(model, :startup)
for t in 1:model[:instance].time for t in 1:model[:instance].time
@ -136,7 +136,7 @@ end
function _add_startup_shutdown_limit_eqs!( function _add_startup_shutdown_limit_eqs!(
model::JuMP.Model, model::JuMP.Model,
g::Unit, g::Unit,
formulation::_GeneratorFormulation, formulation::Formulation,
)::Nothing )::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)
@ -175,7 +175,7 @@ end
function _add_startup_shutdown_costs_eqs!( function _add_startup_shutdown_costs_eqs!(
model::JuMP.Model, model::JuMP.Model,
g::Unit, g::Unit,
formulation::_GeneratorFormulation, formulation::Formulation,
)::Nothing )::Nothing
eq_startup_choose = _init(model, :eq_startup_choose) eq_startup_choose = _init(model, :eq_startup_choose)
eq_startup_restrict = _init(model, :eq_startup_restrict) eq_startup_restrict = _init(model, :eq_startup_restrict)
@ -222,7 +222,7 @@ end
function _add_status_vars!( function _add_status_vars!(
model::JuMP.Model, model::JuMP.Model,
g::Unit, g::Unit,
formulation::_GeneratorFormulation, formulation::Formulation,
)::Nothing )::Nothing
is_on = _init(model, :is_on) is_on = _init(model, :is_on)
switch_on = _init(model, :switch_on) switch_on = _init(model, :switch_on)
@ -244,7 +244,7 @@ end
function _add_status_eqs!( function _add_status_eqs!(
model::JuMP.Model, model::JuMP.Model,
g::Unit, g::Unit,
formulation::_GeneratorFormulation, formulation::Formulation,
)::Nothing )::Nothing
eq_binary_link = _init(model, :eq_binary_link) eq_binary_link = _init(model, :eq_binary_link)
eq_switch_on_off = _init(model, :eq_switch_on_off) eq_switch_on_off = _init(model, :eq_switch_on_off)
@ -280,7 +280,7 @@ end
function _add_ramp_eqs!( function _add_ramp_eqs!(
model::JuMP.Model, model::JuMP.Model,
g::Unit, g::Unit,
formulation::_GeneratorFormulation, formulation::RampingFormulation,
)::Nothing )::Nothing
prod_above = model[:prod_above] prod_above = model[:prod_above]
reserve = model[:reserve] reserve = model[:reserve]
@ -326,7 +326,7 @@ end
function _add_min_uptime_downtime_eqs!( function _add_min_uptime_downtime_eqs!(
model::JuMP.Model, model::JuMP.Model,
g::Unit, g::Unit,
formulation::_GeneratorFormulation, formulation::Formulation,
)::Nothing )::Nothing
is_on = model[:is_on] is_on = model[:is_on]
switch_off = model[:switch_off] switch_off = model[:switch_off]
@ -373,7 +373,7 @@ end
function _add_net_injection_eqs!( function _add_net_injection_eqs!(
model::JuMP.Model, model::JuMP.Model,
g::Unit, g::Unit,
formulation::_GeneratorFormulation, formulation::Formulation,
)::Nothing )::Nothing
expr_net_injection = model[:expr_net_injection] expr_net_injection = model[:expr_net_injection]
for t in 1:model[:instance].time for t in 1:model[:instance].time

@ -2,17 +2,7 @@
# 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.
""" function optimize!(model::JuMP.Model, method::XavQiuWanThi19)::Nothing
optimize!(model::JuMP.Model, method::_XaQiWaTh19)::Nothing
Solve the given unit commitment model, enforcing transmission and N-1
security constraints lazily, according to the algorithm described in:
Xavier, A. S., Qiu, F., Wang, F., & Thimmapuram, P. R. (2019). Transmission
constraint filtering in large-scale security-constrained unit commitment.
IEEE Transactions on Power Systems, 34(3), 2457-2460.
"""
function optimize!(model::JuMP.Model, method::_XaQiWaTh19)::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)
@ -21,7 +11,6 @@ function optimize!(model::JuMP.Model, method::_XaQiWaTh19)::Nothing
@warn "Could not change MIP gap tolerance" @warn "Could not change MIP gap tolerance"
end end
end end
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)

@ -5,7 +5,7 @@
import DataStructures: PriorityQueue import DataStructures: PriorityQueue
""" """
struct _XaQiWaTh19 <: SolutionMethod struct XavQiuWanThi19 <: SolutionMethod
time_limit::Float64 time_limit::Float64
gap_limit::Float64 gap_limit::Float64
two_phase_gap::Bool two_phase_gap::Bool
@ -19,7 +19,8 @@ Lazy constraint solution method described in:
constraint filtering in large-scale security-constrained unit commitment. constraint filtering in large-scale security-constrained unit commitment.
IEEE Transactions on Power Systems, 34(3), 2457-2460. IEEE Transactions on Power Systems, 34(3), 2457-2460.
## Fields Fields
------
- `time_limit`: - `time_limit`:
the time limit over the entire optimization procedure. the time limit over the entire optimization procedure.
@ -36,14 +37,14 @@ Lazy constraint solution method described in:
formulation per time period. formulation per time period.
""" """
struct _XaQiWaTh19 struct XavQiuWanThi19
time_limit::Float64 time_limit::Float64
gap_limit::Float64 gap_limit::Float64
two_phase_gap::Bool two_phase_gap::Bool
max_violations_per_line::Int max_violations_per_line::Int
max_violations_per_period::Int max_violations_per_period::Int
function _XaQiWaTh19(; function XavQiuWanThi19(;
time_limit::Float64 = 86400.0, time_limit::Float64 = 86400.0,
gap_limit::Float64 = 1e-3, gap_limit::Float64 = 1e-3,
two_phase_gap::Bool = true, two_phase_gap::Bool = true,

@ -10,5 +10,5 @@ advanced methods to accelerate the solution process and to enforce transmission
and N-1 security constraints. and N-1 security constraints.
""" """
function optimize!(model::JuMP.Model)::Nothing function optimize!(model::JuMP.Model)::Nothing
return UnitCommitment.optimize!(model, _XaQiWaTh19()) return UnitCommitment.optimize!(model, XavQiuWanThi19())
end end

@ -49,6 +49,9 @@ function handle_message(
if level >= logger.screen_log_level if level >= logger.screen_log_level
printstyled(time_string, color = color) printstyled(time_string, color = color)
println(message) println(message)
flush(stdout)
flush(stderr)
Base.Libc.flush_cstdio()
end end
if logger.file !== nothing && level >= logger.io_log_level if logger.file !== nothing && level >= logger.io_log_level
write(logger.file, time_string) write(logger.file, time_string)

Loading…
Cancel
Save