From 9cd01d29f2419dc83cd550fb31dec3e1ecbe18dd Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Mon, 4 Dec 2023 12:30:50 +1300 Subject: [PATCH] Add support for MOI.UserDefinedFunction (#279) --- src/MOI_wrapper.jl | 9 +++++++++ test/MINLPTests/Project.toml | 2 +- test/MINLPTests/run_minlptests.jl | 14 +++++--------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/MOI_wrapper.jl b/src/MOI_wrapper.jl index f004357..8b791c1 100644 --- a/src/MOI_wrapper.jl +++ b/src/MOI_wrapper.jl @@ -325,6 +325,15 @@ function MOI.set(model::Optimizer, attr::MOI.RawOptimizerAttribute, value) return end +# MOI.UserDefinedFunction + +MOI.supports(model::Optimizer, ::MOI.UserDefinedFunction) = true + +function MOI.set(model::Optimizer, attr::MOI.UserDefinedFunction, args) + MOI.Nonlinear.register_operator(model.nlp_model, attr.name, attr.arity, args...) + return +end + MOI.get(model::Optimizer, ::MOI.NumberOfVariables) = length(model.variable_info) function MOI.get(model::Optimizer, ::MOI.ListOfVariableIndices) diff --git a/test/MINLPTests/Project.toml b/test/MINLPTests/Project.toml index 7b581a2..78ba2b4 100644 --- a/test/MINLPTests/Project.toml +++ b/test/MINLPTests/Project.toml @@ -6,5 +6,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] JuMP = "1" -MINLPTests = "0.6" +MINLPTests = "0.6.1" julia = "1.6" diff --git a/test/MINLPTests/run_minlptests.jl b/test/MINLPTests/run_minlptests.jl index 85bb2b0..d800fec 100644 --- a/test/MINLPTests/run_minlptests.jl +++ b/test/MINLPTests/run_minlptests.jl @@ -12,18 +12,14 @@ using Test solver = JuMP.optimizer_with_attributes(KNITRO.Optimizer, "outlev" => 0, "opttol" => 1e-8) # 005_010 : knitro finds a slightly different solution - # 005_011 : uses the function `\` - # 006_010 : user-defined function - MINLPTests.test_nlp(solver; exclude=["005_010", "005_011", "006_010"]) - MINLPTests.test_nlp_expr( - solver; - exclude=["005_010", "005_011", "006_010", "008_010", "008_011"], - ) + # 008_010 : MINLPTests.jl#21 + MINLPTests.test_nlp(solver; exclude=["005_010"]) + MINLPTests.test_nlp_expr(solver; exclude=["005_010", "008_010"]) # For 005_010, Knitro founds a different solution, close to those of MINLPTests. MINLPTests.nlp_005_010(solver, 1e-5, 1e-5, 1e-5) MINLPTests.nlp_expr_005_010(solver, 1e-5, 1e-5, 1e-5) MINLPTests.test_nlp_cvx(solver) MINLPTests.test_nlp_cvx_expr(solver) - MINLPTests.test_nlp_mi(solver, exclude=["005_011", "006_010"]) - MINLPTests.test_nlp_mi_expr(solver, exclude=["005_011", "006_010"]) + MINLPTests.test_nlp_mi(solver) + MINLPTests.test_nlp_mi_expr(solver) end