Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setting Nothing for MOI.TimeLimitSec #262

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/MOI/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -560,19 +560,18 @@ end

MOI.supports(::Optimizer, ::MOI.TimeLimitSec) = true

function MOI.set(model::Optimizer, ::MOI.TimeLimitSec, limit::Real)
# positive values would mean that its stops after `limit` seconds
# iff there is already a MIP solution available.
MOI.set(model, MOI.RawOptimizerAttribute("MAXTIME"), -floor(Int32, limit))
function MOI.set(model::Optimizer, ::MOI.TimeLimitSec, lim::Union{Real,Nothing})
# 0 No time limit.
# n > 0 If an integer solution has been found, stop MIP search after n ...
# n < 0 Stop in LP or MIP search after n seconds.
n = -floor(Cint, something(lim, 0.0))
MOI.set(model, MOI.RawOptimizerAttribute("MAXTIME"), n)
return
end

function MOI.get(model::Optimizer, ::MOI.TimeLimitSec)
# MOI.attribute_value_type(MOI.TimeLimitSec()) = Union{Nothing, Float64}
return convert(
Float64,
-MOI.get(model, MOI.RawOptimizerAttribute("MAXTIME")),
)
ret = MOI.get(model, MOI.RawOptimizerAttribute("MAXTIME"))
return convert(Float64, -ret)
end

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