Home > matlab > acado > packages > +acado > @ParameterEstimationAlgorithm > getInstructions.m

getInstructions

PURPOSE ^

Used to generate CPP file

SYNOPSIS ^

function getInstructions(obj, cppobj, get)

DESCRIPTION ^

Used to generate CPP file

  Licence:
    This file is part of ACADO Toolkit  - (http://www.acadotoolkit.org/)

    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
    Copyright (C) 2008-2009 by Boris Houska and Hans Joachim Ferreau, K.U.Leuven.
    Developed within the Optimization in Engineering Center (OPTEC) under
    supervision of Moritz Diehl. All rights reserved.

    ACADO Toolkit is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 3 of the License, or (at your option) any later version.

    ACADO Toolkit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with ACADO Toolkit; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

    Author: David Ariens
    Date: 2010

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function getInstructions(obj, cppobj, get)
0002 %Used to generate CPP file
0003 %
0004 %  Licence:
0005 %    This file is part of ACADO Toolkit  - (http://www.acadotoolkit.org/)
0006 %
0007 %    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
0008 %    Copyright (C) 2008-2009 by Boris Houska and Hans Joachim Ferreau, K.U.Leuven.
0009 %    Developed within the Optimization in Engineering Center (OPTEC) under
0010 %    supervision of Moritz Diehl. All rights reserved.
0011 %
0012 %    ACADO Toolkit is free software; you can redistribute it and/or
0013 %    modify it under the terms of the GNU Lesser General Public
0014 %    License as published by the Free Software Foundation; either
0015 %    version 3 of the License, or (at your option) any later version.
0016 %
0017 %    ACADO Toolkit is distributed in the hope that it will be useful,
0018 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
0019 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0020 %    Lesser General Public License for more details.
0021 %
0022 %    You should have received a copy of the GNU Lesser General Public
0023 %    License along with ACADO Toolkit; if not, write to the Free Software
0024 %    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0025 %
0026 %    Author: David Ariens
0027 %    Date: 2010
0028 %
0029 
0030 
0031 global ACADO_;
0032 
0033 if (get == 'B')
0034 
0035    
0036     fprintf(cppobj.fileMEX,sprintf('    ParameterEstimationAlgorithm %s(%s);\n',obj.name, obj.ocp.name));
0037 
0038     obj.getSetInitInstructions(cppobj);   % Inits + sets
0039     
0040     fprintf(cppobj.fileMEX,sprintf('    returnValue returnvalue = %s.solve();\n', obj.name));
0041     
0042     fprintf(cppobj.fileMEX,'\n');
0043 
0044     
0045     fprintf(cppobj.fileMEX,'    VariablesGrid parameters; \n');
0046     fprintf(cppobj.fileMEX,sprintf('    %s.getParameters( parameters );\n', obj.name));    
0047     fprintf(cppobj.fileMEX,'    printf("\\n\\nResults for the parameters: \\n"); \n');
0048     fprintf(cppobj.fileMEX,'    printf("-----------------------------------------------\\n"); \n');
0049     
0050     for i=1:length(cppobj.p)
0051         fprintf(cppobj.fileMEX,'    printf(" ');
0052         fprintf(cppobj.fileMEX,sprintf('%s', cppobj.p{i}.name));
0053         fprintf(cppobj.fileMEX,' = %%.8e  \\n", parameters(0,');
0054         fprintf(cppobj.fileMEX,sprintf('%s', num2str(i-1)));
0055         fprintf(cppobj.fileMEX,')  ); \n');
0056     end
0057    
0058     fprintf(cppobj.fileMEX,'\n');
0059 
0060     fprintf(cppobj.fileMEX,'    VariablesGrid out_states; \n');
0061     fprintf(cppobj.fileMEX,'    VariablesGrid out_parameters; \n');
0062     fprintf(cppobj.fileMEX,'    VariablesGrid out_controls; \n');
0063     fprintf(cppobj.fileMEX,'    VariablesGrid out_disturbances; \n');
0064     fprintf(cppobj.fileMEX,'    VariablesGrid out_algstates; \n');
0065     
0066     fprintf(cppobj.fileMEX,sprintf('    %s.getDifferentialStates(out_states);\n', obj.name));
0067     if (~isempty(cppobj.u))
0068         fprintf(cppobj.fileMEX,sprintf('    %s.getControls(out_controls);\n', obj.name));
0069     end
0070     if (~isempty(cppobj.p))
0071         fprintf(cppobj.fileMEX,sprintf('    %s.getParameters(out_parameters);\n', obj.name));
0072     end
0073     if (~isempty(cppobj.w))
0074         fprintf(cppobj.fileMEX,sprintf('    %s.getDisturbances(out_disturbances);\n', obj.name));
0075     end
0076     if (~isempty(cppobj.z))
0077         fprintf(cppobj.fileMEX,sprintf('    %s.getAlgebraicStates(out_algstates);\n', obj.name));
0078     end
0079         
0080     if (ACADO_.results_to_file == true)
0081         % Write output to files
0082         fprintf(cppobj.fileMEX,sprintf('    out_states.printToFile( "%s_OUT_states.m","STATES",PS_MATLAB ); \n', cppobj.problemname));
0083         fprintf(cppobj.fileMEX,sprintf('    out_controls.printToFile( "%s_OUT_controls.m","CONTROLS",PS_MATLAB ); \n', cppobj.problemname));
0084         fprintf(cppobj.fileMEX,sprintf('    out_parameters.printToFile( "%s_OUT_parameters.m","PARAMETERS",PS_MATLAB ); \n', cppobj.problemname));
0085         fprintf(cppobj.fileMEX,sprintf('    out_disturbances.printToFile( "%s_OUT_disturbances.m","DISTURBANCES",PS_MATLAB ); \n', cppobj.problemname));
0086         fprintf(cppobj.fileMEX,sprintf('    out_algstates.printToFile( "%s_OUT_algebraicstates.m","ALGEBRAICSTATES",PS_MATLAB ); \n', cppobj.problemname));
0087     end
0088 
0089 
0090     fprintf(cppobj.fileMEX,'    const char* outputFieldNames[] = {"STATES", "CONTROLS", "PARAMETERS", "DISTURBANCES", "ALGEBRAICSTATES", "CONVERGENCE_ACHIEVED"}; \n');
0091     fprintf(cppobj.fileMEX,'    plhs[0] = mxCreateStructMatrix( 1,1,6,outputFieldNames ); \n');
0092     
0093     cppobj.getCPPlefthandout('OutS', 'outS', 'out_states')
0094     fprintf(cppobj.fileMEX,'    mxSetField( plhs[0],0,"STATES",OutS );\n');
0095     
0096     cppobj.getCPPlefthandout('OutC', 'outC', 'out_controls')
0097     fprintf(cppobj.fileMEX,'    mxSetField( plhs[0],0,"CONTROLS",OutC );\n\n');
0098     
0099     fprintf(cppobj.fileMEX,sprintf('    mxArray *%s = NULL;\n', 'OutP'));
0100     fprintf(cppobj.fileMEX,sprintf('    double  *%s = NULL;\n', 'outP'));
0101     fprintf(cppobj.fileMEX,sprintf('    %s = mxCreateDoubleMatrix( 1,%d,mxREAL ); \n', 'OutP', length(cppobj.p)));
0102     fprintf(cppobj.fileMEX,sprintf('    %s = mxGetPr( %s );\n', 'outP', 'OutP'));
0103     
0104     for i=1:length(cppobj.p)
0105         fprintf(cppobj.fileMEX,'    %s[0,%d] =  parameters(0,%d); \n', 'outP', i-1, i-1);
0106     end
0107     
0108     fprintf(cppobj.fileMEX,'    mxSetField( plhs[0],0,"PARAMETERS",OutP );\n \n');
0109 
0110     cppobj.getCPPlefthandout('OutW', 'outW', 'out_disturbances')
0111     fprintf(cppobj.fileMEX,'    mxSetField( plhs[0],0,"DISTURBANCES",OutW );\n');
0112 
0113     cppobj.getCPPlefthandout('OutZ', 'outZ', 'out_algstates')
0114     fprintf(cppobj.fileMEX,'    mxSetField( plhs[0],0,"ALGEBRAICSTATES",OutZ );\n');
0115 
0116     fprintf(cppobj.fileMEX,'    mxArray *OutConv = NULL;\n');
0117     fprintf(cppobj.fileMEX,'    if ( returnvalue == SUCCESSFUL_RETURN ) { OutConv = mxCreateDoubleScalar( 1 ); }else{ OutConv = mxCreateDoubleScalar( 0 ); } \n');
0118     fprintf(cppobj.fileMEX,'    mxSetField( plhs[0],0,"CONVERGENCE_ACHIEVED",OutConv );\n');    
0119     
0120     fprintf(cppobj.fileMEX,'\n');
0121     
0122     
0123 end
0124 
0125 end

www.acadotoolkit.org/matlab
Generated on Tue 01-Jun-2010 20:14:12 by m2html © 2005