JuliaNLSolvers / Optim.jl

Optimization functions for Julia
Other
1.11k stars 213 forks source link

Help: Generic non-linear constraint with multiple inputs #1015

Closed fabrizioleone closed 1 year ago

fabrizioleone commented 1 year ago

Hi,

Thanks you for this great package. I am dealing with an optimization problem with generic non-linear constraints. I am reading the relative documentation here.

I understand that non-linear constraints take this form

con_c!(c, x) = (c[1] = x[1]^2 + x[2]^2; c)

and must be passed to optim this way

lc  = [-Inf]
uc  = [1.0]
dfc = TwiceDifferentiableConstraints(con_c!, lc, uc)

How should I supply multiple inputs to con_c!? I would need something like

con_c!(c, x, a) = (c[1] = a*x[1]^2 + x[2]^2; c)

How shall I pass con_c! to TwiceDifferentiableConstraints(con_c!, lc, uc) then?

Thank you

fabrizioleone commented 1 year ago

OK, never mind. I figured it out. I post my solution just for reference in case others are interested:

con_c!(c, x, a) = (c[1] = a*x[1]^2 + x[2]^2; c)
lc  = [-Inf]
uc  = [1.0]
dfc = TwiceDifferentiableConstraints((cox) -> con_c!(c, x, a), lc, uc)