/home/coin/SVN-release/OS-2.3.3/OS/src/OSCommonInterfaces/OSnLNode.cpp

Go to the documentation of this file.
00001 /* $Id: OSnLNode.cpp 3815 2010-11-03 23:46:16Z Gassmann $ */
00017 //#define DEBUGOSNLNODE
00018 
00019 #include "OSnLNode.h"
00020 #include "OSErrorClass.h"
00021 #include "OSParameters.h"
00022 #include "OSMathUtil.h"
00023 
00024 
00025 #ifdef COIN_HAS_CPPAD  
00026 #include<cppad/cppad.hpp>
00027 using CppAD::vector;
00028 typedef AD<double>  ADdouble;
00029 #else
00030 using std::vector;
00031 #endif
00032 
00033 
00034 #include<string>
00035 
00036 #ifdef HAVE_CMATH
00037 # include <cmath>
00038 #else
00039 # ifdef HAVE_MATH_H
00040 #  include <math.h>
00041 # else
00042 #  error "don't have header file for math"
00043 # endif
00044 #endif
00045 
00046 
00047 #include <iostream>
00048 #include <sstream>  
00049 
00050 
00051 using std::ostringstream;
00052 using std::cout;
00053 using std::endl;
00054   
00055 
00056  
00057 //
00058 //const std::string msnodeNames[] = {
00059 //      /*1--*/"plus", "sum", "minus", "negate", "times", "divide",
00060 //      "quotient", "rem", "power", "product",
00061 //      /*2--*/"abs", "floor", "ceiling", "percent", "square", "squareRoot", "ln", "log", "log10", "exp",
00062 //      "factorial", "combination", "permutation", "gcd", "lcm", "roundToInt", "round", "truncate", "sign", "rand","gammaFn", "gammaLn",
00063 //      /*3--*/"sin", "cos", "tan", "arcsin", "arccos", "arctan", "sinh", "cosh", "tanh", "arcsinh", "arccosh", "arctanh",
00064 //      "cot", "coth", "arccot", "arccoth", "sec", "sech", "arcsec", "arcsech", "csc", "csch", "arccsc", "arccsch",
00065 //      /*4--*/"mean", "geometricMean", "harmonicMean", "trimMean", "count", "median", "firstQuartile", "thirdQuartile", "mode", "min", "max",
00066 //      "percentile", "large", "small", "range", "interQuantileRange", "absdev", "stddev", "variance", "cv", "skewness", "kurtosis",
00067 //      "covariance", "correlation", "pearsonCorrelation", "rankCorrelation", "autoCorrelation1", "autoCorrelation", "npv", "irr", 
00068 //      /*"empiricalDiscreteDist", "empiricalDiscreteCum", */"discreteUniformDist", "discreteUniformCum", "discreteUniformInv",
00069 //      "bernoulliDist", "bernoulliCum", "bernoulliInv", "binomialDist", "binomialCum", "binomialInv", "multinomialDist", "multinomialCum", "multinomialInv",
00070 //      "hypergeometricDist", "hypergeometricCum", "hypergeometricInv", "poissonDist", "poissonCum", "poissonInv",
00071 //      "geometricDist", "geometricCum", "geometricInv", "negativeBinomialDist", "negativeBinomialCum", "negativeBinomialInv",
00072 //      /*"empiricalContinousDist", "empiricalContinuousCum",*/ "uniformDist", "uniformCum", "uniformInv",
00073 //      "normalDist", "normalCum", "normalInv", "stdNormalDist", "stdNormalCum", "stdNormalInv", "bivariateNormalDist", "bivariateNormalCum",
00074 //      "exponentialDist", "exponentialCum", "exponentialInv", "weibullDist", "weibullCum", "weibullInv", "erlangDist", "erlangCum", "erlangInv",
00075 //      "gammaDist", "gammaCum", "gammaInv", "betaDist", "betaCum", "betaInv", "betaGeneralDist", "betaGeneralCum", "betaGeneralInv",
00076 //      "lognormalDist", "lognormalCum", "lognormalInv", "cauchyDist", "cauchyCum", "cauchyInv", "tDist", "tCum", "tInv",
00077 //      "chiSquareDist", "chiSquareCum", "chiSquareInv", "fDist", "fCum", "fInv", "logisticDist", "logisticCum", "logisticInv",
00078 //      "logLogisticDist", "logLogisticCum", "logLogisticInv", "logarithmicDist", "logarithmicCum", "logarithmicInv",
00079 //      "paretoDist", "paretoCum", "paretoDist", "rayleighDist", "rayleighCum", "rayleighInv", "pertDist", "pertCum", "pertDist",
00080 //      "triangularDist", "triangularCum", "triangularInv", "unitNormalLinearLoss", erf
00081 //      /*5--*/"number", "identifier", "PI", "E", "INF", "EPS", "TRUE", "FALSE", "EULERGAMMA", "NAN",
00082 //      /*6--*/"variable", "objective", "constraint", "parameter",
00083 //      /*7--*/"if", "lt", "leq", "gt", "geq", "eq", "neq", "and", "or", "xor", "implies", "not",
00084 //      "forAll", "exists", "logicCount", "allDiff", /*"allDisjoint",*/ "atMost", "atLeast", "exactly", 
00085 //      "inSet", "inRealSet", "inPositiveRealSet", "inNonnegativeRealSet", "inIntegerSet", "inPositiveIntegerSet","inNonnegativeIntegerSet",
00086 //      /*8--*/
00087 //      /*9--*/"qTerm", "quadratic", "sim", "simInput", "simOutput", "userF", "arg", "xPath", "xPathIndex",
00088 //      "nodeRef", "arcRef", "complements", /*"prob",*/
00089 //};
00090 
00091 
00092 
00093  
00094 //const int m_miNodeIndexes[] = {
00095 //      /*1--*/1001, 1002, 1003, 1004, 1005, 1006,
00096 //      1007, 1008, 1009, 1010,
00097 //      /*2--*/2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
00098 //      2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022,
00099 //      /*3--*/3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009, 3010, 3011, 3012,
00100 //      3013, 3014, 3015, 3016, 3017, 3018, 3019, 3020, 3021, 3022, 3023, 3024,
00101 //      /*4--*/4001, 4002, 4003, 4004, 4005, 4006, 4007, 4008, 4009, 4010, 4011,
00102 //      4012, 4013, 4014, 4015, 4016, 4017, 4018, 4019, 4020, 4021, 4022,
00103 //      4023, 4024, 4025, 4026, 4027, 4028, 4029, 4030,
00104 //      /*4101, 4102, */4111, 4112, 4113,
00105 //      4121, 4122, 4123, 4131, 4132, 4133, 4141, 4142, 4143,
00106 //      4151, 4152, 4153, 4161, 4162, 4163,
00107 //      4171, 4172, 4173, 4181, 4182, 4183,
00108 //      /*4401, 4402,*/ 4411, 4412, 4413,
00109 //      4421, 4422, 4423, 4431, 4432, 4433, 4441, 4442,
00110 //      4451, 4452, 4453, 4461, 4462, 4463, 4471, 4472, 4473,
00111 //      4481, 4482, 4483, 4491, 4492, 4493, 4501, 4502, 4503,
00112 //      4511, 4512, 4513, 4521, 4522, 4523, 4531, 4532, 4533,
00113 //      4541, 4542, 4543, 4551, 4552, 4553, 4561, 4562, 4563,
00114 //      4571, 4572, 4573, 4581, 4582, 4583,
00115 //      4591, 4592, 4593, 4601, 4602, 4603, 4611, 4612, 4613,
00116 //      4621, 4622, 4623, 4624,4625
00117 //      /*5--*/5001, 5002, 5003, 5004, 5005, 5006, 5007, 5008, 5009, 5010,
00118 //      /*6--*/6001, 6002, 6003, 6004,
00119 //      /*7--*/7001, 7002, 7003, 7004, 7005, 7006, 7007, 7008, 7009, 7010, 7011, 7012,
00120 //      7013, 7014, 7015, 7016, /*7017,*/ 7018, 7019, 7020, 
00121 //      7021, 7022, 7023, 7024, 7025, 7026, 7027,
00122 //      /*8--*/
00123 //      /*9--*/9001, 9002, 9003, 9004, 9005, 9006, 9007, 9008, 9009,
00124 //      9010, 9011, 9012, /*9013,*/
00125 //};
00126 
00127 //const int m_miNodeTypes[] = {
00128 //      /*1--*/2, -1, 2, 1, 2, 2,
00129 //      2, 2, 2, -1,
00130 //      /*2--*/1, 1, 1, 1, 1, 1, 1, 2, 1, 1,
00131 //      1, 2, 2, -1, -1, 1, 2, 2, 1, 1, 1, 1,
00132 //      /*3--*/1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00133 //      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00134 //      /*4--*/-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00135 //      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
00136 //      -1, -1, -1, -1, -1, -1, -1, -1,
00137 //      /*-1, -1, */2, 2, 2,
00138 //      2, 2, 2, 3, 3, 3, -1, -1, -1,
00139 //      4, 4, 4, 2, 2, 2,
00140 //      2, 2, 2, 3, 3, 3,
00141 //      /*-1, -1,*/ 3, 3, 3,
00142 //      3, 3, 3, 1, 1, 1, 7, 7,
00143 //      2, 2, 2, 4, 4, 4, 3, 3, 3,
00144 //      3, 3, 3, 3, 3, 3, 5, 5, 5,
00145 //      3, 3, 3, 3, 3, 3, 2, 2, 2,
00146 //      2, 2, 2, 3, 3, 3, 3, 3, 3,
00147 //      3, 3, 3, 3, 3, 3,
00148 //      3, 3, 3, 2, 2, 2, 4, 4, 4,
00149 //      4, 4, 4, 1,
00150 //      /*5--*/0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00151 //      /*6--*/-1, -1, -1, 0,
00152 //      /*7--*/3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
00153 //      -1, -1, -1, -1, /*-1,*/ -1, -1, -1, 
00154 //      -1, 1, 1, 1, 1, 1, 1
00155 //      /*8--*/
00156 //      /*9--*/-1, -1, -1, -1, -1, -1, 0, -1, -1,
00157 //      -1, -1, 2, /*1,*/
00158 //};
00159 
00160 
00161 
00162 
00163 //
00164 //OSnLNode methods
00165 //
00166 
00167 OSnLNode::OSnLNode():
00168         m_mChildren(NULL),
00169         m_dFunctionValue( OSNAN)
00170         //inumberOfChildren( 0)
00171 {
00172 }//end OSnLNode
00173 
00174 OSnLNode::~OSnLNode(){
00175         #ifdef DEBUGOSNLNODE
00176         cout << "inside OSnLNode destructor" << endl;
00177         #endif
00178 }//end ~OSnLNode
00179 
00180 
00181 OSnLNode* OSnLNode::createExpressionTreeFromPostfix(std::vector<OSnLNode*> nlNodeVec){
00182         std::vector<OSnLNode*> stackVec ;
00183         unsigned int kount =  0;
00184         while(kount <= nlNodeVec.size() - 1){
00185                 int numkids = nlNodeVec[kount]->inumberOfChildren;
00186                 if(numkids  > 0){
00187                         for(int i = numkids - 1; i >= 0;  i--){
00188                                 nlNodeVec[kount]->m_mChildren[i] = stackVec.back()      ;
00189                                 stackVec.pop_back();
00190                         }
00191                 }
00192                 stackVec.push_back( nlNodeVec[kount]);
00193                 kount++;
00194         }
00195         stackVec.clear();
00196         return nlNodeVec[ kount - 1];
00197 }//end createExpressionTreeFromPostfix
00198 
00199 std::vector<OSnLNode*> OSnLNode::getPostfixFromExpressionTree( ){
00200         std::vector<OSnLNode*> postfixVector;
00201         return postOrderOSnLNodeTraversal( &postfixVector);
00202 }//getPostfixFromExpressionTree
00203 
00204 std::vector<OSnLNode*> OSnLNode::postOrderOSnLNodeTraversal( std::vector<OSnLNode*> *postfixVector){
00205         if(inumberOfChildren > 0){
00206                 unsigned int i;
00207                 for(i = 0; i < inumberOfChildren; i++) 
00208                         m_mChildren[i]->postOrderOSnLNodeTraversal( postfixVector);
00209         }
00210         (*postfixVector).push_back( this);
00211         return *postfixVector;
00212 }//end postOrderOSnLNodeTraversal()
00213 
00214 OSnLNode* OSnLNode::createExpressionTreeFromPrefix(std::vector<OSnLNode*> nlNodeVec){
00215         std::vector<OSnLNode*> stackVec;
00216         int kount =  nlNodeVec.size() - 1;
00217         while(kount >= 0){
00218                 int numkids = nlNodeVec[kount]->inumberOfChildren;
00219                 if(numkids > 0){
00220                         for(int i = 0; i < numkids;  i++){
00221                                 nlNodeVec[kount]->m_mChildren[i] = stackVec.back()      ;
00222                                 stackVec.pop_back();
00223                         }
00224                 }
00225                 stackVec.push_back( nlNodeVec[kount]);
00226                 kount--;
00227         }
00228         stackVec.clear();
00229         return nlNodeVec[ 0];
00230 }//end createExpressionTreeFromPrefix
00231 
00232 std::vector<OSnLNode*> OSnLNode::getPrefixFromExpressionTree(){
00233         std::vector<OSnLNode*> prefixVector;
00234         return preOrderOSnLNodeTraversal( &prefixVector);
00235 }//getPrefixFromExpressionTree
00236 
00237 std::vector<OSnLNode*> OSnLNode::preOrderOSnLNodeTraversal( std::vector<OSnLNode*> *prefixVector){
00238         (*prefixVector).push_back( this);
00239         if(inumberOfChildren > 0){
00240                 for(unsigned int i = 0; i < inumberOfChildren; i++)
00241                         m_mChildren[i]->preOrderOSnLNodeTraversal( prefixVector);
00242         }
00243         return *prefixVector;
00244 }//end preOrderOSnLNodeTraversal
00245 
00246 
00247 std::string OSnLNode::getTokenNumber(){
00248         ostringstream outStr;
00249         outStr << inodeInt;
00250         // when I creat an OSnLNode from a token number, I need to know how many children there are
00251 //      if(inodeType == -1){
00252                 outStr << "[";
00253                 outStr << inumberOfChildren ;
00254                 outStr << "]";
00255 //      }
00256         return outStr.str();
00257 }//getTokenNumber
00258 
00259 
00260 //std::string OSnLNode::getTokenName(){
00261 //      ostringstream outStr;
00262 //      outStr << this->snodeName;
00263 //      if(inodeType == -1){
00264 //              outStr << "[";
00265 //              outStr << inumberOfChildren ;
00266 //              outStr << "]";
00267 //      }
00268 //      return outStr.str();
00269 //}//getTokenNumber
00270 
00271 
00272 /*
00273 OSnLNode* OSnLNode::getOSnLNodeFromToken(std::string sToken){
00274 // kipp possibly make this a static method or put it somewhere else
00275         OSnLNode *nlNodePoint;
00276         int nodeID ;
00277         int pos1, pos2;
00278         std::string str1, str2;
00279         // convert the std::string tokens into the appropriate objects
00280                 // kipp -- put in error check -- make sure > 0 and < 10001
00281         nodeID = atoi(  &sToken.substr(0, 4)[0]);
00282         switch (nodeID){
00283                 case OS_SUM:  // the sum token
00284                         pos1 = sToken.find('[');
00285                         pos2 = sToken.find(']');
00286                         if((pos1 == std::string::npos) || (pos2 == std::string::npos)){
00287                                 // throw error
00288                         }
00289                         OSnLNodeSum *nlNodePointSum;
00290                         nlNodePointSum = new OSnLNodeSum();
00291                         nlNodePointSum->inumberOfChildren = atoi(  &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
00292                         nlNodePointSum->m_mChildren = new OSnLNode*[ nlNodePointSum->inumberOfChildren];
00293                         return nlNodePointSum;
00294                 break;
00295                 case OS_MAX:  // the max token
00296                         pos1 = sToken.find('[');
00297                         pos2 = sToken.find(']');
00298                         if((pos1 == std::string::npos) || (pos2 == std::string::npos)){
00299                                 // throw error
00300                         }
00301                         OSnLNodeMax *nlNodePointMax;
00302                         nlNodePointMax = new OSnLNodeMax();
00303                         nlNodePointMax->inumberOfChildren = atoi(  &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
00304                         nlNodePointMax->m_mChildren = new OSnLNode*[ nlNodePointMax->inumberOfChildren];
00305                         return nlNodePointMax;
00306                 break;
00307                 case OS_PRODUCT:  // the product token
00308                         pos1 = sToken.find('[');
00309                         pos2 = sToken.find(']');
00310                         if((pos1 == std::string::npos) || (pos2 == std::string::npos)){
00311                                 // throw error
00312                         }
00313                         OSnLNodeProduct *nlNodePointProduct;
00314                         nlNodePointProduct = new OSnLNodeProduct();
00315                         nlNodePointProduct->inumberOfChildren = atoi(  &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
00316                         nlNodePointProduct->m_mChildren = new OSnLNode*[ nlNodePointProduct->inumberOfChildren];
00317                         return nlNodePointProduct;
00318                 break;
00319                 case OS_NUMBER:  // the number token
00320                         pos1 = sToken.find(':');
00321                         if(pos1 != 4){
00322                                 //throw error
00323                         }
00324                         // now get the second semicolon, the one that should be after value                             
00325                         pos2 = sToken.find(':', pos1 + 1);
00326                         if(pos2 != std::string::npos) {
00327                         }
00328                         else{
00329                                 //throw error
00330                         }
00331                         OSnLNodeNumber *nlNodePointNumber; 
00332                         nlNodePointNumber = new OSnLNodeNumber();
00333                         nlNodePointNumber->value = atof(  &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
00334                         return nlNodePointNumber;
00335                 break;
00336                 case OS_VARIABLE:  // the variable token
00337                         pos1 = sToken.find('[');
00338                         pos2 = sToken.find(']');
00339                         if((pos1 == std::string::npos) || (pos2 == std::string::npos)){
00340                                 // throw error
00341                         }
00342                         OSnLNodeVariable *nlNodePointVariable;
00343                         nlNodePointVariable = new OSnLNodeVariable();
00344                         nlNodePointVariable->inumberOfChildren = atoi(  &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
00345                         nlNodePointVariable->m_mChildren = new OSnLNode*[ nlNodePointVariable->inumberOfChildren];
00346                         // throw error if there is more than one child
00347                         // now get the index and the coefficient
00348                         pos1 = sToken.find(':');
00349                         if(pos1 != 4){
00350                                 //throw error
00351                         }
00352                         // now get the second semicolon, the one that should be after idx                               
00353                         pos2 = sToken.find(':', pos1 + 1);
00354                         if(pos2 == std::string::npos) {
00355                                 //throw error
00356                         }
00357                         nlNodePointVariable->idx = atoi(  &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
00358                         // now get the coefficient
00359                         str1 = sToken;
00360                         str2 = sToken.substr(pos2 + 1, str1.length() - pos2 - 1);
00361                         nlNodePointVariable->coef = atof(&str2[0]);
00362                         return nlNodePointVariable;
00363                 break;
00364                 default:
00365                         nlNodePoint = nlNodeArray[ nlNodeIdxMap[ nodeID]]->cloneOSnLNode();
00366                 
00367                 break;
00368         }
00369         return nlNodePoint;
00370 }//end getOSnLNodeFromToken
00371 */
00372 
00373 
00374 
00375 std::string OSnLNode::getNonlinearExpressionInXML(){
00376         ostringstream outStr;
00377         outStr << "<" ;
00378         outStr << this->getTokenName();
00379 #ifdef DEBUGOSNLNODE
00380         cout << "nonlinear node " << this->getTokenName() << endl;
00381 #endif
00382         if(inumberOfChildren > 0) {
00383                 outStr << ">";
00384         }
00385         else{
00386                 outStr << "/>";
00387         }
00388         if(inumberOfChildren > 0){
00389                 for(unsigned int i = 0; i < inumberOfChildren; i++){
00390                         outStr << m_mChildren[i]->getNonlinearExpressionInXML();
00391                 }
00392         }
00393         if(inumberOfChildren > 0) {
00394                 outStr << "</" ;
00395                 outStr << this->getTokenName() ;
00396                 outStr << ">" ;
00397         }
00398         return outStr.str();
00399 }//getNonlinearExpressionInXML()
00400 //
00401 //
00402 
00403 
00404 void OSnLNode::getVariableIndexMap(std::map<int, int> *varIdx){
00405         unsigned int i;
00406         if(inodeInt != OS_VARIABLE){
00407                 for(i = 0; i < inumberOfChildren; i++){
00408                         m_mChildren[ i]->getVariableIndexMap( varIdx);
00409                 }
00410         }
00411 }//getVariableIndexMap
00412 
00413 bool OSnLNode::IsEqual(OSnLNode *that)
00414 {
00415         #ifdef DEBUG_ISEQUAL_ROUTINES
00416                 cout << "Start comparing in OSnLNode" << endl;
00417         #endif
00418         if (this == NULL)
00419         {       if (that == NULL)
00420                         return true;
00421                 else
00422                 {
00423                         #ifdef DEBUG_ISEQUAL_ROUTINES
00424                                 cout << "First object is NULL, second is not" << endl;
00425                         #endif
00426                         return false;
00427                 }
00428         }
00429         else 
00430         {       if (that == NULL)
00431                 {
00432                         #ifdef DEBUG_ISEQUAL_ROUTINES
00433                                 cout << "Second object is NULL, first is not" << endl;
00434                         #endif
00435                         return false;
00436                 }
00437                 else    
00438                 {
00439                         if (this->inumberOfChildren != that->inumberOfChildren)
00440                                 return false;
00441                         if (this->inodeInt != that->inodeInt)
00442                                 return false;
00443                         if (this->inodeType != that->inodeType)
00444                                 return false;
00445 
00446                         for (int i=0; i<this->inumberOfChildren; i++)
00447                                 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
00448                                         return false;
00449 
00450                         return true;
00451                 }
00452         }
00453 }//OSnLNode::IsEqual
00454 
00455 
00456 // OSnLNodePlus Methods 
00457 OSnLNodePlus::OSnLNodePlus()
00458 {
00459 
00460         inumberOfChildren = 2;
00461         m_mChildren = new OSnLNode*[2];
00462         m_mChildren[ 0] = NULL;
00463         m_mChildren[ 1] = NULL;
00464         inodeInt = 1001;
00465         inodeType = 2;
00466 }//end OSnLNodePlus
00467 
00468 
00469 OSnLNodePlus::~OSnLNodePlus(){
00470         #ifdef DEBUGOSNLNODE
00471         cout << "inside OSnLNodePlus destructor" << endl;
00472         #endif
00473         for(unsigned int i = 0; i < inumberOfChildren; i++){
00474                 if( m_mChildren[ i] != NULL) delete m_mChildren[ i];
00475                 m_mChildren[i] = NULL;
00476         }
00477         //m_mChildren = NULL;
00478         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00479 }//end ~OSnLNodePlus
00480 
00481 std::string OSnLNodePlus::getTokenName(){
00482         return "plus";
00483 }// end OSnLNodePlus::getTokenName()
00484 
00485 
00486 double OSnLNodePlus::calculateFunction(double *x){
00487         m_dFunctionValue = m_mChildren[0]->calculateFunction(x) + m_mChildren[1]->calculateFunction(x);
00488         return m_dFunctionValue;
00489 }// end OSnLNodePlus::calculate
00490 
00491 
00492 ADdouble OSnLNodePlus::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00493         m_ADTape = m_mChildren[0]->constructADTape( ADIdx,  XAD) + m_mChildren[1]->constructADTape( ADIdx,  XAD);
00494         return m_ADTape;
00495 }// end OSnLNodePlus::constructADTape
00496 
00497 
00498 OSnLNode* OSnLNodePlus::cloneOSnLNode(){
00499         OSnLNode *nlNodePoint;
00500         nlNodePoint = new OSnLNodePlus();
00501         return  nlNodePoint;
00502 }//end OSnLNodePlus::cloneOSnLNode
00503 
00504 //
00505 // OSnLNodeSum Methods  
00506 OSnLNodeSum::OSnLNodeSum()
00507 {
00508         inumberOfChildren = 0;
00509         inodeInt = 1002;
00510         inodeType = -1;
00511 }//end OSnLNodeSum
00512 
00513 OSnLNodeSum::~OSnLNodeSum(){
00514         #ifdef DEBUGOSNLNODE
00515         cout << "inside OSnLNodeSum destructor" << endl;
00516         #endif
00517         if(inumberOfChildren > 0){
00518                 for(unsigned int i = 0; i < inumberOfChildren; i++){
00519                         delete m_mChildren[ i];
00520                         m_mChildren[i] = NULL;
00521                 }
00522         }
00523         //m_mChildren = NULL; 
00524         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00525 }//end ~OSnLNodeSum
00526 
00527 std::string OSnLNodeSum::getTokenName(){
00528         return "sum";
00529 }// end OSnLNodeSum::getTokenName()
00530 
00531 double OSnLNodeSum::calculateFunction(double *x){
00532         m_dFunctionValue = 0.0;  
00533         unsigned int i;
00534         for(i = 0; i < inumberOfChildren; i++){
00535                 m_dFunctionValue = m_dFunctionValue + m_mChildren[i]->calculateFunction(x);
00536         }
00537         return m_dFunctionValue;
00538 }// end OSnLNodeSum::calculate
00539 
00540 
00541 ADdouble OSnLNodeSum::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00542         m_ADTape = 0.0;
00543         unsigned int i;
00544         for(i = 0; i < inumberOfChildren; i++){
00545                         m_ADTape = m_ADTape + m_mChildren[i]->constructADTape( ADIdx, XAD);
00546         }
00547         return m_ADTape;
00548 }// end OSnLNodeSum::constructADTape
00549 
00550 OSnLNode* OSnLNodeSum::cloneOSnLNode(){
00551         OSnLNode *nlNodePoint;
00552         nlNodePoint = new OSnLNodeSum();
00553         return  nlNodePoint;
00554 }//end OSnLNodeSum::cloneOSnLNode
00555 //end OSnLNodeSum methods
00556 
00557 
00558 //
00559 // OSnLNodeAllDiff Methods      
00560 
00561 OSnLNodeAllDiff::OSnLNodeAllDiff()
00562 {
00563         inumberOfChildren = 0;
00564         inodeInt = 7016;
00565         inodeType = -1;
00566 }//end OSnLNodeAllDiff
00567 
00568 
00569 OSnLNodeAllDiff::~OSnLNodeAllDiff(){
00570         #ifdef DEBUGOSNLNODE
00571         cout << "inside OSnLNodeAllDiff destructor" << endl;
00572         #endif
00573         if(inumberOfChildren > 0){
00574                 for(unsigned int i = 0; i < inumberOfChildren; i++){
00575                         delete m_mChildren[ i];
00576                         m_mChildren[i] = NULL;
00577                 }
00578         }
00579         //m_mChildren = NULL;
00580         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00581 }//end ~OSnLNodeAllDiff
00582 
00583 std::string OSnLNodeAllDiff::getTokenName(){
00584         return "allDiff";
00585 }// end OSnLNodeAllDiff::getTokenName(
00586 
00587 
00588 double OSnLNodeAllDiff::calculateFunction(double *x){
00589         m_dFunctionValue = 1;
00590         // return a false if not all all different
00591         unsigned int i, k;
00592         if(inumberOfChildren > 1){
00593                 for(i = 0; i < inumberOfChildren - 1; i++){
00594                         for(k = i + 1; k < inumberOfChildren; k++){
00595                                 if(m_mChildren[i]->calculateFunction(x) ==  
00596                                         m_mChildren[k]->calculateFunction(x)) return 0 ;
00597                         }
00598                 }
00599         }
00600         return m_dFunctionValue;
00601 }// end OSnLNodeAllDiff::calculate
00602 
00603 
00604 ADdouble OSnLNodeAllDiff::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00605         try{
00606                 throw ErrorClass("AllDifferent operator not supported by current Algorithmic Differentiation implementation");
00607                 return m_ADTape;
00608         }
00609         catch(const ErrorClass& eclass){
00610                 throw ErrorClass( eclass.errormsg);
00611         }
00612         return m_ADTape;
00613 }// end OSnLNodeAllDiff::constructADTape
00614 
00615 
00616 OSnLNode* OSnLNodeAllDiff::cloneOSnLNode(){
00617         OSnLNode *nlNodePoint;
00618         nlNodePoint = new OSnLNodeAllDiff();
00619         return  nlNodePoint;
00620 }//end OSnLNodeAllDiff::cloneOSnLNode
00621 //end OSnLNodeAllDiff methods
00622 
00623 
00624 
00625 //
00626 // OSnLNodeMax Methods  
00627 OSnLNodeMax::OSnLNodeMax()
00628 {
00629         inumberOfChildren = 0;
00630         inodeInt = 4011;
00631         inodeType = -1;
00632 }//end OSnLNodeMax
00633 
00634 OSnLNodeMax::~OSnLNodeMax(){
00635         #ifdef DEBUGOSNLNODE
00636         cout << "inside OSnLNodeMax destructor" << endl;
00637         #endif
00638         if(inumberOfChildren > 0){
00639                 for(unsigned int i = 0; i < inumberOfChildren; i++){
00640                         delete m_mChildren[ i];
00641                         m_mChildren[i] = NULL;
00642                 }
00643         }
00644         //m_mChildren = NULL;
00645         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00646 }//end ~OSnLNodeMax
00647 
00648 double OSnLNodeMax::calculateFunction(double *x){
00649         m_dFunctionValue = m_mChildren[0]->calculateFunction(x);
00650         if(inumberOfChildren > 1){
00651                 for(unsigned int i = 1; i < inumberOfChildren; i++){
00652                         if(m_mChildren[i]->calculateFunction(x) > m_dFunctionValue){
00653                                 m_dFunctionValue =      m_mChildren[i]->calculateFunction(x);
00654                         }
00655                 }
00656         }
00657         return m_dFunctionValue;
00658 }// end OSnLNodeMax::calculate
00659 
00660 std::string OSnLNodeMax::getTokenName(){
00661         return "max";
00662 }// end OSnLNodeMax::getTokenName(
00663 
00664 
00665 ADdouble OSnLNodeMax::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00666         //if not support in AD, throw an exception
00667         try{
00668                 throw ErrorClass("Max operator not supported by current Algorithmic Differentiation implementation");
00669                 return m_ADTape;
00670         }
00671         catch(const ErrorClass& eclass){
00672                 throw ErrorClass( eclass.errormsg);
00673         }
00674 }// end OSnLNodeMax::constructADTape
00675 
00676 
00677 OSnLNode* OSnLNodeMax::cloneOSnLNode(){
00678         OSnLNode *nlNodePoint;
00679         nlNodePoint = new OSnLNodeMax();
00680         return  nlNodePoint;
00681 }//end OSnLNodeMax::cloneOSnLNode
00682 //
00683 
00684 
00685 
00686 //
00687 // OSnLNodeMin Methods  
00688 OSnLNodeMin::OSnLNodeMin()
00689 {
00690         inumberOfChildren = 0;
00691         inodeInt = 4010;
00692         inodeType = -1;
00693 }//end OSnLNodeMin
00694 
00695 OSnLNodeMin::~OSnLNodeMin(){
00696         #ifdef DEBUGOSNLNODE
00697         cout << "inside OSnLNodeMin destructor" << endl;
00698         #endif
00699         if(inumberOfChildren > 0){
00700                 for(unsigned int i = 0; i < inumberOfChildren; i++){
00701                         delete m_mChildren[ i];
00702                         m_mChildren[i] = NULL;
00703                 }
00704         }
00705         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00706         //m_mChildren = NULL;
00707 }//end ~OSnLNodeMin
00708 
00709 
00710 std::string OSnLNodeMin::getTokenName(){
00711         return "min";
00712 }// end OSnLNodeMin::getTokenName(
00713 
00714 double OSnLNodeMin::calculateFunction(double *x){
00715         m_dFunctionValue = m_mChildren[0]->calculateFunction(x);
00716         if(inumberOfChildren > 1){
00717                 for(unsigned int i = 1; i < inumberOfChildren; i++){
00718                         if(m_mChildren[i]->calculateFunction(x) < m_dFunctionValue){
00719                                 m_dFunctionValue =      m_mChildren[i]->calculateFunction(x);
00720                         }
00721                 }
00722         }
00723         return m_dFunctionValue;
00724 }// end OSnLNodeMin::calculate
00725 
00726 
00727 ADdouble OSnLNodeMin::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00728         //if not support in AD, throw an exception
00729         try{
00730                 throw ErrorClass("Min operator not supported by current Algorithmic Differentiation implementation");
00731                 return m_ADTape;
00732         }
00733         catch(const ErrorClass& eclass){
00734                 throw ErrorClass( eclass.errormsg);
00735         }
00736 }// end OSnLNodeMin::constructADTape
00737 
00738 
00739 OSnLNode* OSnLNodeMin::cloneOSnLNode(){
00740         OSnLNode *nlNodePoint;
00741         nlNodePoint = new OSnLNodeMin();
00742         return  nlNodePoint;
00743 }//end OSnLNodeMin::cloneOSnLNode
00744 //
00745 
00746 
00747 //
00748 //
00749 // OSnLNodeMinus Methods        
00750 OSnLNodeMinus::OSnLNodeMinus()
00751 {
00752         inumberOfChildren = 2;
00753         m_mChildren = new OSnLNode*[2];
00754         m_mChildren[ 0] = NULL;
00755         m_mChildren[ 1] = NULL;
00756         inodeInt = 1003;
00757         inodeType = 2;
00758 }//end OSnLNodeMinus
00759 
00760  
00761 OSnLNodeMinus::~OSnLNodeMinus(){
00762         #ifdef DEBUGOSNLNODE
00763         cout << "inside OSnLNodeMinus destructor" << endl;
00764         #endif
00765         for(unsigned int i = 0; i < inumberOfChildren; i++){
00766                 delete m_mChildren[ i];
00767                 m_mChildren[i] = NULL;
00768         }
00769         //m_mChildren = NULL;
00770         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00771 }//end ~OSnLNodeMinus
00772 
00773 std::string OSnLNodeMinus::getTokenName(){
00774         return "minus";
00775 }// end OSnLNodeSum::getTokenName(
00776 
00777 double OSnLNodeMinus::calculateFunction(double *x){
00778         m_dFunctionValue =  m_mChildren[0]->calculateFunction( x) - m_mChildren[1]->calculateFunction( x);
00779         return m_dFunctionValue;
00780 }// end OSnLNodeMinus::calculate
00781 
00782 
00783 ADdouble OSnLNodeMinus::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00784         m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) - m_mChildren[1]->constructADTape( ADIdx, XAD);
00785         return m_ADTape;
00786 }// end OSnLNodeMinus::constructADTape
00787 
00788 
00789 OSnLNode* OSnLNodeMinus::cloneOSnLNode(){
00790         OSnLNode *nlNodePoint;
00791         nlNodePoint = new OSnLNodeMinus();
00792         return  nlNodePoint;
00793 }//end OSnLNodeMinus::cloneOSnLNode
00794 //
00795 //
00796 
00797  
00798 //
00799 //
00800 // OSnLNodeNegate Methods       
00801 OSnLNodeNegate::OSnLNodeNegate()
00802 {
00803         inumberOfChildren = 1;
00804         m_mChildren = new OSnLNode*[1];
00805         m_mChildren[ 0] = NULL;
00806         inodeInt = 1004;
00807         inodeType = 1;
00808 }//end OSnLNodeNegate
00809 
00810  
00811 OSnLNodeNegate::~OSnLNodeNegate(){
00812         #ifdef DEBUGOSNLNODE
00813         cout << "inside OSnLNodeNegate destructor" << endl;
00814         #endif
00815         for(unsigned int i = 0; i < inumberOfChildren; i++){
00816                 delete m_mChildren[ i];
00817                 m_mChildren[i] = NULL;
00818         }
00819         //m_mChildren = NULL;
00820         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00821 }//end ~OSnLNodeNegate
00822 
00823 std::string OSnLNodeNegate::getTokenName(){
00824         return "negate";
00825 }// end OSnLNodeNegate::getTokenName(
00826 
00827 double OSnLNodeNegate::calculateFunction(double *x){
00828         m_dFunctionValue =  -m_mChildren[0]->calculateFunction( x) ;
00829         return m_dFunctionValue;
00830 }// end OSnLNodeMinus::calculate
00831 
00832 ADdouble OSnLNodeNegate::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00833         m_ADTape = -m_mChildren[0]->constructADTape( ADIdx, XAD);
00834         return m_ADTape;
00835 }// end OSnLNodeNegate::constructADTape
00836 
00837 
00838 OSnLNode* OSnLNodeNegate::cloneOSnLNode(){
00839         OSnLNode *nlNodePoint;
00840         nlNodePoint = new OSnLNodeNegate();
00841         return  nlNodePoint;
00842 }//end OSnLNodeNegate::cloneOSnLNode
00843 //
00844 //
00845 
00846 // OSnLNodeTimes Methods        
00847 OSnLNodeTimes::OSnLNodeTimes()
00848 {
00849         inumberOfChildren = 2;
00850         m_mChildren = new OSnLNode*[2];
00851         m_mChildren[ 0] = NULL;
00852         m_mChildren[ 1] = NULL;
00853         inodeInt = 1005;
00854         inodeType = 2;
00855 }//end OSnLNodeTimes
00856 
00857  
00858 OSnLNodeTimes::~OSnLNodeTimes(){
00859         #ifdef DEBUGOSNLNODE
00860         cout << "inside OSnLNodeTimes destructor" << endl;
00861         #endif
00862         for(unsigned int i = 0; i < inumberOfChildren; i++){
00863                 delete m_mChildren[ i];
00864                 m_mChildren[i] = NULL;
00865         }
00866         //m_mChildren = NULL;
00867         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00868 }//end ~OSnLNodeTimes
00869 
00870 std::string OSnLNodeTimes::getTokenName(){
00871         return "times";
00872 }// end OSnLNodeTimes::getTokenName(
00873 
00874 double OSnLNodeTimes::calculateFunction(double *x){
00875         m_dFunctionValue = m_mChildren[0]->calculateFunction( x)*m_mChildren[1]->calculateFunction( x);
00876         return m_dFunctionValue;
00877 }// end OSnLNodeTimes::calculate
00878 
00879 
00880 ADdouble OSnLNodeTimes::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00881         m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) * m_mChildren[1]->constructADTape( ADIdx, XAD);
00882         return m_ADTape;
00883 }// end OSnLNodeTimes::constructADTape
00884 
00885 OSnLNode* OSnLNodeTimes::cloneOSnLNode(){
00886         OSnLNode *nlNodePoint;
00887         nlNodePoint = new OSnLNodeTimes();
00888         return  nlNodePoint;
00889 }//end OSnLNodeTimes::cloneOSnLNode
00890 
00891 //
00892 //
00893 // OSnLNodeDivide Methods       
00894 OSnLNodeDivide::OSnLNodeDivide()
00895 {
00896         inumberOfChildren = 2;
00897         m_mChildren = new OSnLNode*[2];
00898         m_mChildren[ 0] = NULL;
00899         m_mChildren[ 1] = NULL;
00900         inodeInt = 1006;
00901         inodeType = 2;
00902 }//end OSnLNodeDivide
00903 
00904  
00905 OSnLNodeDivide::~OSnLNodeDivide(){
00906         #ifdef DEBUGOSNLNODE
00907         cout << "inside OSnLNodeDivide destructor" << endl;
00908         #endif
00909         for(unsigned int i = 0; i < inumberOfChildren; i++){
00910                 delete m_mChildren[ i];
00911                 m_mChildren[i] = NULL;
00912         }
00913         //m_mChildren = NULL;
00914         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00915 }//end ~OSnLNodeDivide
00916 
00917 std::string OSnLNodeDivide::getTokenName(){
00918         return "divide";
00919 }// end OSnLNodeDivide::getTokenName(
00920 
00921 double OSnLNodeDivide::calculateFunction(double *x){
00922         // kipp throw error if we divide by 0
00923         m_dFunctionValue = m_mChildren[0]->calculateFunction( x)/m_mChildren[1]->calculateFunction( x);
00924         return m_dFunctionValue;
00925 }// end OSnLNodeDivide::calculate
00926 
00927 
00928 ADdouble OSnLNodeDivide::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00929         m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) / m_mChildren[1]->constructADTape( ADIdx, XAD);
00930         return m_ADTape;
00931 }// end OSnLNodeDivide::constructADTape
00932 
00933 
00934 OSnLNode* OSnLNodeDivide::cloneOSnLNode(){
00935         OSnLNode *nlNodePoint;
00936         nlNodePoint = new OSnLNodeDivide();
00937         return  nlNodePoint;
00938 }//end OSnLNodeDivide::cloneOSnLNode
00939 
00940 
00941 //
00942 // OSnLNodePower Methods        
00943 OSnLNodePower::OSnLNodePower()
00944 {
00945         inumberOfChildren = 2;
00946         m_mChildren = new OSnLNode*[2];
00947         m_mChildren[ 0] = NULL;
00948         m_mChildren[ 1] = NULL;
00949         inodeInt = 1009;
00950         inodeType = 2;
00951 }//end OSnLNodePower
00952 
00953  
00954 OSnLNodePower::~OSnLNodePower(){
00955         #ifdef DEBUGOSNLNODE
00956         cout << "inside OSnLNodePower destructor" << endl;
00957         #endif
00958         for(unsigned int i = 0; i < inumberOfChildren; i++){
00959                 delete m_mChildren[ i];
00960                 m_mChildren[i] = NULL;
00961         }
00962         //m_mChildren = NULL;
00963         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00964 }//end ~OSnLNodePower 
00965 
00966 std::string OSnLNodePower::getTokenName(){
00967         return "power";
00968 }// end OSnLNodePower::getTokenName(
00969 
00970 double OSnLNodePower::calculateFunction(double *x){
00971         // kipp throw error if operation not defined
00972         m_dFunctionValue =  pow(m_mChildren[0]->calculateFunction( x), m_mChildren[1]->calculateFunction( x));
00973         return  m_dFunctionValue;
00974 }// end OSnLNodePower::calculate
00975 
00976 //
00977 ADdouble OSnLNodePower::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00978         //if( typeid( *m_mChildren[1]) == typeid( OSnLNodeNumber) ) {
00979         if( this->m_mChildren[1]->inodeInt == 5001 ) {
00980                 OSnLNodeNumber *numberNode  =  (OSnLNodeNumber*)m_mChildren[1];
00981                 // we have a number node see if interger
00982                 if( (numberNode->value) == int( numberNode->value)){
00983                         m_ADTape =  pow(m_mChildren[0]->constructADTape( ADIdx, XAD) ,  int( numberNode->value));
00984                 }       
00985                 else m_ADTape = pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , m_mChildren[1]->constructADTape( ADIdx, XAD) );      
00986         }
00987         else{
00988                 m_ADTape = pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , m_mChildren[1]->constructADTape( ADIdx, XAD) );   
00989         }
00990         return m_ADTape;
00991 }// end OSnLNodePower::constructADTape
00992 
00993 
00994 
00995 //ADdouble OSnLNodePower::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){  
00996 //              m_ADTape = AD::pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , m_mChildren[1]->constructADTape( ADIdx, XAD) );       
00997 //      return m_ADTape;
00998 //}// end OSnLNodePower::constructADTape
00999 
01000 
01001 
01002 
01003 
01004 OSnLNode* OSnLNodePower::cloneOSnLNode(){
01005         OSnLNode *nlNodePoint;
01006         nlNodePoint = new OSnLNodePower();
01007         return  nlNodePoint;
01008 }//end OSnLNodePower::cloneOSnLNode
01009 //
01010 //
01011 
01012 
01013 //
01014 // OSnLNodePower Methods        
01015 OSnLNodeProduct::OSnLNodeProduct()
01016 {
01017         inumberOfChildren = 0;
01018         inodeInt = 1010;
01019         inodeType = -1;
01020 }//end OSnLNodeProduct
01021 
01022  
01023 OSnLNodeProduct::~OSnLNodeProduct(){
01024         #ifdef DEBUGOSNLNODE
01025         cout << "inside OSnLNodeProduct destructor" << endl;
01026         #endif
01027         if(inumberOfChildren > 0){
01028                 for(unsigned int i = 0; i < inumberOfChildren; i++){
01029                         delete m_mChildren[ i];
01030                         m_mChildren[i] = NULL;
01031                 }
01032         }
01033         //m_mChildren = NULL;
01034         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01035 }//end ~OSnLNodeProduct
01036 
01037 std::string OSnLNodeProduct::getTokenName(){
01038         return "product";
01039 }// end OSnLNodeProduct::getTokenName(
01040 
01041 double OSnLNodeProduct::calculateFunction(double *x){
01042         // kipp throw error if operation not defined
01043         m_dFunctionValue = 1.0;
01044         unsigned int i;
01045         for(i = 0; i < inumberOfChildren; i++){
01046                 m_dFunctionValue = m_dFunctionValue*m_mChildren[i]->calculateFunction(x);
01047         }
01048         return m_dFunctionValue;
01049 }// end OSnLNodeProduct::calculate
01050 
01051 
01052 ADdouble OSnLNodeProduct::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01053         m_ADTape = 1.0;
01054         unsigned int i;
01055         for(i = 0; i < inumberOfChildren; i++){
01056                 m_ADTape = m_ADTape*m_mChildren[i]->constructADTape( ADIdx, XAD);
01057         }
01058         return m_ADTape;
01059 }// end OSnLNodeProduct::constructADTape
01060 
01061 
01062 OSnLNode* OSnLNodeProduct::cloneOSnLNode(){
01063         OSnLNode *nlNodePoint;
01064         nlNodePoint = new OSnLNodeProduct();
01065         return  nlNodePoint;
01066 }//end OSnLNodeProduct::cloneOSnLNode
01067 //
01068 //
01069 
01070 
01071 //
01072 // OSnLNodeLn Methods   
01073 OSnLNodeLn::OSnLNodeLn()
01074 {
01075         inumberOfChildren = 1;
01076         m_mChildren = new OSnLNode*[1];
01077         m_mChildren[ 0] = NULL;
01078         inodeInt = 2007;
01079         inodeType = 1;
01080 }//end OSnLNodeLn
01081 
01082  
01083 OSnLNodeLn::~OSnLNodeLn(){
01084         #ifdef DEBUGOSNLNODE
01085         cout << "inside OSnLNodeLn destructor" << endl;
01086         #endif
01087         for(unsigned int i = 0; i < inumberOfChildren; i++){
01088                 delete m_mChildren[ i];
01089                 m_mChildren[i] = NULL;
01090         }
01091         //m_mChildren = NULL;
01092         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01093 }//end ~OSnLNodeLn
01094 
01095 std::string OSnLNodeLn::getTokenName(){
01096         return "ln";
01097 }// end OSnLNodeLn::getTokenName(
01098 
01099 double OSnLNodeLn::calculateFunction(double *x){
01100         m_dFunctionValue = log(m_mChildren[0]->calculateFunction( x) );
01101         return m_dFunctionValue;
01102 }// end OSnLNodeLn::calculate
01103 
01104 
01105 ADdouble OSnLNodeLn::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01106         m_ADTape = log( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01107         return m_ADTape;
01108 }// end OSnLNodeLn::constructADTape
01109 
01110 OSnLNode* OSnLNodeLn::cloneOSnLNode(){
01111         OSnLNode *nlNodePoint;
01112         nlNodePoint = new OSnLNodeLn();
01113         return  nlNodePoint;
01114 }//end OSnLNodeLn::cloneOSnLNode
01115 
01116 
01117 
01118 
01119 
01120 //
01121 // OSnLNodeSqrt Methods 
01122 OSnLNodeSqrt::OSnLNodeSqrt()
01123 {
01124         inumberOfChildren = 1;
01125         m_mChildren = new OSnLNode*[1];
01126         m_mChildren[ 0] = NULL;
01127         inodeInt = 2006;
01128         inodeType = 1;
01129 }//end OSnLNodeSqrt
01130 
01131  
01132 OSnLNodeSqrt::~OSnLNodeSqrt(){
01133         #ifdef DEBUGOSNLNODE
01134         cout << "inside OSnLNodeSqrt destructor" << endl;
01135         #endif
01136         for(unsigned int i = 0; i < inumberOfChildren; i++){
01137                 delete m_mChildren[ i];
01138                 m_mChildren[i] = NULL;
01139         }
01140         //m_mChildren = NULL;
01141         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01142 }//end ~OSnLNodeSqrt
01143 
01144 std::string OSnLNodeSqrt::getTokenName(){
01145         return "sqrt";
01146 }// end OSnLNodeSqrt::getTokenName(
01147 
01148 double OSnLNodeSqrt::calculateFunction(double *x){
01149         m_dFunctionValue = sqrt(m_mChildren[0]->calculateFunction( x) );
01150         return m_dFunctionValue;
01151 }// end OSnLNodeSqrt::calculate
01152 
01153 
01154 ADdouble OSnLNodeSqrt::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01155         m_ADTape = sqrt( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01156         return m_ADTape;
01157 }// end OSnLNodeSqrt::constructADTape
01158 
01159 OSnLNode* OSnLNodeSqrt::cloneOSnLNode(){
01160         OSnLNode *nlNodePoint;
01161         nlNodePoint = new OSnLNodeSqrt();
01162         return  nlNodePoint;
01163 }//end OSnLNodeSqrt::cloneOSnLNode
01164 
01165 
01166 
01167 //
01168 //
01169 // OSnLNodeSquare Methods       
01170 OSnLNodeSquare::OSnLNodeSquare()
01171 {
01172         inumberOfChildren = 1;
01173         m_mChildren = new OSnLNode*[1];
01174         m_mChildren[ 0] = NULL;
01175         inodeInt = 2005;
01176         inodeType = 1;
01177 }//end OSnLNodeSquare
01178 
01179  
01180 OSnLNodeSquare::~OSnLNodeSquare(){
01181         #ifdef DEBUGOSNLNODE
01182         cout << "inside OSnLNodeSquare destructor" << endl;
01183         #endif
01184         for(unsigned int i = 0; i < inumberOfChildren; i++){
01185                 delete m_mChildren[ i];
01186                 m_mChildren[i] = NULL;
01187         }
01188         //m_mChildren = NULL;
01189         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01190 }//end ~OSnLNodeSquare
01191 
01192 std::string OSnLNodeSquare::getTokenName(){
01193         return "square";
01194 }// end OSnLNodeSquare::getTokenName(
01195 
01196 double OSnLNodeSquare::calculateFunction(double *x){
01197         m_dFunctionValue = pow( (m_mChildren[0]->calculateFunction( x) ), 2);
01198         return m_dFunctionValue;
01199 }// end OSnLNodeSquare::calculate
01200 
01201 
01202 ADdouble OSnLNodeSquare::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01203         m_ADTape = pow( m_mChildren[0]->constructADTape( ADIdx, XAD), int( 2) );
01204         return m_ADTape;
01205 }// end OSnLNodeSquare::constructADTape
01206 
01207 OSnLNode* OSnLNodeSquare::cloneOSnLNode(){
01208         OSnLNode *nlNodePoint;
01209         nlNodePoint = new OSnLNodeSquare();
01210         return  nlNodePoint;
01211 }//end OSnLNodeSquare::cloneOSnLNode
01212 
01213 //
01214 //
01215 // OSnLNodeSin Methods  
01216 OSnLNodeSin::OSnLNodeSin()
01217 {
01218         inumberOfChildren = 1;
01219         m_mChildren = new OSnLNode*[1];
01220         m_mChildren[ 0] = NULL;
01221         inodeInt = 3001;
01222         inodeType = 1;
01223 }//end OSnLNodeSin
01224 
01225  
01226 OSnLNodeSin::~OSnLNodeSin(){
01227         #ifdef DEBUGOSNLNODE
01228         cout << "inside OSnLNodeSin destructor" << endl;
01229         #endif
01230         for(unsigned int i = 0; i < inumberOfChildren; i++){
01231                 delete m_mChildren[ i];
01232                 m_mChildren[i] = NULL;
01233         }
01234         //m_mChildren = NULL;
01235         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01236 }//end ~OSnLNodeSin
01237 
01238 std::string OSnLNodeSin::getTokenName(){
01239         return "sin";
01240 }// end OSnLNodeSin::getTokenName(
01241 
01242 double OSnLNodeSin::calculateFunction(double *x){
01243         m_dFunctionValue = sin(m_mChildren[0]->calculateFunction( x) );
01244         return m_dFunctionValue;
01245 }// end OSnLNodeSin::calculate
01246 
01247 
01248 ADdouble OSnLNodeSin::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01249         m_ADTape = sin( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01250         return m_ADTape;
01251 }// end OSnLNodeSin::constructADTape
01252 
01253 OSnLNode* OSnLNodeSin::cloneOSnLNode(){
01254         OSnLNode *nlNodePoint;
01255         nlNodePoint = new OSnLNodeSin();
01256         return  nlNodePoint;
01257 }//end OSnLNodeSin::cloneOSnLNode
01258 
01259 
01260 //
01261 //
01262 // OSnLNodeCos Methods  
01263 OSnLNodeCos::OSnLNodeCos()
01264 {
01265         inumberOfChildren = 1;
01266         m_mChildren = new OSnLNode*[1];
01267         m_mChildren[ 0] = NULL;
01268         inodeInt = 3002;
01269         inodeType = 1;
01270 }//end OSnLNodeCos
01271 
01272  
01273 OSnLNodeCos::~OSnLNodeCos(){
01274         #ifdef DEBUGOSNLNODE
01275         cout << "inside OSnLNodeCos destructor" << endl;
01276         #endif
01277         for(unsigned int i = 0; i < inumberOfChildren; i++){
01278                 delete m_mChildren[ i];
01279                 m_mChildren[i] = NULL;
01280         }
01281         //m_mChildren = NULL;
01282         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01283 }//end ~OSnLNodeCos
01284 
01285 std::string OSnLNodeCos::getTokenName(){
01286         return "cos";
01287 }// end OSnLNodeCos::getTokenName(
01288 
01289 double OSnLNodeCos::calculateFunction(double *x){
01290         m_dFunctionValue = cos(m_mChildren[0]->calculateFunction( x) );
01291         return m_dFunctionValue;
01292 }// end OSnLNodeCos::calculate
01293 
01294 
01295 ADdouble OSnLNodeCos::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01296         m_ADTape = cos( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01297         return m_ADTape;
01298 }// end OSnLNodeCos::constructADTape
01299 
01300 OSnLNode* OSnLNodeCos::cloneOSnLNode(){
01301         OSnLNode *nlNodePoint;
01302         nlNodePoint = new OSnLNodeCos();
01303         return  nlNodePoint;
01304 }//end OSnLNodeCos::cloneOSnLNode
01305 
01306 
01307 
01308 
01309 //
01310 //
01311 // OSnLNodeExp Methods  
01312 OSnLNodeExp::OSnLNodeExp()
01313 {
01314         inumberOfChildren = 1;
01315         m_mChildren = new OSnLNode*[1];
01316         m_mChildren[ 0] = NULL;
01317         inodeInt = 2010;
01318         inodeType = 1;
01319 }//end OSnLNodeExp
01320 
01321  
01322 OSnLNodeExp::~OSnLNodeExp(){
01323         #ifdef DEBUGOSNLNODE
01324         cout << "inside OSnLNodeExp destructor" << endl;
01325         #endif
01326         for(unsigned int i = 0; i < inumberOfChildren; i++){
01327                 delete m_mChildren[ i];
01328                 m_mChildren[i] = NULL;
01329         }
01330         //m_mChildren = NULL;
01331         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01332 }//end ~OSnLNodeExp
01333 
01334 std::string OSnLNodeExp::getTokenName(){
01335         return "exp";
01336 }// end OSnLNodeExp::getTokenName(
01337 
01338 double OSnLNodeExp::calculateFunction(double *x){
01339         m_dFunctionValue = exp(m_mChildren[0]->calculateFunction( x) );
01340         return m_dFunctionValue;
01341 }// end OSnLNodeExp::calculate
01342 
01343 
01344 ADdouble OSnLNodeExp::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01345         m_ADTape = exp( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01346         return m_ADTape;
01347 }// end OSnLNodeExp::constructADTape
01348 
01349 OSnLNode* OSnLNodeExp::cloneOSnLNode(){
01350         OSnLNode *nlNodePoint;
01351         nlNodePoint = new OSnLNodeExp();
01352         return  nlNodePoint;
01353 }//end OSnLNodeExp::cloneOSnLNode
01354 //
01355 //
01356 
01357 
01358 
01359 //
01360 // OSnLNodeAbs Methods  
01361 OSnLNodeAbs::OSnLNodeAbs()
01362 {
01363         inumberOfChildren = 1;
01364         m_mChildren = new OSnLNode*[1];
01365         m_mChildren[ 0] = NULL;
01366         inodeInt = 2001;
01367         inodeType = 1;
01368 }//end OSnLNodeLn
01369 
01370  
01371 OSnLNodeAbs::~OSnLNodeAbs(){
01372         #ifdef DEBUGOSNLNODE
01373         cout << "inside OSnLNodeAbs destructor" << endl;
01374         #endif
01375         for(unsigned int i = 0; i < inumberOfChildren; i++){
01376                 delete m_mChildren[ i];
01377                 m_mChildren[i] = NULL;
01378         }
01379         //m_mChildren = NULL;
01380         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01381 }//end ~OSnLNodeAbs
01382 
01383 std::string OSnLNodeAbs::getTokenName(){
01384         return "abs";
01385 }// end OSnLNodeAbs::getTokenName(
01386 
01387 double OSnLNodeAbs::calculateFunction(double *x){
01388         m_dFunctionValue = fabs(m_mChildren[0]->calculateFunction( x) );
01389         return m_dFunctionValue;
01390 }// end OSnLNodeAbs::calculate
01391 
01392 
01393 ADdouble OSnLNodeAbs::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01394         m_ADTape = abs( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01395         return m_ADTape;
01396 }// end OSnLNodeAbs::constructADTape
01397 
01398 OSnLNode* OSnLNodeAbs::cloneOSnLNode(){
01399         OSnLNode *nlNodePoint;
01400         nlNodePoint = new OSnLNodeAbs();
01401         return  nlNodePoint;
01402 }//end OSnLNodeAbs::cloneOSnLNode
01403 //
01404 //
01405 
01406 
01407 
01408 
01409 //
01410 // OSnLNodeErf Methods  
01411 OSnLNodeErf::OSnLNodeErf()
01412 {
01413         inumberOfChildren = 1;
01414         m_mChildren = new OSnLNode*[1];
01415         m_mChildren[ 0] = NULL;
01416         inodeInt = 4625;
01417         inodeType = 1;
01418 }//end OSnLNodeErf
01419 
01420  
01421 OSnLNodeErf::~OSnLNodeErf(){
01422         #ifdef DEBUGOSNLNODE
01423         cout << "inside OSnLNodeErf destructor" << endl;
01424         #endif
01425         for(unsigned int i = 0; i < inumberOfChildren; i++){
01426                 delete m_mChildren[ i];
01427                 m_mChildren[i] = NULL;
01428         }
01429         //m_mChildren = NULL;
01430         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01431 }//end ~OSnLNodeErf
01432 
01433 std::string OSnLNodeErf::getTokenName(){
01434         return "erf";
01435 }// end OSnLNodeErf::getTokenName(
01436 
01437 double OSnLNodeErf::calculateFunction(double *x){
01438         const double a = (993./880.);
01439         const double b =  (89./880.); 
01440         //m_dFunctionValue = fabs(m_mChildren[0]->calculateFunction( x) );
01441         m_dFunctionValue = tanh( (a + b * m_mChildren[0]->calculateFunction( x) * m_mChildren[0]->calculateFunction( x)) * m_mChildren[0]->calculateFunction( x) );
01442         //std::cout << "function value =   " << m_dFunctionValue << std::endl;
01443         return m_dFunctionValue;
01444 }// end OSnLNodeErf::calculate
01445 
01446 
01447 ADdouble OSnLNodeErf::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01448 /***
01449  * 
01450  * This is a fast approximation (few numerical operations) 
01451  * with relative error bound $latex 4 \times 10^{-4}$$; see 
01452  * Vedder, J.D., "Simple approximations for the error function and its inverse",
01453  * American Journal of Physics, v 55, n 8, 1987, p 762-3. I took this reference from 
01454  * Brad Bell's erf.hpp
01455  * 
01456  */
01457         const double a = (993./880.);
01458         const double b =  (89./880.); 
01459 
01460         //tanh( (a + b * x * x) * x );
01461         //m_ADTape = CppAD::erf( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01462         m_ADTape = tanh( (a + b * m_mChildren[0]->constructADTape( ADIdx, XAD) * m_mChildren[0]->constructADTape( ADIdx, XAD)) * m_mChildren[0]->constructADTape( ADIdx, XAD) );
01463 
01464         return m_ADTape;
01465 }// end OSnLNodeErf::constructADTape
01466 
01467 OSnLNode* OSnLNodeErf::cloneOSnLNode(){
01468         OSnLNode *nlNodePoint;
01469         nlNodePoint = new OSnLNodeErf();
01470         return  nlNodePoint;
01471 }//end OSnLNodeErf::cloneOSnLNode
01472 //
01473 //
01474 
01475 
01476 
01477 //
01478 // OSnLNodeIf Methods   
01479 OSnLNodeIf::OSnLNodeIf()
01480 {
01481         inumberOfChildren = 3;
01482         m_mChildren = new OSnLNode*[3];
01483         m_mChildren[ 0] = NULL;
01484         m_mChildren[ 1] = NULL;
01485         m_mChildren[ 2] = NULL;
01486         inodeInt = 7001;
01487         inodeType = 3;
01488 }//end OSnLNodeIf
01489 
01490  
01491 OSnLNodeIf::~OSnLNodeIf(){
01492         #ifdef DEBUGOSNLNODE
01493         cout << "inside OSnLNodeIf destructor" << endl;
01494         #endif 
01495         for(unsigned int i = 0; i < inumberOfChildren; i++){
01496                 delete m_mChildren[ i];
01497                 m_mChildren[i] = NULL;
01498         }
01499         //m_mChildren = NULL;
01500         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01501 }//end ~OSnLNodeIf
01502 
01503 std::string OSnLNodeIf::getTokenName(){
01504         return "if";
01505 }// end OSnLNodeIf::getTokenName(
01506 
01507 double OSnLNodeIf::calculateFunction(double *x){
01508         if(m_mChildren[0]->calculateFunction( x)  >= 0) m_dFunctionValue = m_mChildren[ 1]->calculateFunction( x);
01509                 else m_dFunctionValue = m_mChildren[ 2]->calculateFunction( x);
01510         return m_dFunctionValue;
01511 }// end OSnLNodeIf::calculate
01512 
01513 ADdouble OSnLNodeIf::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01514         //if not support in AD, throw an exception
01515         try{
01516                 throw ErrorClass("if operator not supported by current Algorithmic Differentiation implementation");
01517                 return m_ADTape;
01518         }
01519         catch(const ErrorClass& eclass){
01520                 throw ErrorClass( eclass.errormsg);
01521         }
01522 }// end OSnLNodeIf::constructADTape
01523 
01524 OSnLNode* OSnLNodeIf::cloneOSnLNode(){
01525         OSnLNode *nlNodePoint;
01526         nlNodePoint = new OSnLNodeIf();
01527         return  nlNodePoint;
01528 }//end OSnLNodeIf::cloneOSnLNode
01529 //
01530 //
01531 
01532 
01533 // OSnLNodeNumber Methods       
01534 OSnLNodeNumber::OSnLNodeNumber()
01535 {
01536         inodeInt = 5001;
01537         inumberOfChildren = 0;
01538         m_mChildren = NULL;
01539         inodeType = 0;  
01540         value = 0.0;
01541         type = "real";
01542         id = "";
01543 
01544 }//end OSnLNodeNumber
01545 
01546 OSnLNodeNumber::~OSnLNodeNumber(){
01547         #ifdef DEBUGOSNLNODE
01548         cout << "inside OSnLNodeNumber destructor" << endl;
01549         #endif
01550         m_mChildren = NULL;
01551 }//end ~OSnLNodeNumber
01552 
01553 std::string OSnLNodeNumber::getTokenNumber(){
01554         ostringstream outStr;
01555         outStr << inodeInt;
01556         outStr << ":" ;
01557         outStr << value ;
01558         //if(type.length() > 0){
01559                 outStr << ":" ;
01560                 outStr << type ;
01561         //}
01562         //if(id.length() > 0){
01563                 outStr << ":" ;
01564                 outStr << id;
01565         //}
01566         return outStr.str();
01567 }//getTokenNumber
01568 
01569 
01570 std::string OSnLNodeNumber::getTokenName(){
01571         ostringstream outStr;
01572         outStr << "number";
01573         outStr << ":" ;
01574         outStr << value ;
01575         //if(type.length() > 0){
01576                 outStr << ":" ;
01577                 outStr << type ;
01578         //}
01579         //if(id.length() > 0){
01580                 outStr << ":" ;
01581                 outStr << id;
01582         //}
01583         return outStr.str();
01584 }//getTokenName
01585 
01586 
01587 std::string OSnLNodeNumber::getNonlinearExpressionInXML(){
01588         ostringstream outStr;
01589         outStr << "<" ;
01590         outStr << this->getTokenName();
01591                 outStr << "  value=\"";
01592                 outStr << os_dtoa_format(value); 
01593                 outStr << "\"";
01594                 outStr << " type=\"";
01595                 outStr << type ;
01596                 outStr << "\"";
01597                 if(id.length() > 0){
01598                         outStr << "  id=\"";
01599                         outStr << id ;
01600                         outStr << "\"";
01601                 }
01602                 outStr << "/>";
01603         return outStr.str();
01604 }//getNonlinearExpressionInXML()
01605 
01606 
01607 double OSnLNodeNumber::calculateFunction(double *x){
01608         m_dFunctionValue = this->value;
01609         return m_dFunctionValue;
01610 }// end OSnLNodeNumber::calculate
01611 
01612 ADdouble OSnLNodeNumber::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01613         m_ADTape =  this->value;
01614         return m_ADTape;
01615 }// end OSnLNodeNumber::constructADTape
01616 
01617 OSnLNode* OSnLNodeNumber::cloneOSnLNode(){
01618         OSnLNode *nlNodePoint;
01619         nlNodePoint = new OSnLNodeNumber();
01620         return  nlNodePoint;
01621 }//end OSnLNodeNumber::cloneOSnLNode
01622 // edn OSnLNodeNumber methods
01623 
01624 
01625 // OSnLNodeE Methods    
01626 OSnLNodeE::OSnLNodeE()
01627 {
01628         inodeInt = 5004;
01629         inumberOfChildren = 0;
01630         m_mChildren = NULL;
01631         inodeType = 0;  
01632         //value = 0.0;
01633         //type = "real";
01634         //id = "";
01635 
01636 }//end OSnLNodeE
01637 
01638 OSnLNodeE::~OSnLNodeE(){
01639         #ifdef DEBUGOSNLNODE
01640         cout << "inside OSnLNodeE destructor" << endl;
01641         #endif
01642         m_mChildren = NULL;
01643 }//end ~OSnLNodeE
01644 
01645 
01646 
01647 std::string OSnLNodeE::getTokenNumber(){
01648         ostringstream outStr;
01649         outStr << inodeInt;
01650         //outStr << ":" ;
01651         //outStr << value ;
01652         //if(type.length() > 0){
01653         //      outStr << ":" ;
01654         //      outStr << type ;
01655         //}
01656         //if(id.length() > 0){
01657         //      outStr << ":" ;
01658         //      outStr << id;
01659         //}
01660         return outStr.str();
01661 }//getTokenNumber
01662 
01663 
01664 std::string OSnLNodeE::getTokenName(){
01665         ostringstream outStr;
01666         outStr << "E";
01667         //outStr << ":" ;
01668         //outStr << value ;
01669         //if(type.length() > 0){
01670         //      outStr << ":" ;
01671         //      outStr << type ;
01672         //}
01673         //if(id.length() > 0){
01674         //      outStr << ":" ;
01675         //      outStr << id;
01676         //}
01677         return outStr.str();
01678 }//getTokenName
01679 
01680 
01681 std::string OSnLNodeE::getNonlinearExpressionInXML(){
01682         ostringstream outStr;
01683         outStr << "<" ;
01684         outStr << "E";
01685 //              outStr << "  value=\"";
01686 //              outStr << value ;
01687 //              outStr << "\"";
01688 //              outStr << " type=\"";
01689 //              outStr << type ;
01690 //              outStr << "\"";
01691 //              if(id.length() > 0){
01692 //                      outStr << "  id=\"";
01693 //                      outStr << id ;
01694 //                      outStr << "\"";
01695 //              }
01696                 outStr << "/>";
01697         return outStr.str();
01698 }//getNonlinearExpressionInXML()
01699 
01700 
01701 double OSnLNodeE::calculateFunction(double *x){
01702         m_dFunctionValue = OS_E_VALUE;
01703         return m_dFunctionValue;
01704 }// end OSnLNodeE::calculate
01705 
01706 ADdouble OSnLNodeE::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01707         m_ADTape =  OS_E_VALUE;
01708         return m_ADTape;
01709 }// end OSnLE::constructADTape
01710 
01711 OSnLNode* OSnLNodeE::cloneOSnLNode(){
01712         OSnLNode *nlNodePoint;
01713         nlNodePoint = new OSnLNodeE();
01714         return  nlNodePoint;
01715 }//end OSnLNodeE::cloneOSnLNode
01716 
01717 //end OSnLNodeE
01718 
01719 
01720 // OSnLNodePI Methods   
01721 OSnLNodePI::OSnLNodePI()
01722 {
01723         inodeInt = 5003;
01724         inumberOfChildren = 0;
01725         m_mChildren = NULL;
01726         inodeType = 0;  
01727 
01728 
01729 }//end OSnLNodePI
01730 
01731 
01732 OSnLNodePI::~OSnLNodePI(){
01733         #ifdef DEBUGOSNLNODE
01734         cout << "inside OSnLNodePI destructor" << endl;
01735         #endif
01736         m_mChildren = NULL;
01737 }//end ~OSnLNodePI
01738 
01739 
01740 std::string OSnLNodePI::getTokenNumber(){
01741         ostringstream outStr;
01742         outStr << inodeInt;
01743         //outStr << ":" ;
01744         //outStr << value ;
01745         //if(type.length() > 0){
01746         //      outStr << ":" ;
01747         //      outStr << type ;
01748         //}
01749         //if(id.length() > 0){
01750         //      outStr << ":" ;
01751         //      outStr << id;
01752         //}
01753         return outStr.str();
01754 }//getTokenNumber
01755 
01756 
01757 std::string OSnLNodePI::getTokenName(){
01758         ostringstream outStr;
01759         outStr << "PI";
01760         //outStr << ":" ;
01761         //outStr << value ;
01762         //if(type.length() > 0){
01763                 //outStr << ":" ;
01764                 //outStr << type ;
01765         //}
01766         //if(id.length() > 0){
01767                 //outStr << ":" ;
01768                 //outStr << id;
01769         //}
01770         return outStr.str();
01771 }//getTokenName
01772 
01773 
01774 std::string OSnLNodePI::getNonlinearExpressionInXML(){
01775         ostringstream outStr;
01776         outStr << "<" ;
01777         outStr << "PI";
01778 //              outStr << "  value=\"";
01779 //              outStr << value ;
01780 //              outStr << "\"";
01781 //              outStr << " type=\"";
01782 //              outStr << type ;
01783 //              outStr << "\"";
01784 //              if(id.length() > 0){
01785 //                      outStr << "  id=\"";
01786 //                      outStr << id ;
01787 //                      outStr << "\"";
01788 //              }
01789                 outStr << "/>";
01790         return outStr.str();
01791 }//getNonlinearExpressionInXML()
01792 
01793 
01794 double OSnLNodePI::calculateFunction(double *x){
01795         m_dFunctionValue = OS_PI_VALUE;
01796         return m_dFunctionValue;
01797 }// end OSnLNodePI::calculate
01798 
01799 ADdouble OSnLNodePI::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01800         m_ADTape =  OS_PI_VALUE;
01801         return m_ADTape;
01802 }// end OSnLE::constructADTape
01803 
01804 OSnLNode* OSnLNodePI::cloneOSnLNode(){
01805         OSnLNode *nlNodePoint;
01806         nlNodePoint = new OSnLNodePI();
01807         return  nlNodePoint;
01808 }//end OSnLNodePI::cloneOSnLNode
01809 
01810 //end OSnLNodePI methods
01811 
01812 // OSnLNodeVariable Methods     
01813 OSnLNodeVariable::OSnLNodeVariable()
01814 {
01815         inumberOfChildren = 0;
01816         m_mChildren = NULL;
01817         inodeInt = 6001;
01818         inodeType = -1;
01819         coef = 1.0;
01820         idx = -1;
01821 }//end OSnLNodeVariable
01822 
01823 OSnLNodeVariable::~OSnLNodeVariable(){
01824         #ifdef DEBUGOSNLNODE
01825         cout << "inside OSnLNodeVariable destructor" << endl;
01826         cout << "number kids = " <<  inumberOfChildren << endl;
01827         #endif
01828         if(inumberOfChildren > 0){
01829                 for(unsigned int i = 0; i < inumberOfChildren; i++){
01830                         delete m_mChildren[ i];
01831                         m_mChildren[i] = NULL;
01832                 }
01833         }
01834         //m_mChildren = NULL;
01835         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01836 }//end ~OSnLNodeVariable
01837 
01838 
01839 std::string OSnLNodeVariable::getTokenNumber(){
01840         ostringstream outStr;
01841         // put in an error if inodeInt is not 6001
01842         outStr << inodeInt;
01843         outStr << "[";
01844         outStr << inumberOfChildren ;
01845         outStr << "]";
01846         outStr << ":" ;
01847         outStr << idx;
01848         outStr << ":" ;
01849         outStr << coef;
01850         outStr << ":real:" ;
01851         return outStr.str();
01852 }//getTokenNumber
01853 
01854 
01855 std::string OSnLNodeVariable::getTokenName(){
01856         ostringstream outStr;
01857         // put in an error if inodeInt is not 6001
01858         outStr << "variable";
01859         outStr << "[";
01860         outStr << inumberOfChildren ;
01861         outStr << "]";
01862         outStr << ":" ;
01863         outStr << idx;
01864         outStr << ":" ;
01865         outStr << coef;
01866         outStr << ":real:" ;
01867         return outStr.str();
01868 }//getTokenNumber
01869 
01870 
01871 std::string OSnLNodeVariable::getNonlinearExpressionInXML(){
01872         ostringstream outStr;
01873         outStr << "<" ;
01874         outStr << "variable";
01875                 outStr << "  idx=\"";
01876                 outStr << idx ;
01877                 outStr << "\"";
01878                 outStr << "  coef=\"";
01879                 outStr << os_dtoa_format(coef);
01880                 outStr << "\"";
01881         if(inumberOfChildren > 0) {
01882                 outStr << ">";
01883         }
01884         else{
01885                 outStr << "/>";
01886         }
01887         if(inumberOfChildren > 0){
01888                 for(unsigned int i = 0; i < inumberOfChildren; i++){
01889                         outStr << m_mChildren[i]->getNonlinearExpressionInXML();
01890                 }
01891         }
01892         if(inumberOfChildren > 0) {
01893                 outStr << "</" ;
01894                 outStr << "variable" ;
01895                 outStr << ">" ;
01896         }
01897         return outStr.str();
01898 }//getPrefix
01899 
01900 double OSnLNodeVariable::calculateFunction(double *x){
01901         m_dFunctionValue = coef*x[idx];
01902         return m_dFunctionValue;
01903 }// end OSnLNodeVariable::calculate
01904 
01905 ADdouble OSnLNodeVariable::constructADTape(std::map<int, int> *varIdx, vector< ADdouble > *XAD){
01906         m_ADTape = coef;
01907         //std::cout << "Inside OSnLNodeVariable "<<  std::endl;
01908         //std::cout << "Value of OSiL index = " << idx << std::endl;
01909         //std::cout << "Value of AD index = " << (*varIdx)[ idx] << std::endl;
01910         //std::cout << "Value of AD variable = " << (*XAD)[ (*varIdx)[ idx] ] << std::endl;
01911         m_ADTape = coef*(*XAD)[ (*varIdx)[ idx] ];
01912         return m_ADTape;
01913 }// end OSnLNodeVariable::constructADTape
01914 
01915 
01916 void OSnLNodeVariable::getVariableIndexMap(std::map<int, int> *varIdx){
01917         int numVars;
01918         if( (*varIdx).find( idx) != (*varIdx).end() ){
01919                 //std::cout  << "Index already in the map " << idx <<  std::endl;
01920         }
01921         else{ // variable to map with variable index as the key
01922                 //std::cout << "Found a new index to add to the map " << idx << std::endl;
01923                 numVars = (*varIdx).size();
01924                 //std::cout << "numVars =  " << numVars << std::endl;
01925                 (*varIdx)[ idx] = numVars;
01926         }
01927         //std::cout << "Value of index = " << (*varIdx)[ idx] << std::endl;
01928 }//getVariableIndexMap
01929 
01930 
01931 OSnLNode* OSnLNodeVariable::cloneOSnLNode(){
01932         OSnLNode *nlNodePoint;
01933         nlNodePoint = new OSnLNodeVariable();
01934         return  nlNodePoint;
01935 }//end OSnLNodeVariable::cloneOSnLNode
01936            
01937 
01938 
01939 
01940 
01941 
01942 

Generated on Sun Mar 20 03:06:19 2011 by  doxygen 1.4.7