Skip to content

Commit

Permalink
Fix support for MOI.TimeLimitSec (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Aug 17, 2023
1 parent f507fb1 commit 1238563
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,9 @@ function MOI.set(optimizer::Optimizer, ::MOI.TimeLimitSec, ::Nothing)
return
end

function MOI.get(optimizer::Optimizer, attr::MOI.TimeLimitSec)
if !haskey(optimizer.options, :time_limit_secs)
throw(MOI.GetAttributeNotAllowed(attr))
end
return optimizer.options[:time_limit_secs]
function MOI.get(optimizer::Optimizer, ::MOI.TimeLimitSec)
value = get(optimizer.options, :time_limit_secs, nothing)
return value::Union{Float64,Nothing}
end

###
Expand Down
13 changes: 8 additions & 5 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,16 @@ function test_redirect_stdout()
return
end

function test_time_limit()
function test_attribute_TimeLimitSec()
model = SCS.Optimizer()
@test_throws MOI.GetAttributeNotAllowed MOI.get(model, MOI.TimeLimitSec())
MOI.set(model, MOI.TimeLimitSec(), 1)
@test MOI.get(model, MOI.TimeLimitSec()) === 1.0
@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_throws MOI.GetAttributeNotAllowed MOI.get(model, MOI.TimeLimitSec())
@test MOI.get(model, MOI.TimeLimitSec()) === nothing
MOI.set(model, MOI.TimeLimitSec(), 1.0)
@test MOI.get(model, MOI.TimeLimitSec()) == 1.0
return
end

Expand Down

0 comments on commit 1238563

Please sign in to comment.