COPASI API  4.16.103
CNormalSum.h
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/compareExpressions/CNormalSum.h,v $
3 // $Revision: 1.12 $
4 // $Name: $
5 // $Author: gauges $
6 // $Date: 2011/03/13 17:40:50 $
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_CNormalSum_H__
24 #define COPASI_CNormalSum_H__
25 
26 #include <string>
27 #include <set>
28 
30 #include "copasi/copasi.h"
31 
32 class CNormalProduct;
33 class CNormalFraction;
34 class CNormalItemPower;
35 class CNormalLcm;
36 
38 {
39 public:
40  bool operator()(const CNormalProduct* product1, const CNormalProduct* product2) const;
41 };
42 
43 /**
44  * The class for sums used in CNormal
45  */
46 class CNormalSum : public CNormalBase
47 {
48 private:
49  /**
50  * Enumeration of members
51  */
52  std::set<CNormalProduct*, compareProducts > mProducts;
53  std::set<CNormalFraction*> mFractions;
54 
55 public:
56  /**
57  * Default constructor
58  */
59  CNormalSum();
60 
61  /**
62  * Copy Constructor
63  */
64  CNormalSum(const CNormalSum& src);
65 
66  /**
67  * Assignment operator
68  */
69  CNormalSum & operator=(const CNormalSum& src);
70 
71  /**
72  * Smaller operator
73  */
74  bool operator<(const CNormalSum& rhs) const;
75 
76  /**
77  * Destructor
78  */
79  virtual ~CNormalSum();
80 
81  virtual CNormalBase * copy() const;
82 
83  /**
84  * Retrieve the number of summands of this sum.
85  * @return int
86  */
87  int getSize() const;
88 
89  /**
90  * Add product to this sum.
91  * @return true.
92  */
93  bool add(const CNormalProduct& product);
94 
95  /**
96  * Add fraction to this sum.
97  * @return true.
98  */
99  bool add(const CNormalFraction& fraction);
100 
101  /**
102  * Add a sum to this sum.
103  * @return true.
104  */
105  bool add(const CNormalSum& sum);
106 
107  /**
108  * Multiply this sum with a number.
109  * @return true.
110  */
111  bool multiply(const C_FLOAT64& number);
112 
113  /**
114  * Multiply this sum with an itempower.
115  * @return true.
116  */
117  bool multiply(const CNormalItemPower& itemPower);
118 
119  /**
120  * Multiply this sum with another sum, both do not contain fractions!!
121  * @return true.
122  */
123  bool multiply(const CNormalSum& sum);
124 
125  /**
126  * Multiply this sum by a lcm
127  * Numerator and denominator of mFractions do not contain further fractions!
128  * @return true.
129  */
130  bool multiply(const CNormalLcm& lcm);
131 
132  /**
133  * Divide this sum by an itempower, provided it is a factor of it
134  * -This sum does not contain fractions!
135  * @return true.
136  */
137  bool divide(const CNormalItemPower& itemPower);
138 
139  /**
140  * Retrieve the set of products of this sum.
141  * @return mProducts
142  */
143  const std::set<CNormalProduct*, compareProducts >& getProducts() const;
144 
145  /**
146  * Retrieve the set of fractions of this sum.
147  * @return mFractions.
148  */
149  const std::set<CNormalFraction*>& getFractions() const;
150 
151  /**
152  * Examine equality of two sums.
153  * @return bool.
154  */
155  bool operator==(const CNormalSum & rhs) const;
156 
157  /**
158  * Sets the products of this product.
159  */
160  void setProducts(const std::set<CNormalProduct*, compareProducts>& set);
161 
162  /**
163  * Sets the fractions of this product.
164  */
165  void setFractions(const std::set<CNormalFraction*>& set);
166 
167  /**
168  * Check if an itempower is a factor of this sum.
169  * @return positive C_FLOAT64, exponent of the largest power of the item contained in this sum.
170  * if == 0, power is not a factor of this sum.
171  * This sum does not contain fractions!!
172  */
173  C_FLOAT64 checkFactor(const CNormalItemPower& itemPower) const;
174 
175  virtual std::string toString() const;
176 
177  virtual bool simplify();
178 
179  bool checkIsOne() const;
180 
181  bool checkIsZero() const;
182 
183  /**
184  * Returns a sum that is 1.
185  * In this case it only creates a new sum sum and adds a unit product to
186  *the sum.
187  */
188  static CNormalSum* createUnitSum();
189 
190  friend std::ostream & operator<< (std::ostream &os, const CNormalSum & d);
191 
192  static void printProducts(const CNormalSum* pSum);
193 };
194 
195 #endif // COPASI_CNormalSum_H__
virtual bool simplify()
Definition: CNormalSum.cpp:623
bool operator()(const CNormalProduct *product1, const CNormalProduct *product2) const
Definition: CNormalSum.cpp:45
int getSize() const
Definition: CNormalSum.cpp:147
virtual std::string toString() const
Definition: CNormalSum.cpp:473
virtual CNormalBase * copy() const
Definition: CNormalSum.cpp:510
std::set< CNormalProduct *, compareProducts > mProducts
Definition: CNormalSum.h:52
bool add(const CNormalProduct &product)
Definition: CNormalSum.cpp:156
C_FLOAT64 checkFactor(const CNormalItemPower &itemPower) const
Definition: CNormalSum.cpp:382
const std::set< CNormalFraction * > & getFractions() const
Definition: CNormalSum.cpp:425
friend std::ostream & operator<<(std::ostream &os, const CNormalSum &d)
Definition: CNormalSum.cpp:467
bool operator==(const CNormalSum &rhs) const
Definition: CNormalSum.cpp:434
bool divide(const CNormalItemPower &itemPower)
Definition: CNormalSum.cpp:371
virtual ~CNormalSum()
Definition: CNormalSum.cpp:128
void setFractions(const std::set< CNormalFraction * > &set)
Definition: CNormalSum.cpp:603
CNormalSum & operator=(const CNormalSum &src)
Definition: CNormalSum.cpp:108
#define C_FLOAT64
Definition: copasi.h:92
bool checkIsOne() const
Definition: CNormalSum.cpp:850
void setProducts(const std::set< CNormalProduct *, compareProducts > &set)
Definition: CNormalSum.cpp:583
bool checkIsZero() const
Definition: CNormalSum.cpp:874
std::set< CNormalFraction * > mFractions
Definition: CNormalSum.h:53
static CNormalSum * createUnitSum()
Definition: CNormalSum.cpp:889
static void printProducts(const CNormalSum *pSum)
Definition: CNormalSum.cpp:898
bool operator<(const CNormalSum &rhs) const
Definition: CNormalSum.cpp:515
const std::set< CNormalProduct *, compareProducts > & getProducts() const
Definition: CNormalSum.cpp:416
bool multiply(const C_FLOAT64 &number)
Definition: CNormalSum.cpp:249