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