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 params to use id and type instead of string #297

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 14 additions & 7 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,21 @@ function MOI.set(model::Optimizer, attr::MOI.RawOptimizerAttribute, value)
@_checked KN_load_tuner_file(model.inner, value)
elseif attr.name == "free"
@_checked KN_free(model.inner)
elseif !MOI.supports(model, attr)
end
pId = Ref{Cint}(0)
ret = KN_get_param_id(model.inner, attr.name, pId)
if ret == KN_RC_BAD_PARAMINPUT || pId[] <= 0
throw(MOI.UnsupportedAttribute(attr))
elseif value isa Integer
@_checked KN_set_int_param_by_name(model.inner, attr.name, value)
elseif value isa Cdouble
@_checked KN_set_double_param_by_name(model.inner, attr.name, value)
elseif value isa AbstractString
@_checked KN_set_char_param_by_name(model.inner, attr.name, value)
end
pType = Ref{Cint}()
@_checked KN_get_param_type(model.inner, pId[], pType)
if pType[] == KN_PARAMTYPE_INTEGER
@_checked KN_set_int_param(model.inner, pId[], value)
elseif pType[] == KN_PARAMTYPE_FLOAT
@_checked KN_set_double_param(model.inner, pId[], value)
else
@assert pType[] == KN_PARAMTYPE_STRING
@_checked KN_set_char_param(model.inner, pId[], value)
end
model.options[attr.name] = value
return
Expand Down
11 changes: 11 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ function test_get_nlp_block()
return
end

function test_maxtime_cpu()
model = KNITRO.Optimizer()
attr = MOI.RawOptimizerAttribute("mip_maxtimecpu")
@test MOI.supports(model, attr)
MOI.set(model, attr, 30)
p = Ref{Cdouble}(0.0)
KNITRO.KN_get_double_param(model.inner, KNITRO.KN_PARAM_MIP_MAXTIMECPU, p)
@test p == 30.0
odow marked this conversation as resolved.
Show resolved Hide resolved
return
end

end

TestMOIWrapper.runtests()
Loading