Hi Adel,

I'd say you need to negate the return value, according to the user manual, 
nlopt only takes nonlinear constraints of the form g(x) <= 0.

so:
... InequalityConstraint(...)
{
    return( -1.0*(x[2]*x[2]+x[1]) )
}

also, you should consider passing a tolerance when you add the constraint... 
that's also mentioned in the manual :)

-Sam

________________________________
From: NLopt-discuss [[email protected]] on behalf of Adel 
M [[email protected]]
Sent: Monday, December 09, 2013 4:30 PM
To: [email protected]
Subject: [NLopt-discuss] COBYLA with constraints

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!

Best Regards,
Adel

_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss

Reply via email to