export_qpoases_interface.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_qpoases_interface.hpp>
00033 #include <acado/code_generation/templates/templates.hpp>
00034 
00035 using namespace std;
00036 
00037 BEGIN_NAMESPACE_ACADO
00038 
00039 
00040 ExportQpOasesInterface::ExportQpOasesInterface(         const std::string& _headerFileName,
00041                                                                                                         const std::string& _sourceFileName,
00042                                                                                                         const std::string& _commonHeaderName,
00043                                                                                                         const std::string& _realString,
00044                                                                                                         const std::string& _intString,
00045                                                                                                         int _precision,
00046                                                                                                         const std::string& _commentString
00047                                                                                                         )
00048         : qpoHeader(QPOASES_HEADER, _headerFileName, _commonHeaderName, _realString, _intString, _precision, _commentString),
00049           qpoSource(QPOASES_SOURCE, _sourceFileName, _commonHeaderName, _realString, _intString, _precision, _commentString)
00050 {}
00051 
00052 
00053 returnValue ExportQpOasesInterface::configure(  const std::string& _prefix,
00054                                                                                                 const std::string& _solverDefine,
00055                                                                                                 const int nvmax,
00056                                                                                                 const int ncmax,
00057                                                                                                 const int nwsrmax,
00058                                                                                                 const std::string& _printLevel,
00059                                                                                                 bool _useSinglePrecision,
00060 
00061                                                                                                 const std::string& _commonHeader,
00062                                                                                                 const std::string& _namespace,
00063                                                                                                 const std::string& _primalSolution,
00064                                                                                                 const std::string& _dualSolution,
00065                                                                                                 const std::string& _sigma,
00066                                                                                                 bool _hotstartQP,
00067                                                                                                 bool _externalCholesky,
00068                                                                                                 const std::string& _qpH,
00069                                                                                                 const std::string& _qpR,
00070                                                                                                 const std::string& _qpg,
00071                                                                                                 const std::string& _qpA,
00072                                                                                                 const std::string& _qplb,
00073                                                                                                 const std::string& _qpub,
00074                                                                                                 const std::string& _qplbA,
00075                                                                                                 const std::string& _qpubA
00076                                                                                                 )
00077 {
00078         //
00079         // Source file configuration
00080         //
00081 
00082         stringstream s, ctor;
00083         string solverName;
00084         if (ncmax > 0)
00085         {
00086                 solverName = "QProblem";
00087 
00088                 s       << _qpH << ", ";
00089                 if (_externalCholesky == false)
00090                         s << _qpR << ", ";
00091                 s       << _qpg << ", " << _qpA << ", " << _qplb << ", " << _qpub << ", "
00092                         << _qplbA << ", " << _qpubA << ", " << "nWSR";
00093 
00094                 if ( (bool)_hotstartQP == true )
00095                         s << ", " << _dualSolution;
00096 
00097                 ctor << solverName << " qp(" << nvmax << ", " << ncmax << ")";
00098         }
00099         else
00100         {
00101                 solverName = "QProblemB";
00102 
00103                 s       << _qpH << ", ";
00104                 if (_externalCholesky == false)
00105                         s << _qpR << ", ";
00106                 s       << _qpg << ", " << _qplb << ", " << _qpub << ", " << "nWSR";
00107 
00108                 if ( (bool)_hotstartQP == true )
00109                         s << ", " << _dualSolution;
00110 
00111                 ctor << solverName << " qp( " << nvmax << " )";
00112         }
00113 
00114         qpoSource.dictionary[ "@ACADO_COMMON_HEADER@" ] =  _commonHeader;
00115         qpoSource.dictionary[ "@SOLVER_NAME@" ] =  solverName;
00116         qpoSource.dictionary[ "@PREFIX@" ] =  _prefix;
00117         qpoSource.dictionary[ "@USE_NAMESPACE@" ] =  _namespace;
00118         qpoSource.dictionary[ "@CALL_SOLVER@" ] =  s.str();
00119         qpoSource.dictionary[ "@PRIMAL_SOLUTION@" ] =  _primalSolution;
00120         qpoSource.dictionary[ "@DUAL_SOLUTION@" ] =  _dualSolution;
00121         qpoSource.dictionary[ "@CTOR@" ] =  ctor.str();
00122         qpoSource.dictionary[ "@SIGMA@" ] =  _sigma;
00123 
00124         // And then fill a template file
00125         qpoSource.fillTemplate();
00126 
00127         //
00128         // Header file configuration
00129         //
00130 
00131         // Configure the dictionary
00132         qpoHeader.dictionary[ "@PREFIX@" ] =  _prefix;
00133         qpoHeader.dictionary[ "@SOLVER_DEFINE@" ] =  _solverDefine;
00134 
00135         qpoHeader.dictionary[ "@NVMAX@" ] = toString( nvmax );
00136 
00137         qpoHeader.dictionary[ "@NCMAX@" ] = toString( ncmax );
00138 
00139         qpoHeader.dictionary[ "@NWSRMAX@" ] =  toString(nwsrmax > 0 ? nwsrmax : 3 * (nvmax + ncmax));
00140 
00141         qpoHeader.dictionary[ "@PRINT_LEVEL@" ] =  _printLevel;
00142 
00143         double eps;
00144         string realT;
00145         if ( _useSinglePrecision )
00146         {
00147                 eps = 1.193e-07;
00148                 realT = "float";
00149         }
00150         else
00151         {
00152                 eps = 2.221e-16;
00153                 realT = "double";
00154         }
00155         qpoHeader.dictionary[ "@EPS@" ] =  toString( eps );
00156         qpoHeader.dictionary[ "@REAL_T@" ] =  toString( realT );
00157 
00158         // And then fill a template file
00159         qpoHeader.fillTemplate();
00160 
00161         return SUCCESSFUL_RETURN;
00162 }
00163 
00164 returnValue ExportQpOasesInterface::exportCode()
00165 {
00166         qpoHeader.exportCode();
00167         qpoSource.exportCode();
00168 
00169         return SUCCESSFUL_RETURN;
00170 }
00171 
00172 
00173 CLOSE_NAMESPACE_ACADO


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