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