t_evaluation_point.hpp
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 
34 #ifndef ACADO_TOOLKIT_T_EVALUATION_POINT_HPP
35 #define ACADO_TOOLKIT_T_EVALUATION_POINT_HPP
36 
39 
41 
42 
56 template <typename T> class TevaluationPoint{
57 
58 friend class Function;
59 
60 //
61 // PUBLIC MEMBER FUNCTIONS:
62 //
63 
64 public:
65 
66 
69 
70 
72  TevaluationPoint( const Function &f,
73  uint nx_ = 0,
74  uint na_ = 0,
75  uint nu_ = 0,
76  uint np_ = 0,
77  uint nw_ = 0,
78  uint nd_ = 0,
79  uint N_ = 0 );
80 
81 
84 
86  virtual ~TevaluationPoint( );
87 
90 
91 
104  returnValue init( const Function &f,
105  uint nx_ = 0,
106  uint na_ = 0,
107  uint np_ = 0,
108  uint nu_ = 0,
109  uint nw_ = 0,
110  uint nd_ = 0,
111  uint N_ = 0 );
112 
113 
114  inline returnValue setT ( const Tmatrix<T> &t );
115  inline returnValue setX ( const Tmatrix<T> &x );
116  inline returnValue setXA( const Tmatrix<T> &xa );
117  inline returnValue setP ( const Tmatrix<T> &p );
118  inline returnValue setU ( const Tmatrix<T> &u );
119  inline returnValue setW ( const Tmatrix<T> &w );
120  inline returnValue setDX( const Tmatrix<T> &dx );
121 
122  inline Tmatrix<T> getT () const;
123  inline Tmatrix<T> getX () const;
124  inline Tmatrix<T> getXA() const;
125  inline Tmatrix<T> getP () const;
126  inline Tmatrix<T> getU () const;
127  inline Tmatrix<T> getW () const;
128  inline Tmatrix<T> getDX() const;
129 
130 
131 // PROTECTED MEMBER FUNCTIONS:
132 // ---------------------------
133 
134 protected:
135 
136  inline returnValue copy( const int *order, const Tmatrix<T> &rhs );
137 
138  void copy( const TevaluationPoint &rhs );
139  void deleteAll();
140 
141  void copyIdx( const uint &dim, const int *idx1, int **idx2 );
142 
143  inline Tmatrix<T> backCopy( const int *order, const uint &dim ) const;
144 
145  inline Tmatrix<T>* getEvaluationPointer() const;
146 
147 
148 // PROTECTED MEMBERS:
149 // ------------------
150 
151 protected:
152 
154  int **idx;
162  uint N ;
163 };
164 
165 
167 
169 
171 
172 
173 template <typename T> TevaluationPoint<T>::TevaluationPoint( ){ idx = 0; z = 0; }
174 template <typename T> TevaluationPoint<T>::TevaluationPoint( const TevaluationPoint<T>& rhs ){ copy(rhs); }
176 
177 template <typename T> TevaluationPoint<T>::TevaluationPoint( const Function &f ,
178  uint nx_, uint na_,
179  uint nu_, uint np_,
180  uint nw_, uint nd_, uint N_){
181 
182  idx = 0;
183  z = 0;
184  init(f,nx_,na_,nu_,np_,nw_,nd_,N_);
185 }
186 
187 
188 
190 
191  if( this != &rhs ){
192  deleteAll();
193  copy(rhs);
194  }
195  return *this;
196 }
197 
198 
199 template <typename T> returnValue TevaluationPoint<T>::init( const Function &f ,
200  uint nx_, uint na_, uint np_,
201  uint nu_, uint nw_, uint nd_,
202  uint N_ ){
203 
204  uint run1;
205  deleteAll();
206 
207  nx = acadoMax( nx_, f.getNX () );
208  na = acadoMax( na_, f.getNXA() );
209  np = acadoMax( np_, f.getNP () );
210  nu = acadoMax( nu_, f.getNU () );
211  nw = acadoMax( nw_, f.getNW () );
212  nd = acadoMax( nd_, f.getNDX() );
213  N = acadoMax( N_ , f.getNumberOfVariables()+1 );
214 
215  z = new Tmatrix<T>(N);
216 
217  idx = new int*[7];
218 
219  idx[0] = new int [1 ];
220  idx[1] = new int [nx];
221  idx[2] = new int [na];
222  idx[3] = new int [np];
223  idx[4] = new int [nu];
224  idx[5] = new int [nw];
225  idx[6] = new int [nd];
226 
227  idx[0][0] = f.index( VT_TIME, 0 );
228 
229  for( run1 = 0; run1 < nx; run1++ )
230  idx[1][run1] = f.index( VT_DIFFERENTIAL_STATE, run1 );
231 
232  for( run1 = 0; run1 < na; run1++ )
233  idx[2][run1] = f.index( VT_ALGEBRAIC_STATE, run1 );
234 
235  for( run1 = 0; run1 < np; run1++ )
236  idx[3][run1] = f.index( VT_PARAMETER, run1 );
237 
238  for( run1 = 0; run1 < nu; run1++ )
239  idx[4][run1] = f.index( VT_CONTROL, run1 );
240 
241  for( run1 = 0; run1 < nw; run1++ )
242  idx[5][run1] = f.index( VT_DISTURBANCE, run1 );
243 
244  for( run1 = 0; run1 < nd; run1++ )
245  idx[6][run1] = f.index( VT_DDIFFERENTIAL_STATE, run1 );
246 
247  return SUCCESSFUL_RETURN;
248 }
249 
250 
251 
252 //
253 // PROTECTED MEMBER FUNCTIONS:
254 //
255 
256 template <typename T> void TevaluationPoint<T>::copyIdx( const uint &dim, const int *idx1, int **idx2 ){
257 
258  uint i;
259  *idx2 = new int[dim];
260  for( i = 0; i < N; i++ )
261  *idx2[i] = idx1[i];
262 }
263 
264 
265 template <typename T> void TevaluationPoint<T>::copy( const TevaluationPoint<T> &rhs ){
266 
267  nx = rhs.nx;
268  na = rhs.na;
269  np = rhs.np;
270  nu = rhs.nu;
271  nw = rhs.nw;
272  nd = rhs.nd;
273  N = rhs.N ;
274 
275  if( rhs.z != 0 ){
276  z = new Tmatrix<T>(*rhs.z);
277  }
278  else z = 0;
279 
280  if( rhs.idx != 0 ){
281 
282  idx = new int*[7];
283  copyIdx( 1, rhs.idx[0], &idx[0] );
284  copyIdx( nx, rhs.idx[1], &idx[1] );
285  copyIdx( na, rhs.idx[2], &idx[2] );
286  copyIdx( np, rhs.idx[3], &idx[3] );
287  copyIdx( nu, rhs.idx[4], &idx[4] );
288  copyIdx( nw, rhs.idx[5], &idx[5] );
289  copyIdx( nd, rhs.idx[6], &idx[6] );
290  }
291  else idx = 0;
292 }
293 
294 
295 template <typename T> void TevaluationPoint<T>::deleteAll(){
296 
297  if( z != 0 ) delete z;
298 
299  if( idx != 0 ){
300  uint i;
301  for( i = 0; i < 7; i++ )
302  delete[] idx[i];
303  delete[] idx;
304  }
305 }
306 
308 
309 
310 
311 #include <acado/function/t_evaluation_point.ipp>
312 
313 
314 #endif // ACADO_TOOLKIT_T_EVALUATION_POINT_HPP
315 
316 /*
317  * end of file
318  */
Allows to setup and evaluate a general function based on SymbolicExpressions.
Definition: function_.hpp:59
Implements a templated dense matrix class.
Definition: t_matrix.hpp:53
int acadoMax(const int x, const int y)
Definition: acado_utils.cpp:64
returnValue init(const Function &f, uint nx_=0, uint na_=0, uint np_=0, uint nu_=0, uint nw_=0, uint nd_=0, uint N_=0)
Tmatrix< T > getW() const
int getNDX() const
Definition: function.cpp:217
Allows to pass back messages to the calling function.
int getNU() const
Definition: function.cpp:222
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
Tmatrix< T > backCopy(const int *order, const uint &dim) const
Tmatrix< T > * getEvaluationPointer() const
Tmatrix< T > getDX() const
#define CLOSE_NAMESPACE_ACADO
int getNXA() const
Definition: function.cpp:212
returnValue setW(const Tmatrix< T > &w)
returnValue setT(const Tmatrix< T > &t)
returnValue setXA(const Tmatrix< T > &xa)
Tmatrix< T > getP() const
int getNW() const
Definition: function.cpp:245
int getNP() const
Definition: function.cpp:233
Tmatrix< T > getT() const
void copyIdx(const uint &dim, const int *idx1, int **idx2)
returnValue setU(const Tmatrix< T > &u)
Tmatrix< T > getX() const
int index(VariableType variableType_, int index_) const
Definition: function.cpp:176
void rhs(const real_t *x, real_t *f)
Tmatrix< T > getXA() const
int getNX() const
Definition: function.cpp:207
returnValue copy(const int *order, const Tmatrix< T > &rhs)
#define BEGIN_NAMESPACE_ACADO
Tmatrix< T > getU() const
TevaluationPoint< T > & operator=(const TevaluationPoint< T > &rhs)
int getNumberOfVariables() const
Definition: function.cpp:264
returnValue setX(const Tmatrix< T > &x)
returnValue setDX(const Tmatrix< T > &dx)
Allows to setup function evaluation points.
Definition: function_.hpp:45
returnValue setP(const Tmatrix< T > &p)


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