binary_operator.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/utils/acado_utils.hpp>
00036 #include <acado/symbolic_operator/symbolic_operator.hpp>
00037 
00038 
00039 BEGIN_NAMESPACE_ACADO
00040 
00041 
00042 BinaryOperator::BinaryOperator( ) : SmoothOperator( )
00043 {
00044     nCount = 0;
00045 }
00046 
00047 BinaryOperator::BinaryOperator( Operator *_argument1, Operator *_argument2 ) : SmoothOperator( )
00048 {
00049     argument1          = _argument1                      ;
00050     argument2          = _argument2                      ;
00051     dargument1         = NULL                            ;
00052     dargument2         = NULL                            ;
00053     argument1_result  = (double*)calloc(1,sizeof(double));
00054     argument2_result  = (double*)calloc(1,sizeof(double));
00055     dargument1_result = (double*)calloc(1,sizeof(double));
00056     dargument2_result = (double*)calloc(1,sizeof(double));
00057     bufferSize        = 1                                ;
00058     curvature         = CT_UNKNOWN                       ;
00059     monotonicity      = MT_UNKNOWN                       ;
00060 
00061     nCount = 0;
00062 }
00063 
00064 
00065 BinaryOperator::BinaryOperator( const BinaryOperator &arg ){
00066 
00067         argument1  = arg.argument1->clone();
00068     argument2  = arg.argument2->clone();
00069     copy( arg );
00070 }
00071 
00072 
00073 BinaryOperator::~BinaryOperator(){
00074 
00075     deleteAll();
00076 }
00077 
00078 
00079 BinaryOperator& BinaryOperator::operator=( const BinaryOperator &arg ){
00080 
00081     if( this != &arg ){
00082         deleteAll();
00083         copy( arg );
00084     }
00085     return *this;
00086 }
00087 
00088 
00089 NeutralElement BinaryOperator::isOneOrZero() const{ return NE_NEITHER_ONE_NOR_ZERO; }
00090 
00091 BooleanType BinaryOperator::isDependingOn( VariableType var ) const{
00092 
00093     if( argument1->isDependingOn(var) == BT_FALSE &&
00094         argument2->isDependingOn(var) == BT_FALSE )
00095         return BT_FALSE;
00096 
00097     return BT_TRUE;
00098 }
00099 
00100 
00101 BooleanType BinaryOperator::isDependingOn( int dim,
00102                                            VariableType *varType,
00103                                            int *component,
00104                                            BooleanType   *implicit_dep ){
00105 
00106     if( argument1->isDependingOn( dim, varType, component, implicit_dep ) == BT_TRUE ||
00107         argument2->isDependingOn( dim, varType, component, implicit_dep ) == BT_TRUE ){
00108         return BT_TRUE;
00109     }
00110 
00111     return BT_FALSE;
00112 }
00113 
00114 
00115 returnValue BinaryOperator::setMonotonicity( MonotonicityType monotonicity_ ){
00116 
00117     monotonicity = monotonicity_;
00118     return SUCCESSFUL_RETURN;
00119 }
00120 
00121 
00122 returnValue BinaryOperator::setCurvature( CurvatureType curvature_ ){
00123 
00124     curvature = curvature_;
00125     return SUCCESSFUL_RETURN;
00126 }
00127 
00128 
00129 returnValue BinaryOperator::clearBuffer(){
00130 
00131     if( bufferSize > 1 ){
00132         bufferSize = 1;
00133         argument1_result  = (double*)realloc( argument1_result,bufferSize*sizeof(double));
00134         argument2_result  = (double*)realloc( argument2_result,bufferSize*sizeof(double));
00135         dargument1_result = (double*)realloc(dargument1_result,bufferSize*sizeof(double));
00136         dargument2_result = (double*)realloc(dargument2_result,bufferSize*sizeof(double));
00137     }
00138 
00139     return SUCCESSFUL_RETURN;
00140 }
00141 
00142 
00143 
00144 returnValue BinaryOperator::enumerateVariables( SymbolicIndexList *indexList ){
00145 
00146     returnValue returnvalue;
00147     returnvalue = argument1->enumerateVariables( indexList );
00148     if( returnvalue != SUCCESSFUL_RETURN ){
00149         return returnvalue;
00150     }
00151 
00152     return argument2->enumerateVariables( indexList );
00153 }
00154 
00155 
00156 BooleanType BinaryOperator::isVariable( VariableType &varType, int &component ) const{
00157 
00158     return BT_FALSE;
00159 }
00160 
00161 
00162 returnValue BinaryOperator::loadIndices( SymbolicIndexList *indexList ){
00163 
00164     returnValue returnvalue;
00165 
00166     returnvalue = argument1->loadIndices( indexList );
00167 
00168     if( returnvalue != SUCCESSFUL_RETURN ){
00169         return returnvalue;
00170     }
00171 
00172     return argument2->loadIndices( indexList );
00173 }
00174 
00175 
00176 BooleanType BinaryOperator::isSymbolic() const{
00177 
00178     if( argument1->isSymbolic() == BT_FALSE ) return BT_FALSE;
00179     if( argument2->isSymbolic() == BT_FALSE ) return BT_FALSE;
00180 
00181     return BT_TRUE;
00182 }
00183 
00184 
00185 
00186 // //
00187 // // PROTECTED MEMBER FUNCTIONS:
00188 // // ---------------------------
00189 
00190 
00191 void BinaryOperator::copy( const BinaryOperator &arg ){
00192 
00193     int run1;
00194 
00195     bufferSize = arg.bufferSize;
00196 
00197     if( arg.dargument1 == NULL ){
00198         dargument1 = NULL;
00199     }
00200     else{
00201         dargument1 = arg.dargument1->clone();
00202     }
00203 
00204     if( arg.dargument2 == NULL ){
00205         dargument2 = NULL;
00206     }
00207     else{
00208         dargument2 = arg.dargument2->clone();
00209     }
00210 
00211     argument1_result  = (double*)calloc(bufferSize,sizeof(double));
00212     argument2_result  = (double*)calloc(bufferSize,sizeof(double));
00213     dargument1_result = (double*)calloc(bufferSize,sizeof(double));
00214     dargument2_result = (double*)calloc(bufferSize,sizeof(double));
00215 
00216     for( run1 = 0; run1 < bufferSize; run1++ ){
00217 
00218         argument1_result[run1] = arg.argument1_result[run1];
00219         argument2_result[run1] = arg.argument2_result[run1];
00220        dargument1_result[run1] = arg.dargument1_result[run1];
00221        dargument2_result[run1] = arg.dargument2_result[run1];
00222 
00223     }
00224     curvature         = arg.curvature   ;
00225     monotonicity      = arg.monotonicity;
00226 
00227     nCount = 0;
00228 }
00229 
00230 
00231 void BinaryOperator::deleteAll(){
00232 
00233     if( argument1 != 0 ) delete argument1;
00234     if( argument2 != 0 ) delete argument2;
00235 
00236     if( dargument1 != NULL ){
00237         delete dargument1;
00238     }
00239     if( dargument2 != NULL ){
00240         delete dargument2;
00241     }
00242 
00243     free(  argument1_result );
00244     free(  argument2_result );
00245     free( dargument1_result );
00246     free( dargument2_result );
00247 }
00248 
00249 returnValue BinaryOperator::setVariableExportName(      const VariableType &_type,
00250                                                                                                         const std::vector< std::string >& _name
00251                                                                                                         )
00252 {
00253         argument1->setVariableExportName(_type, _name);
00254         argument2->setVariableExportName(_type, _name);
00255 
00256         return Operator::setVariableExportName(_type, _name);
00257 }
00258 
00259 
00260 returnValue BinaryOperator::initDerivative() {
00261 
00262         if( !initialized ) {
00263                 initialized = BT_TRUE;
00264                 argument1->initDerivative();
00265                 return argument2->initDerivative();
00266         }
00267         else {
00268                 return SUCCESSFUL_RETURN;
00269         }
00270 }
00271 
00272 CLOSE_NAMESPACE_ACADO
00273 
00274 // end of file.


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:57:53