Constraint nonlinear problem

I have tried GalacticOptim.jl but I did not manage to get the constraints to work.

using GalacticOptim, Optim
using Plots

rosenbrock(x, p) =  (p[1] - x[1])^2 + p[2] * (x[2] - x[1]^2)^2
x0 = zeros(2)
p  = [1.0, 100.0]
circle_constr(x, p) = [x[1]^2 + x[2]^2 - 1] # x_1^2 + x_^2 <= 1
x0 = zeros(2)

optprob = OptimizationFunction(rosenbrock, GalacticOptim.AutoForwardDiff(); cons=circle_constr)
prob = OptimizationProblem(optprob, x0, p, lcons = [-Inf], ucons = [Inf])
sol = solve(prob, IPNewton())

contourf!(-1:0.1:1, -1:0.1:1, (x,y)->rosenbrock([x,y], p), c=:viridis, lw=0)
contour!(-1:0.1:1, -1:0.1:1, (x,y)->circle_constr([x,y], p)[1], levels=[0], c=:blue)
scatter!([sol.u[1]], [sol.u[1]], c=:red, label="solution")

Although no error is thrown the result is incorrect. It is the unconstrained optimum.

Am I doing something wrong?

I’m guessing you need to set the bounds to [-\infty, 0].

1 Like

The result is slightly more correct but still infeasible.

prob = OptimizationProblem(optprob, x0, p, lcons = [-Inf], ucons = [0])

Try GitHub - mohamed82008/Nonconvex.jl: Toolbox for non-convex constrained optimization..

Can you be more specific? What point do you get from the solver?

u: 2-element Array{Float64,1}:
julia> norm([0.7864151541684259, 0.6176983125233905])
1 Like

I see my error now:

THX for the help!

1 Like