[Scilab-Dev] SciFunction

Sylvestre Ledru sylvestre.ledru at inria.fr
Fri Feb 8 14:38:06 CET 2008


HI Yann,

I am not answering to your question (sorry).
But I would like to inform you that we changed the data type declaration
in CreateVar, GetRhsVar, etc for something less cryptic:

	+ "c" => STRING_DATATYPE
	+ "S" => MATRIX_OF_STRING_DATATYPE
	+ "d" => MATRIX_OF_DOUBLE_DATATYPE
	+ "r" => MATRIX_OF_RATIONAL_DATATYPE
	+ "I" => MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE
	+ "i" => MATRIX_OF_INTEGER_DATATYPE
	+ "b" => MATRIX_OF_BOOLEAN_DATATYPE
	+ "z" => MATRIX_OF_COMPLEX_DATATYPE
	+ "s" => SPARSE_MATRIX_DATATYPE
	+ "l" => LIST_DATATYPE
	+ "t" => TYPED_LIST_DATATYPE
	+ "m" => MATRIX_ORIENTED_TYPED_LIST_DATATYPE
	+ "p" => SCILAB_POINTER_DATATYPE
	+ "h" => GRAPHICAL_HANDLE_DATATYPE
	+ "f" => EXTERNAL_DATATYPE
You will find the list here:
modules/core/includes/stackTypeVariable.h

Cheers,
Sylvestre

Le mercredi 06 février 2008 à 14:50 +0100, COLLETTE Yann a écrit :
> Hello,
> 
> I'm trying to interface an optimisation method under scilab (the 
> optimization method is in fortran and I'm writing the interface in C).
> My question is: how to retrieve the output parameters of a call to 
> SciFunction ?
> The following program is called several times during the run of the 
> optimization:
> 
> /////////////////////////////////////
> //  First I create some parameters. The first one will contain the "x" 
> vector and the second one the gradient of the output (I do this to give 
> the correct size to the stack. If I don't do this, scilab says it 
> doesn't know the ibegin + 1 parameter).
> 
>   // Create the first variable: x
>   n_x1_tmp = n_x;
>   m_x1_tmp = m_x;
>   CreateVar(ibegin,"d",&n_x1_tmp,&m_x1_tmp,&l_x1_tmp);
>   for(i=0;i<ndv; i++) *dstk(l_x1_tmp+i) = *dstk(l_x+i);
> 
>   // Create a fake 2nd variable on the stack. This will allow to call 
> GetRhsVar to retrieve the 2nd output argument
>   n_x2_tmp = 1;
>   m_x2_tmp = 1;
>   CreateVar(ibegin+1,"d",&n_x2_tmp,&m_x2_tmp,&l_x2_tmp);
> 
> ///////////////////////////////////
> // I call the scilab function via SciFunction
> 
> 
>   // Call to the scilab function
>   SciFunction(&ibegin,&l_fobj,&fobj_lhs,&fobj_rhs);
>   if (Err>0)
>     {
>       sciprint("conmin: error when calling objective function\n");
>       return 0;
>     } /* End If */
> 
>   n1 = ndv + 2;
> 
> ////////////////////////////////////
> // Now I get the parameters via GetRhsVar. I hope that the size of the 
> ibegin and ibegin+1 parameters are set correctly by SciFunction (first 
> free the memory and then mallocated correctly to get the output parameters).
>   // Get fobj
>   GetRhsVar(ibegin,  "d",&n_fobj_tmp, &m_fobj_tmp, &l_fobj_tmp);
>   // Get gradient of fobj
>   GetRhsVar(ibegin+1,"d",&n_dfobj_tmp,&m_dfobj_tmp,&l_dfobj_tmp);
> 
> /////////////////////////////////////
> // Finally, I store all the output parameters in temporary arrays 
> (because just after the objective function, I called the constraints 
> also via SciFunction).
> 
>   // Fill C2F(cnmn1).obj: objective function value
>   C2F(cnmn1).obj = *dstk(l_fobj_tmp);
> 
>   // DF(N1) Analytic gradient of the objective function for the current 
> decision variables, X(I).  DF(I) contains the partial derivative
>   //        of OBJ with respect to X(I).  Calculate DF(I), I = 1, NDV if 
> INFO = 3 or INFO = 4 and if NFDG = 0 or NFDG = 2.
>   double * DF = (double *)malloc(n1*sizeof(double));
>   // Fill DF(N1): gradient of objective function value
>   for(j=0;j<ndv;j++) DF[j] = *dstk(l_dfobj_tmp+j);
> 
> ///////////////////////////////////////
> // Is my strategy good or do you recommend another method ?
> 
> Your sincerely,
> 
> Yann COLLETTE
> 
> 
> -- Disclaimer ------------------------------------
> Ce message ainsi que les eventuelles pieces jointes constituent une correspondance privee et confidentielle a l'attention exclusive du destinataire designe ci-dessus. Si vous n'etes pas le destinataire du present message ou une personne susceptible de pouvoir le lui delivrer, il vous est signifie que toute divulgation, distribution ou copie de cette transmission est strictement interdite. Si vous avez recu ce message par erreur, nous vous remercions d'en informer l'expediteur par telephone ou de lui retourner le present message, puis d'effacer immediatement ce message de votre systeme.
> ***
> This e-mail and any attachments is a confidential correspondence intended only for use of the individual or entity named above. If you are not the intended recipient or the agent responsible for delivering the message to the intended recipient, you are hereby notified that any disclosure, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender by phone or by replying this message, and then delete this message from your system.




More information about the dev mailing list