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