COPASI API  4.16.103
CFunctionAnalyzer.h
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/function/CFunctionAnalyzer.h,v $
3 // $Revision: 1.11 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/03/07 19:28:19 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 - 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_CFunctionAnalyzer
24 #define COPASI_CFunctionAnalyzer
25 
26 #include <vector>
27 #include <iostream>
28 #include <string>
29 
30 class CEvaluationNode;
31 class CModel;
32 class CReaction;
33 class CFunction;
35 
36 /**
37  * This class performs an analysis of a kinetic function. The function
38  * to analyze is passed to the constructor. The result can be retrieved
39  * with the getResult() method. The Result class has methods for reporting.
40  * The reporting methods may assume that the function (and possibly the reaction)
41  * still exists, so don't delete the function between the analysis and the
42  * reporting of the results!
43  */
45 {
46 public:
47  /**
48  * This is the base class of the arithmetics of the function analyzer. It describes possibilities for values.
49  * It basically consists of some flags that tell whether the value can be positive, can be negative, can
50  * be zero, or invalid, or if an actual exact numerical value is known.
51  * The usual arithmetic operators are defined for this class, the most important functions need to be
52  * implemented still. The missing functions are not critical since there is a save fallback: If you do not
53  * know how to perform a specific operation on CValues, the result should be (unknown|invalid).
54  */
55  class CValue
56  {
57  public:
58  enum Status
59  {
60  novalue = 0,
61  negative = 1,
62  zero = 2,
63  positive = 4,
64  invalid = 8,
65  known = 16,
66  unknown = 7
67  };
68 
70  : mStatus(Status(novalue)), mDouble(0.0) {};
71 
72  CValue(Status status)
73  : mStatus(status), mDouble(0.0) {};
74 
75  CValue(const double & d)
76  : mStatus(known), mDouble(d) {};
77 
78  const double & getValue() const {return mDouble;};
79 
80  /**
81  * set value to be the only possible value
82  */
83  void setValue(const double & value) {mDouble = value; mStatus = known;};
84 
85  const Status & getStatus() const {return mStatus;};
86 
87  void setStatus(const Status & status) {mStatus = status;};
88 
89  CValue operator*(const CValue & rhs) const;
90  CValue operator/(const CValue & rhs) const;
91  CValue operator+(const CValue & rhs) const;
92  CValue operator-(const CValue & rhs) const;
93  CValue operator^(const CValue & rhs) const;
94 
95  bool isPositive() const;
96  bool containsPositive() const;
97  bool isZero() const;
98  bool containsZero() const;
99  bool isNegative() const;
100  bool containsNegative() const;
101  bool isInvalid() const;
102  bool containsInvalid() const;
103 
104  bool operator==(const CValue & rhs) const;
105  CValue invert() const;
106 
107  protected:
108 
109  /**
110  * convert a CValue with status "known" to a more general status.
111  */
112  // CValue generalize() const;
113 
114  static CValue generalize(const double & d);
115 
116  void Or(int s) {mStatus = Status(mStatus | s);};
117  void Or(const CValue & v); // {mStatus = Status(mStatus | s);};
118 
119  /**
120  * add the value to the set off possible values
121  */
122 #ifdef WIN32 // To prevent a fatal compiler error in Visual Studio C++ 6.0
123  void orValue(const double value) {Or(CValue(value)); /* mDouble = value; Or(known);*/};
124 #else
125  void orValue(const double & value) {Or(CValue(value)); /* mDouble = value; Or(known);*/};
126 #endif
127 
128  private:
129  Status mStatus;
130  double mDouble;
131 
132  /**
133  * insert operator
134  */
135  friend std::ostream & operator<<(std::ostream &os, const CValue & v);
136  };
137 
138  /**
139  * This class contains the result of the analysis of one function.
140  */
141  class Result
142  {
143  public:
144 
145  /**
146  * This contains low level information about one function. The Result class contains
147  * three instances of this structure: For the complete function and for the forward and
148  * backwards part of a reversible function
149  */
151  {
152  std::vector<CValue> mUnchangedParameters;
153  std::vector<std::pair<std::pair<size_t, std::string>, std::vector<CValue> > > mSubstrateZero;
154  std::vector<std::pair<std::pair<size_t, std::string>, std::vector<CValue> > > mProductZero;
155 
156  void writeTable(std::ostream & os, bool rt) const;
157 
158  /**
159  * This writes a (hopefully) user understandable interpretation of the results to os.
160  * The return value indicates if a problem was reported.
161  */
162  bool writeAnalysis(std::ostream & os, bool rt, bool reversible) const;
163  };
164 
165  Result();
166  void clear() {*this = Result();};
167 
168  /**
169  * writes a text report about the function to the stream. The return value
170  * indicates if a problem was reported.
171  */
172  bool writeResult(std::ostream & os, bool rt, bool verbose) const;
173 
174  //void writeTable(std::ostream & os, bool rt) const;
175 
178 
179  /** low level information about the original function */
181 
183 
184  /** low level information about the forward part of the function */
186 
187  /** low level information about the backwards part of the function */
189  };
190 
191  void checkKineticFunction(const CFunction * f, const CReaction * reaction = NULL);
192 
193  CFunctionAnalyzer(const CFunction * f, const CReaction * reaction = NULL)
194  {checkKineticFunction(f, reaction);};
195 
196  const Result & getResult() const {return mResult;};
197 
198  /**
199  * Mode tells how to interpret an object in CValue arithmetics.
200  * NOOBJECT means objects are invalid (e.g. for functions, where no object nodes should occur).
201  * GENERAL means concentrations and volumes are positive, all other values positive, zero, or negative.
202  * POSITIVE means all objects are positive. ACTUAL means the actual value is used for local parameters and constant values.
203  */
205 
206  /**
207  * Do the CValue arithmetics of a tree. The callParameters contain the CValues corresponding
208  * to the CEvaluationNodeVariable nodes. The value of mode should not have an effect if this is called
209  * for a function tree.
210  */
211  static CValue evaluateNode(const CEvaluationNode * node, const std::vector<CValue> & callParameters, Mode mode);
212 
213  /**
214  * constructs call parameters for use with the evaluateNode() method
215  */
216  static void constructCallParameters(const CFunctionParameters & fp, std::vector<CValue> & callParameters, bool posi);
217 
218 protected:
219 
221 
222  /**
223  * constructs call parameters for use with the evaluateNode() method, using the actual values for
224  * local parameters and fixed entities.
225  */
226  static void constructCallParametersActualValues(std::vector<CValue> & callParameters, /*const CModel* model,*/ const CReaction* reaction);
227 
228 public:
229  //convenience function to help with writing the reports
230  //static std::string write(int level, bool rt, const std::string & text);
231  static std::string write(int level, bool rt, const std::string & text, const std::string & longText);
232 };
233 
234 #endif
void orValue(const double &value)
std::vector< std::pair< std::pair< size_t, std::string >, std::vector< CValue > > > mProductZero
static CValue evaluateNode(const CEvaluationNode *node, const std::vector< CValue > &callParameters, Mode mode)
CValue operator/(const CValue &rhs) const
CValue operator-(const CValue &rhs) const
CFunctionAnalyzer(const CFunction *f, const CReaction *reaction=NULL)
static void constructCallParametersActualValues(std::vector< CValue > &callParameters, const CReaction *reaction)
static CValue generalize(const double &d)
FunctionInformation mBPart
void setStatus(const Status &status)
const Result & getResult() const
void setValue(const double &value)
friend std::ostream & operator<<(std::ostream &os, const CValue &v)
static void constructCallParameters(const CFunctionParameters &fp, std::vector< CValue > &callParameters, bool posi)
const Status & getStatus() const
CValue operator^(const CValue &rhs) const
static std::string write(int level, bool rt, const std::string &text, const std::string &longText)
FunctionInformation mOriginalFunction
CValue operator*(const CValue &rhs) const
std::vector< std::pair< std::pair< size_t, std::string >, std::vector< CValue > > > mSubstrateZero
bool operator==(const CValue &rhs) const
void checkKineticFunction(const CFunction *f, const CReaction *reaction=NULL)
const CFunction * mpFunction
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
void writeTable(std::ostream &os, bool rt) const
Definition: CModel.h:50
const double & getValue() const
bool writeResult(std::ostream &os, bool rt, bool verbose) const
FunctionInformation mFPart
bool writeAnalysis(std::ostream &os, bool rt, bool reversible) const
CValue operator+(const CValue &rhs) const