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