export_variable.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 
26 
27 
39 
40 
42 
43 
44 static const double undefinedEntry = 1073741824.03125; // = 2^30 + 2^-5
45 
46 
47 
48 //
49 // PUBLIC MEMBER FUNCTIONS:
50 //
51 
53 {
55 }
56 
57 ExportVariable::ExportVariable( const std::string& _name,
58  uint _nRows,
59  uint _nCols,
60  ExportType _type,
61  ExportStruct _dataStruct,
62  bool _callItByValue,
63  const std::string& _prefix
64  )
65 {
66  DMatrix m(_nRows, _nCols);
68 
69  assignNode(new ExportVariableInternal(_name, DMatrixPtr(new DMatrix( m )), _type, _dataStruct, _callItByValue, _prefix));
70 }
71 
72 
73 ExportVariable::ExportVariable( const std::string& _name,
74  const DMatrix& _data,
75  ExportType _type,
76  ExportStruct _dataStruct,
77  bool _callItByValue,
78  const std::string& _prefix,
79  bool _isGiven
80  )
81 {
83  DMatrixPtr(new DMatrix( _data * (_isGiven == true ? 1.0 : undefinedEntry) )), _type, _dataStruct, _callItByValue, _prefix));
84 }
85 
87  unsigned _nCols,
88  ExportType _type,
89  ExportStruct _dataStruct,
90  bool _callItByValue,
91  const std::string& _prefix
92  )
93 {
94  DMatrix m(_nRows, _nCols);
96 
97  assignNode(new ExportVariableInternal("var", DMatrixPtr(new DMatrix( m )), _type, _dataStruct, _callItByValue, _prefix));
98 }
99 
100 ExportVariable::ExportVariable( const std::string& _name,
101  const DMatrixPtr& _data,
102  ExportType _type,
103  ExportStruct _dataStruct,
104  bool _callItByValue,
105  const std::string& _prefix
106  )
107 {
108  assignNode(new ExportVariableInternal(_name, _data, _type, _dataStruct, _callItByValue, _prefix));
109 }
110 
112 {
113  assignNode(new ExportVariableInternal("var", DMatrixPtr(new DMatrix( _value ))));
114 }
115 
116 
117 ExportVariable::ExportVariable( const double _data )
118 {
119  assignNode(new ExportVariableInternal("var", DMatrixPtr(new DMatrix( _data ))));
120 }
121 
122 
124 {}
125 
127 {
128  ExportVariable ret;
129  if( !isNull() )
130  ret.assignNode( (*this)->clone() );
131 
132  return ret;
133 }
134 
135 
137 {
139 }
140 
141 
143 {
145 }
146 
147 
148 ExportVariable& ExportVariable::setup( const std::string& _name,
149  uint _nRows,
150  uint _nCols,
151  ExportType _type,
152  ExportStruct _dataStruct,
153  bool _callItByValue,
154  const std::string& _prefix
155  )
156 {
157  DMatrix m(_nRows, _nCols);
158  m.setAll( undefinedEntry );
159 
160  assignNode(new ExportVariableInternal(_name, DMatrixPtr(new DMatrix( m )), _type, _dataStruct, _callItByValue, _prefix));
161 
162  return *this;
163 }
164 
165 
166 ExportVariable& ExportVariable::setup( const std::string& _name,
167  const DMatrix& _data,
168  ExportType _type,
169  ExportStruct _dataStruct,
170  bool _callItByValue,
171  const std::string& _prefix,
172  bool _isGiven
173  )
174 {
176  DMatrixPtr(new DMatrix(_data * (_isGiven == true ? 1.0 : undefinedEntry))), _type, _dataStruct, _callItByValue, _prefix));
177 
178  return *this;
179 }
180 
181 
183  uint colIdx
184  ) const
185 {
186  return (*this)->getGivenMatrix()(rowIdx, colIdx);
187 }
188 
189 
191  ) const
192 {
193  return (*this)->getGivenMatrix()( totalIdx );
194 }
195 
196 
198  const ExportIndex& colIdx
199  ) const
200 {
201  return (*this)->isZero(rowIdx, colIdx);
202 }
203 
204 
205 bool ExportVariable::isOne( const ExportIndex& rowIdx,
206  const ExportIndex& colIdx
207  ) const
208 {
209  return (*this)->isOne(rowIdx, colIdx);
210 }
211 
212 
214  const ExportIndex& colIdx
215  ) const
216 {
217  return (*this)->isGiven(rowIdx, colIdx);
218 }
219 
220 
222 {
223  return (*this)->isGiven();
224 }
225 
226 
227 const std::string ExportVariable::get( const ExportIndex& rowIdx,
228  const ExportIndex& colIdx
229  ) const
230 {
231  return (*this)->get(rowIdx, colIdx);
232 }
233 
235 {
236  return (*this)->getNumRows();
237 }
238 
240 {
241  return (*this)->getNumCols();
242 }
243 
244 
246 {
247  return (*this)->getDim();
248 }
249 
250 
252  const ExportVariable& arg2
253  )
254 {
255 // ASSERT( getNumRows() == arg.getNumRows() );
256 // ASSERT( getNumCols() == arg.getNumCols() );
257 
258  return ExportArithmeticStatement(0, ESO_ASSIGN, arg1, ESO_ADD, arg2);
259 }
260 
261 
263  const ExportVariable& arg2
264  )
265 {
266 // ASSERT( getNumRows() == arg.getNumRows() );
267 // ASSERT( getNumCols() == arg.getNumCols() );
268 
269  return ExportArithmeticStatement(0, ESO_ASSIGN, arg1, ESO_SUBTRACT, arg2);
270 }
271 
272 
274  const ExportVariable& arg2
275  )
276 {
277 // ASSERT( getNumRows() == arg.getNumRows() );
278 // ASSERT( getNumCols() == arg.getNumCols() );
279 
280  return ExportArithmeticStatement(arg1, ESO_ASSIGN, arg2, ESO_ADD_ASSIGN, 0);
281 }
282 
283 
285  const ExportVariable& arg2
286  )
287 {
288 // ASSERT( getNumRows() == arg.getNumRows() );
289 // ASSERT( getNumCols() == arg.getNumCols() );
290 
292 }
293 
294 
296  const ExportVariable& arg2
297  )
298 {
299 // ASSERT( getNumCols() == arg.getNumRows() );
300 
301  return ExportArithmeticStatement(0, ESO_ASSIGN, arg1, ESO_MULTIPLY, arg2);
302 }
303 
304 
306  const ExportVariable& arg2
307  )
308 {
309 // ASSERT( getNumRows() == arg.getNumRows() );
310 
312 }
313 
314 
316  const ExportVariable& arg2
317  )
318 {
319 // ASSERT( getNumRows() == arg.getNumRows() );
320 // ASSERT( getNumCols() == arg.getNumCols() );
321 
322  return ExportArithmeticStatement(arg1, ESO_ASSIGN, arg2, ESO_ASSIGN, 0);
323 }
324 
325 
327  ) const
328 {
329 // ASSERT( getNumRows() == arg.getNumRows() );
330 // ASSERT( getNumCols() == arg.getNumCols() );
331 
332  return ExportArithmeticStatement(*this, ESO_ASSIGN, arg.rhs1, arg.op1, arg.rhs2, arg.op2, arg.rhs3);
333 }
334 
335 
337  ) const
338 {
339 // ASSERT( getNumRows() == arg.getNumRows() );
340 // ASSERT( getNumCols() == arg.getNumCols() );
341 //
342 // ASSERT( ( arg.op1 == ESO_MULTIPLY ) || ( arg.op1 == ESO_MULTIPLY_TRANSPOSE ) );
343 
344  return ExportArithmeticStatement( 0,ESO_UNDEFINED,arg.rhs1,arg.op1,arg.rhs2,ESO_ADD,*this );
345 }
346 
347 
349  ) const
350 {
351 // ASSERT( getNumRows() == arg.getNumRows() );
352 // ASSERT( getNumCols() == arg.getNumCols() );
353 //
354 // ASSERT( ( arg.op1 == ESO_MULTIPLY ) || ( arg.op1 == ESO_MULTIPLY_TRANSPOSE ) );
355 
356  return ExportArithmeticStatement( 0,ESO_UNDEFINED,arg.rhs1,arg.op1,arg.rhs2,ESO_SUBTRACT,*this );
357 }
358 
359 
361  ) const
362 {
363 // ASSERT( getNumRows() == arg.getNumRows() );
364 // ASSERT( getNumCols() == arg.getNumCols() );
365 //
366 // ASSERT( ( arg.op1 == ESO_MULTIPLY ) ||
367 // ( arg.op1 == ESO_MULTIPLY_TRANSPOSE ) ||
368 // ( arg.op1 == ESO_ADD ) ||
369 // ( arg.op1 == ESO_SUBTRACT ) );
370 
371  return ExportArithmeticStatement( *this,ESO_ADD_ASSIGN,arg.rhs1,arg.op1,arg.rhs2,arg.op2,arg.rhs3 );
372 }
373 
374 
376  ) const
377 {
378 // ASSERT( getNumRows() == arg.getNumRows() );
379 // ASSERT( getNumCols() == arg.getNumCols() );
380 //
381 // ASSERT( ( arg.op1 == ESO_MULTIPLY ) ||
382 // ( arg.op1 == ESO_MULTIPLY_TRANSPOSE ) ||
383 // ( arg.op1 == ESO_ADD ) ||
384 // ( arg.op1 == ESO_SUBTRACT ) );
385 
386  return ExportArithmeticStatement( *this,ESO_SUBTRACT_ASSIGN,arg.rhs1,arg.op1,arg.rhs2,arg.op2,arg.rhs3 );
387 }
388 
389 
391 {
392  return (*this)->getTranspose();
393 }
394 
396  ) const
397 {
398  return (*this)->getRow( idx );
399 }
400 
401 
403  ) const
404 {
405  return (*this)->getCol( idx );
406 }
407 
408 
410  const ExportIndex& idx2
411  ) const
412 {
413  return (*this)->getRows(idx1, idx2);
414 }
415 
416 
418  const ExportIndex& idx2
419  ) const
420 {
421  return (*this)->getCols(idx1, idx2);
422 }
423 
424 
426  const ExportIndex& rowIdx2,
427  const ExportIndex& colIdx1,
428  const ExportIndex& colIdx2
429  ) const
430 {
431  return (*this)->getSubMatrix(rowIdx1, rowIdx2, colIdx1, colIdx2);
432 }
433 
435  const ExportIndex& colIdx
436  ) const
437 {
438  return (*this)->getSubMatrix(rowIdx, rowIdx + 1, colIdx, colIdx + 1);
439 }
440 
441 
443 {
444  return (*this)->makeRowVector();
445 }
446 
447 
449 {
450  return (*this)->makeColVector();
451 }
452 
453 
455 {
456  return (*this)->isVector();
457 }
458 
459 
461 {
462  return (*this)->getGivenMatrix();
463 }
464 
465 
467 {
468  return (*this)->print();
469 }
470 
472 {
473  return (*this)->isSubMatrix();
474 }
475 
477 {
478  return (*this)->isDiagonal();
479 }
480 
482 
483 // end of file.
void assignNode(SharedObjectNode *node)
Assign the node to a node class pointer (or null)
ExportVariable getRow(const ExportIndex &idx) const
bool isDiagonal() const
bool isSubMatrix() const
ExportVariable getRow(const ExportIndex &idx) const
ExportVariable makeRowVector() const
ExportVariableInternal * operator->()
ExportVariable clone() const
ExportVariable getTranspose() const
ExportVariable & setup(const std::string &_name, uint _nRows=1, uint _nCols=1, ExportType _type=REAL, ExportStruct _dataStruct=ACADO_LOCAL, bool _callItByValue=false, const std::string &_prefix=std::string())
bool isOne(const ExportIndex &rowIdx, const ExportIndex &colIdx) const
Allows to pass back messages to the calling function.
std::shared_ptr< GenericMatrix< double > > DMatrixPtr
Definition: matrix.hpp:463
friend ExportArithmeticStatement operator+=(const ExportVariable &arg1, const ExportVariable &arg2)
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
void setAll(const T &_value)
Definition: matrix.hpp:141
ExportVariable getRows(const ExportIndex &idx1, const ExportIndex &idx2) const
const DMatrix & getGivenMatrix() const
ExportVariable getElement(const ExportIndex &rowIdx, const ExportIndex &colIdx) const
Defines a matrix-valued variable to be used for exporting code.
#define CLOSE_NAMESPACE_ACADO
void simpleForward(const DMatrix &_value)
ExportVariable getSubMatrix(const ExportIndex &rowIdx1, const ExportIndex &rowIdx2, const ExportIndex &colIdx1, const ExportIndex &colIdx2) const
GenericMatrix< double > DMatrix
Definition: matrix.hpp:457
Defines a scalar-valued index variable to be used for exporting code.
static BEGIN_NAMESPACE_ACADO const double undefinedEntry
Allows to export code of different arithmetic statements.
virtual ~ExportVariable()
friend ExportArithmeticStatement operator-=(const ExportVariable &arg1, const ExportVariable &arg2)
friend ExportArithmeticStatement operator^(const ExportVariable &arg1, const ExportVariable &arg2)
const SharedObjectNode * get() const
Get a const pointer to the node.
ExportStruct
double operator()(uint rowIdx, uint colIdx) const
ExportVariable getCols(const ExportIndex &idx1, const ExportIndex &idx2) const
friend ExportArithmeticStatement operator+(const ExportVariable &arg1, const ExportVariable &arg2)
ExportArgumentInternal * operator->()
ExportVariable makeRowVector() const
ExportVariable getTranspose() const
ExportType
friend ExportArithmeticStatement operator==(const ExportVariable &arg1, const ExportVariable &arg2)
virtual uint getDim() const
bool isZero(const ExportIndex &rowIdx, const ExportIndex &colIdx) const
bool isVector() const
bool isGiven() const
bool isNull() const
Is a null pointer?
virtual uint getNumCols() const
ExportVariable getRows(const ExportIndex &idx1, const ExportIndex &idx2) const
ExportVariable getSubMatrix(const ExportIndex &_rowIdx1, const ExportIndex &_rowIdx2, const ExportIndex &_colIdx1, const ExportIndex &_colIdx2) const
#define BEGIN_NAMESPACE_ACADO
friend ExportArithmeticStatement operator-(const ExportVariable &arg1, const ExportVariable &arg2)
returnValue print() const
ExportVariable makeColVector() const
ExportVariable getCols(const ExportIndex &idx1, const ExportIndex &idx2) const
ExportVariable getCol(const ExportIndex &idx) const
friend ExportArithmeticStatement operator*(const ExportVariable &arg1, const ExportVariable &arg2)
ExportVariable getCol(const ExportIndex &idx) const
Defines a matrix-valued variable to be used for exporting code.
ExportVariable makeColVector() const
virtual uint getNumRows() const


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