Thanks for your reply, You're right concerning the constraint function, but for the function to optimize, the tutorial (and the headers) define it with a void pointer. That's why i use the type_cast. Howeve I tried your suggestion but it didn't change a thing :-(
double myfunc(unsigned n, const double *x, double *grad, void *my_func_data) Elias 2010/10/29 Waters, Anthony <[email protected]>: > In the C++ tutorial you use "&data[0]" to send data to the constraint > function: > > opt.add_inequality_constraint(myvconstraint, &data[0], 1e-8); > > So, I'm guessing that your equivalent should be : > > opt.set_min_objective(&SurfLocator::FunctionWrapperNLopt, &P[0]); > > Does that make any sense? > > > Regards, > Anthony Waters > KBC Energy Services > Email: [email protected] > Tel: +44 (0)1606 815100 > > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Elias > Breunig > Sent: 29 October 2010 11:31 > To: [email protected] > Subject: [NLopt-discuss] Problem with set_min_objective > > Hello, > > I'am new to using nlopt an ran in something that i hope is just a > typical newbie problem. > > (c++) > > I want to use nlopt inside a object that acts as nearestneighbour > locator on an parametric manifold. > > therefore i defined within my class SurfLocator > > - a objective function > > double SurfLocator::FunctionWrapperNLopt(const std::vector<double> &x, > std::vector<double> &grad, void *my_func_data) > { > double uvw[] = {x[0],x[1],0}; > double Pt[3]; > double Duvw[9]; > this->Surf->Evaluate(uvw,Pt,Duvw); > > return > pow(Pt[0]-reinterpret_cast<double*>(my_func_data)[0],2)+ > > pow(Pt[1]-reinterpret_cast<double*>(my_func_data)[1],2)+ > > pow(Pt[2]-reinterpret_cast<double*>(my_func_data)[2],2); > } > > This function generates the return value (distance between point and > Surface Point) for nlopt by calling a function of the manifold object > with the parameters x > > - and a routine to handle nlopt that gets a point to find the nearest > neighbour to as input and returns the nearest neighbour (not > implemented here) > > > void SurfLocator::FindNearestPointNLopt(double P[3], double OutPoint[3]) > { > nlopt::opt opt(nlopt::LD_MMA, 2); > > std::vector<double> lb(2); > lb[0] = -HUGE_VAL; lb[1] = 0; > opt.set_lower_bounds(lb); > > opt.set_min_objective(&SurfLocator::FunctionWrapperNLopt, > reinterpret_cast<void*>(P)); > > opt.set_xtol_rel(1e-4); > > std::vector<double> x(2); > x[0] = 0; x[1] = 0; > double minf; > nlopt::result result = opt.optimize(x, minf); > } > > > Everything seems fine so far but when i try to compile (Visual Studio > 2010 Ex) i get an error stating that the > > compiler cannot match the arguments in the call of > opt.set_min_objective to any of its overloadings. > > So whats wrong here... For me it looks quite like the tutorial on the > nlopt webpage, but obviously this is not the case! > > > Thanks for any help > > Elias > > _______________________________________________ > NLopt-discuss mailing list > [email protected] > http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss > This e-mail is confidential and intended only for the individual(s) to whom > it is addressed. If you or your organisation is not an intended recipient of > this e-mail, please notify the sender by replying and do not read or > disseminate its information. Please delete all copies from your system. KBC > is liable neither for the proper or complete transmission of the information > contained in this communication nor for any delay in its receipt. Opinions, > conclusions and other information in this message and attachments that do not > relate to the official business of KBC are neither given nor endorsed by it. > Even though the Webroot Virus Centre has checked this message for all known > viruses, you should carry out your own virus checks before opening any > attachments. Thank you for your co-operation. www.kbcat.com _______________________________________________ NLopt-discuss mailing list [email protected] http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss
