Thanks for your reply. I should have been more careful reading the manual. Unfortunately, I still can't get it to work. I'd really like to continue using NLOPT. It would be very helpful to know whether it is a bug in the Python bindings or if I'm doing something wrong.
I follow the documentation http://ab-initio.mit.edu/wiki/index.php/NLopt_Python_Reference, Section Local/subsidiary optimization algorithm as closely as possible. So I create a new nlopt.opt object `opt2 = nlopt.opt(nlopt.LD_MMA, 2)` and set the stopping criterion to `opt2.set_xtol_rel(1e-4)`. Then I pass the object to opt = nlopt.opt(nlopt.LD_AUGLAG, 2) opt.set_local_optimizer(opt2) Below the overall code + its output: -------------------------- start code ------------------------------------ import nlopt from numpy import * def myfunc(x, grad): if grad.size > 0: grad[0] = 0.0 grad[1] = 0.5 / sqrt(x[1]) return sqrt(x[1]) def myconstraint(x, grad, a, b): if grad.size > 0: grad[0] = 3 * a * (a*x[0] + b)**2 grad[1] = -1.0 return (a*x[0] + b)**3 - x[1] opt2 = nlopt.opt(nlopt.LD_MMA, 2) opt2.set_xtol_rel(1e-4) opt = nlopt.opt(nlopt.LD_AUGLAG, 2) opt.set_local_optimizer(opt2) opt.set_maxeval(1000) opt.set_lower_bounds([-float('inf'), 0]) opt.set_min_objective(myfunc) opt.add_inequality_constraint(lambda x,grad: myconstraint(x,grad,2,0), 1e-8) opt.add_inequality_constraint(lambda x,grad: myconstraint(x,grad,-1,1), 1e-8) opt.set_xtol_rel(1e-4) x = opt.optimize([1.234, 5.678]) minf = opt.last_optimum_value() print "optimum at ", x[0],x[1] print "minimum value = ", minf print "result code = ", opt.last_optimize_result() -------------------------- end code ------------------------------------ ---------------- start output ------------------ python nlopt_test.py optimum at 0.440450564807 0.0 minimum value = 0.0 result code = 5 ---------------- start output ------------------ the correct solution according to the documentation is optimum at 0.333333331366 0.296296292697 minimum value = 0.544331050646 result code = 4 best regards, Sebastian Walter On Mon, Nov 1, 2010 at 4:31 PM, Steven G. Johnson <[email protected]> wrote: > On Oct 31, 2010, at 9:47 AM, Sebastian Walter wrote: >> >> opt.set_local_optimizer(nlopt.LD_MMA) > > This is not corrrect: set_local_optimizer takes as its argument another opt > object (with its own convergence tolerances that you should have set). See > the manual. > > --SGJ > > > _______________________________________________ > NLopt-discuss mailing list > [email protected] > http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss > _______________________________________________ NLopt-discuss mailing list [email protected] http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss
