Skip to content

Commit

Permalink
Add support for MOI.UserDefinedFunction (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Dec 3, 2023
1 parent c09d761 commit 9cd01d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
9 changes: 9 additions & 0 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/MINLPTests/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
JuMP = "1"
MINLPTests = "0.6"
MINLPTests = "0.6.1"
julia = "1.6"
14 changes: 5 additions & 9 deletions test/MINLPTests/run_minlptests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9cd01d2

Please sign in to comment.