Skip to content

Commit

Permalink
Fix support for MOI.TimeLimitSec (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Aug 17, 2023
1 parent 57041ce commit 4bfc9f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,9 @@ function MOI.set(
end

function MOI.get(model::Optimizer, ::MOI.TimeLimitSec)
value = MOI.get(model, MOI.RawOptimizerAttribute("tm_lim"))
# convert internal ms to sec
return MOI.get(model, MOI.RawOptimizerAttribute("tm_lim")) / 1_000
return value == typemax(Int32) ? nothing : value / 1_000
end

MOI.supports_incremental_interface(::Optimizer) = true
Expand Down
15 changes: 14 additions & 1 deletion test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ end
function test_large_time_limits()
model = GLPK.Optimizer()
MOI.set(model, MOI.TimeLimitSec(), 1e9)
@test MOI.get(model, MOI.TimeLimitSec()) == typemax(Cint) / 1_000
@test MOI.get(model, MOI.TimeLimitSec()) == nothing
return
end

Expand Down Expand Up @@ -616,6 +616,19 @@ function test_pr_220()
return
end

function test_attribute_TimeLimitSec()
model = GLPK.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
return
end

end # module

TestMOIWrapper.runtests()

0 comments on commit 4bfc9f2

Please sign in to comment.