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 support for MOI.TimeLimitSec #518

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Gurobi"
uuid = "2e9cd046-0924-5485-92f1-d5272153d98b"
repo = "https://github.com/jump-dev/Gurobi.jl"
version = "1.0.2"
version = "1.0.3"

[deps]
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
Expand Down
15 changes: 11 additions & 4 deletions src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,8 @@ function MOI.set(model::Optimizer, raw::MOI.RawOptimizerAttribute, value)
@assert param_type == 3
GRBsetstrparam(env, param, value)
end
return _check_ret(env, ret)
_check_ret(env, ret)
return
end

function MOI.get(model::Optimizer, raw::MOI.RawOptimizerAttribute)
Expand Down Expand Up @@ -681,13 +682,19 @@ function MOI.get(model::Optimizer, raw::MOI.RawOptimizerAttribute)
end
end

function MOI.set(model::Optimizer, ::MOI.TimeLimitSec, limit::Real)
MOI.set(model, MOI.RawOptimizerAttribute("TimeLimit"), limit)
function MOI.set(
model::Optimizer,
::MOI.TimeLimitSec,
limit::Union{Real,Nothing},
)
float_limit = convert(Float64, something(limit, GRB_INFINITY))
MOI.set(model, MOI.RawOptimizerAttribute("TimeLimit"), float_limit)
return
end

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

MOI.supports_incremental_interface(::Optimizer) = true
Expand Down
13 changes: 13 additions & 0 deletions test/MOI/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,19 @@ function test_modify_after_delete_objective_plural()
return
end

function test_attribute_TimeLimitSec()
model = Gurobi.Optimizer(GRB_ENV)
@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

TestMOIWrapper.runtests()
Loading