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