Skip to content

Commit

Permalink
Fix default value for MOI.TimeLimitSec (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Sep 24, 2023
1 parent 6253234 commit 05ae25e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,9 @@ end
function MOI.set(
model::Optimizer,
::MOI.TimeLimitSec,
value::Union{Nothing,Float64},
limit::Union{Nothing,Real},
)
if value === nothing
model.options.time_limit = Inf
else
model.options.time_limit = value
end
model.options.time_limit = convert(Float64, something(limit, Inf))
return
end

Expand Down Expand Up @@ -102,7 +98,9 @@ MOI.get(model::Optimizer, ::MOI.ResultCount) = length(model.inner.solutions)

MOI.get(model::Optimizer, ::MOI.NumberOfThreads) = model.options.processors

MOI.get(model::Optimizer, ::MOI.TimeLimitSec) = model.options.time_limit
function MOI.get(model::Optimizer, ::MOI.TimeLimitSec)
return isinf(model.options.time_limit) ? nothing : model.options.time_limit
end

MOI.get(model::Optimizer, ::MOI.Silent) = model.options.silent

Expand Down
2 changes: 1 addition & 1 deletion test/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
optimizer,
MOI.RawOptimizerAttribute("mip_gap_1"),
)
@test isinf(MOI.get(optimizer, MOI.TimeLimitSec()))
@test MOI.get(optimizer, MOI.TimeLimitSec()) === nothing
MOI.set(optimizer, MOI.TimeLimitSec(), 12.0)
@test MOI.get(optimizer, MOI.TimeLimitSec()) == 12.0
end
Expand Down

0 comments on commit 05ae25e

Please sign in to comment.