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