COPASI API  4.16.103
CEvaluationNodeLogical.h
Go to the documentation of this file.
1 /* Begin CVS Header
2  $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/function/CEvaluationNodeLogical.h,v $
3  $Revision: 1.22 $
4  $Name: $
5  $Author: shoops $
6  $Date: 2012/05/16 23:11:31 $
7  End CVS Header */
8 
9 // Copyright (C) 2012 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
20 // Properties, Inc. and EML Research, gGmbH.
21 // All rights reserved.
22 
23 #ifndef COPASI_CEvaluationNodeLogical
24 #define COPASI_CEvaluationNodeLogical
25 
26 class ASTNode;
27 class CCopasiDataModel;
28 
29 /**
30  * This is the class for nodes presenting opertors used in an evaluation trees.
31  */
33 {
34 public:
35  /**
36  * Enumeration of possible node types.
37  */
38  enum SubType
39  {
40  INVALID = 0x00FFFFFF,
41  // NOT = 0x00000001,
42  OR = 0x00000001,
43  XOR = 0x00000002,
44  AND = 0x00000003,
45  EQ = 0x00000004,
46  NE = 0x00000005,
47  GT = 0x00000006,
48  GE = 0x00000007,
49  LT = 0x00000008,
50  LE = 0x00000009
51  };
52 
53  // Operations
54 private:
55  /**
56  * Default constructor
57  */
59 
60 public:
61  /**
62  * Default constructor
63  * @param const SubType & subType
64  * @param const Data & data
65  */
67  const Data & data);
68 
69  /**
70  * Copy constructor
71  * @param const CEvaluationNodeLogical & src
72  */
74 
75  /**
76  * Destructor
77  */
78  virtual ~CEvaluationNodeLogical();
79 
80  /**
81  * Calculate the numerical result of the node. It is assumed that
82  * all child nodes are up to date.
83  */
84  virtual inline void calculate()
85  {
86  switch (mType & 0x00FFFFFF)
87  {
88  case OR:
89  mValue = (mpLeft->getValue() > 0.5 ||
90  mpRight->getValue() > 0.5) ? 1.0 : 0.0;
91  break;
92 
93  case XOR:
94  mValue = ((mpLeft->getValue() > 0.5 && mpRight->getValue() < 0.5) ||
95  (mpLeft->getValue() < 0.5 && mpRight->getValue() > 0.5)) ? 1.0 : 0.0;
96  break;
97 
98  case AND:
99  mValue = (mpLeft->getValue() > 0.5 &&
100  mpRight->getValue() > 0.5) ? 1.0 : 0.0;
101  break;
102 
103  case EQ:
104  mValue = (mpLeft->getValue() == mpRight->getValue()) ? 1.0 : 0.0;
105  break;
106 
107  case NE:
108  mValue = (mpLeft->getValue() != mpRight->getValue()) ? 1.0 : 0.0;
109  break;
110 
111  case GT:
112  mValue = (mpLeft->getValue() > mpRight->getValue()) ? 1.0 : 0.0;
113  break;
114 
115  case GE:
116  mValue = (mpLeft->getValue() >= mpRight->getValue()) ? 1.0 : 0.0;
117  break;
118 
119  case LT:
120  mValue = (mpLeft->getValue() < mpRight->getValue()) ? 1.0 : 0.0;
121  break;
122 
123  case LE:
124  mValue = (mpLeft->getValue() <= mpRight->getValue()) ? 1.0 : 0.0;
125  break;
126  }
127  }
128 
129  /**
130  * Compile a node;
131  * @param const CEvaluationTree * pTree
132  * @return bool success;
133  */
134  virtual bool compile(const CEvaluationTree * pTree);
135 
136  /**
137  * Retrieve the infix value of the node and its eventual child nodes.
138  * @return const Data & value
139  */
140  virtual std::string getInfix(const std::vector< std::string > & children) const;
141 
142  /**
143  * Retrieve the display string of the node and its eventual child nodes.
144  * @return const Data & value
145  */
146  virtual std::string getDisplayString(const std::vector< std::string > & children) const;
147 
148  /**
149  * Retrieve the display string of the node and its eventual child nodes in C.
150  * @return const Data & value
151  */
152  virtual std::string getCCodeString(const std::vector< std::string > & children) const;
153 
154  /**
155  * Retrieve the display string of the node and its eventual child nodes
156  * in Berkeley Madonna format.
157  * @return const Data & value
158  */
159  virtual std::string getBerkeleyMadonnaString(const std::vector< std::string > & children) const;
160 
161  /**
162  * Retrieve the display string of the node and its eventual child nodes
163  * in XPPAUT format.
164  * @return const Data & value
165  */
166  virtual std::string getXPPString(const std::vector< std::string > & children) const;
167 
168  /**
169  * Creates a new CEvaluationNodeCall from an ASTNode and the given children
170  * @param const ASTNode* pNode
171  * @param const std::vector< CEvaluationNode * > & children
172  * @return CEvaluationNode * pCretedNode
173  */
174  static CEvaluationNode * fromAST(const ASTNode * pASTNode, const std::vector< CEvaluationNode * > & children);
175 
176  /**
177  * Check whether the result is Boolean
178  * @return bool isBoolean
179  */
180  virtual bool isBoolean() const;
181 
182  /**
183  * Create a new ASTNode corresponding to this OperatorNode.
184  * @return ASTNode* return a pointer to the newly created node;
185  */
186  virtual ASTNode* toAST(const CCopasiDataModel* pDataModel) const;
187 
188  /**
189  * Build the MathML string
190  * @param const std::vector< std::string > & children
191  * @param bool expand = true
192  * @param const std::vector< std::vector< std::string > > & variables
193  * @return std::string MMLString
194  */
195  virtual std::string getMMLString(const std::vector< std::string > & children,
196  bool expand,
197  const std::vector< std::vector< std::string > > & variables) const;
198 
199  // Attributes
200 private:
202 
204 };
205 
206 #endif // COPASI_CEvaluationNodeLogical
virtual std::string getXPPString(const std::vector< std::string > &children) const
const C_FLOAT64 & getValue() const
virtual std::string getBerkeleyMadonnaString(const std::vector< std::string > &children) const
static CEvaluationNode * fromAST(const ASTNode *pASTNode, const std::vector< CEvaluationNode * > &children)
virtual std::string getDisplayString(const std::vector< std::string > &children) const
virtual ASTNode * toAST(const CCopasiDataModel *pDataModel) const
virtual std::string getCCodeString(const std::vector< std::string > &children) const
virtual std::string getMMLString(const std::vector< std::string > &children, bool expand, const std::vector< std::vector< std::string > > &variables) const
virtual bool compile(const CEvaluationTree *pTree)
virtual bool isBoolean() const
static Type subType(const Type &type)
virtual std::string getInfix(const std::vector< std::string > &children) const