Skip to content

Commit

Permalink
Add support for MOI.UserDefinedFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Dec 3, 2023
1 parent c09d761 commit 3ded9b2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
20 changes: 20 additions & 0 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,26 @@ 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.ListOfSupportedNonlinearOperators

function MOI.get(model::Optimizer, attr::MOI.ListOfSupportedNonlinearOperators)
return MOI.get(model.nlp_model, attr)

Check warning on line 345 in src/MOI_wrapper.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper.jl#L344-L345

Added lines #L344 - L345 were not covered by tests
end

MOI.get(model::Optimizer, ::MOI.NumberOfVariables) = length(model.variable_info)

function MOI.get(model::Optimizer, ::MOI.ListOfVariableIndices)
Expand Down
9 changes: 4 additions & 5 deletions test/MINLPTests/run_minlptests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ using Test
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(solver; exclude=["005_010", "005_011"])
MINLPTests.test_nlp_expr(
solver;
exclude=["005_010", "005_011", "006_010", "008_010", "008_011"],
exclude=["005_010", "005_011", "008_010", "008_011"],
)
# 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, exclude=["005_011"])
MINLPTests.test_nlp_mi_expr(solver, exclude=["005_011"])
end

0 comments on commit 3ded9b2

Please sign in to comment.