export_forces_generator.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 
34 using namespace std;
35 
37 
38 ExportForcesGenerator::ExportForcesGenerator( const std::string& _templateName,
39  const std::string& _fileName,
40  const std::string& _commonHeaderName,
41  const std::string& _realString,
42  const std::string& _intString,
43  int _precision,
44  const std::string& _commentString
45  ) : ExportTemplatedFile(_templateName, _fileName, _commonHeaderName, _realString, _intString, _precision, _commentString)
46 {}
47 
49  const unsigned _nu,
50  const unsigned _NN,
51  const std::vector< std::vector< unsigned > >& _lbIdx,
52  const std::vector< std::vector< unsigned > >& _ubIdx,
53  const std::vector< unsigned >& _AbDim,
54  const bool _constHessian,
55  const bool _diagHessian,
56  const bool _diagHessianN,
57  const bool _fixedInitialState,
58  const std::string& _solverName,
59  const unsigned _printLevel,
60  const unsigned _maxIterations,
61  const unsigned _parallel,
62  bool matlabGenerator,
63  bool warmStart
64  )
65 {
66  stringstream s;
67 
68  // Configure the dictionary
69 
70  s.str(std::string());
71  s << _nx;
72  dictionary[ "@NX@" ] = s.str();
73 
74  s.str(std::string());
75  s << _nu;
76  dictionary[ "@NU@" ] = s.str();
77 
78  // NOTE FORCES needs number of shooting nodes...
79  s.str(std::string());
80  s << _NN + 1;
81  dictionary[ "@N@" ] = s.str();
82 
83  s.str(std::string());
84  if (matlabGenerator == true)
85  for (unsigned i = 0; i < _lbIdx.size(); ++i)
86  {
87  if ( i )
88  s << ", ..." << endl << "\t";
89 
90  s << "{";
91  for (unsigned j = 0; j < _lbIdx[ i ].size(); ++j)
92  {
93  if ( j )
94  s << ", ";
95  s << _lbIdx[ i ][ j ] + 1;
96  }
97  s << "}";
98  }
99  else
100  // Python generator
101  for (unsigned i = 0; i < _lbIdx.size(); ++i)
102  {
103  if ( i )
104  s << ", " << endl << "\t";
105 
106  s << "[";
107  for (unsigned j = 0; j < _lbIdx[ i ].size(); ++j)
108  {
109  if ( j )
110  s << ", ";
111  s << _lbIdx[ i ][ j ] + 1;
112  }
113  s << "]";
114  }
115 
116  dictionary[ "@LB_IDX@" ] = s.str();
117 
118  s.str(std::string());
119  if (matlabGenerator == true)
120  for (unsigned i = 0; i < _ubIdx.size(); ++i)
121  {
122  if ( i )
123  s << ", ..." << endl << "\t";
124 
125  s << "{";
126  for (unsigned j = 0; j < _ubIdx[ i ].size(); ++j)
127  {
128  if ( j )
129  s << ", ";
130  s << _ubIdx[ i ][ j ] + 1;
131  }
132  s << "}";
133  }
134  else
135  // Python generator
136  for (unsigned i = 0; i < _ubIdx.size(); ++i)
137  {
138  if ( i )
139  s << ", " << endl << "\t";
140 
141  s << "[";
142  for (unsigned j = 0; j < _ubIdx[ i ].size(); ++j)
143  {
144  if ( j )
145  s << ", ";
146  s << _ubIdx[ i ][ j ] + 1;
147  }
148  s << "]";
149  }
150 
151  dictionary[ "@UB_IDX@" ] = s.str();
152 
153  s.str(std::string());
154  if (matlabGenerator == true)
155  for (unsigned i = 0; i < _NN + 1; ++i)
156  {
157  if ( i )
158  s << ", ..." << endl << "\t";
159 
160  if( i >= _AbDim.size() ) {
161  s << 0;
162  }
163  else {
164  s << _AbDim[ i ];
165  }
166  }
167 // else
168 // // Python generator
169 // return ACADOERROR( RET_NOT_YET_IMPLEMENTED );
170 
171  dictionary[ "@AB_DIM@" ] = s.str();
172 
173  s.str(std::string());
174  s << (_constHessian == true ? 1 : 0);
175  dictionary[ "@CONST_HESSIAN@" ] = s.str();
176 
177  s.str(std::string());
178  s << (_diagHessian == true ? 1 : 0);
179  dictionary[ "@DIAG_HESSIAN@" ] = s.str();
180 
181  s.str(std::string());
182  s << (_diagHessianN == true ? 1 : 0);
183  dictionary[ "@DIAG_HESSIAN_N@" ] = s.str();
184 
185  s.str(std::string());
186  s << (_fixedInitialState == true ? 1 : 0);
187  dictionary[ "@FIXED_INITIAL_STATE@" ] = s.str();
188 
189  dictionary[ "@SOLVER_NAME@" ] = _solverName;
190 
191  s.str(std::string());
192  s << _printLevel;
193  dictionary[ "@PRINT_LEVEL@" ] = s.str();
194 
195  s.str(std::string());
196  s << _maxIterations;
197  dictionary[ "@MAX_ITERATIONS@" ] = s.str();
198 
199  s.str(std::string());
200  s << _parallel;
201  dictionary[ "@PARALLEL@" ] = s.str();
202 
203  dictionary[ "@WARM_START@" ] = warmStart ? "2" : "0";
204 
205  // And then fill a template file
206  fillTemplate();
207 
208  return SUCCESSFUL_RETURN;
209 }
210 
std::map< std::string, std::string > dictionary
Allows to pass back messages to the calling function.
#define CLOSE_NAMESPACE_ACADO
Allows export of template files.
ExportForcesGenerator(const std::string &_templateName, 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())
#define BEGIN_NAMESPACE_ACADO
virtual returnValue configure()


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