<br><font size=3>Hi Davor. </font>
<br>
<br><font size=3>I already had done what you are suggesting. In fact the
example already works fine. The mistake was related to something with the
NOMAD specification. </font>
<br>
<br><font size=3>Thanks a lot for your help!</font>
<br>
<br><font size=3>Now the example code looks like: </font>
<br>
<br><font size=2>#include "nomad.hpp"</font>
<br><font size=2>#include <RInside.h></font>
<br><font size=2>#include <Rcpp.h></font>
<br><font size=2>using namespace std;</font>
<br>
<br><font size=2>/*----------------------------------------*/</font>
<br><font size=2>/* The
problem */</font>
<br><font size=2>/*----------------------------------------*/</font>
<br>
<br><font size=2>class My_Evaluator : public NOMAD::Evaluator {</font>
<br><font size=2>public:</font>
<br><font size=2> My_Evaluator ( const NOMAD::Parameters &
p, RInside & R) :</font>
<br><font size=2> NOMAD::Evaluator
( p) ,m_R(R) {}</font>
<br>
<br><font size=2> ~My_Evaluator ( void ) {}</font>
<br>
<br><font size=2> RInside & m_R;
// reference to the R instance passed
to constructor</font>
<br>
<br><font size=2> bool eval_x ( NOMAD::Eval_Point & x
,</font>
<br><font size=2>
const NOMAD::Double & h_max ,</font>
<br><font size=2>
bool & count_eval
) const {</font>
<br>
<br><font size=2>m_R.parseEvalQ("rFunction <- function (a,b,c){result
<- (a + b + c) * 20; return(result)}");</font>
<br>
<br><font size=2> double x0;</font>
<br><font size=2> x0= x[0].value();</font>
<br><font size=2> double x1;</font>
<br><font size=2> x1= x[1].value();</font>
<br><font size=2> double x2;</font>
<br><font size=2> x2= x[2].value();</font>
<br><font size=2> </font>
<br><font size=2> m_R.assign( x0,"x0" );</font>
<br><font size=2> m_R.assign( x1,"x1" );</font>
<br><font size=2> m_R.assign( x2,"x2" );</font>
<br><font size=2> </font>
<br><font size=2> m_R.parseEvalQ ("eval.data[1,1]<-x0");</font>
<br><font size=2> m_R.parseEvalQ ("eval.data[1,2]<-x1");</font>
<br><font size=2> m_R.parseEvalQ ("eval.data[1,3]<-x2");</font>
<br>
<br><font size=2> m_R.parseEvalQ("predict<-rFunction(eval.data[1,1],eval.data[1,2],eval.data[1,3])");</font>
<br>
<br><font size=2> double predict_ = m_R["predict"];</font>
<br>
<br><font size=2> NOMAD::Double predict = predict_;</font>
<br>
<br><font size=2> NOMAD::Double c1;</font>
<br>
<br><font size=2> c1= x0*predict + x1+x2-72;
//Only one
constraint</font>
<br>
<br><font size=2> x.set_bb_output ( 0 , x0*46.74 + x1*43.47
+ x2*55.72-80); // objective value</font>
<br><font size=2> x.set_bb_output ( 1 , c1);
// constraint 1</font>
<br><font size=2> </font>
<br><font size=2> count_eval = true; // count a black-box evaluation</font>
<br>
<br><font size=2> return true; // the
evaluation succeeded</font>
<br><font size=2> }</font>
<br><font size=2>};</font>
<br>
<br><font size=2>/*------------------------------------------*/</font>
<br><font size=2>/* NOMAD main
function */</font>
<br><font size=2>/*------------------------------------------*/</font>
<br><font size=2>int main ( int argc , char ** argv ) {</font>
<br>
<br><font size=2> // display:</font>
<br><font size=2> NOMAD::Display out ( std::cout );</font>
<br><font size=2> out.precision ( NOMAD::DISPLAY_PRECISION_STD );</font>
<br>
<br><font size=2> try {</font>
<br>
<br><font size=2> RInside R(argc,argv); // create
an embedded R instance</font>
<br>
<br><font size=2> // NOMAD initializations:</font>
<br><font size=2> NOMAD::begin ( argc , argv );</font>
<br>
<br><font size=2> // parameters creation:</font>
<br><font size=2> NOMAD::Parameters p ( out );</font>
<br>
<br><font size=2> //p.set_DIMENSION (8);
// number of variables</font>
<br><font size=2> p.set_DIMENSION (3);
// number of variables</font>
<br>
<br><font size=2> vector<NOMAD::bb_output_type> bbot
(2); // definition of</font>
<br><font size=2> bbot[0] = NOMAD::OBJ;
// output types</font>
<br><font size=2> bbot[1] = NOMAD::PB;</font>
<br><font size=2> p.set_BB_OUTPUT_TYPE ( bbot );</font>
<br>
<br><font size=2> p.set_DISPLAY_STATS ( "bbe ( sol )
obj" );</font>
<br>
<br><font size=2> // p.set_DISPLAY_DEGREE ( FULL_DISPLAY );</font>
<br>
<br><font size=2> NOMAD::Point sp(3);</font>
<br><font size=2> sp[0]=0.15;</font>
<br><font size=2> sp[1]=0.10;</font>
<br><font size=2> sp[2]=0.3;</font>
<br><font size=2> </font>
<br><font size=2> p.set_X0 ( sp ); // starting point</font>
<br>
<br><font size=2> NOMAD::Point lb ( 3 );
// Límite inferior</font>
<br><font size=2> lb[0] = 0;
//</font>
<br><font size=2> lb[1] = 0;
//</font>
<br><font size=2> lb[2] = 0;
//</font>
<br><font size=2> </font>
<br><font size=2> p.set_LOWER_BOUND ( lb ); // all var. >=
0</font>
<br>
<br><font size=2> NOMAD::Point ub ( 3 );
// Límite superior</font>
<br><font size=2> ub[0] = 0.22;
//</font>
<br><font size=2> ub[1] = 0.18;
//</font>
<br><font size=2> ub[2] = 1.00;
//</font>
<br><font size=2> </font>
<br><font size=2> p.set_UPPER_BOUND ( ub );</font>
<br>
<br><font size=2> p.set_MAX_BB_EVAL (50); //
the algorithm terminates after</font>
<br><font size=2>
// 50 black-box
evaluations</font>
<br>
<br><font size=2> // parameters validation:</font>
<br><font size=2> p.check();</font>
<br>
<br><font size=2> // custom evaluator creation:</font>
<br><font size=2> My_Evaluator ev ( p,R );</font>
<br>
<br><font size=2> // algorithm creation and execution:</font>
<br><font size=2> NOMAD::Mads mads ( p , &ev );</font>
<br>
<br><font size=2> mads.run();</font>
<br>
<br><font size=2> }</font>
<br><font size=2> catch ( exception & e ) {</font>
<br><font size=2> cerr << "\nNOMAD has been interrupted
(" << e.what() << ")\n\n";</font>
<br><font size=2> }</font>
<br>
<br><font size=2> NOMAD::Slave::stop_slaves ( out );</font>
<br><font size=2> NOMAD::end();</font>
<br>
<br><font size=2> return EXIT_SUCCESS;</font>
<br><font size=2>}</font>
<br>
<br><font size=3>Best regards!!</font>
<br>
<br><font size=3>César </font>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>Davor Cubranic <cubranic@stat.ubc.ca></b>
</font>
<p><font size=1 face="sans-serif">21/03/2011 10:33 a.m.</font>
<td width=59%>
<table width=100%>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Para</font></div>
<td valign=top><font size=1 face="sans-serif">CESAR PERNALETE <pernaletec@pdvsa.com></font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td valign=top><font size=1 face="sans-serif">rcpp-devel@r-forge.wu-wien.ac.at</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Asunto</font></div>
<td valign=top><font size=1 face="sans-serif">Re: [Rcpp-devel] R Embedded
in a class function</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><font size=3>Hi Cesar,</font>
<br>
<br><font size=3>I don't know why your embed does not work, but I would
suggest to rework your code a bit and follow the pattern used by Dirk in
his Qt example:</font>
<br>
<br><font size=3>1. create an RInside instance "R" in the "main"
function</font>
<br><font size=3>2. pass that RInside instance by reference to the constructor
for MyEvaluator and save it to a private member variable</font>
<br><font size=3>3. MyEvaluator::eval_x can work the same as now, except
that it will begin at the line "R.parseEvalQ" since you already
have the RInside instance</font>
<br>
<br><font size=3>Hope this helps,</font>
<br>
<br><font size=3>Davor</font>
<br>
<br><font size=1 color=#800080 face="sans-serif">----- Remitido por CESAR
PERNALETE/PERNALETEC/PDV/PDVSA con fecha 23/03/2011 09:33 a.m. -----</font>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>CESAR PERNALETE/PERNALETEC/PDV/PDVSA</b></font>
<p><font size=1 face="sans-serif">21/03/2011 11:23 a.m.</font>
<td width=59%>
<table width=100%>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Para</font></div>
<td valign=top><font size=1 face="sans-serif">Davor Cubranic <cubranic@stat.ubc.ca>,
Dirk Eddelbuettel <edd@debian.org></font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td valign=top><font size=1 face="sans-serif">rcpp-devel@r-forge.wu-wien.ac.at,
rcpp-devel-bounces@r-forge.wu-wien.ac.at</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Asunto</font></div>
<td valign=top><font size=1 face="sans-serif">Re: [Rcpp-devel] R Embedded
in a class function</font><a href=Notes:///2425785A0068BAEE/0101AC3F3D01AB1CC3256C3F002FDD52/0000035BF027035B001A0013DE580000>Vínculo</a></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br><font size=2 face="sans-serif">Hi Davor, Dirk.</font>
<br>
<br><font size=2 face="sans-serif">Thanks a lot for your help. I tried
the way Dirk are suggesting and it appears to work fine. The application
at all is not working yet, i don't know exactly </font>
<br><font size=2 face="sans-serif">what is happening, so i did a consultation
to the NOMAD developer. But i believe that the problem of using the R object
into a method is solved. </font>
<br>
<br><font size=2 face="sans-serif">Please, find attached a simplified example
of the code. </font>
<br>
<br><font size=2 face="sans-serif">If you see something weird, please don't
hesitate in writing to the list. </font>
<br>
<br><font size=2 face="sans-serif">Best regards. </font>
<br>
<br><font size=2 face="sans-serif">César </font>
<br>
<br>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>Davor Cubranic <cubranic@stat.ubc.ca></b>
</font>
<br><font size=1 face="sans-serif">Enviado por: rcpp-devel-bounces@r-forge.wu-wien.ac.at</font>
<p><font size=1 face="sans-serif">17/03/2011 07:51 p.m.</font>
<td width=59%>
<table width=100%>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Para</font></div>
<td valign=top><font size=1 face="sans-serif">Dirk Eddelbuettel <edd@debian.org></font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td valign=top><font size=1 face="sans-serif">rcpp-devel@r-forge.wu-wien.ac.at</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Asunto</font></div>
<td valign=top><font size=1 face="sans-serif">Re: [Rcpp-devel] R Embedded
in a class function</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><font size=2><tt>On 2011-03-17, at 3:31 PM, Dirk Eddelbuettel wrote:<br>
<br>
> | And it so happens that I just wrote an example of instantiating
RInside and<br>
> | passing to Qt so that you'd get 'R inside Qt'. That is now
in SVN for<br>
> | RInside but I haven't even gotten around to writing a short blog
post about<br>
> | it. Maybe on the weekend...<br>
> <br>
> I forgot to give the URL:<br>
> <br>
> https://r-forge.r-project.org/scm/viewvc.php/pkg/inst/examples/qt/?root=rinside<br>
> <br>
<br>
But your code still creates R instance in "main", which it then
passes to the QtDensity instance (a subclass of QtMainWindow). OTOH, once
the R instance is stored as a member variable of QtDensity, it *is* used
in QtDensity's methods. <br>
<br>
But I'm quibbling -- it's a good pattern to follow, so Cesar could perhaps
just adapt it to his code.<br>
<br>
Davor<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
Rcpp-devel@lists.r-forge.r-project.org<br>
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel<br>
</tt></font>
<br>