Skip to content

Commit

Permalink
Fix setting Nothing for MOI.TimeLimitSec (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Apr 3, 2024
1 parent 96fd052 commit 4bc4462
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/MOI/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4bc4462

Please sign in to comment.