Closed I-Fons closed 2 years ago
The NLopt wrapper doesn't support constraints, you can use the MOI interface with NLopt to make it work. Your code would then be
using GalacticOptim , Optim , NLopt
myobjfcn(x, p) = (x[1]-p)^2 + p
constraint = (x,p) -> [18 - 5*x[1]]
x0 = ones(1)
p = 2
optprob = OptimizationFunction(myobjfcn, GalacticOptim.AutoForwardDiff(); cons = constraint)
prob = GalacticOptim.OptimizationProblem(optprob, x0, p,
lb = [0.0] , ub = [4.0],
lcons = [-Inf] , ucons = [0.0])
sol = solve(prob, GalacticOptim.MOI.OptimizerWithAttributes(NLopt.Optimizer, "algorithm" => :LN_BOBYQA))
We should error in this case, for now.
Thank you for the correction!
However, as you already mention, the execution of those lines keep throwing the following error:
ERROR: ArgumentError: invalid NLopt arguments: invalid algorithm for constraints
The algorithm doesn't support constraints in that case, try a different one from the docs https://nlopt.readthedocs.io/en/latest/
That was useful, thanks a lot!
I am trying to run this code:
It executes without throwing any error, but the solution provided is the one corresponding to the unconstrained problem. In other words, it lies outside the feasible region defined by including the constraint. The output I get when I execute the function is:
Finally, the packages I am using, and their versions are listed below:
What am I doing wrong? I have emulated the syntax used in https://galacticoptim.sciml.ai/stable/optimization_packages/optim/#Local-Constraint, but this example seems to have the same problem when I run it, that is, the solution is the same when I use constraints and when I remove them.
Thanks for the attention!