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