Skip to content

Commit

Permalink
Fix support for MOI.TimeLimitSec (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Sep 5, 2023
1 parent 069cdda commit 71aeb53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Interfaces/MOI/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions test/Interfaces/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 71aeb53

Please sign in to comment.