My Project
OSnLNode.cpp
Go to the documentation of this file.
1/* $Id$ */
16#include "OSnLNode.h"
17#include "OSErrorClass.h"
18#include "OSParameters.h"
19#include "OSMathUtil.h"
20#include "OSOutput.h"
21
22#include <string>
23#include <cstdlib>
24
25#ifdef HAVE_CMATH
26# include <cmath>
27#else
28# ifdef HAVE_MATH_H
29# include <math.h>
30# else
31# error "don't have header file for math"
32# endif
33#endif
34
35
36#include <iostream>
37#include <sstream>
38
39
40using std::ostringstream;
41using std::cout;
42using std::endl;
43
44
45
46//
47//const std::string msnodeNames[] = {
48// /*1--*/"plus", "sum", "minus", "negate", "times", "divide",
49// "quotient", "rem", "power", "product",
50// /*2--*/"abs", "floor", "ceiling", "percent", "square", "squareRoot", "ln", "log", "log10", "exp",
51// "factorial", "combination", "permutation", "gcd", "lcm", "roundToInt", "round", "truncate", "sign", "rand","gammaFn", "gammaLn",
52// /*3--*/"sin", "cos", "tan", "arcsin", "arccos", "arctan", "sinh", "cosh", "tanh", "arcsinh", "arccosh", "arctanh",
53// "cot", "coth", "arccot", "arccoth", "sec", "sech", "arcsec", "arcsech", "csc", "csch", "arccsc", "arccsch",
54// /*4--*/"mean", "geometricMean", "harmonicMean", "trimMean", "count", "median", "firstQuartile", "thirdQuartile", "mode", "min", "max",
55// "percentile", "large", "small", "range", "interQuantileRange", "absdev", "stddev", "variance", "cv", "skewness", "kurtosis",
56// "covariance", "correlation", "pearsonCorrelation", "rankCorrelation", "autoCorrelation1", "autoCorrelation", "npv", "irr",
57// /*"empiricalDiscreteDist", "empiricalDiscreteCum", */"discreteUniformDist", "discreteUniformCum", "discreteUniformInv",
58// "bernoulliDist", "bernoulliCum", "bernoulliInv", "binomialDist", "binomialCum", "binomialInv", "multinomialDist", "multinomialCum", "multinomialInv",
59// "hypergeometricDist", "hypergeometricCum", "hypergeometricInv", "poissonDist", "poissonCum", "poissonInv",
60// "geometricDist", "geometricCum", "geometricInv", "negativeBinomialDist", "negativeBinomialCum", "negativeBinomialInv",
61// /*"empiricalContinousDist", "empiricalContinuousCum",*/ "uniformDist", "uniformCum", "uniformInv",
62// "normalDist", "normalCum", "normalInv", "stdNormalDist", "stdNormalCum", "stdNormalInv", "bivariateNormalDist", "bivariateNormalCum",
63// "exponentialDist", "exponentialCum", "exponentialInv", "weibullDist", "weibullCum", "weibullInv", "erlangDist", "erlangCum", "erlangInv",
64// "gammaDist", "gammaCum", "gammaInv", "betaDist", "betaCum", "betaInv", "betaGeneralDist", "betaGeneralCum", "betaGeneralInv",
65// "lognormalDist", "lognormalCum", "lognormalInv", "cauchyDist", "cauchyCum", "cauchyInv", "tDist", "tCum", "tInv",
66// "chiSquareDist", "chiSquareCum", "chiSquareInv", "fDist", "fCum", "fInv", "logisticDist", "logisticCum", "logisticInv",
67// "logLogisticDist", "logLogisticCum", "logLogisticInv", "logarithmicDist", "logarithmicCum", "logarithmicInv",
68// "paretoDist", "paretoCum", "paretoDist", "rayleighDist", "rayleighCum", "rayleighInv", "pertDist", "pertCum", "pertDist",
69// "triangularDist", "triangularCum", "triangularInv", "unitNormalLinearLoss", erf
70// /*5--*/"number", "identifier", "PI", "E", "INF", "EPS", "TRUE", "FALSE", "EULERGAMMA", "NAN",
71// /*6--*/"variable", "objective", "constraint", "parameter",
72// /*7--*/"if", "lt", "leq", "gt", "geq", "eq", "neq", "and", "or", "xor", "implies", "not",
73// "forAll", "exists", "logicCount", "allDiff", /*"allDisjoint",*/ "atMost", "atLeast", "exactly",
74// "inSet", "inRealSet", "inPositiveRealSet", "inNonnegativeRealSet", "inIntegerSet", "inPositiveIntegerSet","inNonnegativeIntegerSet",
75// /*8--*/
76// /*9--*/"qTerm", "quadratic", "sim", "simInput", "simOutput", "userF", "arg", "xPath", "xPathIndex",
77// "nodeRef", "arcRef", "complements", /*"prob",*/
78//};
79
80
81
82
83//const int m_miNodeIndexes[] = {
84// /*1--*/1001, 1002, 1003, 1004, 1005, 1006,
85// 1007, 1008, 1009, 1010,
86// /*2--*/2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
87// 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022,
88// /*3--*/3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009, 3010, 3011, 3012,
89// 3013, 3014, 3015, 3016, 3017, 3018, 3019, 3020, 3021, 3022, 3023, 3024,
90// /*4--*/4001, 4002, 4003, 4004, 4005, 4006, 4007, 4008, 4009, 4010, 4011,
91// 4012, 4013, 4014, 4015, 4016, 4017, 4018, 4019, 4020, 4021, 4022,
92// 4023, 4024, 4025, 4026, 4027, 4028, 4029, 4030,
93// /*4101, 4102, */4111, 4112, 4113,
94// 4121, 4122, 4123, 4131, 4132, 4133, 4141, 4142, 4143,
95// 4151, 4152, 4153, 4161, 4162, 4163,
96// 4171, 4172, 4173, 4181, 4182, 4183,
97// /*4401, 4402,*/ 4411, 4412, 4413,
98// 4421, 4422, 4423, 4431, 4432, 4433, 4441, 4442,
99// 4451, 4452, 4453, 4461, 4462, 4463, 4471, 4472, 4473,
100// 4481, 4482, 4483, 4491, 4492, 4493, 4501, 4502, 4503,
101// 4511, 4512, 4513, 4521, 4522, 4523, 4531, 4532, 4533,
102// 4541, 4542, 4543, 4551, 4552, 4553, 4561, 4562, 4563,
103// 4571, 4572, 4573, 4581, 4582, 4583,
104// 4591, 4592, 4593, 4601, 4602, 4603, 4611, 4612, 4613,
105// 4621, 4622, 4623, 4624,4625
106// /*5--*/5001, 5002, 5003, 5004, 5005, 5006, 5007, 5008, 5009, 5010,
107// /*6--*/6001, 6002, 6003, 6004,
108// /*7--*/7001, 7002, 7003, 7004, 7005, 7006, 7007, 7008, 7009, 7010, 7011, 7012,
109// 7013, 7014, 7015, 7016, /*7017,*/ 7018, 7019, 7020,
110// 7021, 7022, 7023, 7024, 7025, 7026, 7027,
111// /*8--*/
112// /*9--*/9001, 9002, 9003, 9004, 9005, 9006, 9007, 9008, 9009,
113// 9010, 9011, 9012, /*9013,*/
114//};
115
116//const int m_miNodeTypes[] = {
117// /*1--*/2, -1, 2, 1, 2, 2,
118// 2, 2, 2, -1,
119// /*2--*/1, 1, 1, 1, 1, 1, 1, 2, 1, 1,
120// 1, 2, 2, -1, -1, 1, 2, 2, 1, 1, 1, 1,
121// /*3--*/1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
122// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
123// /*4--*/-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
124// -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
125// -1, -1, -1, -1, -1, -1, -1, -1,
126// /*-1, -1, */2, 2, 2,
127// 2, 2, 2, 3, 3, 3, -1, -1, -1,
128// 4, 4, 4, 2, 2, 2,
129// 2, 2, 2, 3, 3, 3,
130// /*-1, -1,*/ 3, 3, 3,
131// 3, 3, 3, 1, 1, 1, 7, 7,
132// 2, 2, 2, 4, 4, 4, 3, 3, 3,
133// 3, 3, 3, 3, 3, 3, 5, 5, 5,
134// 3, 3, 3, 3, 3, 3, 2, 2, 2,
135// 2, 2, 2, 3, 3, 3, 3, 3, 3,
136// 3, 3, 3, 3, 3, 3,
137// 3, 3, 3, 2, 2, 2, 4, 4, 4,
138// 4, 4, 4, 1,
139// /*5--*/0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
140// /*6--*/-1, -1, -1, 0,
141// /*7--*/3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
142// -1, -1, -1, -1, /*-1,*/ -1, -1, -1,
143// -1, 1, 1, 1, 1, 1, 1
144// /*8--*/
145// /*9--*/-1, -1, -1, -1, -1, -1, 0, -1, -1,
146// -1, -1, 2, /*1,*/
147//};
148
149
150//
151//ExprNode methods
152//
153
155 inodeInt(-1),
156 inodeType(0),
157 inumberOfChildren( 0),
158 inumberOfMatrixChildren( 0),
159 m_mChildren(NULL),
160 m_mMatrixChildren(NULL)
161{
162#ifndef NDEBUG
163 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside ExprNode constructor");
164#endif
165}//end ExprNode
166
168{
169#ifndef NDEBUG
170 std::ostringstream outStr;
171 outStr << "inside ExprNode destructor" << std::endl;
172 outStr << "scalar kids = " << inumberOfChildren << std::endl;
173 outStr << "matrix kids = " << inumberOfMatrixChildren << std::endl;
175#endif
176 if (inumberOfChildren > 0 && m_mChildren != NULL)
177 {
178 for (unsigned int i=0; i<inumberOfChildren; i++)
179 {
180 if (m_mChildren[i] != NULL)
181 delete m_mChildren[i];
182 m_mChildren[i] = NULL;
183 }
184 delete [] m_mChildren;
185 m_mChildren = NULL;
187 }
188 else if (inumberOfChildren > 0 || m_mChildren != NULL)
189 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_warning, "Warning: Possible memory leak");
190
192 {
193 for (unsigned int i=0; i<inumberOfMatrixChildren; i++)
194 {
195 if (m_mMatrixChildren[i] != NULL)
196 delete m_mMatrixChildren[i];
197 m_mMatrixChildren[i] = NULL;
198 }
199 delete [] m_mMatrixChildren;
200 m_mMatrixChildren = NULL;
202 }
203 else if (inumberOfMatrixChildren > 0 || m_mMatrixChildren != NULL)
204 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_warning, "Warning: Possible memory leak");
205}//end ~ExprNode
206
207
209{
210 ostringstream outStr;
211 outStr << inodeInt;
212 outStr << "[";
213 outStr << inumberOfChildren;
214 outStr << ",";
215 outStr << inumberOfMatrixChildren;
216 outStr << "]";
217 return outStr.str();
218}//getTokenNumber
219
220
222{
223 ostringstream outStr, logStr;
224 outStr << "<";
225 outStr << this->getTokenName();
226#ifndef NDEBUG
227 logStr << "nonlinear node " << this->getTokenName() << endl;
229#endif
231 {
232 outStr << "/>";
233 }
234 else
235 {
236 outStr << ">";
237 if(inumberOfChildren > 0)
238 {
239 for(unsigned int i = 0; i < inumberOfChildren; i++)
240 {
242 }
243 }
245 {
246 for(unsigned int i = 0; i < inumberOfMatrixChildren; i++)
247 {
249 }
250 }
251 outStr << "</";
252 outStr << this->getTokenName();
253 outStr << ">";
254 }
255 return outStr.str();
256}//getNonlinearExpressionInXML()
257
258
260{
261 std::vector<ExprNode*> prefixVector;
262 return preOrderOSnLNodeTraversal( &prefixVector);
263}//getPrefixFromExpressionTree
264
265
266std::vector<ExprNode*> ExprNode::preOrderOSnLNodeTraversal( std::vector<ExprNode*> *prefixVector)
267{
268 (*prefixVector).push_back( this);
269 if(inumberOfChildren > 0)
270 {
271 for(unsigned int i = 0; i < inumberOfChildren; i++)
273 }
275 {
276 for(unsigned int i = 0; i < inumberOfMatrixChildren; i++)
278 }
279 return *prefixVector;
280}//end preOrderOSnLNodeTraversal
281
283{
284 std::vector<ExprNode*> postfixVector;
285 return postOrderOSnLNodeTraversal( &postfixVector);
286}//getPostfixFromExpressionTree
287
288
289std::vector<ExprNode*> ExprNode::postOrderOSnLNodeTraversal( std::vector<ExprNode*> *postfixVector)
290{
291 if(inumberOfChildren > 0)
292 {
293 unsigned int i;
294 for(i = 0; i < inumberOfChildren; i++)
296 }
298 {
299 unsigned int i;
300 for(i = 0; i < inumberOfMatrixChildren; i++)
302 }
303 (*postfixVector).push_back( this);
304 return *postfixVector;
305}//end postOrderOSnLNodeTraversal()
306
307
309{
310#ifndef NDEBUG
311 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in ExprNode");
312#endif
313 if (this == NULL)
314 {
315 if (that == NULL)
316 return true;
317 else
318 {
319#ifndef NDEBUG
321 "First object is NULL, second is not");
322#endif
323 return false;
324 }
325 }
326 else
327 {
328 if (that == NULL)
329 {
330#ifndef NDEBUG
332 "Second object is NULL, first is not");
333#endif
334 return false;
335 }
336 else
337 {
338 if (this->inodeInt != that->inodeInt)
339 return false;
340 if (this->inodeType != that->inodeType)
341 return false;
342 if (this->inumberOfChildren != that->inumberOfChildren)
343 return false;
345 return false;
346
347 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
348 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
349 return false;
350
351 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
352 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
353 return false;
354
355 return true;
356 }
357 }
358}//ExprNode::IsEqual
359// End of ExprNode methods
360
361//
362//OSnLNode methods
363//
364
366 ExprNode(),
367 m_dFunctionValue( OSNaN())
368{
369#ifndef NDEBUG
370 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNode constructor");
371#endif
372}//end OSnLNode
373
375{
376#ifndef NDEBUG
377 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNode destructor");
378#endif
379}//end ~OSnLNode
380
381OSnLNode* OSnLNode::createExpressionTreeFromPrefix(std::vector<ExprNode*> nlNodeVec)
382{
383 std::vector<ExprNode*> stackVec;
384 int kount = nlNodeVec.size() - 1;
385 while(kount >= 0)
386 {
387 int numMtxKids = nlNodeVec[kount]->inumberOfMatrixChildren;
388 int numkids = nlNodeVec[kount]->inumberOfChildren;
389 if(numkids > 0)
390 {
391 for(int i = 0; i < numkids; i++)
392 {
393 nlNodeVec[kount]->m_mChildren[i] = (OSnLNode*)stackVec.back();
394 stackVec.pop_back();
395 }
396 }
397
398 if(numMtxKids > 0)
399 {
400 for(int i = 0; i < numMtxKids; i++)
401 {
402 nlNodeVec[kount]->m_mMatrixChildren[i] = (OSnLMNode*)stackVec.back();
403 stackVec.pop_back();
404 }
405 }
406 stackVec.push_back( nlNodeVec[kount]);
407 kount--;
408 }
409 stackVec.clear();
410 return (OSnLNode*)nlNodeVec[ 0];
411}//end createExpressionTreeFromPrefix
412
413OSnLNode* OSnLNode::createExpressionTreeFromPostfix(std::vector<ExprNode*> nlNodeVec)
414{
415 std::vector<ExprNode*> stackVec;
416
417 size_t kount = 0;
418 while(kount <= nlNodeVec.size() - 1)
419 {
420 int numMtxKids = nlNodeVec[kount]->inumberOfMatrixChildren;
421 if (numMtxKids > 0)
422 {
423 for(int i = numMtxKids - 1; i >= 0; i--)
424 {
425 nlNodeVec[kount]->m_mMatrixChildren[i] = (OSnLMNode*)stackVec.back();
426 stackVec.pop_back();
427 }
428 }
429 int numkids = nlNodeVec[kount]->inumberOfChildren;
430 if (numkids > 0)
431 {
432 for(int i = numkids - 1; i >= 0; i--)
433 {
434 nlNodeVec[kount]->m_mChildren[i] = (OSnLNode*)stackVec.back();
435 stackVec.pop_back();
436 }
437 }
438 stackVec.push_back( nlNodeVec[kount]);
439 kount++;
440 }
441 stackVec.clear();
442 return (OSnLNode*)nlNodeVec[ kount - 1];
443}//end createExpressionTreeFromPostfix
444
445
447{
448 std::vector<ExprNode*> prefixVector;
449 return preOrderOSnLNodeTraversal( &prefixVector);
450}//getPrefixFromExpressionTree
451
452std::vector<ExprNode*> OSnLNode::preOrderOSnLNodeTraversal( std::vector<ExprNode*> *prefixVector)
453{
454 (*prefixVector).push_back( (OSnLNode*)this);
455 if(inumberOfChildren > 0)
456 {
457 for(unsigned int i = 0; i < inumberOfChildren; i++)
459 }
461 {
462 for(unsigned int i = 0; i < inumberOfMatrixChildren; i++)
464 }
465 return *prefixVector;
466}//end preOrderOSnLNodeTraversal
467
469{
470 std::vector<ExprNode*> postfixVector;
471 return postOrderOSnLNodeTraversal( &postfixVector);
472}//getPostfixFromExpressionTree
473
474
475std::vector<ExprNode*> OSnLNode::postOrderOSnLNodeTraversal( std::vector<ExprNode*> *postfixVector)
476{
477 if(inumberOfChildren > 0)
478 {
479 unsigned int i;
480 for(i = 0; i < inumberOfChildren; i++)
482 }
484 {
485 unsigned int i;
486 for(i = 0; i < inumberOfMatrixChildren; i++)
488 }
489 (*postfixVector).push_back( (OSnLNode*)this);
490 return *postfixVector;
491}//end postOrderOSnLNodeTraversal()
492
493void OSnLNode::getVariableIndexMap(std::map<int, int> *varIdx)
494{
495 unsigned int i;
496 if(inodeInt != OS_VARIABLE)
497 {
498 for(i = 0; i < inumberOfChildren; i++)
499 {
500 m_mChildren[ i]->getVariableIndexMap( varIdx);
501 }
502 }
503}//getVariableIndexMap
504
506{
507#ifndef NDEBUG
508 ostringstream outStr;
509 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
510 outStr << " (" << this->getTokenName() << ")" << std::endl;
512#endif
513
514 OSnLNode* ndcopy = (OSnLNode*)cloneExprNode();
517 ndcopy->inodeInt = inodeInt;
518 ndcopy->inodeType = inodeType;
519
520 if (inumberOfChildren > 0)
521 {
522 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
523 for (unsigned int i=0; i < inumberOfChildren; i++)
524 {
525 ndcopy->m_mChildren[i] = /*(OSnLNode)*/m_mChildren[i]->copyNodeAndDescendants();
526 }
527 }
528
530 {
531 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
532 for (unsigned int i=0; i < inumberOfMatrixChildren; i++)
533 {
535 }
536 }
537
538 return ndcopy;
539}// end OSnLNode::copyNodeAndDescendants
540
542{
543#ifndef NDEBUG
544 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLNode");
545#endif
546 if (this == NULL)
547 {
548 if (that == NULL)
549 return true;
550 else
551 {
552#ifndef NDEBUG
554 "First object is NULL, second is not");
555#endif
556 return false;
557 }
558 }
559 else
560 {
561 if (that == NULL)
562 {
563#ifndef NDEBUG
565 "Second object is NULL, first is not");
566#endif
567 return false;
568 }
569 else
570 {
571 if (this->inumberOfChildren != that->inumberOfChildren)
572 return false;
574 return false;
575 if (this->inodeInt != that->inodeInt)
576 return false;
577 if (this->inodeType != that->inodeType)
578 return false;
579
580 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
581 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
582 return false;
583
584 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
585 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
586 return false;
587
588 return true;
589 }
590 }
591}//OSnLNode::IsEqual
592
593
594// OSnLNodePlus Methods
596{
599 m_mChildren = new OSnLNode*[2];
600 m_mChildren[ 0] = NULL;
601 m_mChildren[ 1] = NULL;
603 inodeType = 2;
604}//end OSnLNodePlus
605
606
608{
609 std::ostringstream outStr;
610#ifndef NDEBUG
611 outStr << "inside OSnLNodePlus destructor" << endl;
613#endif
614}//end ~OSnLNodePlus
615
617{
618 return "plus";
619}// end OSnLNodePlus::getTokenName()
620
622{
624 return m_dFunctionValue;
625}// end OSnLNodePlus::calculate
626
627
628ADdouble OSnLNodePlus::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
629{
630 m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) + m_mChildren[1]->constructADTape( ADIdx, XAD);
631 return m_ADTape;
632}// end OSnLNodePlus::constructADTape
633
635{
636 OSnLNode *nlNodePoint;
637 nlNodePoint = new OSnLNodePlus();
638 return nlNodePoint;
639}//end OSnLNodePlus::cloneExprNode
640
641
642//
643// OSnLNodeSum Methods
645{
649 inodeType = -1;
650}//end OSnLNodeSum
651
653{
654#ifndef NDEBUG
655 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeSum destructor");
656#endif
657}//end ~OSnLNodeSum
658
660{
661 return "sum";
662}// end OSnLNodeSum::getTokenName()
663
665{
666 m_dFunctionValue = 0.0;
667 unsigned int i;
668 for(i = 0; i < inumberOfChildren; i++)
669 {
671 }
672 return m_dFunctionValue;
673}// end OSnLNodeSum::calculate
674
675
676ADdouble OSnLNodeSum::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
677{
678 m_ADTape = 0.0;
679 unsigned int i;
680 for(i = 0; i < inumberOfChildren; i++)
681 {
682 m_ADTape = m_ADTape + m_mChildren[i]->constructADTape( ADIdx, XAD);
683 }
684 return m_ADTape;
685}// end OSnLNodeSum::constructADTape
686
688{
689 OSnLNode *nlNodePoint;
690 nlNodePoint = new OSnLNodeSum();
691 return nlNodePoint;
692}//end OSnLNodeSum::cloneExprNode
693//end OSnLNodeSum methods
694
695
696//
697// OSnLNodeAllDiff Methods
698
700{
704 inodeType = -1;
705}//end OSnLNodeAllDiff
706
708{
709#ifndef NDEBUG
710 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeAllDiff destructor");
711#endif
712}//end ~OSnLNodeAllDiff
713
715{
716 return "allDiff";
717}// end OSnLNodeAllDiff::getTokenName(
718
719
721{
723 // return false if not all different
724 unsigned int i, k;
725 if(inumberOfChildren > 1)
726 {
727 for(i = 0; i < inumberOfChildren - 1; i++)
728 {
729 for(k = i + 1; k < inumberOfChildren; k++)
730 {
731 if(m_mChildren[i]->calculateFunction(x) ==
732 m_mChildren[k]->calculateFunction(x)) return 0 ;
733 }
734 }
735 }
736
737 return m_dFunctionValue;
738}// end OSnLNodeAllDiff::calculate
739
740
741ADdouble OSnLNodeAllDiff::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
742{
743 try
744 {
745 throw ErrorClass("AllDifferent operator not supported by current Algorithmic Differentiation implementation");
746 return m_ADTape;
747 }
748 catch(const ErrorClass& eclass)
749 {
750 throw ErrorClass( eclass.errormsg);
751 }
752 return m_ADTape;
753}// end OSnLNodeAllDiff::constructADTape
754
755
757{
758 OSnLNode *nlNodePoint;
759 nlNodePoint = new OSnLNodeAllDiff();
760 return nlNodePoint;
761}//end OSnLNodeAllDiff::cloneExprNode
762//end OSnLNodeAllDiff methods
763
764
765//
766// OSnLNodeMax Methods
768{
772 inodeType = -1;
773}//end OSnLNodeMax
774
776{
777#ifndef NDEBUG
778 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeMax destructor");
779#endif
780}//end ~OSnLNodeMax
781
783{
785
786 for(unsigned int i = 0; i < inumberOfChildren; i++)
787 {
789 {
791 }
792 }
793 return m_dFunctionValue;
794}// end OSnLNodeMax::calculate
795
797{
798 return "max";
799}// end OSnLNodeMax::getTokenName(
800
801
802ADdouble OSnLNodeMax::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
803{
804 //if not support in AD, throw an exception
805 try
806 {
807 throw ErrorClass("Max operator not supported by current Algorithmic Differentiation implementation");
808 return m_ADTape;
809 }
810 catch(const ErrorClass& eclass)
811 {
812 throw ErrorClass( eclass.errormsg);
813 }
814}// end OSnLNodeMax::constructADTape
815
816
818{
819 OSnLNode *nlNodePoint;
820 nlNodePoint = new OSnLNodeMax();
821 return nlNodePoint;
822}//end OSnLNodeMax::cloneExprNode
823
824
825//
826// OSnLNodeMin Methods
828{
832 inodeType = -1;
833}//end OSnLNodeMin
834
836{
837#ifndef NDEBUG
838 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeMin destructor");
839#endif
840}//end ~OSnLNodeMin
841
842
844{
845 return "min";
846}// end OSnLNodeMin::getTokenName(
847
849{
851
852 for(unsigned int i = 0; i < inumberOfChildren; i++)
853 {
855 {
857 }
858 }
859 return m_dFunctionValue;
860}// end OSnLNodeMin::calculate
861
862
863ADdouble OSnLNodeMin::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
864{
865 //if not support in AD, throw an exception
866 try
867 {
868 throw ErrorClass("Min operator not supported by current Algorithmic Differentiation implementation");
869 return m_ADTape;
870 }
871 catch(const ErrorClass& eclass)
872 {
873 throw ErrorClass( eclass.errormsg);
874 }
875}// end OSnLNodeMin::constructADTape
876
877
879{
880 OSnLNode *nlNodePoint;
881 nlNodePoint = new OSnLNodeMin();
882 return nlNodePoint;
883}//end OSnLNodeMin::cloneExprNode
884
885
886//
887// OSnLNodeMinus Methods
889{
892 m_mChildren = new OSnLNode*[2];
893 m_mChildren[ 0] = NULL;
894 m_mChildren[ 1] = NULL;
896 inodeType = 2;
897}//end OSnLNodeMinus
898
899
901{
902#ifndef NDEBUG
903 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeMinus destructor");
904#endif
905}//end ~OSnLNodeMinus
906
908{
909 return "minus";
910}// end OSnLNodeSum::getTokenName(
911
913{
915 return m_dFunctionValue;
916}// end OSnLNodeMinus::calculate
917
918
919ADdouble OSnLNodeMinus::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
920{
921 m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) - m_mChildren[1]->constructADTape( ADIdx, XAD);
922 return m_ADTape;
923}// end OSnLNodeMinus::constructADTape
924
925
927{
928 OSnLNode *nlNodePoint;
929 nlNodePoint = new OSnLNodeMinus();
930 return nlNodePoint;
931}//end OSnLNodeMinus::cloneExprNode
932
933
934//
935//
936// OSnLNodeNegate Methods
938{
941 m_mChildren = new OSnLNode*[1];
942 m_mChildren[ 0] = NULL;
944 inodeType = 1;
945}//end OSnLNodeNegate
946
947
949{
950#ifndef NDEBUG
951 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeNegate destructor");
952#endif
953}//end ~OSnLNodeNegate
954
956{
957 return "negate";
958}// end OSnLNodeNegate::getTokenName(
959
961{
963 return m_dFunctionValue;
964}// end OSnLNodeMinus::calculate
965
966ADdouble OSnLNodeNegate::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
967{
968 m_ADTape = -m_mChildren[0]->constructADTape( ADIdx, XAD);
969 return m_ADTape;
970}// end OSnLNodeNegate::constructADTape
971
973{
974 OSnLNode *nlNodePoint;
975 nlNodePoint = new OSnLNodeNegate();
976 return nlNodePoint;
977}//end OSnLNodeNegate::cloneExprNode
978
979
980// OSnLNodeTimes Methods
982{
985 m_mChildren = new OSnLNode*[2];
986 m_mChildren[ 0] = NULL;
987 m_mChildren[ 1] = NULL;
989 inodeType = 2;
990}//end OSnLNodeTimes
991
992
994{
995#ifndef NDEBUG
996 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeTimes destructor");
997#endif
998}//end ~OSnLNodeTimes
999
1001{
1002 return "times";
1003}// end OSnLNodeTimes::getTokenName(
1004
1006{
1008 return m_dFunctionValue;
1009}// end OSnLNodeTimes::calculate
1010
1011
1012ADdouble OSnLNodeTimes::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
1013{
1014 m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) * m_mChildren[1]->constructADTape( ADIdx, XAD);
1015 return m_ADTape;
1016}// end OSnLNodeTimes::constructADTape
1017
1019{
1020 OSnLNode *nlNodePoint;
1021 nlNodePoint = new OSnLNodeTimes();
1022 return nlNodePoint;
1023}//end OSnLNodeTimes::cloneExprNode
1024
1025
1026//
1027// OSnLNodeDivide Methods
1029{
1032 m_mChildren = new OSnLNode*[2];
1033 m_mChildren[ 0] = NULL;
1034 m_mChildren[ 1] = NULL;
1036 inodeType = 2;
1037}//end OSnLNodeDivide
1038
1039
1041{
1042#ifndef NDEBUG
1043 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeDivide destructor");
1044#endif
1045}//end ~OSnLNodeDivide
1046
1048{
1049 return "divide";
1050}// end OSnLNodeDivide::getTokenName(
1051
1053{
1054 // kipp throw error if we divide by 0
1056 return m_dFunctionValue;
1057}// end OSnLNodeDivide::calculate
1058
1059
1060ADdouble OSnLNodeDivide::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
1061{
1062 m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) / m_mChildren[1]->constructADTape( ADIdx, XAD);
1063 return m_ADTape;
1064}// end OSnLNodeDivide::constructADTape
1065
1066
1068{
1069 OSnLNode *nlNodePoint;
1070 nlNodePoint = new OSnLNodeDivide();
1071 return nlNodePoint;
1072}//end OSnLNodeDivide::cloneExprNode
1073
1074
1075//
1076// OSnLNodePower Methods
1078{
1081 m_mChildren = new OSnLNode*[2];
1082 m_mChildren[ 0] = NULL;
1083 m_mChildren[ 1] = NULL;
1085 inodeType = 2;
1086}//end OSnLNodePower
1087
1088
1090{
1091#ifndef NDEBUG
1092 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodePower destructor");
1093#endif
1094}//end ~OSnLNodePower
1095
1097{
1098 return "power";
1099}// end OSnLNodePower::getTokenName(
1100
1102{
1103 // kipp throw error if operation not defined
1105 return m_dFunctionValue;
1106}// end OSnLNodePower::calculate
1107
1108//
1109ADdouble OSnLNodePower::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
1110{
1111 //if( typeid( *m_mChildren[1]) == typeid( OSnLNodeNumber) ) {
1112 if( this->m_mChildren[1]->inodeInt == 5001 )
1113 {
1114 OSnLNodeNumber *numberNode = (OSnLNodeNumber*)m_mChildren[1];
1115 // we have a number node see if integer
1116 if( (numberNode->value) == int( numberNode->value))
1117 {
1118 m_ADTape = pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , int( numberNode->value));
1119 }
1120 else m_ADTape = pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , m_mChildren[1]->constructADTape( ADIdx, XAD) );
1121 }
1122 else
1123 {
1124 m_ADTape = pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , m_mChildren[1]->constructADTape( ADIdx, XAD) );
1125 }
1126 return m_ADTape;
1127}// end OSnLNodePower::constructADTape
1128
1129
1130//ADdouble OSnLNodePower::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD){
1131// m_ADTape = AD::pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , m_mChildren[1]->constructADTape( ADIdx, XAD) );
1132// return m_ADTape;
1133//}// end OSnLNodePower::constructADTape
1134
1135
1137{
1138 OSnLNode *nlNodePoint;
1139 nlNodePoint = new OSnLNodePower();
1140 return nlNodePoint;
1141}//end OSnLNodePower::cloneExprNode
1142
1143
1144//
1145// OSnLNodeProduct Methods
1147{
1151 inodeType = -1;
1152}//end OSnLNodeProduct
1153
1154
1156{
1157#ifndef NDEBUG
1158 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeProduct destructor");
1159#endif
1160}//end ~OSnLNodeProduct
1161
1163{
1164 return "product";
1165}// end OSnLNodeProduct::getTokenName(
1166
1168{
1169 // kipp throw error if operation not defined
1170 m_dFunctionValue = 1.0;
1171 unsigned int i;
1172 for(i = 0; i < inumberOfChildren; i++)
1173 {
1175 }
1176 return m_dFunctionValue;
1177}// end OSnLNodeProduct::calculate
1178
1179
1181{
1182 m_ADTape = 1.0;
1183 unsigned int i;
1184 for(i = 0; i < inumberOfChildren; i++)
1185 {
1186 m_ADTape = m_ADTape*m_mChildren[i]->constructADTape( ADIdx, XAD);
1187 }
1188 return m_ADTape;
1189}// end OSnLNodeProduct::constructADTape
1190
1191
1193{
1194 OSnLNode *nlNodePoint;
1195 nlNodePoint = new OSnLNodeProduct();
1196 return nlNodePoint;
1197}//end OSnLNodeProduct::cloneExprNode
1198
1199
1200//
1201// OSnLNodeLn Methods
1203{
1206 m_mChildren = new OSnLNode*[1];
1207 m_mChildren[ 0] = NULL;
1208 inodeInt = OS_LN;
1209 inodeType = 1;
1210}//end OSnLNodeLn
1211
1212
1214{
1215#ifndef NDEBUG
1216 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeLn destructor");
1217#endif
1218}//end ~OSnLNodeLn
1219
1221{
1222 return "ln";
1223}// end OSnLNodeLn::getTokenName(
1224
1226{
1228 return m_dFunctionValue;
1229}// end OSnLNodeLn::calculate
1230
1231
1232ADdouble OSnLNodeLn::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
1233{
1234 m_ADTape = log( m_mChildren[0]->constructADTape( ADIdx, XAD) );
1235 return m_ADTape;
1236}// end OSnLNodeLn::constructADTape
1237
1239{
1240 OSnLNode *nlNodePoint;
1241 nlNodePoint = new OSnLNodeLn();
1242 return nlNodePoint;
1243}//end OSnLNodeLn::cloneExprNode
1244
1245
1246//
1247// OSnLNodeSqrt Methods
1249{
1252 m_mChildren = new OSnLNode*[1];
1253 m_mChildren[ 0] = NULL;
1254 inodeInt = OS_SQRT;
1255 inodeType = 1;
1256}//end OSnLNodeSqrt
1257
1258
1260{
1261#ifndef NDEBUG
1262 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeSqrt destructor");
1263#endif
1264}//end ~OSnLNodeSqrt
1265
1267{
1268 return "sqrt";
1269}// end OSnLNodeSqrt::getTokenName(
1270
1272{
1274 return m_dFunctionValue;
1275}// end OSnLNodeSqrt::calculate
1276
1277
1278ADdouble OSnLNodeSqrt::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
1279{
1280 m_ADTape = sqrt( m_mChildren[0]->constructADTape( ADIdx, XAD) );
1281 return m_ADTape;
1282}// end OSnLNodeSqrt::constructADTape
1283
1285{
1286 OSnLNode *nlNodePoint;
1287 nlNodePoint = new OSnLNodeSqrt();
1288 return nlNodePoint;
1289}//end OSnLNodeSqrt::cloneExprNode
1290
1291
1292//
1293// OSnLNodeSquare Methods
1295{
1298 m_mChildren = new OSnLNode*[1];
1299 m_mChildren[ 0] = NULL;
1301 inodeType = 1;
1302}//end OSnLNodeSquare
1303
1304
1306{
1307#ifndef NDEBUG
1308 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeSquare destructor");
1309#endif
1310}//end ~OSnLNodeSquare
1311
1313{
1314 return "square";
1315}// end OSnLNodeSquare::getTokenName(
1316
1318{
1319 m_dFunctionValue = pow( (m_mChildren[0]->calculateFunction( x) ), 2);
1320 return m_dFunctionValue;
1321}// end OSnLNodeSquare::calculate
1322
1323
1324ADdouble OSnLNodeSquare::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
1325{
1326 m_ADTape = pow( m_mChildren[0]->constructADTape( ADIdx, XAD), int( 2) );
1327 return m_ADTape;
1328}// end OSnLNodeSquare::constructADTape
1329
1331{
1332 OSnLNode *nlNodePoint;
1333 nlNodePoint = new OSnLNodeSquare();
1334 return nlNodePoint;
1335}//end OSnLNodeSquare::cloneExprNode
1336
1337
1338//
1339// OSnLNodeSin Methods
1341{
1344 m_mChildren = new OSnLNode*[1];
1345 m_mChildren[ 0] = NULL;
1346 inodeInt = OS_SIN;
1347 inodeType = 1;
1348}//end OSnLNodeSin
1349
1350
1352{
1353#ifndef NDEBUG
1354 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeSin destructor");
1355#endif
1356}//end ~OSnLNodeSin
1357
1359{
1360 return "sin";
1361}// end OSnLNodeSin::getTokenName(
1362
1364{
1366 return m_dFunctionValue;
1367}// end OSnLNodeSin::calculate
1368
1369
1370ADdouble OSnLNodeSin::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
1371{
1372 m_ADTape = sin( m_mChildren[0]->constructADTape( ADIdx, XAD) );
1373 return m_ADTape;
1374}// end OSnLNodeSin::constructADTape
1375
1377{
1378 OSnLNode *nlNodePoint;
1379 nlNodePoint = new OSnLNodeSin();
1380 return nlNodePoint;
1381}//end OSnLNodeSin::cloneExprNode
1382
1383
1384//
1385// OSnLNodeCos Methods
1387{
1390 m_mChildren = new OSnLNode*[1];
1391 m_mChildren[ 0] = NULL;
1392 inodeInt = OS_COS;
1393 inodeType = 1;
1394}//end OSnLNodeCos
1395
1396
1398{
1399#ifndef NDEBUG
1400 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeCos destructor");
1401#endif
1402}//end ~OSnLNodeCos
1403
1405{
1406 return "cos";
1407}// end OSnLNodeCos::getTokenName(
1408
1410{
1412 return m_dFunctionValue;
1413}// end OSnLNodeCos::calculate
1414
1415
1416ADdouble OSnLNodeCos::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
1417{
1418 m_ADTape = cos( m_mChildren[0]->constructADTape( ADIdx, XAD) );
1419 return m_ADTape;
1420}// end OSnLNodeCos::constructADTape
1421
1423{
1424 OSnLNode *nlNodePoint;
1425 nlNodePoint = new OSnLNodeCos();
1426 return nlNodePoint;
1427}//end OSnLNodeCos::cloneExprNode
1428
1429
1430//
1431// OSnLNodeExp Methods
1433{
1436 m_mChildren = new OSnLNode*[1];
1437 m_mChildren[ 0] = NULL;
1438 inodeInt = OS_EXP;
1439 inodeType = 1;
1440}//end OSnLNodeExp
1441
1442
1444{
1445#ifndef NDEBUG
1446 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeExp destructor");
1447#endif
1448}//end ~OSnLNodeExp
1449
1451{
1452 return "exp";
1453}// end OSnLNodeExp::getTokenName(
1454
1456{
1458 return m_dFunctionValue;
1459}// end OSnLNodeExp::calculate
1460
1461
1462ADdouble OSnLNodeExp::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
1463{
1464 m_ADTape = exp( m_mChildren[0]->constructADTape( ADIdx, XAD) );
1465 return m_ADTape;
1466}// end OSnLNodeExp::constructADTape
1467
1469{
1470 OSnLNode *nlNodePoint;
1471 nlNodePoint = new OSnLNodeExp();
1472 return nlNodePoint;
1473}//end OSnLNodeExp::cloneExprNode
1474
1475
1476//
1477// OSnLNodeAbs Methods
1479{
1482 m_mChildren = new OSnLNode*[1];
1483 m_mChildren[ 0] = NULL;
1484 inodeInt = OS_ABS;
1485 inodeType = 1;
1486}//end OSnLNodeLn
1487
1488
1490{
1491#ifndef NDEBUG
1492 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeAbs destructor");
1493#endif
1494}//end ~OSnLNodeAbs
1495
1497{
1498 return "abs";
1499}// end OSnLNodeAbs::getTokenName(
1500
1502{
1504 return m_dFunctionValue;
1505}// end OSnLNodeAbs::calculate
1506
1507
1508ADdouble OSnLNodeAbs::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
1509{
1510 m_ADTape = abs( m_mChildren[0]->constructADTape( ADIdx, XAD) );
1511 return m_ADTape;
1512}// end OSnLNodeAbs::constructADTape
1513
1515{
1516 OSnLNode *nlNodePoint;
1517 nlNodePoint = new OSnLNodeAbs();
1518 return nlNodePoint;
1519}//end OSnLNodeAbs::cloneExprNode
1520// end OSnLNodeAbs methods
1521
1522
1523//
1524// OSnLNodeErf Methods
1526{
1529 m_mChildren = new OSnLNode*[1];
1530 m_mChildren[ 0] = NULL;
1531 inodeInt = OS_ERF;
1532 inodeType = 1;
1533}//end OSnLNodeErf
1534
1535
1537{
1538#ifndef NDEBUG
1539 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeErf destructor");
1540#endif
1541}//end ~OSnLNodeErf
1542
1544{
1545 return "erf";
1546}// end OSnLNodeErf::getTokenName(
1547
1549{
1550 const double a = (993./880.);
1551 const double b = (89./880.);
1553 //std::cout << "function value = " << m_dFunctionValue << std::endl;
1554 return m_dFunctionValue;
1555}// end OSnLNodeErf::calculate
1556
1557
1558ADdouble OSnLNodeErf::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
1559{
1560 /***
1561 *
1562 * This is a fast approximation (few numerical operations)
1563 * with relative error bound $latex 4 \times 10^{-4}$$; see
1564 * Vedder, J.D., "Simple approximations for the error function and its inverse",
1565 * American Journal of Physics, v 55, n 8, 1987, p 762-3. I took this reference from
1566 * Brad Bell's erf.hpp
1567 *
1568 */
1569 const double a = (993./880.);
1570 const double b = (89./880.);
1571
1572 //tanh( (a + b * x * x) * x );
1573 //m_ADTape = CppAD::erf( m_mChildren[0]->constructADTape( ADIdx, XAD) );
1574 m_ADTape = tanh( (a + b * m_mChildren[0]->constructADTape( ADIdx, XAD) * m_mChildren[0]->constructADTape( ADIdx, XAD)) * m_mChildren[0]->constructADTape( ADIdx, XAD) );
1575
1576 return m_ADTape;
1577}// end OSnLNodeErf::constructADTape
1578
1580{
1581 OSnLNode *nlNodePoint;
1582 nlNodePoint = new OSnLNodeErf();
1583 return nlNodePoint;
1584}//end OSnLNodeErf::cloneExprNode
1585// end OSnLNodeErf methods
1586
1587
1588// OSnLNodeIf Methods
1590{
1593 m_mChildren = new OSnLNode*[3];
1594 m_mChildren[ 0] = NULL;
1595 m_mChildren[ 1] = NULL;
1596 m_mChildren[ 2] = NULL;
1597 inodeInt = OS_IF;
1598 inodeType = 3;
1599}//end OSnLNodeIf
1600
1601
1603{
1604#ifndef NDEBUG
1605 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeIf destructor");
1606#endif
1607}//end ~OSnLNodeIf
1608
1610{
1611 return "if";
1612}// end OSnLNodeIf::getTokenName(
1613
1615{
1618 return m_dFunctionValue;
1619}// end OSnLNodeIf::calculate
1620
1621ADdouble OSnLNodeIf::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
1622{
1623 //if not support in AD, throw an exception
1624 try
1625 {
1626 throw ErrorClass("if operator not supported by current Algorithmic Differentiation implementation");
1627 return m_ADTape;
1628 }
1629 catch(const ErrorClass& eclass)
1630 {
1631 throw ErrorClass( eclass.errormsg);
1632 }
1633}// end OSnLNodeIf::constructADTape
1634
1636{
1637 OSnLNode *nlNodePoint;
1638 nlNodePoint = new OSnLNodeIf();
1639 return nlNodePoint;
1640}//end OSnLNodeIf::cloneExprNode
1641// end OSnLNodeIf methods
1642
1643
1644//
1645// OSnLNodeNumber Methods
1647{
1651 m_mChildren = NULL;
1652 m_mMatrixChildren = NULL;
1653 inodeType = 0;
1654 value = 0.0;
1655
1656 type = "real";
1657 id = "";
1658
1659}//end OSnLNodeNumber
1660
1662{
1663#ifndef NDEBUG
1664 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeNumber destructor");
1665#endif
1666}//end ~OSnLNodeNumber
1667
1669{
1670 ostringstream outStr;
1671 outStr << inodeInt;
1672 outStr << ":" ;
1673 outStr << value ;
1674// //if(type.length() > 0){
1675// outStr << ":" ;
1676// outStr << type ;
1677// //}
1678// //if(id.length() > 0){
1679// outStr << ":" ;
1680// outStr << id;
1681// //}
1682 return outStr.str();
1683}//getTokenNumber
1684
1685
1687{
1688 return "number";
1689}//getTokenName
1690
1691
1693{
1694 ostringstream outStr;
1695 outStr << "<" ;
1696 outStr << this->getTokenName();
1697 outStr << " value=\"";
1698 outStr << os_dtoa_format(value);
1699 outStr << "\"";
1700 if (type != "real")
1701 {
1702 outStr << " type=\"";
1703 outStr << type ;
1704 outStr << "\"";
1705 }
1706 if(id.length() > 0)
1707 {
1708 outStr << " id=\"";
1709 outStr << id ;
1710 outStr << "\"";
1711 }
1712 outStr << "/>";
1713 return outStr.str();
1714}//getNonlinearExpressionInXML()
1715
1716
1718{
1719 m_dFunctionValue = this->value;
1720 return m_dFunctionValue;
1721}// end OSnLNodeNumber::calculate
1722
1723ADdouble OSnLNodeNumber::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
1724{
1725 m_ADTape = this->value;
1726 return m_ADTape;
1727}// end OSnLNodeNumber::constructADTape
1728
1730{
1731 OSnLNode *nlNodePoint;
1732 nlNodePoint = new OSnLNodeNumber();
1733 return nlNodePoint;
1734}//end OSnLNodeNumber::cloneExprNode
1735
1736
1738{
1739#ifndef NDEBUG
1740 ostringstream outStr;
1741 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
1742 outStr << " (" << this->getTokenName() << ")" << std::endl;
1744#endif
1745
1749 ndcopy->inodeInt = inodeInt;
1750 ndcopy->inodeType = inodeType;
1751 ndcopy->value = value;
1752 ndcopy->type = type;
1753 ndcopy->id = id;
1754
1755 if (inumberOfChildren > 0)
1756 {
1757 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
1758 for (unsigned int i=0; i < inumberOfChildren; i++)
1759 {
1761 }
1762 }
1763
1765 {
1766 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
1767 for (unsigned int i=0; i < inumberOfMatrixChildren; i++)
1768 {
1770 }
1771 }
1772
1773 return ndcopy;
1774}// end OSnLNodeNumber::copyNodeAndDescendants
1775
1777{
1778#ifndef NDEBUG
1779 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLNodeNumber");
1780#endif
1781 if (this == NULL)
1782 {
1783 if (that == NULL)
1784 return true;
1785 else
1786 {
1787#ifndef NDEBUG
1789 "First object is NULL, second is not");
1790#endif
1791 return false;
1792 }
1793 }
1794 else
1795 {
1796 if (that == NULL)
1797 {
1798#ifndef NDEBUG
1800 "Second object is NULL, first is not");
1801#endif
1802 return false;
1803 }
1804 else
1805 {
1806 if (this->inodeInt != that->inodeInt)
1807 return false;
1808 if (this->inodeType != that->inodeType)
1809 return false;
1810 if (this->inumberOfChildren != that->inumberOfChildren)
1811 return false;
1813 return false;
1814
1815 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
1816 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
1817 return false;
1818
1819 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
1820 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
1821 return false;
1822
1823 if (this->value != that->value)
1824 return false;
1825 if (this->type != that->type)
1826 return false;
1827 if (this->id != that->id)
1828 return false;
1829 return true;
1830 }
1831 }
1832}//OSnLNodeNumber::IsEqual
1833// end OSnLNodeNumber methods
1834
1835
1836// OSnLNodeE Methods
1838{
1839 inodeInt = OS_E;
1842 m_mChildren = NULL;
1843 m_mMatrixChildren = NULL;
1844 inodeType = 0;
1845 //value = 0.0;
1846 //type = "real";
1847 //id = "";
1848}//end OSnLNodeE
1849
1851{
1852#ifndef NDEBUG
1853 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeE destructor");
1854#endif
1855}//end ~OSnLNodeE
1856
1857
1859{
1860 ostringstream outStr;
1861 outStr << inodeInt;
1862 return outStr.str();
1863}//getTokenNumber
1864
1865
1867{
1868 ostringstream outStr;
1869 outStr << "E";
1870 return outStr.str();
1871}//getTokenName
1872
1873
1875{
1876 ostringstream outStr;
1877 outStr << "<" ;
1878 outStr << "E";
1879 outStr << "/>";
1880 return outStr.str();
1881}//getNonlinearExpressionInXML()
1882
1883
1885{
1887 return m_dFunctionValue;
1888}// end OSnLNodeE::calculate
1889
1890ADdouble OSnLNodeE::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
1891{
1893 return m_ADTape;
1894}// end OSnLE::constructADTape
1895
1897{
1898 OSnLNode *nlNodePoint;
1899 nlNodePoint = new OSnLNodeE();
1900 return nlNodePoint;
1901}//end OSnLNodeE::cloneExprNode
1902//end OSnLNodeE
1903
1904
1905// OSnLNodePI Methods
1907{
1908 inodeInt = OS_PI;
1911 m_mChildren = NULL;
1912 m_mMatrixChildren = NULL;
1913 inodeType = 0;
1914}//end OSnLNodePI
1915
1916
1918{
1919#ifndef NDEBUG
1920 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodePI destructor");
1921#endif
1922}//end ~OSnLNodePI
1923
1924
1926{
1927 ostringstream outStr;
1928 outStr << inodeInt;
1929 return outStr.str();
1930}//getTokenNumber
1931
1932
1934{
1935 ostringstream outStr;
1936 outStr << "PI";
1937 return outStr.str();
1938}//getTokenName
1939
1940
1942{
1943 ostringstream outStr;
1944 outStr << "<" ;
1945 outStr << "PI";
1946 outStr << "/>";
1947 return outStr.str();
1948}//getNonlinearExpressionInXML()
1949
1950
1952{
1954 return m_dFunctionValue;
1955}// end OSnLNodePI::calculate
1956
1957ADdouble OSnLNodePI::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
1958{
1960 return m_ADTape;
1961}// end OSnLE::constructADTape
1962
1964{
1965 OSnLNode *nlNodePoint;
1966 nlNodePoint = new OSnLNodePI();
1967 return nlNodePoint;
1968}//end OSnLNodePI::cloneExprNode
1969//end OSnLNodePI methods
1970
1971
1972// OSnLNodeVariable Methods
1974{
1977 m_mChildren = NULL;
1978 m_mMatrixChildren = NULL;
1980 inodeType = -1;
1981 coef = 1.0;
1982 idx = -1;
1983}//end OSnLNodeVariable
1984
1986{
1987 std::ostringstream outStr;
1988#ifndef NDEBUG
1989 outStr << "inside OSnLNodeVariable destructor" << endl;
1991#endif
1992}//end ~OSnLNodeVariable
1993
1994
1996{
1997 ostringstream outStr;
1998 // put in an error if inodeInt is not 6001
1999 outStr << inodeInt;
2000 outStr << "[";
2001 outStr << inumberOfChildren ;
2002 outStr << "]";
2003 outStr << ":" ;
2004 outStr << idx;
2005 outStr << ":" ;
2006 outStr << coef;
2007 outStr << ":real:" ;
2008 return outStr.str();
2009}//getTokenNumber
2010
2011
2013{
2014 ostringstream outStr;
2015 // put in an error if inodeInt is not 6001
2016 outStr << "variable";
2017 outStr << "[";
2018 outStr << inumberOfChildren ;
2019 outStr << "]";
2020 outStr << ":" ;
2021 outStr << idx;
2022 outStr << ":" ;
2023 outStr << coef;
2024 outStr << ":real:" ;
2025 return outStr.str();
2026}//getTokenName
2027
2028
2030{
2031 ostringstream outStr;
2032 outStr << "<";
2033 outStr << "variable";
2034 outStr << " idx=\"";
2035 outStr << idx;
2036 outStr << "\"";
2037 if (coef < 1 || coef > 1)
2038 {
2039 outStr << " coef=\"";
2040 outStr << os_dtoa_format(coef);
2041 outStr << "\"";
2042 }
2043 if (inumberOfChildren > 0)
2044 {
2045 outStr << ">";
2046 for(unsigned int i = 0; i < inumberOfChildren; i++)
2047 {
2049 }
2050 outStr << "</variable>";
2051 }
2052 else
2053 {
2054 outStr << "/>";
2055 }
2056 return outStr.str();
2057}//getNonlinearExpressionInXML
2058
2060{
2062 return m_dFunctionValue;
2063}// end OSnLNodeVariable::calculate
2064
2065ADdouble OSnLNodeVariable::constructADTape(std::map<int, int> *varIdx, ADvector *XAD)
2066{
2067 m_ADTape = coef*(*XAD)[ (*varIdx)[ idx] ];
2068 return m_ADTape;
2069}// end OSnLNodeVariable::constructADTape
2070
2071
2072void OSnLNodeVariable::getVariableIndexMap(std::map<int, int> *varIdx)
2073{
2074 int numVars;
2075 if( (*varIdx).find( idx) == (*varIdx).end() ) // variable to map with variable index as the key
2076 {
2077 //just put a placeholder for now to record the key.
2078 // The value will be added once we know the location within the sparse Jacobian
2079 (*varIdx)[ idx] = 1;
2080#ifndef NDEBUG
2081 ostringstream outStr;
2082 outStr << "add variable " << idx << " to the map" << std::endl;
2084#endif
2085 }
2086}//getVariableIndexMap
2087
2089{
2090 OSnLNode *nlNodePoint;
2091 nlNodePoint = new OSnLNodeVariable();
2092 return nlNodePoint;
2093}//end OSnLNodeVariable::cloneExprNode
2094
2095
2097{
2098#ifndef NDEBUG
2099 ostringstream outStr;
2100 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
2101 outStr << " (" << this->getTokenName() << ")" << std::endl;
2103#endif
2104
2108 ndcopy->inodeInt = inodeInt;
2109 ndcopy->inodeType = inodeType;
2110 ndcopy->coef = coef;
2111 ndcopy->idx = idx;
2112
2113 if (inumberOfChildren > 0)
2114 {
2115 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
2116 for (unsigned int i=0; i < inumberOfChildren; i++)
2117 {
2118 ndcopy->m_mChildren[i] = /*(OSnLNode)*/m_mChildren[i]->copyNodeAndDescendants();
2119 }
2120 }
2121
2123 {
2124 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
2125 for (unsigned int i=0; i < inumberOfMatrixChildren; i++)
2126 {
2128 }
2129 }
2130
2131 return ndcopy;
2132}// end OSnLNodeVariable::copyNodeAndDescendants
2133
2134
2136{
2137#ifndef NDEBUG
2138 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLNodeVariable");
2139#endif
2140 if (this == NULL)
2141 {
2142 if (that == NULL)
2143 return true;
2144 else
2145 {
2146#ifndef NDEBUG
2148 "First object is NULL, second is not");
2149#endif
2150 return false;
2151 }
2152 }
2153 else
2154 {
2155 if (that == NULL)
2156 {
2157#ifndef NDEBUG
2159 "Second object is NULL, first is not");
2160#endif
2161 return false;
2162 }
2163 else
2164 {
2165 if (this->inodeInt != that->inodeInt)
2166 return false;
2167 if (this->inodeType != that->inodeType)
2168 return false;
2169 if (this->inumberOfChildren != that->inumberOfChildren)
2170 return false;
2172 return false;
2173
2174 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
2175 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
2176 return false;
2177
2178 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
2179 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
2180 return false;
2181
2182 if (this->coef != that->coef)
2183 return false;
2184 if (this->idx != that->idx)
2185 return false;
2186 return true;
2187 }
2188 }
2189}//OSnLNodeVariable::IsEqual
2190
2191
2192
2195//
2196// OSnLNodeMatrixDeterminant Methods
2205
2207{
2208#ifndef NDEBUG
2209 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeMatrixDeterminant destructor");
2210#endif
2211}//end ~OSnLNodeMatrixDeterminant
2212
2213
2215{
2217
2218 for(unsigned int i = 0; i < inumberOfChildren; i++)
2219 {
2221 {
2223 }
2224 }
2225 return m_dFunctionValue;
2226}// end OSnLNodeMatrixDeterminant::calculate
2227
2229{
2230 return "matrixDeterminant";
2231}// end OSnLNodeMatrixDeterminant::getTokenName(
2232
2233
2235{
2236 //if not support in AD, throw an exception
2237 try
2238 {
2239 throw ErrorClass("Matrix determinant operator not supported by current Algorithmic Differentiation implementation");
2240 return m_ADTape;
2241 }
2242 catch(const ErrorClass& eclass)
2243 {
2244 throw ErrorClass( eclass.errormsg);
2245 }
2246}// end OSnLNodeMatrixDeterminant::constructADTape
2247
2248
2250{
2251 OSnLNode *nlNodePoint;
2252 nlNodePoint = new OSnLNodeMatrixDeterminant();
2253 return nlNodePoint;
2254}//end OSnLNodeMatrixDeterminant::cloneExprNode
2255
2256
2257// OSnLNodeMatrixTrace Methods
2259{
2262 m_mMatrixChildren = new OSnLMNode*[1];
2264 inodeType = 0;
2265}//end OSnLNodeMatrixTrace
2266
2268{
2269#ifndef NDEBUG
2270 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeMatrixTrace destructor");
2271#endif
2272}//end ~OSnLNodeMatrixDeterminant
2273
2275{
2276#if 0
2278
2279 for(unsigned int i = 0; i < inumberOfChildren; i++)
2280 {
2282 {
2284 }
2285 }
2286 return m_dFunctionValue;
2287#endif
2288 return 0.0;
2289}// end OSnLNodeMatrixTrace::calculate
2290
2292{
2293 return "matrixTrace";
2294}// end OSnLNodeMatrixTrace::getTokenName(
2295
2296
2298{
2299 //if not support in AD, throw an exception
2300 try
2301 {
2302 throw ErrorClass("Matrix trace operator not supported by current Algorithmic Differentiation implementation");
2303 return m_ADTape;
2304 }
2305 catch(const ErrorClass& eclass)
2306 {
2307 throw ErrorClass( eclass.errormsg);
2308 }
2309}// end OSnLNodeMatrixTrace::constructADTape
2310
2311
2313{
2314 OSnLNode *nlNodePoint;
2315 nlNodePoint = new OSnLNodeMatrixTrace();
2316 return nlNodePoint;
2317}//end OSnLNodeMatrixTrace::cloneExprNode
2318
2319
2320//
2321// OSnLNodeMatrixToScalar Methods
2323{
2326 m_mMatrixChildren = new OSnLMNode*[1];
2328 inodeType = 0;
2329}//end OSnLNodeMatrixToScalar
2330
2332{
2333#ifndef NDEBUG
2334 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeMatrixToScalar destructor");
2335#endif
2336}//end ~OSnLNodeMatrixToScalar
2337
2339{
2341
2342 for(unsigned int i = 0; i < inumberOfChildren; i++)
2343 {
2345 {
2347 }
2348 }
2349 return m_dFunctionValue;
2350}// end OSnLNodeMatrixToScalar::calculate
2351
2353{
2354 return "matrixToScalar";
2355}// end OSnLNodeMatrixToScalar::getTokenName(
2356
2357
2359{
2360 //if not support in AD, throw an exception
2361 try
2362 {
2363 throw ErrorClass("Matrix-to-scalar conversion not supported by current Algorithmic Differentiation implementation");
2364 return m_ADTape;
2365 }
2366 catch(const ErrorClass& eclass)
2367 {
2368 throw ErrorClass( eclass.errormsg);
2369 }
2370}// end OSnLNodeMatrixToScalar::constructADTape
2371
2372
2374{
2375 OSnLNode *nlNodePoint;
2376 nlNodePoint = new OSnLNodeMatrixToScalar();
2377 return nlNodePoint;
2378}//end OSnLNodeMatrixToScalar::cloneExprNode
2379
2380
2381/***********************************************************
2382 * Implementation of OSnLMNode and inheriting classes *
2383 ***********************************************************/
2385 ExprNode()
2386{
2387#ifndef NDEBUG
2388 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLMNode constructor");
2389#endif
2390}//end OSnLMNode
2391
2393{
2394#ifndef NDEBUG
2395 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLMNode destructor");
2396#endif
2397}//end ~OSnLNode
2398
2400{
2401#ifndef NDEBUG
2402 ostringstream outStr;
2403 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
2404 outStr << " (" << this->getTokenName() << ")" << std::endl;
2406#endif
2407
2408 OSnLMNode* ndcopy = (OSnLMNode*)cloneExprNode();
2411 ndcopy->inodeInt = inodeInt;
2412 ndcopy->inodeType = inodeType;
2413
2414 if (inumberOfChildren > 0)
2415 {
2416 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
2417 for (unsigned int i=0; i < inumberOfChildren; i++)
2418 {
2420 }
2421 }
2422
2424 {
2425 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
2426 for (unsigned int i=0; i < inumberOfMatrixChildren; i++)
2427 {
2429 }
2430 }
2431
2432 return ndcopy;
2433}// end copyNodeAndDescendants
2434
2435#if 0
2436OSnLMNode* OSnLMNode::createExpressionTreeFromPostfix(std::vector<OSnLMNode*> nlMNodeVec)
2437{
2438 std::vector<OSnLMNode*> stackVec ;
2439 unsigned int kount = 0;
2440 while(kount <= nlMNodeVec.size() - 1)
2441 {
2442 int numkids = nlMNodeVec[kount]->inumberOfMatrixChildren;
2443 if(numkids > 0)
2444 {
2445 for(int i = numkids - 1; i >= 0; i--)
2446 {
2447 nlMNodeVec[kount]->m_mMatrixChildren[i] = stackVec.back() ;
2448 stackVec.pop_back();
2449 }
2450 }
2451 stackVec.push_back( nlMNodeVec[kount]);
2452 kount++;
2453 }
2454 stackVec.clear();
2455 return nlMNodeVec[ kount - 1];
2456}//end createExpressionTreeFromPostfix
2457
2458std::vector<OSnLMNode*> OSnLMNode::getPostfixFromExpressionTree( )
2459{
2460// std::vector<OSnLMNode*> postfixVector;
2461// return postOrderOSnLNodeTraversal( &postfixVector);
2462 return 0;
2463}//getPostfixFromExpressionTree
2464
2465std::vector<OSnLNode*> OSnLNode::postOrderOSnLNodeTraversal( std::vector<OSnLNode*> *postfixVector)
2466{
2467 if(inumberOfChildren > 0)
2468 {
2469 unsigned int i;
2470 for(i = 0; i < inumberOfChildren; i++)
2471 m_mChildren[i]->postOrderOSnLNodeTraversal( postfixVector);
2472 }
2473 (*postfixVector).push_back( this);
2474 return *postfixVector;
2475}//end postOrderOSnLNodeTraversal()
2476#endif
2477
2479{
2480 std::vector<ExprNode*> stackVec;
2481 int kount = nlNodeVec.size() - 1;
2482 while(kount >= 0)
2483 {
2484 int numkids = nlNodeVec[kount]->inumberOfChildren;
2485 if(numkids > 0)
2486 {
2487 for(int i = 0; i < numkids; i++)
2488 {
2489 nlNodeVec[kount]->m_mChildren[i] = (OSnLNode*)stackVec.back();
2490 stackVec.pop_back();
2491 }
2492 }
2493 int mtxkids = nlNodeVec[kount]->inumberOfMatrixChildren;
2494 if(mtxkids > 0)
2495 {
2496 for(int i = 0; i < mtxkids; i++)
2497 {
2498 nlNodeVec[kount]->m_mMatrixChildren[i] = (OSnLMNode*)stackVec.back();
2499 stackVec.pop_back();
2500 }
2501 }
2502 stackVec.push_back( nlNodeVec[kount]);
2503 kount--;
2504 }
2505 stackVec.clear();
2506 return (OSnLMNode*)nlNodeVec[ 0];
2507}//end createExpressionTreeFromPrefix
2508
2510{
2511 std::vector<ExprNode*> stackVec;
2512 size_t kount = 0;
2513
2514 while(kount <= nlNodeVec.size() - 1)
2515 {
2516 int numMtxKids = nlNodeVec[kount]->inumberOfMatrixChildren;
2517 if (numMtxKids > 0)
2518 {
2519 for(int i = numMtxKids - 1; i >= 0; i--)
2520 {
2521 nlNodeVec[kount]->m_mMatrixChildren[i] = (OSnLMNode*)stackVec.back();
2522 stackVec.pop_back();
2523 }
2524 }
2525 int numkids = nlNodeVec[kount]->inumberOfChildren;
2526 if (numkids > 0)
2527 {
2528 for(int i = numkids - 1; i >= 0; i--)
2529 {
2530 nlNodeVec[kount]->m_mChildren[i] = (OSnLNode*)stackVec.back();
2531 stackVec.pop_back();
2532 }
2533 }
2534 stackVec.push_back( nlNodeVec[kount]);
2535 kount++;
2536 }
2537 stackVec.clear();
2538 return (OSnLMNode*)nlNodeVec[ kount - 1];
2539}//end createExpressionTreeFromPostfix
2540
2541
2543{
2544 std::vector<ExprNode*> prefixVector;
2545 return preOrderOSnLNodeTraversal( &prefixVector);
2546}//getPrefixFromExpressionTree
2547
2548std::vector<ExprNode*> OSnLMNode::preOrderOSnLNodeTraversal( std::vector<ExprNode*> *prefixVector)
2549{
2550 (*prefixVector).push_back( (OSnLMNode*)this);
2551 if(inumberOfChildren > 0)
2552 {
2553 for(unsigned int i = 0; i < inumberOfChildren; i++)
2555 }
2557 {
2558 for(unsigned int i = 0; i < inumberOfMatrixChildren; i++)
2560 }
2561 return *prefixVector;
2562}//end preOrderOSnLNodeTraversal
2563
2565{
2566 std::vector<ExprNode*> postfixVector;
2567 return postOrderOSnLNodeTraversal( &postfixVector);
2568}//getPostfixFromExpressionTree
2569
2570
2571std::vector<ExprNode*> OSnLMNode::postOrderOSnLNodeTraversal( std::vector<ExprNode*> *postfixVector)
2572{
2573 if(inumberOfChildren > 0)
2574 {
2575 unsigned int i;
2576 for(i = 0; i < inumberOfChildren; i++)
2578 }
2580 {
2581 unsigned int i;
2582 for(i = 0; i < inumberOfMatrixChildren; i++)
2584 }
2585 (*postfixVector).push_back( (OSnLMNode*)this);
2586 return *postfixVector;
2587}//end postOrderOSnLNodeTraversal()
2588
2589#if 0
2590std::string OSnLMNode::getTokenNumber()
2591{
2592 ostringstream outStr;
2593 outStr << inodeInt;
2594
2595 // when I create an OSnLNode from a token number, I need to know how many children there are
2596// if(inodeType == -1){
2597 outStr << "[";
2598 outStr << inumberOfChildren ;
2599 outStr << "]";
2600// }
2601 return outStr.str();
2602}//getTokenNumber
2603
2604
2605/*
2606OSnLNode* OSnLNode::getOSnLNodeFromToken(std::string sToken){
2607// kipp possibly make this a static method or put it somewhere else
2608 OSnLNode *nlNodePoint;
2609 int nodeID ;
2610 int pos1, pos2;
2611 std::string str1, str2;
2612 // convert the std::string tokens into the appropriate objects
2613 // kipp -- put in error check -- make sure > 0 and < 10001
2614 nodeID = atoi( &sToken.substr(0, 4)[0]);
2615 switch (nodeID){
2616 case OS_SUM: // the sum token
2617 pos1 = sToken.find('[');
2618 pos2 = sToken.find(']');
2619 if((pos1 == std::string::npos) || (pos2 == std::string::npos)){
2620 // throw error
2621 }
2622 OSnLNodeSum *nlNodePointSum;
2623 nlNodePointSum = new OSnLNodeSum();
2624 nlNodePointSum->inumberOfChildren = atoi( &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
2625 nlNodePointSum->m_mChildren = new OSnLNode*[ nlNodePointSum->inumberOfChildren];
2626 return nlNodePointSum;
2627 break;
2628 case OS_MAX: // the max token
2629 pos1 = sToken.find('[');
2630 pos2 = sToken.find(']');
2631 if((pos1 == std::string::npos) || (pos2 == std::string::npos)){
2632 // throw error
2633 }
2634 OSnLNodeMax *nlNodePointMax;
2635 nlNodePointMax = new OSnLNodeMax();
2636 nlNodePointMax->inumberOfChildren = atoi( &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
2637 nlNodePointMax->m_mChildren = new OSnLNode*[ nlNodePointMax->inumberOfChildren];
2638 return nlNodePointMax;
2639 break;
2640 case OS_PRODUCT: // the product token
2641 pos1 = sToken.find('[');
2642 pos2 = sToken.find(']');
2643 if((pos1 == std::string::npos) || (pos2 == std::string::npos)){
2644 // throw error
2645 }
2646 OSnLNodeProduct *nlNodePointProduct;
2647 nlNodePointProduct = new OSnLNodeProduct();
2648 nlNodePointProduct->inumberOfChildren = atoi( &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
2649 nlNodePointProduct->m_mChildren = new OSnLNode*[ nlNodePointProduct->inumberOfChildren];
2650 return nlNodePointProduct;
2651 break;
2652 case OS_NUMBER: // the number token
2653 pos1 = sToken.find(':');
2654 if(pos1 != 4){
2655 //throw error
2656 }
2657 // now get the second semicolon, the one that should be after value
2658 pos2 = sToken.find(':', pos1 + 1);
2659 if(pos2 != std::string::npos) {
2660 }
2661 else{
2662 //throw error
2663 }
2664 OSnLNodeNumber *nlNodePointNumber;
2665 nlNodePointNumber = new OSnLNodeNumber();
2666 nlNodePointNumber->value = atof( &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
2667 return nlNodePointNumber;
2668 break;
2669 case OS_VARIABLE: // the variable token
2670 pos1 = sToken.find('[');
2671 pos2 = sToken.find(']');
2672 if((pos1 == std::string::npos) || (pos2 == std::string::npos)){
2673 // throw error
2674 }
2675 OSnLNodeVariable *nlNodePointVariable;
2676 nlNodePointVariable = new OSnLNodeVariable();
2677 nlNodePointVariable->inumberOfChildren = atoi( &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
2678 nlNodePointVariable->m_mChildren = new OSnLNode*[ nlNodePointVariable->inumberOfChildren];
2679 // throw error if there is more than one child
2680 // now get the index and the coefficient
2681 pos1 = sToken.find(':');
2682 if(pos1 != 4){
2683 //throw error
2684 }
2685 // now get the second semicolon, the one that should be after idx
2686 pos2 = sToken.find(':', pos1 + 1);
2687 if(pos2 == std::string::npos) {
2688 //throw error
2689 }
2690 nlNodePointVariable->idx = atoi( &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
2691 // now get the coefficient
2692 str1 = sToken;
2693 str2 = sToken.substr(pos2 + 1, str1.length() - pos2 - 1);
2694 nlNodePointVariable->coef = atof(&str2[0]);
2695 return nlNodePointVariable;
2696 break;
2697 default:
2698 nlNodePoint = nlNodeArray[ nlNodeIdxMap[ nodeID]]->cloneExprNode();
2699 break;
2700 }
2701 return nlNodePoint;
2702}//end getOSnLNodeFromToken
2703*/
2704
2705
2706
2708{
2709 ostringstream outStr, logStr;
2710 outStr << "<" ;
2711 outStr << this->getTokenName();
2712#ifndef NDEBUG
2713 logStr << "nonlinear node " << this->getTokenName() << endl;
2715#endif
2716 if(inumberOfChildren > 0)
2717 {
2718
2719 outStr << ">";
2720 }
2721 else
2722 {
2723
2724 outStr << "/>";
2725 }
2726 if(inumberOfChildren > 0)
2727 {
2728 for(unsigned int i = 0; i < inumberOfChildren; i++)
2729 {
2731 }
2732 }
2733 if(inumberOfChildren > 0)
2734
2735 {
2736 outStr << "</" ;
2737 outStr << this->getTokenName() ;
2738 outStr << ">" ;
2739 }
2740 return outStr.str();
2741}//getNonlinearExpressionInXML()
2742//
2743//
2744
2745void OSnLNode::getVariableIndexMap(std::map<int, int> *varIdx)
2746{
2747 unsigned int i;
2748 if(inodeInt != OS_VARIABLE)
2749 {
2750 for(i = 0; i < inumberOfChildren; i++)
2751 {
2752 m_mChildren[ i]->getVariableIndexMap( varIdx);
2753 }
2754
2755
2756 }
2757}//getVariableIndexMap
2758#endif
2759
2761{
2762#ifndef NDEBUG
2763 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLMNode");
2764#endif
2765 if (this == NULL)
2766 {
2767 if (that == NULL)
2768 return true;
2769 else
2770 {
2771#ifndef NDEBUG
2773 "First object is NULL, second is not");
2774#endif
2775 return false;
2776 }
2777 }
2778 else
2779 {
2780 if (that == NULL)
2781 {
2782#ifndef NDEBUG
2784 "Second object is NULL, first is not");
2785#endif
2786 return false;
2787 }
2788 else
2789 {
2790 if (this->inumberOfChildren != that->inumberOfChildren)
2791 return false;
2793 return false;
2794 if (this->inodeInt != that->inodeInt)
2795 return false;
2796 if (this->inodeType != that->inodeType)
2797 return false;
2798
2799 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
2800 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
2801 return false;
2802
2803 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
2804 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
2805 return false;
2806
2807 return true;
2808 }
2809 }
2810}//OSnLMNode::IsEqual
2811
2812#if 0
2814{
2815 OSnLMNode* ndcopy = cloneExprNode();
2816
2819 ndcopy->inodeInt = inodeInt;
2820 ndcopy->inodeType = inodeType;
2821
2822 if (inumberOfChildren > 0)
2823 {
2824 //ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
2825 for (int i=0; i < inumberOfChildren; i++)
2826 {
2827 ndcopy->m_mChildren[i] = m_mChildren[i]->(OSnLNode)copyNodeAndDescendants();
2828 }
2829 }
2830
2832 {
2833 //ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
2834 for (int i=0; i < inumberOfMatrixChildren; i++)
2835 {
2836 ndcopy->m_mMatrixChildren[i] = m_mMatrixChildren[i]->(OSnLMNode)copyNodeAndDescendants();
2837 }
2838 }
2839
2840 return ndcopy;
2841}// end OSnLNode::copyNodeAndDescendants
2842#endif
2843
2844// OSnLMNodeMatrixPlus Methods
2846{
2849 m_mChildren = NULL;
2850 m_mMatrixChildren = new OSnLMNode*[2];
2852 inodeType = 2;
2853}//end OSnLMNodeMatrixPlus
2854
2856{
2857 std::ostringstream outStr;
2858#ifndef NDEBUG
2859 outStr << "inside OSnLMNodeMatrixPlus destructor" << endl;
2861#endif
2862}//end ~OSnLMNodeMatrixPlus
2863
2865{
2866 return "matrixPlus";
2867}// end OSnLMNodeMatrixPlus::getTokenName()
2868
2870{
2871 OSnLMNode *nlMNodePoint;
2872 nlMNodePoint = new OSnLMNodeMatrixPlus();
2873 return nlMNodePoint;
2874}//end OSnLMNodeMatrixPlus::cloneExprNode
2875
2876
2877// OSnLMNodeMatrixSum Methods
2879{
2882 m_mChildren = NULL;
2883 m_mMatrixChildren = NULL;
2885 inodeType = -1;
2886
2887
2888}//end OSnLMNodeMatrixSum
2889
2891{
2892 std::ostringstream outStr;
2893#ifndef NDEBUG
2894 outStr << "inside OSnLMNodeMatrixSum destructor" << endl;
2896#endif
2897}//end ~OSnLMNodeMatrixSum
2898
2900{
2901 return "matrixSum";
2902}// end OSnLMNodeMatrixSum::getTokenName()
2903
2905{
2906 OSnLMNode *nlMNodePoint;
2907 nlMNodePoint = new OSnLMNodeMatrixSum();
2908 return nlMNodePoint;
2909}//end OSnLMNodeMatrixSum::cloneExprNode
2910
2911//
2912// OSnLMNodeMatrixProduct Methods
2914{
2917 m_mChildren = NULL;
2918 m_mMatrixChildren = NULL;
2920 inodeType = -1;
2921}//end OSnLMNodeMatrixProduct
2922
2923
2925{
2926#ifndef NDEBUG
2927 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLMNodeMatrixProduct destructor");
2928#endif
2929}//end ~OSnLMNodeMatrixProduct
2930
2932{
2933 return "matrixProduct";
2934}// end OSnLMNodeMatrixProduct::getTokenName(
2935
2936#if 0
2937double OSnLMNodeMatrixProduct::calculateFunction(double *x)
2938{
2939 // kipp throw error if operation not defined
2940 m_dFunctionValue = 1.0;
2941 unsigned int i;
2942 for(i = 0; i < inumberOfChildren; i++)
2943 {
2944 m_dFunctionValue = m_dFunctionValue*m_mChildren[i]->calculateFunction(x);
2945 }
2946 return m_dFunctionValue;
2947}// end OSnLMNodeMatrixProduct::calculate
2948
2949
2950ADdouble OSnLMNodeMatrixProduct::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
2951{
2952 m_ADTape = 1.0;
2953 unsigned int i;
2954 for(i = 0; i < inumberOfChildren; i++)
2955 {
2956 m_ADTape = m_ADTape*m_mChildren[i]->constructADTape( ADIdx, XAD);
2957 }
2958 return m_ADTape;
2959}// end OSnLMNodeMatrixProduct::constructADTape
2960#endif
2961
2963{
2964 OSnLMNode *nlMNodePoint;
2965 nlMNodePoint = new OSnLMNodeMatrixProduct();
2966 return nlMNodePoint;
2967}//end OSnLMNodeMatrixProduct::cloneExprNode
2968
2969
2970// OSnLMNodeMatrixMinus Methods
2972{
2975 m_mChildren = NULL;
2976 m_mMatrixChildren = new OSnLMNode*[2];
2978 inodeType = 2;
2979}//end OSnLMNodeMatrixMinus
2980
2982{
2983 std::ostringstream outStr;
2984#ifndef NDEBUG
2985 outStr << "inside OSnLMNodeMatrixMinus destructor" << endl;
2987#endif
2988}//end ~OSnLMNodeMatrixMinus
2989
2991{
2992 return "matrixMinus";
2993}// end OSnLMNodeMatrixMinus::getTokenName()
2994
2996{
2997 OSnLMNode *nlMNodePoint;
2998 nlMNodePoint = new OSnLMNodeMatrixMinus();
2999 return nlMNodePoint;
3000}//end OSnLMNodeMatrixMinus::cloneExprNode
3001
3002// OSnLMNodeMatrixNegate Methods
3004{
3007 m_mChildren = NULL;
3008 m_mMatrixChildren = new OSnLMNode*[1];
3010 inodeType = 1;
3011}//end OSnLMNodeMatrixNegate
3012
3014{
3015 std::ostringstream outStr;
3016#ifndef NDEBUG
3017 outStr << "inside OSnLMNodeMatrixNegate destructor" << endl;
3019#endif
3020}//end ~OSnLMNodeMatrixNegate
3021
3023{
3024 return "matrixNegate";
3025}// end OSnLMNodeMatrixNegate::getTokenName()
3026
3028{
3029 OSnLMNode *nlMNodePoint;
3030 nlMNodePoint = new OSnLMNodeMatrixNegate();
3031 return nlMNodePoint;
3032}//end OSnLMNodeMatrixNegate::cloneExprNode
3033
3034// OSnLMNodeMatrixTimes Methods
3036{
3039 m_mChildren = NULL;
3040 m_mMatrixChildren = new OSnLMNode*[2];
3042 inodeType = 2;
3043}//end OSnLMNodeMatrixTimes
3044
3046{
3047 std::ostringstream outStr;
3048#ifndef NDEBUG
3049 outStr << "inside OSnLMNodeMatrixTimes destructor" << endl;
3051#endif
3052}//end ~OSnLMNodeMatrixTimes
3053
3055{
3056 return "matrixTimes";
3057}// end OSnLMNodeMatrixTimes::getTokenName()
3058
3060{
3061 OSnLMNode *nlMNodePoint;
3062 nlMNodePoint = new OSnLMNodeMatrixTimes();
3063 return nlMNodePoint;
3064}//end OSnLMNodeMatrixTimes::cloneExprNode
3065
3066// OSnLMNodeMatrixInverse Methods
3068{
3071 m_mChildren = NULL;
3072 m_mMatrixChildren = new OSnLMNode*[1];
3074 inodeType = 1;
3075}//end OSnLMNodeMatrixInverse
3076
3078{
3079 std::ostringstream outStr;
3080#ifndef NDEBUG
3081 outStr << "inside OSnLMNodeMatrixInverse destructor" << endl;
3083#endif
3084}//end ~OSnLMNodeMatrixInverse
3085
3087{
3088 return "matrixInverse";
3089}// end OSnLMNodeMatrixInverse::getTokenName()
3090
3092{
3093 OSnLMNode *nlMNodePoint;
3094 nlMNodePoint = new OSnLMNodeMatrixInverse();
3095 return nlMNodePoint;
3096}//end OSnLMNodeMatrixInverse::cloneExprNode
3097
3098
3099// OSnLMNodeMatrixTranspose Methods
3101{
3104 m_mChildren = NULL;
3105 m_mMatrixChildren = new OSnLMNode*[1];
3107 inodeType = 1;
3108}//end OSnLMNodeMatrixTranspose
3109
3111{
3112 std::ostringstream outStr;
3113#ifndef NDEBUG
3114 outStr << "inside OSnLMNodeMatrixTranspose destructor" << endl;
3116#endif
3117}//end ~OSnLMNodeMatrixTranspose
3118
3120{
3121 return "matrixTranspose";
3122}// end OSnLMNodeMatrixTranspose::getTokenName()
3123
3125{
3126 OSnLMNode *nlMNodePoint;
3127 nlMNodePoint = new OSnLMNodeMatrixTranspose();
3128 return nlMNodePoint;
3129}//end OSnLMNodeMatrixTranspose::cloneExprNode
3130
3131// OSnLMNodeMatrixScalarTimes Methods
3133{
3136 m_mChildren = new OSnLNode*[1];
3137 m_mMatrixChildren = new OSnLMNode*[1];
3139 inodeType = 1;
3140}//end OSnLMNodeMatrixScalarTimes
3141
3143{
3144 std::ostringstream outStr;
3145#ifndef NDEBUG
3146 outStr << "inside OSnLMNodeMatrixScalarTimes destructor" << endl;
3148#endif
3149}//end ~OSnLMNodeMatrixScalarTimes
3150
3152{
3153 return "matrixScalarTimes";
3154}// end OSnLMNodeMatrixScalarTimes::getTokenName()
3155
3157{
3158 OSnLMNode *nlMNodePoint;
3159 nlMNodePoint = new OSnLMNodeMatrixScalarTimes();
3160 return nlMNodePoint;
3161}//end OSnLMNodeMatrixScalarTimes::cloneExprNode
3162
3163// OSnLMNodeMatrixDotTimes Methods
3165{
3168 m_mChildren = NULL;
3169 m_mMatrixChildren = new OSnLMNode*[2];
3171 inodeType = 2;
3172}//end OSnLMNodeMatrixDotTimes
3173
3175{
3176 std::ostringstream outStr;
3177#ifndef NDEBUG
3178 outStr << "inside OSnLMNodeMatrixDotTimes destructor" << endl;
3180#endif
3181}//end ~OSnLMNodeMatrixDotTimes
3182
3184{
3185 return "matrixDotTimes";
3186}// end OSnLMNodeMatrixDotTimes::getTokenName()
3187
3189{
3190 OSnLMNode *nlMNodePoint;
3191 nlMNodePoint = new OSnLMNodeMatrixDotTimes();
3192 return nlMNodePoint;
3193}//end OSnLMNodeMatrixDotTimes::cloneExprNode
3194
3195
3196// OSnLMNodeIdentityMatrix Methods
3198{
3201 m_mChildren = new OSnLNode*[1];
3202 m_mMatrixChildren = NULL;
3204 inodeType = -1;
3205}//end OSnLMNodeIdentityMatrix
3206
3208{
3209 std::ostringstream outStr;
3210#ifndef NDEBUG
3211 outStr << "inside OSnLMNodeIdentityMatrix destructor" << endl;
3213#endif
3214}//end ~OSnLMNodeIdentityMatrix
3215
3217{
3218 return "identityMatrix";
3219}// end OSnLMNodeIdentityMatrix::getTokenName()
3220
3222{
3223 OSnLMNode *nlMNodePoint;
3224 nlMNodePoint = new OSnLMNodeIdentityMatrix();
3225 return nlMNodePoint;
3226}//end OSnLMNodeIdentityMatrix::cloneExprNode
3227
3228
3229// OSnLMNodeMatrixLowerTriangle Methods
3231{
3234 m_mChildren = NULL;
3235 m_mMatrixChildren = new OSnLMNode*[1];
3237 inodeType = 1;
3238 includeDiagonal = true;
3239}//end OSnLMNodeMatrixLowerTriangle
3240
3242{
3243 std::ostringstream outStr;
3244#ifndef NDEBUG
3245 outStr << "inside OSnLMNodeMatrixLowerTriangle destructor" << endl;
3247#endif
3248}//end ~OSnLMNodeMatrixLowerTriangle
3249
3251{
3252 return "matrixLowerTriangle";
3253}// end OSnLMNodeMatrixLowerTriangle::getTokenName()
3254
3256{
3257 OSnLMNode *nlMNodePoint;
3258 nlMNodePoint = new OSnLMNodeMatrixLowerTriangle();
3259 return nlMNodePoint;
3260}//end OSnLMNodeMatrixLowerTriangle::cloneExprNode
3261
3263{
3264#ifndef NDEBUG
3265 ostringstream outStr;
3266 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
3267 outStr << " (" << this->getTokenName() << ")" << std::endl;
3269#endif
3270
3274 ndcopy->inodeInt = inodeInt;
3275 ndcopy->inodeType = inodeType;
3277
3278 if (inumberOfChildren > 0)
3279 {
3280 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
3281 for (unsigned int i=0; i < inumberOfChildren; i++)
3282 {
3284 }
3285 }
3286
3288 {
3289 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
3290 for (unsigned int i=0; i < inumberOfMatrixChildren; i++)
3291 {
3293 }
3294 }
3295
3296 return ndcopy;
3297}// end copyNodeAndDescendants
3298
3300{
3301 ostringstream outStr;
3302 outStr << "<matrixLowerTriangle";
3303 if (includeDiagonal == false)
3304 outStr << " includeDiagonal=\"false\"";
3305 outStr << ">" << std::endl;
3306
3308
3309 outStr << "</matrixLowerTriangle>";
3310 return outStr.str();
3311}//OSnLMNodeMatrixLowerTriangle::getNonlinearExpressionInXML
3312
3314{
3315#ifndef NDEBUG
3316 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLMNodeMatrixLowerTriangle");
3317#endif
3318 if (this == NULL)
3319 {
3320 if (that == NULL)
3321 return true;
3322 else
3323 {
3324#ifndef NDEBUG
3326 "First object is NULL, second is not");
3327#endif
3328 return false;
3329 }
3330 }
3331 else
3332 {
3333 if (that == NULL)
3334 {
3335#ifndef NDEBUG
3337 "Second object is NULL, first is not");
3338#endif
3339 return false;
3340 }
3341 else
3342 {
3343 if (this->inodeInt != that->inodeInt)
3344 return false;
3345 if (this->inodeType != that->inodeType)
3346 return false;
3347 if (this->inumberOfChildren != that->inumberOfChildren)
3348 return false;
3350 return false;
3351
3352 if (this->includeDiagonal != that->includeDiagonal)
3353 return false;
3354
3355 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
3356 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
3357 return false;
3358
3359 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
3360 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
3361 return false;
3362
3363 return true;
3364 }
3365 }
3366}//OSnLMNodeMatrixLowerTriangle::IsEqual
3367
3368
3369// OSnLMNodeMatrixUpperTriangle Methods
3370
3372{
3375 m_mChildren = NULL;
3376 m_mMatrixChildren = new OSnLMNode*[1];
3378 inodeType = 1;
3379
3380 includeDiagonal = true;
3381}//end OSnLMNodeMatrixUpperTriangle
3382
3384{
3385 std::ostringstream outStr;
3386#ifndef NDEBUG
3387 outStr << "inside OSnLMNodeMatrixUpperTriangle destructor" << endl;
3389#endif
3390}//end ~OSnLMNodeMatrixUpperTriangle
3391
3393{
3394 ostringstream outStr;
3395 outStr << "<matrixUpperTriangle";
3396 if (includeDiagonal == false)
3397 outStr << " includeDiagonal=\"false\"";
3398 outStr << ">" << std::endl;
3399
3401
3402 outStr << "</matrixUpperTriangle>";
3403 return outStr.str();
3404}//OSnLMNodeMatrixUpperTriangle::getNonlinearExpressionInXML
3405
3407{
3408 return "matrixUpperTriangle";
3409}// end OSnLMNodeMatrixUpperTriangle::getTokenName()
3410
3412{
3413 OSnLMNode *nlMNodePoint;
3414 nlMNodePoint = new OSnLMNodeMatrixUpperTriangle();
3415 return nlMNodePoint;
3416}//end OSnLMNodeMatrixUpperTriangle::cloneExprNode
3417
3419{
3420#ifndef NDEBUG
3421 ostringstream outStr;
3422 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
3423 outStr << " (" << this->getTokenName() << ")" << std::endl;
3425#endif
3426
3430 ndcopy->inodeInt = inodeInt;
3431 ndcopy->inodeType = inodeType;
3433
3434 if (inumberOfChildren > 0)
3435 {
3436 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
3437 for (unsigned int i=0; i < inumberOfChildren; i++)
3438 {
3440 }
3441 }
3442
3444 {
3445 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
3446 for (unsigned int i=0; i < inumberOfMatrixChildren; i++)
3447 {
3449 }
3450 }
3451
3452 return ndcopy;
3453}// end copyNodeAndDescendants
3454
3456{
3457#ifndef NDEBUG
3458 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLMNodeMatrixUpperTriangle");
3459#endif
3460 if (this == NULL)
3461 {
3462 if (that == NULL)
3463 return true;
3464 else
3465 {
3466#ifndef NDEBUG
3468 "First object is NULL, second is not");
3469#endif
3470 return false;
3471 }
3472 }
3473 else
3474 {
3475 if (that == NULL)
3476 {
3477#ifndef NDEBUG
3479 "Second object is NULL, first is not");
3480#endif
3481 return false;
3482 }
3483 else
3484 {
3485 if (this->inodeInt != that->inodeInt)
3486 return false;
3487 if (this->inodeType != that->inodeType)
3488 return false;
3489 if (this->inumberOfChildren != that->inumberOfChildren)
3490 return false;
3492 return false;
3493
3494 if (this->includeDiagonal != that->includeDiagonal)
3495 return false;
3496
3497 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
3498 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
3499 return false;
3500
3501 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
3502 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
3503 return false;
3504
3505 return true;
3506 }
3507 }
3508}//OSnLMNodeMatrixUpperTriangle::IsEqual
3509
3510
3511// OSnLMNodeMatrixDiagonal Methods
3513{
3516 m_mChildren = NULL;
3517 m_mMatrixChildren = new OSnLMNode*[1];
3519 inodeType = 1;
3520}//end OSnLMNodeMatrixDiagonal
3521
3523{
3524 std::ostringstream outStr;
3525#ifndef NDEBUG
3526 outStr << "inside OSnLMNodeMatrixDiagonal destructor" << endl;
3528#endif
3529}//end ~OSnLMNodeMatrixDiagonal
3530
3532{
3533 return "matrixDiagonal";
3534}// end OSnLMNodeMatrixDiagonal::getTokenName()
3535
3537{
3538 OSnLMNode *nlMNodePoint;
3539 nlMNodePoint = new OSnLMNodeMatrixDiagonal();
3540 return nlMNodePoint;
3541}//end OSnLMNodeMatrixDiagonal::cloneExprNode
3542
3543
3544// OSnLMNodeDiagonalMatrixFromVector Methods
3554
3556{
3557 std::ostringstream outStr;
3558#ifndef NDEBUG
3559 outStr << "inside OSnLMNodeDiagonalMatrixFromVector destructor" << endl;
3561#endif
3562}//end ~OSnLMNodeDiagonalMatrixFromVector
3563
3565{
3566 return "diagonalMatrixFromVector";
3567}// end OSnLMNodeDiagonalMatrixFromVector::getTokenName()
3568
3570{
3571 OSnLMNode *nlMNodePoint;
3572 nlMNodePoint = new OSnLMNodeDiagonalMatrixFromVector();
3573 return nlMNodePoint;
3574}//end OSnLMNodeDiagonalMatrixFromVector::cloneExprNode
3575
3576
3577// OSnLMNodeMatrixSubmatrixAt Methods
3579{
3582 m_mChildren = new OSnLNode*[4];
3583 m_mMatrixChildren = new OSnLMNode*[1];
3585 inodeType = 1;
3586}//end OSnLMNodeMatrixSubmatrixAt
3587
3589{
3590 std::ostringstream outStr;
3591#ifndef NDEBUG
3592 outStr << "inside OSnLMNodeMatrixSubmatrixAt destructor" << endl;
3594#endif
3595}//end ~OSnLMNodeMatrixSubmatrixAt
3596
3598{
3599 return "matrixSubmatrixAt";
3600}// end OSnLMNodeMatrixSubmatrixAt::getTokenName()
3601
3603{
3604 OSnLMNode *nlMNodePoint;
3605 nlMNodePoint = new OSnLMNodeMatrixSubmatrixAt();
3606 return nlMNodePoint;
3607}//end OSnLMNodeMatrixSubmatrixAt::cloneExprNode
3608
3609
3610// OSnLMNodeMatrixReference Methods
3612 idx(-1)
3613{
3616 m_mChildren = NULL;
3617 m_mMatrixChildren = NULL;
3619 inodeType = -1;
3620}//end OSnLMNodeMatrixReference
3621
3623{
3624 std::ostringstream outStr;
3625#ifndef NDEBUG
3626 outStr << "inside OSnLMNodeMatrixReference destructor" << endl;
3628#endif
3629}//end ~OSnLMNodeMatrixReference
3630
3632{
3633 ostringstream outStr;
3634 outStr << inodeInt;
3635 outStr << "[";
3636 outStr << inumberOfChildren;
3637 outStr << "]";
3638 outStr << ":";
3639 outStr << idx;
3640 outStr << ":";
3641 return outStr.str();
3642}//getTokenNumber
3643
3645{
3646 return "matrixReference";
3647}// end OSnLMNodeMatrixReference::getTokenName()
3648
3649
3651{
3652 ostringstream outStr;
3653 outStr << "<matrixReference idx=\"" << idx << "\"/>" << std::endl;
3654 return outStr.str();
3655}//OSnLMNodeMatrixReference::getNonlinearExpressionInXML
3656
3658{
3659 OSnLMNode *nlMNodePoint;
3660 nlMNodePoint = new OSnLMNodeMatrixReference();
3661 return nlMNodePoint;
3662}//end OSnLMNodeMatrixReference::cloneExprNode
3663
3665{
3666#ifndef NDEBUG
3667 ostringstream outStr;
3668 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
3669 outStr << " (" << this->getTokenName() << ")" << std::endl;
3671#endif
3672
3676 ndcopy->inodeInt = inodeInt;
3677 ndcopy->inodeType = inodeType;
3678 ndcopy->idx = idx;
3679
3680 if (inumberOfChildren > 0)
3681 {
3682 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
3683 for (unsigned int i=0; i < inumberOfChildren; i++)
3684 {
3686 }
3687 }
3688
3690 {
3691 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
3692 for (unsigned int i=0; i < inumberOfMatrixChildren; i++)
3693 {
3695 }
3696 }
3697
3698 return ndcopy;
3699}// end copyNodeAndDescendants
3700
3702{
3703#ifndef NDEBUG
3704 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLMNodeMatrixReference");
3705#endif
3706 if (this == NULL)
3707 {
3708 if (that == NULL)
3709 return true;
3710 else
3711 {
3712#ifndef NDEBUG
3714 "First object is NULL, second is not");
3715#endif
3716 return false;
3717 }
3718 }
3719 else
3720 {
3721 if (that == NULL)
3722 {
3723#ifndef NDEBUG
3725 "Second object is NULL, first is not");
3726#endif
3727 return false;
3728 }
3729 else
3730 {
3731 if (this->inodeInt != that->inodeInt)
3732 return false;
3733 if (this->inodeType != that->inodeType)
3734 return false;
3735 if (this->inumberOfChildren != that->inumberOfChildren)
3736 return false;
3738 return false;
3739
3740 if (this->idx != that->idx)
3741 return false;
3742
3743 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
3744 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
3745 return false;
3746
3747 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
3748 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
3749 return false;
3750
3751 return true;
3752 }
3753 }
3754}//OSnLMNodeMatrixReference::IsEqual
3755
3756
3757// OSnLMNodeMatrixVar Methods
3759 idx(-1)
3760{
3763 m_mChildren = NULL;
3764 m_mMatrixChildren = NULL;
3766 inodeType = -1;
3767}//end OSnLMNodeMatrixVar
3768
3770{
3771 std::ostringstream outStr;
3772#ifndef NDEBUG
3773 outStr << "inside OSnLMNodeMatrixVar destructor" << endl;
3775#endif
3776}//end ~OSnLMNodeMatrixVar
3777
3779{
3780 ostringstream outStr;
3781 outStr << inodeInt;
3782 outStr << "[";
3783 outStr << inumberOfChildren;
3784 outStr << "]";
3785 outStr << ":";
3786 outStr << idx;
3787 outStr << ":";
3788 return outStr.str();
3789}//getTokenNumber
3790
3792{
3793 return "matrixVar";
3794}// end OSnLMNodeMatrixVar::getTokenName()
3795
3796
3798{
3799 ostringstream outStr;
3800
3801 outStr << "<matrixVar idx=\"" << idx << "\"/>" << std::endl;
3802 return outStr.str();
3803}//OSnLMNodeMatrixVar::getNonlinearExpressionInXML
3804
3805#if 0
3806double OSnLMNodeMatrixVar::calculateFunction(double *x)
3807{
3808 m_dFunctionValue = coef*x[idx];
3809 return m_dFunctionValue;
3810}// end OSnLMNodeMatrixVar::calculate
3811
3812ADdouble OSnLMNodeMatrixVar::constructADTape(std::map<int, int> *varIdx, ADvector *XAD)
3813{
3814 m_ADTape = coef;
3815 m_ADTape = coef*(*XAD)[ (*varIdx)[ idx] ];
3816 return m_ADTape;
3817}// end OSnLMNodeMatrixVar::constructADTape
3818
3819
3820void OSnLMNodeMatrixVar::getVariableIndexMap(std::map<int, int> *varIdx)
3821{
3822 int numVars;
3823 if( (*varIdx).find( idx) != (*varIdx).end() )
3824 {
3825 //std::cout << "Index already in the map " << idx << std::endl;
3826 }
3827 else // variable to map with variable index as the key
3828 {
3829 //std::cout << "Found a new index to add to the map " << idx << std::endl;
3830 numVars = (*varIdx).size();
3831 //std::cout << "numVars = " << numVars << std::endl;
3832 (*varIdx)[ idx] = numVars;
3833 }
3834 //std::cout << "Value of index = " << (*varIdx)[ idx] << std::endl;
3835}//getVariableIndexMap
3836#endif
3837
3838
3840{
3841 OSnLMNode *nlMNodePoint;
3842 nlMNodePoint = new OSnLMNodeMatrixVar();
3843 return nlMNodePoint;
3844}//end OSnLMNodeMatrixVar::cloneExprNode
3845
3847{
3848#ifndef NDEBUG
3849 ostringstream outStr;
3850 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
3851 outStr << " (" << this->getTokenName() << ")" << std::endl;
3853#endif
3854
3858 ndcopy->inodeInt = inodeInt;
3859 ndcopy->inodeType = inodeType;
3860 ndcopy->idx = idx;
3861
3862 if (inumberOfChildren > 0)
3863 {
3864 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
3865 for (unsigned int i=0; i < inumberOfChildren; i++)
3866 {
3868 }
3869 }
3870
3872 {
3873 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
3874 for (unsigned int i=0; i < inumberOfMatrixChildren; i++)
3875 {
3877 }
3878 }
3879
3880 return ndcopy;
3881}// end copyNodeAndDescendants
3882
3884{
3885#ifndef NDEBUG
3886 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLMNodeMatrixVar");
3887#endif
3888 if (this == NULL)
3889 {
3890 if (that == NULL)
3891 return true;
3892 else
3893 {
3894#ifndef NDEBUG
3896 "First object is NULL, second is not");
3897#endif
3898 return false;
3899 }
3900 }
3901 else
3902 {
3903 if (that == NULL)
3904 {
3905#ifndef NDEBUG
3907 "Second object is NULL, first is not");
3908#endif
3909 return false;
3910 }
3911 else
3912 {
3913 if (this->inodeInt != that->inodeInt)
3914 return false;
3915 if (this->inodeType != that->inodeType)
3916 return false;
3917 if (this->inumberOfChildren != that->inumberOfChildren)
3918 return false;
3920 return false;
3921
3922 if (this->idx != that->idx)
3923 return false;
3924
3925 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
3926 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
3927 return false;
3928
3929 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
3930 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
3931 return false;
3932
3933 return true;
3934 }
3935 }
3936}//OSnLMNodeMatrixVar::IsEqual
3937
3938
3939// OSnLMNodeMatrixObj Methods
3941 idx(-1)
3942{
3945 m_mChildren = NULL;
3946 m_mMatrixChildren = NULL;
3948 inodeType = -1;
3949}//end OSnLMNodeMatrixObj
3950
3952{
3953 std::ostringstream outStr;
3954#ifndef NDEBUG
3955 outStr << "inside OSnLMNodeMatrixObj destructor" << endl;
3957#endif
3958}//end ~OSnLMNodeMatrixObj
3959
3961{
3962 ostringstream outStr;
3963 outStr << inodeInt;
3964 outStr << "[";
3965 outStr << inumberOfChildren;
3966 outStr << "]";
3967 outStr << ":";
3968 outStr << idx;
3969 outStr << ":";
3970 return outStr.str();
3971}//getTokenNumber
3972
3974{
3975 return "matrixObj";
3976}// end OSnLMNodeMatrixVar::getTokenName()
3977
3978
3980{
3981 ostringstream outStr;
3982 outStr << "<matrixObj idx=\"" << idx << "\"/>" << std::endl;
3983 return outStr.str();
3984}//OSnLMNodeMatrixObj::getNonlinearExpressionInXML
3985
3986#if 0
3987double OSnLMNodeMatrixObj::calculateFunction(double *x)
3988{
3989 m_dFunctionValue = coef*x[idx];
3990 return m_dFunctionValue;
3991}// end OSnLMNodeMatrixObj::calculate
3992
3993ADdouble OSnLMNodeMatrixObj::constructADTape(std::map<int, int> *varIdx, ADvector *XAD)
3994{
3995 m_ADTape = coef;
3996 m_ADTape = coef*(*XAD)[ (*varIdx)[ idx] ];
3997 return m_ADTape;
3998}// end OSnLMNodeMatrixObj::constructADTape
3999
4000void OSnLMNodeMatrixObj::getVariableIndexMap(std::map<int, int> *varIdx)
4001{
4002 int numVars;
4003 if( (*varIdx).find( idx) != (*varIdx).end() )
4004 {
4005 //std::cout << "Index already in the map " << idx << std::endl;
4006 }
4007 else // variable to map with variable index as the key
4008 {
4009 //std::cout << "Found a new index to add to the map " << idx << std::endl;
4010 numVars = (*varIdx).size();
4011 //std::cout << "numVars = " << numVars << std::endl;
4012 (*varIdx)[ idx] = numVars;
4013 }
4014 //std::cout << "Value of index = " << (*varIdx)[ idx] << std::endl;
4015}//getVariableIndexMap
4016#endif
4017
4019{
4020 OSnLMNode *nlMNodePoint;
4021 nlMNodePoint = new OSnLMNodeMatrixObj();
4022 return nlMNodePoint;
4023}//end OSnLMNodeMatrixObj::cloneExprNode
4024
4026{
4027#ifndef NDEBUG
4028 ostringstream outStr;
4029 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
4030 outStr << " (" << this->getTokenName() << ")" << std::endl;
4032#endif
4033
4037 ndcopy->inodeInt = inodeInt;
4038 ndcopy->inodeType = inodeType;
4039 ndcopy->idx = idx;
4040
4041 if (inumberOfChildren > 0)
4042 {
4043 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
4044 for (unsigned int i=0; i < inumberOfChildren; i++)
4045 {
4047 }
4048 }
4049
4051 {
4052 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
4053 for (unsigned int i=0; i < inumberOfMatrixChildren; i++)
4054 {
4056 }
4057 }
4058
4059 return ndcopy;
4060}// end copyNodeAndDescendants
4061
4063{
4064#ifndef NDEBUG
4065 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLMNodeMatrixObj");
4066#endif
4067 if (this == NULL)
4068 {
4069 if (that == NULL)
4070 return true;
4071 else
4072 {
4073#ifndef NDEBUG
4075 "First object is NULL, second is not");
4076#endif
4077 return false;
4078 }
4079 }
4080 else
4081 {
4082 if (that == NULL)
4083 {
4084#ifndef NDEBUG
4086 "Second object is NULL, first is not");
4087#endif
4088 return false;
4089 }
4090 else
4091 {
4092 if (this->inodeInt != that->inodeInt)
4093 return false;
4094 if (this->inodeType != that->inodeType)
4095 return false;
4096 if (this->inumberOfChildren != that->inumberOfChildren)
4097 return false;
4099 return false;
4100
4101 if (this->idx != that->idx)
4102 return false;
4103
4104 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
4105 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
4106 return false;
4107
4108 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
4109 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
4110 return false;
4111
4112 return true;
4113 }
4114 }
4115}//OSnLMNodeMatrixObj::IsEqual
4116
4117
4118// OSnLMNodeMatrixCon Methods
4120 idx(-1)
4121{
4124 m_mChildren = NULL;
4125 m_mMatrixChildren = NULL;
4127 inodeType = -1;
4128}//end OSnLMNodeMatrixCon
4129
4131{
4132 std::ostringstream outStr;
4133#ifndef NDEBUG
4134 outStr << "inside OSnLMNodeMatrixCon destructor" << endl;
4136#endif
4137}//end ~OSnLMNodeMatrixCon
4138
4140{
4141 ostringstream outStr;
4142 outStr << inodeInt;
4143 outStr << "[";
4144 outStr << inumberOfChildren;
4145 outStr << "]";
4146 outStr << ":";
4147 outStr << idx;
4148 outStr << ":";
4149 return outStr.str();
4150}//getTokenNumber
4151
4153{
4154 return "matrixCon";
4155}// end OSnLMNodeMatrixCon::getTokenName()
4156
4157
4159{
4160 ostringstream outStr;
4161 outStr << "<matrixCon idx=\"" << idx << "\"/>" << std::endl;
4162 return outStr.str();
4163}//OSnLMNodeMatrixCon::getNonlinearExpressionInXML
4164
4165#if 0
4166double OSnLMNodeMatrixCon::calculateFunction(double *x)
4167{
4168 m_dFunctionValue = coef*x[idx];
4169 return m_dFunctionValue;
4170}// end OSnLMNodeMatrixCon::calculate
4171
4172ADdouble OSnLMNodeMatrixCon::constructADTape(std::map<int, int> *varIdx, ADvector *XAD)
4173{
4174 m_ADTape = coef;
4175 m_ADTape = coef*(*XAD)[ (*varIdx)[ idx] ];
4176 return m_ADTape;
4177}// end OSnLMNodeMatrixCon::constructADTape
4178
4179
4180void OSnLMNodeMatrixCon::getVariableIndexMap(std::map<int, int> *varIdx)
4181{
4182 int numVars;
4183 if( (*varIdx).find( idx) != (*varIdx).end() )
4184 {
4185 //std::cout << "Index already in the map " << idx << std::endl;
4186 }
4187 else // variable to map with variable index as the key
4188 {
4189 //std::cout << "Found a new index to add to the map " << idx << std::endl;
4190 numVars = (*varIdx).size();
4191 //std::cout << "numVars = " << numVars << std::endl;
4192 (*varIdx)[ idx] = numVars;
4193 }
4194 //std::cout << "Value of index = " << (*varIdx)[ idx] << std::endl;
4195}//getVariableIndexMap
4196#endif
4197
4198
4200{
4201 OSnLMNode *nlMNodePoint;
4202 nlMNodePoint = new OSnLMNodeMatrixCon();
4203 return nlMNodePoint;
4204}//end OSnLMNodeMatrixCon::cloneExprNode
4205
4207{
4208#ifndef NDEBUG
4209 ostringstream outStr;
4210 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
4211 outStr << " (" << this->getTokenName() << ")" << std::endl;
4213#endif
4214
4218 ndcopy->inodeInt = inodeInt;
4219 ndcopy->inodeType = inodeType;
4220 ndcopy->idx = idx;
4221
4222 if (inumberOfChildren > 0)
4223 {
4224 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
4225 for (unsigned int i=0; i < inumberOfChildren; i++)
4226 {
4228 }
4229 }
4230
4232 {
4233 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
4234 for (unsigned int i=0; i < inumberOfMatrixChildren; i++)
4235 {
4237 }
4238 }
4239
4240 return ndcopy;
4241}// end copyNodeAndDescendants
4242
4243
4245{
4246#ifndef NDEBUG
4247 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLMNodeMatrixCon");
4248#endif
4249 if (this == NULL)
4250 {
4251 if (that == NULL)
4252 return true;
4253 else
4254 {
4255#ifndef NDEBUG
4257 "First object is NULL, second is not");
4258#endif
4259 return false;
4260 }
4261 }
4262 else
4263 {
4264 if (that == NULL)
4265 {
4266#ifndef NDEBUG
4268 "Second object is NULL, first is not");
4269#endif
4270 return false;
4271 }
4272 else
4273 {
4274 if (this->inodeInt != that->inodeInt)
4275 return false;
4276 if (this->inodeType != that->inodeType)
4277 return false;
4278 if (this->inumberOfChildren != that->inumberOfChildren)
4279 return false;
4281 return false;
4282
4283 if (this->idx != that->idx)
4284 return false;
4285
4286 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
4287 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
4288 return false;
4289
4290 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
4291 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
4292 return false;
4293
4294 return true;
4295 }
4296 }
4297}//OSnLMNodeMatrixCon::IsEqual
4298
const OSSmartPtr< OSOutput > osoutput
Definition OSOutput.cpp:39
std::string os_dtoa_format(double x)
double OSNaN()
returns the value for NaN used in OS
This file defines the OSnLNode class along with its derived classes.
std::vector< ADdouble > ADvector
Definition OSnLNode.h:40
double ADdouble
Definition OSnLNode.h:39
used for throwing exceptions.
std::string errormsg
errormsg is the error that is causing the exception to be thrown
A generic class from which we derive both OSnLNode and OSnLMNode.
Definition OSnLNode.h:57
virtual std::vector< ExprNode * > getPrefixFromExpressionTree()
Get a vector of pointers to OSnLNodes and OSnLMNodes that correspond to the (scalar-valued or matrix-...
Definition OSnLNode.cpp:259
OSnLNode ** m_mChildren
m_mChildren holds all the operands, that is, nodes that the current node operates on.
Definition OSnLNode.h:84
int inodeType
inodeType essentially tracks whether the number of children are known or not.
Definition OSnLNode.h:69
int inodeInt
inodeInt is the unique integer assigned to the OSnLNode or OSnLMNode in OSParameters....
Definition OSnLNode.h:62
virtual std::vector< ExprNode * > getPostfixFromExpressionTree()
Get a vector of pointers to ExprNodes that correspond to the expression tree in postfix format.
Definition OSnLNode.cpp:282
virtual bool IsEqual(ExprNode *that)
A function to check for the equality of two objects.
Definition OSnLNode.cpp:308
virtual ~ExprNode()
default destructor.
Definition OSnLNode.cpp:167
virtual std::string getTokenNumber()
Definition OSnLNode.cpp:208
ExprNode()
default constructor.
Definition OSnLNode.cpp:154
unsigned int inumberOfMatrixChildren
inumberOfMatrixChildren is the number of OSnLMNode child elements If this number is not fixed,...
Definition OSnLNode.h:79
virtual std::vector< ExprNode * > preOrderOSnLNodeTraversal(std::vector< ExprNode * > *prefixVector)
Called by getPrefixFromExpressionTree().
Definition OSnLNode.cpp:266
unsigned int inumberOfChildren
inumberOfChildren is the number of OSnLNode child elements If this number is not fixed,...
Definition OSnLNode.h:74
virtual std::string getNonlinearExpressionInXML()
The following method writes an OSnLNode or OSnLMNode in OSiL format.
Definition OSnLNode.cpp:221
OSnLMNode ** m_mMatrixChildren
m_mMatrixChildren holds all the matrix-valued operands, if any.
Definition OSnLNode.h:89
virtual std::vector< ExprNode * > postOrderOSnLNodeTraversal(std::vector< ExprNode * > *postfixVector)
Called by getPostfixFromExpressionTree().
Definition OSnLNode.cpp:289
virtual ExprNode * cloneExprNode()=0
Create or clone a node of this type.
virtual std::string getTokenName()=0
~OSnLMNodeDiagonalMatrixFromVector()
default destructor.
virtual std::string getTokenName()
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
OSnLMNodeDiagonalMatrixFromVector()
default constructor.
The OSnLMNode Class for nonlinear expressions involving matrices.
Definition OSnLNode.h:1761
std::vector< ExprNode * > postOrderOSnLNodeTraversal(std::vector< ExprNode * > *postfixVector)
Called by getPostfixFromExpressionTree().
std::vector< ExprNode * > getPrefixFromExpressionTree()
Get a vector of pointers to OSnLNodes and OSnLMNodes that correspond to the (matrix-valued) expressio...
OSnLMNode * createExpressionTreeFromPrefix(std::vector< ExprNode * > nlNodeVec)
Take a vector of ExprNodes (OSnLNodes and OSnLMNodes) in prefix format and create a matrix-valued OSE...
OSnLMNode * createExpressionTreeFromPostfix(std::vector< ExprNode * > nlNodeVec)
Take a vector of ExprNodes (OSnLNodes and OSnLMNodes) in postfix format and create a matrix-valued OS...
std::vector< ExprNode * > preOrderOSnLNodeTraversal(std::vector< ExprNode * > *prefixVector)
Called by getPrefixFromExpressionTree().
std::vector< ExprNode * > getPostfixFromExpressionTree()
Get a vector of pointers to ExprNodes that correspond to the expression tree in postfix format.
virtual OSnLMNode * copyNodeAndDescendants()
make a copy of this node and all its descendants
bool IsEqual(OSnLMNode *that)
A function to check for the equality of two objects.
virtual ~OSnLMNode()
default destructor.
OSnLMNode()
default constructor.
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
OSnLMNodeIdentityMatrix()
default constructor.
~OSnLMNodeIdentityMatrix()
default destructor.
virtual std::string getTokenName()
int idx
The index of the matrixCon.
Definition OSnLNode.h:2679
virtual OSnLMNode * copyNodeAndDescendants()
make a copy of this node and all its descendants
~OSnLMNodeMatrixCon()
default destructor.
virtual std::string getNonlinearExpressionInXML()
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
virtual std::string getTokenNumber()
OSnLMNodeMatrixCon()
default constructor.
virtual bool IsEqual(OSnLMNodeMatrixCon *that)
A function to check for the equality of two objects.
virtual std::string getTokenName()
OSnLMNodeMatrixDiagonal()
default constructor.
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
~OSnLMNodeMatrixDiagonal()
default destructor.
virtual std::string getTokenName()
~OSnLMNodeMatrixDotTimes()
default destructor.
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
OSnLMNodeMatrixDotTimes()
default constructor.
virtual std::string getTokenName()
~OSnLMNodeMatrixInverse()
default destructor.
virtual std::string getTokenName()
OSnLMNodeMatrixInverse()
default constructor.
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
bool includeDiagonal
A boolean to express whether the diagonal is to be part of the upper triangle or not.
Definition OSnLNode.h:2241
virtual std::string getNonlinearExpressionInXML()
virtual OSnLMNode * copyNodeAndDescendants()
make a copy of this node and all its descendants
virtual std::string getTokenName()
OSnLMNodeMatrixLowerTriangle()
default constructor.
~OSnLMNodeMatrixLowerTriangle()
default destructor.
virtual bool IsEqual(OSnLMNodeMatrixLowerTriangle *that)
A function to check for the equality of two objects.
~OSnLMNodeMatrixMinus()
default destructor.
virtual std::string getTokenName()
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
OSnLMNodeMatrixMinus()
default constructor.
OSnLMNodeMatrixNegate()
default constructor.
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
~OSnLMNodeMatrixNegate()
default destructor.
virtual std::string getTokenName()
OSnLMNodeMatrixObj()
default constructor.
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
virtual bool IsEqual(OSnLMNodeMatrixObj *that)
A function to check for the equality of two objects.
virtual std::string getNonlinearExpressionInXML()
~OSnLMNodeMatrixObj()
default destructor.
virtual OSnLMNode * copyNodeAndDescendants()
make a copy of this node and all its descendants
int idx
The index of the matrixObj.
Definition OSnLNode.h:2608
virtual std::string getTokenNumber()
virtual std::string getTokenName()
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
OSnLMNodeMatrixPlus()
default constructor.
virtual std::string getTokenName()
~OSnLMNodeMatrixPlus()
default destructor.
virtual OSnLMNode * cloneExprNode()
The implementation of the virtual functions.
~OSnLMNodeMatrixProduct()
default destructor.
OSnLMNodeMatrixProduct()
default constructor.
virtual std::string getTokenName()
int idx
The index of the matrix.
Definition OSnLNode.h:2466
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
virtual std::string getTokenName()
OSnLMNodeMatrixReference()
default constructor.
virtual std::string getTokenNumber()
virtual OSnLMNode * copyNodeAndDescendants()
make a copy of this node and all its descendants
virtual bool IsEqual(OSnLMNodeMatrixReference *that)
A function to check for the equality of two objects.
virtual std::string getNonlinearExpressionInXML()
~OSnLMNodeMatrixReference()
default destructor.
~OSnLMNodeMatrixScalarTimes()
default destructor.
virtual std::string getTokenName()
OSnLMNodeMatrixScalarTimes()
default constructor.
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
virtual std::string getTokenName()
~OSnLMNodeMatrixSubmatrixAt()
default destructor.
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
OSnLMNodeMatrixSubmatrixAt()
default constructor.
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
virtual std::string getTokenName()
~OSnLMNodeMatrixSum()
default destructor.
OSnLMNodeMatrixSum()
default constructor.
virtual std::string getTokenName()
~OSnLMNodeMatrixTimes()
default destructor.
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
OSnLMNodeMatrixTimes()
default constructor.
virtual std::string getTokenName()
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
OSnLMNodeMatrixTranspose()
default constructor.
~OSnLMNodeMatrixTranspose()
default destructor.
virtual std::string getTokenName()
bool includeDiagonal
A boolean to express whether the diagonal is to be part of the upper triangle or not.
Definition OSnLNode.h:2295
virtual std::string getNonlinearExpressionInXML()
virtual OSnLMNode * copyNodeAndDescendants()
make a copy of this node and all its descendants
OSnLMNodeMatrixUpperTriangle()
default constructor.
virtual bool IsEqual(OSnLMNodeMatrixUpperTriangle *that)
A function to check for the equality of two objects.
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
~OSnLMNodeMatrixUpperTriangle()
default destructor.
virtual std::string getTokenName()
virtual std::string getTokenNumber()
virtual OSnLMNode * cloneExprNode()
Create or clone a node of this type.
~OSnLMNodeMatrixVar()
default destructor.
int idx
The index of the matrixVar.
Definition OSnLNode.h:2537
virtual OSnLMNode * copyNodeAndDescendants()
make a copy of this node and all its descendants
virtual std::string getNonlinearExpressionInXML()
OSnLMNodeMatrixVar()
default constructor.
virtual bool IsEqual(OSnLMNodeMatrixVar *that)
A function to check for the equality of two objects.
~OSnLNodeAbs()
default destructor.
OSnLNodeAbs()
default constructor.
virtual std::string getTokenName()
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
virtual std::string getTokenName()
Definition OSnLNode.cpp:714
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
Definition OSnLNode.cpp:756
~OSnLNodeAllDiff()
default destructor.
Definition OSnLNode.cpp:707
OSnLNodeAllDiff()
default constructor.
Definition OSnLNode.cpp:699
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
Definition OSnLNode.cpp:720
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
Definition OSnLNode.cpp:741
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
virtual std::string getTokenName()
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
~OSnLNodeCos()
default destructor.
OSnLNodeCos()
default constructor.
~OSnLNodeDivide()
default destructor.
OSnLNodeDivide()
default constructor.
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
virtual std::string getTokenName()
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
~OSnLNodeE()
default destructor.
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
virtual std::string getTokenName()
OSnLNodeE()
default constructor.
virtual std::string getTokenNumber()
virtual std::string getNonlinearExpressionInXML()
OSnLNodeErf()
default constructor.
virtual std::string getTokenName()
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
Create the AD tape to be evaluated by AD.
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
~OSnLNodeErf()
default destructor.
OSnLNodeExp()
default constructor.
~OSnLNodeExp()
default destructor.
virtual std::string getTokenName()
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
The OSnLNode Class for nonlinear expressions.
Definition OSnLNode.h:180
virtual std::vector< ExprNode * > postOrderOSnLNodeTraversal(std::vector< ExprNode * > *postfixVector)
Called by getPostfixFromExpressionTree().
Definition OSnLNode.cpp:475
OSnLNode * createExpressionTreeFromPostfix(std::vector< ExprNode * > nlNodeVec)
Take a vector of ExprNodes (OSnLNodes and OSnLMNodes) in postfix format and create a scalar-valued OS...
Definition OSnLNode.cpp:413
OSnLNode()
default constructor.
Definition OSnLNode.cpp:365
bool IsEqual(OSnLNode *that)
A function to check for the equality of two objects.
Definition OSnLNode.cpp:541
virtual std::vector< ExprNode * > preOrderOSnLNodeTraversal(std::vector< ExprNode * > *prefixVector)
Called by getPrefixFromExpressionTree().
Definition OSnLNode.cpp:452
virtual OSnLNode * copyNodeAndDescendants()
make a copy of this node and all its descendants
Definition OSnLNode.cpp:505
virtual ~OSnLNode()
default destructor.
Definition OSnLNode.cpp:374
virtual std::vector< ExprNode * > getPostfixFromExpressionTree()
Get a vector of pointers to ExprNodes that correspond to the expression tree in postfix format.
Definition OSnLNode.cpp:468
virtual void getVariableIndexMap(std::map< int, int > *varIdx)
varIdx is a map where the key is the index of an OSnLNodeVariable and (*varIdx)[ idx] is the kth vari...
Definition OSnLNode.cpp:493
ADdouble m_ADTape
m_ADTape stores the expression tree for the this OSnLNode as an ADdouble.
Definition OSnLNode.h:190
virtual std::vector< ExprNode * > getPrefixFromExpressionTree()
Get a vector of pointers to OSnLNodes and OSnLMNodes that correspond to the (scalar-valued or matrix-...
Definition OSnLNode.cpp:446
OSnLNode * createExpressionTreeFromPrefix(std::vector< ExprNode * > nlNodeVec)
Take a vector of ExprNodes (OSnLNodes and OSnLMNodes) in prefix format and create a scalar-valued OSE...
Definition OSnLNode.cpp:381
virtual double calculateFunction(double *x)=0
Calculate the function value given the current variable values.
double m_dFunctionValue
m_dFunctionValue holds the function value given the current variable values.
Definition OSnLNode.h:185
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)=0
Create the AD tape to be evaluated by AD.
~OSnLNodeIf()
default destructor.
OSnLNodeIf()
default constructor.
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
virtual std::string getTokenName()
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
~OSnLNodeLn()
default destructor.
virtual std::string getTokenName()
OSnLNodeLn()
default constructor.
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
~OSnLNodeMatrixDeterminant()
default destructor.
virtual OSnLNode * cloneExprNode()
Create or clone a node of this type.
virtual double calculateFunction(double *x)
The implementation of the virtual functions.
OSnLNodeMatrixDeterminant()
default constructor.
virtual std::string getTokenName()
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
~OSnLNodeMatrixToScalar()
default destructor.
OSnLNodeMatrixToScalar()
default constructor.
virtual std::string getTokenName()
virtual OSnLNode * cloneExprNode()
Create or clone a node of this type.
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
Create the AD tape to be evaluated by AD.
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
virtual std::string getTokenName()
virtual double calculateFunction(double *x)
The implementation of the virtual functions.
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
~OSnLNodeMatrixTrace()
default destructor.
OSnLNodeMatrixTrace()
default constructor.
virtual OSnLNode * cloneExprNode()
Create or clone a node of this type.
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
Definition OSnLNode.cpp:782
virtual std::string getTokenName()
Definition OSnLNode.cpp:796
~OSnLNodeMax()
default destructor.
Definition OSnLNode.cpp:775
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
Definition OSnLNode.cpp:802
OSnLNodeMax()
default constructor.
Definition OSnLNode.cpp:767
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
Definition OSnLNode.cpp:817
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
Definition OSnLNode.cpp:848
~OSnLNodeMin()
default destructor.
Definition OSnLNode.cpp:835
virtual std::string getTokenName()
Definition OSnLNode.cpp:843
OSnLNodeMin()
default constructor.
Definition OSnLNode.cpp:827
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
Definition OSnLNode.cpp:878
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
Definition OSnLNode.cpp:863
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
Definition OSnLNode.cpp:926
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
Definition OSnLNode.cpp:912
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
Definition OSnLNode.cpp:919
~OSnLNodeMinus()
default destructor.
Definition OSnLNode.cpp:900
OSnLNodeMinus()
default constructor.
Definition OSnLNode.cpp:888
virtual std::string getTokenName()
Definition OSnLNode.cpp:907
virtual std::string getTokenName()
Definition OSnLNode.cpp:955
OSnLNodeNegate()
default constructor.
Definition OSnLNode.cpp:937
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
Definition OSnLNode.cpp:972
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
Definition OSnLNode.cpp:966
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
Definition OSnLNode.cpp:960
~OSnLNodeNegate()
default destructor.
Definition OSnLNode.cpp:948
The OSnLNodeNumber Class.
Definition OSnLNode.h:1263
double value
value is the value of the number
Definition OSnLNode.h:1266
virtual std::string getTokenNumber()
virtual std::string getTokenName()
virtual std::string getNonlinearExpressionInXML()
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
~OSnLNodeNumber()
default destructor.
OSnLNodeNumber()
default constructor.
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
std::string id
later, e.g.
Definition OSnLNode.h:1274
virtual OSnLNode * copyNodeAndDescendants()
make a copy of this node and all its descendants
std::string type
in the C++ type is real
Definition OSnLNode.h:1269
virtual bool IsEqual(OSnLNodeNumber *that)
A function to check for the equality of two objects.
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
virtual std::string getTokenName()
~OSnLNodePI()
default destructor.
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
virtual std::string getTokenNumber()
virtual std::string getNonlinearExpressionInXML()
OSnLNodePI()
default constructor.
virtual double calculateFunction(double *x)
The implementation of the virtual functions.
Definition OSnLNode.cpp:621
virtual std::string getTokenName()
Definition OSnLNode.cpp:616
OSnLNodePlus()
default constructor.
Definition OSnLNode.cpp:595
~OSnLNodePlus()
default destructor.
Definition OSnLNode.cpp:607
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
Definition OSnLNode.cpp:634
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
Definition OSnLNode.cpp:628
~OSnLNodePower()
default destructor.
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
virtual std::string getTokenName()
OSnLNodePower()
default constructor.
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
virtual std::string getTokenName()
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
OSnLNodeProduct()
default constructor.
~OSnLNodeProduct()
default destructor.
OSnLNodeSin()
default constructor.
~OSnLNodeSin()
default destructor.
virtual std::string getTokenName()
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
OSnLNodeSqrt()
default constructor.
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
~OSnLNodeSqrt()
default destructor.
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
virtual std::string getTokenName()
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
OSnLNodeSquare()
default constructor.
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
~OSnLNodeSquare()
default destructor.
virtual std::string getTokenName()
OSnLNodeSum()
default constructor.
Definition OSnLNode.cpp:644
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
Definition OSnLNode.cpp:664
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
Definition OSnLNode.cpp:676
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
Definition OSnLNode.cpp:687
virtual std::string getTokenName()
Definition OSnLNode.cpp:659
~OSnLNodeSum()
default destructor.
Definition OSnLNode.cpp:652
OSnLNodeTimes()
default constructor.
Definition OSnLNode.cpp:981
virtual std::string getTokenName()
~OSnLNodeTimes()
default destructor.
Definition OSnLNode.cpp:993
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
Create the AD tape to be evaluated by AD.
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
The OSnLNodeVariable Class.
Definition OSnLNode.h:1479
~OSnLNodeVariable()
default destructor.
virtual std::string getTokenName()
virtual OSnLNode * cloneExprNode()
The implementation of the virtual functions.
virtual OSnLNode * copyNodeAndDescendants()
make a copy of this node and all its descendants
virtual ADdouble constructADTape(std::map< int, int > *ADIdx, ADvector *XAD)
The implementation of the virtual functions.
virtual bool IsEqual(OSnLNodeVariable *that)
A function to check for the equality of two objects.
OSnLNodeVariable()
default constructor.
virtual std::string getNonlinearExpressionInXML()
int idx
idx is the index of the variable
Definition OSnLNode.h:1488
virtual double calculateFunction(double *x)
Calculate the function value given the current variable values.
double coef
coef is an option coefficient on the variable, the default value is 1.0
Definition OSnLNode.h:1485
virtual std::string getTokenNumber()
virtual void getVariableIndexMap(std::map< int, int > *varIdx)
varIdx is a map where the key is the index of an OSnLNodeVariable and (*varIdx)[ idx] is the kth vari...
#define OS_PRODUCT
#define OS_SUM
#define OS_MAX
#define OS_MATRIX_SUM
#define OS_MATRIX_UPPERTRIANGLE
#define OS_MATRIX_DOTTIMES
#define OS_MIN
#define OS_PI
#define OS_IF
#define OS_MATRIX_NEGATE
#define OS_MATRIX_PLUS
#define OS_VARIABLE
#define OS_MATRIX_TIMES
#define OS_NEGATE
#define OS_MATRIX_OBJ
#define OS_DIVIDE
#define OS_MATRIX_INVERSE
#define OS_MATRIX_LOWERTRIANGLE
#define OS_E
#define OS_ERF
#define OS_PLUS
#define OS_LN
#define OS_IDENTITY_MATRIX
#define OS_SQRT
#define OS_MATRIX_DETERMINANT
#define OS_MATRIX_TO_SCALAR
#define OS_MATRIX_MINUS
#define OS_E_VALUE
#define OS_COS
#define OS_MATRIX_REFERENCE
@ ENUM_OUTPUT_LEVEL_detailed_trace
@ ENUM_OUTPUT_LEVEL_trace
@ ENUM_OUTPUT_LEVEL_warning
#define OS_SQUARE
#define OS_POWER
#define OS_ALLDIFF
#define OS_MATRIX_VAR
#define OS_ABS
#define OS_SIN
#define OS_DIAGONAL_MATRIX_FROM_VECTOR
#define OS_MATRIX_SCALARTIMES
#define OS_NUMBER
#define OS_TIMES
#define OS_MATRIX_PRODUCT
#define OS_MATRIX_TRANSPOSE
#define OS_MATRIX_CON
#define OS_MATRIX_TRACE
@ ENUM_OUTPUT_AREA_OSInstance
#define OS_PI_VALUE
#define OS_EXP
#define OS_MATRIX_SUBMATRIX_AT
#define OS_MATRIX_DIAGONAL
#define OS_MINUS
#define OSDBL_MAX