stevengj / nlopt

library for nonlinear optimization, wrapping many algorithms for global and local, constrained or unconstrained, optimization
Other
1.87k stars 577 forks source link

SLSQP vs MMA #315

Open nicolapiccinelli opened 4 years ago

nicolapiccinelli commented 4 years ago

Hi, I'm trying to use SLSQP to solve an MPC problem with Matlab, but without any luck. So I've tried to run the example that can be found here NLopt_Tutorial and for SLSQP I'm obtaining very strange results. I put here a comparison of the outcome of the optimization:

MMA nlopt_optimize eval 92: 0.544331 xopt = 0.3333 0.2963 cost = 0.5443 retcode = 4

SLSQP nlopt_optimize eval 43: 0.544331 xopt = 0.5078 4.7625 cost = 2.1823 retcode = 3

The parameters used are the same for both the optimizers:

opt.ftol_rel = 1e-10
opt.ftol_abs = 1e-10
opt.xtol_rel = 1e-10
opt.maxeval = 400

It's normal that SLSQP isn't able to give the same optimal variables and cost even if it converges to the same evaluation value?

jschueller commented 4 years ago

what do you mean by "same evaluation value" ?

nicolapiccinelli commented 4 years ago

what do you mean by "same evaluation value" ?

I mean the value print in the console when the verbose mode is activated, they are both to 0.544331

nicolapiccinelli commented 4 years ago

what do you mean by "same evaluation value" ?

I mean the value print in the console when the verbose mode is activated, they are both to 0.544331

I've added also the print of the vector x and at each iteration, it doesn't coincide with the value returned by nlopt_optimize.

jschueller commented 4 years ago

yes, this typically happens with some algorithms that have an inner loop to compute some direction and only check the cost enhancement from the points evaluated in the main loop.

nicolapiccinelli commented 4 years ago

yes, this typically happens with some algorithms that have an inner loop to compute some direction and only check the cost enhancement from the points evaluated in the main loop.

There is something strange, now I've started the optimization again and I'm able to get in the output the same values of MMA. I don't understand why, but, what I see in the code is that even if ftol is reached the main loop (do-while with the switch-case) makes a further slsqp iteration. Is this correct?