Skip to content

Commit

Permalink
Fix support for MOI.TimeLimitSec (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
hlyang1992 authored Dec 3, 2023
1 parent 36f8d85 commit 844b960
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/MOI/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,21 @@ function MOI.get(model::Optimizer, param::MOI.RawOptimizerAttribute)
return
end

function MOI.set(model::Optimizer, ::MOI.TimeLimitSec, limit::Real)
MOI.set(model, MOI.RawOptimizerAttribute("CPXPARAM_TimeLimit"), limit)
const _TIME_LIMIT_DEFAULT = 1.0e75

function MOI.set(
model::Optimizer,
::MOI.TimeLimitSec,
limit::Union{Nothing,Real},
)
new_limit = something(limit, _TIME_LIMIT_DEFAULT)
MOI.set(model, MOI.RawOptimizerAttribute("CPXPARAM_TimeLimit"), new_limit)
return
end

function MOI.get(model::Optimizer, ::MOI.TimeLimitSec)
return MOI.get(model, MOI.RawOptimizerAttribute("CPXPARAM_TimeLimit"))
limit = MOI.get(model, MOI.RawOptimizerAttribute("CPXPARAM_TimeLimit"))
return limit === _TIME_LIMIT_DEFAULT ? nothing : limit
end

MOI.supports_incremental_interface(::Optimizer) = true
Expand Down

0 comments on commit 844b960

Please sign in to comment.