Skip to content

Commit

Permalink
Add support for MOI.UserDefinedFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriAlston committed Nov 7, 2024
1 parent 3b28b2e commit 8079a8e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/eago_optimizer/moi_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,21 @@ function MOI.get(m::Optimizer, ::Type{VI}, name::String)
else
return index_storage
end
end
end

#####
##### Support and set user-defined functions
#####
MOI.supports(m::Optimizer, ::MOI.UserDefinedFunction) = true

function MOI.set(m::Optimizer, udf::MOI.UserDefinedFunction, f)
if isnothing(m._input_problem._nlp_data)
model = MOI.Nonlinear.Model()
backend = MOI.Nonlinear.SparseReverseMode()
vars = MOI.get(m, MOI.ListOfVariableIndices())
evaluator = MOI.Nonlinear.Evaluator(model, backend, vars)
m._input_problem._nlp_data = MOI.NLPBlockData(evaluator)
end
MOI.Nonlinear.register_operator(m._input_problem._nlp_data.evaluator.model, udf.name, udf.arity, f...)
return nothing
end

0 comments on commit 8079a8e

Please sign in to comment.