NLopt constraints are in the form f(x) <= 0. If you want to be >= 0, you have to flip the sign, i.e. return -(x[2]*x[2]+x[1]).
On Dec 9, 2013, at 10:30 AM, Adel M <[email protected]> wrote: > Hi, > I have a problem when adding an inequality constraint in the form of > X[2]*X[2]+X[1]>=0 that seems not to taken into account by the optimizer > > My C++ code looks like: > static double InequalityConstraint(const std::vector<double>& x, > std::vector<double> &grad, void *data) > { > return (x[2]*x[2]+x[1]); > } > and > opt1.add_inequality_constraint(InequalityConstraint,NULL); > (opt1 is my nlopt::opt ) > > I cannot figure out why this constraint is not taken into account! _______________________________________________ NLopt-discuss mailing list [email protected] http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss
