From 4bc4462eef6d213c0c45a07f8325d8fec1bf7ac5 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Thu, 4 Apr 2024 09:37:51 +1300 Subject: [PATCH] Fix setting Nothing for MOI.TimeLimitSec (#262) --- src/MOI/MOI_wrapper.jl | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/MOI/MOI_wrapper.jl b/src/MOI/MOI_wrapper.jl index ac3e6e02..c5096f23 100644 --- a/src/MOI/MOI_wrapper.jl +++ b/src/MOI/MOI_wrapper.jl @@ -560,19 +560,18 @@ end MOI.supports(::Optimizer, ::MOI.TimeLimitSec) = true -function MOI.set(model::Optimizer, ::MOI.TimeLimitSec, limit::Real) - # positive values would mean that its stops after `limit` seconds - # iff there is already a MIP solution available. - MOI.set(model, MOI.RawOptimizerAttribute("MAXTIME"), -floor(Int32, limit)) +function MOI.set(model::Optimizer, ::MOI.TimeLimitSec, lim::Union{Real,Nothing}) + # 0 No time limit. + # n > 0 If an integer solution has been found, stop MIP search after n ... + # n < 0 Stop in LP or MIP search after n seconds. + n = -floor(Cint, something(lim, 0.0)) + MOI.set(model, MOI.RawOptimizerAttribute("MAXTIME"), n) return end function MOI.get(model::Optimizer, ::MOI.TimeLimitSec) - # MOI.attribute_value_type(MOI.TimeLimitSec()) = Union{Nothing, Float64} - return convert( - Float64, - -MOI.get(model, MOI.RawOptimizerAttribute("MAXTIME")), - ) + ret = MOI.get(model, MOI.RawOptimizerAttribute("MAXTIME")) + return convert(Float64, -ret) end MOI.supports_incremental_interface(::Optimizer) = true