Skip to content

Commit 9cd01d2

Browse files
authored
Add support for MOI.UserDefinedFunction (#279)
1 parent c09d761 commit 9cd01d2

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/MOI_wrapper.jl

+9
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@ function MOI.set(model::Optimizer, attr::MOI.RawOptimizerAttribute, value)
325325
return
326326
end
327327

328+
# MOI.UserDefinedFunction
329+
330+
MOI.supports(model::Optimizer, ::MOI.UserDefinedFunction) = true
331+
332+
function MOI.set(model::Optimizer, attr::MOI.UserDefinedFunction, args)
333+
MOI.Nonlinear.register_operator(model.nlp_model, attr.name, attr.arity, args...)
334+
return
335+
end
336+
328337
MOI.get(model::Optimizer, ::MOI.NumberOfVariables) = length(model.variable_info)
329338

330339
function MOI.get(model::Optimizer, ::MOI.ListOfVariableIndices)

test/MINLPTests/Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
66

77
[compat]
88
JuMP = "1"
9-
MINLPTests = "0.6"
9+
MINLPTests = "0.6.1"
1010
julia = "1.6"

test/MINLPTests/run_minlptests.jl

+5-9
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@ using Test
1212
solver =
1313
JuMP.optimizer_with_attributes(KNITRO.Optimizer, "outlev" => 0, "opttol" => 1e-8)
1414
# 005_010 : knitro finds a slightly different solution
15-
# 005_011 : uses the function `\`
16-
# 006_010 : user-defined function
17-
MINLPTests.test_nlp(solver; exclude=["005_010", "005_011", "006_010"])
18-
MINLPTests.test_nlp_expr(
19-
solver;
20-
exclude=["005_010", "005_011", "006_010", "008_010", "008_011"],
21-
)
15+
# 008_010 : MINLPTests.jl#21
16+
MINLPTests.test_nlp(solver; exclude=["005_010"])
17+
MINLPTests.test_nlp_expr(solver; exclude=["005_010", "008_010"])
2218
# For 005_010, Knitro founds a different solution, close to those of MINLPTests.
2319
MINLPTests.nlp_005_010(solver, 1e-5, 1e-5, 1e-5)
2420
MINLPTests.nlp_expr_005_010(solver, 1e-5, 1e-5, 1e-5)
2521
MINLPTests.test_nlp_cvx(solver)
2622
MINLPTests.test_nlp_cvx_expr(solver)
27-
MINLPTests.test_nlp_mi(solver, exclude=["005_011", "006_010"])
28-
MINLPTests.test_nlp_mi_expr(solver, exclude=["005_011", "006_010"])
23+
MINLPTests.test_nlp_mi(solver)
24+
MINLPTests.test_nlp_mi_expr(solver)
2925
end

0 commit comments

Comments
 (0)