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