diff --git a/src/eago_optimizer/moi_wrapper.jl b/src/eago_optimizer/moi_wrapper.jl index 6727a4e0..a1c0dafe 100644 --- a/src/eago_optimizer/moi_wrapper.jl +++ b/src/eago_optimizer/moi_wrapper.jl @@ -314,4 +314,21 @@ function MOI.get(m::Optimizer, ::Type{VI}, name::String) else return index_storage end -end \ No newline at end of file +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