Make tests completely silent; remove set_gap warnings on Cbc

update-deps
Alinson S. Xavier 3 years ago
parent cda1e368fe
commit 16b0fec6cd

@ -3,13 +3,12 @@
# 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::XavQiuWanThi2019.Method)::Nothing function optimize!(model::JuMP.Model, method::XavQiuWanThi2019.Method)::Nothing
if !occursin("Gurobi", JuMP.solver_name(model))
method.two_phase_gap = false
end
function set_gap(gap) function set_gap(gap)
try JuMP.set_optimizer_attribute(model, "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
@warn "Could not change MIP gap tolerance"
end
end end
initial_time = time() initial_time = time()
large_gap = false large_gap = false
@ -17,8 +16,6 @@ function optimize!(model::JuMP.Model, method::XavQiuWanThi2019.Method)::Nothing
if has_transmission && method.two_phase_gap if has_transmission && method.two_phase_gap
set_gap(1e-2) set_gap(1e-2)
large_gap = true large_gap = true
else
set_gap(method.gap_limit)
end end
while true while true
time_elapsed = time() - initial_time time_elapsed = time() - initial_time

@ -13,7 +13,7 @@ Lazy constraint solution method described in:
module XavQiuWanThi2019 module XavQiuWanThi2019
import ..SolutionMethod import ..SolutionMethod
""" """
struct Method mutable struct Method
time_limit::Float64 time_limit::Float64
gap_limit::Float64 gap_limit::Float64
two_phase_gap::Bool two_phase_gap::Bool
@ -27,7 +27,7 @@ Fields
- `time_limit`: - `time_limit`:
the time limit over the entire optimization procedure. the time limit over the entire optimization procedure.
- `gap_limit`: - `gap_limit`:
the desired relative optimality gap. the desired relative optimality gap. Only used when `two_phase_gap=true`.
- `two_phase_gap`: - `two_phase_gap`:
if true, solve the problem with large gap tolerance first, then reduce if true, solve the problem with large gap tolerance first, then reduce
the gap tolerance when no further violated constraints are found. the gap tolerance when no further violated constraints are found.
@ -39,7 +39,7 @@ Fields
formulation per time period. formulation per time period.
""" """
struct Method <: SolutionMethod mutable struct Method <: SolutionMethod
time_limit::Float64 time_limit::Float64
gap_limit::Float64 gap_limit::Float64
two_phase_gap::Bool two_phase_gap::Bool

@ -5,20 +5,11 @@
import Logging: min_enabled_level, shouldlog, handle_message import Logging: min_enabled_level, shouldlog, handle_message
using Base.CoreLogging, Logging, Printf using Base.CoreLogging, Logging, Printf
struct TimeLogger <: AbstractLogger Base.@kwdef struct TimeLogger <: AbstractLogger
initial_time::Float64 initial_time::Float64
file::Union{Nothing,IOStream} file::Union{Nothing,IOStream} = nothing
screen_log_level::Any screen_log_level::Any = CoreLogging.Info
io_log_level::Any io_log_level::Any = CoreLogging.Info
end
function TimeLogger(;
initial_time::Float64,
file::Union{Nothing,IOStream} = nothing,
screen_log_level = CoreLogging.Info,
io_log_level = CoreLogging.Info,
)::TimeLogger
return TimeLogger(initial_time, file, screen_log_level, io_log_level)
end end
min_enabled_level(logger::TimeLogger) = logger.io_log_level min_enabled_level(logger::TimeLogger) = logger.io_log_level
@ -61,7 +52,12 @@ function handle_message(
end end
end end
function _setup_logger() function _setup_logger(; level = CoreLogging.Info)
initial_time = time() initial_time = time()
return global_logger(TimeLogger(initial_time = initial_time)) return global_logger(
TimeLogger(
initial_time = initial_time,
screen_log_level = level,
)
)
end end

@ -72,26 +72,19 @@ function _test(formulation::Formulation)::Nothing
end end
@testset "formulations" begin @testset "formulations" begin
@show "testset formulations"
_test(Formulation()) _test(Formulation())
@show "ArrCon2000 ramping"
_test(Formulation(ramping = ArrCon2000.Ramping())) _test(Formulation(ramping = ArrCon2000.Ramping()))
# _test(Formulation(ramping = DamKucRajAta2016.Ramping())) # _test(Formulation(ramping = DamKucRajAta2016.Ramping()))
@show "MorLatRam2013 ramping"
_test( _test(
Formulation( Formulation(
ramping = MorLatRam2013.Ramping(), ramping = MorLatRam2013.Ramping(),
startup_costs = MorLatRam2013.StartupCosts(), startup_costs = MorLatRam2013.StartupCosts(),
), ),
) )
@show "PanGua2016 ramping"
_test(Formulation(ramping = PanGua2016.Ramping())) _test(Formulation(ramping = PanGua2016.Ramping()))
@show "Gar1962 PwlCosts"
_test(Formulation(pwl_costs = Gar1962.PwlCosts())) _test(Formulation(pwl_costs = Gar1962.PwlCosts()))
@show "CarArr2006 PwlCosts"
_test(Formulation(pwl_costs = CarArr2006.PwlCosts())) _test(Formulation(pwl_costs = CarArr2006.PwlCosts()))
@show "KnuOstWat2018 PwlCosts"
_test(Formulation(pwl_costs = KnuOstWat2018.PwlCosts())) _test(Formulation(pwl_costs = KnuOstWat2018.PwlCosts()))
_small_test( _small_test(
Formulation(ramping = WanHob2016.Ramping()), Formulation(ramping = WanHob2016.Ramping()),

@ -6,12 +6,11 @@ using Test
using UnitCommitment using UnitCommitment
push!(Base.LOAD_PATH, @__DIR__) push!(Base.LOAD_PATH, @__DIR__)
UnitCommitment._setup_logger() UnitCommitment._setup_logger(level = Base.CoreLogging.Error)
const ENABLE_LARGE_TESTS = ("UCJL_LARGE_TESTS" in keys(ENV)) const ENABLE_LARGE_TESTS = ("UCJL_LARGE_TESTS" in keys(ENV))
@testset "UnitCommitment" begin @testset "UnitCommitment" begin
@show "running runtests.jl"
include("usage.jl") include("usage.jl")
@testset "import" begin @testset "import" begin
include("import/egret_test.jl") include("import/egret_test.jl")
@ -28,7 +27,6 @@ const ENABLE_LARGE_TESTS = ("UCJL_LARGE_TESTS" in keys(ENV))
include("solution/methods/XavQiuWanThi19/sensitivity_test.jl") include("solution/methods/XavQiuWanThi19/sensitivity_test.jl")
end end
@testset "transform" begin @testset "transform" begin
@show "beginning transform"
include("transform/initcond_test.jl") include("transform/initcond_test.jl")
include("transform/slice_test.jl") include("transform/slice_test.jl")
@testset "randomize" begin @testset "randomize" begin

@ -5,7 +5,6 @@
using UnitCommitment, LinearAlgebra, Cbc, JuMP, JSON, GZip using UnitCommitment, LinearAlgebra, Cbc, JuMP, JSON, GZip
@testset "slice" begin @testset "slice" begin
@show "beginning slice"
instance = UnitCommitment.read_benchmark("test/case14") instance = UnitCommitment.read_benchmark("test/case14")
modified = UnitCommitment.slice(instance, 1:2) modified = UnitCommitment.slice(instance, 1:2)
@ -36,8 +35,6 @@ using UnitCommitment, LinearAlgebra, Cbc, JuMP, JSON, GZip
@test length(ps.demand) == 2 @test length(ps.demand) == 2
@test length(ps.revenue) == 2 @test length(ps.revenue) == 2
end end
@show "beginning building model under slice"
@show instance.reserves
# Should be able to build model without errors # Should be able to build model without errors
optimizer = optimizer_with_attributes(Cbc.Optimizer, "logLevel" => 0) optimizer = optimizer_with_attributes(Cbc.Optimizer, "logLevel" => 0)
model = UnitCommitment.build_model( model = UnitCommitment.build_model(

Loading…
Cancel
Save