export_qpoases_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 using namespace std;
36 
38 
39 
40 ExportQpOasesInterface::ExportQpOasesInterface( const std::string& _headerFileName,
41  const std::string& _sourceFileName,
42  const std::string& _commonHeaderName,
43  const std::string& _realString,
44  const std::string& _intString,
45  int _precision,
46  const std::string& _commentString
47  )
48  : qpoHeader(QPOASES_HEADER, _headerFileName, _commonHeaderName, _realString, _intString, _precision, _commentString),
49  qpoSource(QPOASES_SOURCE, _sourceFileName, _commonHeaderName, _realString, _intString, _precision, _commentString)
50 {}
51 
52 
53 returnValue ExportQpOasesInterface::configure( const std::string& _prefix,
54  const std::string& _solverDefine,
55  const int nvmax,
56  const int ncmax,
57  const int nwsrmax,
58  const std::string& _printLevel,
59  bool _useSinglePrecision,
60 
61  const std::string& _commonHeader,
62  const std::string& _namespace,
63  const std::string& _primalSolution,
64  const std::string& _dualSolution,
65  const std::string& _sigma,
66  bool _hotstartQP,
67  bool _externalCholesky,
68  const std::string& _qpH,
69  const std::string& _qpR,
70  const std::string& _qpg,
71  const std::string& _qpA,
72  const std::string& _qplb,
73  const std::string& _qpub,
74  const std::string& _qplbA,
75  const std::string& _qpubA
76  )
77 {
78  //
79  // Source file configuration
80  //
81 
82  stringstream s, ctor;
83  string solverName;
84  if (ncmax > 0)
85  {
86  solverName = "QProblem";
87 
88  s << _qpH << ", ";
89  if (_externalCholesky == false)
90  s << _qpR << ", ";
91  s << _qpg << ", " << _qpA << ", " << _qplb << ", " << _qpub << ", "
92  << _qplbA << ", " << _qpubA << ", " << ExportStatement::fcnPrefix << _prefix << "_nWSR";
93 
94  if ( (bool)_hotstartQP == true )
95  s << ", " << _dualSolution;
96 
97  ctor << solverName << " qp(" << nvmax << ", " << ncmax << ")";
98  }
99  else
100  {
101  solverName = "QProblemB";
102 
103  s << _qpH << ", ";
104  if (_externalCholesky == false)
105  s << _qpR << ", ";
106  s << _qpg << ", " << _qplb << ", " << _qpub << ", " << ExportStatement::fcnPrefix << _prefix << "_nWSR";
107 
108  if ( (bool)_hotstartQP == true )
109  s << ", " << _dualSolution;
110 
111  ctor << solverName << " qp( " << nvmax << " )";
112  }
113 
114  qpoSource.dictionary[ "@ACADO_COMMON_HEADER@" ] = _commonHeader;
115  qpoSource.dictionary[ "@SOLVER_NAME@" ] = solverName;
116  qpoSource.dictionary[ "@PREFIX@" ] = _prefix;
117  qpoSource.dictionary[ "@USE_NAMESPACE@" ] = _namespace;
118  qpoSource.dictionary[ "@CALL_SOLVER@" ] = s.str();
119  qpoSource.dictionary[ "@PRIMAL_SOLUTION@" ] = _primalSolution;
120  qpoSource.dictionary[ "@DUAL_SOLUTION@" ] = _dualSolution;
121  qpoSource.dictionary[ "@CTOR@" ] = ctor.str();
122  qpoSource.dictionary[ "@SIGMA@" ] = _sigma;
123  qpoSource.dictionary[ "@MODULE_NAME@" ] = ExportStatement::fcnPrefix;
124  qpoSource.dictionary[ "@MODULE_PREFIX@" ] = ExportStatement::varPrefix;
125 
126  // And then fill a template file
128 
129  //
130  // Header file configuration
131  //
132 
133  // Configure the dictionary
134  qpoHeader.dictionary[ "@MODULE_NAME@" ] = ExportStatement::fcnPrefix;
135  qpoHeader.dictionary[ "@MODULE_PREFIX@" ] = ExportStatement::varPrefix;
136 
137  qpoHeader.dictionary[ "@PREFIX@" ] = _prefix;
138  qpoHeader.dictionary[ "@SOLVER_DEFINE@" ] = _solverDefine;
139 
140  qpoHeader.dictionary[ "@NVMAX@" ] = toString( nvmax );
141 
142  qpoHeader.dictionary[ "@NCMAX@" ] = toString( ncmax );
143 
144  qpoHeader.dictionary[ "@NWSRMAX@" ] = toString(nwsrmax > 0 ? nwsrmax : 3 * (nvmax + ncmax));
145 
146  qpoHeader.dictionary[ "@PRINT_LEVEL@" ] = _printLevel;
147 
148  double eps;
149  string realT;
150  if ( _useSinglePrecision )
151  {
152  eps = 1.193e-07;
153  realT = "float";
154  }
155  else
156  {
157  eps = 2.221e-16;
158  realT = "double";
159  }
160  qpoHeader.dictionary[ "@EPS@" ] = toString( eps );
161  qpoHeader.dictionary[ "@REAL_T@" ] = toString( realT );
162 
163  // And then fill a template file
165 
166  return SUCCESSFUL_RETURN;
167 }
168 
170 {
173 
174  return SUCCESSFUL_RETURN;
175 }
176 
177 
std::map< std::string, std::string > dictionary
Allows to pass back messages to the calling function.
virtual returnValue configure(const std::string &_prefix, const std::string &_solverDefine, const int nvmax, const int ncmax, const int nwsrmax, const std::string &_printLevel, bool _useSinglePrecision, const std::string &_commonHeader, const std::string &_namespace, const std::string &_primalSolution, const std::string &_dualSolution, const std::string &_sigma, bool _hotstartQP, bool _externalCholesky, const std::string &_qpH, const std::string &_qpR, const std::string &_qpg, const std::string &_qpA, const std::string &_qplb, const std::string &_qpub, const std::string &_qplbA, const std::string &_qpubA)
string toString(T const &value)
#define CLOSE_NAMESPACE_ACADO
ExportQpOasesInterface(const std::string &_headerFileName, const std::string &_sourceFileName, const std::string &_commonHeaderName="", const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16, const std::string &_commentString=std::string())
static std::string fcnPrefix
virtual returnValue exportCode()
#define BEGIN_NAMESPACE_ACADO
virtual returnValue exportCode() const
Definition: export_file.cpp:82
static std::string varPrefix


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