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

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

Generated on Thu Aug 5 03:02:58 2010 by  doxygen 1.4.7