COPASI API  4.16.103
Public Member Functions | Private Attributes | Friends | List of all members
CNormalLcm Class Reference

#include <CNormalLcm.h>

Collaboration diagram for CNormalLcm:
Collaboration graph
[legend]

Public Member Functions

bool add (const CNormalItemPower &itemPower)
 
bool add (const CNormalSum &sum)
 
 CNormalLcm ()
 
 CNormalLcm (const CNormalLcm &src)
 
const std::set
< CNormalItemPower
*, compareItemPowers > & 
getItemPowers () const
 
const std::vector< CNormalSum * > & getSums () const
 
CNormalLcmoperator= (const CNormalLcm &src)
 
bool remove (const CNormalItemPower &itemPower)
 
bool remove (const CNormalSum &sum)
 
std::string toString () const
 
 ~CNormalLcm ()
 

Private Attributes

std::set< CNormalItemPower
*, compareItemPowers
mItemPowers
 
std::vector< CNormalSum * > mSums
 

Friends

std::ostream & operator<< (std::ostream &os, const CNormalLcm &d)
 

Detailed Description

The class for lcms used in CNormal

Definition at line 33 of file CNormalLcm.h.

Constructor & Destructor Documentation

CNormalLcm::CNormalLcm ( )

Default constructor

Definition at line 37 of file CNormalLcm.cpp.

38 {}
CNormalLcm::CNormalLcm ( const CNormalLcm src)

Copy contructor

Definition at line 43 of file CNormalLcm.cpp.

References mItemPowers, and mSums.

44 {
45  std::set <CNormalItemPower*, compareItemPowers >::const_iterator it;
46  std::set <CNormalItemPower*, compareItemPowers >::const_iterator itEnd = src.mItemPowers.end();
47 
48  for (it = src.mItemPowers.begin(); it != itEnd; ++it)
49  {
50  mItemPowers.insert(new CNormalItemPower(**it));
51  }
52 
53  std::vector<CNormalSum*>::const_iterator it2;
54  std::vector<CNormalSum*>::const_iterator it2End = src.mSums.end();
55 
56  for (it2 = src.mSums.begin(); it2 != it2End; ++it2)
57  {
58  mSums.push_back(new CNormalSum(**it2));
59  }
60 }
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
Definition: CNormalLcm.h:39
std::vector< CNormalSum * > mSums
Definition: CNormalLcm.h:40
CNormalLcm::~CNormalLcm ( )

Destructor

Definition at line 85 of file CNormalLcm.cpp.

References mItemPowers, and mSums.

86 {
87  std::set<CNormalItemPower*, compareItemPowers >::const_iterator it;
88  std::set<CNormalItemPower*, compareItemPowers >::const_iterator itEnd = mItemPowers.end();
89 
90  for (it = mItemPowers.begin(); it != itEnd; ++it)
91  delete *it;
92 
93  std::vector<CNormalSum*>::const_iterator it2;
94  std::vector<CNormalSum*>::const_iterator it2End = mSums.end();
95 
96  for (it2 = mSums.begin(); it2 != it2End; ++it2)
97  delete *it2;
98 }
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
Definition: CNormalLcm.h:39
std::vector< CNormalSum * > mSums
Definition: CNormalLcm.h:40

Member Function Documentation

bool CNormalLcm::add ( const CNormalItemPower itemPower)

Add an itempower to this lcm, ie. lcm := LeastCommonMultiple(lcm,itempower)

Returns
true.

Definition at line 105 of file CNormalLcm.cpp.

References CNormalItemPower::getExp(), CNormalItemPower::getItem(), and mItemPowers.

Referenced by add(), and CNormalFraction::findLcm().

106 {
107  std::set <CNormalItemPower*, compareItemPowers >::iterator it;
108  std::set <CNormalItemPower*, compareItemPowers >::iterator itEnd = mItemPowers.end();
109 
110  for (it = mItemPowers.begin(); it != itEnd; ++it)
111  {
112  if ((*it)->getItem().areEqual(itemPower.getItem()))
113  {
114  (*it)->setExp((*it)->getExp() > itemPower.getExp() ? (*it)->getExp() : itemPower.getExp());
115  return true;
116  }
117  }
118 
119  CNormalItemPower* tmp = new CNormalItemPower(itemPower);
120  mItemPowers.insert(tmp);
121  return true;
122 }
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
Definition: CNormalLcm.h:39
const C_FLOAT64 & getExp() const
CNormalBase & getItem()
bool CNormalLcm::add ( const CNormalSum sum)

Add a fractionless sum to this lcm, ie. lcm := LeastCommonMultiple(lcm,sum)

Returns
true.

Definition at line 129 of file CNormalLcm.cpp.

References add(), CNormalProduct::getItemPowers(), CNormalSum::getProducts(), and mSums.

130 {
131  switch (sum.getProducts().size())
132  {
133  case 0: //Sum must contain at least one product!
134  {
135  return false;
136  }
137 
138  case 1:
139  {
140  CNormalProduct* product = *sum.getProducts().begin();
141  std::set<CNormalItemPower*, compareItemPowers >::const_iterator it;
142  std::set<CNormalItemPower*, compareItemPowers >::const_iterator itEnd = product->getItemPowers().end();
143 
144  for (it = product->getItemPowers().begin(); it != itEnd; ++it)
145  {
146  add(**it);
147  }
148 
149  return true;
150  }
151 
152  default:
153  {
154  std::vector<CNormalSum*>::iterator it;
155  std::vector<CNormalSum*>::iterator itEnd = mSums.end();
156 
157  for (it = mSums.begin(); it != itEnd; ++it)
158  {
159  if (sum == **it)
160  {
161  return true;
162  }
163  }
164 
165  CNormalSum* tmp = new CNormalSum(sum);
166  mSums.push_back(tmp);
167  return true;
168  }
169  }
170 }
bool add(const CNormalItemPower &itemPower)
Definition: CNormalLcm.cpp:105
const std::set< CNormalItemPower *, compareItemPowers > & getItemPowers() const
std::vector< CNormalSum * > mSums
Definition: CNormalLcm.h:40
const std::set< CNormalProduct *, compareProducts > & getProducts() const
Definition: CNormalSum.cpp:416
const std::set< CNormalItemPower *, compareItemPowers > & CNormalLcm::getItemPowers ( ) const

Retrieve the set of itempowers of this lcm.

Returns
mItemPowers.

Definition at line 266 of file CNormalLcm.cpp.

References mItemPowers.

Referenced by convertToCEvaluationNode(), and CNormalProduct::multiply().

267 {
268  return mItemPowers;
269 }
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
Definition: CNormalLcm.h:39
const std::vector< CNormalSum * > & CNormalLcm::getSums ( ) const

Retrieve the vector of sums of this lcm.

Returns
mSums.

Definition at line 275 of file CNormalLcm.cpp.

References mSums.

Referenced by convertToCEvaluationNode(), and CNormalProduct::multiply().

276 {
277  return mSums;
278 }
std::vector< CNormalSum * > mSums
Definition: CNormalLcm.h:40
CNormalLcm & CNormalLcm::operator= ( const CNormalLcm src)

Assignment operator

Definition at line 65 of file CNormalLcm.cpp.

References mItemPowers, and mSums.

66 {
67  std::set<CNormalItemPower*, compareItemPowers >::const_iterator it;
68  std::set<CNormalItemPower*, compareItemPowers >::const_iterator itEnd = src.mItemPowers.end();
69 
70  for (it = src.mItemPowers.begin(); it != itEnd; ++it)
71  mItemPowers.insert(new CNormalItemPower(**it));
72 
73  std::vector<CNormalSum*>::const_iterator it2;
74  std::vector<CNormalSum*>::const_iterator it2End = src.mSums.end();
75 
76  for (it2 = src.mSums.begin(); it2 != it2End; ++it2)
77  mSums.push_back(new CNormalSum(**it2));
78 
79  return *this;
80 }
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
Definition: CNormalLcm.h:39
std::vector< CNormalSum * > mSums
Definition: CNormalLcm.h:40
bool CNormalLcm::remove ( const CNormalItemPower itemPower)

Remove an itempower from this lcm, provided it is a factor

Returns
true.

Definition at line 176 of file CNormalLcm.cpp.

References C_FLOAT64, CNormalItemPower::getExp(), CNormalItemPower::getItem(), and mItemPowers.

Referenced by CNormalFraction::multiply().

177 {
178  std::set <CNormalItemPower*, compareItemPowers >::iterator it;
179  std::set <CNormalItemPower*, compareItemPowers >::iterator itEnd = mItemPowers.end();
180 
181  for (it = mItemPowers.begin(); it != itEnd; ++it)
182  {
183  if ((*it)->getItem().areEqual(itemPower.getItem()))
184  {
185  C_FLOAT64 dif = (*it)->getExp() - itemPower.getExp();
186 
187  if (dif <= -1.0E-100)
188  return false;
189 
190  if (fabs(dif) < 1.0E-100)
191  {
192  delete *it;
193  mItemPowers.erase(it);
194  return true;
195  }
196 
197  (*it)->setExp(dif);
198  return true;
199  }
200  }
201 
202  return false;
203 }
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
Definition: CNormalLcm.h:39
const C_FLOAT64 & getExp() const
#define C_FLOAT64
Definition: copasi.h:92
CNormalBase & getItem()
bool CNormalLcm::remove ( const CNormalSum sum)

Remove a fractionless sum from this lcm, provided it is a factor

Returns
true.

Definition at line 209 of file CNormalLcm.cpp.

References CNormalProduct::getItemPowers(), CNormalSum::getProducts(), and mSums.

210 {
211  bool result = true;
212  std::set <CNormalItemPower*, compareItemPowers >::const_iterator it, itEnd;
213  std::vector<CNormalSum*>::iterator it2, itEnd2;
214  const CNormalProduct* pProduct = NULL;
215 
216  switch (sum.getProducts().size())
217  {
218  case 0:
219  result = false;
220  break;
221 
222  case 1:
223  pProduct = *sum.getProducts().begin();
224  itEnd = pProduct->getItemPowers().end();
225 
226  for (it = pProduct->getItemPowers().begin(); it != itEnd && result == true; ++it)
227  {
228  if (remove(**it) == false)
229  {
230  result = false;
231  }
232  }
233 
234  break;
235 
236  default:
237  itEnd2 = mSums.end();
238  result = false;
239 
240  for (it2 = mSums.begin(); it2 != itEnd2; ++it2)
241  {
242  if (**it2 == sum)
243  {
244  delete *it2;
245  mSums.erase(it2);
246  result = true;
247  break;
248  }
249  }
250 
251  // the below causes issues on VS, as in a way the iterator is no longer
252  // valid after removal, instead the result is set in the loop
253  //if (it2 == itEnd2)
254  //{
255  // result = false;
256  //}
257  }
258 
259  return result;
260 }
const std::set< CNormalItemPower *, compareItemPowers > & getItemPowers() const
std::vector< CNormalSum * > mSums
Definition: CNormalLcm.h:40
const std::set< CNormalProduct *, compareProducts > & getProducts() const
Definition: CNormalSum.cpp:416
std::string CNormalLcm::toString ( ) const

Definition at line 280 of file CNormalLcm.cpp.

281 {
282  std::ostringstream os;
283  os << *this;
284  return os.str();
285 }

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const CNormalLcm d 
)
friend

Definition at line 287 of file CNormalLcm.cpp.

288 {
289  if (d.mItemPowers.size() + d.mSums.size() != 0)
290  {
291  bool firstFactor = true;
292  std::set <CNormalItemPower*, compareItemPowers >::const_iterator it;
293  std::set <CNormalItemPower*, compareItemPowers >::const_iterator itEnd = d.mItemPowers.end();
294 
295  for (it = d.mItemPowers.begin(); it != itEnd; ++it)
296  {
297  if (firstFactor == false)
298  {
299  os << " * ";
300  }
301 
302  os << **it;
303  firstFactor = false;
304  }
305 
306  std::vector<CNormalSum*>::const_iterator it2;
307  std::vector<CNormalSum*>::const_iterator it2End = d.mSums.end();
308 
309  for (it2 = d.mSums.begin(); it2 != it2End; ++it2)
310  {
311  if (firstFactor == false)
312  {
313  os << " * ";
314  }
315 
316  os << "(" << **it2 << ")";
317  firstFactor = false;
318  }
319  }
320  else
321  {
322  os << "1.0";
323  }
324 
325  return os;
326 }
std::set< CNormalItemPower *, compareItemPowers > mItemPowers
Definition: CNormalLcm.h:39
std::vector< CNormalSum * > mSums
Definition: CNormalLcm.h:40

Member Data Documentation

std::set<CNormalItemPower*, compareItemPowers > CNormalLcm::mItemPowers
private

Enumeration of members

Definition at line 39 of file CNormalLcm.h.

Referenced by add(), CNormalLcm(), getItemPowers(), operator<<(), operator=(), remove(), and ~CNormalLcm().

std::vector<CNormalSum*> CNormalLcm::mSums
private

Definition at line 40 of file CNormalLcm.h.

Referenced by add(), CNormalLcm(), getSums(), operator<<(), operator=(), remove(), and ~CNormalLcm().


The documentation for this class was generated from the following files: