evaluation_point.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/function/function.hpp>
00036 
00037 using namespace std;
00038 
00039 BEGIN_NAMESPACE_ACADO
00040 
00041 
00042 //
00043 // PUBLIC MEMBER FUNCTIONS:
00044 //
00045 
00046 
00047 EvaluationPoint::EvaluationPoint( ){
00048 
00049     z   = 0;
00050     idx = 0;
00051 }
00052 
00053 
00054 EvaluationPoint::EvaluationPoint( const EvaluationPoint& rhs ){ copy( rhs        ); }
00055 EvaluationPoint::~EvaluationPoint(                           ){ deleteAll(       ); }
00056 
00057 
00058 EvaluationPoint::EvaluationPoint( const Function &f ,
00059                                   uint nx_, uint na_,
00060                                   uint nu_, uint np_,
00061                                   uint nw_, uint nd_, uint N_){
00062 
00063     z   = 0;
00064     idx = 0;
00065     init(f,nx_,na_,nu_,np_,nw_,nd_,N_);
00066 }
00067 
00068 EvaluationPoint::EvaluationPoint( const Function   &f   ,
00069                                   const OCPiterate &iter  ){
00070 
00071     z   = 0;
00072     idx = 0;
00073     init( f, iter );
00074 }
00075 
00076 
00077 EvaluationPoint& EvaluationPoint::operator=( const EvaluationPoint& rhs ){
00078 
00079     if( this != &rhs ){
00080         deleteAll();
00081         copy(rhs);
00082     }
00083     return *this;
00084 }
00085 
00086 
00087 returnValue EvaluationPoint::init( const Function   &f   ,
00088                        const OCPiterate &iter  ){
00089 
00090     return init( f, iter.getNX(), iter.getNXA(), iter.getNP(), iter.getNU(), iter.getNW() );
00091 }
00092 
00093 
00094 returnValue EvaluationPoint::init( const Function &f ,
00095                                    uint nx_, uint na_, uint np_,
00096                                    uint nu_, uint nw_, uint nd_,
00097                                    uint N_                       ){
00098 
00099     uint run1;
00100     deleteAll();
00101 
00102     nx = acadoMax( nx_, f.getNX ()                 );
00103     na = acadoMax( na_, f.getNXA()                 );
00104     np = acadoMax( np_, f.getNP ()                 );
00105     nu = acadoMax( nu_, f.getNU ()                 );
00106     nw = acadoMax( nw_, f.getNW ()                 );
00107     nd = acadoMax( nd_, f.getNDX()                 );
00108     N  = acadoMax( N_ , f.getNumberOfVariables()+1 );
00109 
00110     if( N != 0 ) z = new double[N];
00111     else         z = 0            ;
00112 
00113         setZero( );
00114 
00115     idx = new int*[7 ];
00116 
00117     idx[0] = new int [1 ];
00118     idx[1] = new int [nx];
00119     idx[2] = new int [na];
00120     idx[3] = new int [np];
00121     idx[4] = new int [nu];
00122     idx[5] = new int [nw];
00123     idx[6] = new int [nd];
00124 
00125     idx[0][0] = f.index( VT_TIME, 0 );
00126 
00127     for( run1 = 0; run1 < nx; run1++ )
00128         idx[1][run1] = f.index( VT_DIFFERENTIAL_STATE, run1 );
00129 
00130     for( run1 = 0; run1 < na; run1++ )
00131         idx[2][run1] = f.index( VT_ALGEBRAIC_STATE, run1 );
00132 
00133     for( run1 = 0; run1 < np; run1++ )
00134         idx[3][run1] = f.index( VT_PARAMETER, run1 );
00135 
00136     for( run1 = 0; run1 < nu; run1++ )
00137         idx[4][run1] = f.index( VT_CONTROL, run1 );
00138 
00139     for( run1 = 0; run1 < nw; run1++ )
00140         idx[5][run1] = f.index( VT_DISTURBANCE, run1 );
00141 
00142     for( run1 = 0; run1 < nd; run1++ )
00143         idx[6][run1] = f.index( VT_DDIFFERENTIAL_STATE, run1 );
00144 
00145     return SUCCESSFUL_RETURN;
00146 }
00147 
00148 
00149 returnValue EvaluationPoint::print() const{
00150 
00151     uint run1;
00152 
00153     cout << "Time = " << scientific << z[idx[0][0]] << endl;
00154 
00155         for (run1 = 0; run1 < nx; run1++)
00156                 cout << "x[" << run1 << "] = " << scientific << z[idx[1][run1]] << endl;
00157 
00158         for (run1 = 0; run1 < na; run1++)
00159                 cout << "x[" << run1 << "] = " << scientific << z[idx[2][run1]] << endl;
00160 
00161         for (run1 = 0; run1 < np; run1++)
00162                 cout << "x[" << run1 << "] = " << scientific << z[idx[3][run1]] << endl;
00163 
00164         for (run1 = 0; run1 < nu; run1++)
00165                 cout << "x[" << run1 << "] = " << scientific << z[idx[4][run1]] << endl;
00166 
00167         for (run1 = 0; run1 < nw; run1++)
00168                 cout << "x[" << run1 << "] = " << scientific << z[idx[5][run1]] << endl;
00169 
00170     return SUCCESSFUL_RETURN;
00171 }
00172 
00173 
00174 
00175 //
00176 // PROTECTED MEMBER FUNCTIONS:
00177 //
00178 
00179 
00180 void EvaluationPoint::copyIdx( const uint &dim, const int *idx1, int **idx2 ){
00181 
00182     uint i;
00183     *idx2 = new int[dim];
00184     for( i = 0; i < N; i++ )
00185         *idx2[i] = idx1[i];
00186 }
00187 
00188 
00189 void EvaluationPoint::copy( const EvaluationPoint &rhs ){
00190 
00191     uint i;
00192 
00193     nx = rhs.nx;
00194     na = rhs.na;
00195     np = rhs.np;
00196     nu = rhs.nu;
00197     nw = rhs.nw;
00198     nd = rhs.nd;
00199     N  = rhs.N ;
00200 
00201     if( rhs.z != 0 ){
00202         z = new double[N];
00203         for( i = 0; i < N; i++ )
00204             z[i] = rhs.z[i];
00205     }
00206     else z = 0;
00207 
00208     if( rhs.idx != 0 ){
00209 
00210         idx = new int*[7];
00211         copyIdx(  1, rhs.idx[0], &idx[0] );
00212         copyIdx( nx, rhs.idx[1], &idx[1] );
00213         copyIdx( na, rhs.idx[2], &idx[2] );
00214         copyIdx( np, rhs.idx[3], &idx[3] );
00215         copyIdx( nu, rhs.idx[4], &idx[4] );
00216         copyIdx( nw, rhs.idx[5], &idx[5] );
00217         copyIdx( nd, rhs.idx[6], &idx[6] );
00218     }
00219     else idx = 0;
00220 }
00221 
00222 
00223 void EvaluationPoint::deleteAll(){
00224 
00225     if( z != 0 ) delete[] z;
00226 
00227     if( idx != 0 ){
00228         uint i;
00229         for( i = 0; i < 7; i++ )
00230             delete[] idx[i];
00231         delete[] idx;
00232     }
00233 }
00234 
00235 
00236 CLOSE_NAMESPACE_ACADO
00237 
00238 // end of file.


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