Skip to content

Commit

Permalink
Fix support for MOI.TimeLimitSec (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Aug 17, 2023
1 parent 0160bd3 commit c002fd8
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.jl
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,8 @@ function MOI.set(model::Optimizer, ::MOI.TimeLimitSec, limit::Real)
end

function MOI.get(model::Optimizer, ::MOI.TimeLimitSec)
return MOI.get(model, MOI.RawOptimizerAttribute("time_limit"))
value = MOI.get(model, MOI.RawOptimizerAttribute("time_limit"))
return value == Inf ? nothing : value
end

###
Expand Down
15 changes: 14 additions & 1 deletion test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ end
function test_attributes()
model = HiGHS.Optimizer()
@test MOI.get(model, MOI.SolverName()) == "HiGHS"
@test MOI.get(model, MOI.TimeLimitSec()) > 10000
@test MOI.get(model, MOI.TimeLimitSec()) === nothing
MOI.set(model, MOI.TimeLimitSec(), 500)
@test MOI.get(model, MOI.TimeLimitSec()) == 500.0
@test MOI.get(model, MOI.RawSolver()) == model
Expand Down Expand Up @@ -424,6 +424,19 @@ function test_dual_issue_157()
return
end

function test_attribute_TimeLimitSec()
model = HiGHS.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

TestMOIHighs.runtests()

0 comments on commit c002fd8

Please sign in to comment.