uniform_noise.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 
34 
35 #include <stdlib.h>
36 #include <time.h>
37 
38 
39 
41 
42 
43 
44 
46 {
47 }
48 
49 
50 UniformNoise::UniformNoise( const DVector& _lowerLimit,
51  const DVector& _upperLimit
52  ) : Noise( )
53 {
54  if ( _lowerLimit.getDim( ) == _upperLimit.getDim( ) )
55  {
56  w.init( _lowerLimit.getDim( ),1 );
57  lowerLimit = _lowerLimit;
58  upperLimit = _upperLimit;
59  }
60  else
62 }
63 
64 
66  double _lowerLimit,
67  double _upperLimit
68  ) : Noise( )
69 {
70  w.init( _dim,1 );
71  lowerLimit.init(_dim);
72  upperLimit.init(_dim);
73 
74  for( uint i=0; i<_dim; ++i )
75  {
76  lowerLimit(i) = _lowerLimit;
77  upperLimit(i) = _upperLimit;
78  }
79 }
80 
81 
83 {
84  lowerLimit = rhs.lowerLimit;
85  upperLimit = rhs.upperLimit;
86 }
87 
88 
90 {
91 }
92 
93 
95 {
96  if( this != &rhs )
97  {
98  Noise::operator=( rhs );
99 
100  lowerLimit = rhs.lowerLimit;
101  upperLimit = rhs.upperLimit;
102  }
103 
104  return *this;
105 }
106 
107 
109 {
110  return ( new UniformNoise( *this ) );
111 }
112 
113 
115  ) const
116 {
117  if ( idx >= getDim( ) )
118  return 0;
119 
120  UniformNoise tmp( DVector(1),DVector(1) );
121  tmp.Noise::operator=( *this );
122  tmp.w.init( 1,1 );
123  tmp.lowerLimit(0) = lowerLimit(idx);
124  tmp.upperLimit(0) = upperLimit(idx);
125 
126  return ( new UniformNoise( tmp ) );
127 }
128 
129 
130 
132  const DVector& _upperLimit
133  )
134 {
135  if ( lowerLimit.getDim( ) != _lowerLimit.getDim( ) )
137 
138  if ( upperLimit.getDim( ) != _upperLimit.getDim( ) )
140 
141  for( uint i=0; i<_lowerLimit.getDim( ); ++i )
142  if ( _lowerLimit(i) > _upperLimit(i) )
144 
145  lowerLimit = _lowerLimit;
146  upperLimit = _upperLimit;
147 
148  return SUCCESSFUL_RETURN;
149 }
150 
151 
153  double _upperLimit
154  )
155 {
156  if ( _lowerLimit > _upperLimit )
158 
159  for( uint i=0; i<getDim( ); ++i )
160  {
161  lowerLimit(i) = _lowerLimit;
162  upperLimit(i) = _upperLimit;
163  }
164 
165  return SUCCESSFUL_RETURN;
166 }
167 
168 
170  double _lowerLimit,
171  double _upperLimit
172  )
173 {
174  if ( idx >= getDim( ) )
176 
177  if ( _lowerLimit > _upperLimit )
179 
180  lowerLimit(idx) = _lowerLimit;
181  upperLimit(idx) = _upperLimit;
182 
183  return SUCCESSFUL_RETURN;
184 }
185 
186 
187 
189  )
190 {
191  if ( lowerLimit.getDim( ) != upperLimit.getDim( ) )
193 
194  if ( lowerLimit.getDim( ) == 0 )
196 
197  /* initialize random seed: */
198  if ( seed == 0 )
199  srand( (unsigned int)time(0) );
200  else
201  srand( seed );
202 
203  setStatus( BS_READY );
204 
205  return SUCCESSFUL_RETURN;
206 }
207 
208 
210  )
211 {
212  if ( getStatus( ) != BS_READY )
214 
215  if ( getDim( ) != _w.getDim( ) )
217 
218  if ( w.getNumPoints( ) != 1 )
219  w.init( 1,getDim() );
220 
221  for( uint j=0; j<getDim( ); ++j )
223 
224  _w = w.getVector( 0 );
225 
226  return SUCCESSFUL_RETURN;
227 }
228 
229 
231  )
232 {
233  if ( getStatus( ) != BS_READY )
235 
236  if ( getDim( ) != _w.getNumValues( ) )
238 
239  if ( w.getNumPoints( ) != _w.getNumPoints( ) )
240  w.init( getDim(),_w.getNumPoints( ) );
241 
242  for( uint i=0; i<_w.getNumPoints( ); ++i )
243  for( uint j=0; j<getDim( ); ++j )
245 
246  _w = w;
247 
248  return SUCCESSFUL_RETURN;
249 }
250 
251 
252 //
253 // PROTECTED MEMBER FUNCTIONS:
254 //
255 
256 
257 
259 
260 // end of file.
virtual ~UniformNoise()
returnValue setLimit(uint idx, double _lowerLimit, double _upperLimit)
void init(unsigned _dim=0)
Definition: vector.hpp:155
Provides a time grid consisting of vector-valued optimization variables at each grid point...
Allows to pass back messages to the calling function.
virtual returnValue init(uint seed=0)
Base class for generating pseudo-random noise for simulating the Process.
Definition: noise.hpp:56
VariablesGrid w
Definition: noise.hpp:194
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
returnValue setStatus(BlockStatus _status)
Generates pseudo-random uniformly distributed noise for simulating the Process.
DVector upperLimit
#define CLOSE_NAMESPACE_ACADO
virtual returnValue step(DVector &_w)
double getUniformRandomNumber(double _lowerLimit, double _upperLimit) const
BlockStatus getStatus() const
unsigned getDim() const
Definition: vector.hpp:172
returnValue init()
void rhs(const real_t *x, real_t *f)
returnValue setLimits(const DVector &_lowerLimit, const DVector &_upperLimit)
GenericVector< double > DVector
Definition: vector.hpp:329
Noise & operator=(const Noise &rhs)
Definition: noise.cpp:56
uint getNumPoints() const
DVector lowerLimit
virtual UniformNoise * clone() const
DVector getVector(uint pointIdx) const
#define BEGIN_NAMESPACE_ACADO
uint getDim() const
UniformNoise & operator=(const UniformNoise &rhs)
#define ACADOERROR(retval)


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