From 71aeb53d7b02f1a71eb0ce7696f087726e390c39 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Wed, 6 Sep 2023 03:50:13 +1200 Subject: [PATCH] Fix support for MOI.TimeLimitSec (#140) --- src/Interfaces/MOI/attributes.jl | 9 ++++++--- test/Interfaces/MOI_wrapper.jl | 12 ++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Interfaces/MOI/attributes.jl b/src/Interfaces/MOI/attributes.jl index bd50f67..6a03747 100644 --- a/src/Interfaces/MOI/attributes.jl +++ b/src/Interfaces/MOI/attributes.jl @@ -58,10 +58,13 @@ end # # TimeLimitSec # -MOI.get(m::Optimizer, ::MOI.TimeLimitSec) = m.inner.params.IPM.TimeLimit +function MOI.get(m::Optimizer, ::MOI.TimeLimitSec) + value = m.inner.params.IPM.TimeLimit + return value == Inf ? nothing : value +end -function MOI.set(m::Optimizer, ::MOI.TimeLimitSec, t) - m.inner.params.IPM.TimeLimit = t +function MOI.set(m::Optimizer, ::MOI.TimeLimitSec, t::Union{Real,Nothing}) + m.inner.params.IPM.TimeLimit = convert(Float64, something(t, Inf)) return nothing end diff --git a/test/Interfaces/MOI_wrapper.jl b/test/Interfaces/MOI_wrapper.jl index 17154b4..6e0e91e 100644 --- a/test/Interfaces/MOI_wrapper.jl +++ b/test/Interfaces/MOI_wrapper.jl @@ -110,3 +110,15 @@ MOIU.@model(ModelData, "test_unbounded", ]) end + +@testset "test_attribute_TimeLimitSec" begin + model = Tulip.Optimizer() + @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 MOI.get(model, MOI.TimeLimitSec()) === nothing + MOI.set(model, MOI.TimeLimitSec(), 1.0) + @test MOI.get(model, MOI.TimeLimitSec()) == 1.0 +end