From 1238563ab3ffcf1a3799b7ba153c2ea4a5d3fdbf Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Thu, 17 Aug 2023 15:30:08 +1200 Subject: [PATCH] Fix support for MOI.TimeLimitSec (#282) --- src/MOI_wrapper/MOI_wrapper.jl | 8 +++----- test/MOI_wrapper.jl | 13 ++++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/MOI_wrapper/MOI_wrapper.jl b/src/MOI_wrapper/MOI_wrapper.jl index becb63f..d50d8aa 100644 --- a/src/MOI_wrapper/MOI_wrapper.jl +++ b/src/MOI_wrapper/MOI_wrapper.jl @@ -188,11 +188,9 @@ function MOI.set(optimizer::Optimizer, ::MOI.TimeLimitSec, ::Nothing) return end -function MOI.get(optimizer::Optimizer, attr::MOI.TimeLimitSec) - if !haskey(optimizer.options, :time_limit_secs) - throw(MOI.GetAttributeNotAllowed(attr)) - end - return optimizer.options[:time_limit_secs] +function MOI.get(optimizer::Optimizer, ::MOI.TimeLimitSec) + value = get(optimizer.options, :time_limit_secs, nothing) + return value::Union{Float64,Nothing} end ### diff --git a/test/MOI_wrapper.jl b/test/MOI_wrapper.jl index 429e32f..f77ebd1 100644 --- a/test/MOI_wrapper.jl +++ b/test/MOI_wrapper.jl @@ -249,13 +249,16 @@ function test_redirect_stdout() return end -function test_time_limit() +function test_attribute_TimeLimitSec() model = SCS.Optimizer() - @test_throws MOI.GetAttributeNotAllowed MOI.get(model, MOI.TimeLimitSec()) - MOI.set(model, MOI.TimeLimitSec(), 1) - @test MOI.get(model, MOI.TimeLimitSec()) === 1.0 + @test MOI.supports(model, MOI.TimeLimitSec()) + @test MOI.get(model, MOI.TimeLimitSec()) === nothing + MOI.set(model, MOI.TimeLimitSec(), 0.0) + @test MOI.get(model, MOI.TimeLimitSec()) == 0.0 MOI.set(model, MOI.TimeLimitSec(), nothing) - @test_throws MOI.GetAttributeNotAllowed MOI.get(model, MOI.TimeLimitSec()) + @test MOI.get(model, MOI.TimeLimitSec()) === nothing + MOI.set(model, MOI.TimeLimitSec(), 1.0) + @test MOI.get(model, MOI.TimeLimitSec()) == 1.0 return end