export_hpmpc_interface.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
33 #include <acado/code_generation/templates/templates.hpp>
34 
35 #include <sstream>
36 
37 using namespace std;
38 
40 
41 ExportHpmpcInterface::ExportHpmpcInterface( const std::string& _fileName,
42  const std::string& _commonHeaderName,
43  const std::string& _realString,
44  const std::string& _intString,
45  int _precision,
46  const std::string& _commentString
47  ) : ExportTemplatedFile(HPMPC_INTERFACE, _fileName, _commonHeaderName, _realString, _intString, _precision, _commentString)
48 {}
49 
51  const unsigned _printLevel,
52  bool _useSinglePrecision,
53  bool _warmStart,
54  const std::string& _Hx,
55  const std::string& _Hu,
56  const std::string& _lbA,
57  const std::string& _ubA,
58  const unsigned _DimH,
59  const std::vector< unsigned >& _conDim,
60  const unsigned _NI,
61  const unsigned _NX,
62  const unsigned _NU
63  )
64 {
65  stringstream ss;
66  // Configure the dictionary
67  dictionary[ "@MAX_ITER@" ] = toString( _maxIter );
68  dictionary[ "@PRINT_LEVEL@" ] = _printLevel == 0 ? toString( 0 ) : toString( 1 );
69  dictionary[ "@PRECISION@" ] = _useSinglePrecision == true ? "1" : "0";
70  dictionary[ "@WARM_START@" ] = _warmStart == true ? "1" : "0";
71  dictionary[ "@MODULE_NAME@" ] = ExportStatement::fcnPrefix;
72  dictionary[ "@MODULE_PREFIX@" ] = ExportStatement::varPrefix;
73  dictionary[ "@QP_DIMMU@"] = toString( 2*(_NX+_NU)*(_NI+1) + 2*_DimH );
74  // Single precision is not supported yet!
75  if(_useSinglePrecision) return ACADOERROR( RET_NOT_YET_IMPLEMENTED );
76 
77  if (_conDim.size() > 0)
78  {
79  dictionary[ "@QP_Hx@" ] = _Hx;
80  dictionary[ "@QP_Hu@" ] = _Hu;
81  dictionary[ "@QP_LBA@" ] = _lbA;
82  dictionary[ "@QP_UBA@" ] = _ubA;
83 
84  ss.str( string() );
85  ss << "unsigned int nD[";
86  ss << _NI;
87  ss << " + 1] = {";
88  for (unsigned i = 0; i < _conDim.size(); ++i)
89  {
90  ss << _conDim[ i ];
91  if (i < _conDim.size() - 1)
92  ss << ", ";
93  }
94  ss << "};";
95  dictionary[ "@QP_ND_ARRAY@" ] = ss.str();
96  }
97  else
98  {
99  dictionary[ "@QP_D@" ] = dictionary[ "@QP_LBA@" ] = dictionary[ "@QP_UBA@" ] = "0";
100  ss.str( string() );
101  ss << "unsigned int nD[";
102  ss << _NI;
103  ss << " + 1]; for (kk = 0; kk < ";
104  ss << _NI;
105  ss << " + 1; nD[ kk++ ] = 0);";
106  dictionary[ "@QP_ND_ARRAY@" ] = ss.str();
107  }
108 
109  // And then fill a template file
110  fillTemplate();
111 
112  return SUCCESSFUL_RETURN;
113 }
114 
std::map< std::string, std::string > dictionary
Allows to pass back messages to the calling function.
ExportHpmpcInterface(const std::string &_fileName, const std::string &_commonHeaderName="", const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16, const std::string &_commentString=std::string())
string toString(T const &value)
#define CLOSE_NAMESPACE_ACADO
Allows export of template files.
static std::string fcnPrefix
#define BEGIN_NAMESPACE_ACADO
virtual returnValue configure()
static std::string varPrefix
#define ACADOERROR(retval)


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:34