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 00034 #include <acado/utils/acado_utils.hpp> 00035 #include <acado/symbolic_expression/symbolic_expression.hpp> 00036 #include <acado/function/function_.hpp> 00037 #include <acado/function/transition.hpp> 00038 00039 00040 BEGIN_NAMESPACE_ACADO 00041 00042 00043 00044 00045 // 00046 // PUBLIC MEMBER FUNCTIONS: 00047 // 00048 00049 Transition::Transition( ) 00050 :Function(){ 00051 00052 counter = 0; 00053 component = 0; 00054 } 00055 00056 Transition::Transition( const Transition& arg ) 00057 :Function(arg){ 00058 00059 int run1; 00060 counter = arg.counter; 00061 if( arg.component != 0 ){ 00062 component = (int*)calloc(counter,sizeof(int)); 00063 for( run1 = 0; run1 < counter; run1++ ) 00064 component[run1] = arg.component[run1]; 00065 } 00066 else component = 0; 00067 } 00068 00069 Transition::~Transition( ){ 00070 00071 if( component != 0 ) free(component); 00072 } 00073 00074 00075 Transition& Transition::operator=( const Transition& arg ){ 00076 00077 if ( this != &arg ){ 00078 00079 if( component != 0 ) 00080 free(component); 00081 00082 Function::operator=( arg ); 00083 00084 counter = arg.counter; 00085 00086 if( arg.component == 0 ){ 00087 component = 0; 00088 } 00089 else{ 00090 int run1; 00091 component = (int*)calloc(counter,sizeof(int)); 00092 for( run1 = 0; run1 < counter; run1++ ){ 00093 component[run1] = arg.component[run1]; 00094 } 00095 } 00096 } 00097 return *this; 00098 } 00099 00100 00101 Transition& Transition::operator<<( const DifferentialState& arg ){ 00102 00103 uint run1; 00104 component = (int*)realloc(component,(counter+arg.getDim())*sizeof(int)); 00105 00106 for( run1 = 0; run1 < arg.getDim(); run1++ ){ 00107 counter++; 00108 component[counter-1] = arg.getComponent(run1); 00109 } 00110 return *this; 00111 } 00112 00113 00114 Transition& Transition::operator==( const Expression& arg ){ 00115 00116 Function::operator<<(arg); 00117 return *this; 00118 } 00119 00120 00121 Transition& Transition::operator==( const double &arg ){ 00122 00123 Expression tmp; 00124 tmp = arg; 00125 return operator==(tmp); 00126 } 00127 00128 00129 Transition& Transition::operator==( const DVector& arg ){ 00130 00131 uint run1; 00132 00133 for( run1 = 0; run1 < arg.getDim(); run1++ ) 00134 operator==( arg(run1) ); 00135 00136 return *this; 00137 } 00138 00139 00140 Transition& Transition::operator==( const DMatrix& arg ){ 00141 00142 uint run1, run2; 00143 00144 for( run1 = 0; run1 < arg.getNumRows(); run1++ ) 00145 for( run2 = 0; run2 < arg.getNumCols(); run2++ ) 00146 operator==( arg(run1,run2) ); 00147 00148 return *this; 00149 } 00150 00151 00152 00153 00154 00155 CLOSE_NAMESPACE_ACADO 00156 00157 // end of file.