/Users/kmartin/Documents/files/code/cpp/OScpp/COIN-OS/OS/src/OSCommonInterfaces/OSnLNode.cpp

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

Generated on Sat Mar 29 22:38:01 2008 by  doxygen 1.5.3