<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 &quot;nomad.hpp&quot;</font>
<br><font size=2>#include &lt;RInside.h&gt;</font>
<br><font size=2>#include &lt;Rcpp.h&gt;</font>
<br><font size=2>using namespace std;</font>
<br>
<br><font size=2>/*----------------------------------------*/</font>
<br><font size=2>/* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; The
problem &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</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>&nbsp; &nbsp; My_Evaluator ( const NOMAD::Parameters &amp;
p, RInside &amp; R) :</font>
<br><font size=2>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NOMAD::Evaluator
( p) ,m_R(R) &nbsp;{}</font>
<br>
<br><font size=2>&nbsp; ~My_Evaluator ( void ) {}</font>
<br>
<br><font size=2>&nbsp; RInside &amp; m_R; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp;// reference to the R instance passed
to constructor</font>
<br>
<br><font size=2>&nbsp; bool eval_x ( NOMAD::Eval_Point &nbsp; &amp; x
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;,</font>
<br><font size=2>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
const NOMAD::Double &amp; h_max &nbsp; &nbsp; &nbsp;,</font>
<br><font size=2>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
bool &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp; count_eval
&nbsp; ) const {</font>
<br>
<br><font size=2>m_R.parseEvalQ(&quot;rFunction &lt;- function (a,b,c){result
&lt;- (a + b + c) * 20; return(result)}&quot;);</font>
<br>
<br><font size=2>&nbsp; &nbsp;double x0;</font>
<br><font size=2>&nbsp; &nbsp;x0= x[0].value();</font>
<br><font size=2>&nbsp; &nbsp;double x1;</font>
<br><font size=2>&nbsp; &nbsp;x1= x[1].value();</font>
<br><font size=2>&nbsp; &nbsp;double x2;</font>
<br><font size=2>&nbsp; &nbsp;x2= x[2].value();</font>
<br><font size=2>&nbsp; &nbsp;</font>
<br><font size=2>&nbsp; &nbsp;m_R.assign( x0,&quot;x0&quot; );</font>
<br><font size=2>&nbsp; &nbsp;m_R.assign( x1,&quot;x1&quot; );</font>
<br><font size=2>&nbsp; &nbsp;m_R.assign( x2,&quot;x2&quot; );</font>
<br><font size=2>&nbsp; &nbsp;</font>
<br><font size=2>&nbsp; &nbsp;m_R.parseEvalQ (&quot;eval.data[1,1]&lt;-x0&quot;);</font>
<br><font size=2>&nbsp; &nbsp;m_R.parseEvalQ (&quot;eval.data[1,2]&lt;-x1&quot;);</font>
<br><font size=2>&nbsp; &nbsp;m_R.parseEvalQ (&quot;eval.data[1,3]&lt;-x2&quot;);</font>
<br>
<br><font size=2>&nbsp; &nbsp; m_R.parseEvalQ(&quot;predict&lt;-rFunction(eval.data[1,1],eval.data[1,2],eval.data[1,3])&quot;);</font>
<br>
<br><font size=2>&nbsp; &nbsp;double predict_ = m_R[&quot;predict&quot;];</font>
<br>
<br><font size=2>&nbsp; &nbsp;NOMAD::Double predict = predict_;</font>
<br>
<br><font size=2>&nbsp; &nbsp;NOMAD::Double c1;</font>
<br>
<br><font size=2>&nbsp; &nbsp;c1= x0*predict + x1+x2-72; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Only one
constraint</font>
<br>
<br><font size=2>&nbsp; &nbsp;x.set_bb_output &nbsp;( 0 , x0*46.74 + x1*43.47
+ x2*55.72-80); // objective value</font>
<br><font size=2>&nbsp; &nbsp;x.set_bb_output &nbsp;( 1 , c1); &nbsp; &nbsp;
// constraint 1</font>
<br><font size=2>&nbsp; &nbsp;</font>
<br><font size=2>&nbsp; &nbsp;count_eval = true; // count a black-box evaluation</font>
<br>
<br><font size=2>&nbsp; &nbsp; return true; &nbsp; &nbsp; &nbsp; // the
evaluation succeeded</font>
<br><font size=2>&nbsp; }</font>
<br><font size=2>};</font>
<br>
<br><font size=2>/*------------------------------------------*/</font>
<br><font size=2>/* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NOMAD main
function &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */</font>
<br><font size=2>/*------------------------------------------*/</font>
<br><font size=2>int main ( int argc , char ** argv ) {</font>
<br>
<br><font size=2>&nbsp; // display:</font>
<br><font size=2>&nbsp; NOMAD::Display out ( std::cout );</font>
<br><font size=2>&nbsp; out.precision ( NOMAD::DISPLAY_PRECISION_STD );</font>
<br>
<br><font size=2>&nbsp; try {</font>
<br>
<br><font size=2>&nbsp; &nbsp; &nbsp; RInside R(argc,argv); &nbsp;// create
an embedded R instance</font>
<br>
<br><font size=2>&nbsp; &nbsp; // NOMAD initializations:</font>
<br><font size=2>&nbsp; &nbsp; NOMAD::begin ( argc , argv );</font>
<br>
<br><font size=2>&nbsp; &nbsp; // parameters creation:</font>
<br><font size=2>&nbsp; &nbsp; NOMAD::Parameters p ( out );</font>
<br>
<br><font size=2>&nbsp; &nbsp; //p.set_DIMENSION (8); &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; // number of variables</font>
<br><font size=2>&nbsp; &nbsp; p.set_DIMENSION (3); &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; // number of variables</font>
<br>
<br><font size=2>&nbsp; &nbsp; vector&lt;NOMAD::bb_output_type&gt; bbot
(2); // definition of</font>
<br><font size=2>&nbsp; &nbsp; bbot[0] = NOMAD::OBJ; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // output types</font>
<br><font size=2>&nbsp; &nbsp; bbot[1] = NOMAD::PB;</font>
<br><font size=2>&nbsp; &nbsp; p.set_BB_OUTPUT_TYPE ( bbot );</font>
<br>
<br><font size=2>&nbsp; &nbsp; p.set_DISPLAY_STATS ( &quot;bbe ( sol )
obj&quot; );</font>
<br>
<br><font size=2>&nbsp; &nbsp; // p.set_DISPLAY_DEGREE ( FULL_DISPLAY );</font>
<br>
<br><font size=2>&nbsp; &nbsp; NOMAD::Point sp(3);</font>
<br><font size=2>&nbsp; &nbsp; sp[0]=0.15;</font>
<br><font size=2>&nbsp; &nbsp; sp[1]=0.10;</font>
<br><font size=2>&nbsp; &nbsp; sp[2]=0.3;</font>
<br><font size=2>&nbsp; &nbsp; </font>
<br><font size=2>&nbsp; &nbsp; p.set_X0 ( sp ); &nbsp;// starting point</font>
<br>
<br><font size=2>&nbsp; &nbsp; NOMAD::Point lb ( 3 ); &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Límite inferior</font>
<br><font size=2>&nbsp; &nbsp; lb[0] = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//</font>
<br><font size=2>&nbsp; &nbsp; lb[1] = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//</font>
<br><font size=2>&nbsp; &nbsp; lb[2] = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//</font>
<br><font size=2>&nbsp; </font>
<br><font size=2>&nbsp; &nbsp; p.set_LOWER_BOUND ( lb ); // all var. &gt;=
0</font>
<br>
<br><font size=2>&nbsp; &nbsp; NOMAD::Point ub ( 3 ); &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Límite superior</font>
<br><font size=2>&nbsp; &nbsp; ub[0] = 0.22; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
//</font>
<br><font size=2>&nbsp; &nbsp; ub[1] = 0.18; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
//</font>
<br><font size=2>&nbsp; &nbsp; ub[2] = 1.00; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//</font>
<br><font size=2>&nbsp; </font>
<br><font size=2>&nbsp; &nbsp; p.set_UPPER_BOUND ( ub );</font>
<br>
<br><font size=2>&nbsp; &nbsp; p.set_MAX_BB_EVAL (50); &nbsp; &nbsp; //
the algorithm terminates after</font>
<br><font size=2>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 50 black-box
evaluations</font>
<br>
<br><font size=2>&nbsp; &nbsp; // parameters validation:</font>
<br><font size=2>&nbsp; &nbsp; p.check();</font>
<br>
<br><font size=2>&nbsp; &nbsp; // custom evaluator creation:</font>
<br><font size=2>&nbsp; &nbsp; My_Evaluator ev &nbsp; ( p,R );</font>
<br>
<br><font size=2>&nbsp; &nbsp; // algorithm creation and execution:</font>
<br><font size=2>&nbsp; &nbsp; NOMAD::Mads mads ( p , &amp;ev );</font>
<br>
<br><font size=2>&nbsp; &nbsp; mads.run();</font>
<br>
<br><font size=2>&nbsp; }</font>
<br><font size=2>&nbsp; catch ( exception &amp; e ) {</font>
<br><font size=2>&nbsp; &nbsp; cerr &lt;&lt; &quot;\nNOMAD has been interrupted
(&quot; &lt;&lt; e.what() &lt;&lt; &quot;)\n\n&quot;;</font>
<br><font size=2>&nbsp; }</font>
<br>
<br><font size=2>&nbsp; NOMAD::Slave::stop_slaves ( out );</font>
<br><font size=2>&nbsp; NOMAD::end();</font>
<br>
<br><font size=2>&nbsp; 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 &lt;cubranic@stat.ubc.ca&gt;</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 &lt;pernaletec@pdvsa.com&gt;</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 &quot;R&quot; in the &quot;main&quot;
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 &quot;R.parseEvalQ&quot; 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 &lt;cubranic@stat.ubc.ca&gt;,
Dirk Eddelbuettel &lt;edd@debian.org&gt;</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 &lt;cubranic@stat.ubc.ca&gt;</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 &lt;edd@debian.org&gt;</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>
&gt; | And it so happens that I just wrote an example of instantiating
RInside and<br>
&gt; | passing to Qt so that you'd get 'R inside Qt'. &nbsp;That is now
in SVN for<br>
&gt; | RInside but I haven't even gotten around to writing a short blog
post about<br>
&gt; | it. &nbsp;Maybe on the weekend...<br>
&gt; <br>
&gt; I forgot to give the URL:<br>
&gt; <br>
&gt; https://r-forge.r-project.org/scm/viewvc.php/pkg/inst/examples/qt/?root=rinside<br>
&gt; <br>
<br>
But your code still creates R instance in &quot;main&quot;, 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>