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

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

Generated on Thu Nov 10 03:05:48 2011 by  doxygen 1.4.7