00001
00018
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 }
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 }
00046
00047
00048 std::vector<OSnLNode*> OSExpressionTree::getPostfixFromExpressionTree(){
00049 return m_treeRoot->getPostfixFromExpressionTree();
00050 }
00051
00052
00053 std::vector<OSnLNode*> OSExpressionTree::getPrefixFromExpressionTree(){
00054 return m_treeRoot->getPrefixFromExpressionTree();
00055 }
00056
00057
00058
00059 double OSExpressionTree::calculateFunction( double *x, bool new_x){
00060
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 }
00069
00070 std::map<int, int> *OSExpressionTree::getVariableIndiciesMap(){
00071 if( m_bIndexMapGenerated == true) return mapVarIdx;
00072 mapVarIdx = new std::map<int, int>();
00073 std::map<int, int>::iterator m_mPosVarIdx;
00074 m_treeRoot->getVariableIndexMap( mapVarIdx);
00075
00076
00077
00078
00079
00080
00081 m_bIndexMapGenerated = true;
00082 return mapVarIdx;
00083 }
00084
00085 bool OSExpressionTree::IsEqual(OSExpressionTree *that)
00086 {
00087 #ifdef DEBUG_ISEQUAL_ROUTINES
00088 cout << "Start comparing in OSExpressionTree" << endl;
00089 #endif
00090 if (this == NULL)
00091 { if (that == NULL)
00092 return true;
00093 else
00094 {
00095 #ifdef DEBUG_ISEQUAL_ROUTINES
00096 cout << "First object is NULL, second is not" << endl;
00097 #endif
00098 return false;
00099 }
00100 }
00101 else
00102 { if (that == NULL)
00103 {
00104 #ifdef DEBUG_ISEQUAL_ROUTINES
00105 cout << "Second object is NULL, first is not" << endl;
00106 #endif
00107 return false;
00108 }
00109 else
00110 {
00111 if (!this->m_treeRoot->IsEqual(that->m_treeRoot))
00112 return false;
00113
00114 return true;
00115 }
00116 }
00117 }
00118
00119