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

Go to the documentation of this file.
00001 /* $Id: OSnLNode.cpp 3488 2010-04-29 20:16:06Z 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         m_mChildren(NULL),
00159         m_dFunctionValue( OSNAN)
00160         //inumberOfChildren( 0)
00161 {
00162 }//end OSnLNode
00163 
00164 OSnLNode::~OSnLNode(){
00165         #ifdef DEBUGOSNLNODE
00166         cout << "inside OSnLNode destructor" << endl;
00167         #endif
00168 }//end ~OSnLNode
00169 
00170 
00171 OSnLNode* OSnLNode::createExpressionTreeFromPostfix(std::vector<OSnLNode*> nlNodeVec){
00172         std::vector<OSnLNode*> stackVec ;
00173         unsigned int kount =  0;
00174         while(kount <= nlNodeVec.size() - 1){
00175                 int numkids = nlNodeVec[kount]->inumberOfChildren;
00176                 if(numkids  > 0){
00177                         for(int i = numkids - 1; i >= 0;  i--){
00178                                 nlNodeVec[kount]->m_mChildren[i] = stackVec.back()      ;
00179                                 stackVec.pop_back();
00180                         }
00181                 }
00182                 stackVec.push_back( nlNodeVec[kount]);
00183                 kount++;
00184         }
00185         stackVec.clear();
00186         return nlNodeVec[ kount - 1];
00187 }//end createExpressionTreeFromPostfix
00188 
00189 std::vector<OSnLNode*> OSnLNode::getPostfixFromExpressionTree( ){
00190         std::vector<OSnLNode*> postfixVector;
00191         return postOrderOSnLNodeTraversal( &postfixVector);
00192 }//getPostfixFromExpressionTree
00193 
00194 std::vector<OSnLNode*> OSnLNode::postOrderOSnLNodeTraversal( std::vector<OSnLNode*> *postfixVector){
00195         if(inumberOfChildren > 0){
00196                 unsigned int i;
00197                 for(i = 0; i < inumberOfChildren; i++) 
00198                         m_mChildren[i]->postOrderOSnLNodeTraversal( postfixVector);
00199         }
00200         (*postfixVector).push_back( this);
00201         return *postfixVector;
00202 }//end postOrderOSnLNodeTraversal()
00203 
00204 OSnLNode* OSnLNode::createExpressionTreeFromPrefix(std::vector<OSnLNode*> nlNodeVec){
00205         std::vector<OSnLNode*> stackVec;
00206         int kount =  nlNodeVec.size() - 1;
00207         while(kount >= 0){
00208                 int numkids = nlNodeVec[kount]->inumberOfChildren;
00209                 if(numkids > 0){
00210                         for(int i = 0; i < numkids;  i++){
00211                                 nlNodeVec[kount]->m_mChildren[i] = stackVec.back()      ;
00212                                 stackVec.pop_back();
00213                         }
00214                 }
00215                 stackVec.push_back( nlNodeVec[kount]);
00216                 kount--;
00217         }
00218         stackVec.clear();
00219         return nlNodeVec[ 0];
00220 }//end createExpressionTreeFromPrefix
00221 
00222 std::vector<OSnLNode*> OSnLNode::getPrefixFromExpressionTree(){
00223         std::vector<OSnLNode*> prefixVector;
00224         return preOrderOSnLNodeTraversal( &prefixVector);
00225 }//getPrefixFromExpressionTree
00226 
00227 std::vector<OSnLNode*> OSnLNode::preOrderOSnLNodeTraversal( std::vector<OSnLNode*> *prefixVector){
00228         (*prefixVector).push_back( this);
00229         if(inumberOfChildren > 0){
00230                 for(unsigned int i = 0; i < inumberOfChildren; i++)
00231                         m_mChildren[i]->preOrderOSnLNodeTraversal( prefixVector);
00232         }
00233         return *prefixVector;
00234 }//end preOrderOSnLNodeTraversal
00235 
00236 
00237 std::string OSnLNode::getTokenNumber(){
00238         ostringstream outStr;
00239         outStr << inodeInt;
00240         // when I creat an OSnLNode from a token number, I need to know how many children there are
00241         if(inodeType == -1){
00242                 outStr << "[";
00243                 outStr << inumberOfChildren ;
00244                 outStr << "]";
00245         }
00246         return outStr.str();
00247 }//getTokenNumber
00248 
00249 
00250 //std::string OSnLNode::getTokenName(){
00251 //      ostringstream outStr;
00252 //      outStr << this->snodeName;
00253 //      if(inodeType == -1){
00254 //              outStr << "[";
00255 //              outStr << inumberOfChildren ;
00256 //              outStr << "]";
00257 //      }
00258 //      return outStr.str();
00259 //}//getTokenNumber
00260 
00261 
00262 /*
00263 OSnLNode* OSnLNode::getOSnLNodeFromToken(std::string sToken){
00264 // kipp possibly make this a static method or put it somewhere else
00265         OSnLNode *nlNodePoint;
00266         int nodeID ;
00267         int pos1, pos2;
00268         std::string str1, str2;
00269         // convert the std::string tokens into the appropriate objects
00270                 // kipp -- put in error check -- make sure > 0 and < 10001
00271         nodeID = atoi(  &sToken.substr(0, 4)[0]);
00272         switch (nodeID){
00273                 case OS_SUM:  // the sum token
00274                         pos1 = sToken.find('[');
00275                         pos2 = sToken.find(']');
00276                         if((pos1 == std::string::npos) || (pos2 == std::string::npos)){
00277                                 // throw error
00278                         }
00279                         OSnLNodeSum *nlNodePointSum;
00280                         nlNodePointSum = new OSnLNodeSum();
00281                         nlNodePointSum->inumberOfChildren = atoi(  &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
00282                         nlNodePointSum->m_mChildren = new OSnLNode*[ nlNodePointSum->inumberOfChildren];
00283                         return nlNodePointSum;
00284                 break;
00285                 case OS_MAX:  // the max token
00286                         pos1 = sToken.find('[');
00287                         pos2 = sToken.find(']');
00288                         if((pos1 == std::string::npos) || (pos2 == std::string::npos)){
00289                                 // throw error
00290                         }
00291                         OSnLNodeMax *nlNodePointMax;
00292                         nlNodePointMax = new OSnLNodeMax();
00293                         nlNodePointMax->inumberOfChildren = atoi(  &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
00294                         nlNodePointMax->m_mChildren = new OSnLNode*[ nlNodePointMax->inumberOfChildren];
00295                         return nlNodePointMax;
00296                 break;
00297                 case OS_PRODUCT:  // the product token
00298                         pos1 = sToken.find('[');
00299                         pos2 = sToken.find(']');
00300                         if((pos1 == std::string::npos) || (pos2 == std::string::npos)){
00301                                 // throw error
00302                         }
00303                         OSnLNodeProduct *nlNodePointProduct;
00304                         nlNodePointProduct = new OSnLNodeProduct();
00305                         nlNodePointProduct->inumberOfChildren = atoi(  &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
00306                         nlNodePointProduct->m_mChildren = new OSnLNode*[ nlNodePointProduct->inumberOfChildren];
00307                         return nlNodePointProduct;
00308                 break;
00309                 case OS_NUMBER:  // the number token
00310                         pos1 = sToken.find(':');
00311                         if(pos1 != 4){
00312                                 //throw error
00313                         }
00314                         // now get the second semicolon, the one that should be after value                             
00315                         pos2 = sToken.find(':', pos1 + 1);
00316                         if(pos2 != std::string::npos) {
00317                         }
00318                         else{
00319                                 //throw error
00320                         }
00321                         OSnLNodeNumber *nlNodePointNumber; 
00322                         nlNodePointNumber = new OSnLNodeNumber();
00323                         nlNodePointNumber->value = atof(  &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
00324                         return nlNodePointNumber;
00325                 break;
00326                 case OS_VARIABLE:  // the variable token
00327                         pos1 = sToken.find('[');
00328                         pos2 = sToken.find(']');
00329                         if((pos1 == std::string::npos) || (pos2 == std::string::npos)){
00330                                 // throw error
00331                         }
00332                         OSnLNodeVariable *nlNodePointVariable;
00333                         nlNodePointVariable = new OSnLNodeVariable();
00334                         nlNodePointVariable->inumberOfChildren = atoi(  &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
00335                         nlNodePointVariable->m_mChildren = new OSnLNode*[ nlNodePointVariable->inumberOfChildren];
00336                         // throw error if there is more than one child
00337                         // now get the index and the coefficient
00338                         pos1 = sToken.find(':');
00339                         if(pos1 != 4){
00340                                 //throw error
00341                         }
00342                         // now get the second semicolon, the one that should be after idx                               
00343                         pos2 = sToken.find(':', pos1 + 1);
00344                         if(pos2 == std::string::npos) {
00345                                 //throw error
00346                         }
00347                         nlNodePointVariable->idx = atoi(  &sToken.substr(pos1 + 1, pos2 - pos1 - 1)[0]);
00348                         // now get the coefficient
00349                         str1 = sToken;
00350                         str2 = sToken.substr(pos2 + 1, str1.length() - pos2 - 1);
00351                         nlNodePointVariable->coef = atof(&str2[0]);
00352                         return nlNodePointVariable;
00353                 break;
00354                 default:
00355                         nlNodePoint = nlNodeArray[ nlNodeIdxMap[ nodeID]]->cloneOSnLNode();
00356                 
00357                 break;
00358         }
00359         return nlNodePoint;
00360 }//end getOSnLNodeFromToken
00361 */
00362 
00363 
00364 
00365 std::string OSnLNode::getNonlinearExpressionInXML(){
00366         ostringstream outStr;
00367         outStr << "<" ;
00368         outStr << this->getTokenName();
00369 #ifdef DEBUGOSNLNODE
00370         cout << "nonlinear node " << this->getTokenName() << endl;
00371 #endif
00372         if(inumberOfChildren > 0) {
00373                 outStr << ">";
00374         }
00375         else{
00376                 outStr << "/>";
00377         }
00378         if(inumberOfChildren > 0){
00379                 for(unsigned int i = 0; i < inumberOfChildren; i++){
00380                         outStr << m_mChildren[i]->getNonlinearExpressionInXML();
00381                 }
00382         }
00383         if(inumberOfChildren > 0) {
00384                 outStr << "</" ;
00385                 outStr << this->getTokenName() ;
00386                 outStr << ">" ;
00387         }
00388         return outStr.str();
00389 }//getNonlinearExpressionInXML()
00390 //
00391 //
00392 
00393 
00394 void OSnLNode::getVariableIndexMap(std::map<int, int> *varIdx){
00395         unsigned int i;
00396         if(inodeInt != OS_VARIABLE){
00397                 for(i = 0; i < inumberOfChildren; i++){
00398                         m_mChildren[ i]->getVariableIndexMap( varIdx);
00399                 }
00400         }
00401 }//getVariableIndexMap
00402         
00403 // OSnLNodePlus Methods 
00404 OSnLNodePlus::OSnLNodePlus()
00405 {
00406 
00407         inumberOfChildren = 2;
00408         m_mChildren = new OSnLNode*[2];
00409         m_mChildren[ 0] = NULL;
00410         m_mChildren[ 1] = NULL;
00411         inodeInt = 1001;
00412         inodeType = 2;
00413 }//end OSnLNodePlus
00414 
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 std::string OSnLNodePlus::getTokenName(){
00429         return "plus";
00430 }// end OSnLNodePlus::getTokenName()
00431 
00432 
00433 double OSnLNodePlus::calculateFunction(double *x){
00434         m_dFunctionValue = m_mChildren[0]->calculateFunction(x) + m_mChildren[1]->calculateFunction(x);
00435         return m_dFunctionValue;
00436 }// end OSnLNodePlus::calculate
00437 
00438 
00439 ADdouble OSnLNodePlus::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00440         m_ADTape = m_mChildren[0]->constructADTape( ADIdx,  XAD) + m_mChildren[1]->constructADTape( ADIdx,  XAD);
00441         return m_ADTape;
00442 }// end OSnLNodePlus::constructADTape
00443 
00444 
00445 OSnLNode* OSnLNodePlus::cloneOSnLNode(){
00446         OSnLNode *nlNodePoint;
00447         nlNodePoint = new OSnLNodePlus();
00448         return  nlNodePoint;
00449 }//end OSnLNodePlus::cloneOSnLNode
00450 
00451 //
00452 // OSnLNodeSum Methods  
00453 OSnLNodeSum::OSnLNodeSum()
00454 {
00455         inumberOfChildren = 0;
00456         inodeInt = 1002;
00457         inodeType = -1;
00458 }//end OSnLNodeSum
00459 
00460 OSnLNodeSum::~OSnLNodeSum(){
00461         #ifdef DEBUGOSNLNODE
00462         cout << "inside OSnLNodeSum destructor" << endl;
00463         #endif
00464         if(inumberOfChildren > 0){
00465                 for(unsigned int i = 0; i < inumberOfChildren; i++){
00466                         delete m_mChildren[ i];
00467                         m_mChildren[i] = NULL;
00468                 }
00469         }
00470         //m_mChildren = NULL; 
00471         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00472 }//end ~OSnLNodeSum
00473 
00474 std::string OSnLNodeSum::getTokenName(){
00475         return "sum";
00476 }// end OSnLNodeSum::getTokenName()
00477 
00478 double OSnLNodeSum::calculateFunction(double *x){
00479         m_dFunctionValue = 0.0;  
00480         unsigned int i;
00481         for(i = 0; i < inumberOfChildren; i++){
00482                 m_dFunctionValue = m_dFunctionValue + m_mChildren[i]->calculateFunction(x);
00483         }
00484         return m_dFunctionValue;
00485 }// end OSnLNodeSum::calculate
00486 
00487 
00488 ADdouble OSnLNodeSum::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00489         m_ADTape = 0.0;
00490         unsigned int i;
00491         for(i = 0; i < inumberOfChildren; i++){
00492                         m_ADTape = m_ADTape + m_mChildren[i]->constructADTape( ADIdx, XAD);
00493         }
00494         return m_ADTape;
00495 }// end OSnLNodeSum::constructADTape
00496 
00497 OSnLNode* OSnLNodeSum::cloneOSnLNode(){
00498         OSnLNode *nlNodePoint;
00499         nlNodePoint = new OSnLNodeSum();
00500         return  nlNodePoint;
00501 }//end OSnLNodeSum::cloneOSnLNode
00502 //end OSnLNodeSum methods
00503 
00504 
00505 //
00506 // OSnLNodeAllDiff Methods      
00507 
00508 OSnLNodeAllDiff::OSnLNodeAllDiff()
00509 {
00510         inumberOfChildren = 0;
00511         inodeInt = 7016;
00512         inodeType = -1;
00513 }//end OSnLNodeAllDiff
00514 
00515 
00516 OSnLNodeAllDiff::~OSnLNodeAllDiff(){
00517         #ifdef DEBUGOSNLNODE
00518         cout << "inside OSnLNodeAllDiff destructor" << endl;
00519         #endif
00520         if(inumberOfChildren > 0){
00521                 for(unsigned int i = 0; i < inumberOfChildren; i++){
00522                         delete m_mChildren[ i];
00523                         m_mChildren[i] = NULL;
00524                 }
00525         }
00526         //m_mChildren = NULL;
00527         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00528 }//end ~OSnLNodeAllDiff
00529 
00530 std::string OSnLNodeAllDiff::getTokenName(){
00531         return "allDiff";
00532 }// end OSnLNodeAllDiff::getTokenName(
00533 
00534 
00535 double OSnLNodeAllDiff::calculateFunction(double *x){
00536         m_dFunctionValue = 1;
00537         // return a false if not all all different
00538         unsigned int i, k;
00539         if(inumberOfChildren > 1){
00540                 for(i = 0; i < inumberOfChildren - 1; i++){
00541                         for(k = i + 1; k < inumberOfChildren; k++){
00542                                 if(m_mChildren[i]->calculateFunction(x) ==  
00543                                         m_mChildren[k]->calculateFunction(x)) return 0 ;
00544                         }
00545                 }
00546         }
00547         return m_dFunctionValue;
00548 }// end OSnLNodeAllDiff::calculate
00549 
00550 
00551 ADdouble OSnLNodeAllDiff::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00552         try{
00553                 throw ErrorClass("AllDifferent operator not supported by current Algorithmic Differentiation implementation");
00554                 return m_ADTape;
00555         }
00556         catch(const ErrorClass& eclass){
00557                 throw ErrorClass( eclass.errormsg);
00558         }
00559         return m_ADTape;
00560 }// end OSnLNodeAllDiff::constructADTape
00561 
00562 
00563 OSnLNode* OSnLNodeAllDiff::cloneOSnLNode(){
00564         OSnLNode *nlNodePoint;
00565         nlNodePoint = new OSnLNodeAllDiff();
00566         return  nlNodePoint;
00567 }//end OSnLNodeAllDiff::cloneOSnLNode
00568 //end OSnLNodeAllDiff methods
00569 
00570 
00571 
00572 //
00573 // OSnLNodeMax Methods  
00574 OSnLNodeMax::OSnLNodeMax()
00575 {
00576         inumberOfChildren = 0;
00577         inodeInt = 4011;
00578         inodeType = -1;
00579 }//end OSnLNodeMax
00580 
00581 OSnLNodeMax::~OSnLNodeMax(){
00582         #ifdef DEBUGOSNLNODE
00583         cout << "inside OSnLNodeMax destructor" << endl;
00584         #endif
00585         if(inumberOfChildren > 0){
00586                 for(unsigned int i = 0; i < inumberOfChildren; i++){
00587                         delete m_mChildren[ i];
00588                         m_mChildren[i] = NULL;
00589                 }
00590         }
00591         //m_mChildren = NULL;
00592         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00593 }//end ~OSnLNodeMax
00594 
00595 double OSnLNodeMax::calculateFunction(double *x){
00596         m_dFunctionValue = m_mChildren[0]->calculateFunction(x);
00597         if(inumberOfChildren > 1){
00598                 for(unsigned int i = 1; i < inumberOfChildren; i++){
00599                         if(m_mChildren[i]->calculateFunction(x) > m_dFunctionValue){
00600                                 m_dFunctionValue =      m_mChildren[i]->calculateFunction(x);
00601                         }
00602                 }
00603         }
00604         return m_dFunctionValue;
00605 }// end OSnLNodeMax::calculate
00606 
00607 std::string OSnLNodeMax::getTokenName(){
00608         return "max";
00609 }// end OSnLNodeMax::getTokenName(
00610 
00611 
00612 ADdouble OSnLNodeMax::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00613         //if not support in AD, throw an exception
00614         try{
00615                 throw ErrorClass("Max operator not supported by current Algorithmic Differentiation implementation");
00616                 return m_ADTape;
00617         }
00618         catch(const ErrorClass& eclass){
00619                 throw ErrorClass( eclass.errormsg);
00620         }
00621 }// end OSnLNodeMax::constructADTape
00622 
00623 
00624 OSnLNode* OSnLNodeMax::cloneOSnLNode(){
00625         OSnLNode *nlNodePoint;
00626         nlNodePoint = new OSnLNodeMax();
00627         return  nlNodePoint;
00628 }//end OSnLNodeMax::cloneOSnLNode
00629 //
00630 
00631 
00632 
00633 //
00634 // OSnLNodeMin Methods  
00635 OSnLNodeMin::OSnLNodeMin()
00636 {
00637         inumberOfChildren = 0;
00638         inodeInt = 4010;
00639         inodeType = -1;
00640 }//end OSnLNodeMin
00641 
00642 OSnLNodeMin::~OSnLNodeMin(){
00643         #ifdef DEBUGOSNLNODE
00644         cout << "inside OSnLNodeMin destructor" << endl;
00645         #endif
00646         if(inumberOfChildren > 0){
00647                 for(unsigned int i = 0; i < inumberOfChildren; i++){
00648                         delete m_mChildren[ i];
00649                         m_mChildren[i] = NULL;
00650                 }
00651         }
00652         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00653         //m_mChildren = NULL;
00654 }//end ~OSnLNodeMin
00655 
00656 
00657 std::string OSnLNodeMin::getTokenName(){
00658         return "min";
00659 }// end OSnLNodeMin::getTokenName(
00660 
00661 double OSnLNodeMin::calculateFunction(double *x){
00662         m_dFunctionValue = m_mChildren[0]->calculateFunction(x);
00663         if(inumberOfChildren > 1){
00664                 for(unsigned int i = 1; i < inumberOfChildren; i++){
00665                         if(m_mChildren[i]->calculateFunction(x) < m_dFunctionValue){
00666                                 m_dFunctionValue =      m_mChildren[i]->calculateFunction(x);
00667                         }
00668                 }
00669         }
00670         return m_dFunctionValue;
00671 }// end OSnLNodeMin::calculate
00672 
00673 
00674 ADdouble OSnLNodeMin::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00675         //if not support in AD, throw an exception
00676         try{
00677                 throw ErrorClass("Min operator not supported by current Algorithmic Differentiation implementation");
00678                 return m_ADTape;
00679         }
00680         catch(const ErrorClass& eclass){
00681                 throw ErrorClass( eclass.errormsg);
00682         }
00683 }// end OSnLNodeMin::constructADTape
00684 
00685 
00686 OSnLNode* OSnLNodeMin::cloneOSnLNode(){
00687         OSnLNode *nlNodePoint;
00688         nlNodePoint = new OSnLNodeMin();
00689         return  nlNodePoint;
00690 }//end OSnLNodeMin::cloneOSnLNode
00691 //
00692 
00693 
00694 //
00695 //
00696 // OSnLNodeMinus Methods        
00697 OSnLNodeMinus::OSnLNodeMinus()
00698 {
00699         inumberOfChildren = 2;
00700         m_mChildren = new OSnLNode*[2];
00701         m_mChildren[ 0] = NULL;
00702         m_mChildren[ 1] = NULL;
00703         inodeInt = 1003;
00704         inodeType = 2;
00705 }//end OSnLNodeMinus
00706 
00707  
00708 OSnLNodeMinus::~OSnLNodeMinus(){
00709         #ifdef DEBUGOSNLNODE
00710         cout << "inside OSnLNodeMinus destructor" << endl;
00711         #endif
00712         for(unsigned int i = 0; i < inumberOfChildren; i++){
00713                 delete m_mChildren[ i];
00714                 m_mChildren[i] = NULL;
00715         }
00716         //m_mChildren = NULL;
00717         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00718 }//end ~OSnLNodeMinus
00719 
00720 std::string OSnLNodeMinus::getTokenName(){
00721         return "minus";
00722 }// end OSnLNodeSum::getTokenName(
00723 
00724 double OSnLNodeMinus::calculateFunction(double *x){
00725         m_dFunctionValue =  m_mChildren[0]->calculateFunction( x) - m_mChildren[1]->calculateFunction( x);
00726         return m_dFunctionValue;
00727 }// end OSnLNodeMinus::calculate
00728 
00729 
00730 ADdouble OSnLNodeMinus::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00731         m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) - m_mChildren[1]->constructADTape( ADIdx, XAD);
00732         return m_ADTape;
00733 }// end OSnLNodeMinus::constructADTape
00734 
00735 
00736 OSnLNode* OSnLNodeMinus::cloneOSnLNode(){
00737         OSnLNode *nlNodePoint;
00738         nlNodePoint = new OSnLNodeMinus();
00739         return  nlNodePoint;
00740 }//end OSnLNodeMinus::cloneOSnLNode
00741 //
00742 //
00743 
00744  
00745 //
00746 //
00747 // OSnLNodeNegate Methods       
00748 OSnLNodeNegate::OSnLNodeNegate()
00749 {
00750         inumberOfChildren = 1;
00751         m_mChildren = new OSnLNode*[1];
00752         m_mChildren[ 0] = NULL;
00753         inodeInt = 1004;
00754         inodeType = 1;
00755 }//end OSnLNodeNegate
00756 
00757  
00758 OSnLNodeNegate::~OSnLNodeNegate(){
00759         #ifdef DEBUGOSNLNODE
00760         cout << "inside OSnLNodeNegate destructor" << endl;
00761         #endif
00762         for(unsigned int i = 0; i < inumberOfChildren; i++){
00763                 delete m_mChildren[ i];
00764                 m_mChildren[i] = NULL;
00765         }
00766         //m_mChildren = NULL;
00767         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00768 }//end ~OSnLNodeNegate
00769 
00770 std::string OSnLNodeNegate::getTokenName(){
00771         return "negate";
00772 }// end OSnLNodeNegate::getTokenName(
00773 
00774 double OSnLNodeNegate::calculateFunction(double *x){
00775         m_dFunctionValue =  -m_mChildren[0]->calculateFunction( x) ;
00776         return m_dFunctionValue;
00777 }// end OSnLNodeMinus::calculate
00778 
00779 ADdouble OSnLNodeNegate::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00780         m_ADTape = -m_mChildren[0]->constructADTape( ADIdx, XAD);
00781         return m_ADTape;
00782 }// end OSnLNodeNegate::constructADTape
00783 
00784 
00785 OSnLNode* OSnLNodeNegate::cloneOSnLNode(){
00786         OSnLNode *nlNodePoint;
00787         nlNodePoint = new OSnLNodeNegate();
00788         return  nlNodePoint;
00789 }//end OSnLNodeNegate::cloneOSnLNode
00790 //
00791 //
00792 
00793 // OSnLNodeTimes Methods        
00794 OSnLNodeTimes::OSnLNodeTimes()
00795 {
00796         inumberOfChildren = 2;
00797         m_mChildren = new OSnLNode*[2];
00798         m_mChildren[ 0] = NULL;
00799         m_mChildren[ 1] = NULL;
00800         inodeInt = 1005;
00801         inodeType = 2;
00802 }//end OSnLNodeTimes
00803 
00804  
00805 OSnLNodeTimes::~OSnLNodeTimes(){
00806         #ifdef DEBUGOSNLNODE
00807         cout << "inside OSnLNodeTimes destructor" << endl;
00808         #endif
00809         for(unsigned int i = 0; i < inumberOfChildren; i++){
00810                 delete m_mChildren[ i];
00811                 m_mChildren[i] = NULL;
00812         }
00813         //m_mChildren = NULL;
00814         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00815 }//end ~OSnLNodeTimes
00816 
00817 std::string OSnLNodeTimes::getTokenName(){
00818         return "times";
00819 }// end OSnLNodeTimes::getTokenName(
00820 
00821 double OSnLNodeTimes::calculateFunction(double *x){
00822         m_dFunctionValue = m_mChildren[0]->calculateFunction( x)*m_mChildren[1]->calculateFunction( x);
00823         return m_dFunctionValue;
00824 }// end OSnLNodeTimes::calculate
00825 
00826 
00827 ADdouble OSnLNodeTimes::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00828         m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) * m_mChildren[1]->constructADTape( ADIdx, XAD);
00829         return m_ADTape;
00830 }// end OSnLNodeTimes::constructADTape
00831 
00832 OSnLNode* OSnLNodeTimes::cloneOSnLNode(){
00833         OSnLNode *nlNodePoint;
00834         nlNodePoint = new OSnLNodeTimes();
00835         return  nlNodePoint;
00836 }//end OSnLNodeTimes::cloneOSnLNode
00837 
00838 //
00839 //
00840 // OSnLNodeDivide Methods       
00841 OSnLNodeDivide::OSnLNodeDivide()
00842 {
00843         inumberOfChildren = 2;
00844         m_mChildren = new OSnLNode*[2];
00845         m_mChildren[ 0] = NULL;
00846         m_mChildren[ 1] = NULL;
00847         inodeInt = 1006;
00848         inodeType = 2;
00849 }//end OSnLNodeDivide
00850 
00851  
00852 OSnLNodeDivide::~OSnLNodeDivide(){
00853         #ifdef DEBUGOSNLNODE
00854         cout << "inside OSnLNodeDivide destructor" << endl;
00855         #endif
00856         for(unsigned int i = 0; i < inumberOfChildren; i++){
00857                 delete m_mChildren[ i];
00858                 m_mChildren[i] = NULL;
00859         }
00860         //m_mChildren = NULL;
00861         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00862 }//end ~OSnLNodeDivide
00863 
00864 std::string OSnLNodeDivide::getTokenName(){
00865         return "divide";
00866 }// end OSnLNodeDivide::getTokenName(
00867 
00868 double OSnLNodeDivide::calculateFunction(double *x){
00869         // kipp throw error if we divide by 0
00870         m_dFunctionValue = m_mChildren[0]->calculateFunction( x)/m_mChildren[1]->calculateFunction( x);
00871         return m_dFunctionValue;
00872 }// end OSnLNodeDivide::calculate
00873 
00874 
00875 ADdouble OSnLNodeDivide::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00876         m_ADTape = m_mChildren[0]->constructADTape( ADIdx, XAD) / m_mChildren[1]->constructADTape( ADIdx, XAD);
00877         return m_ADTape;
00878 }// end OSnLNodeDivide::constructADTape
00879 
00880 
00881 OSnLNode* OSnLNodeDivide::cloneOSnLNode(){
00882         OSnLNode *nlNodePoint;
00883         nlNodePoint = new OSnLNodeDivide();
00884         return  nlNodePoint;
00885 }//end OSnLNodeDivide::cloneOSnLNode
00886 
00887 
00888 //
00889 // OSnLNodePower Methods        
00890 OSnLNodePower::OSnLNodePower()
00891 {
00892         inumberOfChildren = 2;
00893         m_mChildren = new OSnLNode*[2];
00894         m_mChildren[ 0] = NULL;
00895         m_mChildren[ 1] = NULL;
00896         inodeInt = 1009;
00897         inodeType = 2;
00898 }//end OSnLNodePower
00899 
00900  
00901 OSnLNodePower::~OSnLNodePower(){
00902         #ifdef DEBUGOSNLNODE
00903         cout << "inside OSnLNodePower destructor" << endl;
00904         #endif
00905         for(unsigned int i = 0; i < inumberOfChildren; i++){
00906                 delete m_mChildren[ i];
00907                 m_mChildren[i] = NULL;
00908         }
00909         //m_mChildren = NULL;
00910         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00911 }//end ~OSnLNodePower 
00912 
00913 std::string OSnLNodePower::getTokenName(){
00914         return "power";
00915 }// end OSnLNodePower::getTokenName(
00916 
00917 double OSnLNodePower::calculateFunction(double *x){
00918         // kipp throw error if operation not defined
00919         m_dFunctionValue =  pow(m_mChildren[0]->calculateFunction( x), m_mChildren[1]->calculateFunction( x));
00920         return  m_dFunctionValue;
00921 }// end OSnLNodePower::calculate
00922 
00923 //
00924 ADdouble OSnLNodePower::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
00925         //if( typeid( *m_mChildren[1]) == typeid( OSnLNodeNumber) ) {
00926         if( this->m_mChildren[1]->inodeInt == 5001 ) {
00927                 OSnLNodeNumber *numberNode  =  (OSnLNodeNumber*)m_mChildren[1];
00928                 // we have a number node see if interger
00929                 if( (numberNode->value) == int( numberNode->value)){
00930                         m_ADTape =  pow(m_mChildren[0]->constructADTape( ADIdx, XAD) ,  int( numberNode->value));
00931                 }       
00932                 else m_ADTape = pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , m_mChildren[1]->constructADTape( ADIdx, XAD) );      
00933         }
00934         else{
00935                 m_ADTape = pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , m_mChildren[1]->constructADTape( ADIdx, XAD) );   
00936         }
00937         return m_ADTape;
00938 }// end OSnLNodePower::constructADTape
00939 
00940 
00941 
00942 //ADdouble OSnLNodePower::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){  
00943 //              m_ADTape = AD::pow(m_mChildren[0]->constructADTape( ADIdx, XAD) , m_mChildren[1]->constructADTape( ADIdx, XAD) );       
00944 //      return m_ADTape;
00945 //}// end OSnLNodePower::constructADTape
00946 
00947 
00948 
00949 
00950 
00951 OSnLNode* OSnLNodePower::cloneOSnLNode(){
00952         OSnLNode *nlNodePoint;
00953         nlNodePoint = new OSnLNodePower();
00954         return  nlNodePoint;
00955 }//end OSnLNodePower::cloneOSnLNode
00956 //
00957 //
00958 
00959 
00960 //
00961 // OSnLNodePower Methods        
00962 OSnLNodeProduct::OSnLNodeProduct()
00963 {
00964         inumberOfChildren = 0;
00965         inodeInt = 1010;
00966         inodeType = -1;
00967 }//end OSnLNodeProduct
00968 
00969  
00970 OSnLNodeProduct::~OSnLNodeProduct(){
00971         #ifdef DEBUGOSNLNODE
00972         cout << "inside OSnLNodeProduct destructor" << endl;
00973         #endif
00974         if(inumberOfChildren > 0){
00975                 for(unsigned int i = 0; i < inumberOfChildren; i++){
00976                         delete m_mChildren[ i];
00977                         m_mChildren[i] = NULL;
00978                 }
00979         }
00980         //m_mChildren = NULL;
00981         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
00982 }//end ~OSnLNodeProduct
00983 
00984 std::string OSnLNodeProduct::getTokenName(){
00985         return "product";
00986 }// end OSnLNodeProduct::getTokenName(
00987 
00988 double OSnLNodeProduct::calculateFunction(double *x){
00989         // kipp throw error if operation not defined
00990         m_dFunctionValue = 1.0;
00991         unsigned int i;
00992         for(i = 0; i < inumberOfChildren; i++){
00993                 m_dFunctionValue = m_dFunctionValue*m_mChildren[i]->calculateFunction(x);
00994         }
00995         return m_dFunctionValue;
00996 }// end OSnLNodeProduct::calculate
00997 
00998 
00999 ADdouble OSnLNodeProduct::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01000         m_ADTape = 1.0;
01001         unsigned int i;
01002         for(i = 0; i < inumberOfChildren; i++){
01003                 m_ADTape = m_ADTape*m_mChildren[i]->constructADTape( ADIdx, XAD);
01004         }
01005         return m_ADTape;
01006 }// end OSnLNodeProduct::constructADTape
01007 
01008 
01009 OSnLNode* OSnLNodeProduct::cloneOSnLNode(){
01010         OSnLNode *nlNodePoint;
01011         nlNodePoint = new OSnLNodeProduct();
01012         return  nlNodePoint;
01013 }//end OSnLNodeProduct::cloneOSnLNode
01014 //
01015 //
01016 
01017 
01018 //
01019 // OSnLNodeLn Methods   
01020 OSnLNodeLn::OSnLNodeLn()
01021 {
01022         inumberOfChildren = 1;
01023         m_mChildren = new OSnLNode*[1];
01024         m_mChildren[ 0] = NULL;
01025         inodeInt = 2007;
01026         inodeType = 1;
01027 }//end OSnLNodeLn
01028 
01029  
01030 OSnLNodeLn::~OSnLNodeLn(){
01031         #ifdef DEBUGOSNLNODE
01032         cout << "inside OSnLNodeLn destructor" << endl;
01033         #endif
01034         for(unsigned int i = 0; i < inumberOfChildren; i++){
01035                 delete m_mChildren[ i];
01036                 m_mChildren[i] = NULL;
01037         }
01038         //m_mChildren = NULL;
01039         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01040 }//end ~OSnLNodeLn
01041 
01042 std::string OSnLNodeLn::getTokenName(){
01043         return "ln";
01044 }// end OSnLNodeLn::getTokenName(
01045 
01046 double OSnLNodeLn::calculateFunction(double *x){
01047         m_dFunctionValue = log(m_mChildren[0]->calculateFunction( x) );
01048         return m_dFunctionValue;
01049 }// end OSnLNodeLn::calculate
01050 
01051 
01052 ADdouble OSnLNodeLn::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01053         m_ADTape = log( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01054         return m_ADTape;
01055 }// end OSnLNodeLn::constructADTape
01056 
01057 OSnLNode* OSnLNodeLn::cloneOSnLNode(){
01058         OSnLNode *nlNodePoint;
01059         nlNodePoint = new OSnLNodeLn();
01060         return  nlNodePoint;
01061 }//end OSnLNodeLn::cloneOSnLNode
01062 
01063 
01064 
01065 
01066 
01067 //
01068 // OSnLNodeSqrt Methods 
01069 OSnLNodeSqrt::OSnLNodeSqrt()
01070 {
01071         inumberOfChildren = 1;
01072         m_mChildren = new OSnLNode*[1];
01073         m_mChildren[ 0] = NULL;
01074         inodeInt = 2006;
01075         inodeType = 1;
01076 }//end OSnLNodeSqrt
01077 
01078  
01079 OSnLNodeSqrt::~OSnLNodeSqrt(){
01080         #ifdef DEBUGOSNLNODE
01081         cout << "inside OSnLNodeSqrt destructor" << endl;
01082         #endif
01083         for(unsigned int i = 0; i < inumberOfChildren; i++){
01084                 delete m_mChildren[ i];
01085                 m_mChildren[i] = NULL;
01086         }
01087         //m_mChildren = NULL;
01088         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01089 }//end ~OSnLNodeSqrt
01090 
01091 std::string OSnLNodeSqrt::getTokenName(){
01092         return "sqrt";
01093 }// end OSnLNodeSqrt::getTokenName(
01094 
01095 double OSnLNodeSqrt::calculateFunction(double *x){
01096         m_dFunctionValue = sqrt(m_mChildren[0]->calculateFunction( x) );
01097         return m_dFunctionValue;
01098 }// end OSnLNodeSqrt::calculate
01099 
01100 
01101 ADdouble OSnLNodeSqrt::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01102         m_ADTape = sqrt( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01103         return m_ADTape;
01104 }// end OSnLNodeSqrt::constructADTape
01105 
01106 OSnLNode* OSnLNodeSqrt::cloneOSnLNode(){
01107         OSnLNode *nlNodePoint;
01108         nlNodePoint = new OSnLNodeSqrt();
01109         return  nlNodePoint;
01110 }//end OSnLNodeSqrt::cloneOSnLNode
01111 
01112 
01113 
01114 //
01115 //
01116 // OSnLNodeSquare Methods       
01117 OSnLNodeSquare::OSnLNodeSquare()
01118 {
01119         inumberOfChildren = 1;
01120         m_mChildren = new OSnLNode*[1];
01121         m_mChildren[ 0] = NULL;
01122         inodeInt = 2005;
01123         inodeType = 1;
01124 }//end OSnLNodeSquare
01125 
01126  
01127 OSnLNodeSquare::~OSnLNodeSquare(){
01128         #ifdef DEBUGOSNLNODE
01129         cout << "inside OSnLNodeSquare destructor" << endl;
01130         #endif
01131         for(unsigned int i = 0; i < inumberOfChildren; i++){
01132                 delete m_mChildren[ i];
01133                 m_mChildren[i] = NULL;
01134         }
01135         //m_mChildren = NULL;
01136         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01137 }//end ~OSnLNodeSquare
01138 
01139 std::string OSnLNodeSquare::getTokenName(){
01140         return "square";
01141 }// end OSnLNodeSquare::getTokenName(
01142 
01143 double OSnLNodeSquare::calculateFunction(double *x){
01144         m_dFunctionValue = pow( (m_mChildren[0]->calculateFunction( x) ), 2);
01145         return m_dFunctionValue;
01146 }// end OSnLNodeSquare::calculate
01147 
01148 
01149 ADdouble OSnLNodeSquare::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01150         m_ADTape = pow( m_mChildren[0]->constructADTape( ADIdx, XAD), int( 2) );
01151         return m_ADTape;
01152 }// end OSnLNodeSquare::constructADTape
01153 
01154 OSnLNode* OSnLNodeSquare::cloneOSnLNode(){
01155         OSnLNode *nlNodePoint;
01156         nlNodePoint = new OSnLNodeSquare();
01157         return  nlNodePoint;
01158 }//end OSnLNodeSquare::cloneOSnLNode
01159 
01160 //
01161 //
01162 // OSnLNodeSin Methods  
01163 OSnLNodeSin::OSnLNodeSin()
01164 {
01165         inumberOfChildren = 1;
01166         m_mChildren = new OSnLNode*[1];
01167         m_mChildren[ 0] = NULL;
01168         inodeInt = 3001;
01169         inodeType = 1;
01170 }//end OSnLNodeSin
01171 
01172  
01173 OSnLNodeSin::~OSnLNodeSin(){
01174         #ifdef DEBUGOSNLNODE
01175         cout << "inside OSnLNodeSin destructor" << endl;
01176         #endif
01177         for(unsigned int i = 0; i < inumberOfChildren; i++){
01178                 delete m_mChildren[ i];
01179                 m_mChildren[i] = NULL;
01180         }
01181         //m_mChildren = NULL;
01182         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01183 }//end ~OSnLNodeSin
01184 
01185 std::string OSnLNodeSin::getTokenName(){
01186         return "sin";
01187 }// end OSnLNodeSin::getTokenName(
01188 
01189 double OSnLNodeSin::calculateFunction(double *x){
01190         m_dFunctionValue = sin(m_mChildren[0]->calculateFunction( x) );
01191         return m_dFunctionValue;
01192 }// end OSnLNodeSin::calculate
01193 
01194 
01195 ADdouble OSnLNodeSin::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01196         m_ADTape = sin( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01197         return m_ADTape;
01198 }// end OSnLNodeSin::constructADTape
01199 
01200 OSnLNode* OSnLNodeSin::cloneOSnLNode(){
01201         OSnLNode *nlNodePoint;
01202         nlNodePoint = new OSnLNodeSin();
01203         return  nlNodePoint;
01204 }//end OSnLNodeSin::cloneOSnLNode
01205 
01206 
01207 //
01208 //
01209 // OSnLNodeCos Methods  
01210 OSnLNodeCos::OSnLNodeCos()
01211 {
01212         inumberOfChildren = 1;
01213         m_mChildren = new OSnLNode*[1];
01214         m_mChildren[ 0] = NULL;
01215         inodeInt = 3002;
01216         inodeType = 1;
01217 }//end OSnLNodeCos
01218 
01219  
01220 OSnLNodeCos::~OSnLNodeCos(){
01221         #ifdef DEBUGOSNLNODE
01222         cout << "inside OSnLNodeCos 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 ~OSnLNodeCos
01231 
01232 std::string OSnLNodeCos::getTokenName(){
01233         return "cos";
01234 }// end OSnLNodeCos::getTokenName(
01235 
01236 double OSnLNodeCos::calculateFunction(double *x){
01237         m_dFunctionValue = cos(m_mChildren[0]->calculateFunction( x) );
01238         return m_dFunctionValue;
01239 }// end OSnLNodeCos::calculate
01240 
01241 
01242 ADdouble OSnLNodeCos::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01243         m_ADTape = cos( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01244         return m_ADTape;
01245 }// end OSnLNodeCos::constructADTape
01246 
01247 OSnLNode* OSnLNodeCos::cloneOSnLNode(){
01248         OSnLNode *nlNodePoint;
01249         nlNodePoint = new OSnLNodeCos();
01250         return  nlNodePoint;
01251 }//end OSnLNodeCos::cloneOSnLNode
01252 
01253 
01254 
01255 
01256 //
01257 //
01258 // OSnLNodeExp Methods  
01259 OSnLNodeExp::OSnLNodeExp()
01260 {
01261         inumberOfChildren = 1;
01262         m_mChildren = new OSnLNode*[1];
01263         m_mChildren[ 0] = NULL;
01264         inodeInt = 2010;
01265         inodeType = 1;
01266 }//end OSnLNodeExp
01267 
01268  
01269 OSnLNodeExp::~OSnLNodeExp(){
01270         #ifdef DEBUGOSNLNODE
01271         cout << "inside OSnLNodeExp destructor" << endl;
01272         #endif
01273         for(unsigned int i = 0; i < inumberOfChildren; i++){
01274                 delete m_mChildren[ i];
01275                 m_mChildren[i] = NULL;
01276         }
01277         //m_mChildren = NULL;
01278         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01279 }//end ~OSnLNodeExp
01280 
01281 std::string OSnLNodeExp::getTokenName(){
01282         return "exp";
01283 }// end OSnLNodeExp::getTokenName(
01284 
01285 double OSnLNodeExp::calculateFunction(double *x){
01286         m_dFunctionValue = exp(m_mChildren[0]->calculateFunction( x) );
01287         return m_dFunctionValue;
01288 }// end OSnLNodeExp::calculate
01289 
01290 
01291 ADdouble OSnLNodeExp::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01292         m_ADTape = exp( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01293         return m_ADTape;
01294 }// end OSnLNodeExp::constructADTape
01295 
01296 OSnLNode* OSnLNodeExp::cloneOSnLNode(){
01297         OSnLNode *nlNodePoint;
01298         nlNodePoint = new OSnLNodeExp();
01299         return  nlNodePoint;
01300 }//end OSnLNodeExp::cloneOSnLNode
01301 //
01302 //
01303 
01304 
01305 
01306 //
01307 // OSnLNodeAbs Methods  
01308 OSnLNodeAbs::OSnLNodeAbs()
01309 {
01310         inumberOfChildren = 1;
01311         m_mChildren = new OSnLNode*[1];
01312         m_mChildren[ 0] = NULL;
01313         inodeInt = 2001;
01314         inodeType = 1;
01315 }//end OSnLNodeLn
01316 
01317  
01318 OSnLNodeAbs::~OSnLNodeAbs(){
01319         #ifdef DEBUGOSNLNODE
01320         cout << "inside OSnLNodeAbs destructor" << endl;
01321         #endif
01322         for(unsigned int i = 0; i < inumberOfChildren; i++){
01323                 delete m_mChildren[ i];
01324                 m_mChildren[i] = NULL;
01325         }
01326         //m_mChildren = NULL;
01327         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01328 }//end ~OSnLNodeAbs
01329 
01330 std::string OSnLNodeAbs::getTokenName(){
01331         return "abs";
01332 }// end OSnLNodeAbs::getTokenName(
01333 
01334 double OSnLNodeAbs::calculateFunction(double *x){
01335         m_dFunctionValue = fabs(m_mChildren[0]->calculateFunction( x) );
01336         return m_dFunctionValue;
01337 }// end OSnLNodeAbs::calculate
01338 
01339 
01340 ADdouble OSnLNodeAbs::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01341         m_ADTape = abs( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01342         return m_ADTape;
01343 }// end OSnLNodeAbs::constructADTape
01344 
01345 OSnLNode* OSnLNodeAbs::cloneOSnLNode(){
01346         OSnLNode *nlNodePoint;
01347         nlNodePoint = new OSnLNodeAbs();
01348         return  nlNodePoint;
01349 }//end OSnLNodeAbs::cloneOSnLNode
01350 //
01351 //
01352 
01353 
01354 
01355 
01356 //
01357 // OSnLNodeErf Methods  
01358 OSnLNodeErf::OSnLNodeErf()
01359 {
01360         inumberOfChildren = 1;
01361         m_mChildren = new OSnLNode*[1];
01362         m_mChildren[ 0] = NULL;
01363         inodeInt = 4625;
01364         inodeType = 1;
01365 }//end OSnLNodeErf
01366 
01367  
01368 OSnLNodeErf::~OSnLNodeErf(){
01369         #ifdef DEBUGOSNLNODE
01370         cout << "inside OSnLNodeErf destructor" << endl;
01371         #endif
01372         for(unsigned int i = 0; i < inumberOfChildren; i++){
01373                 delete m_mChildren[ i];
01374                 m_mChildren[i] = NULL;
01375         }
01376         //m_mChildren = NULL;
01377         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01378 }//end ~OSnLNodeErf
01379 
01380 std::string OSnLNodeErf::getTokenName(){
01381         return "erf";
01382 }// end OSnLNodeErf::getTokenName(
01383 
01384 double OSnLNodeErf::calculateFunction(double *x){
01385         m_dFunctionValue = fabs(m_mChildren[0]->calculateFunction( x) );
01386         return m_dFunctionValue;
01387 }// end OSnLNodeErf::calculate
01388 
01389 
01390 ADdouble OSnLNodeErf::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01391         const double a = (993./880.);
01392         const double b =  (89./880.); 
01393 
01394         //tanh( (a + b * x * x) * x );
01395         //m_ADTape = CppAD::erf( m_mChildren[0]->constructADTape( ADIdx, XAD) );
01396         m_ADTape = tanh( (a + b * m_mChildren[0]->constructADTape( ADIdx, XAD) * m_mChildren[0]->constructADTape( ADIdx, XAD)) * m_mChildren[0]->constructADTape( ADIdx, XAD) );
01397 
01398         return m_ADTape;
01399 }// end OSnLNodeErf::constructADTape
01400 
01401 OSnLNode* OSnLNodeErf::cloneOSnLNode(){
01402         OSnLNode *nlNodePoint;
01403         nlNodePoint = new OSnLNodeErf();
01404         return  nlNodePoint;
01405 }//end OSnLNodeErf::cloneOSnLNode
01406 //
01407 //
01408 
01409 
01410 
01411 //
01412 // OSnLNodeIf Methods   
01413 OSnLNodeIf::OSnLNodeIf()
01414 {
01415         inumberOfChildren = 3;
01416         m_mChildren = new OSnLNode*[3];
01417         m_mChildren[ 0] = NULL;
01418         m_mChildren[ 1] = NULL;
01419         m_mChildren[ 2] = NULL;
01420         inodeInt = 7001;
01421         inodeType = 3;
01422 }//end OSnLNodeIf
01423 
01424  
01425 OSnLNodeIf::~OSnLNodeIf(){
01426         #ifdef DEBUGOSNLNODE
01427         cout << "inside OSnLNodeIf destructor" << endl;
01428         #endif 
01429         for(unsigned int i = 0; i < inumberOfChildren; i++){
01430                 delete m_mChildren[ i];
01431                 m_mChildren[i] = NULL;
01432         }
01433         //m_mChildren = NULL;
01434         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01435 }//end ~OSnLNodeIf
01436 
01437 std::string OSnLNodeIf::getTokenName(){
01438         return "if";
01439 }// end OSnLNodeIf::getTokenName(
01440 
01441 double OSnLNodeIf::calculateFunction(double *x){
01442         if(m_mChildren[0]->calculateFunction( x)  >= 0) m_dFunctionValue = m_mChildren[ 1]->calculateFunction( x);
01443                 else m_dFunctionValue = m_mChildren[ 2]->calculateFunction( x);
01444         return m_dFunctionValue;
01445 }// end OSnLNodeIf::calculate
01446 
01447 ADdouble OSnLNodeIf::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01448         //if not support in AD, throw an exception
01449         try{
01450                 throw ErrorClass("if operator not supported by current Algorithmic Differentiation implementation");
01451                 return m_ADTape;
01452         }
01453         catch(const ErrorClass& eclass){
01454                 throw ErrorClass( eclass.errormsg);
01455         }
01456 }// end OSnLNodeIf::constructADTape
01457 
01458 OSnLNode* OSnLNodeIf::cloneOSnLNode(){
01459         OSnLNode *nlNodePoint;
01460         nlNodePoint = new OSnLNodeIf();
01461         return  nlNodePoint;
01462 }//end OSnLNodeIf::cloneOSnLNode
01463 //
01464 //
01465 
01466 
01467 // OSnLNodeNumber Methods       
01468 OSnLNodeNumber::OSnLNodeNumber()
01469 {
01470         inodeInt = 5001;
01471         inumberOfChildren = 0;
01472         m_mChildren = NULL;
01473         inodeType = 0;  
01474         value = 0.0;
01475         type = "real";
01476         id = "";
01477 
01478 }//end OSnLNodeNumber
01479 
01480 OSnLNodeNumber::~OSnLNodeNumber(){
01481         #ifdef DEBUGOSNLNODE
01482         cout << "inside OSnLNodeNumber destructor" << endl;
01483         #endif
01484         m_mChildren = NULL;
01485 }//end ~OSnLNodeNumber
01486 
01487 std::string OSnLNodeNumber::getTokenNumber(){
01488         ostringstream outStr;
01489         outStr << inodeInt;
01490         outStr << ":" ;
01491         outStr << value ;
01492         //if(type.length() > 0){
01493                 outStr << ":" ;
01494                 outStr << type ;
01495         //}
01496         //if(id.length() > 0){
01497                 outStr << ":" ;
01498                 outStr << id;
01499         //}
01500         return outStr.str();
01501 }//getTokenNumber
01502 
01503 
01504 std::string OSnLNodeNumber::getTokenName(){
01505         ostringstream outStr;
01506         outStr << "number";
01507         outStr << ":" ;
01508         outStr << value ;
01509         //if(type.length() > 0){
01510                 outStr << ":" ;
01511                 outStr << type ;
01512         //}
01513         //if(id.length() > 0){
01514                 outStr << ":" ;
01515                 outStr << id;
01516         //}
01517         return outStr.str();
01518 }//getTokenName
01519 
01520 
01521 std::string OSnLNodeNumber::getNonlinearExpressionInXML(){
01522         ostringstream outStr;
01523         outStr << "<" ;
01524         outStr << this->getTokenName();
01525                 outStr << "  value=\"";
01526                 outStr << os_dtoa_format(value); 
01527                 outStr << "\"";
01528                 outStr << " type=\"";
01529                 outStr << type ;
01530                 outStr << "\"";
01531                 if(id.length() > 0){
01532                         outStr << "  id=\"";
01533                         outStr << id ;
01534                         outStr << "\"";
01535                 }
01536                 outStr << "/>";
01537         return outStr.str();
01538 }//getNonlinearExpressionInXML()
01539 
01540 
01541 double OSnLNodeNumber::calculateFunction(double *x){
01542         m_dFunctionValue = this->value;
01543         return m_dFunctionValue;
01544 }// end OSnLNodeNumber::calculate
01545 
01546 ADdouble OSnLNodeNumber::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01547         m_ADTape =  this->value;
01548         return m_ADTape;
01549 }// end OSnLNodeNumber::constructADTape
01550 
01551 OSnLNode* OSnLNodeNumber::cloneOSnLNode(){
01552         OSnLNode *nlNodePoint;
01553         nlNodePoint = new OSnLNodeNumber();
01554         return  nlNodePoint;
01555 }//end OSnLNodeNumber::cloneOSnLNode
01556 // edn OSnLNodeNumber methods
01557 
01558 
01559 // OSnLNodeE Methods    
01560 OSnLNodeE::OSnLNodeE()
01561 {
01562         inodeInt = 5004;
01563         inumberOfChildren = 0;
01564         m_mChildren = NULL;
01565         inodeType = 0;  
01566         //value = 0.0;
01567         //type = "real";
01568         //id = "";
01569 
01570 }//end OSnLNodeE
01571 
01572 OSnLNodeE::~OSnLNodeE(){
01573         #ifdef DEBUGOSNLNODE
01574         cout << "inside OSnLNodeE destructor" << endl;
01575         #endif
01576         m_mChildren = NULL;
01577 }//end ~OSnLNodeE
01578 
01579 
01580 
01581 std::string OSnLNodeE::getTokenNumber(){
01582         ostringstream outStr;
01583         outStr << inodeInt;
01584         //outStr << ":" ;
01585         //outStr << value ;
01586         //if(type.length() > 0){
01587         //      outStr << ":" ;
01588         //      outStr << type ;
01589         //}
01590         //if(id.length() > 0){
01591         //      outStr << ":" ;
01592         //      outStr << id;
01593         //}
01594         return outStr.str();
01595 }//getTokenNumber
01596 
01597 
01598 std::string OSnLNodeE::getTokenName(){
01599         ostringstream outStr;
01600         outStr << "E";
01601         //outStr << ":" ;
01602         //outStr << value ;
01603         //if(type.length() > 0){
01604         //      outStr << ":" ;
01605         //      outStr << type ;
01606         //}
01607         //if(id.length() > 0){
01608         //      outStr << ":" ;
01609         //      outStr << id;
01610         //}
01611         return outStr.str();
01612 }//getTokenName
01613 
01614 
01615 std::string OSnLNodeE::getNonlinearExpressionInXML(){
01616         ostringstream outStr;
01617         outStr << "<" ;
01618         outStr << "E";
01619 //              outStr << "  value=\"";
01620 //              outStr << value ;
01621 //              outStr << "\"";
01622 //              outStr << " type=\"";
01623 //              outStr << type ;
01624 //              outStr << "\"";
01625 //              if(id.length() > 0){
01626 //                      outStr << "  id=\"";
01627 //                      outStr << id ;
01628 //                      outStr << "\"";
01629 //              }
01630                 outStr << "/>";
01631         return outStr.str();
01632 }//getNonlinearExpressionInXML()
01633 
01634 
01635 double OSnLNodeE::calculateFunction(double *x){
01636         m_dFunctionValue = OS_E_VALUE;
01637         return m_dFunctionValue;
01638 }// end OSnLNodeE::calculate
01639 
01640 ADdouble OSnLNodeE::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01641         m_ADTape =  OS_E_VALUE;
01642         return m_ADTape;
01643 }// end OSnLE::constructADTape
01644 
01645 OSnLNode* OSnLNodeE::cloneOSnLNode(){
01646         OSnLNode *nlNodePoint;
01647         nlNodePoint = new OSnLNodeE();
01648         return  nlNodePoint;
01649 }//end OSnLNodeE::cloneOSnLNode
01650 
01651 //end OSnLNodeE
01652 
01653 
01654 // OSnLNodePI Methods   
01655 OSnLNodePI::OSnLNodePI()
01656 {
01657         inodeInt = 5003;
01658         inumberOfChildren = 0;
01659         m_mChildren = NULL;
01660         inodeType = 0;  
01661 
01662 
01663 }//end OSnLNodePI
01664 
01665 
01666 OSnLNodePI::~OSnLNodePI(){
01667         #ifdef DEBUGOSNLNODE
01668         cout << "inside OSnLNodePI destructor" << endl;
01669         #endif
01670         m_mChildren = NULL;
01671 }//end ~OSnLNodePI
01672 
01673 
01674 std::string OSnLNodePI::getTokenNumber(){
01675         ostringstream outStr;
01676         outStr << inodeInt;
01677         //outStr << ":" ;
01678         //outStr << value ;
01679         //if(type.length() > 0){
01680         //      outStr << ":" ;
01681         //      outStr << type ;
01682         //}
01683         //if(id.length() > 0){
01684         //      outStr << ":" ;
01685         //      outStr << id;
01686         //}
01687         return outStr.str();
01688 }//getTokenNumber
01689 
01690 
01691 std::string OSnLNodePI::getTokenName(){
01692         ostringstream outStr;
01693         outStr << "PI";
01694         //outStr << ":" ;
01695         //outStr << value ;
01696         //if(type.length() > 0){
01697                 //outStr << ":" ;
01698                 //outStr << type ;
01699         //}
01700         //if(id.length() > 0){
01701                 //outStr << ":" ;
01702                 //outStr << id;
01703         //}
01704         return outStr.str();
01705 }//getTokenName
01706 
01707 
01708 std::string OSnLNodePI::getNonlinearExpressionInXML(){
01709         ostringstream outStr;
01710         outStr << "<" ;
01711         outStr << "PI";
01712 //              outStr << "  value=\"";
01713 //              outStr << value ;
01714 //              outStr << "\"";
01715 //              outStr << " type=\"";
01716 //              outStr << type ;
01717 //              outStr << "\"";
01718 //              if(id.length() > 0){
01719 //                      outStr << "  id=\"";
01720 //                      outStr << id ;
01721 //                      outStr << "\"";
01722 //              }
01723                 outStr << "/>";
01724         return outStr.str();
01725 }//getNonlinearExpressionInXML()
01726 
01727 
01728 double OSnLNodePI::calculateFunction(double *x){
01729         m_dFunctionValue = OS_PI_VALUE;
01730         return m_dFunctionValue;
01731 }// end OSnLNodePI::calculate
01732 
01733 ADdouble OSnLNodePI::constructADTape(std::map<int, int> *ADIdx, vector< ADdouble > *XAD){
01734         m_ADTape =  OS_PI_VALUE;
01735         return m_ADTape;
01736 }// end OSnLE::constructADTape
01737 
01738 OSnLNode* OSnLNodePI::cloneOSnLNode(){
01739         OSnLNode *nlNodePoint;
01740         nlNodePoint = new OSnLNodePI();
01741         return  nlNodePoint;
01742 }//end OSnLNodePI::cloneOSnLNode
01743 
01744 //end OSnLNodePI methods
01745 
01746 // OSnLNodeVariable Methods     
01747 OSnLNodeVariable::OSnLNodeVariable()
01748 {
01749         inumberOfChildren = 0;
01750         m_mChildren = NULL;
01751         inodeInt = 6001;
01752         inodeType = -1;
01753         coef = 1.0;
01754         idx = -1;
01755 }//end OSnLNodeVariable
01756 
01757 OSnLNodeVariable::~OSnLNodeVariable(){
01758         #ifdef DEBUGOSNLNODE
01759         cout << "inside OSnLNodeVariable destructor" << endl;
01760         cout << "number kids = " <<  inumberOfChildren << endl;
01761         #endif
01762         if(inumberOfChildren > 0){
01763                 for(unsigned int i = 0; i < inumberOfChildren; i++){
01764                         delete m_mChildren[ i];
01765                         m_mChildren[i] = NULL;
01766                 }
01767         }
01768         //m_mChildren = NULL;
01769         if(inumberOfChildren > 0 && m_mChildren != NULL) delete[]  m_mChildren;
01770 }//end ~OSnLNodeVariable
01771 
01772 
01773 std::string OSnLNodeVariable::getTokenNumber(){
01774         ostringstream outStr;
01775         // put in an error if inodeInt is not 6001
01776         outStr << inodeInt;
01777         outStr << "[";
01778         outStr << inumberOfChildren ;
01779         outStr << "]";
01780         outStr << ":" ;
01781         outStr << idx;
01782         outStr << ":" ;
01783         outStr << coef;
01784         outStr << ":real:" ;
01785         return outStr.str();
01786 }//getTokenNumber
01787 
01788 
01789 std::string OSnLNodeVariable::getTokenName(){
01790         ostringstream outStr;
01791         // put in an error if inodeInt is not 6001
01792         outStr << "variable";
01793         outStr << "[";
01794         outStr << inumberOfChildren ;
01795         outStr << "]";
01796         outStr << ":" ;
01797         outStr << idx;
01798         outStr << ":" ;
01799         outStr << coef;
01800         outStr << ":real:" ;
01801         return outStr.str();
01802 }//getTokenNumber
01803 
01804 
01805 std::string OSnLNodeVariable::getNonlinearExpressionInXML(){
01806         ostringstream outStr;
01807         outStr << "<" ;
01808         outStr << "variable";
01809                 outStr << "  idx=\"";
01810                 outStr << idx ;
01811                 outStr << "\"";
01812                 outStr << "  coef=\"";
01813                 outStr << os_dtoa_format(coef);
01814                 outStr << "\"";
01815         if(inumberOfChildren > 0) {
01816                 outStr << ">";
01817         }
01818         else{
01819                 outStr << "/>";
01820         }
01821         if(inumberOfChildren > 0){
01822                 for(unsigned int i = 0; i < inumberOfChildren; i++){
01823                         outStr << m_mChildren[i]->getNonlinearExpressionInXML();
01824                 }
01825         }
01826         if(inumberOfChildren > 0) {
01827                 outStr << "</" ;
01828                 outStr << "variable" ;
01829                 outStr << ">" ;
01830         }
01831         return outStr.str();
01832 }//getPrefix
01833 
01834 double OSnLNodeVariable::calculateFunction(double *x){
01835         m_dFunctionValue = coef*x[idx];
01836         return m_dFunctionValue;
01837 }// end OSnLNodeVariable::calculate
01838 
01839 ADdouble OSnLNodeVariable::constructADTape(std::map<int, int> *varIdx, vector< ADdouble > *XAD){
01840         m_ADTape = coef;
01841         //std::cout << "Inside OSnLNodeVariable "<<  std::endl;
01842         //std::cout << "Value of OSiL index = " << idx << std::endl;
01843         //std::cout << "Value of AD index = " << (*varIdx)[ idx] << std::endl;
01844         //std::cout << "Value of AD variable = " << (*XAD)[ (*varIdx)[ idx] ] << std::endl;
01845         m_ADTape = coef*(*XAD)[ (*varIdx)[ idx] ];
01846         return m_ADTape;
01847 }// end OSnLNodeVariable::constructADTape
01848 
01849 
01850 void OSnLNodeVariable::getVariableIndexMap(std::map<int, int> *varIdx){
01851         int numVars;
01852         if( (*varIdx).find( idx) != (*varIdx).end() ){
01853                 //std::cout  << "Index already in the map " << idx <<  std::endl;
01854         }
01855         else{ // variable to map with variable index as the key
01856                 //std::cout << "Found a new index to add to the map " << idx << std::endl;
01857                 numVars = (*varIdx).size();
01858                 //std::cout << "numVars =  " << numVars << std::endl;
01859                 (*varIdx)[ idx] = numVars;
01860         }
01861         //std::cout << "Value of index = " << (*varIdx)[ idx] << std::endl;
01862 }//getVariableIndexMap
01863 
01864 
01865 OSnLNode* OSnLNodeVariable::cloneOSnLNode(){
01866         OSnLNode *nlNodePoint;
01867         nlNodePoint = new OSnLNodeVariable();
01868         return  nlNodePoint;
01869 }//end OSnLNodeVariable::cloneOSnLNode
01870            
01871 
01872 
01873 
01874 
01875 
01876 

Generated on Mon May 3 03:05:24 2010 by  doxygen 1.4.7