Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MOI.UserDefinedFunction #138

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 5 additions & 6 deletions src/eago_optimizer/optimize/nonconvex/stack_management.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,27 +236,26 @@ $(TYPEDSIGNATURES)
Check the optimization problem for unbounded branching variables, which would interfere
with EAGO's branch-and-bound routine since there are no well-defined branching rules
for cases where the interval bounds contain `-Inf` or `Inf`. If any branching variables
are missing bounds, add the missing bound at +/- 1E10 and warn the user.
are missing bounds, add the missing bound at +/- 1E6 and warn the user.
"""
function unbounded_check!(m::GlobalOptimizer)
if m._parameters.unbounded_check
unbounded_flag = false
wp = m._working_problem
epigraph_flag = _variable_num(FullVar(), m) != m._input_problem._variable_count
for i = 1:_variable_num(BranchVar(), m) - epigraph_flag #Not including epigraph reformulation variable
for i = 1:_variable_num(BranchVar(), m)
if !wp._variable_info[i].has_lower_bound
unbounded_flag = true
wp._variable_info[i] = VariableInfo(wp._variable_info[i], GT(-1E10))
wp._variable_info[i] = VariableInfo(wp._variable_info[i], GT(-1E6)) # Some solvers break if bounds are too large
end
if !wp._variable_info[i].has_upper_bound
unbounded_flag = true
wp._variable_info[i] = VariableInfo(wp._variable_info[i], LT(1E10))
wp._variable_info[i] = VariableInfo(wp._variable_info[i], LT(1E6)) # Some solvers break if bounds are too large
end
end
unbounded_flag && @warn("""
At least one branching variable is unbounded. This will interfere with EAGO's global
optimization routine and may cause unexpected results. Bounds have been automatically
generated at +/- 1E10 for all unbounded variables, but tighter user-defined bounds are
generated at +/- 1E6 for all unbounded variables, but tighter user-defined bounds are
highly recommended. To disable this warning and the automatic generation of bounds, use
the option `unbounded_check = false`.""")
end
Expand Down
Loading