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

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

Generated on Thu Oct 8 03:02:59 2009 by  doxygen 1.4.7