- Main Page
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# /home/coin/SVN-release/OS-2.3.5/OS/src/OSCommonInterfaces/OSExpressionTree.cpp

Go to the documentation of this file.

    00001 /* $Id: OSExpressionTree.cpp 3815 2010-11-03 23:46:16Z Gassmann $ */
    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         std::map<int, int>::iterator m_mPosVarIdx;
    00074         m_treeRoot->getVariableIndexMap( mapVarIdx);
    00075         //std::cout << "SIZE OF MAP =  "  << (*mapVarIdx).size() << std::endl;
    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
    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 }//OSExpressionTree::IsEqual
    00118
    00119