projection.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-2013 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 
37 
38 
39 
41 
42 
44  :SmoothOperator( ){
45 
46  scale = 1.0 ;
50 
51  nCount = 0;
52 }
53 
54 
55 Projection::Projection( const std::string &name_ )
56  :SmoothOperator( ){
57 
58  scale = 1.0 ;
62  name = name_ ;
63 
64  nCount = 0;
65 }
66 
67 
68 Projection::Projection( VariableType variableType_, int vIndex_, const std::string &name_ ) :SmoothOperator( )
69 {
70  variableType = variableType_ ;
71  vIndex = vIndex_ ;
73 
74  scale = 1.0 ;
78 
79  std::stringstream ss;
80  switch(variableType){
81 
83  ss << "xd" << "[" << vIndex <<"]";
84  break;
85 
86  case VT_ALGEBRAIC_STATE:
87  ss << "xa" << "[" << vIndex <<"]";
88  break;
89 
90  case VT_CONTROL:
91  ss << "u" << "[" << vIndex <<"]";
92  break;
93 
94  case VT_INTEGER_CONTROL:
95  ss << "v" << "[" << vIndex <<"]";
96  break;
97 
98  case VT_PARAMETER:
99  ss << "p" << "[" << vIndex <<"]";
100  break;
101 
102  case VT_ONLINE_DATA:
103  ss << "od" << "[" << vIndex <<"]";
104  break;
105 
107  ss << "q" << "[" << vIndex <<"]";
108  break;
109 
110  case VT_DISTURBANCE:
111  ss << "w" << "[" << vIndex <<"]";
112  break;
113 
114  case VT_TIME:
115  ss << "t" << "[" << vIndex <<"]";
116  break;
117 
119  ss << "a" << "[" << vIndex <<"]";
120  break;
121 
123  ss << "dx" << "[" << vIndex <<"]";
124  break;
125 
126  default: break;
127  }
128  name = ss.str();
129  nCount = 0;
130 }
131 
132 
134 
135 
137 
138  copy( arg );
139 }
140 
141 
143 
144  return new Projection(*this);
145 }
146 
147 
148 void Projection::copy( const Projection &arg ){
149 
150  if( this != &arg ){
151 
152  variableType = arg.variableType ;
154  vIndex = arg.vIndex ;
155  scale = arg.scale ;
156  name = arg.name ;
157  operatorName = arg.operatorName ;
158  curvature = arg.curvature ;
159  monotonicity = arg.monotonicity ;
160 
161  nCount = 0;
162  }
163 }
164 
165 
166 returnValue Projection::evaluate( int number, double *x, double *result ){
167 
168  result[0] = x[variableIndex];
169  return SUCCESSFUL_RETURN;
170 }
171 
172 
174 
176  return SUCCESSFUL_RETURN;
177 }
178 
179 
181 
182  if( variableIndex == index ){
183  return new DoubleConstant( 1.0 , NE_ONE );
184  }
185  else{
186  return new DoubleConstant( 0.0 , NE_ZERO );
187  }
188 }
189 
190 
192  VariableType *varType,
193  int *component,
194  Operator **seed,
195  int &nNewIS,
196  TreeProjection ***newIS ){
197 
198  return ADforwardProtected( dim, varType, component, seed, nNewIS, newIS );
199 }
200 
201 
202 
204  VariableType *varType ,
205  int *component,
206  Operator *seed ,
207  Operator **df ,
208  int &nNewIS ,
209  TreeProjection ***newIS ){
210 
211  return ADbackwardProtected( dim, varType, component, seed, df, nNewIS, newIS );
212 }
213 
214 
216  VariableType *varType ,
217  int *component ,
218  Operator *l ,
219  Operator **S ,
220  int dimS ,
221  Operator **dfS ,
222  Operator **ldf ,
223  Operator **H ,
224  int &nNewLIS ,
225  TreeProjection ***newLIS ,
226  int &nNewSIS ,
227  TreeProjection ***newSIS ,
228  int &nNewHIS ,
229  TreeProjection ***newHIS ){
230 
231  return ADsymmetricProtected( dim, varType, component, l, S, dimS, dfS, ldf, H, nNewLIS, newLIS, nNewSIS, newSIS, nNewHIS, newHIS );
232 }
233 
234 
235 
236 Operator* Projection::substitute( int index, const Operator *sub ){
237 
238  if( variableIndex == index ){
239  return sub->clone();
240  }
241  else{
242  return clone();
243  }
244 }
245 
246 
247 
249 
251 }
252 
253 
254 
255 
257 
258  if( variableType == var ) return BT_TRUE;
259  return BT_FALSE;
260 }
261 
262 
263 
264 
266  VariableType *varType,
267  int *component,
268  BooleanType *implicit_dep ){
269 
270  int run1 = 0;
271 
272  while( run1 < dim ){
273 
274  if( varType[run1] == variableType && component[run1] == vIndex ){
275  return BT_TRUE;
276  }
277  run1++;
278  }
279  return BT_FALSE;
280 }
281 
282 
284  VariableType *varType,
285  int *component,
286  BooleanType *implicit_dep ){
287 
288  return BT_TRUE;
289 }
290 
291 
293  VariableType *varType,
294  int *component,
295  BooleanType *implicit_dep ){
296 
297  return BT_TRUE;
298 }
299 
300 
302  VariableType *varType,
303  int *component,
304  BooleanType *implicit_dep ){
305 
306  return BT_TRUE;
307 }
308 
309 
311 
312  return monotonicity;
313 }
314 
315 
317 
318  return curvature;
319 }
320 
321 
323 
324  monotonicity = monotonicity_;
325  return SUCCESSFUL_RETURN;
326 }
327 
328 
330 
331  curvature = curvature_;
332  return SUCCESSFUL_RETURN;
333 }
334 
335 
336 returnValue Projection::AD_forward( int number, double *x, double *seed,
337  double *f, double *df ){
338 
339  f[0] = x[variableIndex];
340  df[0] = seed[variableIndex];
341 
342  return SUCCESSFUL_RETURN;
343 }
344 
345 
346 returnValue Projection::AD_forward( int number, double *seed, double *df ){
347 
348  df[0] = seed[variableIndex];
349  return SUCCESSFUL_RETURN;
350 }
351 
352 
353 returnValue Projection::AD_backward( int number, double seed, double *df ){
354 
355  df[variableIndex] = df[variableIndex] + seed;
356  return SUCCESSFUL_RETURN;
357 }
358 
359 
360 returnValue Projection::AD_forward2( int number, double *seed, double *dseed,
361  double *df, double *ddf ){
362 
363  df[0] = seed [variableIndex];
364  ddf[0] = dseed[variableIndex];
365  return SUCCESSFUL_RETURN;
366 }
367 
368 returnValue Projection::AD_backward2( int number, double seed1, double seed2,
369  double *df, double *ddf ){
370 
371  df[variableIndex] = df[variableIndex] + seed1;
372  ddf[variableIndex] = ddf[variableIndex] + seed2;
373 
374  return SUCCESSFUL_RETURN;
375 }
376 
377 
378 
379 std::ostream& Projection::print( std::ostream &stream ) const{
380 
381  return stream << name;
382 }
383 
384 
386 
387  return SUCCESSFUL_RETURN;
388 }
389 
390 
392 
393  return operatorName;
394 }
395 
396 
397 double Projection::getScale() const{
398 
399  return scale;
400 }
401 
402 
403 returnValue Projection::setScale( const double &scale_ ){
404 
405  scale = scale_;
406  return SUCCESSFUL_RETURN;
407 }
408 
409 
410 BooleanType Projection::isVariable( VariableType &varType, int &component ) const
411 {
412  varType = variableType;
413  component = vIndex ;
414 
415  return BT_TRUE;
416 }
417 
419 
421  vIndex, scale );
422  return SUCCESSFUL_RETURN;
423 }
424 
425 
427 
428  return variableIndex;
429 }
430 
431 
433 
434  return vIndex;
435 }
436 
437 
439 {
440  return variableType;
441 }
442 
443 
445 
446  indexList->addNewElement( variableType, vIndex );
447  return SUCCESSFUL_RETURN;
448 }
449 
450 
452 
453  return BT_TRUE;
454 }
455 
456 
458  VariableType *varType,
459  int *component,
460  Operator **seed,
461  int &nNewIS,
462  TreeProjection ***newIS ){
463 
464  int run1 = 0;
465 
466  while( run1 < dim ){
467 
468  if( varType[run1] == variableType && component[run1] == vIndex ){
469  return seed[run1]->clone();
470  }
471  run1++;
472  }
473 
474  return new DoubleConstant( 0.0 , NE_ZERO );
475 }
476 
477 
478 
480  VariableType *varType ,
481  int *component,
482  Operator *seed ,
483  Operator **df ,
484  int &nNewIS ,
485  TreeProjection ***newIS ){
486 
487  int run1 = 0;
488 
489  while( run1 < dim ){
490 
491  if( varType[run1] == variableType && component[run1] == vIndex ){
492 
493  if( df[run1]->isOneOrZero() == NE_ZERO ){
494  delete df[run1];
495  df[run1] = seed->clone();
496  }
497  else{
498 
499  if( seed-> isOneOrZero() != NE_ZERO ){
500 
501  Operator *tmp = df[run1]->clone();
502  delete df[run1];
503  df[run1] = new Addition(tmp->clone(),seed->clone());
504  delete tmp;
505  }
506  }
507 
508  break;
509  }
510  run1++;
511  }
512 
513  delete seed;
514  return SUCCESSFUL_RETURN;
515 }
516 
517 
519  VariableType *varType ,
520  int *component ,
521  Operator *l ,
522  Operator **S ,
523  int dimS ,
524  Operator **dfS ,
525  Operator **ldf ,
526  Operator **H ,
527  int &nNewLIS ,
528  TreeProjection ***newLIS ,
529  int &nNewSIS ,
530  TreeProjection ***newSIS ,
531  int &nNewHIS ,
532  TreeProjection ***newHIS ){
533 
534  int run1 = 0;
535 
536  while( run1 < dim ){
537 
538  if( varType[run1] == variableType && component[run1] == vIndex ){
539 
540  int run2;
541  for( run2 = 0; run2 < dimS; run2++ ){
542  delete dfS[run2];
543  dfS[run2] = S[run1*dimS+run2]->clone();
544  }
545 
546  if( ldf[run1]->isOneOrZero() == NE_ZERO ){
547  delete ldf[run1];
548  ldf[run1] = l->clone();
549  }
550  else{
551 
552  if( l->isOneOrZero() != NE_ZERO ){
553 
554  Operator *tmp = ldf[run1]->clone();
555  delete ldf[run1];
556  ldf[run1] = new Addition(tmp->clone(),l->clone());
557  delete tmp;
558  }
559  }
560  break;
561  }
562  run1++;
563  }
564 
565  delete l;
566  return SUCCESSFUL_RETURN;
567 }
568 
569 returnValue Projection::setVariableExportName( const VariableType &_type, const std::vector<std::string > &_name ){
570 
571  if (variableType == _type)
572  {
573  this->name = _name[vIndex];
574  }
575  return Operator::setVariableExportName(_type, _name);
576 }
577 
578 
580  return BT_TRUE;
581 }
582 
583 
585 
586 // end of file.
OperatorName
Definition: acado_types.hpp:72
virtual returnValue enumerateVariables(SymbolicIndexList *indexList)
Definition: projection.cpp:418
virtual BooleanType isPolynomialIn(int dim, VariableType *varType, int *component, BooleanType *implicit_dep)
Definition: projection.cpp:292
virtual MonotonicityType getMonotonicity()
Definition: projection.cpp:310
virtual std::ostream & print(std::ostream &stream) const
Definition: projection.cpp:379
virtual returnValue setScale(const double &scale_)
Definition: projection.cpp:403
Abstract base class for all scalar-valued symbolic operators.
Definition: operator.hpp:60
VariableType variableType
Definition: projection.hpp:547
VariableType getType() const
Definition: projection.cpp:438
virtual NeutralElement isOneOrZero() const =0
virtual void copy(const Projection &arg)
Definition: projection.cpp:148
CurvatureType curvature
Definition: projection.hpp:555
virtual Operator * substitute(int index, const Operator *sub)
Definition: projection.cpp:236
OperatorName operatorName
Definition: projection.hpp:553
Allows to pass back messages to the calling function.
virtual BooleanType isRationalIn(int dim, VariableType *varType, int *component, BooleanType *implicit_dep)
Definition: projection.cpp:301
virtual Operator * clone() const =0
virtual CurvatureType getCurvature()
Definition: projection.cpp:316
virtual BooleanType isTrivial() const
Definition: projection.cpp:579
virtual ~Projection()
Definition: projection.cpp:133
virtual returnValue setMonotonicity(MonotonicityType monotonicity_)
Definition: projection.cpp:322
virtual returnValue setVariableExportName(const VariableType &_type, const std::vector< std::string > &_name)
Definition: operator.cpp:223
virtual Operator * differentiate(int index)
Definition: projection.cpp:180
virtual void project(int &idx)=0
virtual returnValue AD_forward2(int number, double *seed1, double *seed2, double *df, double *ddf)
Definition: projection.cpp:360
#define CLOSE_NAMESPACE_ACADO
virtual NeutralElement isOneOrZero() const
Definition: projection.cpp:248
Manages the indices of SymbolicVariables.
VariableType
Definition: acado_types.hpp:95
virtual returnValue AD_backward2(int number, double seed1, double seed2, double *df, double *ddf)
Definition: projection.cpp:368
virtual BooleanType isSymbolic() const
Definition: projection.cpp:451
virtual returnValue setVariableExportName(const VariableType &_type, const std::vector< std::string > &_name)
Definition: projection.cpp:569
virtual BooleanType isVariable(VariableType &varType, int &component) const
Definition: projection.cpp:410
double scale
Definition: projection.hpp:550
virtual returnValue loadIndices(SymbolicIndexList *indexList)
Definition: projection.cpp:444
int determineVariableIndex(VariableType variableType_, int index_, double scale)
virtual returnValue ADsymmetricProtected(int dim, VariableType *varType, int *component, Operator *l, Operator **S, int dimS, Operator **dfS, Operator **ldf, Operator **H, int &nNewLIS, TreeProjection ***newLIS, int &nNewSIS, TreeProjection ***newSIS, int &nNewHIS, TreeProjection ***newHIS)
Definition: projection.cpp:518
virtual double getScale() const
Definition: projection.cpp:397
Implements the scalar addition operator within the symbolic expressions family.
Definition: addition.hpp:54
std::string name
Definition: projection.hpp:551
virtual Operator * AD_forward(int dim, VariableType *varType, int *component, Operator **seed, int &nNewIS, TreeProjection ***newIS)
Definition: projection.cpp:191
virtual Operator * clone() const
Definition: projection.cpp:142
Implements the projection operator within the symbolic operators family.
Definition: projection.hpp:55
MonotonicityType monotonicity
Definition: projection.hpp:556
#define BT_TRUE
Definition: acado_types.hpp:47
NeutralElement
Definition: acado_types.hpp:64
Abstract base class for all scalar-valued symbolic operators.
MonotonicityType
virtual Operator * ADforwardProtected(int dim, VariableType *varType, int *component, Operator **seed, int &nNewIS, TreeProjection ***newIS)
Definition: projection.cpp:457
virtual returnValue ADbackwardProtected(int dim, VariableType *varType, int *component, Operator *seed, Operator **df, int &nNewIS, TreeProjection ***newIS)
Definition: projection.cpp:479
Implements the tree-projection operator within the family of SymbolicOperators.
virtual returnValue clearBuffer()
Definition: projection.cpp:385
CurvatureType
virtual int getVariableIndex() const
Definition: projection.cpp:426
#define BEGIN_NAMESPACE_ACADO
Abstract base class for templated evaluation of operators.
virtual BooleanType isDependingOn(VariableType var) const
Definition: projection.cpp:256
#define BT_FALSE
Definition: acado_types.hpp:49
virtual int getGlobalIndex() const
Definition: projection.cpp:432
virtual returnValue evaluate(int number, double *x, double *result)
Definition: projection.cpp:166
virtual returnValue setCurvature(CurvatureType curvature_)
Definition: projection.cpp:329
BooleanType addNewElement(VariableType variableType_, int index_)
virtual OperatorName getName()
Definition: projection.cpp:391
virtual BooleanType isLinearIn(int dim, VariableType *varType, int *component, BooleanType *implicit_dep)
Definition: projection.cpp:283
virtual returnValue AD_backward(int dim, VariableType *varType, int *component, Operator *seed, Operator **df, int &nNewIS, TreeProjection ***newIS)
Definition: projection.cpp:203
Implements a scalar constant within the symbolic operators family.
int variableIndex
Definition: projection.hpp:548
virtual returnValue AD_symmetric(int dim, VariableType *varType, int *component, Operator *l, Operator **S, int dimS, Operator **dfS, Operator **ldf, Operator **H, int &nNewLIS, TreeProjection ***newLIS, int &nNewSIS, TreeProjection ***newSIS, int &nNewHIS, TreeProjection ***newHIS)
Definition: projection.cpp:215


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