doubleconstant.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 
37 
38 
39 
41 
42 
43 
44 
46 {
47  nCount = 0;
48 
49  value = 0;
51 }
52 
53 DoubleConstant::DoubleConstant( double value_, NeutralElement neutralElement_ )
54  : SmoothOperator( ), value( value_ ), neutralElement( neutralElement_ )
55 {
56  nCount = 0;
57 
58  // XXX: This should be revised!!!
59  if (fabs( value ) < 10.0 * EPS)
60  {
62  }
63  else if (fabs(1.0 - value) < 10.0 * EPS)
64  {
66  }
67 }
68 
69 
71 
72  value = arg.value ;
74 
75  nCount = 0;
76 }
77 
78 
80 
81 }
82 
83 
85 
86  if( this != &arg ){
87 
88  value = arg.value ;
90 
91  nCount = 0;
92  }
93 
94  return *this;
95 }
96 
97 
98 returnValue DoubleConstant::evaluate( int number, double *x, double *result ){
99 
100  result[0] = value;
101  return SUCCESSFUL_RETURN;
102 }
103 
104 
106 
107  x->set(value);
108  return SUCCESSFUL_RETURN;
109 }
110 
111 
113 
114  return new DoubleConstant( 0.0 , NE_ZERO );
115 }
116 
117 
119  VariableType *varType,
120  int *component,
121  Operator **seed,
122  int &nNewIS,
123  TreeProjection ***newIS ){
124 
125  return new DoubleConstant( 0.0, NE_ZERO );
126 }
127 
128 
129 
131  VariableType *varType ,
132  int *component,
133  Operator *seed ,
134  Operator **df ,
135  int &nNewIS ,
136  TreeProjection ***newIS ){
137 
138  delete seed;
139  return SUCCESSFUL_RETURN;
140 }
141 
142 
144  VariableType *varType ,
145  int *component ,
146  Operator *l ,
147  Operator **S ,
148  int dimS ,
149  Operator **dfS ,
150  Operator **ldf ,
151  Operator **H ,
152  int &nNewLIS ,
153  TreeProjection ***newLIS ,
154  int &nNewSIS ,
155  TreeProjection ***newSIS ,
156  int &nNewHIS ,
157  TreeProjection ***newHIS ){
158 
159  delete l;
160  return SUCCESSFUL_RETURN;
161 }
162 
163 
164 Operator* DoubleConstant::substitute( int index, const Operator *sub ){
165 
166  return clone();
167 }
168 
169 
170 
172 
173  return neutralElement;
174 }
175 
176 
178 
179  return BT_FALSE;
180 }
181 
182 
184  VariableType *varType,
185  int *component,
186  BooleanType *implicit_dep ){
187 
188  return BT_FALSE;
189 }
190 
191 
193  VariableType *varType,
194  int *component,
195  BooleanType *implicit_dep ){
196 
197  return BT_TRUE;
198 }
199 
200 
202  VariableType *varType,
203  int *component,
204  BooleanType *implicit_dep ){
205 
206  return BT_TRUE;
207 }
208 
209 
211  VariableType *varType,
212  int *component,
213  BooleanType *implicit_dep ){
214 
215  return BT_TRUE;
216 }
217 
218 
220 
221  return MT_CONSTANT;
222 }
223 
224 
226 
227  return CT_CONSTANT;
228 }
229 
230 
232 
233  return SUCCESSFUL_RETURN;
234 }
235 
236 
238 
239  return SUCCESSFUL_RETURN;
240 }
241 
242 
243 returnValue DoubleConstant::AD_forward( int number, double *x, double *seed,
244  double *f, double *df ){
245 
246  f[0] = value;
247  df[0] = 0.0;
248 
249  return SUCCESSFUL_RETURN;
250 }
251 
252 
253 
254 returnValue DoubleConstant::AD_forward( int number, double *seed, double *df ){
255 
256  df[0] = 0.0;
257  return SUCCESSFUL_RETURN;
258 }
259 
260 
261 returnValue DoubleConstant::AD_backward( int number, double seed, double *df ){
262 
263  return SUCCESSFUL_RETURN;
264 }
265 
266 
267 returnValue DoubleConstant::AD_forward2( int number, double *seed, double *dseed,
268  double *df, double *ddf ){
269 
270  df[0] = 0.0;
271  ddf[0] = 0.0;
272 
273  return SUCCESSFUL_RETURN;
274 }
275 
276 
277 returnValue DoubleConstant::AD_backward2( int number, double seed1, double seed2,
278  double *df, double *ddf ){
279 
280  return SUCCESSFUL_RETURN;
281 }
282 
283 
284 
285 std::ostream& DoubleConstant::print( std::ostream &stream ) const{
286 
287  return stream << "(real_t)(" << value << ")";
288 }
289 
290 
292 
293  return new DoubleConstant(*this);
294 }
295 
296 
298 
299  return SUCCESSFUL_RETURN;
300 }
301 
302 
304 
305  return SUCCESSFUL_RETURN;
306 }
307 
308 //
309 // PROTECTED MEMBER FUNCTIONS:
310 // ---------------------------
311 
313 
314  return ON_DOUBLE_CONSTANT;
315 }
316 
317 BooleanType DoubleConstant::isVariable( VariableType &varType, int &component ) const
318 {
319  return BT_FALSE;
320 }
321 
322 
324 
325  return SUCCESSFUL_RETURN;
326 }
327 
328 
330 
331  return BT_TRUE;
332 }
333 
334 
336 
337  return value;
338 }
339 
340 
342 
343 // end of file.
OperatorName
Definition: acado_types.hpp:72
virtual BooleanType isSymbolic() const
virtual returnValue AD_backward(int dim, VariableType *varType, int *component, Operator *seed, Operator **df, int &nNewIS, TreeProjection ***newIS)
virtual returnValue loadIndices(SymbolicIndexList *indexList)
virtual returnValue setMonotonicity(MonotonicityType monotonicity_)
Abstract base class for all scalar-valued symbolic operators.
Definition: operator.hpp:60
virtual BooleanType isDependingOn(VariableType var) const
DoubleConstant & operator=(const DoubleConstant &arg)
virtual NeutralElement isOneOrZero() const
BEGIN_NAMESPACE_ACADO const double EPS
virtual double getValue() const
Allows to pass back messages to the calling function.
virtual BooleanType isLinearIn(int dim, VariableType *varType, int *component, BooleanType *implicit_dep)
virtual BooleanType isRationalIn(int dim, VariableType *varType, int *component, BooleanType *implicit_dep)
virtual Operator * differentiate(int index)
virtual returnValue clearBuffer()
#define CLOSE_NAMESPACE_ACADO
Manages the indices of SymbolicVariables.
virtual void set(double &arg)=0
VariableType
Definition: acado_types.hpp:95
virtual returnValue evaluate(int number, double *x, double *result)
virtual returnValue AD_forward2(int number, double *seed1, double *seed2, double *df, double *ddf)
virtual returnValue AD_backward2(int number, double seed1, double seed2, double *df, double *ddf)
virtual BooleanType isPolynomialIn(int dim, VariableType *varType, int *component, BooleanType *implicit_dep)
virtual BooleanType isVariable(VariableType &varType, int &component) const
virtual returnValue AD_symmetric(int dim, VariableType *varType, int *component, Operator *l, Operator **S, int dimS, Operator **dfS, Operator **ldf, Operator **H, int &nNewLIS, TreeProjection ***newLIS, int &nNewSIS, TreeProjection ***newSIS, int &nNewHIS, TreeProjection ***newHIS)
virtual Operator * clone() const
virtual returnValue setCurvature(CurvatureType curvature_)
virtual std::ostream & print(std::ostream &stream) const
virtual OperatorName getName()
#define BT_TRUE
Definition: acado_types.hpp:47
NeutralElement
Definition: acado_types.hpp:64
Abstract base class for all scalar-valued symbolic operators.
MonotonicityType
virtual Operator * AD_forward(int dim, VariableType *varType, int *component, Operator **seed, int &nNewIS, TreeProjection ***newIS)
NeutralElement neutralElement
Implements the tree-projection operator within the family of SymbolicOperators.
CurvatureType
#define BEGIN_NAMESPACE_ACADO
Abstract base class for templated evaluation of operators.
virtual Operator * substitute(int index, const Operator *sub)
#define BT_FALSE
Definition: acado_types.hpp:49
virtual MonotonicityType getMonotonicity()
Implements a scalar constant within the symbolic operators family.
virtual CurvatureType getCurvature()
virtual returnValue enumerateVariables(SymbolicIndexList *indexList)


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