00001
00016 #include "OSnLNode.h"
00017 #include "OSErrorClass.h"
00018 #include "OSParameters.h"
00019 #include "OSMathUtil.h"
00020 #include "OSOutput.h"
00021
00022 #include <string>
00023 #include <cstdlib>
00024
00025 #ifdef HAVE_CMATH
00026 # include <cmath>
00027 #else
00028 # ifdef HAVE_MATH_H
00029 # include <math.h>
00030 # else
00031 # error "don't have header file for math"
00032 # endif
00033 #endif
00034
00035
00036 #include <iostream>
00037 #include <sstream>
00038
00039
00040 using std::ostringstream;
00041 using std::cout;
00042 using std::endl;
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 ExprNode::ExprNode():
00155 inodeInt(-1),
00156 inodeType(0),
00157 inumberOfChildren( 0),
00158 inumberOfMatrixChildren( 0),
00159 m_mChildren(NULL),
00160 m_mMatrixChildren(NULL)
00161 {
00162 #ifndef NDEBUG
00163 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside ExprNode constructor");
00164 #endif
00165 }
00166
00167 ExprNode::~ExprNode()
00168 {
00169 #ifndef NDEBUG
00170 std::ostringstream outStr;
00171 outStr << "inside ExprNode destructor" << std::endl;
00172 outStr << "scalar kids = " << inumberOfChildren << std::endl;
00173 outStr << "matrix kids = " << inumberOfMatrixChildren << std::endl;
00174 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
00175 #endif
00176 if (inumberOfChildren > 0 && m_mChildren != NULL)
00177 {
00178 for (int i=0; i<inumberOfChildren; i++)
00179 {
00180 if (m_mChildren[i] != NULL)
00181 delete m_mChildren[i];
00182 m_mChildren[i] = NULL;
00183 }
00184 delete [] m_mChildren;
00185 m_mChildren = NULL;
00186 inumberOfChildren = 0;
00187 }
00188 else if (inumberOfChildren > 0 || m_mChildren != NULL)
00189 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_warning, "Warning: Possible memory leak");
00190
00191 if (inumberOfMatrixChildren > 0 && m_mMatrixChildren != NULL)
00192 {
00193 for (int i=0; i<inumberOfMatrixChildren; i++)
00194 {
00195 if (m_mMatrixChildren[i] != NULL)
00196 delete m_mMatrixChildren[i];
00197 m_mMatrixChildren[i] = NULL;
00198 }
00199 delete [] m_mMatrixChildren;
00200 m_mMatrixChildren = NULL;
00201 inumberOfMatrixChildren = 0;
00202 }
00203 else if (inumberOfMatrixChildren > 0 || m_mMatrixChildren != NULL)
00204 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_warning, "Warning: Possible memory leak");
00205 }
00206
00207
00208 std::string ExprNode::getTokenNumber()
00209 {
00210 ostringstream outStr;
00211 outStr << inodeInt;
00212 outStr << "[";
00213 outStr << inumberOfChildren;
00214 outStr << ",";
00215 outStr << inumberOfMatrixChildren;
00216 outStr << "]";
00217 return outStr.str();
00218 }
00219
00220
00221 std::string ExprNode::getNonlinearExpressionInXML()
00222 {
00223 ostringstream outStr, logStr;
00224 outStr << "<";
00225 outStr << this->getTokenName();
00226 #ifndef NDEBUG
00227 logStr << "nonlinear node " << this->getTokenName() << endl;
00228 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, logStr.str());
00229 #endif
00230 if(inumberOfChildren == 0 && inumberOfMatrixChildren == 0)
00231 {
00232 outStr << "/>";
00233 }
00234 else
00235 {
00236 outStr << ">";
00237 if(inumberOfChildren > 0)
00238 {
00239 for(unsigned int i = 0; i < inumberOfChildren; i++)
00240 {
00241 outStr << m_mChildren[i]->getNonlinearExpressionInXML();
00242 }
00243 }
00244 if(inumberOfMatrixChildren > 0)
00245 {
00246 for(unsigned int i = 0; i < inumberOfMatrixChildren; i++)
00247 {
00248 outStr << m_mMatrixChildren[i]->getNonlinearExpressionInXML();
00249 }
00250 }
00251 outStr << "</";
00252 outStr << this->getTokenName();
00253 outStr << ">";
00254 }
00255 return outStr.str();
00256 }
00257
00258
00259 std::vector<ExprNode*> ExprNode::getPrefixFromExpressionTree()
00260 {
00261 std::vector<ExprNode*> prefixVector;
00262 return preOrderOSnLNodeTraversal( &prefixVector);
00263 }
00264
00265
00266 std::vector<ExprNode*> ExprNode::preOrderOSnLNodeTraversal( std::vector<ExprNode*> *prefixVector)
00267 {
00268 (*prefixVector).push_back( this);
00269 if(inumberOfChildren > 0)
00270 {
00271 for(unsigned int i = 0; i < inumberOfChildren; i++)
00272 m_mChildren[i]->ExprNode::preOrderOSnLNodeTraversal( prefixVector);
00273 }
00274 if(inumberOfMatrixChildren > 0)
00275 {
00276 for(unsigned int i = 0; i < inumberOfMatrixChildren; i++)
00277 m_mMatrixChildren[i]->ExprNode::preOrderOSnLNodeTraversal( prefixVector);
00278 }
00279 return *prefixVector;
00280 }
00281
00282 std::vector<ExprNode*> ExprNode::getPostfixFromExpressionTree( )
00283 {
00284 std::vector<ExprNode*> postfixVector;
00285 return postOrderOSnLNodeTraversal( &postfixVector);
00286 }
00287
00288
00289 std::vector<ExprNode*> ExprNode::postOrderOSnLNodeTraversal( std::vector<ExprNode*> *postfixVector)
00290 {
00291 if(inumberOfChildren > 0)
00292 {
00293 unsigned int i;
00294 for(i = 0; i < inumberOfChildren; i++)
00295 m_mChildren[i]->ExprNode::postOrderOSnLNodeTraversal( postfixVector);
00296 }
00297 if(inumberOfMatrixChildren > 0)
00298 {
00299 unsigned int i;
00300 for(i = 0; i < inumberOfMatrixChildren; i++)
00301 m_mMatrixChildren[i]->ExprNode::postOrderOSnLNodeTraversal( postfixVector);
00302 }
00303 (*postfixVector).push_back( this);
00304 return *postfixVector;
00305 }
00306
00307
00308 bool ExprNode::IsEqual(ExprNode *that)
00309 {
00310 #ifndef NDEBUG
00311 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in ExprNode");
00312 #endif
00313 if (this == NULL)
00314 {
00315 if (that == NULL)
00316 return true;
00317 else
00318 {
00319 #ifndef NDEBUG
00320 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
00321 "First object is NULL, second is not");
00322 #endif
00323 return false;
00324 }
00325 }
00326 else
00327 {
00328 if (that == NULL)
00329 {
00330 #ifndef NDEBUG
00331 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
00332 "Second object is NULL, first is not");
00333 #endif
00334 return false;
00335 }
00336 else
00337 {
00338 if (this->inodeInt != that->inodeInt)
00339 return false;
00340 if (this->inodeType != that->inodeType)
00341 return false;
00342 if (this->inumberOfChildren != that->inumberOfChildren)
00343 return false;
00344 if (this->inumberOfMatrixChildren != that->inumberOfMatrixChildren)
00345 return false;
00346
00347 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
00348 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
00349 return false;
00350
00351 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
00352 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
00353 return false;
00354
00355 return true;
00356 }
00357 }
00358 }
00359
00360
00361
00362
00363
00364
00365 OSnLNode::OSnLNode():
00366 ExprNode(),
00367 m_dFunctionValue( OSNaN())
00368 {
00369 #ifndef NDEBUG
00370 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNode constructor");
00371 #endif
00372 }
00373
00374 OSnLNode::~OSnLNode()
00375 {
00376 #ifndef NDEBUG
00377 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNode destructor");
00378 #endif
00379 }
00380
00381 OSnLNode* OSnLNode::createExpressionTreeFromPrefix(std::vector<ExprNode*> nlNodeVec)
00382 {
00383 std::vector<ExprNode*> stackVec;
00384 int kount = nlNodeVec.size() - 1;
00385 while(kount >= 0)
00386 {
00387 int numMtxKids = nlNodeVec[kount]->inumberOfMatrixChildren;
00388 int numkids = nlNodeVec[kount]->inumberOfChildren;
00389 if(numkids > 0)
00390 {
00391 for(int i = 0; i < numkids; i++)
00392 {
00393 nlNodeVec[kount]->m_mChildren[i] = (OSnLNode*)stackVec.back();
00394 stackVec.pop_back();
00395 }
00396 }
00397
00398 if(numMtxKids > 0)
00399 {
00400 for(int i = 0; i < numMtxKids; i++)
00401 {
00402 nlNodeVec[kount]->m_mMatrixChildren[i] = (OSnLMNode*)stackVec.back();
00403 stackVec.pop_back();
00404 }
00405 }
00406 stackVec.push_back( nlNodeVec[kount]);
00407 kount--;
00408 }
00409 stackVec.clear();
00410 return (OSnLNode*)nlNodeVec[ 0];
00411 }
00412
00413 OSnLNode* OSnLNode::createExpressionTreeFromPostfix(std::vector<ExprNode*> nlNodeVec)
00414 {
00415 std::vector<ExprNode*> stackVec;
00416
00417 int kount = 0;
00418 while(kount <= nlNodeVec.size() - 1)
00419 {
00420 int numMtxKids = nlNodeVec[kount]->inumberOfMatrixChildren;
00421 if (numMtxKids > 0)
00422 {
00423 for(int i = numMtxKids - 1; i >= 0; i--)
00424 {
00425 nlNodeVec[kount]->m_mMatrixChildren[i] = (OSnLMNode*)stackVec.back();
00426 stackVec.pop_back();
00427 }
00428 }
00429 int numkids = nlNodeVec[kount]->inumberOfChildren;
00430 if (numkids > 0)
00431 {
00432 for(int i = numkids - 1; i >= 0; i--)
00433 {
00434 nlNodeVec[kount]->m_mChildren[i] = (OSnLNode*)stackVec.back();
00435 stackVec.pop_back();
00436 }
00437 }
00438 stackVec.push_back( nlNodeVec[kount]);
00439 kount++;
00440 }
00441 stackVec.clear();
00442 return (OSnLNode*)nlNodeVec[ kount - 1];
00443 }
00444
00445
00446 std::vector<ExprNode*> OSnLNode::getPrefixFromExpressionTree()
00447 {
00448 std::vector<ExprNode*> prefixVector;
00449 return preOrderOSnLNodeTraversal( &prefixVector);
00450 }
00451
00452 std::vector<ExprNode*> OSnLNode::preOrderOSnLNodeTraversal( std::vector<ExprNode*> *prefixVector)
00453 {
00454 (*prefixVector).push_back( (OSnLNode*)this);
00455 if(inumberOfChildren > 0)
00456 {
00457 for(unsigned int i = 0; i < inumberOfChildren; i++)
00458 m_mChildren[i]->OSnLNode::preOrderOSnLNodeTraversal( prefixVector);
00459 }
00460 if(inumberOfMatrixChildren > 0)
00461 {
00462 for(unsigned int i = 0; i < inumberOfMatrixChildren; i++)
00463 m_mMatrixChildren[i]->OSnLMNode::preOrderOSnLNodeTraversal( prefixVector);
00464 }
00465 return *prefixVector;
00466 }
00467
00468 std::vector<ExprNode*> OSnLNode::getPostfixFromExpressionTree( )
00469 {
00470 std::vector<ExprNode*> postfixVector;
00471 return postOrderOSnLNodeTraversal( &postfixVector);
00472 }
00473
00474
00475 std::vector<ExprNode*> OSnLNode::postOrderOSnLNodeTraversal( std::vector<ExprNode*> *postfixVector)
00476 {
00477 if(inumberOfChildren > 0)
00478 {
00479 unsigned int i;
00480 for(i = 0; i < inumberOfChildren; i++)
00481 m_mChildren[i]->OSnLNode::postOrderOSnLNodeTraversal( postfixVector);
00482 }
00483 if(inumberOfMatrixChildren > 0)
00484 {
00485 unsigned int i;
00486 for(i = 0; i < inumberOfMatrixChildren; i++)
00487 m_mMatrixChildren[i]->OSnLMNode::postOrderOSnLNodeTraversal( postfixVector);
00488 }
00489 (*postfixVector).push_back( (OSnLNode*)this);
00490 return *postfixVector;
00491 }
00492
00493 void OSnLNode::getVariableIndexMap(std::map<int, int> *varIdx)
00494 {
00495 unsigned int i;
00496 if(inodeInt != OS_VARIABLE)
00497 {
00498 for(i = 0; i < inumberOfChildren; i++)
00499 {
00500 m_mChildren[ i]->getVariableIndexMap( varIdx);
00501 }
00502 }
00503 }
00504
00505 OSnLNode* OSnLNode::copyNodeAndDescendants()
00506 {
00507 #ifndef NDEBUG
00508 ostringstream outStr;
00509 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
00510 outStr << " (" << this->getTokenName() << ")" << std::endl;
00511 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
00512 #endif
00513
00514 OSnLNode* ndcopy = (OSnLNode*)cloneExprNode();
00515 ndcopy->inumberOfChildren = inumberOfChildren;
00516 ndcopy->inumberOfMatrixChildren = inumberOfMatrixChildren;
00517 ndcopy->inodeInt = inodeInt;
00518 ndcopy->inodeType = inodeType;
00519
00520 if (inumberOfChildren > 0)
00521 {
00522 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
00523 for (int i=0; i < inumberOfChildren; i++)
00524 {
00525 ndcopy->m_mChildren[i] = m_mChildren[i]->copyNodeAndDescendants();
00526 }
00527 }
00528
00529 if (inumberOfMatrixChildren > 0)
00530 {
00531 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
00532 for (int i=0; i < inumberOfMatrixChildren; i++)
00533 {
00534 ndcopy->m_mMatrixChildren[i] = m_mMatrixChildren[i]->copyNodeAndDescendants();
00535 }
00536 }
00537
00538 return ndcopy;
00539 }
00540
00541 bool OSnLNode::IsEqual(OSnLNode *that)
00542 {
00543 #ifndef NDEBUG
00544 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLNode");
00545 #endif
00546 if (this == NULL)
00547 {
00548 if (that == NULL)
00549 return true;
00550 else
00551 {
00552 #ifndef NDEBUG
00553 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
00554 "First object is NULL, second is not");
00555 #endif
00556 return false;
00557 }
00558 }
00559 else
00560 {
00561 if (that == NULL)
00562 {
00563 #ifndef NDEBUG
00564 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
00565 "Second object is NULL, first is not");
00566 #endif
00567 return false;
00568 }
00569 else
00570 {
00571 if (this->inumberOfChildren != that->inumberOfChildren)
00572 return false;
00573 if (this->inumberOfMatrixChildren != that->inumberOfMatrixChildren)
00574 return false;
00575 if (this->inodeInt != that->inodeInt)
00576 return false;
00577 if (this->inodeType != that->inodeType)
00578 return false;
00579
00580 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
00581 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
00582 return false;
00583
00584 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
00585 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
00586 return false;
00587
00588 return true;
00589 }
00590 }
00591 }
00592
00593
00594
00595 OSnLNodePlus::OSnLNodePlus()
00596 {
00597 inumberOfChildren = 2;
00598 inumberOfMatrixChildren = 0;
00599 m_mChildren = new OSnLNode*[2];
00600 m_mChildren[ 0] = NULL;
00601 m_mChildren[ 1] = NULL;
00602 inodeInt = OS_PLUS;
00603 inodeType = 2;
00604 }
00605
00606
00607 OSnLNodePlus::~OSnLNodePlus()
00608 {
00609 std::ostringstream outStr;
00610 #ifndef NDEBUG
00611 outStr << "inside OSnLNodePlus destructor" << endl;
00612 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
00613 #endif
00614 }
00615
00616 std::string OSnLNodePlus::getTokenName()
00617 {
00618 return "plus";
00619 }
00620
00621 double OSnLNodePlus::calculateFunction(double *x)
00622 {
00623 m_dFunctionValue = m_mChildren[0]->calculateFunction(x) + m_mChildren[1]->calculateFunction(x);
00624 return m_dFunctionValue;
00625 }
00626
00627
00628 ADdouble OSnLNodePlus::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
00629 {
00630 m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) + m_mChildren[1]->constructADTape( ADIdx, XAD);
00631 return m_ADTape;
00632 }
00633
00634 OSnLNode* OSnLNodePlus::cloneExprNode()
00635 {
00636 OSnLNode *nlNodePoint;
00637 nlNodePoint = new OSnLNodePlus();
00638 return nlNodePoint;
00639 }
00640
00641
00642
00643
00644 OSnLNodeSum::OSnLNodeSum()
00645 {
00646 inumberOfChildren = 0;
00647 inumberOfMatrixChildren = 0;
00648 inodeInt = OS_SUM;
00649 inodeType = -1;
00650 }
00651
00652 OSnLNodeSum::~OSnLNodeSum()
00653 {
00654 #ifndef NDEBUG
00655 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeSum destructor");
00656 #endif
00657 }
00658
00659 std::string OSnLNodeSum::getTokenName()
00660 {
00661 return "sum";
00662 }
00663
00664 double OSnLNodeSum::calculateFunction(double *x)
00665 {
00666 m_dFunctionValue = 0.0;
00667 unsigned int i;
00668 for(i = 0; i < inumberOfChildren; i++)
00669 {
00670 m_dFunctionValue = m_dFunctionValue + m_mChildren[i]->calculateFunction(x);
00671 }
00672 return m_dFunctionValue;
00673 }
00674
00675
00676 ADdouble OSnLNodeSum::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
00677 {
00678 m_ADTape = 0.0;
00679 unsigned int i;
00680 for(i = 0; i < inumberOfChildren; i++)
00681 {
00682 m_ADTape = m_ADTape + m_mChildren[i]->constructADTape( ADIdx, XAD);
00683 }
00684 return m_ADTape;
00685 }
00686
00687 OSnLNode* OSnLNodeSum::cloneExprNode()
00688 {
00689 OSnLNode *nlNodePoint;
00690 nlNodePoint = new OSnLNodeSum();
00691 return nlNodePoint;
00692 }
00693
00694
00695
00696
00697
00698
00699 OSnLNodeAllDiff::OSnLNodeAllDiff()
00700 {
00701 inumberOfChildren = 0;
00702 inumberOfMatrixChildren = 0;
00703 inodeInt = OS_ALLDIFF;
00704 inodeType = -1;
00705 }
00706
00707 OSnLNodeAllDiff::~OSnLNodeAllDiff()
00708 {
00709 #ifndef NDEBUG
00710 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeAllDiff destructor");
00711 #endif
00712 }
00713
00714 std::string OSnLNodeAllDiff::getTokenName()
00715 {
00716 return "allDiff";
00717 }
00718
00719
00720 double OSnLNodeAllDiff::calculateFunction(double *x)
00721 {
00722 m_dFunctionValue = 1;
00723
00724 unsigned int i, k;
00725 if(inumberOfChildren > 1)
00726 {
00727 for(i = 0; i < inumberOfChildren - 1; i++)
00728 {
00729 for(k = i + 1; k < inumberOfChildren; k++)
00730 {
00731 if(m_mChildren[i]->calculateFunction(x) ==
00732 m_mChildren[k]->calculateFunction(x)) return 0 ;
00733 }
00734 }
00735 }
00736
00737 return m_dFunctionValue;
00738 }
00739
00740
00741 ADdouble OSnLNodeAllDiff::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
00742 {
00743 try
00744 {
00745 throw ErrorClass("AllDifferent operator not supported by current Algorithmic Differentiation implementation");
00746 return m_ADTape;
00747 }
00748 catch(const ErrorClass& eclass)
00749 {
00750 throw ErrorClass( eclass.errormsg);
00751 }
00752 return m_ADTape;
00753 }
00754
00755
00756 OSnLNode* OSnLNodeAllDiff::cloneExprNode()
00757 {
00758 OSnLNode *nlNodePoint;
00759 nlNodePoint = new OSnLNodeAllDiff();
00760 return nlNodePoint;
00761 }
00762
00763
00764
00765
00766
00767 OSnLNodeMax::OSnLNodeMax()
00768 {
00769 inumberOfChildren = 0;
00770 inumberOfMatrixChildren = 0;
00771 inodeInt = OS_MAX;
00772 inodeType = -1;
00773 }
00774
00775 OSnLNodeMax::~OSnLNodeMax()
00776 {
00777 #ifndef NDEBUG
00778 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeMax destructor");
00779 #endif
00780 }
00781
00782 double OSnLNodeMax::calculateFunction(double *x)
00783 {
00784 m_dFunctionValue = -OSDBL_MAX;
00785
00786 for(unsigned int i = 0; i < inumberOfChildren; i++)
00787 {
00788 if(m_mChildren[i]->calculateFunction(x) > m_dFunctionValue)
00789 {
00790 m_dFunctionValue = m_mChildren[i]->calculateFunction(x);
00791 }
00792 }
00793 return m_dFunctionValue;
00794 }
00795
00796 std::string OSnLNodeMax::getTokenName()
00797 {
00798 return "max";
00799 }
00800
00801
00802 ADdouble OSnLNodeMax::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
00803 {
00804
00805 try
00806 {
00807 throw ErrorClass("Max operator not supported by current Algorithmic Differentiation implementation");
00808 return m_ADTape;
00809 }
00810 catch(const ErrorClass& eclass)
00811 {
00812 throw ErrorClass( eclass.errormsg);
00813 }
00814 }
00815
00816
00817 OSnLNode* OSnLNodeMax::cloneExprNode()
00818 {
00819 OSnLNode *nlNodePoint;
00820 nlNodePoint = new OSnLNodeMax();
00821 return nlNodePoint;
00822 }
00823
00824
00825
00826
00827 OSnLNodeMin::OSnLNodeMin()
00828 {
00829 inumberOfChildren = 0;
00830 inumberOfMatrixChildren = 0;
00831 inodeInt = OS_MIN;
00832 inodeType = -1;
00833 }
00834
00835 OSnLNodeMin::~OSnLNodeMin()
00836 {
00837 #ifndef NDEBUG
00838 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeMin destructor");
00839 #endif
00840 }
00841
00842
00843 std::string OSnLNodeMin::getTokenName()
00844 {
00845 return "min";
00846 }
00847
00848 double OSnLNodeMin::calculateFunction(double *x)
00849 {
00850 m_dFunctionValue = OSDBL_MAX;
00851
00852 for(unsigned int i = 0; i < inumberOfChildren; i++)
00853 {
00854 if(m_mChildren[i]->calculateFunction(x) < m_dFunctionValue)
00855 {
00856 m_dFunctionValue = m_mChildren[i]->calculateFunction(x);
00857 }
00858 }
00859 return m_dFunctionValue;
00860 }
00861
00862
00863 ADdouble OSnLNodeMin::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
00864 {
00865
00866 try
00867 {
00868 throw ErrorClass("Min operator not supported by current Algorithmic Differentiation implementation");
00869 return m_ADTape;
00870 }
00871 catch(const ErrorClass& eclass)
00872 {
00873 throw ErrorClass( eclass.errormsg);
00874 }
00875 }
00876
00877
00878 OSnLNode* OSnLNodeMin::cloneExprNode()
00879 {
00880 OSnLNode *nlNodePoint;
00881 nlNodePoint = new OSnLNodeMin();
00882 return nlNodePoint;
00883 }
00884
00885
00886
00887
00888 OSnLNodeMinus::OSnLNodeMinus()
00889 {
00890 inumberOfChildren = 2;
00891 inumberOfMatrixChildren = 0;
00892 m_mChildren = new OSnLNode*[2];
00893 m_mChildren[ 0] = NULL;
00894 m_mChildren[ 1] = NULL;
00895 inodeInt = OS_MINUS;
00896 inodeType = 2;
00897 }
00898
00899
00900 OSnLNodeMinus::~OSnLNodeMinus()
00901 {
00902 #ifndef NDEBUG
00903 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeMinus destructor");
00904 #endif
00905 }
00906
00907 std::string OSnLNodeMinus::getTokenName()
00908 {
00909 return "minus";
00910 }
00911
00912 double OSnLNodeMinus::calculateFunction(double *x)
00913 {
00914 m_dFunctionValue = m_mChildren[0]->calculateFunction( x) - m_mChildren[1]->calculateFunction( x);
00915 return m_dFunctionValue;
00916 }
00917
00918
00919 ADdouble OSnLNodeMinus::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
00920 {
00921 m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) - m_mChildren[1]->constructADTape( ADIdx, XAD);
00922 return m_ADTape;
00923 }
00924
00925
00926 OSnLNode* OSnLNodeMinus::cloneExprNode()
00927 {
00928 OSnLNode *nlNodePoint;
00929 nlNodePoint = new OSnLNodeMinus();
00930 return nlNodePoint;
00931 }
00932
00933
00934
00935
00936
00937 OSnLNodeNegate::OSnLNodeNegate()
00938 {
00939 inumberOfChildren = 1;
00940 inumberOfMatrixChildren = 0;
00941 m_mChildren = new OSnLNode*[1];
00942 m_mChildren[ 0] = NULL;
00943 inodeInt = OS_NEGATE;
00944 inodeType = 1;
00945 }
00946
00947
00948 OSnLNodeNegate::~OSnLNodeNegate()
00949 {
00950 #ifndef NDEBUG
00951 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeNegate destructor");
00952 #endif
00953 }
00954
00955 std::string OSnLNodeNegate::getTokenName()
00956 {
00957 return "negate";
00958 }
00959
00960 double OSnLNodeNegate::calculateFunction(double *x)
00961 {
00962 m_dFunctionValue = -m_mChildren[0]->calculateFunction( x) ;
00963 return m_dFunctionValue;
00964 }
00965
00966 ADdouble OSnLNodeNegate::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
00967 {
00968 m_ADTape = -m_mChildren[0]->constructADTape( ADIdx, XAD);
00969 return m_ADTape;
00970 }
00971
00972 OSnLNode* OSnLNodeNegate::cloneExprNode()
00973 {
00974 OSnLNode *nlNodePoint;
00975 nlNodePoint = new OSnLNodeNegate();
00976 return nlNodePoint;
00977 }
00978
00979
00980
00981 OSnLNodeTimes::OSnLNodeTimes()
00982 {
00983 inumberOfChildren = 2;
00984 inumberOfMatrixChildren = 0;
00985 m_mChildren = new OSnLNode*[2];
00986 m_mChildren[ 0] = NULL;
00987 m_mChildren[ 1] = NULL;
00988 inodeInt = OS_TIMES;
00989 inodeType = 2;
00990 }
00991
00992
00993 OSnLNodeTimes::~OSnLNodeTimes()
00994 {
00995 #ifndef NDEBUG
00996 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeTimes destructor");
00997 #endif
00998 }
00999
01000 std::string OSnLNodeTimes::getTokenName()
01001 {
01002 return "times";
01003 }
01004
01005 double OSnLNodeTimes::calculateFunction(double *x)
01006 {
01007 m_dFunctionValue = m_mChildren[0]->calculateFunction( x)*m_mChildren[1]->calculateFunction( x);
01008 return m_dFunctionValue;
01009 }
01010
01011
01012 ADdouble OSnLNodeTimes::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01013 {
01014 m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) * m_mChildren[1]->constructADTape( ADIdx, XAD);
01015 return m_ADTape;
01016 }
01017
01018 OSnLNode* OSnLNodeTimes::cloneExprNode()
01019 {
01020 OSnLNode *nlNodePoint;
01021 nlNodePoint = new OSnLNodeTimes();
01022 return nlNodePoint;
01023 }
01024
01025
01026
01027
01028 OSnLNodeDivide::OSnLNodeDivide()
01029 {
01030 inumberOfChildren = 2;
01031 inumberOfMatrixChildren = 0;
01032 m_mChildren = new OSnLNode*[2];
01033 m_mChildren[ 0] = NULL;
01034 m_mChildren[ 1] = NULL;
01035 inodeInt = OS_DIVIDE;
01036 inodeType = 2;
01037 }
01038
01039
01040 OSnLNodeDivide::~OSnLNodeDivide()
01041 {
01042 #ifndef NDEBUG
01043 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeDivide destructor");
01044 #endif
01045 }
01046
01047 std::string OSnLNodeDivide::getTokenName()
01048 {
01049 return "divide";
01050 }
01051
01052 double OSnLNodeDivide::calculateFunction(double *x)
01053 {
01054
01055 m_dFunctionValue = m_mChildren[0]->calculateFunction( x)/m_mChildren[1]->calculateFunction( x);
01056 return m_dFunctionValue;
01057 }
01058
01059
01060 ADdouble OSnLNodeDivide::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01061 {
01062 m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) / m_mChildren[1]->constructADTape( ADIdx, XAD);
01063 return m_ADTape;
01064 }
01065
01066
01067 OSnLNode* OSnLNodeDivide::cloneExprNode()
01068 {
01069 OSnLNode *nlNodePoint;
01070 nlNodePoint = new OSnLNodeDivide();
01071 return nlNodePoint;
01072 }
01073
01074
01075
01076
01077 OSnLNodePower::OSnLNodePower()
01078 {
01079 inumberOfChildren = 2;
01080 inumberOfMatrixChildren = 0;
01081 m_mChildren = new OSnLNode*[2];
01082 m_mChildren[ 0] = NULL;
01083 m_mChildren[ 1] = NULL;
01084 inodeInt = OS_POWER;
01085 inodeType = 2;
01086 }
01087
01088
01089 OSnLNodePower::~OSnLNodePower()
01090 {
01091 #ifndef NDEBUG
01092 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodePower destructor");
01093 #endif
01094 }
01095
01096 std::string OSnLNodePower::getTokenName()
01097 {
01098 return "power";
01099 }
01100
01101 double OSnLNodePower::calculateFunction(double *x)
01102 {
01103
01104 m_dFunctionValue = pow(m_mChildren[0]->calculateFunction( x), m_mChildren[1]->calculateFunction( x));
01105 return m_dFunctionValue;
01106 }
01107
01108
01109 ADdouble OSnLNodePower::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01110 {
01111
01112 if( this->m_mChildren[1]->inodeInt == 5001 )
01113 {
01114 OSnLNodeNumber *numberNode = (OSnLNodeNumber*)m_mChildren[1];
01115
01116 if( (numberNode->value) == int( numberNode->value))
01117 {
01118 m_ADTape = pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , int( numberNode->value));
01119 }
01120 else m_ADTape = pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , m_mChildren[1]->constructADTape( ADIdx, XAD) );
01121 }
01122 else
01123 {
01124 m_ADTape = pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , m_mChildren[1]->constructADTape( ADIdx, XAD) );
01125 }
01126 return m_ADTape;
01127 }
01128
01129
01130
01131
01132
01133
01134
01135
01136 OSnLNode* OSnLNodePower::cloneExprNode()
01137 {
01138 OSnLNode *nlNodePoint;
01139 nlNodePoint = new OSnLNodePower();
01140 return nlNodePoint;
01141 }
01142
01143
01144
01145
01146 OSnLNodeProduct::OSnLNodeProduct()
01147 {
01148 inumberOfChildren = 0;
01149 inumberOfMatrixChildren = 0;
01150 inodeInt = OS_PRODUCT;
01151 inodeType = -1;
01152 }
01153
01154
01155 OSnLNodeProduct::~OSnLNodeProduct()
01156 {
01157 #ifndef NDEBUG
01158 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeProduct destructor");
01159 #endif
01160 }
01161
01162 std::string OSnLNodeProduct::getTokenName()
01163 {
01164 return "product";
01165 }
01166
01167 double OSnLNodeProduct::calculateFunction(double *x)
01168 {
01169
01170 m_dFunctionValue = 1.0;
01171 unsigned int i;
01172 for(i = 0; i < inumberOfChildren; i++)
01173 {
01174 m_dFunctionValue = m_dFunctionValue*m_mChildren[i]->calculateFunction(x);
01175 }
01176 return m_dFunctionValue;
01177 }
01178
01179
01180 ADdouble OSnLNodeProduct::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01181 {
01182 m_ADTape = 1.0;
01183 unsigned int i;
01184 for(i = 0; i < inumberOfChildren; i++)
01185 {
01186 m_ADTape = m_ADTape*m_mChildren[i]->constructADTape( ADIdx, XAD);
01187 }
01188 return m_ADTape;
01189 }
01190
01191
01192 OSnLNode* OSnLNodeProduct::cloneExprNode()
01193 {
01194 OSnLNode *nlNodePoint;
01195 nlNodePoint = new OSnLNodeProduct();
01196 return nlNodePoint;
01197 }
01198
01199
01200
01201
01202 OSnLNodeLn::OSnLNodeLn()
01203 {
01204 inumberOfChildren = 1;
01205 inumberOfMatrixChildren = 0;
01206 m_mChildren = new OSnLNode*[1];
01207 m_mChildren[ 0] = NULL;
01208 inodeInt = OS_LN;
01209 inodeType = 1;
01210 }
01211
01212
01213 OSnLNodeLn::~OSnLNodeLn()
01214 {
01215 #ifndef NDEBUG
01216 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeLn destructor");
01217 #endif
01218 }
01219
01220 std::string OSnLNodeLn::getTokenName()
01221 {
01222 return "ln";
01223 }
01224
01225 double OSnLNodeLn::calculateFunction(double *x)
01226 {
01227 m_dFunctionValue = log(m_mChildren[0]->calculateFunction( x) );
01228 return m_dFunctionValue;
01229 }
01230
01231
01232 ADdouble OSnLNodeLn::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01233 {
01234 m_ADTape = log( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01235 return m_ADTape;
01236 }
01237
01238 OSnLNode* OSnLNodeLn::cloneExprNode()
01239 {
01240 OSnLNode *nlNodePoint;
01241 nlNodePoint = new OSnLNodeLn();
01242 return nlNodePoint;
01243 }
01244
01245
01246
01247
01248 OSnLNodeSqrt::OSnLNodeSqrt()
01249 {
01250 inumberOfChildren = 1;
01251 inumberOfMatrixChildren = 0;
01252 m_mChildren = new OSnLNode*[1];
01253 m_mChildren[ 0] = NULL;
01254 inodeInt = OS_SQRT;
01255 inodeType = 1;
01256 }
01257
01258
01259 OSnLNodeSqrt::~OSnLNodeSqrt()
01260 {
01261 #ifndef NDEBUG
01262 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeSqrt destructor");
01263 #endif
01264 }
01265
01266 std::string OSnLNodeSqrt::getTokenName()
01267 {
01268 return "sqrt";
01269 }
01270
01271 double OSnLNodeSqrt::calculateFunction(double *x)
01272 {
01273 m_dFunctionValue = sqrt(m_mChildren[0]->calculateFunction( x) );
01274 return m_dFunctionValue;
01275 }
01276
01277
01278 ADdouble OSnLNodeSqrt::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01279 {
01280 m_ADTape = sqrt( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01281 return m_ADTape;
01282 }
01283
01284 OSnLNode* OSnLNodeSqrt::cloneExprNode()
01285 {
01286 OSnLNode *nlNodePoint;
01287 nlNodePoint = new OSnLNodeSqrt();
01288 return nlNodePoint;
01289 }
01290
01291
01292
01293
01294 OSnLNodeSquare::OSnLNodeSquare()
01295 {
01296 inumberOfChildren = 1;
01297 inumberOfMatrixChildren = 0;
01298 m_mChildren = new OSnLNode*[1];
01299 m_mChildren[ 0] = NULL;
01300 inodeInt = OS_SQUARE;
01301 inodeType = 1;
01302 }
01303
01304
01305 OSnLNodeSquare::~OSnLNodeSquare()
01306 {
01307 #ifndef NDEBUG
01308 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeSquare destructor");
01309 #endif
01310 }
01311
01312 std::string OSnLNodeSquare::getTokenName()
01313 {
01314 return "square";
01315 }
01316
01317 double OSnLNodeSquare::calculateFunction(double *x)
01318 {
01319 m_dFunctionValue = pow( (m_mChildren[0]->calculateFunction( x) ), 2);
01320 return m_dFunctionValue;
01321 }
01322
01323
01324 ADdouble OSnLNodeSquare::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01325 {
01326 m_ADTape = pow( m_mChildren[0]->constructADTape( ADIdx, XAD), int( 2) );
01327 return m_ADTape;
01328 }
01329
01330 OSnLNode* OSnLNodeSquare::cloneExprNode()
01331 {
01332 OSnLNode *nlNodePoint;
01333 nlNodePoint = new OSnLNodeSquare();
01334 return nlNodePoint;
01335 }
01336
01337
01338
01339
01340 OSnLNodeSin::OSnLNodeSin()
01341 {
01342 inumberOfChildren = 1;
01343 inumberOfMatrixChildren = 0;
01344 m_mChildren = new OSnLNode*[1];
01345 m_mChildren[ 0] = NULL;
01346 inodeInt = OS_SIN;
01347 inodeType = 1;
01348 }
01349
01350
01351 OSnLNodeSin::~OSnLNodeSin()
01352 {
01353 #ifndef NDEBUG
01354 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeSin destructor");
01355 #endif
01356 }
01357
01358 std::string OSnLNodeSin::getTokenName()
01359 {
01360 return "sin";
01361 }
01362
01363 double OSnLNodeSin::calculateFunction(double *x)
01364 {
01365 m_dFunctionValue = sin(m_mChildren[0]->calculateFunction( x) );
01366 return m_dFunctionValue;
01367 }
01368
01369
01370 ADdouble OSnLNodeSin::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01371 {
01372 m_ADTape = sin( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01373 return m_ADTape;
01374 }
01375
01376 OSnLNode* OSnLNodeSin::cloneExprNode()
01377 {
01378 OSnLNode *nlNodePoint;
01379 nlNodePoint = new OSnLNodeSin();
01380 return nlNodePoint;
01381 }
01382
01383
01384
01385
01386 OSnLNodeCos::OSnLNodeCos()
01387 {
01388 inumberOfChildren = 1;
01389 inumberOfMatrixChildren = 0;
01390 m_mChildren = new OSnLNode*[1];
01391 m_mChildren[ 0] = NULL;
01392 inodeInt = OS_COS;
01393 inodeType = 1;
01394 }
01395
01396
01397 OSnLNodeCos::~OSnLNodeCos()
01398 {
01399 #ifndef NDEBUG
01400 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeCos destructor");
01401 #endif
01402 }
01403
01404 std::string OSnLNodeCos::getTokenName()
01405 {
01406 return "cos";
01407 }
01408
01409 double OSnLNodeCos::calculateFunction(double *x)
01410 {
01411 m_dFunctionValue = cos(m_mChildren[0]->calculateFunction( x) );
01412 return m_dFunctionValue;
01413 }
01414
01415
01416 ADdouble OSnLNodeCos::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01417 {
01418 m_ADTape = cos( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01419 return m_ADTape;
01420 }
01421
01422 OSnLNode* OSnLNodeCos::cloneExprNode()
01423 {
01424 OSnLNode *nlNodePoint;
01425 nlNodePoint = new OSnLNodeCos();
01426 return nlNodePoint;
01427 }
01428
01429
01430
01431
01432 OSnLNodeExp::OSnLNodeExp()
01433 {
01434 inumberOfChildren = 1;
01435 inumberOfMatrixChildren = 0;
01436 m_mChildren = new OSnLNode*[1];
01437 m_mChildren[ 0] = NULL;
01438 inodeInt = OS_EXP;
01439 inodeType = 1;
01440 }
01441
01442
01443 OSnLNodeExp::~OSnLNodeExp()
01444 {
01445 #ifndef NDEBUG
01446 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeExp destructor");
01447 #endif
01448 }
01449
01450 std::string OSnLNodeExp::getTokenName()
01451 {
01452 return "exp";
01453 }
01454
01455 double OSnLNodeExp::calculateFunction(double *x)
01456 {
01457 m_dFunctionValue = exp(m_mChildren[0]->calculateFunction( x) );
01458 return m_dFunctionValue;
01459 }
01460
01461
01462 ADdouble OSnLNodeExp::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01463 {
01464 m_ADTape = exp( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01465 return m_ADTape;
01466 }
01467
01468 OSnLNode* OSnLNodeExp::cloneExprNode()
01469 {
01470 OSnLNode *nlNodePoint;
01471 nlNodePoint = new OSnLNodeExp();
01472 return nlNodePoint;
01473 }
01474
01475
01476
01477
01478 OSnLNodeAbs::OSnLNodeAbs()
01479 {
01480 inumberOfChildren = 1;
01481 inumberOfMatrixChildren = 0;
01482 m_mChildren = new OSnLNode*[1];
01483 m_mChildren[ 0] = NULL;
01484 inodeInt = OS_ABS;
01485 inodeType = 1;
01486 }
01487
01488
01489 OSnLNodeAbs::~OSnLNodeAbs()
01490 {
01491 #ifndef NDEBUG
01492 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeAbs destructor");
01493 #endif
01494 }
01495
01496 std::string OSnLNodeAbs::getTokenName()
01497 {
01498 return "abs";
01499 }
01500
01501 double OSnLNodeAbs::calculateFunction(double *x)
01502 {
01503 m_dFunctionValue = fabs(m_mChildren[0]->calculateFunction( x) );
01504 return m_dFunctionValue;
01505 }
01506
01507
01508 ADdouble OSnLNodeAbs::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01509 {
01510 m_ADTape = abs( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01511 return m_ADTape;
01512 }
01513
01514 OSnLNode* OSnLNodeAbs::cloneExprNode()
01515 {
01516 OSnLNode *nlNodePoint;
01517 nlNodePoint = new OSnLNodeAbs();
01518 return nlNodePoint;
01519 }
01520
01521
01522
01523
01524
01525 OSnLNodeErf::OSnLNodeErf()
01526 {
01527 inumberOfChildren = 1;
01528 inumberOfMatrixChildren = 0;
01529 m_mChildren = new OSnLNode*[1];
01530 m_mChildren[ 0] = NULL;
01531 inodeInt = OS_ERF;
01532 inodeType = 1;
01533 }
01534
01535
01536 OSnLNodeErf::~OSnLNodeErf()
01537 {
01538 #ifndef NDEBUG
01539 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeErf destructor");
01540 #endif
01541 }
01542
01543 std::string OSnLNodeErf::getTokenName()
01544 {
01545 return "erf";
01546 }
01547
01548 double OSnLNodeErf::calculateFunction(double *x)
01549 {
01550 const double a = (993./880.);
01551 const double b = (89./880.);
01552 m_dFunctionValue = tanh( (a + b * m_mChildren[0]->calculateFunction( x) * m_mChildren[0]->calculateFunction( x)) * m_mChildren[0]->calculateFunction( x) );
01553
01554 return m_dFunctionValue;
01555 }
01556
01557
01558 ADdouble OSnLNodeErf::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01559 {
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569 const double a = (993./880.);
01570 const double b = (89./880.);
01571
01572
01573
01574 m_ADTape = tanh( (a + b * m_mChildren[0]->constructADTape( ADIdx, XAD) * m_mChildren[0]->constructADTape( ADIdx, XAD)) * m_mChildren[0]->constructADTape( ADIdx, XAD) );
01575
01576 return m_ADTape;
01577 }
01578
01579 OSnLNode* OSnLNodeErf::cloneExprNode()
01580 {
01581 OSnLNode *nlNodePoint;
01582 nlNodePoint = new OSnLNodeErf();
01583 return nlNodePoint;
01584 }
01585
01586
01587
01588
01589 OSnLNodeIf::OSnLNodeIf()
01590 {
01591 inumberOfChildren = 3;
01592 inumberOfMatrixChildren = 0;
01593 m_mChildren = new OSnLNode*[3];
01594 m_mChildren[ 0] = NULL;
01595 m_mChildren[ 1] = NULL;
01596 m_mChildren[ 2] = NULL;
01597 inodeInt = OS_IF;
01598 inodeType = 3;
01599 }
01600
01601
01602 OSnLNodeIf::~OSnLNodeIf()
01603 {
01604 #ifndef NDEBUG
01605 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeIf destructor");
01606 #endif
01607 }
01608
01609 std::string OSnLNodeIf::getTokenName()
01610 {
01611 return "if";
01612 }
01613
01614 double OSnLNodeIf::calculateFunction(double *x)
01615 {
01616 if(m_mChildren[0]->calculateFunction( x) >= 0) m_dFunctionValue = m_mChildren[ 1]->calculateFunction( x);
01617 else m_dFunctionValue = m_mChildren[ 2]->calculateFunction( x);
01618 return m_dFunctionValue;
01619 }
01620
01621 ADdouble OSnLNodeIf::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01622 {
01623
01624 try
01625 {
01626 throw ErrorClass("if operator not supported by current Algorithmic Differentiation implementation");
01627 return m_ADTape;
01628 }
01629 catch(const ErrorClass& eclass)
01630 {
01631 throw ErrorClass( eclass.errormsg);
01632 }
01633 }
01634
01635 OSnLNode* OSnLNodeIf::cloneExprNode()
01636 {
01637 OSnLNode *nlNodePoint;
01638 nlNodePoint = new OSnLNodeIf();
01639 return nlNodePoint;
01640 }
01641
01642
01643
01644
01645
01646 OSnLNodeNumber::OSnLNodeNumber()
01647 {
01648 inodeInt = OS_NUMBER;
01649 inumberOfChildren = 0;
01650 inumberOfMatrixChildren = 0;
01651 m_mChildren = NULL;
01652 m_mMatrixChildren = NULL;
01653 inodeType = 0;
01654 value = 0.0;
01655
01656 type = "real";
01657 id = "";
01658
01659 }
01660
01661 OSnLNodeNumber::~OSnLNodeNumber()
01662 {
01663 #ifndef NDEBUG
01664 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeNumber destructor");
01665 #endif
01666 }
01667
01668 std::string OSnLNodeNumber::getTokenNumber()
01669 {
01670 ostringstream outStr;
01671 outStr << inodeInt;
01672 outStr << ":" ;
01673 outStr << value ;
01674
01675
01676
01677
01678
01679
01680
01681
01682 return outStr.str();
01683 }
01684
01685
01686 std::string OSnLNodeNumber::getTokenName()
01687 {
01688 return "number";
01689 }
01690
01691
01692 std::string OSnLNodeNumber::getNonlinearExpressionInXML()
01693 {
01694 ostringstream outStr;
01695 outStr << "<" ;
01696 outStr << this->getTokenName();
01697 outStr << " value=\"";
01698 outStr << os_dtoa_format(value);
01699 outStr << "\"";
01700 if (type != "real")
01701 {
01702 outStr << " type=\"";
01703 outStr << type ;
01704 outStr << "\"";
01705 }
01706 if(id.length() > 0)
01707 {
01708 outStr << " id=\"";
01709 outStr << id ;
01710 outStr << "\"";
01711 }
01712 outStr << "/>";
01713 return outStr.str();
01714 }
01715
01716
01717 double OSnLNodeNumber::calculateFunction(double *x)
01718 {
01719 m_dFunctionValue = this->value;
01720 return m_dFunctionValue;
01721 }
01722
01723 ADdouble OSnLNodeNumber::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01724 {
01725 m_ADTape = this->value;
01726 return m_ADTape;
01727 }
01728
01729 OSnLNode* OSnLNodeNumber::cloneExprNode()
01730 {
01731 OSnLNode *nlNodePoint;
01732 nlNodePoint = new OSnLNodeNumber();
01733 return nlNodePoint;
01734 }
01735
01736
01737 OSnLNode* OSnLNodeNumber::copyNodeAndDescendants()
01738 {
01739 #ifndef NDEBUG
01740 ostringstream outStr;
01741 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
01742 outStr << " (" << this->getTokenName() << ")" << std::endl;
01743 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
01744 #endif
01745
01746 OSnLNodeNumber* ndcopy = (OSnLNodeNumber*)cloneExprNode();
01747 ndcopy->inumberOfChildren = inumberOfChildren;
01748 ndcopy->inumberOfMatrixChildren = inumberOfMatrixChildren;
01749 ndcopy->inodeInt = inodeInt;
01750 ndcopy->inodeType = inodeType;
01751 ndcopy->value = value;
01752 ndcopy->type = type;
01753 ndcopy->id = id;
01754
01755 if (inumberOfChildren > 0)
01756 {
01757 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
01758 for (int i=0; i < inumberOfChildren; i++)
01759 {
01760 ndcopy->m_mChildren[i] = m_mChildren[i]->copyNodeAndDescendants();
01761 }
01762 }
01763
01764 if (inumberOfMatrixChildren > 0)
01765 {
01766 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
01767 for (int i=0; i < inumberOfMatrixChildren; i++)
01768 {
01769 ndcopy->m_mMatrixChildren[i] = m_mMatrixChildren[i]->copyNodeAndDescendants();
01770 }
01771 }
01772
01773 return ndcopy;
01774 }
01775
01776 bool OSnLNodeNumber::IsEqual(OSnLNodeNumber *that)
01777 {
01778 #ifndef NDEBUG
01779 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLNodeNumber");
01780 #endif
01781 if (this == NULL)
01782 {
01783 if (that == NULL)
01784 return true;
01785 else
01786 {
01787 #ifndef NDEBUG
01788 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
01789 "First object is NULL, second is not");
01790 #endif
01791 return false;
01792 }
01793 }
01794 else
01795 {
01796 if (that == NULL)
01797 {
01798 #ifndef NDEBUG
01799 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
01800 "Second object is NULL, first is not");
01801 #endif
01802 return false;
01803 }
01804 else
01805 {
01806 if (this->inodeInt != that->inodeInt)
01807 return false;
01808 if (this->inodeType != that->inodeType)
01809 return false;
01810 if (this->inumberOfChildren != that->inumberOfChildren)
01811 return false;
01812 if (this->inumberOfMatrixChildren != that->inumberOfMatrixChildren)
01813 return false;
01814
01815 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
01816 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
01817 return false;
01818
01819 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
01820 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
01821 return false;
01822
01823 if (this->value != that->value)
01824 return false;
01825 if (this->type != that->type)
01826 return false;
01827 if (this->id != that->id)
01828 return false;
01829 return true;
01830 }
01831 }
01832 }
01833
01834
01835
01836
01837 OSnLNodeE::OSnLNodeE()
01838 {
01839 inodeInt = OS_E;
01840 inumberOfChildren = 0;
01841 inumberOfMatrixChildren = 0;
01842 m_mChildren = NULL;
01843 m_mMatrixChildren = NULL;
01844 inodeType = 0;
01845
01846
01847
01848 }
01849
01850 OSnLNodeE::~OSnLNodeE()
01851 {
01852 #ifndef NDEBUG
01853 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeE destructor");
01854 #endif
01855 }
01856
01857
01858 std::string OSnLNodeE::getTokenNumber()
01859 {
01860 ostringstream outStr;
01861 outStr << inodeInt;
01862 return outStr.str();
01863 }
01864
01865
01866 std::string OSnLNodeE::getTokenName()
01867 {
01868 ostringstream outStr;
01869 outStr << "E";
01870 return outStr.str();
01871 }
01872
01873
01874 std::string OSnLNodeE::getNonlinearExpressionInXML()
01875 {
01876 ostringstream outStr;
01877 outStr << "<" ;
01878 outStr << "E";
01879 outStr << "/>";
01880 return outStr.str();
01881 }
01882
01883
01884 double OSnLNodeE::calculateFunction(double *x)
01885 {
01886 m_dFunctionValue = OS_E_VALUE;
01887 return m_dFunctionValue;
01888 }
01889
01890 ADdouble OSnLNodeE::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01891 {
01892 m_ADTape = OS_E_VALUE;
01893 return m_ADTape;
01894 }
01895
01896 OSnLNode* OSnLNodeE::cloneExprNode()
01897 {
01898 OSnLNode *nlNodePoint;
01899 nlNodePoint = new OSnLNodeE();
01900 return nlNodePoint;
01901 }
01902
01903
01904
01905
01906 OSnLNodePI::OSnLNodePI()
01907 {
01908 inodeInt = OS_PI;
01909 inumberOfChildren = 0;
01910 inumberOfMatrixChildren = 0;
01911 m_mChildren = NULL;
01912 m_mMatrixChildren = NULL;
01913 inodeType = 0;
01914 }
01915
01916
01917 OSnLNodePI::~OSnLNodePI()
01918 {
01919 #ifndef NDEBUG
01920 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodePI destructor");
01921 #endif
01922 }
01923
01924
01925 std::string OSnLNodePI::getTokenNumber()
01926 {
01927 ostringstream outStr;
01928 outStr << inodeInt;
01929 return outStr.str();
01930 }
01931
01932
01933 std::string OSnLNodePI::getTokenName()
01934 {
01935 ostringstream outStr;
01936 outStr << "PI";
01937 return outStr.str();
01938 }
01939
01940
01941 std::string OSnLNodePI::getNonlinearExpressionInXML()
01942 {
01943 ostringstream outStr;
01944 outStr << "<" ;
01945 outStr << "PI";
01946 outStr << "/>";
01947 return outStr.str();
01948 }
01949
01950
01951 double OSnLNodePI::calculateFunction(double *x)
01952 {
01953 m_dFunctionValue = OS_PI_VALUE;
01954 return m_dFunctionValue;
01955 }
01956
01957 ADdouble OSnLNodePI::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
01958 {
01959 m_ADTape = OS_PI_VALUE;
01960 return m_ADTape;
01961 }
01962
01963 OSnLNode* OSnLNodePI::cloneExprNode()
01964 {
01965 OSnLNode *nlNodePoint;
01966 nlNodePoint = new OSnLNodePI();
01967 return nlNodePoint;
01968 }
01969
01970
01971
01972
01973 OSnLNodeVariable::OSnLNodeVariable()
01974 {
01975 inumberOfChildren = 0;
01976 inumberOfMatrixChildren = 0;
01977 m_mChildren = NULL;
01978 m_mMatrixChildren = NULL;
01979 inodeInt = OS_VARIABLE;
01980 inodeType = -1;
01981 coef = 1.0;
01982 idx = -1;
01983 }
01984
01985 OSnLNodeVariable::~OSnLNodeVariable()
01986 {
01987 std::ostringstream outStr;
01988 #ifndef NDEBUG
01989 outStr << "inside OSnLNodeVariable destructor" << endl;
01990 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
01991 #endif
01992 }
01993
01994
01995 std::string OSnLNodeVariable::getTokenNumber()
01996 {
01997 ostringstream outStr;
01998
01999 outStr << inodeInt;
02000 outStr << "[";
02001 outStr << inumberOfChildren ;
02002 outStr << "]";
02003 outStr << ":" ;
02004 outStr << idx;
02005 outStr << ":" ;
02006 outStr << coef;
02007 outStr << ":real:" ;
02008 return outStr.str();
02009 }
02010
02011
02012 std::string OSnLNodeVariable::getTokenName()
02013 {
02014 ostringstream outStr;
02015
02016 outStr << "variable";
02017 outStr << "[";
02018 outStr << inumberOfChildren ;
02019 outStr << "]";
02020 outStr << ":" ;
02021 outStr << idx;
02022 outStr << ":" ;
02023 outStr << coef;
02024 outStr << ":real:" ;
02025 return outStr.str();
02026 }
02027
02028
02029 std::string OSnLNodeVariable::getNonlinearExpressionInXML()
02030 {
02031 ostringstream outStr;
02032 outStr << "<";
02033 outStr << "variable";
02034 outStr << " idx=\"";
02035 outStr << idx;
02036 outStr << "\"";
02037 if (coef < 1 || coef > 1)
02038 {
02039 outStr << " coef=\"";
02040 outStr << os_dtoa_format(coef);
02041 outStr << "\"";
02042 }
02043 if (inumberOfChildren > 0)
02044 {
02045 outStr << ">";
02046 for(unsigned int i = 0; i < inumberOfChildren; i++)
02047 {
02048 outStr << m_mChildren[i]->getNonlinearExpressionInXML();
02049 }
02050 outStr << "</variable>";
02051 }
02052 else
02053 {
02054 outStr << "/>";
02055 }
02056 return outStr.str();
02057 }
02058
02059 double OSnLNodeVariable::calculateFunction(double *x)
02060 {
02061 m_dFunctionValue = coef*x[idx];
02062 return m_dFunctionValue;
02063 }
02064
02065 ADdouble OSnLNodeVariable::constructADTape(std::map<int, int> *varIdx, ADvector *XAD)
02066 {
02067 m_ADTape = coef*(*XAD)[ (*varIdx)[ idx] ];
02068 return m_ADTape;
02069 }
02070
02071
02072 void OSnLNodeVariable::getVariableIndexMap(std::map<int, int> *varIdx)
02073 {
02074 int numVars;
02075 if( (*varIdx).find( idx) == (*varIdx).end() )
02076 {
02077
02078
02079 (*varIdx)[ idx] = 1;
02080 #ifndef NDEBUG
02081 ostringstream outStr;
02082 outStr << "add variable " << idx << " to the map" << std::endl;
02083 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
02084 #endif
02085 }
02086 }
02087
02088 OSnLNode* OSnLNodeVariable::cloneExprNode()
02089 {
02090 OSnLNode *nlNodePoint;
02091 nlNodePoint = new OSnLNodeVariable();
02092 return nlNodePoint;
02093 }
02094
02095
02096 OSnLNode* OSnLNodeVariable::copyNodeAndDescendants()
02097 {
02098 #ifndef NDEBUG
02099 ostringstream outStr;
02100 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
02101 outStr << " (" << this->getTokenName() << ")" << std::endl;
02102 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
02103 #endif
02104
02105 OSnLNodeVariable* ndcopy = (OSnLNodeVariable*)cloneExprNode();
02106 ndcopy->inumberOfChildren = inumberOfChildren;
02107 ndcopy->inumberOfMatrixChildren = inumberOfMatrixChildren;
02108 ndcopy->inodeInt = inodeInt;
02109 ndcopy->inodeType = inodeType;
02110 ndcopy->coef = coef;
02111 ndcopy->idx = idx;
02112
02113 if (inumberOfChildren > 0)
02114 {
02115 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
02116 for (int i=0; i < inumberOfChildren; i++)
02117 {
02118 ndcopy->m_mChildren[i] = m_mChildren[i]->copyNodeAndDescendants();
02119 }
02120 }
02121
02122 if (inumberOfMatrixChildren > 0)
02123 {
02124 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
02125 for (int i=0; i < inumberOfMatrixChildren; i++)
02126 {
02127 ndcopy->m_mMatrixChildren[i] = m_mMatrixChildren[i]->copyNodeAndDescendants();
02128 }
02129 }
02130
02131 return ndcopy;
02132 }
02133
02134
02135 bool OSnLNodeVariable::IsEqual(OSnLNodeVariable *that)
02136 {
02137 #ifndef NDEBUG
02138 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLNodeVariable");
02139 #endif
02140 if (this == NULL)
02141 {
02142 if (that == NULL)
02143 return true;
02144 else
02145 {
02146 #ifndef NDEBUG
02147 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
02148 "First object is NULL, second is not");
02149 #endif
02150 return false;
02151 }
02152 }
02153 else
02154 {
02155 if (that == NULL)
02156 {
02157 #ifndef NDEBUG
02158 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
02159 "Second object is NULL, first is not");
02160 #endif
02161 return false;
02162 }
02163 else
02164 {
02165 if (this->inodeInt != that->inodeInt)
02166 return false;
02167 if (this->inodeType != that->inodeType)
02168 return false;
02169 if (this->inumberOfChildren != that->inumberOfChildren)
02170 return false;
02171 if (this->inumberOfMatrixChildren != that->inumberOfMatrixChildren)
02172 return false;
02173
02174 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
02175 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
02176 return false;
02177
02178 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
02179 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
02180 return false;
02181
02182 if (this->coef != that->coef)
02183 return false;
02184 if (this->idx != that->idx)
02185 return false;
02186 return true;
02187 }
02188 }
02189 }
02190
02191
02192
02195
02196
02197 OSnLNodeMatrixDeterminant::OSnLNodeMatrixDeterminant()
02198 {
02199 inumberOfChildren = 0;
02200 inumberOfMatrixChildren = 1;
02201 m_mMatrixChildren = new OSnLMNode*[1];
02202 inodeInt = OS_MATRIX_DETERMINANT;
02203 inodeType = 0;
02204 }
02205
02206 OSnLNodeMatrixDeterminant::~OSnLNodeMatrixDeterminant()
02207 {
02208 #ifndef NDEBUG
02209 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeMatrixDeterminant destructor");
02210 #endif
02211 }
02212
02213
02214 double OSnLNodeMatrixDeterminant::calculateFunction(double *x)
02215 {
02216 m_dFunctionValue = -OSDBL_MAX;
02217
02218 for(unsigned int i = 0; i < inumberOfChildren; i++)
02219 {
02220 if(m_mChildren[i]->calculateFunction(x) > m_dFunctionValue)
02221 {
02222 m_dFunctionValue = m_mChildren[i]->calculateFunction(x);
02223 }
02224 }
02225 return m_dFunctionValue;
02226 }
02227
02228 std::string OSnLNodeMatrixDeterminant::getTokenName()
02229 {
02230 return "matrixDeterminant";
02231 }
02232
02233
02234 ADdouble OSnLNodeMatrixDeterminant::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
02235 {
02236
02237 try
02238 {
02239 throw ErrorClass("Matrix determinant operator not supported by current Algorithmic Differentiation implementation");
02240 return m_ADTape;
02241 }
02242 catch(const ErrorClass& eclass)
02243 {
02244 throw ErrorClass( eclass.errormsg);
02245 }
02246 }
02247
02248
02249 OSnLNode* OSnLNodeMatrixDeterminant::cloneExprNode()
02250 {
02251 OSnLNode *nlNodePoint;
02252 nlNodePoint = new OSnLNodeMatrixDeterminant();
02253 return nlNodePoint;
02254 }
02255
02256
02257
02258 OSnLNodeMatrixTrace::OSnLNodeMatrixTrace()
02259 {
02260 inumberOfChildren = 0;
02261 inumberOfMatrixChildren = 1;
02262 m_mMatrixChildren = new OSnLMNode*[1];
02263 inodeInt = OS_MATRIX_TRACE;
02264 inodeType = 0;
02265 }
02266
02267 OSnLNodeMatrixTrace::~OSnLNodeMatrixTrace()
02268 {
02269 #ifndef NDEBUG
02270 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeMatrixTrace destructor");
02271 #endif
02272 }
02273
02274 double OSnLNodeMatrixTrace::calculateFunction(double *x)
02275 {
02276 #if 0
02277 m_dFunctionValue = -OSDBL_MAX;
02278
02279 for(unsigned int i = 0; i < inumberOfChildren; i++)
02280 {
02281 if(m_mChildren[i]->calculateFunction(x) > m_dFunctionValue)
02282 {
02283 m_dFunctionValue = m_mChildren[i]->calculateFunction(x);
02284 }
02285 }
02286 return m_dFunctionValue;
02287 #endif
02288 return 0.0;
02289 }
02290
02291 std::string OSnLNodeMatrixTrace::getTokenName()
02292 {
02293 return "matrixTrace";
02294 }
02295
02296
02297 ADdouble OSnLNodeMatrixTrace::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
02298 {
02299
02300 try
02301 {
02302 throw ErrorClass("Matrix trace operator not supported by current Algorithmic Differentiation implementation");
02303 return m_ADTape;
02304 }
02305 catch(const ErrorClass& eclass)
02306 {
02307 throw ErrorClass( eclass.errormsg);
02308 }
02309 }
02310
02311
02312 OSnLNode* OSnLNodeMatrixTrace::cloneExprNode()
02313 {
02314 OSnLNode *nlNodePoint;
02315 nlNodePoint = new OSnLNodeMatrixTrace();
02316 return nlNodePoint;
02317 }
02318
02319
02320
02321
02322 OSnLNodeMatrixToScalar::OSnLNodeMatrixToScalar()
02323 {
02324 inumberOfChildren = 0;
02325 inumberOfMatrixChildren = 1;
02326 m_mMatrixChildren = new OSnLMNode*[1];
02327 inodeInt = OS_MATRIX_TO_SCALAR;
02328 inodeType = 0;
02329 }
02330
02331 OSnLNodeMatrixToScalar::~OSnLNodeMatrixToScalar()
02332 {
02333 #ifndef NDEBUG
02334 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLNodeMatrixToScalar destructor");
02335 #endif
02336 }
02337
02338 double OSnLNodeMatrixToScalar::calculateFunction(double *x)
02339 {
02340 m_dFunctionValue = -OSDBL_MAX;
02341
02342 for(unsigned int i = 0; i < inumberOfChildren; i++)
02343 {
02344 if(m_mChildren[i]->calculateFunction(x) > m_dFunctionValue)
02345 {
02346 m_dFunctionValue = m_mChildren[i]->calculateFunction(x);
02347 }
02348 }
02349 return m_dFunctionValue;
02350 }
02351
02352 std::string OSnLNodeMatrixToScalar::getTokenName()
02353 {
02354 return "matrixToScalar";
02355 }
02356
02357
02358 ADdouble OSnLNodeMatrixToScalar::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
02359 {
02360
02361 try
02362 {
02363 throw ErrorClass("Matrix-to-scalar conversion not supported by current Algorithmic Differentiation implementation");
02364 return m_ADTape;
02365 }
02366 catch(const ErrorClass& eclass)
02367 {
02368 throw ErrorClass( eclass.errormsg);
02369 }
02370 }
02371
02372
02373 OSnLNode* OSnLNodeMatrixToScalar::cloneExprNode()
02374 {
02375 OSnLNode *nlNodePoint;
02376 nlNodePoint = new OSnLNodeMatrixToScalar();
02377 return nlNodePoint;
02378 }
02379
02380
02381
02382
02383
02384 OSnLMNode::OSnLMNode():
02385 ExprNode()
02386 {
02387 #ifndef NDEBUG
02388 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLMNode constructor");
02389 #endif
02390 }
02391
02392 OSnLMNode::~OSnLMNode()
02393 {
02394 #ifndef NDEBUG
02395 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLMNode destructor");
02396 #endif
02397 }
02398
02399 OSnLMNode* OSnLMNode::copyNodeAndDescendants()
02400 {
02401 #ifndef NDEBUG
02402 ostringstream outStr;
02403 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
02404 outStr << " (" << this->getTokenName() << ")" << std::endl;
02405 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
02406 #endif
02407
02408 OSnLMNode* ndcopy = (OSnLMNode*)cloneExprNode();
02409 ndcopy->inumberOfChildren = inumberOfChildren;
02410 ndcopy->inumberOfMatrixChildren = inumberOfMatrixChildren;
02411 ndcopy->inodeInt = inodeInt;
02412 ndcopy->inodeType = inodeType;
02413
02414 if (inumberOfChildren > 0)
02415 {
02416 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
02417 for (int i=0; i < inumberOfChildren; i++)
02418 {
02419 ndcopy->m_mChildren[i] = m_mChildren[i]->copyNodeAndDescendants();
02420 }
02421 }
02422
02423 if (inumberOfMatrixChildren > 0)
02424 {
02425 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
02426 for (int i=0; i < inumberOfMatrixChildren; i++)
02427 {
02428 ndcopy->m_mMatrixChildren[i] = m_mMatrixChildren[i]->copyNodeAndDescendants();
02429 }
02430 }
02431
02432 return ndcopy;
02433 }
02434
02435 #if 0
02436 OSnLMNode* OSnLMNode::createExpressionTreeFromPostfix(std::vector<OSnLMNode*> nlMNodeVec)
02437 {
02438 std::vector<OSnLMNode*> stackVec ;
02439 unsigned int kount = 0;
02440 while(kount <= nlMNodeVec.size() - 1)
02441 {
02442 int numkids = nlMNodeVec[kount]->inumberOfMatrixChildren;
02443 if(numkids > 0)
02444 {
02445 for(int i = numkids - 1; i >= 0; i--)
02446 {
02447 nlMNodeVec[kount]->m_mMatrixChildren[i] = stackVec.back() ;
02448 stackVec.pop_back();
02449 }
02450 }
02451 stackVec.push_back( nlMNodeVec[kount]);
02452 kount++;
02453 }
02454 stackVec.clear();
02455 return nlMNodeVec[ kount - 1];
02456 }
02457
02458 std::vector<OSnLMNode*> OSnLMNode::getPostfixFromExpressionTree( )
02459 {
02460
02461
02462 return 0;
02463 }
02464
02465 std::vector<OSnLNode*> OSnLNode::postOrderOSnLNodeTraversal( std::vector<OSnLNode*> *postfixVector)
02466 {
02467 if(inumberOfChildren > 0)
02468 {
02469 unsigned int i;
02470 for(i = 0; i < inumberOfChildren; i++)
02471 m_mChildren[i]->postOrderOSnLNodeTraversal( postfixVector);
02472 }
02473 (*postfixVector).push_back( this);
02474 return *postfixVector;
02475 }
02476 #endif
02477
02478 OSnLMNode* OSnLMNode::createExpressionTreeFromPrefix(std::vector<ExprNode*> nlNodeVec)
02479 {
02480 std::vector<ExprNode*> stackVec;
02481 int kount = nlNodeVec.size() - 1;
02482 while(kount >= 0)
02483 {
02484 int numkids = nlNodeVec[kount]->inumberOfChildren;
02485 if(numkids > 0)
02486 {
02487 for(int i = 0; i < numkids; i++)
02488 {
02489 nlNodeVec[kount]->m_mChildren[i] = (OSnLNode*)stackVec.back();
02490 stackVec.pop_back();
02491 }
02492 }
02493 int mtxkids = nlNodeVec[kount]->inumberOfMatrixChildren;
02494 if(mtxkids > 0)
02495 {
02496 for(int i = 0; i < mtxkids; i++)
02497 {
02498 nlNodeVec[kount]->m_mMatrixChildren[i] = (OSnLMNode*)stackVec.back();
02499 stackVec.pop_back();
02500 }
02501 }
02502 stackVec.push_back( nlNodeVec[kount]);
02503 kount--;
02504 }
02505 stackVec.clear();
02506 return (OSnLMNode*)nlNodeVec[ 0];
02507 }
02508
02509 OSnLMNode* OSnLMNode::createExpressionTreeFromPostfix(std::vector<ExprNode*> nlNodeVec)
02510 {
02511 std::vector<ExprNode*> stackVec;
02512 int kount = 0;
02513
02514 while(kount <= nlNodeVec.size() - 1)
02515 {
02516 int numMtxKids = nlNodeVec[kount]->inumberOfMatrixChildren;
02517 if (numMtxKids > 0)
02518 {
02519 for(int i = numMtxKids - 1; i >= 0; i--)
02520 {
02521 nlNodeVec[kount]->m_mMatrixChildren[i] = (OSnLMNode*)stackVec.back();
02522 stackVec.pop_back();
02523 }
02524 }
02525 int numkids = nlNodeVec[kount]->inumberOfChildren;
02526 if (numkids > 0)
02527 {
02528 for(int i = numkids - 1; i >= 0; i--)
02529 {
02530 nlNodeVec[kount]->m_mChildren[i] = (OSnLNode*)stackVec.back();
02531 stackVec.pop_back();
02532 }
02533 }
02534 stackVec.push_back( nlNodeVec[kount]);
02535 kount++;
02536 }
02537 stackVec.clear();
02538 return (OSnLMNode*)nlNodeVec[ kount - 1];
02539 }
02540
02541
02542 std::vector<ExprNode*> OSnLMNode::getPrefixFromExpressionTree()
02543 {
02544 std::vector<ExprNode*> prefixVector;
02545 return preOrderOSnLNodeTraversal( &prefixVector);
02546 }
02547
02548 std::vector<ExprNode*> OSnLMNode::preOrderOSnLNodeTraversal( std::vector<ExprNode*> *prefixVector)
02549 {
02550 (*prefixVector).push_back( (OSnLMNode*)this);
02551 if(inumberOfChildren > 0)
02552 {
02553 for(unsigned int i = 0; i < inumberOfChildren; i++)
02554 m_mChildren[i]->OSnLNode::preOrderOSnLNodeTraversal( prefixVector);
02555 }
02556 if(inumberOfMatrixChildren > 0)
02557 {
02558 for(unsigned int i = 0; i < inumberOfMatrixChildren; i++)
02559 m_mMatrixChildren[i]->OSnLMNode::preOrderOSnLNodeTraversal( prefixVector);
02560 }
02561 return *prefixVector;
02562 }
02563
02564 std::vector<ExprNode*> OSnLMNode::getPostfixFromExpressionTree( )
02565 {
02566 std::vector<ExprNode*> postfixVector;
02567 return postOrderOSnLNodeTraversal( &postfixVector);
02568 }
02569
02570
02571 std::vector<ExprNode*> OSnLMNode::postOrderOSnLNodeTraversal( std::vector<ExprNode*> *postfixVector)
02572 {
02573 if(inumberOfChildren > 0)
02574 {
02575 unsigned int i;
02576 for(i = 0; i < inumberOfChildren; i++)
02577 m_mChildren[i]->OSnLNode::postOrderOSnLNodeTraversal( postfixVector);
02578 }
02579 if(inumberOfMatrixChildren > 0)
02580 {
02581 unsigned int i;
02582 for(i = 0; i < inumberOfMatrixChildren; i++)
02583 m_mMatrixChildren[i]->OSnLMNode::postOrderOSnLNodeTraversal( postfixVector);
02584 }
02585 (*postfixVector).push_back( (OSnLMNode*)this);
02586 return *postfixVector;
02587 }
02588
02589 #if 0
02590 std::string OSnLMNode::getTokenNumber()
02591 {
02592 ostringstream outStr;
02593 outStr << inodeInt;
02594
02595
02596
02597 outStr << "[";
02598 outStr << inumberOfChildren ;
02599 outStr << "]";
02600
02601 return outStr.str();
02602 }
02603
02604
02605
02606
02607
02608
02609
02610
02611
02612
02613
02614
02615
02616
02617
02618
02619
02620
02621
02622
02623
02624
02625
02626
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638
02639
02640
02641
02642
02643
02644
02645
02646
02647
02648
02649
02650
02651
02652
02653
02654
02655
02656
02657
02658
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674
02675
02676
02677
02678
02679
02680
02681
02682
02683
02684
02685
02686
02687
02688
02689
02690
02691
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704
02705
02706
02707 std::string OSnLMNode::getNonlinearExpressionInXML()
02708 {
02709 ostringstream outStr, logStr;
02710 outStr << "<" ;
02711 outStr << this->getTokenName();
02712 #ifndef NDEBUG
02713 logStr << "nonlinear node " << this->getTokenName() << endl;
02714 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, logStr.str());
02715 #endif
02716 if(inumberOfChildren > 0)
02717 {
02718
02719 outStr << ">";
02720 }
02721 else
02722 {
02723
02724 outStr << "/>";
02725 }
02726 if(inumberOfChildren > 0)
02727 {
02728 for(unsigned int i = 0; i < inumberOfChildren; i++)
02729 {
02730 outStr << m_mChildren[i]->getNonlinearExpressionInXML();
02731 }
02732 }
02733 if(inumberOfChildren > 0)
02734
02735 {
02736 outStr << "</" ;
02737 outStr << this->getTokenName() ;
02738 outStr << ">" ;
02739 }
02740 return outStr.str();
02741 }
02742
02743
02744
02745 void OSnLNode::getVariableIndexMap(std::map<int, int> *varIdx)
02746 {
02747 unsigned int i;
02748 if(inodeInt != OS_VARIABLE)
02749 {
02750 for(i = 0; i < inumberOfChildren; i++)
02751 {
02752 m_mChildren[ i]->getVariableIndexMap( varIdx);
02753 }
02754
02755
02756 }
02757 }
02758 #endif
02759
02760 bool OSnLMNode::IsEqual(OSnLMNode *that)
02761 {
02762 #ifndef NDEBUG
02763 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLMNode");
02764 #endif
02765 if (this == NULL)
02766 {
02767 if (that == NULL)
02768 return true;
02769 else
02770 {
02771 #ifndef NDEBUG
02772 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
02773 "First object is NULL, second is not");
02774 #endif
02775 return false;
02776 }
02777 }
02778 else
02779 {
02780 if (that == NULL)
02781 {
02782 #ifndef NDEBUG
02783 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
02784 "Second object is NULL, first is not");
02785 #endif
02786 return false;
02787 }
02788 else
02789 {
02790 if (this->inumberOfChildren != that->inumberOfChildren)
02791 return false;
02792 if (this->inumberOfMatrixChildren != that->inumberOfMatrixChildren)
02793 return false;
02794 if (this->inodeInt != that->inodeInt)
02795 return false;
02796 if (this->inodeType != that->inodeType)
02797 return false;
02798
02799 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
02800 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
02801 return false;
02802
02803 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
02804 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
02805 return false;
02806
02807 return true;
02808 }
02809 }
02810 }
02811
02812 #if 0
02813 OSnLMNode* OSnLMNode::copyNodeAndDescendants()
02814 {
02815 OSnLMNode* ndcopy = cloneExprNode();
02816
02817 ndcopy->inumberOfChildren = inumberOfChildren;
02818 ndcopy->inumberOfMatrixChildren = inumberOfMatrixChildren;
02819 ndcopy->inodeInt = inodeInt;
02820 ndcopy->inodeType = inodeType;
02821
02822 if (inumberOfChildren > 0)
02823 {
02824
02825 for (int i=0; i < inumberOfChildren; i++)
02826 {
02827 ndcopy->m_mChildren[i] = m_mChildren[i]->(OSnLNode)copyNodeAndDescendants();
02828 }
02829 }
02830
02831 if (inumberOfMatrixChildren > 0)
02832 {
02833
02834 for (int i=0; i < inumberOfMatrixChildren; i++)
02835 {
02836 ndcopy->m_mMatrixChildren[i] = m_mMatrixChildren[i]->(OSnLMNode)copyNodeAndDescendants();
02837 }
02838 }
02839
02840 return ndcopy;
02841 }
02842 #endif
02843
02844
02845 OSnLMNodeMatrixPlus::OSnLMNodeMatrixPlus()
02846 {
02847 inumberOfChildren = 0;
02848 inumberOfMatrixChildren = 2;
02849 m_mChildren = NULL;
02850 m_mMatrixChildren = new OSnLMNode*[2];
02851 inodeInt = OS_MATRIX_PLUS;
02852 inodeType = 2;
02853 }
02854
02855 OSnLMNodeMatrixPlus::~OSnLMNodeMatrixPlus()
02856 {
02857 std::ostringstream outStr;
02858 #ifndef NDEBUG
02859 outStr << "inside OSnLMNodeMatrixPlus destructor" << endl;
02860 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
02861 #endif
02862 }
02863
02864 std::string OSnLMNodeMatrixPlus::getTokenName()
02865 {
02866 return "matrixPlus";
02867 }
02868
02869 OSnLMNode* OSnLMNodeMatrixPlus::cloneExprNode()
02870 {
02871 OSnLMNode *nlMNodePoint;
02872 nlMNodePoint = new OSnLMNodeMatrixPlus();
02873 return nlMNodePoint;
02874 }
02875
02876
02877
02878 OSnLMNodeMatrixSum::OSnLMNodeMatrixSum()
02879 {
02880 inumberOfChildren = 0;
02881 inumberOfMatrixChildren = 0;
02882 m_mChildren = NULL;
02883 m_mMatrixChildren = NULL;
02884 inodeInt = OS_MATRIX_SUM;
02885 inodeType = -1;
02886
02887
02888 }
02889
02890 OSnLMNodeMatrixSum::~OSnLMNodeMatrixSum()
02891 {
02892 std::ostringstream outStr;
02893 #ifndef NDEBUG
02894 outStr << "inside OSnLMNodeMatrixSum destructor" << endl;
02895 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
02896 #endif
02897 }
02898
02899 std::string OSnLMNodeMatrixSum::getTokenName()
02900 {
02901 return "matrixSum";
02902 }
02903
02904 OSnLMNode* OSnLMNodeMatrixSum::cloneExprNode()
02905 {
02906 OSnLMNode *nlMNodePoint;
02907 nlMNodePoint = new OSnLMNodeMatrixSum();
02908 return nlMNodePoint;
02909 }
02910
02911
02912
02913 OSnLMNodeMatrixProduct::OSnLMNodeMatrixProduct()
02914 {
02915 inumberOfChildren = 0;
02916 inumberOfMatrixChildren = 0;
02917 m_mChildren = NULL;
02918 m_mMatrixChildren = NULL;
02919 inodeInt = OS_MATRIX_PRODUCT;
02920 inodeType = -1;
02921 }
02922
02923
02924 OSnLMNodeMatrixProduct::~OSnLMNodeMatrixProduct()
02925 {
02926 #ifndef NDEBUG
02927 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "inside OSnLMNodeMatrixProduct destructor");
02928 #endif
02929 }
02930
02931 std::string OSnLMNodeMatrixProduct::getTokenName()
02932 {
02933 return "matrixProduct";
02934 }
02935
02936 #if 0
02937 double OSnLMNodeMatrixProduct::calculateFunction(double *x)
02938 {
02939
02940 m_dFunctionValue = 1.0;
02941 unsigned int i;
02942 for(i = 0; i < inumberOfChildren; i++)
02943 {
02944 m_dFunctionValue = m_dFunctionValue*m_mChildren[i]->calculateFunction(x);
02945 }
02946 return m_dFunctionValue;
02947 }
02948
02949
02950 ADdouble OSnLMNodeMatrixProduct::constructADTape(std::map<int, int> *ADIdx, ADvector *XAD)
02951 {
02952 m_ADTape = 1.0;
02953 unsigned int i;
02954 for(i = 0; i < inumberOfChildren; i++)
02955 {
02956 m_ADTape = m_ADTape*m_mChildren[i]->constructADTape( ADIdx, XAD);
02957 }
02958 return m_ADTape;
02959 }
02960 #endif
02961
02962 OSnLMNode* OSnLMNodeMatrixProduct::cloneExprNode()
02963 {
02964 OSnLMNode *nlMNodePoint;
02965 nlMNodePoint = new OSnLMNodeMatrixProduct();
02966 return nlMNodePoint;
02967 }
02968
02969
02970
02971 OSnLMNodeMatrixMinus::OSnLMNodeMatrixMinus()
02972 {
02973 inumberOfChildren = 0;
02974 inumberOfMatrixChildren = 2;
02975 m_mChildren = NULL;
02976 m_mMatrixChildren = new OSnLMNode*[2];
02977 inodeInt = OS_MATRIX_MINUS;
02978 inodeType = 2;
02979 }
02980
02981 OSnLMNodeMatrixMinus::~OSnLMNodeMatrixMinus()
02982 {
02983 std::ostringstream outStr;
02984 #ifndef NDEBUG
02985 outStr << "inside OSnLMNodeMatrixMinus destructor" << endl;
02986 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
02987 #endif
02988 }
02989
02990 std::string OSnLMNodeMatrixMinus::getTokenName()
02991 {
02992 return "matrixMinus";
02993 }
02994
02995 OSnLMNode* OSnLMNodeMatrixMinus::cloneExprNode()
02996 {
02997 OSnLMNode *nlMNodePoint;
02998 nlMNodePoint = new OSnLMNodeMatrixMinus();
02999 return nlMNodePoint;
03000 }
03001
03002
03003 OSnLMNodeMatrixNegate::OSnLMNodeMatrixNegate()
03004 {
03005 inumberOfChildren = 0;
03006 inumberOfMatrixChildren = 1;
03007 m_mChildren = NULL;
03008 m_mMatrixChildren = new OSnLMNode*[1];
03009 inodeInt = OS_MATRIX_NEGATE;
03010 inodeType = 1;
03011 }
03012
03013 OSnLMNodeMatrixNegate::~OSnLMNodeMatrixNegate()
03014 {
03015 std::ostringstream outStr;
03016 #ifndef NDEBUG
03017 outStr << "inside OSnLMNodeMatrixNegate destructor" << endl;
03018 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03019 #endif
03020 }
03021
03022 std::string OSnLMNodeMatrixNegate::getTokenName()
03023 {
03024 return "matrixNegate";
03025 }
03026
03027 OSnLMNode* OSnLMNodeMatrixNegate::cloneExprNode()
03028 {
03029 OSnLMNode *nlMNodePoint;
03030 nlMNodePoint = new OSnLMNodeMatrixNegate();
03031 return nlMNodePoint;
03032 }
03033
03034
03035 OSnLMNodeMatrixTimes::OSnLMNodeMatrixTimes()
03036 {
03037 inumberOfChildren = 0;
03038 inumberOfMatrixChildren = 2;
03039 m_mChildren = NULL;
03040 m_mMatrixChildren = new OSnLMNode*[2];
03041 inodeInt = OS_MATRIX_TIMES;
03042 inodeType = 2;
03043 }
03044
03045 OSnLMNodeMatrixTimes::~OSnLMNodeMatrixTimes()
03046 {
03047 std::ostringstream outStr;
03048 #ifndef NDEBUG
03049 outStr << "inside OSnLMNodeMatrixTimes destructor" << endl;
03050 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03051 #endif
03052 }
03053
03054 std::string OSnLMNodeMatrixTimes::getTokenName()
03055 {
03056 return "matrixTimes";
03057 }
03058
03059 OSnLMNode* OSnLMNodeMatrixTimes::cloneExprNode()
03060 {
03061 OSnLMNode *nlMNodePoint;
03062 nlMNodePoint = new OSnLMNodeMatrixTimes();
03063 return nlMNodePoint;
03064 }
03065
03066
03067 OSnLMNodeMatrixInverse::OSnLMNodeMatrixInverse()
03068 {
03069 inumberOfChildren = 0;
03070 inumberOfMatrixChildren = 1;
03071 m_mChildren = NULL;
03072 m_mMatrixChildren = new OSnLMNode*[1];
03073 inodeInt = OS_MATRIX_INVERSE;
03074 inodeType = 1;
03075 }
03076
03077 OSnLMNodeMatrixInverse::~OSnLMNodeMatrixInverse()
03078 {
03079 std::ostringstream outStr;
03080 #ifndef NDEBUG
03081 outStr << "inside OSnLMNodeMatrixInverse destructor" << endl;
03082 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03083 #endif
03084 }
03085
03086 std::string OSnLMNodeMatrixInverse::getTokenName()
03087 {
03088 return "matrixInverse";
03089 }
03090
03091 OSnLMNode* OSnLMNodeMatrixInverse::cloneExprNode()
03092 {
03093 OSnLMNode *nlMNodePoint;
03094 nlMNodePoint = new OSnLMNodeMatrixInverse();
03095 return nlMNodePoint;
03096 }
03097
03098
03099
03100 OSnLMNodeMatrixTranspose::OSnLMNodeMatrixTranspose()
03101 {
03102 inumberOfChildren = 0;
03103 inumberOfMatrixChildren = 1;
03104 m_mChildren = NULL;
03105 m_mMatrixChildren = new OSnLMNode*[1];
03106 inodeInt = OS_MATRIX_TRANSPOSE;
03107 inodeType = 1;
03108 }
03109
03110 OSnLMNodeMatrixTranspose::~OSnLMNodeMatrixTranspose()
03111 {
03112 std::ostringstream outStr;
03113 #ifndef NDEBUG
03114 outStr << "inside OSnLMNodeMatrixTranspose destructor" << endl;
03115 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03116 #endif
03117 }
03118
03119 std::string OSnLMNodeMatrixTranspose::getTokenName()
03120 {
03121 return "matrixTranspose";
03122 }
03123
03124 OSnLMNode* OSnLMNodeMatrixTranspose::cloneExprNode()
03125 {
03126 OSnLMNode *nlMNodePoint;
03127 nlMNodePoint = new OSnLMNodeMatrixTranspose();
03128 return nlMNodePoint;
03129 }
03130
03131
03132 OSnLMNodeMatrixScalarTimes::OSnLMNodeMatrixScalarTimes()
03133 {
03134 inumberOfChildren = 1;
03135 inumberOfMatrixChildren = 1;
03136 m_mChildren = new OSnLNode*[1];
03137 m_mMatrixChildren = new OSnLMNode*[1];
03138 inodeInt = OS_MATRIX_SCALARTIMES;
03139 inodeType = 1;
03140 }
03141
03142 OSnLMNodeMatrixScalarTimes::~OSnLMNodeMatrixScalarTimes()
03143 {
03144 std::ostringstream outStr;
03145 #ifndef NDEBUG
03146 outStr << "inside OSnLMNodeMatrixScalarTimes destructor" << endl;
03147 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03148 #endif
03149 }
03150
03151 std::string OSnLMNodeMatrixScalarTimes::getTokenName()
03152 {
03153 return "matrixScalarTimes";
03154 }
03155
03156 OSnLMNode* OSnLMNodeMatrixScalarTimes::cloneExprNode()
03157 {
03158 OSnLMNode *nlMNodePoint;
03159 nlMNodePoint = new OSnLMNodeMatrixScalarTimes();
03160 return nlMNodePoint;
03161 }
03162
03163
03164 OSnLMNodeMatrixDotTimes::OSnLMNodeMatrixDotTimes()
03165 {
03166 inumberOfChildren = 0;
03167 inumberOfMatrixChildren = 2;
03168 m_mChildren = NULL;
03169 m_mMatrixChildren = new OSnLMNode*[2];
03170 inodeInt = OS_MATRIX_DOTTIMES;
03171 inodeType = 2;
03172 }
03173
03174 OSnLMNodeMatrixDotTimes::~OSnLMNodeMatrixDotTimes()
03175 {
03176 std::ostringstream outStr;
03177 #ifndef NDEBUG
03178 outStr << "inside OSnLMNodeMatrixDotTimes destructor" << endl;
03179 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03180 #endif
03181 }
03182
03183 std::string OSnLMNodeMatrixDotTimes::getTokenName()
03184 {
03185 return "matrixDotTimes";
03186 }
03187
03188 OSnLMNode* OSnLMNodeMatrixDotTimes::cloneExprNode()
03189 {
03190 OSnLMNode *nlMNodePoint;
03191 nlMNodePoint = new OSnLMNodeMatrixDotTimes();
03192 return nlMNodePoint;
03193 }
03194
03195
03196
03197 OSnLMNodeIdentityMatrix::OSnLMNodeIdentityMatrix()
03198 {
03199 inumberOfChildren = 1;
03200 inumberOfMatrixChildren = 0;
03201 m_mChildren = new OSnLNode*[1];
03202 m_mMatrixChildren = NULL;
03203 inodeInt = OS_IDENTITY_MATRIX;
03204 inodeType = -1;
03205 }
03206
03207 OSnLMNodeIdentityMatrix::~OSnLMNodeIdentityMatrix()
03208 {
03209 std::ostringstream outStr;
03210 #ifndef NDEBUG
03211 outStr << "inside OSnLMNodeIdentityMatrix destructor" << endl;
03212 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03213 #endif
03214 }
03215
03216 std::string OSnLMNodeIdentityMatrix::getTokenName()
03217 {
03218 return "identityMatrix";
03219 }
03220
03221 OSnLMNode* OSnLMNodeIdentityMatrix::cloneExprNode()
03222 {
03223 OSnLMNode *nlMNodePoint;
03224 nlMNodePoint = new OSnLMNodeIdentityMatrix();
03225 return nlMNodePoint;
03226 }
03227
03228
03229
03230 OSnLMNodeMatrixLowerTriangle::OSnLMNodeMatrixLowerTriangle()
03231 {
03232 inumberOfChildren = 0;
03233 inumberOfMatrixChildren = 1;
03234 m_mChildren = NULL;
03235 m_mMatrixChildren = new OSnLMNode*[1];
03236 inodeInt = OS_MATRIX_LOWERTRIANGLE;
03237 inodeType = 1;
03238 includeDiagonal = true;
03239 }
03240
03241 OSnLMNodeMatrixLowerTriangle::~OSnLMNodeMatrixLowerTriangle()
03242 {
03243 std::ostringstream outStr;
03244 #ifndef NDEBUG
03245 outStr << "inside OSnLMNodeMatrixLowerTriangle destructor" << endl;
03246 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03247 #endif
03248 }
03249
03250 std::string OSnLMNodeMatrixLowerTriangle::getTokenName()
03251 {
03252 return "matrixLowerTriangle";
03253 }
03254
03255 OSnLMNode* OSnLMNodeMatrixLowerTriangle::cloneExprNode()
03256 {
03257 OSnLMNode *nlMNodePoint;
03258 nlMNodePoint = new OSnLMNodeMatrixLowerTriangle();
03259 return nlMNodePoint;
03260 }
03261
03262 OSnLMNode* OSnLMNodeMatrixLowerTriangle::copyNodeAndDescendants()
03263 {
03264 #ifndef NDEBUG
03265 ostringstream outStr;
03266 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
03267 outStr << " (" << this->getTokenName() << ")" << std::endl;
03268 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03269 #endif
03270
03271 OSnLMNodeMatrixLowerTriangle* ndcopy = (OSnLMNodeMatrixLowerTriangle*)cloneExprNode();
03272 ndcopy->inumberOfChildren = inumberOfChildren;
03273 ndcopy->inumberOfMatrixChildren = inumberOfMatrixChildren;
03274 ndcopy->inodeInt = inodeInt;
03275 ndcopy->inodeType = inodeType;
03276 ndcopy->includeDiagonal = includeDiagonal;
03277
03278 if (inumberOfChildren > 0)
03279 {
03280 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
03281 for (int i=0; i < inumberOfChildren; i++)
03282 {
03283 ndcopy->m_mChildren[i] = m_mChildren[i]->copyNodeAndDescendants();
03284 }
03285 }
03286
03287 if (inumberOfMatrixChildren > 0)
03288 {
03289 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
03290 for (int i=0; i < inumberOfMatrixChildren; i++)
03291 {
03292 ndcopy->m_mMatrixChildren[i] = m_mMatrixChildren[i]->copyNodeAndDescendants();
03293 }
03294 }
03295
03296 return ndcopy;
03297 }
03298
03299 std::string OSnLMNodeMatrixLowerTriangle::getNonlinearExpressionInXML()
03300 {
03301 ostringstream outStr;
03302 outStr << "<matrixLowerTriangle";
03303 if (includeDiagonal == false)
03304 outStr << " includeDiagonal=\"false\"";
03305 outStr << ">" << std::endl;
03306
03307 outStr << m_mMatrixChildren[0]->getNonlinearExpressionInXML();
03308
03309 outStr << "</matrixLowerTriangle>";
03310 return outStr.str();
03311 }
03312
03313 bool OSnLMNodeMatrixLowerTriangle::IsEqual(OSnLMNodeMatrixLowerTriangle *that)
03314 {
03315 #ifndef NDEBUG
03316 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLMNodeMatrixLowerTriangle");
03317 #endif
03318 if (this == NULL)
03319 {
03320 if (that == NULL)
03321 return true;
03322 else
03323 {
03324 #ifndef NDEBUG
03325 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
03326 "First object is NULL, second is not");
03327 #endif
03328 return false;
03329 }
03330 }
03331 else
03332 {
03333 if (that == NULL)
03334 {
03335 #ifndef NDEBUG
03336 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
03337 "Second object is NULL, first is not");
03338 #endif
03339 return false;
03340 }
03341 else
03342 {
03343 if (this->inodeInt != that->inodeInt)
03344 return false;
03345 if (this->inodeType != that->inodeType)
03346 return false;
03347 if (this->inumberOfChildren != that->inumberOfChildren)
03348 return false;
03349 if (this->inumberOfMatrixChildren != that->inumberOfMatrixChildren)
03350 return false;
03351
03352 if (this->includeDiagonal != that->includeDiagonal)
03353 return false;
03354
03355 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
03356 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
03357 return false;
03358
03359 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
03360 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
03361 return false;
03362
03363 return true;
03364 }
03365 }
03366 }
03367
03368
03369
03370
03371 OSnLMNodeMatrixUpperTriangle::OSnLMNodeMatrixUpperTriangle()
03372 {
03373 inumberOfChildren = 0;
03374 inumberOfMatrixChildren = 1;
03375 m_mChildren = NULL;
03376 m_mMatrixChildren = new OSnLMNode*[1];
03377 inodeInt = OS_MATRIX_UPPERTRIANGLE;
03378 inodeType = 1;
03379
03380 includeDiagonal = true;
03381 }
03382
03383 OSnLMNodeMatrixUpperTriangle::~OSnLMNodeMatrixUpperTriangle()
03384 {
03385 std::ostringstream outStr;
03386 #ifndef NDEBUG
03387 outStr << "inside OSnLMNodeMatrixUpperTriangle destructor" << endl;
03388 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03389 #endif
03390 }
03391
03392 std::string OSnLMNodeMatrixUpperTriangle::getNonlinearExpressionInXML()
03393 {
03394 ostringstream outStr;
03395 outStr << "<matrixUpperTriangle";
03396 if (includeDiagonal == false)
03397 outStr << " includeDiagonal=\"false\"";
03398 outStr << ">" << std::endl;
03399
03400 outStr << m_mMatrixChildren[0]->getNonlinearExpressionInXML();
03401
03402 outStr << "</matrixUpperTriangle>";
03403 return outStr.str();
03404 }
03405
03406 std::string OSnLMNodeMatrixUpperTriangle::getTokenName()
03407 {
03408 return "matrixUpperTriangle";
03409 }
03410
03411 OSnLMNode* OSnLMNodeMatrixUpperTriangle::cloneExprNode()
03412 {
03413 OSnLMNode *nlMNodePoint;
03414 nlMNodePoint = new OSnLMNodeMatrixUpperTriangle();
03415 return nlMNodePoint;
03416 }
03417
03418 OSnLMNode* OSnLMNodeMatrixUpperTriangle::copyNodeAndDescendants()
03419 {
03420 #ifndef NDEBUG
03421 ostringstream outStr;
03422 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
03423 outStr << " (" << this->getTokenName() << ")" << std::endl;
03424 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03425 #endif
03426
03427 OSnLMNodeMatrixUpperTriangle* ndcopy = (OSnLMNodeMatrixUpperTriangle*)cloneExprNode();
03428 ndcopy->inumberOfChildren = inumberOfChildren;
03429 ndcopy->inumberOfMatrixChildren = inumberOfMatrixChildren;
03430 ndcopy->inodeInt = inodeInt;
03431 ndcopy->inodeType = inodeType;
03432 ndcopy->includeDiagonal = includeDiagonal;
03433
03434 if (inumberOfChildren > 0)
03435 {
03436 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
03437 for (int i=0; i < inumberOfChildren; i++)
03438 {
03439 ndcopy->m_mChildren[i] = m_mChildren[i]->copyNodeAndDescendants();
03440 }
03441 }
03442
03443 if (inumberOfMatrixChildren > 0)
03444 {
03445 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
03446 for (int i=0; i < inumberOfMatrixChildren; i++)
03447 {
03448 ndcopy->m_mMatrixChildren[i] = m_mMatrixChildren[i]->copyNodeAndDescendants();
03449 }
03450 }
03451
03452 return ndcopy;
03453 }
03454
03455 bool OSnLMNodeMatrixUpperTriangle::IsEqual(OSnLMNodeMatrixUpperTriangle *that)
03456 {
03457 #ifndef NDEBUG
03458 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLMNodeMatrixUpperTriangle");
03459 #endif
03460 if (this == NULL)
03461 {
03462 if (that == NULL)
03463 return true;
03464 else
03465 {
03466 #ifndef NDEBUG
03467 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
03468 "First object is NULL, second is not");
03469 #endif
03470 return false;
03471 }
03472 }
03473 else
03474 {
03475 if (that == NULL)
03476 {
03477 #ifndef NDEBUG
03478 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
03479 "Second object is NULL, first is not");
03480 #endif
03481 return false;
03482 }
03483 else
03484 {
03485 if (this->inodeInt != that->inodeInt)
03486 return false;
03487 if (this->inodeType != that->inodeType)
03488 return false;
03489 if (this->inumberOfChildren != that->inumberOfChildren)
03490 return false;
03491 if (this->inumberOfMatrixChildren != that->inumberOfMatrixChildren)
03492 return false;
03493
03494 if (this->includeDiagonal != that->includeDiagonal)
03495 return false;
03496
03497 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
03498 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
03499 return false;
03500
03501 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
03502 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
03503 return false;
03504
03505 return true;
03506 }
03507 }
03508 }
03509
03510
03511
03512 OSnLMNodeMatrixDiagonal::OSnLMNodeMatrixDiagonal()
03513 {
03514 inumberOfChildren = 0;
03515 inumberOfMatrixChildren = 1;
03516 m_mChildren = NULL;
03517 m_mMatrixChildren = new OSnLMNode*[1];
03518 inodeInt = OS_MATRIX_DIAGONAL;
03519 inodeType = 1;
03520 }
03521
03522 OSnLMNodeMatrixDiagonal::~OSnLMNodeMatrixDiagonal()
03523 {
03524 std::ostringstream outStr;
03525 #ifndef NDEBUG
03526 outStr << "inside OSnLMNodeMatrixDiagonal destructor" << endl;
03527 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03528 #endif
03529 }
03530
03531 std::string OSnLMNodeMatrixDiagonal::getTokenName()
03532 {
03533 return "matrixDiagonal";
03534 }
03535
03536 OSnLMNode* OSnLMNodeMatrixDiagonal::cloneExprNode()
03537 {
03538 OSnLMNode *nlMNodePoint;
03539 nlMNodePoint = new OSnLMNodeMatrixDiagonal();
03540 return nlMNodePoint;
03541 }
03542
03543
03544
03545 OSnLMNodeDiagonalMatrixFromVector::OSnLMNodeDiagonalMatrixFromVector()
03546 {
03547 inumberOfChildren = 0;
03548 inumberOfMatrixChildren = 1;
03549 m_mChildren = NULL;
03550 m_mMatrixChildren = new OSnLMNode*[1];
03551 inodeInt = OS_DIAGONAL_MATRIX_FROM_VECTOR;
03552 inodeType = -1;
03553 }
03554
03555 OSnLMNodeDiagonalMatrixFromVector::~OSnLMNodeDiagonalMatrixFromVector()
03556 {
03557 std::ostringstream outStr;
03558 #ifndef NDEBUG
03559 outStr << "inside OSnLMNodeDiagonalMatrixFromVector destructor" << endl;
03560 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03561 #endif
03562 }
03563
03564 std::string OSnLMNodeDiagonalMatrixFromVector::getTokenName()
03565 {
03566 return "diagonalMatrixFromVector";
03567 }
03568
03569 OSnLMNode* OSnLMNodeDiagonalMatrixFromVector::cloneExprNode()
03570 {
03571 OSnLMNode *nlMNodePoint;
03572 nlMNodePoint = new OSnLMNodeDiagonalMatrixFromVector();
03573 return nlMNodePoint;
03574 }
03575
03576
03577
03578 OSnLMNodeMatrixSubmatrixAt::OSnLMNodeMatrixSubmatrixAt()
03579 {
03580 inumberOfChildren = 4;
03581 inumberOfMatrixChildren = 1;
03582 m_mChildren = new OSnLNode*[4];
03583 m_mMatrixChildren = new OSnLMNode*[1];
03584 inodeInt = OS_MATRIX_SUBMATRIX_AT;
03585 inodeType = 1;
03586 }
03587
03588 OSnLMNodeMatrixSubmatrixAt::~OSnLMNodeMatrixSubmatrixAt()
03589 {
03590 std::ostringstream outStr;
03591 #ifndef NDEBUG
03592 outStr << "inside OSnLMNodeMatrixSubmatrixAt destructor" << endl;
03593 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03594 #endif
03595 }
03596
03597 std::string OSnLMNodeMatrixSubmatrixAt::getTokenName()
03598 {
03599 return "matrixSubmatrixAt";
03600 }
03601
03602 OSnLMNode* OSnLMNodeMatrixSubmatrixAt::cloneExprNode()
03603 {
03604 OSnLMNode *nlMNodePoint;
03605 nlMNodePoint = new OSnLMNodeMatrixSubmatrixAt();
03606 return nlMNodePoint;
03607 }
03608
03609
03610
03611 OSnLMNodeMatrixReference::OSnLMNodeMatrixReference():
03612 idx(-1)
03613 {
03614 inumberOfChildren = 0;
03615 inumberOfMatrixChildren = 0;
03616 m_mChildren = NULL;
03617 m_mMatrixChildren = NULL;
03618 inodeInt = OS_MATRIX_REFERENCE;
03619 inodeType = -1;
03620 }
03621
03622 OSnLMNodeMatrixReference::~OSnLMNodeMatrixReference()
03623 {
03624 std::ostringstream outStr;
03625 #ifndef NDEBUG
03626 outStr << "inside OSnLMNodeMatrixReference destructor" << endl;
03627 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03628 #endif
03629 }
03630
03631 std::string OSnLMNodeMatrixReference::getTokenNumber()
03632 {
03633 ostringstream outStr;
03634 outStr << inodeInt;
03635 outStr << "[";
03636 outStr << inumberOfChildren;
03637 outStr << "]";
03638 outStr << ":";
03639 outStr << idx;
03640 outStr << ":";
03641 return outStr.str();
03642 }
03643
03644 std::string OSnLMNodeMatrixReference::getTokenName()
03645 {
03646 return "matrixReference";
03647 }
03648
03649
03650 std::string OSnLMNodeMatrixReference::getNonlinearExpressionInXML()
03651 {
03652 ostringstream outStr;
03653 outStr << "<matrixReference idx=\"" << idx << "\"/>" << std::endl;
03654 return outStr.str();
03655 }
03656
03657 OSnLMNode* OSnLMNodeMatrixReference::cloneExprNode()
03658 {
03659 OSnLMNode *nlMNodePoint;
03660 nlMNodePoint = new OSnLMNodeMatrixReference();
03661 return nlMNodePoint;
03662 }
03663
03664 OSnLMNode* OSnLMNodeMatrixReference::copyNodeAndDescendants()
03665 {
03666 #ifndef NDEBUG
03667 ostringstream outStr;
03668 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
03669 outStr << " (" << this->getTokenName() << ")" << std::endl;
03670 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03671 #endif
03672
03673 OSnLMNodeMatrixReference* ndcopy = (OSnLMNodeMatrixReference*)cloneExprNode();
03674 ndcopy->inumberOfChildren = inumberOfChildren;
03675 ndcopy->inumberOfMatrixChildren = inumberOfMatrixChildren;
03676 ndcopy->inodeInt = inodeInt;
03677 ndcopy->inodeType = inodeType;
03678 ndcopy->idx = idx;
03679
03680 if (inumberOfChildren > 0)
03681 {
03682 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
03683 for (int i=0; i < inumberOfChildren; i++)
03684 {
03685 ndcopy->m_mChildren[i] = m_mChildren[i]->copyNodeAndDescendants();
03686 }
03687 }
03688
03689 if (inumberOfMatrixChildren > 0)
03690 {
03691 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
03692 for (int i=0; i < inumberOfMatrixChildren; i++)
03693 {
03694 ndcopy->m_mMatrixChildren[i] = m_mMatrixChildren[i]->copyNodeAndDescendants();
03695 }
03696 }
03697
03698 return ndcopy;
03699 }
03700
03701 bool OSnLMNodeMatrixReference::IsEqual(OSnLMNodeMatrixReference *that)
03702 {
03703 #ifndef NDEBUG
03704 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLMNodeMatrixReference");
03705 #endif
03706 if (this == NULL)
03707 {
03708 if (that == NULL)
03709 return true;
03710 else
03711 {
03712 #ifndef NDEBUG
03713 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
03714 "First object is NULL, second is not");
03715 #endif
03716 return false;
03717 }
03718 }
03719 else
03720 {
03721 if (that == NULL)
03722 {
03723 #ifndef NDEBUG
03724 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
03725 "Second object is NULL, first is not");
03726 #endif
03727 return false;
03728 }
03729 else
03730 {
03731 if (this->inodeInt != that->inodeInt)
03732 return false;
03733 if (this->inodeType != that->inodeType)
03734 return false;
03735 if (this->inumberOfChildren != that->inumberOfChildren)
03736 return false;
03737 if (this->inumberOfMatrixChildren != that->inumberOfMatrixChildren)
03738 return false;
03739
03740 if (this->idx != that->idx)
03741 return false;
03742
03743 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
03744 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
03745 return false;
03746
03747 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
03748 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
03749 return false;
03750
03751 return true;
03752 }
03753 }
03754 }
03755
03756
03757
03758 OSnLMNodeMatrixVar::OSnLMNodeMatrixVar():
03759 idx(-1)
03760 {
03761 inumberOfChildren = 0;
03762 inumberOfMatrixChildren = 0;
03763 m_mChildren = NULL;
03764 m_mMatrixChildren = NULL;
03765 inodeInt = OS_MATRIX_VAR;
03766 inodeType = -1;
03767 }
03768
03769 OSnLMNodeMatrixVar::~OSnLMNodeMatrixVar()
03770 {
03771 std::ostringstream outStr;
03772 #ifndef NDEBUG
03773 outStr << "inside OSnLMNodeMatrixVar destructor" << endl;
03774 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03775 #endif
03776 }
03777
03778 std::string OSnLMNodeMatrixVar::getTokenNumber()
03779 {
03780 ostringstream outStr;
03781 outStr << inodeInt;
03782 outStr << "[";
03783 outStr << inumberOfChildren;
03784 outStr << "]";
03785 outStr << ":";
03786 outStr << idx;
03787 outStr << ":";
03788 return outStr.str();
03789 }
03790
03791 std::string OSnLMNodeMatrixVar::getTokenName()
03792 {
03793 return "matrixVar";
03794 }
03795
03796
03797 std::string OSnLMNodeMatrixVar::getNonlinearExpressionInXML()
03798 {
03799 ostringstream outStr;
03800
03801 outStr << "<matrixVar idx=\"" << idx << "\"/>" << std::endl;
03802 return outStr.str();
03803 }
03804
03805 #if 0
03806 double OSnLMNodeMatrixVar::calculateFunction(double *x)
03807 {
03808 m_dFunctionValue = coef*x[idx];
03809 return m_dFunctionValue;
03810 }
03811
03812 ADdouble OSnLMNodeMatrixVar::constructADTape(std::map<int, int> *varIdx, ADvector *XAD)
03813 {
03814 m_ADTape = coef;
03815 m_ADTape = coef*(*XAD)[ (*varIdx)[ idx] ];
03816 return m_ADTape;
03817 }
03818
03819
03820 void OSnLMNodeMatrixVar::getVariableIndexMap(std::map<int, int> *varIdx)
03821 {
03822 int numVars;
03823 if( (*varIdx).find( idx) != (*varIdx).end() )
03824 {
03825
03826 }
03827 else
03828 {
03829
03830 numVars = (*varIdx).size();
03831
03832 (*varIdx)[ idx] = numVars;
03833 }
03834
03835 }
03836 #endif
03837
03838
03839 OSnLMNode* OSnLMNodeMatrixVar::cloneExprNode()
03840 {
03841 OSnLMNode *nlMNodePoint;
03842 nlMNodePoint = new OSnLMNodeMatrixVar();
03843 return nlMNodePoint;
03844 }
03845
03846 OSnLMNode* OSnLMNodeMatrixVar::copyNodeAndDescendants()
03847 {
03848 #ifndef NDEBUG
03849 ostringstream outStr;
03850 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
03851 outStr << " (" << this->getTokenName() << ")" << std::endl;
03852 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03853 #endif
03854
03855 OSnLMNodeMatrixVar* ndcopy = (OSnLMNodeMatrixVar*)cloneExprNode();
03856 ndcopy->inumberOfChildren = inumberOfChildren;
03857 ndcopy->inumberOfMatrixChildren = inumberOfMatrixChildren;
03858 ndcopy->inodeInt = inodeInt;
03859 ndcopy->inodeType = inodeType;
03860 ndcopy->idx = idx;
03861
03862 if (inumberOfChildren > 0)
03863 {
03864 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
03865 for (int i=0; i < inumberOfChildren; i++)
03866 {
03867 ndcopy->m_mChildren[i] = m_mChildren[i]->copyNodeAndDescendants();
03868 }
03869 }
03870
03871 if (inumberOfMatrixChildren > 0)
03872 {
03873 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
03874 for (int i=0; i < inumberOfMatrixChildren; i++)
03875 {
03876 ndcopy->m_mMatrixChildren[i] = m_mMatrixChildren[i]->copyNodeAndDescendants();
03877 }
03878 }
03879
03880 return ndcopy;
03881 }
03882
03883 bool OSnLMNodeMatrixVar::IsEqual(OSnLMNodeMatrixVar *that)
03884 {
03885 #ifndef NDEBUG
03886 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLMNodeMatrixVar");
03887 #endif
03888 if (this == NULL)
03889 {
03890 if (that == NULL)
03891 return true;
03892 else
03893 {
03894 #ifndef NDEBUG
03895 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
03896 "First object is NULL, second is not");
03897 #endif
03898 return false;
03899 }
03900 }
03901 else
03902 {
03903 if (that == NULL)
03904 {
03905 #ifndef NDEBUG
03906 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
03907 "Second object is NULL, first is not");
03908 #endif
03909 return false;
03910 }
03911 else
03912 {
03913 if (this->inodeInt != that->inodeInt)
03914 return false;
03915 if (this->inodeType != that->inodeType)
03916 return false;
03917 if (this->inumberOfChildren != that->inumberOfChildren)
03918 return false;
03919 if (this->inumberOfMatrixChildren != that->inumberOfMatrixChildren)
03920 return false;
03921
03922 if (this->idx != that->idx)
03923 return false;
03924
03925 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
03926 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
03927 return false;
03928
03929 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
03930 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
03931 return false;
03932
03933 return true;
03934 }
03935 }
03936 }
03937
03938
03939
03940 OSnLMNodeMatrixObj::OSnLMNodeMatrixObj():
03941 idx(-1)
03942 {
03943 inumberOfChildren = 0;
03944 inumberOfMatrixChildren = 0;
03945 m_mChildren = NULL;
03946 m_mMatrixChildren = NULL;
03947 inodeInt = OS_MATRIX_OBJ;
03948 inodeType = -1;
03949 }
03950
03951 OSnLMNodeMatrixObj::~OSnLMNodeMatrixObj()
03952 {
03953 std::ostringstream outStr;
03954 #ifndef NDEBUG
03955 outStr << "inside OSnLMNodeMatrixObj destructor" << endl;
03956 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
03957 #endif
03958 }
03959
03960 std::string OSnLMNodeMatrixObj::getTokenNumber()
03961 {
03962 ostringstream outStr;
03963 outStr << inodeInt;
03964 outStr << "[";
03965 outStr << inumberOfChildren;
03966 outStr << "]";
03967 outStr << ":";
03968 outStr << idx;
03969 outStr << ":";
03970 return outStr.str();
03971 }
03972
03973 std::string OSnLMNodeMatrixObj::getTokenName()
03974 {
03975 return "matrixObj";
03976 }
03977
03978
03979 std::string OSnLMNodeMatrixObj::getNonlinearExpressionInXML()
03980 {
03981 ostringstream outStr;
03982 outStr << "<matrixObj idx=\"" << idx << "\"/>" << std::endl;
03983 return outStr.str();
03984 }
03985
03986 #if 0
03987 double OSnLMNodeMatrixObj::calculateFunction(double *x)
03988 {
03989 m_dFunctionValue = coef*x[idx];
03990 return m_dFunctionValue;
03991 }
03992
03993 ADdouble OSnLMNodeMatrixObj::constructADTape(std::map<int, int> *varIdx, ADvector *XAD)
03994 {
03995 m_ADTape = coef;
03996 m_ADTape = coef*(*XAD)[ (*varIdx)[ idx] ];
03997 return m_ADTape;
03998 }
03999
04000 void OSnLMNodeMatrixObj::getVariableIndexMap(std::map<int, int> *varIdx)
04001 {
04002 int numVars;
04003 if( (*varIdx).find( idx) != (*varIdx).end() )
04004 {
04005
04006 }
04007 else
04008 {
04009
04010 numVars = (*varIdx).size();
04011
04012 (*varIdx)[ idx] = numVars;
04013 }
04014
04015 }
04016 #endif
04017
04018 OSnLMNode* OSnLMNodeMatrixObj::cloneExprNode()
04019 {
04020 OSnLMNode *nlMNodePoint;
04021 nlMNodePoint = new OSnLMNodeMatrixObj();
04022 return nlMNodePoint;
04023 }
04024
04025 OSnLMNode* OSnLMNodeMatrixObj::copyNodeAndDescendants()
04026 {
04027 #ifndef NDEBUG
04028 ostringstream outStr;
04029 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
04030 outStr << " (" << this->getTokenName() << ")" << std::endl;
04031 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
04032 #endif
04033
04034 OSnLMNodeMatrixObj* ndcopy = (OSnLMNodeMatrixObj*)cloneExprNode();
04035 ndcopy->inumberOfChildren = inumberOfChildren;
04036 ndcopy->inumberOfMatrixChildren = inumberOfMatrixChildren;
04037 ndcopy->inodeInt = inodeInt;
04038 ndcopy->inodeType = inodeType;
04039 ndcopy->idx = idx;
04040
04041 if (inumberOfChildren > 0)
04042 {
04043 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
04044 for (int i=0; i < inumberOfChildren; i++)
04045 {
04046 ndcopy->m_mChildren[i] = m_mChildren[i]->copyNodeAndDescendants();
04047 }
04048 }
04049
04050 if (inumberOfMatrixChildren > 0)
04051 {
04052 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
04053 for (int i=0; i < inumberOfMatrixChildren; i++)
04054 {
04055 ndcopy->m_mMatrixChildren[i] = m_mMatrixChildren[i]->copyNodeAndDescendants();
04056 }
04057 }
04058
04059 return ndcopy;
04060 }
04061
04062 bool OSnLMNodeMatrixObj::IsEqual(OSnLMNodeMatrixObj *that)
04063 {
04064 #ifndef NDEBUG
04065 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLMNodeMatrixObj");
04066 #endif
04067 if (this == NULL)
04068 {
04069 if (that == NULL)
04070 return true;
04071 else
04072 {
04073 #ifndef NDEBUG
04074 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
04075 "First object is NULL, second is not");
04076 #endif
04077 return false;
04078 }
04079 }
04080 else
04081 {
04082 if (that == NULL)
04083 {
04084 #ifndef NDEBUG
04085 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
04086 "Second object is NULL, first is not");
04087 #endif
04088 return false;
04089 }
04090 else
04091 {
04092 if (this->inodeInt != that->inodeInt)
04093 return false;
04094 if (this->inodeType != that->inodeType)
04095 return false;
04096 if (this->inumberOfChildren != that->inumberOfChildren)
04097 return false;
04098 if (this->inumberOfMatrixChildren != that->inumberOfMatrixChildren)
04099 return false;
04100
04101 if (this->idx != that->idx)
04102 return false;
04103
04104 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
04105 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
04106 return false;
04107
04108 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
04109 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
04110 return false;
04111
04112 return true;
04113 }
04114 }
04115 }
04116
04117
04118
04119 OSnLMNodeMatrixCon::OSnLMNodeMatrixCon():
04120 idx(-1)
04121 {
04122 inumberOfChildren = 0;
04123 inumberOfMatrixChildren = 0;
04124 m_mChildren = NULL;
04125 m_mMatrixChildren = NULL;
04126 inodeInt = OS_MATRIX_CON;
04127 inodeType = -1;
04128 }
04129
04130 OSnLMNodeMatrixCon::~OSnLMNodeMatrixCon()
04131 {
04132 std::ostringstream outStr;
04133 #ifndef NDEBUG
04134 outStr << "inside OSnLMNodeMatrixCon destructor" << endl;
04135 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
04136 #endif
04137 }
04138
04139 std::string OSnLMNodeMatrixCon::getTokenNumber()
04140 {
04141 ostringstream outStr;
04142 outStr << inodeInt;
04143 outStr << "[";
04144 outStr << inumberOfChildren;
04145 outStr << "]";
04146 outStr << ":";
04147 outStr << idx;
04148 outStr << ":";
04149 return outStr.str();
04150 }
04151
04152 std::string OSnLMNodeMatrixCon::getTokenName()
04153 {
04154 return "matrixCon";
04155 }
04156
04157
04158 std::string OSnLMNodeMatrixCon::getNonlinearExpressionInXML()
04159 {
04160 ostringstream outStr;
04161 outStr << "<matrixCon idx=\"" << idx << "\"/>" << std::endl;
04162 return outStr.str();
04163 }
04164
04165 #if 0
04166 double OSnLMNodeMatrixCon::calculateFunction(double *x)
04167 {
04168 m_dFunctionValue = coef*x[idx];
04169 return m_dFunctionValue;
04170 }
04171
04172 ADdouble OSnLMNodeMatrixCon::constructADTape(std::map<int, int> *varIdx, ADvector *XAD)
04173 {
04174 m_ADTape = coef;
04175 m_ADTape = coef*(*XAD)[ (*varIdx)[ idx] ];
04176 return m_ADTape;
04177 }
04178
04179
04180 void OSnLMNodeMatrixCon::getVariableIndexMap(std::map<int, int> *varIdx)
04181 {
04182 int numVars;
04183 if( (*varIdx).find( idx) != (*varIdx).end() )
04184 {
04185
04186 }
04187 else
04188 {
04189
04190 numVars = (*varIdx).size();
04191
04192 (*varIdx)[ idx] = numVars;
04193 }
04194
04195 }
04196 #endif
04197
04198
04199 OSnLMNode* OSnLMNodeMatrixCon::cloneExprNode()
04200 {
04201 OSnLMNode *nlMNodePoint;
04202 nlMNodePoint = new OSnLMNodeMatrixCon();
04203 return nlMNodePoint;
04204 }
04205
04206 OSnLMNode* OSnLMNodeMatrixCon::copyNodeAndDescendants()
04207 {
04208 #ifndef NDEBUG
04209 ostringstream outStr;
04210 outStr << "In copyNodeAndDescendants(), copy a node of type " << inodeInt;
04211 outStr << " (" << this->getTokenName() << ")" << std::endl;
04212 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, outStr.str());
04213 #endif
04214
04215 OSnLMNodeMatrixCon* ndcopy = (OSnLMNodeMatrixCon*)cloneExprNode();
04216 ndcopy->inumberOfChildren = inumberOfChildren;
04217 ndcopy->inumberOfMatrixChildren = inumberOfMatrixChildren;
04218 ndcopy->inodeInt = inodeInt;
04219 ndcopy->inodeType = inodeType;
04220 ndcopy->idx = idx;
04221
04222 if (inumberOfChildren > 0)
04223 {
04224 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
04225 for (int i=0; i < inumberOfChildren; i++)
04226 {
04227 ndcopy->m_mChildren[i] = m_mChildren[i]->copyNodeAndDescendants();
04228 }
04229 }
04230
04231 if (inumberOfMatrixChildren > 0)
04232 {
04233 ndcopy->m_mChildren = new OSnLNode*[inumberOfChildren];
04234 for (int i=0; i < inumberOfMatrixChildren; i++)
04235 {
04236 ndcopy->m_mMatrixChildren[i] = m_mMatrixChildren[i]->copyNodeAndDescendants();
04237 }
04238 }
04239
04240 return ndcopy;
04241 }
04242
04243
04244 bool OSnLMNodeMatrixCon::IsEqual(OSnLMNodeMatrixCon *that)
04245 {
04246 #ifndef NDEBUG
04247 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Start comparing in OSnLMNodeMatrixCon");
04248 #endif
04249 if (this == NULL)
04250 {
04251 if (that == NULL)
04252 return true;
04253 else
04254 {
04255 #ifndef NDEBUG
04256 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
04257 "First object is NULL, second is not");
04258 #endif
04259 return false;
04260 }
04261 }
04262 else
04263 {
04264 if (that == NULL)
04265 {
04266 #ifndef NDEBUG
04267 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
04268 "Second object is NULL, first is not");
04269 #endif
04270 return false;
04271 }
04272 else
04273 {
04274 if (this->inodeInt != that->inodeInt)
04275 return false;
04276 if (this->inodeType != that->inodeType)
04277 return false;
04278 if (this->inumberOfChildren != that->inumberOfChildren)
04279 return false;
04280 if (this->inumberOfMatrixChildren != that->inumberOfMatrixChildren)
04281 return false;
04282
04283 if (this->idx != that->idx)
04284 return false;
04285
04286 for (unsigned int i = 0; i < this->inumberOfChildren; i++)
04287 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
04288 return false;
04289
04290 for (unsigned int i = 0; i < this->inumberOfMatrixChildren; i++)
04291 if (!this->m_mMatrixChildren[i]->IsEqual(that->m_mMatrixChildren[i]))
04292 return false;
04293
04294 return true;
04295 }
04296 }
04297 }
04298