evaluation_point.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-2014 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 
36 
37 using namespace std;
38 
40 
41 
42 //
43 // PUBLIC MEMBER FUNCTIONS:
44 //
45 
46 
48 
49  z = 0;
50  idx = 0;
51 }
52 
53 
56 
57 
59  uint nx_, uint na_,
60  uint nu_, uint np_,
61  uint nw_, uint nd_, uint N_){
62 
63  z = 0;
64  idx = 0;
65  init(f,nx_,na_,nu_,np_,nw_,nd_,N_);
66 }
67 
69  const OCPiterate &iter ){
70 
71  z = 0;
72  idx = 0;
73  init( f, iter );
74 }
75 
76 
78 
79  if( this != &rhs ){
80  deleteAll();
81  copy(rhs);
82  }
83  return *this;
84 }
85 
86 
88  const OCPiterate &iter ){
89 
90  return init( f, iter.getNX(), iter.getNXA(), iter.getNP(), iter.getNU(), iter.getNW() );
91 }
92 
93 
95  uint nx_, uint na_, uint np_,
96  uint nu_, uint nw_, uint nd_,
97  uint N_ ){
98 
99  uint run1;
100  deleteAll();
101 
102  nx = acadoMax( nx_, f.getNX () );
103  na = acadoMax( na_, f.getNXA() );
104  np = acadoMax( np_, f.getNP () );
105  nu = acadoMax( nu_, f.getNU () );
106  nw = acadoMax( nw_, f.getNW () );
107  nd = acadoMax( nd_, f.getNDX() );
108  N = acadoMax( N_ , f.getNumberOfVariables()+1 );
109 
110  if( N != 0 ) z = new double[N];
111  else z = 0 ;
112 
113  setZero( );
114 
115  idx = new int*[7 ];
116 
117  idx[0] = new int [1 ];
118  idx[1] = new int [nx];
119  idx[2] = new int [na];
120  idx[3] = new int [np];
121  idx[4] = new int [nu];
122  idx[5] = new int [nw];
123  idx[6] = new int [nd];
124 
125  idx[0][0] = f.index( VT_TIME, 0 );
126 
127  for( run1 = 0; run1 < nx; run1++ )
128  idx[1][run1] = f.index( VT_DIFFERENTIAL_STATE, run1 );
129 
130  for( run1 = 0; run1 < na; run1++ )
131  idx[2][run1] = f.index( VT_ALGEBRAIC_STATE, run1 );
132 
133  for( run1 = 0; run1 < np; run1++ )
134  idx[3][run1] = f.index( VT_PARAMETER, run1 );
135 
136  for( run1 = 0; run1 < nu; run1++ )
137  idx[4][run1] = f.index( VT_CONTROL, run1 );
138 
139  for( run1 = 0; run1 < nw; run1++ )
140  idx[5][run1] = f.index( VT_DISTURBANCE, run1 );
141 
142  for( run1 = 0; run1 < nd; run1++ )
143  idx[6][run1] = f.index( VT_DDIFFERENTIAL_STATE, run1 );
144 
145  return SUCCESSFUL_RETURN;
146 }
147 
148 
150 
151  uint run1;
152 
153  cout << "Time = " << scientific << z[idx[0][0]] << endl;
154 
155  for (run1 = 0; run1 < nx; run1++)
156  cout << "x[" << run1 << "] = " << scientific << z[idx[1][run1]] << endl;
157 
158  for (run1 = 0; run1 < na; run1++)
159  cout << "x[" << run1 << "] = " << scientific << z[idx[2][run1]] << endl;
160 
161  for (run1 = 0; run1 < np; run1++)
162  cout << "x[" << run1 << "] = " << scientific << z[idx[3][run1]] << endl;
163 
164  for (run1 = 0; run1 < nu; run1++)
165  cout << "x[" << run1 << "] = " << scientific << z[idx[4][run1]] << endl;
166 
167  for (run1 = 0; run1 < nw; run1++)
168  cout << "x[" << run1 << "] = " << scientific << z[idx[5][run1]] << endl;
169 
170  return SUCCESSFUL_RETURN;
171 }
172 
173 
174 
175 //
176 // PROTECTED MEMBER FUNCTIONS:
177 //
178 
179 
180 void EvaluationPoint::copyIdx( const uint &dim, const int *idx1, int **idx2 ){
181 
182  uint i;
183  *idx2 = new int[dim];
184  for( i = 0; i < N; i++ )
185  *idx2[i] = idx1[i];
186 }
187 
188 
190 
191  uint i;
192 
193  nx = rhs.nx;
194  na = rhs.na;
195  np = rhs.np;
196  nu = rhs.nu;
197  nw = rhs.nw;
198  nd = rhs.nd;
199  N = rhs.N ;
200 
201  if( rhs.z != 0 ){
202  z = new double[N];
203  for( i = 0; i < N; i++ )
204  z[i] = rhs.z[i];
205  }
206  else z = 0;
207 
208  if( rhs.idx != 0 ){
209 
210  idx = new int*[7];
211  copyIdx( 1, rhs.idx[0], &idx[0] );
212  copyIdx( nx, rhs.idx[1], &idx[1] );
213  copyIdx( na, rhs.idx[2], &idx[2] );
214  copyIdx( np, rhs.idx[3], &idx[3] );
215  copyIdx( nu, rhs.idx[4], &idx[4] );
216  copyIdx( nw, rhs.idx[5], &idx[5] );
217  copyIdx( nd, rhs.idx[6], &idx[6] );
218  }
219  else idx = 0;
220 }
221 
222 
224 
225  if( z != 0 ) delete[] z;
226 
227  if( idx != 0 ){
228  uint i;
229  for( i = 0; i < 7; i++ )
230  delete[] idx[i];
231  delete[] idx;
232  }
233 }
234 
235 
237 
238 // end of file.
#define N
Data class for storing generic optimization variables.
Definition: ocp_iterate.hpp:57
Allows to setup and evaluate a general function based on SymbolicExpressions.
Definition: function_.hpp:59
void copyIdx(const uint &dim, const int *idx1, int **idx2)
uint getNX() const
int acadoMax(const int x, const int y)
Definition: acado_utils.cpp:64
int getNDX() const
Definition: function.cpp:217
virtual ~EvaluationPoint()
Allows to pass back messages to the calling function.
returnValue print() const
Allows to setup function evaluation points.
int getNU() const
Definition: function.cpp:222
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
uint getNP() const
uint getNU() const
#define CLOSE_NAMESPACE_ACADO
int getNXA() const
Definition: function.cpp:212
returnValue init(const Function &f, uint nx_=0, uint na_=0, uint np_=0, uint nu_=0, uint nw_=0, uint nd_=0, uint N_=0)
int getNW() const
Definition: function.cpp:245
EvaluationPoint & operator=(const EvaluationPoint &rhs)
uint getNW() const
returnValue copy(const int *order, const DVector &rhs)
int getNP() const
Definition: function.cpp:233
const int nu
int index(VariableType variableType_, int index_) const
Definition: function.cpp:176
void rhs(const real_t *x, real_t *f)
int getNX() const
Definition: function.cpp:207
uint getNXA() const
#define BEGIN_NAMESPACE_ACADO
void init(int nV, int nC, SymmetricMatrix *H, real_t *g, Matrix *A, const real_t *const lb, const real_t *const ub, const real_t *const lbA, const real_t *const ubA, int nWSR, const real_t *const x0, Options *options, int nOutputs, mxArray *plhs[])
int getNumberOfVariables() const
Definition: function.cpp:264


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