export_variable.cpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  */
00025 
00026 
00027 
00035 #include <acado/code_generation/export_variable.hpp>
00036 #include <acado/code_generation/export_variable_internal.hpp>
00037 #include <acado/code_generation/export_arithmetic_statement.hpp>
00038 #include <acado/symbolic_expression/acado_syntax.hpp>
00039 
00040 
00041 BEGIN_NAMESPACE_ACADO
00042 
00043 
00044 static const double undefinedEntry = 1073741824.03125; // = 2^30 + 2^-5
00045 
00046 
00047 
00048 //
00049 // PUBLIC MEMBER FUNCTIONS:
00050 //
00051 
00052 ExportVariable::ExportVariable()
00053 {
00054         assignNode(new ExportVariableInternal("var", DMatrixPtr(new DMatrix( ))));
00055 }
00056 
00057 ExportVariable::ExportVariable( const std::string& _name,
00058                                                                 uint _nRows,
00059                                                                 uint _nCols,
00060                                                                 ExportType _type,
00061                                                                 ExportStruct _dataStruct,
00062                                                                 bool _callItByValue,
00063                                                                 const std::string& _prefix
00064                                                                 )
00065 {
00066         DMatrix m(_nRows, _nCols);
00067         m.setAll( undefinedEntry );
00068 
00069         assignNode(new ExportVariableInternal(_name, DMatrixPtr(new DMatrix( m )), _type, _dataStruct, _callItByValue, _prefix));
00070 }
00071 
00072 
00073 ExportVariable::ExportVariable( const std::string& _name,
00074                                                                 const DMatrix& _data,
00075                                                                 ExportType _type,
00076                                                                 ExportStruct _dataStruct,
00077                                                                 bool _callItByValue,
00078                                                                 const std::string& _prefix,
00079                                                                 bool _isGiven
00080                                                                 )
00081 {
00082         assignNode(new ExportVariableInternal(_name,
00083                         DMatrixPtr(new DMatrix( _data * (_isGiven == true ? 1.0 : undefinedEntry) )), _type, _dataStruct, _callItByValue, _prefix));
00084 }
00085 
00086 ExportVariable::ExportVariable( unsigned _nRows,
00087                                                                 unsigned _nCols,
00088                                                                 ExportType _type,
00089                                                                 ExportStruct _dataStruct,
00090                                                                 bool _callItByValue,
00091                                                                 const std::string& _prefix
00092                                                                 )
00093 {
00094         DMatrix m(_nRows, _nCols);
00095         m.setAll( undefinedEntry );
00096 
00097         assignNode(new ExportVariableInternal("var", DMatrixPtr(new DMatrix( m )), _type, _dataStruct, _callItByValue, _prefix));
00098 }
00099 
00100 ExportVariable::ExportVariable( const std::string& _name,
00101                                                                 const DMatrixPtr& _data,
00102                                                                 ExportType _type,
00103                                                                 ExportStruct _dataStruct,
00104                                                                 bool _callItByValue,
00105                                                                 const std::string& _prefix
00106                                                                 )
00107 {
00108         assignNode(new ExportVariableInternal(_name, _data, _type, _dataStruct, _callItByValue, _prefix));
00109 }
00110 
00111 void ExportVariable::simpleForward(const DMatrix& _value)
00112 {
00113         assignNode(new ExportVariableInternal("var", DMatrixPtr(new DMatrix( _value ))));
00114 }
00115 
00116 
00117 ExportVariable::ExportVariable( const double _data )
00118 {
00119         assignNode(new ExportVariableInternal("var", DMatrixPtr(new DMatrix( _data ))));
00120 }
00121 
00122 
00123 ExportVariable::~ExportVariable( )
00124 {}
00125 
00126 ExportVariable ExportVariable::clone() const
00127 {
00128         ExportVariable ret;
00129         if( !isNull() )
00130                 ret.assignNode( (*this)->clone() );
00131 
00132         return ret;
00133 }
00134 
00135 
00136 ExportVariableInternal* ExportVariable::operator->()
00137 {
00138         return (ExportVariableInternal*)(ExportArgument::operator->());
00139 }
00140 
00141 
00142 const ExportVariableInternal* ExportVariable::operator->() const
00143 {
00144         return (const ExportVariableInternal*)(ExportArgument::operator->());
00145 }
00146 
00147 
00148 ExportVariable& ExportVariable::setup(  const std::string& _name,
00149                                                                                 uint _nRows,
00150                                                                                 uint _nCols,
00151                                                                                 ExportType _type,
00152                                                                                 ExportStruct _dataStruct,
00153                                                                                 bool _callItByValue,
00154                                                                                 const std::string& _prefix
00155                                                                                 )
00156 {
00157         DMatrix m(_nRows, _nCols);
00158         m.setAll( undefinedEntry );
00159 
00160         assignNode(new ExportVariableInternal(_name, DMatrixPtr(new DMatrix( m )), _type, _dataStruct, _callItByValue, _prefix));
00161 
00162         return *this;
00163 }
00164 
00165 
00166 ExportVariable& ExportVariable::setup(  const std::string& _name,
00167                                                                                 const DMatrix& _data,
00168                                                                                 ExportType _type,
00169                                                                                 ExportStruct _dataStruct,
00170                                                                                 bool _callItByValue,
00171                                                                                 const std::string& _prefix,
00172                                                                                 bool _isGiven
00173                                                                                 )
00174 {
00175         assignNode(new ExportVariableInternal(_name,
00176                         DMatrixPtr(new DMatrix(_data * (_isGiven == true ? 1.0 : undefinedEntry))), _type, _dataStruct, _callItByValue, _prefix));
00177 
00178         return *this;
00179 }
00180 
00181 
00182 double ExportVariable::operator()(      uint rowIdx,
00183                                                                         uint colIdx
00184                                                                         ) const
00185 {
00186         return (*this)->getGivenMatrix()(rowIdx, colIdx);
00187 }
00188 
00189 
00190 double ExportVariable::operator()(      uint totalIdx
00191                                                                         ) const
00192 {
00193         return (*this)->getGivenMatrix()( totalIdx );
00194 }
00195 
00196 
00197 bool ExportVariable::isZero(    const ExportIndex& rowIdx,
00198                                                                 const ExportIndex& colIdx
00199                                                                 ) const
00200 {
00201         return (*this)->isZero(rowIdx, colIdx);
00202 }
00203 
00204 
00205 bool ExportVariable::isOne(     const ExportIndex& rowIdx,
00206                                                         const ExportIndex& colIdx
00207                                                         ) const
00208 {
00209         return (*this)->isOne(rowIdx, colIdx);
00210 }
00211 
00212 
00213 bool ExportVariable::isGiven(   const ExportIndex& rowIdx,
00214                                                                 const ExportIndex& colIdx
00215                                                                 ) const
00216 {
00217         return (*this)->isGiven(rowIdx, colIdx);
00218 }
00219 
00220 
00221 bool ExportVariable::isGiven( ) const
00222 {
00223         return (*this)->isGiven();
00224 }
00225 
00226 
00227 const std::string ExportVariable::get(  const ExportIndex& rowIdx,
00228                                                                                 const ExportIndex& colIdx
00229                                                                                 ) const
00230 {
00231         return (*this)->get(rowIdx, colIdx);
00232 }
00233 
00234 uint ExportVariable::getNumRows( ) const
00235 {
00236         return (*this)->getNumRows();
00237 }
00238 
00239 uint ExportVariable::getNumCols( ) const
00240 {
00241         return (*this)->getNumCols();
00242 }
00243 
00244 
00245 uint ExportVariable::getDim( ) const
00246 {
00247         return (*this)->getDim();
00248 }
00249 
00250 
00251 ExportArithmeticStatement operator+(    const ExportVariable& arg1,
00252                                                                                 const ExportVariable& arg2
00253                                                                                 )
00254 {
00255 //      ASSERT( getNumRows() == arg.getNumRows() );
00256 //      ASSERT( getNumCols() == arg.getNumCols() );
00257 
00258         return ExportArithmeticStatement(0, ESO_ASSIGN, arg1, ESO_ADD, arg2);
00259 }
00260 
00261 
00262 ExportArithmeticStatement operator-(    const ExportVariable& arg1,
00263                                                                                 const ExportVariable& arg2
00264                                                                                 )
00265 {
00266 //      ASSERT( getNumRows() == arg.getNumRows() );
00267 //      ASSERT( getNumCols() == arg.getNumCols() );
00268 
00269         return ExportArithmeticStatement(0, ESO_ASSIGN, arg1, ESO_SUBTRACT, arg2);
00270 }
00271 
00272 
00273 ExportArithmeticStatement operator+=(   const ExportVariable& arg1,
00274                                                                                 const ExportVariable& arg2
00275                                                                                 )
00276 {
00277 //      ASSERT( getNumRows() == arg.getNumRows() );
00278 //      ASSERT( getNumCols() == arg.getNumCols() );
00279 
00280         return ExportArithmeticStatement(arg1, ESO_ASSIGN, arg2, ESO_ADD_ASSIGN, 0);
00281 }
00282 
00283 
00284 ExportArithmeticStatement operator-=(   const ExportVariable& arg1,
00285                                                                                 const ExportVariable& arg2
00286                                                                                 )
00287 {
00288 //      ASSERT( getNumRows() == arg.getNumRows() );
00289 //      ASSERT( getNumCols() == arg.getNumCols() );
00290 
00291         return ExportArithmeticStatement(arg1, ESO_ASSIGN, arg2, ESO_SUBTRACT_ASSIGN, 0);
00292 }
00293 
00294 
00295 ExportArithmeticStatement operator*(    const ExportVariable& arg1,
00296                                                                                 const ExportVariable& arg2
00297                                                                                 )
00298 {
00299 //      ASSERT( getNumCols() == arg.getNumRows() );
00300 
00301         return ExportArithmeticStatement(0, ESO_ASSIGN, arg1, ESO_MULTIPLY, arg2);
00302 }
00303 
00304 
00305 ExportArithmeticStatement operator^(    const ExportVariable& arg1,
00306                                                                                 const ExportVariable& arg2
00307                                                                                 )
00308 {
00309 //      ASSERT( getNumRows() == arg.getNumRows() );
00310 
00311         return ExportArithmeticStatement(0, ESO_ASSIGN, arg1, ESO_MULTIPLY_TRANSPOSE, arg2);
00312 }
00313 
00314 
00315 ExportArithmeticStatement operator==(   const ExportVariable& arg1,
00316                                                                                 const ExportVariable& arg2
00317                                                                                 )
00318 {
00319 //      ASSERT( getNumRows() == arg.getNumRows() );
00320 //      ASSERT( getNumCols() == arg.getNumCols() );
00321 
00322         return ExportArithmeticStatement(arg1, ESO_ASSIGN, arg2, ESO_ASSIGN, 0);
00323 }
00324 
00325 
00326 ExportArithmeticStatement ExportVariable::operator==(   ExportArithmeticStatement arg
00327                                                                                                                 ) const
00328 {
00329 //      ASSERT( getNumRows() == arg.getNumRows() );
00330 //      ASSERT( getNumCols() == arg.getNumCols() );
00331 
00332         return ExportArithmeticStatement(*this, ESO_ASSIGN, arg.rhs1, arg.op1, arg.rhs2, arg.op2, arg.rhs3);
00333 }
00334 
00335 
00336 ExportArithmeticStatement ExportVariable::operator+(    ExportArithmeticStatement arg
00337                                                                                                                 ) const
00338 {
00339 //      ASSERT( getNumRows() == arg.getNumRows() );
00340 //      ASSERT( getNumCols() == arg.getNumCols() );
00341 //
00342 //      ASSERT( ( arg.op1 == ESO_MULTIPLY ) || ( arg.op1 == ESO_MULTIPLY_TRANSPOSE ) );
00343 
00344         return ExportArithmeticStatement( 0,ESO_UNDEFINED,arg.rhs1,arg.op1,arg.rhs2,ESO_ADD,*this );
00345 }
00346 
00347 
00348 ExportArithmeticStatement ExportVariable::operator-(    ExportArithmeticStatement arg
00349                                                                                                                 ) const
00350 {
00351 //      ASSERT( getNumRows() == arg.getNumRows() );
00352 //      ASSERT( getNumCols() == arg.getNumCols() );
00353 //
00354 //      ASSERT( ( arg.op1 == ESO_MULTIPLY ) || ( arg.op1 == ESO_MULTIPLY_TRANSPOSE ) );
00355 
00356         return ExportArithmeticStatement( 0,ESO_UNDEFINED,arg.rhs1,arg.op1,arg.rhs2,ESO_SUBTRACT,*this );
00357 }
00358 
00359 
00360 ExportArithmeticStatement ExportVariable::operator+=(   ExportArithmeticStatement arg
00361                                                                                                                 ) const
00362 {
00363 //      ASSERT( getNumRows() == arg.getNumRows() );
00364 //      ASSERT( getNumCols() == arg.getNumCols() );
00365 //
00366 //      ASSERT( ( arg.op1 == ESO_MULTIPLY ) ||
00367 //                      ( arg.op1 == ESO_MULTIPLY_TRANSPOSE ) ||
00368 //                      ( arg.op1 == ESO_ADD ) ||
00369 //                      ( arg.op1 == ESO_SUBTRACT ) );
00370 
00371         return ExportArithmeticStatement( *this,ESO_ADD_ASSIGN,arg.rhs1,arg.op1,arg.rhs2,arg.op2,arg.rhs3 );
00372 }
00373 
00374 
00375 ExportArithmeticStatement ExportVariable::operator-=(   ExportArithmeticStatement arg
00376                                                                                                                 ) const
00377 {
00378 //      ASSERT( getNumRows() == arg.getNumRows() );
00379 //      ASSERT( getNumCols() == arg.getNumCols() );
00380 //
00381 //      ASSERT( ( arg.op1 == ESO_MULTIPLY ) ||
00382 //                      ( arg.op1 == ESO_MULTIPLY_TRANSPOSE ) ||
00383 //                      ( arg.op1 == ESO_ADD ) ||
00384 //                      ( arg.op1 == ESO_SUBTRACT ) );
00385 
00386         return ExportArithmeticStatement( *this,ESO_SUBTRACT_ASSIGN,arg.rhs1,arg.op1,arg.rhs2,arg.op2,arg.rhs3 );
00387 }
00388 
00389 
00390 ExportVariable ExportVariable::getTranspose( ) const
00391 {
00392         return (*this)->getTranspose();
00393 }
00394 
00395 ExportVariable ExportVariable::getRow(  const ExportIndex& idx
00396                                                                                 ) const
00397 {
00398         return (*this)->getRow( idx );
00399 }
00400 
00401 
00402 ExportVariable ExportVariable::getCol(  const ExportIndex& idx
00403                                                                                 ) const
00404 {
00405         return (*this)->getCol( idx );
00406 }
00407 
00408 
00409 ExportVariable ExportVariable::getRows( const ExportIndex& idx1,
00410                                                                                 const ExportIndex& idx2
00411                                                                                 ) const
00412 {
00413         return (*this)->getRows(idx1, idx2);
00414 }
00415 
00416 
00417 ExportVariable ExportVariable::getCols( const ExportIndex& idx1,
00418                                                                                 const ExportIndex& idx2
00419                                                                                 ) const
00420 {
00421         return (*this)->getCols(idx1, idx2);
00422 }
00423 
00424 
00425 ExportVariable ExportVariable::getSubMatrix(    const ExportIndex& rowIdx1,
00426                                                                                                 const ExportIndex& rowIdx2,
00427                                                                                                 const ExportIndex& colIdx1,
00428                                                                                                 const ExportIndex& colIdx2
00429                                                                                                 ) const
00430 {
00431         return (*this)->getSubMatrix(rowIdx1, rowIdx2, colIdx1, colIdx2);
00432 }
00433 
00434 ExportVariable ExportVariable::getElement(      const ExportIndex& rowIdx,
00435                                                                                         const ExportIndex& colIdx
00436                                                                                         ) const
00437 {
00438         return (*this)->getSubMatrix(rowIdx, rowIdx + 1, colIdx, colIdx + 1);
00439 }
00440 
00441 
00442 ExportVariable ExportVariable::makeRowVector( ) const
00443 {
00444         return (*this)->makeRowVector();
00445 }
00446 
00447 
00448 ExportVariable ExportVariable::makeColVector( ) const
00449 {
00450         return (*this)->makeColVector();
00451 }
00452 
00453 
00454 bool ExportVariable::isVector( ) const
00455 {
00456         return (*this)->isVector();
00457 }
00458 
00459 
00460 const DMatrix& ExportVariable::getGivenMatrix( ) const
00461 {
00462         return (*this)->getGivenMatrix();
00463 }
00464 
00465 
00466 returnValue ExportVariable::print( ) const
00467 {
00468         return (*this)->print();
00469 }
00470 
00471 bool ExportVariable::isSubMatrix() const
00472 {
00473         return (*this)->isSubMatrix();
00474 }
00475 
00476 bool ExportVariable::isDiagonal() const
00477 {
00478         return (*this)->isDiagonal();
00479 }
00480 
00481 CLOSE_NAMESPACE_ACADO
00482 
00483 // end of file.


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:37:01