57 globalExportVariableName =
"acado_aux";
75 for( run1 = 0; run1 < dim; run1++ ){
76 f[run1] = arg.
f[run1]->
clone();
82 if( arg.
sub == NULL ){
88 lhs_comp = (
int*)calloc(n,
sizeof(
int));
90 for( run1 = 0; run1 < n; run1++ ){
104 for( run1 = 0; run1 < dim; run1++ ){
111 for( run1 = 0; run1 < n; run1++ ){
120 if( lhs_comp != NULL ){
134 for( run1 = 0; run1 < dim; run1++ ){
141 for( run1 = 0; run1 < n; run1++ ){
148 if( lhs_comp != NULL ){
165 for( run1 = 0; run1 < dim; run1++ ){
166 f[run1] = arg.
f[run1]->
clone();
172 if( arg.
sub == NULL ){
178 lhs_comp = (
int*)calloc(n,
sizeof(
int));
180 for( run1 = 0; run1 < n; run1++ ){
182 lhs_comp[run1] = arg.
lhs_comp[run1];
194 expression = safeCopy;
205 for( run1 = 0; run1 < arg.getDim(); run1++ ){
213 f[dim] = arg.element[run1]->clone();
214 f[dim]-> loadIndices ( indexList );
217 (indexList->getNumberOfOperators())*
sizeof(
Operator*));
218 lhs_comp = (
int*)realloc(lhs_comp,
219 (indexList->getNumberOfOperators())*
sizeof(
int));
221 indexList->getOperators( sub, lhs_comp, &n );
225 sub[nn]-> enumerateVariables( indexList );
229 f[dim]-> enumerateVariables( indexList );
242 for( run1 = 0; run1 < n; run1++ ){
245 lhs_comp[run1] ) ] );
247 for( run1 = 0; run1 < dim; run1++ ){
248 f[run1]->evaluate( 0, x, &result[run1] );
260 cout <<
"Symbolic expression evaluation:" << endl;
262 for( run1 = 0; run1 < n; run1++ ){
265 lhs_comp[run1] ) ] );
267 cout <<
"sub[" << lhs_comp[ run1 ] <<
"] = " 272 for (run1 = 0; run1 < dim; run1++) {
273 f[run1]->evaluate(0, x, &result[run1]);
276 cout <<
"f[" << run1 <<
"] = " << scientific << result[run1] << endl;
288 for( run1 = 0; run1 < n; run1++ ){
290 lhs_comp[run1] ) ] );
292 for( run1 = 0; run1 < dim; run1++ ){
293 f[run1]->evaluate( number, x, &result[run1] );
314 int sub_index = index(variableType_, index_ );
327 if( fabs( sub_ ) > 10.0*
EPS ){
328 if( fabs( 1.0 - sub_ ) < 10.0*
EPS ){
330 for( run1 = 0; run1 < dim; run1++ ){
337 for( run1 = 0; run1 < dim; run1++ ){
345 for( run1 = 0; run1 < dim; run1++ ){
358 tmp.
lhs_comp = (
int*)calloc(n,
sizeof(
int));
362 if( fabs(sub_) > 10.0*
EPS ){
363 if( fabs( 1.0-sub_ ) < 10.0*
EPS ){
365 for( run1 = 0; run1 < n; run1++ ){
367 tmp.
lhs_comp[run1] = lhs_comp[run1];
373 for( run1 = 0; run1 < n; run1++ ){
375 tmp.
lhs_comp[run1] = lhs_comp[run1];
382 for( run1 = 0; run1 < n; run1++ ){
384 tmp.
lhs_comp[run1] = lhs_comp[run1];
405 if( f[0]->isOneOrZero() ==
NE_ZERO ){
408 if( f[0]->isOneOrZero() ==
NE_ONE ){
417 for( run1 = 1; run1 < dim; run1++ ){
420 if( f[run1]->isOneOrZero() !=
NE_ONE ){
425 if( f[run1]->isOneOrZero() !=
NE_ZERO ){
438 int nn = variable.
getDim();
443 int *component =
new int [nn];
445 for( run1 = 0; run1 < nn; run1++ ){
470 for( run1 = 0; run1 < n; run1++ ){
471 implicit_dep[run1] = sub[run1]->
isDependingOn( 1, varType, component, implicit_dep );
473 for( run1 = 0; run1 < dim; run1++ ){
474 if( f[run1]->isDependingOn( 1, varType, component, implicit_dep ) ==
BT_TRUE ){
475 delete[] implicit_dep;
482 delete[] implicit_dep;
491 int nn = variable.
getDim();
496 int *component =
new int [nn];
498 for( run1 = 0; run1 < nn; run1++ ){
523 for( run1 = 0; run1 < n; run1++ ){
524 implicit_dep[run1] = sub[run1]->
isLinearIn( 1, varType, component, implicit_dep );
526 for( run1 = 0; run1 < dim; run1++ ){
527 if( f[run1]->isLinearIn( 1, varType, component, implicit_dep ) ==
BT_FALSE ){
528 delete[] implicit_dep;
535 delete[] implicit_dep;
544 int nn = variable.
getDim();
549 int *component =
new int [nn];
551 for( run1 = 0; run1 < nn; run1++ ){
576 for( run1 = 0; run1 < n; run1++ ){
577 implicit_dep[run1] = sub[run1]->
isPolynomialIn( 1, varType, component, implicit_dep );
579 for( run1 = 0; run1 < dim; run1++ ){
580 if( f[run1]->isPolynomialIn( 1, varType, component, implicit_dep ) ==
BT_FALSE ){
581 delete[] implicit_dep;
588 delete[] implicit_dep;
598 int nn = variable.
getDim();
603 int *component =
new int [nn];
605 for( run1 = 0; run1 < nn; run1++ ){
630 for( run1 = 0; run1 < n; run1++ ){
631 implicit_dep[run1] = sub[run1]->
isRationalIn( 1, varType, component, implicit_dep );
633 for( run1 = 0; run1 < dim; run1++ ){
634 if( f[run1]->isRationalIn( 1, varType, component, implicit_dep ) ==
BT_FALSE ){
635 delete[] implicit_dep;
642 delete[] implicit_dep;
654 for (run1 = 0; run1 < dim; run1++)
656 int mf = f[run1]->getMonotonicity();
689 for( run1 = 0; run1 < dim; run1++ ){
724 for( run1 = 0; run1 < n; run1++ ){
725 sub[run1]->AD_forward( 0, x, seed,
729 for( run1 = 0; run1 < dim; run1++ ){
730 f[run1]->AD_forward( 0, x, seed, &ff[run1], &df[run1] );
739 double *ff,
double *df ){
743 for( run1 = 0; run1 < n; run1++ ){
744 sub[run1]->AD_forward( number, x, seed,
748 for( run1 = 0; run1 < dim; run1++ ){
749 f[run1]->AD_forward( number, x, seed, &ff[run1], &df[run1] );
760 for( run1 = 0; run1 < n; run1++ ){
761 sub[run1]->AD_forward( number, seed,
764 for( run1 = 0; run1 < dim; run1++ ){
765 f[run1]->AD_forward( number, seed, &df[run1] );
776 for( run1 = dim-1; run1 >= 0; run1-- ){
777 f[run1]->AD_backward( 0, seed[run1], df );
781 for( run1 = n-1; run1 >= 0; run1-- ){
797 for( run1 = dim-1; run1 >= 0; run1-- ){
798 f[run1]->AD_backward( number, seed[run1], df );
801 for( run1 = n-1; run1 >= 0; run1-- ){
802 sub[run1]->AD_backward( number,
812 double *dseed,
double *df,
817 for( run1 = 0; run1 < n; run1++ ){
818 sub[run1]->AD_forward2( number, seed, dseed,
822 for( run1 = 0; run1 < dim; run1++ ){
823 f[run1]->AD_forward2( number, seed, dseed, &df[run1], &ddf[run1] );
831 double *df,
double *ddf ){
835 for( run1 = dim-1; run1 >= 0; run1-- ){
836 f[run1]->AD_backward2( number, seed1[run1], seed2[run1], df, ddf );
840 for( run1 = n-1; run1 >= 0; run1-- ){
841 sub[run1]->AD_backward2( number,
855 const char *fcnName ,
856 const char *realString
859 stream <<
"/* This file was auto-generated by ACADO Toolkit. */" << endl << endl;
861 exportForwardDeclarations(stream, fcnName, realString);
863 exportCode(stream, fcnName, realString);
870 const char *realString
875 "/** Export of an ACADO symbolic function.\n" 877 " * \\param in Input to the exported function.\n" 878 " * \\param out Output of the exported function.\n" 880 <<
"void " << fcnName <<
"(const " << realString <<
"* in, " 881 << realString <<
"* out);" << endl;
889 const char *realString,
903 for (run1 = 0; run1 < n; run1++)
904 if (lhs_comp[run1] + 1 > nni)
905 nni = lhs_comp[run1] + 1;
907 unsigned numX = _numX > 0 ? _numX : getNX();
908 unsigned numXA = _numXA > 0 ? _numXA : getNXA();
909 unsigned numU = _numU > 0 ? _numU : getNU();
910 unsigned numP = _numP > 0 ? _numP : getNP();
911 unsigned numDX = _numDX > 0 ? _numDX : getNDX();
912 unsigned numOD = _numOD > 0 ? _numOD : getNOD();
916 stream <<
"void " << fcnName <<
"(const " << realString <<
"* in, " << realString <<
"* out)\n{\n";
919 stream <<
"const " << realString <<
"* xd = in;" << endl;
923 stream <<
"const " << realString <<
"* xa = in + " << offset <<
";" << endl;
927 stream <<
"const " << realString <<
"* u = in + " << offset <<
";" << endl;
931 stream <<
"const " << realString <<
"* v = in + " << offset <<
";" << endl;
935 stream <<
"const " << realString <<
"* p = in + " << offset <<
";" << endl;
939 stream <<
"const " << realString <<
"* od = in + " << offset <<
";" << endl;
943 stream <<
"const " << realString <<
"* q = in + " << offset <<
";" << endl;
947 stream <<
"const " << realString <<
"* w = in + " << offset <<
";" << endl;
951 stream <<
"const " << realString <<
"* dx = in + " << offset <<
";" << endl;
955 stream <<
"const " << realString <<
"* t = in + " << offset <<
";" << endl;
960 stream <<
"/* Vector of auxiliary variables; number of elements: " << n <<
". */" << endl;
962 if ( allocateMemory )
968 stream << realString <<
" a[" << n <<
"];";
971 stream << realString <<
"* a = " << globalExportVariableName <<
";";
972 stream << endl << endl;
974 stream <<
"/* Compute intermediate quantities: */" << endl;
977 vector< string > auxVarIndividualNames;
978 auxVarIndividualNames.resize( nni );
979 for (run1 = 0; run1 < n; run1++)
982 ss <<
"a" <<
"[" << run1 <<
"]";
983 auxVarIndividualNames[ lhs_comp[ run1 ] ] = ss.str();
987 iof.
set(16, iof.
width, ios::scientific);
990 for (run1 = 0; run1 < n; run1++)
995 stream <<
"a[" << run1 <<
"] = " << *sub[ run1 ] <<
";" << endl;
999 stream << endl <<
"/* Compute outputs: */" << endl;
1000 for (run1 = 0; run1 < dim; run1++)
1005 stream <<
"out[" << run1 <<
"] = " << *f[ run1 ] <<
";" << endl;
1010 stream <<
"}" << endl << endl;
1021 for( run1 = 0; run1 < n; run1++ ){
1022 returnvalue = sub[run1]->clearBuffer();
1027 for( run1 = 0; run1 < dim; run1++ ){
1028 returnvalue = f[run1]->clearBuffer();
1040 return makeImplicit(dim);
1047 int var_counter = indexList->makeImplicit(dim_);
1049 for( run1 = 0; run1 < dim_; run1++ ){
1068 return indexList->getNX();
1073 return indexList->getNXA();
1078 return indexList->getNDX();
1083 return indexList->getNU();
1088 return indexList->getNUI();
1093 return indexList->getNP();
1098 return indexList->getNPI();
1103 return indexList->getNW();
1108 return indexList->getNT();
1113 return indexList->getOD();
1118 return indexList->index( variableType_, index_ );
1123 return indexList->scale( variableType_, index_ );
1129 return indexList->getNumberOfVariables();
1136 if ( (
int)componentIdx < getDim( ) )
1137 return f[componentIdx]->
clone( );
1146 for( run1 = 0; run1 < n; run1++ ){
1149 for( run1 = 0; run1 < dim; run1++ ){
1163 if (_name.size() == 0)
1166 globalExportVariableName = _name;
1173 return globalExportVariableName;
virtual returnValue AD_backward2(int number, double *seed1, double *seed2, double *df, double *ddf)
virtual ~FunctionEvaluationTree()
Abstract base class for all scalar-valued symbolic operators.
virtual int getNumberOfVariables() const
VariableType variableType
virtual returnValue AD_forward(double *x, double *seed, double *f, double *df)
virtual BooleanType isDependingOn(VariableType var) const =0
virtual int getNU() const
virtual returnValue AD_forward2(int number, double *seed1, double *seed2, double *df, double *ddf)
BEGIN_NAMESPACE_ACADO const double EPS
SymbolicIndexList * substitute(VariableType variableType_, int index_)
FunctionEvaluationTree * differentiate(int index)
virtual returnValue clearBuffer()
Allows to pass back messages to the calling function.
returnValue exportForwardDeclarations(std::ostream &stream=std::cout, const char *fcnName="ACADOfcn", const char *realString="double") const
virtual Operator * clone() const =0
virtual Operator * substitute(int index, const Operator *sub)=0
virtual int getNT() const
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
returnValue C_print(std::ostream &stream=std::cout, const char *fcnName="ACADOfcn", const char *realString="double") const
std::string globalExportVariableName
unsigned getGlobalExportVariableSize() const
virtual returnValue AD_backward(double *seed, double *df)
#define CLOSE_NAMESPACE_ACADO
virtual int getNOD() const
virtual int getNW() const
virtual returnValue operator<<(const Expression &arg)
Manages the indices of SymbolicVariables.
virtual int index(VariableType variableType_, int index_) const
Base class for all variables within the symbolic expressions family.
virtual MonotonicityType getMonotonicity()
virtual Operator * getExpression(uint componentIdx) const
virtual returnValue evaluate(double *x, double *result)
virtual NeutralElement isOneOrZero()
virtual BooleanType isRationalIn(const Expression &variable)
virtual BooleanType isDependingOn(const Expression &variable)
returnValue exportCode(std::ostream &stream=std::cout, const char *fcnName="ACADOfcn", const char *realString="double", uint _numX=0, uint _numXA=0, uint _numU=0, uint _numP=0, uint _numDX=0, uint _numOD=0, bool allocateMemory=true, bool staticMemory=false) const
virtual int getNPI() const
virtual int getNDX() const
virtual int getNP() const
Implements the scalar subtraction operator within the symbolic operators family.
std::string getGlobalExportVariableName() const
virtual Operator * clone() const
virtual double scale(VariableType variableType_, int index_) const
Implements the projection operator within the symbolic operators family.
virtual BooleanType isLinearIn(int dim, VariableType *varType, int *component, BooleanType *implicit_dep)=0
virtual BooleanType isSymbolic() const
virtual int getNUI() const
virtual BooleanType isVariable(VariableType &varType, int &component) const =0
virtual BooleanType isPolynomialIn(int dim, VariableType *varType, int *component, BooleanType *implicit_dep)=0
Organizes the evaluation of the function tree.
virtual FunctionEvaluationTree substitute(VariableType variableType_, int index_, double sub_)
FunctionEvaluationTree & operator=(const FunctionEvaluationTree &arg)
#define BEGIN_NAMESPACE_ACADO
virtual BooleanType isRationalIn(int dim, VariableType *varType, int *component, BooleanType *implicit_dep)=0
returnValue setGlobalExportVariableName(const std::string &_name)
virtual returnValue setScale(double *scale_)
virtual CurvatureType getCurvature()
virtual BooleanType isLinearIn(const Expression &variable)
Implements a scalar constant within the symbolic operators family.
SymbolicIndexList * indexList
virtual int getNX() const
virtual int getNXA() const
#define ACADOERROR(retval)
virtual returnValue makeImplicit()
virtual BooleanType isPolynomialIn(const Expression &variable)