00001
00016 #include "OSnLNode.h"
00017 #include "OSErrorClass.h"
00018 #include "OSParameters.h"
00019 #include "OSMathUtil.h"
00020 #include "OSOutput.h"
00021
00022 #include <string>
00023 #include <cstdlib>
00024
00025 #ifdef HAVE_CMATH
00026 # include <cmath>
00027 #else
00028 # ifdef HAVE_MATH_H
00029 # include <math.h>
00030 # else
00031 # error "don't have header file for math"
00032 # endif
00033 #endif
00034
00035
00036 #include <iostream>
00037 #include <sstream>
00038
00039
00040 using std::ostringstream;
00041 using std::cout;
00042 using std::endl;
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 OSnLNode::OSnLNode():
00157 m_mChildren(NULL),
00158 m_dFunctionValue( OSNaN())
00159
00160 {
00161 }
00162
00163 OSnLNode::~OSnLNode()
00164 {
00165 #ifndef NDEBUG
00166 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNode destructor");
00167 #endif
00168 }
00169
00170 OSnLNode* OSnLNode::copyNodeAndDescendants()
00171 {
00172 OSnLNode* ndcopy = cloneOSnLNode();
00173 ndcopy->inumberOfChildren = inumberOfChildren;
00174 ndcopy->inodeInt = inodeInt;
00175 ndcopy->inodeType = inodeType;
00176
00177 if (inumberOfChildren > 0)
00178 {
00179
00180 for (int i=0; i < inumberOfChildren; i++)
00181 {
00182 ndcopy->m_mChildren[i] = m_mChildren[i]->copyNodeAndDescendants();
00183 }
00184 }
00185
00186 return ndcopy;
00187 }
00188
00189 OSnLNode* OSnLNode::createExpressionTreeFromPostfix(std::vector<OSnLNode*> nlNodeVec)
00190 {
00191 std::vector<OSnLNode*> stackVec ;
00192 unsigned int kount = 0;
00193 while(kount <= nlNodeVec.size() - 1)
00194 {
00195 int numkids = nlNodeVec[kount]->inumberOfChildren;
00196 if(numkids > 0)
00197 {
00198 for(int i = numkids - 1; i >= 0; i--)
00199 {
00200 nlNodeVec[kount]->m_mChildren[i] = stackVec.back() ;
00201 stackVec.pop_back();
00202 }
00203 }
00204 stackVec.push_back( nlNodeVec[kount]);
00205 kount++;
00206 }
00207 stackVec.clear();
00208 return nlNodeVec[ kount - 1];
00209 }
00210
00211 std::vector<OSnLNode*> OSnLNode::getPostfixFromExpressionTree( )
00212 {
00213 std::vector<OSnLNode*> postfixVector;
00214 return postOrderOSnLNodeTraversal( &postfixVector);
00215 }
00216
00217 std::vector<OSnLNode*> OSnLNode::postOrderOSnLNodeTraversal( std::vector<OSnLNode*> *postfixVector)
00218 {
00219 if(inumberOfChildren > 0)
00220 {
00221 unsigned int i;
00222 for(i = 0; i < inumberOfChildren; i++)
00223 m_mChildren[i]->postOrderOSnLNodeTraversal( postfixVector);
00224 }
00225 (*postfixVector).push_back( this);
00226 return *postfixVector;
00227 }
00228
00229 OSnLNode* OSnLNode::createExpressionTreeFromPrefix(std::vector<OSnLNode*> nlNodeVec)
00230 {
00231 std::vector<OSnLNode*> stackVec;
00232 int kount = nlNodeVec.size() - 1;
00233 while(kount >= 0)
00234 {
00235 int numkids = nlNodeVec[kount]->inumberOfChildren;
00236 if(numkids > 0)
00237 {
00238 for(int i = 0; i < numkids; i++)
00239 {
00240 nlNodeVec[kount]->m_mChildren[i] = stackVec.back() ;
00241 stackVec.pop_back();
00242 }
00243 }
00244 stackVec.push_back( nlNodeVec[kount]);
00245 kount--;
00246 }
00247 stackVec.clear();
00248 return nlNodeVec[ 0];
00249 }
00250
00251 std::vector<OSnLNode*> OSnLNode::getPrefixFromExpressionTree()
00252 {
00253 std::vector<OSnLNode*> prefixVector;
00254 return preOrderOSnLNodeTraversal( &prefixVector);
00255 }
00256
00257 std::vector<OSnLNode*> OSnLNode::preOrderOSnLNodeTraversal( std::vector<OSnLNode*> *prefixVector)
00258 {
00259 (*prefixVector).push_back( this);
00260 if(inumberOfChildren > 0)
00261 {
00262 for(unsigned int i = 0; i < inumberOfChildren; i++)
00263 m_mChildren[i]->preOrderOSnLNodeTraversal( prefixVector);
00264 }
00265 return *prefixVector;
00266 }
00267
00268
00269 std::string OSnLNode::getTokenNumber()
00270 {
00271 ostringstream outStr;
00272 outStr << inodeInt;
00273
00274
00275 outStr << "[";
00276 outStr << inumberOfChildren ;
00277 outStr << "]";
00278
00279 return outStr.str();
00280 }
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398 std::string OSnLNode::getNonlinearExpressionInXML()
00399 {
00400 ostringstream outStr, logStr;
00401 outStr << "<" ;
00402 outStr << this->getTokenName();
00403 #ifndef NDEBUG
00404 logStr << "nonlinear node " << this->getTokenName() << endl;
00405 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, logStr.str());
00406 #endif
00407 if(inumberOfChildren > 0)
00408 {
00409 outStr << ">";
00410 }
00411 else
00412 {
00413 outStr << "/>";
00414 }
00415 if(inumberOfChildren > 0)
00416 {
00417 for(unsigned int i = 0; i < inumberOfChildren; i++)
00418 {
00419 outStr << m_mChildren[i]->getNonlinearExpressionInXML();
00420 }
00421 }
00422 if(inumberOfChildren > 0)
00423 {
00424 outStr << "</" ;
00425 outStr << this->getTokenName() ;
00426 outStr << ">" ;
00427 }
00428 return outStr.str();
00429 }
00430
00431
00432
00433
00434 void OSnLNode::getVariableIndexMap(std::map<int, int> *varIdx)
00435 {
00436 unsigned int i;
00437 if(inodeInt != OS_VARIABLE)
00438 {
00439 for(i = 0; i < inumberOfChildren; i++)
00440 {
00441 m_mChildren[ i]->getVariableIndexMap( varIdx);
00442 }
00443 }
00444 }
00445
00446 bool OSnLNode::IsEqual(OSnLNode *that)
00447 {
00448 #ifndef NDEBUG
00449 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLNode");
00450 #endif
00451 if (this == NULL)
00452 {
00453 if (that == NULL)
00454 return true;
00455 else
00456 {
00457 #ifndef NDEBUG
00458 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace,
00459 "First object is NULL, second is not");
00460 #endif
00461 return false;
00462 }
00463 }
00464 else
00465 {
00466 if (that == NULL)
00467 {
00468 #ifndef NDEBUG
00469 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace,
00470 "Second object is NULL, first is not");
00471 #endif
00472 return false;
00473 }
00474 else
00475 {
00476 if (this->inumberOfChildren != that->inumberOfChildren)
00477 return false;
00478 if (this->inodeInt != that->inodeInt)
00479 return false;
00480 if (this->inodeType != that->inodeType)
00481 return false;
00482
00483 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
00484 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
00485 return false;
00486
00487 return true;
00488 }
00489 }
00490 }
00491
00492
00493
00494 OSnLNodePlus::OSnLNodePlus()
00495 {
00496
00497 inumberOfChildren = 2;
00498 m_mChildren = new OSnLNode*[2];
00499 m_mChildren[ 0] = NULL;
00500 m_mChildren[ 1] = NULL;
00501 inodeInt = 1001;
00502 inodeType = 2;
00503 }
00504
00505
00506 OSnLNodePlus::~OSnLNodePlus()
00507 {
00508 #ifndef NDEBUG
00509 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodePlus destructor");
00510 #endif
00511 for(unsigned int i = 0; i < inumberOfChildren; i++)
00512 {
00513 if( m_mChildren[ i] != NULL) delete m_mChildren[ i];
00514 m_mChildren[i] = NULL;
00515 }
00516
00517 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
00518 }
00519
00520 std::string OSnLNodePlus::getTokenName()
00521 {
00522 return "plus";
00523 }
00524
00525
00526 double OSnLNodePlus::calculateFunction(double *x)
00527 {
00528 m_dFunctionValue = m_mChildren[0]->calculateFunction(x) + m_mChildren[1]->calculateFunction(x);
00529 return m_dFunctionValue;
00530 }
00531
00532
00533 ADdouble OSnLNodePlus::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
00534 {
00535 m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) + m_mChildren[1]->constructADTape( ADIdx, XAD);
00536 return m_ADTape;
00537 }
00538
00539
00540 OSnLNode* OSnLNodePlus::cloneOSnLNode()
00541 {
00542 OSnLNode *nlNodePoint;
00543 nlNodePoint = new OSnLNodePlus();
00544 return nlNodePoint;
00545 }
00546
00547
00548
00549 OSnLNodeSum::OSnLNodeSum()
00550 {
00551 inumberOfChildren = 0;
00552 inodeInt = 1002;
00553 inodeType = -1;
00554 }
00555
00556 OSnLNodeSum::~OSnLNodeSum()
00557 {
00558 #ifndef NDEBUG
00559 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeSum destructor");
00560 #endif
00561 if(inumberOfChildren > 0)
00562 {
00563 for(unsigned int i = 0; i < inumberOfChildren; i++)
00564 {
00565 delete m_mChildren[ i];
00566 m_mChildren[i] = NULL;
00567 }
00568 }
00569
00570 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
00571 }
00572
00573 std::string OSnLNodeSum::getTokenName()
00574 {
00575 return "sum";
00576 }
00577
00578 double OSnLNodeSum::calculateFunction(double *x)
00579 {
00580 m_dFunctionValue = 0.0;
00581 unsigned int i;
00582 for(i = 0; i < inumberOfChildren; i++)
00583 {
00584 m_dFunctionValue = m_dFunctionValue + m_mChildren[i]->calculateFunction(x);
00585 }
00586 return m_dFunctionValue;
00587 }
00588
00589
00590 ADdouble OSnLNodeSum::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
00591 {
00592 m_ADTape = 0.0;
00593 unsigned int i;
00594 for(i = 0; i < inumberOfChildren; i++)
00595 {
00596 m_ADTape = m_ADTape + m_mChildren[i]->constructADTape( ADIdx, XAD);
00597 }
00598 return m_ADTape;
00599 }
00600
00601 OSnLNode* OSnLNodeSum::cloneOSnLNode()
00602 {
00603 OSnLNode *nlNodePoint;
00604 nlNodePoint = new OSnLNodeSum();
00605 return nlNodePoint;
00606 }
00607
00608
00609
00610
00611
00612
00613 OSnLNodeAllDiff::OSnLNodeAllDiff()
00614 {
00615 inumberOfChildren = 0;
00616 inodeInt = 7016;
00617 inodeType = -1;
00618 }
00619
00620
00621 OSnLNodeAllDiff::~OSnLNodeAllDiff()
00622 {
00623 #ifndef NDEBUG
00624 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeAllDiff destructor");
00625 #endif
00626 if(inumberOfChildren > 0)
00627 {
00628 for(unsigned int i = 0; i < inumberOfChildren; i++)
00629 {
00630 delete m_mChildren[ i];
00631 m_mChildren[i] = NULL;
00632 }
00633 }
00634
00635 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
00636 }
00637
00638 std::string OSnLNodeAllDiff::getTokenName()
00639 {
00640 return "allDiff";
00641 }
00642
00643
00644 double OSnLNodeAllDiff::calculateFunction(double *x)
00645 {
00646 m_dFunctionValue = 1;
00647
00648 unsigned int i, k;
00649 if(inumberOfChildren > 1)
00650 {
00651 for(i = 0; i < inumberOfChildren - 1; i++)
00652 {
00653 for(k = i + 1; k < inumberOfChildren; k++)
00654 {
00655 if(m_mChildren[i]->calculateFunction(x) ==
00656 m_mChildren[k]->calculateFunction(x)) return 0 ;
00657 }
00658 }
00659 }
00660 return m_dFunctionValue;
00661 }
00662
00663
00664 ADdouble OSnLNodeAllDiff::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
00665 {
00666 try
00667 {
00668 throw ErrorClass("AllDifferent operator not supported by current Algorithmic Differentiation implementation");
00669 return m_ADTape;
00670 }
00671 catch(const ErrorClass& eclass)
00672 {
00673 throw ErrorClass( eclass.errormsg);
00674 }
00675 return m_ADTape;
00676 }
00677
00678
00679 OSnLNode* OSnLNodeAllDiff::cloneOSnLNode()
00680 {
00681 OSnLNode *nlNodePoint;
00682 nlNodePoint = new OSnLNodeAllDiff();
00683 return nlNodePoint;
00684 }
00685
00686
00687
00688
00689
00690
00691 OSnLNodeMax::OSnLNodeMax()
00692 {
00693 inumberOfChildren = 0;
00694 inodeInt = 4011;
00695 inodeType = -1;
00696 }
00697
00698 OSnLNodeMax::~OSnLNodeMax()
00699 {
00700 #ifndef NDEBUG
00701 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeMax destructor");
00702 #endif
00703 if(inumberOfChildren > 0)
00704 {
00705 for(unsigned int i = 0; i < inumberOfChildren; i++)
00706 {
00707 delete m_mChildren[ i];
00708 m_mChildren[i] = NULL;
00709 }
00710 }
00711
00712 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
00713 }
00714
00715 double OSnLNodeMax::calculateFunction(double *x)
00716 {
00717 m_dFunctionValue = -OSDBL_MAX;
00718
00719 for(unsigned int i = 0; i < inumberOfChildren; i++)
00720 {
00721 if(m_mChildren[i]->calculateFunction(x) > m_dFunctionValue)
00722 {
00723 m_dFunctionValue = m_mChildren[i]->calculateFunction(x);
00724 }
00725 }
00726 return m_dFunctionValue;
00727 }
00728
00729 std::string OSnLNodeMax::getTokenName()
00730 {
00731 return "max";
00732 }
00733
00734
00735 ADdouble OSnLNodeMax::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
00736 {
00737
00738 try
00739 {
00740 throw ErrorClass("Max operator not supported by current Algorithmic Differentiation implementation");
00741 return m_ADTape;
00742 }
00743 catch(const ErrorClass& eclass)
00744 {
00745 throw ErrorClass( eclass.errormsg);
00746 }
00747 }
00748
00749
00750 OSnLNode* OSnLNodeMax::cloneOSnLNode()
00751 {
00752 OSnLNode *nlNodePoint;
00753 nlNodePoint = new OSnLNodeMax();
00754 return nlNodePoint;
00755 }
00756
00757
00758
00759
00760
00761
00762 OSnLNodeMin::OSnLNodeMin()
00763 {
00764 inumberOfChildren = 0;
00765 inodeInt = 4010;
00766 inodeType = -1;
00767 }
00768
00769 OSnLNodeMin::~OSnLNodeMin()
00770 {
00771 #ifndef NDEBUG
00772 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeMin destructor");
00773 #endif
00774 if(inumberOfChildren > 0)
00775 {
00776 for(unsigned int i = 0; i < inumberOfChildren; i++)
00777 {
00778 delete m_mChildren[ i];
00779 m_mChildren[i] = NULL;
00780 }
00781 }
00782 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
00783
00784 }
00785
00786
00787 std::string OSnLNodeMin::getTokenName()
00788 {
00789 return "min";
00790 }
00791
00792 double OSnLNodeMin::calculateFunction(double *x)
00793 {
00794 m_dFunctionValue = OSDBL_MAX;
00795
00796 for(unsigned int i = 0; i < inumberOfChildren; i++)
00797 {
00798 if(m_mChildren[i]->calculateFunction(x) < m_dFunctionValue)
00799 {
00800 m_dFunctionValue = m_mChildren[i]->calculateFunction(x);
00801 }
00802 }
00803 return m_dFunctionValue;
00804 }
00805
00806
00807 ADdouble OSnLNodeMin::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
00808 {
00809
00810 try
00811 {
00812 throw ErrorClass("Min operator not supported by current Algorithmic Differentiation implementation");
00813 return m_ADTape;
00814 }
00815 catch(const ErrorClass& eclass)
00816 {
00817 throw ErrorClass( eclass.errormsg);
00818 }
00819 }
00820
00821
00822 OSnLNode* OSnLNodeMin::cloneOSnLNode()
00823 {
00824 OSnLNode *nlNodePoint;
00825 nlNodePoint = new OSnLNodeMin();
00826 return nlNodePoint;
00827 }
00828
00829
00830
00831
00832
00833
00834 OSnLNodeMinus::OSnLNodeMinus()
00835 {
00836 inumberOfChildren = 2;
00837 m_mChildren = new OSnLNode*[2];
00838 m_mChildren[ 0] = NULL;
00839 m_mChildren[ 1] = NULL;
00840 inodeInt = 1003;
00841 inodeType = 2;
00842 }
00843
00844
00845 OSnLNodeMinus::~OSnLNodeMinus()
00846 {
00847 #ifndef NDEBUG
00848 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeMinus destructor");
00849 #endif
00850 for(unsigned int i = 0; i < inumberOfChildren; i++)
00851 {
00852 delete m_mChildren[ i];
00853 m_mChildren[i] = NULL;
00854 }
00855
00856 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
00857 }
00858
00859 std::string OSnLNodeMinus::getTokenName()
00860 {
00861 return "minus";
00862 }
00863
00864 double OSnLNodeMinus::calculateFunction(double *x)
00865 {
00866 m_dFunctionValue = m_mChildren[0]->calculateFunction( x) - m_mChildren[1]->calculateFunction( x);
00867 return m_dFunctionValue;
00868 }
00869
00870
00871 ADdouble OSnLNodeMinus::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
00872 {
00873 m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) - m_mChildren[1]->constructADTape( ADIdx, XAD);
00874 return m_ADTape;
00875 }
00876
00877
00878 OSnLNode* OSnLNodeMinus::cloneOSnLNode()
00879 {
00880 OSnLNode *nlNodePoint;
00881 nlNodePoint = new OSnLNodeMinus();
00882 return nlNodePoint;
00883 }
00884
00885
00886
00887
00888
00889
00890
00891 OSnLNodeNegate::OSnLNodeNegate()
00892 {
00893 inumberOfChildren = 1;
00894 m_mChildren = new OSnLNode*[1];
00895 m_mChildren[ 0] = NULL;
00896 inodeInt = 1004;
00897 inodeType = 1;
00898 }
00899
00900
00901 OSnLNodeNegate::~OSnLNodeNegate()
00902 {
00903 #ifndef NDEBUG
00904 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeNegate destructor");
00905 #endif
00906 for(unsigned int i = 0; i < inumberOfChildren; i++)
00907 {
00908 delete m_mChildren[ i];
00909 m_mChildren[i] = NULL;
00910 }
00911
00912 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
00913 }
00914
00915 std::string OSnLNodeNegate::getTokenName()
00916 {
00917 return "negate";
00918 }
00919
00920 double OSnLNodeNegate::calculateFunction(double *x)
00921 {
00922 m_dFunctionValue = -m_mChildren[0]->calculateFunction( x) ;
00923 return m_dFunctionValue;
00924 }
00925
00926 ADdouble OSnLNodeNegate::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
00927 {
00928 m_ADTape = -m_mChildren[0]->constructADTape( ADIdx, XAD);
00929 return m_ADTape;
00930 }
00931
00932
00933 OSnLNode* OSnLNodeNegate::cloneOSnLNode()
00934 {
00935 OSnLNode *nlNodePoint;
00936 nlNodePoint = new OSnLNodeNegate();
00937 return nlNodePoint;
00938 }
00939
00940
00941
00942
00943 OSnLNodeTimes::OSnLNodeTimes()
00944 {
00945 inumberOfChildren = 2;
00946 m_mChildren = new OSnLNode*[2];
00947 m_mChildren[ 0] = NULL;
00948 m_mChildren[ 1] = NULL;
00949 inodeInt = 1005;
00950 inodeType = 2;
00951 }
00952
00953
00954 OSnLNodeTimes::~OSnLNodeTimes()
00955 {
00956 #ifndef NDEBUG
00957 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeTimes destructor");
00958 #endif
00959 for(unsigned int i = 0; i < inumberOfChildren; i++)
00960 {
00961 delete m_mChildren[ i];
00962 m_mChildren[i] = NULL;
00963 }
00964
00965 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
00966 }
00967
00968 std::string OSnLNodeTimes::getTokenName()
00969 {
00970 return "times";
00971 }
00972
00973 double OSnLNodeTimes::calculateFunction(double *x)
00974 {
00975 m_dFunctionValue = m_mChildren[0]->calculateFunction( x)*m_mChildren[1]->calculateFunction( x);
00976 return m_dFunctionValue;
00977 }
00978
00979
00980 ADdouble OSnLNodeTimes::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
00981 {
00982 m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) * m_mChildren[1]->constructADTape( ADIdx, XAD);
00983 return m_ADTape;
00984 }
00985
00986 OSnLNode* OSnLNodeTimes::cloneOSnLNode()
00987 {
00988 OSnLNode *nlNodePoint;
00989 nlNodePoint = new OSnLNodeTimes();
00990 return nlNodePoint;
00991 }
00992
00993
00994
00995
00996 OSnLNodeDivide::OSnLNodeDivide()
00997 {
00998 inumberOfChildren = 2;
00999 m_mChildren = new OSnLNode*[2];
01000 m_mChildren[ 0] = NULL;
01001 m_mChildren[ 1] = NULL;
01002 inodeInt = 1006;
01003 inodeType = 2;
01004 }
01005
01006
01007 OSnLNodeDivide::~OSnLNodeDivide()
01008 {
01009 #ifndef NDEBUG
01010 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeDivide destructor");
01011 #endif
01012 for(unsigned int i = 0; i < inumberOfChildren; i++)
01013 {
01014 delete m_mChildren[ i];
01015 m_mChildren[i] = NULL;
01016 }
01017
01018 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
01019 }
01020
01021 std::string OSnLNodeDivide::getTokenName()
01022 {
01023 return "divide";
01024 }
01025
01026 double OSnLNodeDivide::calculateFunction(double *x)
01027 {
01028
01029 m_dFunctionValue = m_mChildren[0]->calculateFunction( x)/m_mChildren[1]->calculateFunction( x);
01030 return m_dFunctionValue;
01031 }
01032
01033
01034 ADdouble OSnLNodeDivide::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01035 {
01036 m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) / m_mChildren[1]->constructADTape( ADIdx, XAD);
01037 return m_ADTape;
01038 }
01039
01040
01041 OSnLNode* OSnLNodeDivide::cloneOSnLNode()
01042 {
01043 OSnLNode *nlNodePoint;
01044 nlNodePoint = new OSnLNodeDivide();
01045 return nlNodePoint;
01046 }
01047
01048
01049
01050
01051 OSnLNodePower::OSnLNodePower()
01052 {
01053 inumberOfChildren = 2;
01054 m_mChildren = new OSnLNode*[2];
01055 m_mChildren[ 0] = NULL;
01056 m_mChildren[ 1] = NULL;
01057 inodeInt = 1009;
01058 inodeType = 2;
01059 }
01060
01061
01062 OSnLNodePower::~OSnLNodePower()
01063 {
01064 #ifndef NDEBUG
01065 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodePower destructor");
01066 #endif
01067 for(unsigned int i = 0; i < inumberOfChildren; i++)
01068 {
01069 delete m_mChildren[ i];
01070 m_mChildren[i] = NULL;
01071 }
01072
01073 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
01074 }
01075
01076 std::string OSnLNodePower::getTokenName()
01077 {
01078 return "power";
01079 }
01080
01081 double OSnLNodePower::calculateFunction(double *x)
01082 {
01083
01084 m_dFunctionValue = pow(m_mChildren[0]->calculateFunction( x), m_mChildren[1]->calculateFunction( x));
01085 return m_dFunctionValue;
01086 }
01087
01088
01089 ADdouble OSnLNodePower::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01090 {
01091
01092 if( this->m_mChildren[1]->inodeInt == 5001 )
01093 {
01094 OSnLNodeNumber *numberNode = (OSnLNodeNumber*)m_mChildren[1];
01095
01096 if( (numberNode->value) == int( numberNode->value))
01097 {
01098 m_ADTape = pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , int( numberNode->value));
01099 }
01100 else m_ADTape = pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , m_mChildren[1]->constructADTape( ADIdx, XAD) );
01101 }
01102 else
01103 {
01104 m_ADTape = pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , m_mChildren[1]->constructADTape( ADIdx, XAD) );
01105 }
01106 return m_ADTape;
01107 }
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120 OSnLNode* OSnLNodePower::cloneOSnLNode()
01121 {
01122 OSnLNode *nlNodePoint;
01123 nlNodePoint = new OSnLNodePower();
01124 return nlNodePoint;
01125 }
01126
01127
01128
01129
01130
01131
01132 OSnLNodeProduct::OSnLNodeProduct()
01133 {
01134 inumberOfChildren = 0;
01135 inodeInt = 1010;
01136 inodeType = -1;
01137 }
01138
01139
01140 OSnLNodeProduct::~OSnLNodeProduct()
01141 {
01142 #ifndef NDEBUG
01143 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeProduct destructor");
01144 #endif
01145 if(inumberOfChildren > 0)
01146 {
01147 for(unsigned int i = 0; i < inumberOfChildren; i++)
01148 {
01149 delete m_mChildren[ i];
01150 m_mChildren[i] = NULL;
01151 }
01152 }
01153
01154 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
01155 }
01156
01157 std::string OSnLNodeProduct::getTokenName()
01158 {
01159 return "product";
01160 }
01161
01162 double OSnLNodeProduct::calculateFunction(double *x)
01163 {
01164
01165 m_dFunctionValue = 1.0;
01166 unsigned int i;
01167 for(i = 0; i < inumberOfChildren; i++)
01168 {
01169 m_dFunctionValue = m_dFunctionValue*m_mChildren[i]->calculateFunction(x);
01170 }
01171 return m_dFunctionValue;
01172 }
01173
01174
01175 ADdouble OSnLNodeProduct::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01176 {
01177 m_ADTape = 1.0;
01178 unsigned int i;
01179 for(i = 0; i < inumberOfChildren; i++)
01180 {
01181 m_ADTape = m_ADTape*m_mChildren[i]->constructADTape( ADIdx, XAD);
01182 }
01183 return m_ADTape;
01184 }
01185
01186
01187 OSnLNode* OSnLNodeProduct::cloneOSnLNode()
01188 {
01189 OSnLNode *nlNodePoint;
01190 nlNodePoint = new OSnLNodeProduct();
01191 return nlNodePoint;
01192 }
01193
01194
01195
01196
01197
01198
01199 OSnLNodeLn::OSnLNodeLn()
01200 {
01201 inumberOfChildren = 1;
01202 m_mChildren = new OSnLNode*[1];
01203 m_mChildren[ 0] = NULL;
01204 inodeInt = 2007;
01205 inodeType = 1;
01206 }
01207
01208
01209 OSnLNodeLn::~OSnLNodeLn()
01210 {
01211 #ifndef NDEBUG
01212 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeLn destructor");
01213 #endif
01214 for(unsigned int i = 0; i < inumberOfChildren; i++)
01215 {
01216 delete m_mChildren[ i];
01217 m_mChildren[i] = NULL;
01218 }
01219
01220 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
01221 }
01222
01223 std::string OSnLNodeLn::getTokenName()
01224 {
01225 return "ln";
01226 }
01227
01228 double OSnLNodeLn::calculateFunction(double *x)
01229 {
01230 m_dFunctionValue = log(m_mChildren[0]->calculateFunction( x) );
01231 return m_dFunctionValue;
01232 }
01233
01234
01235 ADdouble OSnLNodeLn::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01236 {
01237 m_ADTape = log( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01238 return m_ADTape;
01239 }
01240
01241 OSnLNode* OSnLNodeLn::cloneOSnLNode()
01242 {
01243 OSnLNode *nlNodePoint;
01244 nlNodePoint = new OSnLNodeLn();
01245 return nlNodePoint;
01246 }
01247
01248
01249
01250
01251
01252
01253
01254 OSnLNodeSqrt::OSnLNodeSqrt()
01255 {
01256 inumberOfChildren = 1;
01257 m_mChildren = new OSnLNode*[1];
01258 m_mChildren[ 0] = NULL;
01259 inodeInt = 2006;
01260 inodeType = 1;
01261 }
01262
01263
01264 OSnLNodeSqrt::~OSnLNodeSqrt()
01265 {
01266 #ifndef NDEBUG
01267 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeSqrt destructor");
01268 #endif
01269 for(unsigned int i = 0; i < inumberOfChildren; i++)
01270 {
01271 delete m_mChildren[ i];
01272 m_mChildren[i] = NULL;
01273 }
01274
01275 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
01276 }
01277
01278 std::string OSnLNodeSqrt::getTokenName()
01279 {
01280 return "squareRoot";
01281 }
01282
01283 double OSnLNodeSqrt::calculateFunction(double *x)
01284 {
01285 m_dFunctionValue = sqrt(m_mChildren[0]->calculateFunction( x) );
01286 return m_dFunctionValue;
01287 }
01288
01289
01290 ADdouble OSnLNodeSqrt::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01291 {
01292 m_ADTape = sqrt( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01293 return m_ADTape;
01294 }
01295
01296 OSnLNode* OSnLNodeSqrt::cloneOSnLNode()
01297 {
01298 OSnLNode *nlNodePoint;
01299 nlNodePoint = new OSnLNodeSqrt();
01300 return nlNodePoint;
01301 }
01302
01303
01304
01305
01306
01307
01308 OSnLNodeSquare::OSnLNodeSquare()
01309 {
01310 inumberOfChildren = 1;
01311 m_mChildren = new OSnLNode*[1];
01312 m_mChildren[ 0] = NULL;
01313 inodeInt = 2005;
01314 inodeType = 1;
01315 }
01316
01317
01318 OSnLNodeSquare::~OSnLNodeSquare()
01319 {
01320 #ifndef NDEBUG
01321 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeSquare destructor");
01322 #endif
01323 for(unsigned int i = 0; i < inumberOfChildren; i++)
01324 {
01325 delete m_mChildren[ i];
01326 m_mChildren[i] = NULL;
01327 }
01328
01329 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
01330 }
01331
01332 std::string OSnLNodeSquare::getTokenName()
01333 {
01334 return "square";
01335 }
01336
01337 double OSnLNodeSquare::calculateFunction(double *x)
01338 {
01339 m_dFunctionValue = pow( (m_mChildren[0]->calculateFunction( x) ), 2);
01340 return m_dFunctionValue;
01341 }
01342
01343
01344 ADdouble OSnLNodeSquare::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01345 {
01346 m_ADTape = pow( m_mChildren[0]->constructADTape( ADIdx, XAD), int( 2) );
01347 return m_ADTape;
01348 }
01349
01350 OSnLNode* OSnLNodeSquare::cloneOSnLNode()
01351 {
01352 OSnLNode *nlNodePoint;
01353 nlNodePoint = new OSnLNodeSquare();
01354 return nlNodePoint;
01355 }
01356
01357
01358
01359
01360 OSnLNodeSin::OSnLNodeSin()
01361 {
01362 inumberOfChildren = 1;
01363 m_mChildren = new OSnLNode*[1];
01364 m_mChildren[ 0] = NULL;
01365 inodeInt = 3001;
01366 inodeType = 1;
01367 }
01368
01369
01370 OSnLNodeSin::~OSnLNodeSin()
01371 {
01372 #ifndef NDEBUG
01373 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeSin destructor");
01374 #endif
01375 for(unsigned int i = 0; i < inumberOfChildren; i++)
01376 {
01377 delete m_mChildren[ i];
01378 m_mChildren[i] = NULL;
01379 }
01380
01381 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
01382 }
01383
01384 std::string OSnLNodeSin::getTokenName()
01385 {
01386 return "sin";
01387 }
01388
01389 double OSnLNodeSin::calculateFunction(double *x)
01390 {
01391 m_dFunctionValue = sin(m_mChildren[0]->calculateFunction( x) );
01392 return m_dFunctionValue;
01393 }
01394
01395
01396 ADdouble OSnLNodeSin::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01397 {
01398 m_ADTape = sin( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01399 return m_ADTape;
01400 }
01401
01402 OSnLNode* OSnLNodeSin::cloneOSnLNode()
01403 {
01404 OSnLNode *nlNodePoint;
01405 nlNodePoint = new OSnLNodeSin();
01406 return nlNodePoint;
01407 }
01408
01409
01410
01411
01412
01413 OSnLNodeCos::OSnLNodeCos()
01414 {
01415 inumberOfChildren = 1;
01416 m_mChildren = new OSnLNode*[1];
01417 m_mChildren[ 0] = NULL;
01418 inodeInt = 3002;
01419 inodeType = 1;
01420 }
01421
01422
01423 OSnLNodeCos::~OSnLNodeCos()
01424 {
01425 #ifndef NDEBUG
01426 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeCos destructor");
01427 #endif
01428 for(unsigned int i = 0; i < inumberOfChildren; i++)
01429 {
01430 delete m_mChildren[ i];
01431 m_mChildren[i] = NULL;
01432 }
01433
01434 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
01435 }
01436
01437 std::string OSnLNodeCos::getTokenName()
01438 {
01439 return "cos";
01440 }
01441
01442 double OSnLNodeCos::calculateFunction(double *x)
01443 {
01444 m_dFunctionValue = cos(m_mChildren[0]->calculateFunction( x) );
01445 return m_dFunctionValue;
01446 }
01447
01448
01449 ADdouble OSnLNodeCos::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01450 {
01451 m_ADTape = cos( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01452 return m_ADTape;
01453 }
01454
01455 OSnLNode* OSnLNodeCos::cloneOSnLNode()
01456 {
01457 OSnLNode *nlNodePoint;
01458 nlNodePoint = new OSnLNodeCos();
01459 return nlNodePoint;
01460 }
01461
01462
01463
01464
01465
01466
01467
01468 OSnLNodeExp::OSnLNodeExp()
01469 {
01470 inumberOfChildren = 1;
01471 m_mChildren = new OSnLNode*[1];
01472 m_mChildren[ 0] = NULL;
01473 inodeInt = 2010;
01474 inodeType = 1;
01475 }
01476
01477
01478 OSnLNodeExp::~OSnLNodeExp()
01479 {
01480 #ifndef NDEBUG
01481 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeExp destructor");
01482 #endif
01483 for(unsigned int i = 0; i < inumberOfChildren; i++)
01484 {
01485 delete m_mChildren[ i];
01486 m_mChildren[i] = NULL;
01487 }
01488
01489 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
01490 }
01491
01492 std::string OSnLNodeExp::getTokenName()
01493 {
01494 return "exp";
01495 }
01496
01497 double OSnLNodeExp::calculateFunction(double *x)
01498 {
01499 m_dFunctionValue = exp(m_mChildren[0]->calculateFunction( x) );
01500 return m_dFunctionValue;
01501 }
01502
01503
01504 ADdouble OSnLNodeExp::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01505 {
01506 m_ADTape = exp( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01507 return m_ADTape;
01508 }
01509
01510 OSnLNode* OSnLNodeExp::cloneOSnLNode()
01511 {
01512 OSnLNode *nlNodePoint;
01513 nlNodePoint = new OSnLNodeExp();
01514 return nlNodePoint;
01515 }
01516
01517
01518
01519
01520
01521
01522
01523 OSnLNodeAbs::OSnLNodeAbs()
01524 {
01525 inumberOfChildren = 1;
01526 m_mChildren = new OSnLNode*[1];
01527 m_mChildren[ 0] = NULL;
01528 inodeInt = 2001;
01529 inodeType = 1;
01530 }
01531
01532
01533 OSnLNodeAbs::~OSnLNodeAbs()
01534 {
01535 #ifndef NDEBUG
01536 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeAbs destructor");
01537 #endif
01538 for(unsigned int i = 0; i < inumberOfChildren; i++)
01539 {
01540 delete m_mChildren[ i];
01541 m_mChildren[i] = NULL;
01542 }
01543
01544 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
01545 }
01546
01547 std::string OSnLNodeAbs::getTokenName()
01548 {
01549 return "abs";
01550 }
01551
01552 double OSnLNodeAbs::calculateFunction(double *x)
01553 {
01554 m_dFunctionValue = fabs(m_mChildren[0]->calculateFunction( x) );
01555 return m_dFunctionValue;
01556 }
01557
01558
01559 ADdouble OSnLNodeAbs::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01560 {
01561 m_ADTape = abs( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01562 return m_ADTape;
01563 }
01564
01565 OSnLNode* OSnLNodeAbs::cloneOSnLNode()
01566 {
01567 OSnLNode *nlNodePoint;
01568 nlNodePoint = new OSnLNodeAbs();
01569 return nlNodePoint;
01570 }
01571
01572
01573
01574
01575
01576
01577
01578
01579 OSnLNodeErf::OSnLNodeErf()
01580 {
01581 inumberOfChildren = 1;
01582 m_mChildren = new OSnLNode*[1];
01583 m_mChildren[ 0] = NULL;
01584 inodeInt = 4625;
01585 inodeType = 1;
01586 }
01587
01588
01589 OSnLNodeErf::~OSnLNodeErf()
01590 {
01591 #ifndef NDEBUG
01592 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeErf destructor");
01593 #endif
01594 for(unsigned int i = 0; i < inumberOfChildren; i++)
01595 {
01596 delete m_mChildren[ i];
01597 m_mChildren[i] = NULL;
01598 }
01599
01600 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
01601 }
01602
01603 std::string OSnLNodeErf::getTokenName()
01604 {
01605 return "erf";
01606 }
01607
01608 double OSnLNodeErf::calculateFunction(double *x)
01609 {
01610 const double a = (993./880.);
01611 const double b = (89./880.);
01612
01613 m_dFunctionValue = tanh( (a + b * m_mChildren[0]->calculateFunction( x) * m_mChildren[0]->calculateFunction( x)) * m_mChildren[0]->calculateFunction( x) );
01614
01615 return m_dFunctionValue;
01616 }
01617
01618
01619 ADdouble OSnLNodeErf::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01620 {
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630 const double a = (993./880.);
01631 const double b = (89./880.);
01632
01633
01634
01635 m_ADTape = tanh( (a + b * m_mChildren[0]->constructADTape( ADIdx, XAD) * m_mChildren[0]->constructADTape( ADIdx, XAD)) * m_mChildren[0]->constructADTape( ADIdx, XAD) );
01636
01637 return m_ADTape;
01638 }
01639
01640 OSnLNode* OSnLNodeErf::cloneOSnLNode()
01641 {
01642 OSnLNode *nlNodePoint;
01643 nlNodePoint = new OSnLNodeErf();
01644 return nlNodePoint;
01645 }
01646
01647
01648
01649
01650
01651
01652
01653 OSnLNodeIf::OSnLNodeIf()
01654 {
01655 inumberOfChildren = 3;
01656 m_mChildren = new OSnLNode*[3];
01657 m_mChildren[ 0] = NULL;
01658 m_mChildren[ 1] = NULL;
01659 m_mChildren[ 2] = NULL;
01660 inodeInt = 7001;
01661 inodeType = 3;
01662 }
01663
01664
01665 OSnLNodeIf::~OSnLNodeIf()
01666 {
01667 #ifndef NDEBUG
01668 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeIf destructor");
01669 #endif
01670 for(unsigned int i = 0; i < inumberOfChildren; i++)
01671 {
01672 delete m_mChildren[ i];
01673 m_mChildren[i] = NULL;
01674 }
01675
01676 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
01677 }
01678
01679 std::string OSnLNodeIf::getTokenName()
01680 {
01681 return "if";
01682 }
01683
01684 double OSnLNodeIf::calculateFunction(double *x)
01685 {
01686 if(m_mChildren[0]->calculateFunction( x) >= 0) m_dFunctionValue = m_mChildren[ 1]->calculateFunction( x);
01687 else m_dFunctionValue = m_mChildren[ 2]->calculateFunction( x);
01688 return m_dFunctionValue;
01689 }
01690
01691 ADdouble OSnLNodeIf::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01692 {
01693
01694 try
01695 {
01696 throw ErrorClass("if operator not supported by current Algorithmic Differentiation implementation");
01697 return m_ADTape;
01698 }
01699 catch(const ErrorClass& eclass)
01700 {
01701 throw ErrorClass( eclass.errormsg);
01702 }
01703 }
01704
01705 OSnLNode* OSnLNodeIf::cloneOSnLNode()
01706 {
01707 OSnLNode *nlNodePoint;
01708 nlNodePoint = new OSnLNodeIf();
01709 return nlNodePoint;
01710 }
01711
01712
01713
01714
01715
01716 OSnLNodeNumber::OSnLNodeNumber()
01717 {
01718 inodeInt = 5001;
01719 inumberOfChildren = 0;
01720 m_mChildren = NULL;
01721 inodeType = 0;
01722 value = 0.0;
01723
01724 type = "real";
01725 id = "";
01726
01727 }
01728
01729 OSnLNodeNumber::~OSnLNodeNumber()
01730 {
01731 #ifndef NDEBUG
01732 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeNumber destructor");
01733 #endif
01734 m_mChildren = NULL;
01735 }
01736
01737 std::string OSnLNodeNumber::getTokenNumber()
01738 {
01739 ostringstream outStr;
01740 outStr << inodeInt;
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751 return outStr.str();
01752 }
01753
01754
01755 std::string OSnLNodeNumber::getTokenName()
01756 {
01757 return "number";
01758 }
01759
01760
01761 std::string OSnLNodeNumber::getNonlinearExpressionInXML()
01762 {
01763 ostringstream outStr;
01764 outStr << "<" ;
01765 outStr << this->getTokenName();
01766 outStr << " value=\"";
01767 outStr << os_dtoa_format(value);
01768 outStr << "\"";
01769 outStr << " type=\"";
01770 outStr << type ;
01771 outStr << "\"";
01772 if(id.length() > 0)
01773 {
01774 outStr << " id=\"";
01775 outStr << id ;
01776 outStr << "\"";
01777 }
01778 outStr << "/>";
01779 return outStr.str();
01780 }
01781
01782
01783 double OSnLNodeNumber::calculateFunction(double *x)
01784 {
01785 m_dFunctionValue = this->value;
01786 return m_dFunctionValue;
01787 }
01788
01789 ADdouble OSnLNodeNumber::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01790 {
01791 m_ADTape = this->value;
01792 return m_ADTape;
01793 }
01794
01795 OSnLNode* OSnLNodeNumber::cloneOSnLNode()
01796 {
01797 OSnLNode *nlNodePoint;
01798 nlNodePoint = new OSnLNodeNumber();
01799 return nlNodePoint;
01800 }
01801
01802
01803
01804
01805 OSnLNodeE::OSnLNodeE()
01806 {
01807 inodeInt = 5004;
01808 inumberOfChildren = 0;
01809 m_mChildren = NULL;
01810 inodeType = 0;
01811
01812
01813
01814
01815 }
01816
01817 OSnLNodeE::~OSnLNodeE()
01818 {
01819 #ifndef NDEBUG
01820 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeE destructor");
01821 #endif
01822 m_mChildren = NULL;
01823 }
01824
01825
01826
01827 std::string OSnLNodeE::getTokenNumber()
01828 {
01829 ostringstream outStr;
01830 outStr << inodeInt;
01831 return outStr.str();
01832 }
01833
01834
01835 std::string OSnLNodeE::getTokenName()
01836 {
01837 ostringstream outStr;
01838 outStr << "E";
01839 return outStr.str();
01840 }
01841
01842
01843 std::string OSnLNodeE::getNonlinearExpressionInXML()
01844 {
01845 ostringstream outStr;
01846 outStr << "<" ;
01847 outStr << "E";
01848 outStr << "/>";
01849 return outStr.str();
01850 }
01851
01852
01853 double OSnLNodeE::calculateFunction(double *x)
01854 {
01855 m_dFunctionValue = OS_E_VALUE;
01856 return m_dFunctionValue;
01857 }
01858
01859 ADdouble OSnLNodeE::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01860 {
01861 m_ADTape = OS_E_VALUE;
01862 return m_ADTape;
01863 }
01864
01865 OSnLNode* OSnLNodeE::cloneOSnLNode()
01866 {
01867 OSnLNode *nlNodePoint;
01868 nlNodePoint = new OSnLNodeE();
01869 return nlNodePoint;
01870 }
01871
01872
01873
01874
01875
01876 OSnLNodePI::OSnLNodePI()
01877 {
01878 inodeInt = 5003;
01879 inumberOfChildren = 0;
01880 m_mChildren = NULL;
01881 inodeType = 0;
01882
01883
01884 }
01885
01886
01887 OSnLNodePI::~OSnLNodePI()
01888 {
01889 #ifndef NDEBUG
01890 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodePI destructor");
01891 #endif
01892 m_mChildren = NULL;
01893 }
01894
01895
01896 std::string OSnLNodePI::getTokenNumber()
01897 {
01898 ostringstream outStr;
01899 outStr << inodeInt;
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910 return outStr.str();
01911 }
01912
01913
01914 std::string OSnLNodePI::getTokenName()
01915 {
01916 ostringstream outStr;
01917 outStr << "PI";
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928 return outStr.str();
01929 }
01930
01931
01932 std::string OSnLNodePI::getNonlinearExpressionInXML()
01933 {
01934 ostringstream outStr;
01935 outStr << "<" ;
01936 outStr << "PI";
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948 outStr << "/>";
01949 return outStr.str();
01950 }
01951
01952
01953 double OSnLNodePI::calculateFunction(double *x)
01954 {
01955 m_dFunctionValue = OS_PI_VALUE;
01956 return m_dFunctionValue;
01957 }
01958
01959 ADdouble OSnLNodePI::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01960 {
01961 m_ADTape = OS_PI_VALUE;
01962 return m_ADTape;
01963 }
01964
01965 OSnLNode* OSnLNodePI::cloneOSnLNode()
01966 {
01967 OSnLNode *nlNodePoint;
01968 nlNodePoint = new OSnLNodePI();
01969 return nlNodePoint;
01970 }
01971
01972
01973
01974
01975 OSnLNodeVariable::OSnLNodeVariable()
01976 {
01977 inumberOfChildren = 0;
01978 m_mChildren = NULL;
01979 inodeInt = 6001;
01980 inodeType = -1;
01981 coef = 1.0;
01982 idx = -1;
01983 }
01984
01985 OSnLNodeVariable::~OSnLNodeVariable()
01986 {
01987 std::ostringstream outStr;
01988 #ifndef NDEBUG
01989 outStr << "inside OSnLNodeVariable destructor" << endl;
01990 outStr << "number kids = " << inumberOfChildren << endl;
01991 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSExpressionTree, ENUM_OUTPUT_LEVEL_trace, outStr.str());
01992 #endif
01993 if(inumberOfChildren > 0)
01994 {
01995 for(unsigned int i = 0; i < inumberOfChildren; i++)
01996 {
01997 delete m_mChildren[ i];
01998 m_mChildren[i] = NULL;
01999 }
02000 }
02001
02002 if(inumberOfChildren > 0 && m_mChildren != NULL) delete[] m_mChildren;
02003 }
02004
02005
02006 std::string OSnLNodeVariable::getTokenNumber()
02007 {
02008 ostringstream outStr;
02009
02010 outStr << inodeInt;
02011 outStr << "[";
02012 outStr << inumberOfChildren ;
02013 outStr << "]";
02014 outStr << ":" ;
02015 outStr << idx;
02016 outStr << ":" ;
02017 outStr << coef;
02018 outStr << ":real:" ;
02019 return outStr.str();
02020 }
02021
02022
02023 std::string OSnLNodeVariable::getTokenName()
02024 {
02025 ostringstream outStr;
02026
02027 outStr << "variable";
02028 outStr << "[";
02029 outStr << inumberOfChildren ;
02030 outStr << "]";
02031 outStr << ":" ;
02032 outStr << idx;
02033 outStr << ":" ;
02034 outStr << coef;
02035 outStr << ":real:" ;
02036 return outStr.str();
02037 }
02038
02039
02040 std::string OSnLNodeVariable::getNonlinearExpressionInXML()
02041 {
02042 ostringstream outStr;
02043 outStr << "<" ;
02044 outStr << "variable";
02045 outStr << " idx=\"";
02046 outStr << idx ;
02047 outStr << "\"";
02048 outStr << " coef=\"";
02049 outStr << os_dtoa_format(coef);
02050 outStr << "\"";
02051 if(inumberOfChildren > 0)
02052 {
02053 outStr << ">";
02054 }
02055 else
02056 {
02057 outStr << "/>";
02058 }
02059 if(inumberOfChildren > 0)
02060 {
02061 for(unsigned int i = 0; i < inumberOfChildren; i++)
02062 {
02063 outStr << m_mChildren[i]->getNonlinearExpressionInXML();
02064 }
02065 }
02066 if(inumberOfChildren > 0)
02067 {
02068 outStr << "</" ;
02069 outStr << "variable" ;
02070 outStr << ">" ;
02071 }
02072 return outStr.str();
02073 }
02074
02075 double OSnLNodeVariable::calculateFunction(double *x)
02076 {
02077 m_dFunctionValue = coef*x[idx];
02078 return m_dFunctionValue;
02079 }
02080
02081 ADdouble OSnLNodeVariable::constructADTape(std::map<int, int> *varIdx, ADvector *XAD)
02082 {
02083 m_ADTape = coef;
02084
02085
02086
02087
02088 m_ADTape = coef*(*XAD)[ (*varIdx)[ idx] ];
02089 return m_ADTape;
02090 }
02091
02092
02093 void OSnLNodeVariable::getVariableIndexMap(std::map<int, int> *varIdx)
02094 {
02095 int numVars;
02096 if( (*varIdx).find( idx) != (*varIdx).end() )
02097 {
02098
02099 }
02100 else
02101 {
02102
02103 numVars = (*varIdx).size();
02104
02105 (*varIdx)[ idx] = numVars;
02106 }
02107
02108 }
02109
02110
02111 OSnLNode* OSnLNodeVariable::cloneOSnLNode()
02112 {
02113 OSnLNode *nlNodePoint;
02114 nlNodePoint = new OSnLNodeVariable();
02115 return nlNodePoint;
02116 }
02117
02118
02119
02120
02121
02122
02123