00001 00017 //#define DEBUG 00018 #include "OSExpressionTree.h" 00019 #include<vector> 00020 00021 using std::cout; 00022 using std::endl; 00023 00024 OSExpressionTree::OSExpressionTree(): 00025 m_treeRoot( NULL), 00026 mapVarIdx( NULL), 00027 m_bIndexMapGenerated( false), 00028 bCppADMustReTape( false), 00029 bDestroyNlNodes( true){ 00030 }//end OSExpressionTree 00031 00032 00033 OSExpressionTree::~OSExpressionTree(){ 00034 #ifdef DEBUG 00035 cout << "Inside the OSExpressionTree Destructor" << endl; 00036 #endif 00037 if( bDestroyNlNodes == true){ 00038 if(m_treeRoot != NULL) delete m_treeRoot; 00039 } 00040 if(mapVarIdx != NULL){ 00041 delete mapVarIdx; 00042 mapVarIdx = NULL; 00043 } 00044 }//end ~OSExpressionTree 00045 00046 00047 std::vector<OSnLNode*> OSExpressionTree::getPostfixFromExpressionTree(){ 00048 return m_treeRoot->getPostfixFromExpressionTree(); 00049 }//getPostfixFromExpressionTree 00050 00051 00052 std::vector<OSnLNode*> OSExpressionTree::getPrefixFromExpressionTree(){ 00053 return m_treeRoot->getPrefixFromExpressionTree(); 00054 }//getPrefixFromExpressionTree 00055 00056 00057 00058 double OSExpressionTree::calculateFunction( double *x, bool new_x){ 00059 //calculateFunctionCppAD( x, functionEvaluated); 00060 if( new_x == false){ 00061 return m_dTreeRootValue; 00062 } 00063 else{ 00064 m_dTreeRootValue = m_treeRoot->calculateFunction( x); 00065 return m_dTreeRootValue; 00066 } 00067 }//calculateFunction 00068 00069 std::map<int, int> *OSExpressionTree::getVariableIndiciesMap(){ 00070 if( m_bIndexMapGenerated == true) return mapVarIdx; 00071 mapVarIdx = new std::map<int, int>(); 00072 m_treeRoot->getVariableIndexMap( mapVarIdx); 00073 //std::cout << "SIZE OF MAP = " << (*mapVarIdx).size() << std::endl; 00074 int kount = 0; 00075 for(m_mPosVarIdx = (*mapVarIdx).begin(); m_mPosVarIdx != (*mapVarIdx).end(); ++m_mPosVarIdx){ 00076 m_mPosVarIdx->second = kount++; 00077 //std::cout << "POSITION FIRST = " << m_mPosVarIdx->first ; 00078 //std::cout << " POSITION SECOND = " << m_mPosVarIdx->second << std::endl; 00079 } 00080 m_bIndexMapGenerated = true; 00081 return mapVarIdx; 00082 }//getVariableIndicies 00083