export_forces_generator.cpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  */
00025 
00032 #include <acado/code_generation/export_forces_generator.hpp>
00033 
00034 using namespace std;
00035 
00036 BEGIN_NAMESPACE_ACADO
00037 
00038 ExportForcesGenerator::ExportForcesGenerator(   const std::string& _templateName,
00039                                                                                                 const std::string& _fileName,
00040                                                                                                 const std::string& _commonHeaderName,
00041                                                                                                 const std::string& _realString,
00042                                                                                                 const std::string& _intString,
00043                                                                                                 int _precision,
00044                                                                                                 const std::string& _commentString
00045                                                 ) : ExportTemplatedFile(_templateName, _fileName, _commonHeaderName, _realString, _intString, _precision, _commentString)
00046 {}
00047 
00048 returnValue ExportForcesGenerator::configure(   const unsigned _nx,
00049                                                                                                 const unsigned _nu,
00050                                                                                                 const unsigned _NN,
00051                                                                                                 const std::vector< std::vector< unsigned > >& _lbIdx,
00052                                                                                                 const std::vector< std::vector< unsigned > >& _ubIdx,
00053                                                                                                 const bool _constHessian,
00054                                                                                                 const bool _diagHessian,
00055                                                                                                 const bool _diagHessianN,
00056                                                                                                 const bool _fixedInitialState,
00057                                                                                                 const std::string& _solverName,
00058                                                                                                 const unsigned _printLevel,
00059                                                                                                 const unsigned _maxIterations,
00060                                                                                                 const unsigned _parallel,
00061                                                                                                 bool matlabGenerator,
00062                                                                                                 bool warmStart
00063                                                                                                 )
00064 {
00065         stringstream s;
00066 
00067         // Configure the dictionary
00068 
00069         s.str(std::string());
00070         s << _nx;
00071         dictionary[ "@NX@" ] =  s.str();
00072 
00073         s.str(std::string());
00074         s << _nu;
00075         dictionary[ "@NU@" ] =  s.str();
00076 
00077         // NOTE FORCES needs number of shooting nodes...
00078         s.str(std::string());
00079         s << _NN + 1;
00080         dictionary[ "@N@" ] =  s.str();
00081 
00082         s.str(std::string());
00083         if (matlabGenerator == true)
00084                 for (unsigned i = 0; i < _lbIdx.size(); ++i)
00085                 {
00086                         if ( i )
00087                                 s << ", ..." << endl << "\t";
00088 
00089                         s << "{";
00090                         for (unsigned j = 0; j < _lbIdx[ i ].size(); ++j)
00091                         {
00092                                 if ( j )
00093                                         s << ", ";
00094                                 s << _lbIdx[ i ][ j ] + 1;
00095                         }
00096                         s << "}";
00097                 }
00098         else
00099                 // Python generator
00100                 for (unsigned i = 0; i < _lbIdx.size(); ++i)
00101                 {
00102                         if ( i )
00103                                 s << ", " << endl << "\t";
00104 
00105                         s << "[";
00106                         for (unsigned j = 0; j < _lbIdx[ i ].size(); ++j)
00107                         {
00108                                 if ( j )
00109                                         s << ", ";
00110                                 s << _lbIdx[ i ][ j ] + 1;
00111                         }
00112                         s << "]";
00113                 }
00114 
00115         dictionary[ "@LB_IDX@" ] =  s.str();
00116 
00117         s.str(std::string());
00118         if (matlabGenerator == true)
00119                 for (unsigned i = 0; i < _ubIdx.size(); ++i)
00120                 {
00121                         if ( i )
00122                                 s << ", ..." << endl << "\t";
00123 
00124                         s << "{";
00125                         for (unsigned j = 0; j < _ubIdx[ i ].size(); ++j)
00126                         {
00127                                 if ( j )
00128                                         s << ", ";
00129                                 s << _ubIdx[ i ][ j ] + 1;
00130                         }
00131                         s << "}";
00132                 }
00133         else
00134                 // Python generator
00135                 for (unsigned i = 0; i < _ubIdx.size(); ++i)
00136                 {
00137                         if ( i )
00138                                 s << ", " << endl << "\t";
00139 
00140                         s << "[";
00141                         for (unsigned j = 0; j < _ubIdx[ i ].size(); ++j)
00142                         {
00143                                 if ( j )
00144                                         s << ", ";
00145                                 s << _ubIdx[ i ][ j ] + 1;
00146                         }
00147                         s << "]";
00148                 }
00149 
00150         dictionary[ "@UB_IDX@" ] =  s.str();
00151 
00152         s.str(std::string());
00153         s << (_constHessian == true ? 1 : 0);
00154         dictionary[ "@CONST_HESSIAN@" ] =  s.str();
00155 
00156         s.str(std::string());
00157         s << (_diagHessian == true ? 1 : 0);
00158         dictionary[ "@DIAG_HESSIAN@" ] =  s.str();
00159 
00160         s.str(std::string());
00161         s << (_diagHessianN == true ? 1 : 0);
00162         dictionary[ "@DIAG_HESSIAN_N@" ] =  s.str();
00163 
00164         s.str(std::string());
00165         s << (_fixedInitialState == true ? 1 : 0);
00166         dictionary[ "@FIXED_INITIAL_STATE@" ] =  s.str();
00167 
00168         dictionary[ "@SOLVER_NAME@" ] =  _solverName;
00169 
00170         s.str(std::string());
00171         s << _printLevel;
00172         dictionary[ "@PRINT_LEVEL@" ] =  s.str();
00173 
00174         s.str(std::string());
00175         s << _maxIterations;
00176         dictionary[ "@MAX_ITERATIONS@" ] =  s.str();
00177 
00178         s.str(std::string());
00179         s << _parallel;
00180         dictionary[ "@PARALLEL@" ] =  s.str();
00181 
00182         dictionary[ "@WARM_START@" ] =  warmStart ? "2" : "0";
00183 
00184         // And then fill a template file
00185         fillTemplate();
00186 
00187         return SUCCESSFUL_RETURN;
00188 }
00189 
00190 CLOSE_NAMESPACE_ACADO


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:58:09