Skip to content

Commit 057b2e7

Browse files
authored
Merge pull request #108 from SCIP-Interfaces/tk/parameter-types
Handle parameter types properly.
2 parents d0749c9 + 00856bc commit 057b2e7

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

src/managed_scip.jl

+22-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,28 @@ function free_scip(mscip::ManagedSCIP)
4949
@assert mscip.scip[] == C_NULL
5050
end
5151

52-
"Set generic parameter."
53-
function set_parameter(mscip::ManagedSCIP, name::String, value)
54-
@SC SCIPsetParam(mscip, name, Ptr{Cvoid}(value))
52+
"Set a parameter."
53+
function set_parameter(mscip::ManagedSCIP, name::AbstractString, value)
54+
param = SCIPgetParam(mscip, name)
55+
if param == C_NULL
56+
error("Unrecognized parameter: $name")
57+
end
58+
paramtype = SCIPparamGetType(param)
59+
if paramtype === SCIP_PARAMTYPE_BOOL
60+
@SC SCIPsetBoolParam(mscip, name, value)
61+
elseif paramtype === SCIP_PARAMTYPE_INT
62+
@SC SCIPsetIntParam(mscip, name, value)
63+
elseif paramtype === SCIP_PARAMTYPE_LONGINT
64+
@SC SCIPsetLongintParam(mscip, name, value)
65+
elseif paramtype === SCIP_PARAMTYPE_REAL
66+
@SC SCIPsetRealParam(mscip, name, value)
67+
elseif paramtype === SCIP_PARAMTYPE_CHAR
68+
@SC SCIPsetCharParam(mscip, name, value)
69+
elseif paramtype === SCIP_PARAMTYPE_STRING
70+
@SC SCIPsetStringParam(mscip, name, value)
71+
else
72+
error("Unexpected parameter type: $paramtype")
73+
end
5574
return nothing
5675
end
5776

test/MOI_additional.jl

+24
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,27 @@ end
388388
MOI.set(optimizer, MOI.ObjectiveSense(), MOI.MAX_SENSE)
389389
@test_throws ErrorException MOI.get(optimizer, MOI.ObjectiveFunction{MOI.SingleVariable}())
390390
end
391+
392+
@testset "set_parameter" begin
393+
# TODO: verify that the parameter was actually set (implement a get_parameter function)
394+
# bool
395+
optimizer = SCIP.Optimizer(branching_preferbinary=true)
396+
397+
# int
398+
optimizer = SCIP.Optimizer(conflict_minmaxvars=1)
399+
400+
# long int
401+
optimizer = SCIP.Optimizer(heuristics_alns_maxnodes=2)
402+
403+
# real
404+
optimizer = SCIP.Optimizer(branching_scorefac=0.15)
405+
406+
# char
407+
optimizer = SCIP.Optimizer(branching_scorefunc='s')
408+
409+
# string
410+
optimizer = SCIP.Optimizer(heuristics_alns_rewardfilename="abc.txt")
411+
412+
# invalid
413+
@test_throws ErrorException SCIP.Optimizer(some_invalid_param_name=true)
414+
end

0 commit comments

Comments
 (0)