Skip to content

Commit

Permalink
Fix support for MOI.TimeLimitSec (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Aug 25, 2023
1 parent 38464c2 commit f3a85f2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
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()

2 comments on commit f3a85f2

@odow
Copy link
Member Author

@odow odow commented on f3a85f2 Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/90309

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.3 -m "<description of version>" f3a85f27548d266cd4e9ae259be2d8655cae7861
git push origin v1.0.3

Please sign in to comment.