export_qpoases3_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 ExportQpOases3Interface::ExportQpOases3Interface( 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  : ExportQpOasesInterface( _headerFileName,_sourceFileName,_commonHeaderName,_realString,_intString,_precision,_commentString )
49 {
50  qpoHeader.templateName = QPOASES3_HEADER;
51  qpoSource.templateName = QPOASES3_SOURCE;
52 }
53 
54 
55 returnValue ExportQpOases3Interface::configure( const std::string& _prefix,
56  const std::string& _solverDefine,
57  const int nvmax,
58  const int ncmax,
59  const int nwsrmax,
60  const std::string& _printLevel,
61  bool _useSinglePrecision,
62 
63  const std::string& _commonHeader,
64  const std::string& _namespace,
65  const std::string& _primalSolution,
66  const std::string& _dualSolution,
67  const std::string& _sigma,
68  bool _hotstartQP,
69  bool _externalCholesky,
70  const std::string& _qpH,
71  const std::string& _qpR,
72  const std::string& _qpg,
73  const std::string& _qpA,
74  const std::string& _qplb,
75  const std::string& _qpub,
76  const std::string& _qplbA,
77  const std::string& _qpubA
78  )
79 {
80  //
81  // Source file configuration
82  //
83 
84  stringstream s, ctor;
85  string solverName;
86  if (ncmax > 0)
87  {
88  solverName = "QProblem";
89 
90  if ( ( (bool)_hotstartQP == true ) || (_externalCholesky == false) )
91  {
92  s << "initW( &qp, ";
93  s << _qpH << ", " << _qpg << ", " << _qpA << ", " << _qplb << ", " << _qpub << ", "
94  << _qplbA << ", " << _qpubA << ", " << "&" << ExportStatement::fcnPrefix << _prefix << "_nWSR,0";
95 
96  if ( (bool)_hotstartQP == true )
97  s << ", 0," << _dualSolution << ", ";
98  else
99  s << ", 0,0, ";
100 
101  if (_externalCholesky == false)
102  s << "0,0," << _qpR;
103  else
104  s << "0,0,0";
105  }
106  else
107  {
108  s << "init( &qp, ";
109  s << _qpH << ", " << _qpg << ", " << _qpA << ", " << _qplb << ", " << _qpub << ", "
110  << _qplbA << ", " << _qpubA << ", " << "&" << ExportStatement::fcnPrefix << _prefix << "_nWSR,0";
111  }
112  s << " );";
113 
114  ctor << solverName << "CON( &qp, " << nvmax << "," << ncmax << ",HST_POSDEF )";
115  }
116  else
117  {
118  solverName = "QProblemB";
119 
120  if ( ( (bool)_hotstartQP == true ) || (_externalCholesky == false) )
121  {
122  s << "initW( &qp, ";
123  s << _qpH << ", " << _qpg << ", " << _qplb << ", " << _qpub << ", " << "&" << ExportStatement::fcnPrefix << _prefix << "_nWSR,0";
124 
125  if ( (bool)_hotstartQP == true )
126  s << ", 0," << _dualSolution << ", ";
127  else
128  s << ", 0,0, ";
129 
130  if (_externalCholesky == false)
131  s << "0," << _qpR;
132  else
133  s << "0,0";
134  }
135  else
136  {
137  s << "init( &qp, ";
138  s << _qpH << ", " << _qpg << ", " << _qplb << ", " << _qpub << ", " << "&" << ExportStatement::fcnPrefix << _prefix << "_nWSR,0";
139  }
140  s << " );";
141 
142  ctor << solverName << "CON( &qp, " << nvmax << ",HST_POSDEF )";
143  }
144 
145  qpoSource.dictionary[ "@ACADO_COMMON_HEADER@" ] = _commonHeader;
146  qpoSource.dictionary[ "@SOLVER_NAME@" ] = solverName;
147  qpoSource.dictionary[ "@PREFIX@" ] = _prefix;
148  qpoSource.dictionary[ "@USE_NAMESPACE@" ] = _namespace;
149  qpoSource.dictionary[ "@CALL_SOLVER@" ] = s.str();
150  qpoSource.dictionary[ "@PRIMAL_SOLUTION@" ] = _primalSolution;
151  qpoSource.dictionary[ "@DUAL_SOLUTION@" ] = _dualSolution;
152  qpoSource.dictionary[ "@CTOR@" ] = ctor.str();
153  qpoSource.dictionary[ "@SIGMA@" ] = _sigma;
154  qpoSource.dictionary[ "@MODULE_NAME@" ] = ExportStatement::fcnPrefix;
155  qpoSource.dictionary[ "@MODULE_PREFIX@" ] = ExportStatement::varPrefix;
156 
157  // And then fill a template file
159 
160  //
161  // Header file configuration
162  //
163 
164  // Configure the dictionary
165  qpoHeader.dictionary[ "@MODULE_NAME@" ] = ExportStatement::fcnPrefix;
166  qpoHeader.dictionary[ "@MODULE_PREFIX@" ] = ExportStatement::varPrefix;
167 
168  qpoHeader.dictionary[ "@PREFIX@" ] = _prefix;
169  qpoHeader.dictionary[ "@SOLVER_DEFINE@" ] = _solverDefine;
170 
171  qpoHeader.dictionary[ "@NVMAX@" ] = toString( nvmax );
172 
173  qpoHeader.dictionary[ "@NCMAX@" ] = toString( ncmax );
174 
175  qpoHeader.dictionary[ "@NWSRMAX@" ] = toString(nwsrmax > 0 ? nwsrmax : 3 * (nvmax + ncmax));
176 
177  qpoHeader.dictionary[ "@PRINT_LEVEL@" ] = _printLevel;
178 
179  double eps;
180  string realT;
181  if ( _useSinglePrecision )
182  {
183  eps = 1.193e-07;
184  realT = "float";
185  }
186  else
187  {
188  eps = 2.221e-16;
189  realT = "double";
190  }
191  qpoHeader.dictionary[ "@EPS@" ] = toString( eps );
192  qpoHeader.dictionary[ "@REAL_T@" ] = toString( realT );
193 
194  // And then fill a template file
196 
197  return SUCCESSFUL_RETURN;
198 }
199 
201 {
204 
205  return SUCCESSFUL_RETURN;
206 }
207 
208 
std::map< std::string, std::string > dictionary
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)
Allows to pass back messages to the calling function.
string toString(T const &value)
#define CLOSE_NAMESPACE_ACADO
static std::string fcnPrefix
#define BEGIN_NAMESPACE_ACADO
A class for generating the glue code for interfacing qpOASES.
ExportQpOases3Interface(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())
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