COPASI API  4.16.103
Functions | Variables
ConvertToCEvaluationNode.h File Reference
#include <string>
#include <map>
#include "copasi/compareExpressions/CNormalFraction.h"
Include dependency graph for ConvertToCEvaluationNode.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

CEvaluationNodeconvertToCEvaluationNode (const CNormalFraction &fraction)
 
CEvaluationNodeconvertToCEvaluationNode (const CNormalItem &item)
 
CEvaluationNodeconvertToCEvaluationNode (const CNormalItemPower &itemPower)
 
CEvaluationNodeconvertToCEvaluationNode (const CNormalLcm &lcm)
 
CEvaluationNodeconvertToCEvaluationNode (const CNormalProduct &product)
 
CEvaluationNodeconvertToCEvaluationNode (const CNormalSum &sum)
 
CEvaluationNodeconvertToCEvaluationNode (const CNormalChoice &choice)
 
CEvaluationNodeconvertToCEvaluationNode (const CNormalChoiceLogical &choice)
 
CEvaluationNodeconvertToCEvaluationNode (const CNormalLogicalItem &choice)
 
CEvaluationNodeconvertToCEvaluationNode (const CNormalLogical &logical)
 
CEvaluationNodeconvertToCEvaluationNode (const CNormalBase &base)
 
CEvaluationNodeconvertToCEvaluationNode (const CNormalGeneralPower &pow)
 
CEvaluationNodeconvertToCEvaluationNode (const CNormalFunction &fun)
 
CEvaluationNodeconvertToCEvaluationNode (const CNormalCall &call)
 
CNormalCallcreateCall (const CEvaluationNode *node)
 
CNormalChoicecreateChoice (const CEvaluationNode *pNode)
 
CNormalFractioncreateFraction (const CEvaluationNode *node)
 
CNormalFunctioncreateFunction (const CEvaluationNode *node)
 
CNormalGeneralPowercreateGeneralPower (const CEvaluationNode *node)
 
CNormalItemcreateItem (const CEvaluationNode *node)
 
CNormalItemPowercreateItemPower (const CEvaluationNode *node)
 
CNormalBasecreateItemPowerItem (const CEvaluationNode *pNode)
 
CNormalLogicalcreateLogical (const CEvaluationNode *pNode)
 
CNormalChoiceLogicalcreateLogicalChoice (const CEvaluationNode *pNode)
 
CNormalLogicalItemcreateLogicalItem (const CEvaluationNode *pNode)
 
CNormalFractioncreateNormalRepresentation (const CEvaluationNode *node)
 
CNormalProductcreateProduct (const CEvaluationNode *node)
 
CNormalSumcreateSum (const CEvaluationNode *node)
 
bool isLogical (const CEvaluationNode *pNode)
 

Variables

std::map< std::string, const
CEvaluationNode * > 
str2eval
 

Function Documentation

CEvaluationNode* convertToCEvaluationNode ( const CNormalFraction fraction)

Definition at line 66 of file ConvertToCEvaluationNode.cpp.

References CCopasiNode< _Data >::addChild(), CNormalFraction::checkDenominatorOne(), convertToCEvaluationNode(), CEvaluationNodeOperator::DIVIDE, CNormalFraction::getDenominator(), CNormalFraction::getNumerator(), and pResult.

Referenced by convertToCEvaluationNode(), and CNormalTranslation::normAndSimplifyReptdly().

67 {
68  CEvaluationNode* pResult = NULL;
69 
70  if (fraction.checkDenominatorOne())
71  {
72  pResult = convertToCEvaluationNode(fraction.getNumerator());
73  }
74  else
75  {
78  pDivision->addChild(pChild);
79  pChild = convertToCEvaluationNode(fraction.getDenominator());
80  pDivision->addChild(pChild);
81  pResult = pDivision;
82  }
83 
84  return pResult;
85 }
CNormalSum & getNumerator()
CEvaluationNode * convertToCEvaluationNode(const CNormalFraction &fraction)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CNormalSum & getDenominator()
const CArrayAnnotation * pResult
bool checkDenominatorOne() const
CEvaluationNode* convertToCEvaluationNode ( const CNormalItem item)

Definition at line 87 of file ConvertToCEvaluationNode.cpp.

References CEvaluationNodeConstant::_INFINITY, CEvaluationNodeConstant::_NaN, CEvaluationNodeVariable::ANY, CNormalItem::CONSTANT, CEvaluationNodeConstant::EXPONENTIALE, CEvaluationNodeConstant::FALSE, CNormalItem::getName(), CNormalItem::getType(), CEvaluationNode::INVALID, CEvaluationNodeConstant::PI, CEvaluationNodeConstant::TRUE, and CNormalItem::VARIABLE.

88 {
89  CEvaluationNode* pNode = NULL;
91 
92  switch (item.getType())
93  {
95 
96  // create a CEvaluationNodeNumber
97  if (item.getName() == "pi" || item.getName() == "PI")
98  {
100  }
101  else if (item.getName() == "EXPONENTIALE" || item.getName() == "exponentiale")
102  {
104  }
105  else if (item.getName() == "TRUE" || item.getName() == "true")
106  {
108  }
109  else if (item.getName() == "FALSE" || item.getName() == "false")
110  {
112  }
113  else if (item.getName() == "INFINITY" || item.getName() == "infinity")
114  {
116  }
117  else if (item.getName() == "NAN" || item.getName() == "nan" || item.getName() == "Nan")
118  {
120  }
121 
123  break;
125  // create a CEvaluationNodeVariable
127  break;
128  }
129 
130  // TODO what about object nodes ?????
131  return pNode;
132 }
const Type & getType() const
Definition: CNormalItem.cpp:91
const std::string getName() const
Definition: CNormalItem.cpp:82
CEvaluationNode* convertToCEvaluationNode ( const CNormalItemPower itemPower)

Definition at line 134 of file ConvertToCEvaluationNode.cpp.

References CCopasiNode< _Data >::addChild(), convertToCEvaluationNode(), CEvaluationNodeNumber::DOUBLE, CNormalItemPower::getExp(), CNormalItemPower::getItem(), CEvaluationNodeOperator::POWER, and pResult.

135 {
136  CEvaluationNode* pResult = NULL;
137 
138  if (fabs(itemPower.getExp() - 1.0) < 1e-12)
139  {
140  pResult = convertToCEvaluationNode(itemPower.getItem());
141  }
142  else
143  {
144  std::ostringstream sstream;
146  CEvaluationNode* pChild = convertToCEvaluationNode(itemPower.getItem());
147  pPowerNode->addChild(pChild);
148  sstream << itemPower.getExp();
149  pPowerNode->addChild(new CEvaluationNodeNumber(CEvaluationNodeNumber::DOUBLE, sstream.str()));
150  pResult = pPowerNode;
151  }
152 
153  return pResult;
154 }
CEvaluationNode * convertToCEvaluationNode(const CNormalFraction &fraction)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
const C_FLOAT64 & getExp() const
const CArrayAnnotation * pResult
CNormalBase & getItem()
CEvaluationNode* convertToCEvaluationNode ( const CNormalLcm lcm)

Definition at line 156 of file ConvertToCEvaluationNode.cpp.

References CCopasiNode< _Data >::addChild(), convertToCEvaluationNode(), CCopasiNode< _Data >::getChild(), CNormalLcm::getItemPowers(), CCopasiNode< _Data >::getParent(), CNormalLcm::getSums(), CEvaluationNodeOperator::MULTIPLY, pResult, and CCopasiNode< _Data >::removeChild().

157 {
158  CEvaluationNode* pResult = NULL;
159  const std::set<CNormalItemPower*, compareItemPowers >& itemPowers = lcm.getItemPowers();
160  std::set<CNormalItemPower*, compareItemPowers >::const_iterator it = itemPowers.begin();
161  std::set<CNormalItemPower*, compareItemPowers >::const_iterator itEnd = itemPowers.end();
163  pResult = pMult;
164  CEvaluationNode* pChild = NULL;
165 
166  while (it != itEnd)
167  {
168  assert(pMult != NULL);
170  pMult->addChild(pChild);
171  pChild = convertToCEvaluationNode(**it);
172  pMult->addChild(pChild);
173  pMult = dynamic_cast<CEvaluationNodeOperator*>(pMult->getChild());
174  ++it;
175  }
176 
177  const std::vector<CNormalSum*>& sums = lcm.getSums();
178 
179  std::vector<CNormalSum*>::const_iterator it2 = sums.begin();
180 
181  std::vector<CNormalSum*>::const_iterator itEnd2 = sums.end();
182 
183  while (it2 != itEnd2)
184  {
185  assert(pMult != NULL);
187  pMult->addChild(pChild);
188  pChild = convertToCEvaluationNode(**it);
189  pMult->addChild(pChild);
190  pMult = dynamic_cast<CEvaluationNodeOperator*>(pMult->getChild());
191  ++it;
192  }
193 
194  if (pMult->getParent() == pResult)
195  {
196  pResult->removeChild(pMult);
197  delete pMult;
198  }
199  else
200  {
201  CEvaluationNode* pParent = dynamic_cast<CEvaluationNode*>(pMult->getParent());
202  assert(pParent != NULL);
203  pParent->removeChild(pMult);
204  delete pMult;
205  pMult = dynamic_cast<CEvaluationNodeOperator*>(pParent->getParent());
206  assert(pMult != NULL);
207  pMult->removeChild(pParent);
208  pMult->addChild(dynamic_cast<CEvaluationNode*>(pParent->getChild())->copyBranch());
209  delete pParent;
210  }
211 
212  return pResult;
213 }
const std::vector< CNormalSum * > & getSums() const
Definition: CNormalLcm.cpp:275
CEvaluationNode * convertToCEvaluationNode(const CNormalFraction &fraction)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
const CArrayAnnotation * pResult
CCopasiNode< Data > * getParent()
Definition: CCopasiNode.h:139
virtual bool removeChild(CCopasiNode< Data > *pChild)
Definition: CCopasiNode.h:181
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
const std::set< CNormalItemPower *, compareItemPowers > & getItemPowers() const
Definition: CNormalLcm.cpp:266
CEvaluationNode* convertToCEvaluationNode ( const CNormalProduct product)

Definition at line 215 of file ConvertToCEvaluationNode.cpp.

References convertToCEvaluationNode(), CNormalTranslation::createChain(), CEvaluationNodeNumber::DOUBLE, CNormalProduct::getFactor(), CNormalProduct::getItemPowers(), CNormalTranslation::ONE_NODE, pResult, and CNormalTranslation::TIMES_NODE.

216 {
217  CEvaluationNode* pResult = NULL;
218  std::ostringstream sstream;
219 
220  if (product.getItemPowers().size() == 0)
221  {
222  sstream.precision(18);
223  sstream << product.getFactor();
224  pResult = new CEvaluationNodeNumber(CEvaluationNodeNumber::DOUBLE, sstream.str());
225  }
226  else
227  {
228  const std::set<CNormalItemPower*, compareItemPowers >& itemPowers = product.getItemPowers();
229  std::set<CNormalItemPower*, compareItemPowers >::const_iterator it = itemPowers.begin();
230  std::set<CNormalItemPower*, compareItemPowers >::const_iterator itEnd = itemPowers.end();
231  CEvaluationNode* pChild = NULL;
232  std::vector<CEvaluationNode*> products;
233 
234  while (it != itEnd)
235  {
236  pChild = convertToCEvaluationNode(**it);
237  products.push_back(pChild);
238  ++it;
239  }
240 
241  if (fabs(product.getFactor() - 1.0) >= 1e-12)
242  {
243  sstream.precision(18);
244  sstream << product.getFactor();
245  products.push_back(new CEvaluationNodeNumber(CEvaluationNodeNumber::DOUBLE, sstream.str()));
246  }
247 
249  }
250 
251  return pResult;
252 }
CEvaluationNode * convertToCEvaluationNode(const CNormalFraction &fraction)
static const CEvaluationNode ONE_NODE
const std::set< CNormalItemPower *, compareItemPowers > & getItemPowers() const
const C_FLOAT64 & getFactor() const
const CArrayAnnotation * pResult
static const CEvaluationNode TIMES_NODE
static CEvaluationNode * createChain(const CEvaluationNode *pLink, const CEvaluationNode *pNeutralElement, const std::vector< const CEvaluationNode * > &elements)
CEvaluationNode* convertToCEvaluationNode ( const CNormalSum sum)

Definition at line 254 of file ConvertToCEvaluationNode.cpp.

References convertToCEvaluationNode(), CEvaluationNode::copyBranch(), CNormalTranslation::createChain(), CNormalSum::getFractions(), CNormalSum::getProducts(), CNormalTranslation::PLUS_NODE, pResult, and CNormalTranslation::ZERO_NODE.

255 {
256  const std::set<CNormalFraction*>& fractions = sum.getFractions();
257  std::set<CNormalFraction*>::const_iterator it = fractions.begin();
258  std::set<CNormalFraction*>::const_iterator itEnd = fractions.end();
259  std::vector<const CEvaluationNode*> summands;
260  CEvaluationNode* pChild = NULL;
261 
262  while (it != itEnd)
263  {
264  pChild = convertToCEvaluationNode(**it);
265  summands.push_back(pChild);
266  ++it;
267  }
268 
269  const std::set<CNormalProduct*, compareProducts >& products = sum.getProducts();
270 
271  std::set<CNormalProduct*, compareProducts >::const_iterator it2 = products.begin();
272 
273  std::set<CNormalProduct*, compareProducts >::const_iterator itEnd2 = products.end();
274 
275  while (it2 != itEnd2)
276  {
277  pChild = convertToCEvaluationNode(**it2);
278  summands.push_back(pChild);
279  ++it2;
280  }
281 
282  CEvaluationNode* pResult = NULL;
283 
284  if (!summands.empty())
285  {
287  }
288  else
289  {
291  }
292 
293  std::vector<const CEvaluationNode*>::iterator vIt = summands.begin(), vEndit = summands.end();
294 
295  while (vIt != vEndit)
296  {
297  delete *vIt;
298  ++vIt;
299  }
300 
301  return pResult;
302 }
CEvaluationNode * copyBranch() const
CEvaluationNode * convertToCEvaluationNode(const CNormalFraction &fraction)
const std::set< CNormalFraction * > & getFractions() const
Definition: CNormalSum.cpp:425
static const CEvaluationNode ZERO_NODE
const CArrayAnnotation * pResult
static CEvaluationNode * createChain(const CEvaluationNode *pLink, const CEvaluationNode *pNeutralElement, const std::vector< const CEvaluationNode * > &elements)
static const CEvaluationNode PLUS_NODE
const std::set< CNormalProduct *, compareProducts > & getProducts() const
Definition: CNormalSum.cpp:416
CEvaluationNode* convertToCEvaluationNode ( const CNormalChoice choice)

Definition at line 1720 of file ConvertToCEvaluationNode.cpp.

References CCopasiNode< _Data >::addChild(), convertToCEvaluationNode(), CNormalChoice::getCondition(), CNormalChoice::getFalseExpression(), CNormalChoice::getTrueExpression(), and CEvaluationNodeChoice::IF.

1721 {
1722  // this will become a CEvaluationNodeChoice with an mpIf, an mpTrue and and
1723  // mpFalse
1724  CEvaluationNodeChoice* pChoiceNode = NULL;
1726 
1727  if (pChild1 != NULL)
1728  {
1730 
1731  if (pChild2 != NULL)
1732  {
1734 
1735  if (pChild3 != NULL)
1736  {
1737  pChoiceNode = new CEvaluationNodeChoice(CEvaluationNodeChoice::IF, "IF");
1738  pChoiceNode->addChild(pChild1);
1739  pChoiceNode->addChild(pChild2);
1740  pChoiceNode->addChild(pChild3);
1741  }
1742  }
1743  }
1744 
1745  return pChoiceNode;
1746 }
const CNormalFraction & getTrueExpression() const
CEvaluationNode * convertToCEvaluationNode(const CNormalFraction &fraction)
const CNormalLogical & getCondition() const
const CNormalFraction & getFalseExpression() const
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CEvaluationNode* convertToCEvaluationNode ( const CNormalChoiceLogical choice)

Definition at line 1748 of file ConvertToCEvaluationNode.cpp.

References CCopasiNode< _Data >::addChild(), convertToCEvaluationNode(), CNormalChoiceLogical::getCondition(), CNormalChoiceLogical::getFalseExpression(), CNormalChoiceLogical::getTrueExpression(), and CEvaluationNodeChoice::IF.

1749 {
1750  // this will become a CEvaluationNodeChoice with an mpIf, an mpTrue and and
1751  // mpFalse
1752  CEvaluationNodeChoice* pChoiceNode = NULL;
1754 
1755  if (pChild1 != NULL)
1756  {
1758 
1759  if (pChild2 != NULL)
1760  {
1762 
1763  if (pChild3 != NULL)
1764  {
1765  pChoiceNode = new CEvaluationNodeChoice(CEvaluationNodeChoice::IF, "IF");
1766  pChoiceNode->addChild(pChild1);
1767  pChoiceNode->addChild(pChild2);
1768  pChoiceNode->addChild(pChild3);
1769  }
1770  }
1771  }
1772 
1773  return pChoiceNode;
1774 }
const CNormalLogical & getCondition() const
CEvaluationNode * convertToCEvaluationNode(const CNormalFraction &fraction)
const CNormalLogical & getFalseExpression() const
const CNormalLogical & getTrueExpression() const
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CEvaluationNode* convertToCEvaluationNode ( const CNormalLogicalItem choice)

Definition at line 1776 of file ConvertToCEvaluationNode.cpp.

References CCopasiNode< _Data >::addChild(), CEvaluationNode::compile(), convertToCEvaluationNode(), CNormalLogicalItem::EQ, CEvaluationNodeLogical::EQ, CNormalLogicalItem::FALSE, CEvaluationNodeConstant::FALSE, CNormalLogicalItem::GE, CEvaluationNodeLogical::GE, CNormalLogicalItem::getLeft(), CNormalLogicalItem::getRight(), CNormalLogicalItem::getType(), CNormalLogicalItem::GT, CEvaluationNodeLogical::GT, CNormalLogicalItem::INVALID, CNormalLogicalItem::LE, CEvaluationNodeLogical::LE, CNormalLogicalItem::LT, CEvaluationNodeLogical::LT, CNormalLogicalItem::NE, CEvaluationNodeLogical::NE, CNormalLogicalItem::TRUE, and CEvaluationNodeConstant::TRUE.

1777 {
1778  CEvaluationNode* pLogicalNode = NULL;
1779 
1780  switch (item.getType())
1781  {
1783  pLogicalNode = new CEvaluationNodeConstant(CEvaluationNodeConstant::TRUE, "TRUE");
1784  pLogicalNode->compile(NULL);
1785  break;
1787  pLogicalNode = new CEvaluationNodeConstant(CEvaluationNodeConstant::FALSE, "FALSE");
1788  pLogicalNode->compile(NULL);
1789  break;
1791  pLogicalNode = new CEvaluationNodeLogical(CEvaluationNodeLogical::EQ, "==");
1792  break;
1794  pLogicalNode = new CEvaluationNodeLogical(CEvaluationNodeLogical::NE, "!=");
1795  break;
1797  pLogicalNode = new CEvaluationNodeLogical(CEvaluationNodeLogical::LT, "<");
1798  break;
1800  pLogicalNode = new CEvaluationNodeLogical(CEvaluationNodeLogical::GT, ">");
1801  break;
1803  pLogicalNode = new CEvaluationNodeLogical(CEvaluationNodeLogical::GE, ">=");
1804  break;
1806  pLogicalNode = new CEvaluationNodeLogical(CEvaluationNodeLogical::LE, "<=");
1807  break;
1809  break;
1810  }
1811 
1812  if (item.getType() != CNormalLogicalItem::TRUE && item.getType() != CNormalLogicalItem::FALSE)
1813  {
1814  CEvaluationNode* pChild1 = convertToCEvaluationNode(item.getLeft());
1815 
1816  if (pChild1 == NULL)
1817  {
1818  delete pLogicalNode;
1819  pLogicalNode = NULL;
1820  }
1821  else
1822  {
1823  CEvaluationNode* pChild2 = convertToCEvaluationNode(item.getRight());
1824 
1825  if (pChild2 == NULL)
1826  {
1827  delete pLogicalNode;
1828  pLogicalNode = NULL;
1829  }
1830  else
1831  {
1832  pLogicalNode->addChild(pChild1);
1833  pLogicalNode->addChild(pChild2);
1834  pLogicalNode->compile(NULL);
1835  }
1836  }
1837  }
1838 
1839  return pLogicalNode;
1840 }
CEvaluationNode * convertToCEvaluationNode(const CNormalFraction &fraction)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
virtual bool compile(const CEvaluationTree *pTree)
CEvaluationNode* convertToCEvaluationNode ( const CNormalLogical logical)

Definition at line 1842 of file ConvertToCEvaluationNode.cpp.

References CCopasiNode< _Data >::addChild(), CEvaluationNodeLogical::AND, convertToCEvaluationNode(), CEvaluationNode::copyBranch(), CNormalTranslation::createChain(), CNormalLogical::getAndSets(), CNormalLogical::getChoices(), CNormalLogical::isNegated(), CNormalTranslation::NEUTRAL_ELEMENT_AND, CNormalTranslation::NEUTRAL_ELEMENT_OR, CEvaluationNodeFunction::NOT, CEvaluationNodeLogical::OR, and pResult.

1843 {
1844  CEvaluationNode* pResult = NULL;
1845  // go through all mAndSets and create AND combined chains which are then
1846  // combined with OR
1847  // do the same with all choice sets
1848  // combine the two results with OR
1849  CEvaluationNode* pNotNode = NULL;
1850  CEvaluationNode* pNode = NULL;
1853  std::vector<CEvaluationNode*> andElements;
1854  std::vector<CEvaluationNode*> orElements;
1855  CNormalLogical::ChoiceSetOfSets::const_iterator cIt = logical.getChoices().begin(), cEndit = logical.getChoices().end();
1856 
1857  while (cIt != cEndit)
1858  {
1859  CNormalLogical::ChoiceSet::const_iterator cInnerIt = (*cIt).first.begin(), cInnerEndit = (*cIt).first.end();
1860 
1861  while (cInnerIt != cInnerEndit)
1862  {
1863  pNode = convertToCEvaluationNode(*(*cInnerIt).first);
1864  assert(pNode != NULL);
1865 
1866  if ((*cInnerIt).second == true)
1867  {
1868  // only create the not node if it wouldn't result in the neutral
1869  // element
1871  {
1873  pNotNode->addChild(pNode);
1874  pNode = pNotNode;
1875  }
1876  else
1877  {
1878  pNode = NULL;
1879  }
1880  }
1881 
1882  ++cInnerIt;
1883 
1884  // if it is not the neutral element or it is the last element to be
1885  // inserted into an otherwise empty vector, insert the element
1886  if (((pNode != NULL) && ((*pNode) != CNormalTranslation::NEUTRAL_ELEMENT_AND)) || (andElements.empty() && cInnerIt == cInnerEndit))
1887  {
1888  andElements.push_back(pNode);
1889  }
1890  }
1891 
1892  // create the and chain
1894  assert(pNode != NULL);
1895  andElements.clear();
1896 
1897  // check *cIt.second if it is true
1898  if ((*cIt).second == true)
1899  {
1900  // create a not node if it would not result in the creation of the
1901  // neutral element
1903  {
1905  pNode->addChild(pNode);
1906  pNode = pNotNode;
1907  }
1908  else
1909  {
1910  pNode = NULL;
1911  }
1912  }
1913 
1914  ++cIt;
1915 
1916  // if it is not the neutral element or it is the last element to be
1917  // inserted into an otherwise empty vector, insert the element
1918  if (((pNode != NULL) && ((*pNode) != CNormalTranslation::NEUTRAL_ELEMENT_OR)) || (orElements.empty() && cIt == cEndit))
1919  {
1920  orElements.push_back(pNode);
1921  }
1922  }
1923 
1924  // create the OR chain
1925  if (!orElements.empty())
1926  {
1928  assert(pNode != NULL);
1929  orElements.clear();
1930  }
1931 
1932  pResult = pNode;
1933  pNode = NULL;
1934 
1935  CNormalLogical::ItemSetOfSets::const_iterator iIt = logical.getAndSets().begin(), iEndit = logical.getAndSets().end();
1936 
1937  while (iIt != iEndit)
1938  {
1939  CNormalLogical::ItemSet::const_iterator iInnerIt = (*iIt).first.begin(), iInnerEndit = (*iIt).first.end();
1940 
1941  while (iInnerIt != iInnerEndit)
1942  {
1943  pNode = convertToCEvaluationNode(*(*iInnerIt).first);
1944  assert(pNode != NULL);
1945 
1946  if ((*iInnerIt).second == true)
1947  {
1948  // only create the not node if it wouldn't result in the neutral
1949  // element
1951  {
1953  pNotNode->addChild(pNode);
1954  pNode = pNotNode;
1955  }
1956  else
1957  {
1958  delete pNode;
1959  pNode = NULL;
1960  }
1961  }
1962 
1963  ++iInnerIt;
1964 
1965  // if it is not the neutral element or it is the last element to be
1966  // inserted into an otherwise empty vector, insert the element
1967  if (((pNode != NULL) && ((*pNode) != CNormalTranslation::NEUTRAL_ELEMENT_AND)) || (andElements.empty() && iInnerIt == iInnerEndit))
1968  {
1969  andElements.push_back(pNode);
1970  }
1971  }
1972 
1973  // create the and chain
1975  assert(pNode != NULL);
1976  andElements.clear();
1977 
1978  // check *iIt.second if it is true
1979  if ((*iIt).second == true)
1980  {
1981 
1982  // create a not node if it does not result in the neutral node
1984  {
1986  pNotNode->addChild(pNode);
1987  pNode = pNotNode;
1988  }
1989  else
1990  {
1991  delete pNode;
1992  pNode = NULL;
1993  }
1994  }
1995 
1996  ++iIt;
1997 
1998  // if it is not the neutral element or it is the last element to be
1999  // inserted into an otherwise empty vector, insert the element
2000  if (((pNode != NULL) && ((*pNode) != CNormalTranslation::NEUTRAL_ELEMENT_OR)) || (orElements.empty() && iIt == iEndit))
2001  {
2002  orElements.push_back(pNode);
2003  }
2004  }
2005 
2006  // create the OR chain
2007  if (!orElements.empty())
2008  {
2010  assert(pNode != NULL);
2011  orElements.clear();
2012  }
2013 
2014  if (pResult == NULL)
2015  {
2016  pResult = pNode;
2017  assert(pResult != NULL);
2018  }
2019  else
2020  {
2022  {
2023  pResult = pNode;
2024  }
2025  else if (*pNode == CNormalTranslation::NEUTRAL_ELEMENT_OR)
2026  {
2027  CEvaluationNode* pTmpNode = pOrNode->copyBranch();
2028  pTmpNode->addChild(pResult);
2029  pTmpNode->addChild(pNode);
2030  pResult = pTmpNode;
2031  }
2032  }
2033 
2034  // check if mNot is set
2035  if (logical.isNegated() == true)
2036  {
2038  pNode->addChild(pResult);
2039  pResult = pNotNode;
2040  }
2041 
2042  // clean up
2043  delete pOrNode;
2044  delete pAndNode;
2045  assert(pResult != NULL);
2046  return pResult;
2047 }
CEvaluationNode * copyBranch() const
static const CEvaluationNode NEUTRAL_ELEMENT_AND
ChoiceSetOfSets & getChoices()
CEvaluationNode * convertToCEvaluationNode(const CNormalFraction &fraction)
bool isNegated() const
static const CEvaluationNode NEUTRAL_ELEMENT_OR
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
const CArrayAnnotation * pResult
static CEvaluationNode * createChain(const CEvaluationNode *pLink, const CEvaluationNode *pNeutralElement, const std::vector< const CEvaluationNode * > &elements)
ItemSetOfSets & getAndSets()
CEvaluationNode* convertToCEvaluationNode ( const CNormalBase base)

Definition at line 1092 of file ConvertToCEvaluationNode.cpp.

References convertToCEvaluationNode().

1093 {
1094  CEvaluationNode* pNode = NULL;
1095 
1096  if (dynamic_cast<const CNormalItem*>(&base) != NULL)
1097  {
1098  pNode = convertToCEvaluationNode(dynamic_cast<const CNormalItem&>(base));
1099  }
1100  else if (dynamic_cast<const CNormalItemPower*>(&base) != NULL)
1101  {
1102  pNode = convertToCEvaluationNode(dynamic_cast<const CNormalItemPower&>(base));
1103  }
1104  else if (dynamic_cast<const CNormalGeneralPower*>(&base) != NULL)
1105  {
1106  pNode = convertToCEvaluationNode(dynamic_cast<const CNormalGeneralPower&>(base));
1107  }
1108  else if (dynamic_cast<const CNormalFunction*>(&base) != NULL)
1109  {
1110  pNode = convertToCEvaluationNode(dynamic_cast<const CNormalFunction&>(base));
1111  }
1112  else if (dynamic_cast<const CNormalCall*>(&base) != NULL)
1113  {
1114  pNode = convertToCEvaluationNode(dynamic_cast<const CNormalCall&>(base));
1115  }
1116  else if (dynamic_cast<const CNormalFraction*>(&base) != NULL)
1117  {
1118  pNode = convertToCEvaluationNode(dynamic_cast<const CNormalFraction&>(base));
1119  }
1120  else if (dynamic_cast<const CNormalProduct*>(&base) != NULL)
1121  {
1122  pNode = convertToCEvaluationNode(dynamic_cast<const CNormalProduct&>(base));
1123  }
1124  else if (dynamic_cast<const CNormalSum*>(&base) != NULL)
1125  {
1126  pNode = convertToCEvaluationNode(dynamic_cast<const CNormalSum&>(base));
1127  }
1128  else if (dynamic_cast<const CNormalLogical*>(&base) != NULL)
1129  {
1130  pNode = convertToCEvaluationNode(dynamic_cast<const CNormalLogical&>(base));
1131  }
1132  else if (dynamic_cast<const CNormalChoice*>(&base) != NULL)
1133  {
1134  pNode = convertToCEvaluationNode(dynamic_cast<const CNormalChoice&>(base));
1135  }
1136 
1137  return pNode;
1138 }
CEvaluationNode * convertToCEvaluationNode(const CNormalFraction &fraction)
CEvaluationNode* convertToCEvaluationNode ( const CNormalGeneralPower pow)

Definition at line 1140 of file ConvertToCEvaluationNode.cpp.

References CCopasiNode< _Data >::addChild(), CNormalFraction::checkIsOne(), convertToCEvaluationNode(), CNormalGeneralPower::getLeft(), CNormalGeneralPower::getRight(), CNormalGeneralPower::getType(), CNormalGeneralPower::INVALID, CNormalGeneralPower::MODULO, CEvaluationNodeOperator::MODULUS, CNormalGeneralPower::POWER, CEvaluationNodeOperator::POWER, and pResult.

1141 {
1142  CEvaluationNode* pResult = NULL;
1143 
1144  switch (pow.getType())
1145  {
1148  break;
1151  break;
1153  break;
1154  }
1155 
1156  if (pResult != NULL)
1157  {
1158  if (pow.getRight().checkIsOne())
1159  {
1160  delete pResult;
1161  pResult = convertToCEvaluationNode(pow.getLeft());
1162  }
1163  else
1164  {
1166  pResult->addChild(pChild);
1167  pChild = convertToCEvaluationNode(pow.getRight());
1168  pResult->addChild(pChild);
1169  }
1170  }
1171 
1172  return pResult;
1173 }
bool checkIsOne() const
CNormalFraction & getLeft()
CEvaluationNode * convertToCEvaluationNode(const CNormalFraction &fraction)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CNormalFraction & getRight()
const CArrayAnnotation * pResult
CEvaluationNode* convertToCEvaluationNode ( const CNormalFunction fun)

Definition at line 1220 of file ConvertToCEvaluationNode.cpp.

References CNormalFunction::ABS, CEvaluationNodeFunction::ABS, CCopasiNode< _Data >::addChild(), CNormalFunction::ARCCOS, CEvaluationNodeFunction::ARCCOS, CNormalFunction::ARCCOSH, CEvaluationNodeFunction::ARCCOSH, CNormalFunction::ARCCOT, CEvaluationNodeFunction::ARCCOT, CNormalFunction::ARCCOTH, CEvaluationNodeFunction::ARCCOTH, CNormalFunction::ARCCSC, CEvaluationNodeFunction::ARCCSC, CNormalFunction::ARCCSCH, CEvaluationNodeFunction::ARCCSCH, CNormalFunction::ARCSEC, CEvaluationNodeFunction::ARCSEC, CNormalFunction::ARCSECH, CEvaluationNodeFunction::ARCSECH, CNormalFunction::ARCSIN, CEvaluationNodeFunction::ARCSIN, CNormalFunction::ARCSINH, CEvaluationNodeFunction::ARCSINH, CNormalFunction::ARCTAN, CEvaluationNodeFunction::ARCTAN, CNormalFunction::ARCTANH, CEvaluationNodeFunction::ARCTANH, CNormalFunction::CEIL, CEvaluationNodeFunction::CEIL, convertToCEvaluationNode(), CNormalFunction::COS, CEvaluationNodeFunction::COS, CNormalFunction::COSH, CEvaluationNodeFunction::COSH, CNormalFunction::COT, CEvaluationNodeFunction::COT, CNormalFunction::COTH, CEvaluationNodeFunction::COTH, CNormalFunction::CSC, CEvaluationNodeFunction::CSC, CNormalFunction::CSCH, CEvaluationNodeFunction::CSCH, CNormalFunction::EXP, CEvaluationNodeFunction::EXP, CNormalFunction::FACTORIAL, CEvaluationNodeFunction::FACTORIAL, CNormalFunction::FLOOR, CEvaluationNodeFunction::FLOOR, CNormalFunction::getFraction(), CNormalFunction::getType(), CEvaluationNodeFunction::INVALID, CNormalFunction::INVALID, CNormalFunction::LOG, CEvaluationNodeFunction::LOG, CNormalFunction::LOG10, CEvaluationNodeFunction::LOG10, CNormalFunction::NAMES, pResult, CNormalFunction::SEC, CEvaluationNodeFunction::SEC, CNormalFunction::SECH, CEvaluationNodeFunction::SECH, CNormalFunction::SIN, CEvaluationNodeFunction::SIN, CNormalFunction::SINH, CEvaluationNodeFunction::SINH, CNormalFunction::SQRT, CEvaluationNodeFunction::SQRT, CNormalFunction::TAN, CEvaluationNodeFunction::TAN, CNormalFunction::TANH, and CEvaluationNodeFunction::TANH.

1221 {
1222  CEvaluationNode* pResult = NULL;
1223  std::string data;
1225 
1226  switch (fun.getType())
1227  {
1228  case CNormalFunction::LOG:
1229  subType = CEvaluationNodeFunction::LOG;
1230  data = CNormalFunction::NAMES[fun.getType()];
1231  break;
1234  data = CNormalFunction::NAMES[fun.getType()];
1235  break;
1236  case CNormalFunction::EXP:
1237  subType = CEvaluationNodeFunction::EXP;
1238  data = CNormalFunction::NAMES[fun.getType()];
1239  break;
1240  case CNormalFunction::SIN:
1241  subType = CEvaluationNodeFunction::SIN;
1242  data = CNormalFunction::NAMES[fun.getType()];
1243  break;
1244  case CNormalFunction:: COS:
1245  subType = CEvaluationNodeFunction::COS;
1246  data = CNormalFunction::NAMES[fun.getType()];
1247  break;
1248  case CNormalFunction::TAN:
1249  subType = CEvaluationNodeFunction::TAN;
1250  data = CNormalFunction::NAMES[fun.getType()];
1251  break;
1252  case CNormalFunction::SEC:
1253  subType = CEvaluationNodeFunction::SEC;
1254  data = CNormalFunction::NAMES[fun.getType()];
1255  break;
1256  case CNormalFunction::CSC:
1257  subType = CEvaluationNodeFunction::CSC;
1258  data = CNormalFunction::NAMES[fun.getType()];
1259  break;
1260  case CNormalFunction::COT:
1261  subType = CEvaluationNodeFunction::COT;
1262  data = CNormalFunction::NAMES[fun.getType()];
1263  break;
1264  case CNormalFunction::SINH:
1266  data = CNormalFunction::NAMES[fun.getType()];
1267  break;
1268  case CNormalFunction::COSH:
1270  data = CNormalFunction::NAMES[fun.getType()];
1271  break;
1272  case CNormalFunction::TANH:
1274  data = CNormalFunction::NAMES[fun.getType()];
1275  break;
1276  case CNormalFunction::SECH:
1278  data = CNormalFunction::NAMES[fun.getType()];
1279  break;
1280  case CNormalFunction::CSCH:
1282  data = CNormalFunction::NAMES[fun.getType()];
1283  break;
1284  case CNormalFunction::COTH:
1286  data = CNormalFunction::NAMES[fun.getType()];
1287  break;
1290  data = CNormalFunction::NAMES[fun.getType()];
1291  break;
1294  data = CNormalFunction::NAMES[fun.getType()];
1295  break;
1298  data = CNormalFunction::NAMES[fun.getType()];
1299  break;
1302  data = CNormalFunction::NAMES[fun.getType()];
1303  break;
1306  data = CNormalFunction::NAMES[fun.getType()];
1307  break;
1310  data = CNormalFunction::NAMES[fun.getType()];
1311  break;
1314  data = CNormalFunction::NAMES[fun.getType()];
1315  break;
1318  data = CNormalFunction::NAMES[fun.getType()];
1319  break;
1322  data = CNormalFunction::NAMES[fun.getType()];
1323  break;
1326  data = CNormalFunction::NAMES[fun.getType()];
1327  break;
1330  data = CNormalFunction::NAMES[fun.getType()];
1331  break;
1334  data = CNormalFunction::NAMES[fun.getType()];
1335  break;
1336  case CNormalFunction::SQRT:
1338  data = CNormalFunction::NAMES[fun.getType()];
1339  break;
1340  case CNormalFunction::ABS:
1341  subType = CEvaluationNodeFunction::ABS;
1342  data = CNormalFunction::NAMES[fun.getType()];
1343  break;
1346  data = CNormalFunction::NAMES[fun.getType()];
1347  break;
1348  case CNormalFunction::CEIL:
1350  data = CNormalFunction::NAMES[fun.getType()];
1351  break;
1354  data = CNormalFunction::NAMES[fun.getType()];
1355  break;
1357  data = "@";
1358  break;
1359  }
1360 
1361  pResult = new CEvaluationNodeFunction(subType, data);
1362 
1363  if (subType != CEvaluationNodeFunction::INVALID)
1364  {
1366  pResult->addChild(pChild);
1367  }
1368 
1369  return pResult;
1370 }
CEvaluationNode * convertToCEvaluationNode(const CNormalFraction &fraction)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
static const char * NAMES[]
const CArrayAnnotation * pResult
Type getType() const
CNormalFraction & getFraction()
CEvaluationNode* convertToCEvaluationNode ( const CNormalCall call)

Definition at line 1175 of file ConvertToCEvaluationNode.cpp.

References CCopasiNode< _Data >::addChild(), convertToCEvaluationNode(), CEvaluationNodeDelay::DELAY, CNormalCall::DELAY, CNormalCall::EXPRESSION, CEvaluationNodeCall::EXPRESSION, CNormalCall::FUNCTION, CEvaluationNodeCall::FUNCTION, CNormalCall::getFractions(), CNormalCall::getName(), CNormalCall::getType(), CEvaluationNodeCall::INVALID, and CNormalCall::INVALID.

1176 {
1177  CEvaluationNode* pCall = NULL;
1178 
1179  // check if the name contains any non-whitespace characters at all
1180  if (call.getName().find_first_not_of("\t\r\n ") != std::string::npos)
1181  {
1183 
1184  switch (call.getType())
1185  {
1188  break;
1189  case CNormalCall::FUNCTION:
1191  break;
1192  case CNormalCall::DELAY:
1193  pCall = new CEvaluationNodeDelay(CEvaluationNodeDelay::DELAY, "delay");
1194  break;
1195  case CNormalCall::INVALID:
1196  break;
1197  }
1198 
1199  if (!pCall)
1200  {
1201  pCall = new CEvaluationNodeCall(type, call.getName());
1202  }
1203 
1204  const std::vector<CNormalFraction*>& children = call.getFractions();
1205 
1206  std::vector<CNormalFraction*>::const_iterator it = children.begin(), endit = children.end();
1207 
1208  while (it != endit)
1209  {
1210  CEvaluationNode* pChild = convertToCEvaluationNode(**it);
1211  assert(pChild != NULL);
1212  pCall->addChild(pChild);
1213  ++it;
1214  }
1215  }
1216 
1217  return pCall;
1218 }
const std::string & getName() const
CEvaluationNode * convertToCEvaluationNode(const CNormalFraction &fraction)
const std::vector< CNormalFraction * > & getFractions() const
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
Type getType() const
CNormalCall* createCall ( const CEvaluationNode node)

Create an function call from an evaluation node.

Returns
CNormalCall*, pointer to newly created call

Definition at line 1451 of file ConvertToCEvaluationNode.cpp.

References CNormalCall::add(), CEvaluationNode::CALL, createNormalRepresentation(), CNormalCall::DELAY, CEvaluationNode::DELAY, CNormalCall::EXPRESSION, CEvaluationNodeCall::EXPRESSION, CNormalCall::FUNCTION, CEvaluationNodeCall::FUNCTION, CCopasiNode< _Data >::getChild(), CCopasiNode< _Data >::getData(), CCopasiNode< _Data >::getSibling(), CEvaluationNode::getType(), CEvaluationNodeCall::INVALID, CNormalCall::INVALID, CNormalCall::setName(), CNormalCall::setType(), CEvaluationNode::subType(), and CEvaluationNode::type().

Referenced by createItemPower(), and createItemPowerItem().

1452 {
1453  CNormalCall* pCall = NULL;
1455 
1456  if (type == CEvaluationNode::CALL || type == CEvaluationNode::DELAY)
1457  {
1458  // create a call object and add all children
1459  pCall = new CNormalCall();
1460  // set the name
1461  pCall->setName(node->getData());
1462  const CEvaluationNode* pChild = dynamic_cast<const CEvaluationNode*>(node->getChild());
1463 
1464  while (pChild != NULL)
1465  {
1466  CNormalFraction* pFraction = createNormalRepresentation(pChild);
1467  assert(pFraction != NULL);
1468  pCall->add(*pFraction);
1469  delete pFraction;
1470  pChild = dynamic_cast<const CEvaluationNode*>(pChild->getSibling());
1471  }
1472 
1473  if (type == CEvaluationNode::DELAY)
1474  {
1475  pCall->setType(CNormalCall::DELAY);
1476  }
1477  else
1478  {
1480 
1481  switch (subType)
1482  {
1485  break;
1488  break;
1490  pCall->setType(CNormalCall::INVALID);
1491  break;
1492  }
1493  }
1494  }
1495 
1496  return pCall;
1497 }
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
void setType(Type type)
const Type & getType() const
void setName(const std::string &name)
static Type type(const Type &type)
bool add(const CNormalFraction &fraction)
static Type subType(const Type &type)
CNormalFraction * createNormalRepresentation(const CEvaluationNode *node)
virtual const Data & getData() const
Definition: CCopasiNode.h:118
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CNormalChoice* createChoice ( const CEvaluationNode pNode)

This version of the method is wrong. CEvaluationNode* convertToCEvaluationNode(const CNormalLogical& logical) { CEvaluationNode* pResult = NULL; bool error = false; CEvaluationNodeFunction* pNot = NULL; CNormalLogical::ItemSetOfSets::const_iterator it = logical.getAndSets().begin(), endit = logical.getAndSets().end(); std::vector<CEvaluationNode*> andItems; while (it != endit && error == false) { CEvaluationNode* pTmpResult = NULL; if ((it).first.size() == 1) { pTmpResult = convertToCEvaluationNode(*(*(*it).first.begin()).first); if ((*(*it).first.begin()).second == true) { pNot = new CEvaluationNodeFunction(CEvaluationNodeFunction::NOT, "NOT"); pNot->addChild(pTmpResult); pTmpResult = pNot; } } else if ((*it).first.size() > 1) { CNormalLogical::ItemSet::const_iterator innerit = (*it).first.begin(), innerendit = (*it).first.end(); create the not CEvaluationNode pOrNode = new CEvaluationNodeLogical(CEvaluationNodeLogical::OR, "OR"); pTmpResult = pOrNode; while (innerit != innerendit && error == false) { CEvaluationNode* pItem = convertToCEvaluationNode(*(innerit).first); if (pItem != NULL) { if ((*innerit).second == true) { pNot = new CEvaluationNodeFunction(CEvaluationNodeFunction::NOT, "NOT"); pNot->addChild(pItem); pItem = pNot; } pOrNode->addChild(pItem); pOrNode->addChild(new CEvaluationNodeLogical(CEvaluationNodeLogical::OR, "OR")); pOrNode = dynamic_cast<CEvaluationNodeLogical>(pOrNode->getChild()->getSibling()); } else { error = true; delete pTmpResult; pTmpResult = NULL; } ++innerit; } if (error == false) { replace the parent of the current pOrNode with its first child; CEvaluationNode * pGrandParent = dynamic_cast<CEvaluationNode*>(pOrNode->getParent()); pGrandParent->removeChild(pOrNode->getParent()); pOrNode = dynamic_cast<CEvaluationNode*>(pOrNode->getParent()); CEvaluationNode* pChild = dynamic_cast<CEvaluationNode*>(pOrNode->getChild()); pOrNode->removeChild(pChild); pGrandParent->addChild(pChild); delete pOrNode; } } if (pTmpResult != NULL) { if ((it).second == true) { pNot = new CEvaluationNodeFunction(CEvaluationNodeFunction::NOT, "NOT"); pNot->addChild(pTmpResult); } andItems.push_back(pTmpResult); } ++it; } CNormalLogical::ChoiceSetOfSets::const_iterator it2 = logical.getChoices().begin(), endit2 = logical.getChoices().end(); while (it2 != endit2 && error == false) { CEvaluationNode pTmpResult = NULL; if ((it2).first.size() == 1) { pTmpResult = convertToCEvaluationNode(*(*(*it2).first.begin()).first); if ((*(*it2).first.begin()).second == true) { pNot = new CEvaluationNodeFunction(CEvaluationNodeFunction::NOT, "NOT"); pNot->addChild(pTmpResult); pTmpResult = pNot; } } else if ((*it2).first.size() > 1) { CNormalLogical::ChoiceSet::const_iterator innerit = (*it2).first.begin(), innerendit = (*it2).first.end(); create the not CEvaluationNode pOrNode = new CEvaluationNodeLogical(CEvaluationNodeLogical::OR, "OR"); pTmpResult = pOrNode; while (innerit != innerendit && error != true) { CEvaluationNode* pItem = convertToCEvaluationNode(*(innerit).first); if (pItem != NULL) { if ((*innerit).second == true) { pNot = new CEvaluationNodeFunction(CEvaluationNodeFunction::NOT, "NOT"); pNot->addChild(pItem); pItem = pNot; } pOrNode->addChild(pItem); pOrNode->addChild(new CEvaluationNodeLogical(CEvaluationNodeLogical::OR, "OR")); pOrNode = dynamic_cast<CEvaluationNodeLogical>(pOrNode->getChild()->getSibling()); } else { delete pTmpResult; pTmpResult = NULL; error = true; } ++innerit; } replace the parent of the current pOrNode with its first child; if (error == false) { CEvaluationNode * pGrandParent = dynamic_cast<CEvaluationNode*>(pOrNode->getParent()); pGrandParent->removeChild(pOrNode->getParent()); pOrNode = dynamic_cast<CEvaluationNode*>(pOrNode->getParent()); CEvaluationNode* pChild = dynamic_cast<CEvaluationNode*>(pOrNode->getChild()); pOrNode->removeChild(pChild); pGrandParent->addChild(pChild); delete pOrNode; } } if (pTmpResult != NULL) { if ((it2).second == true) { pNot = new CEvaluationNodeFunction(CEvaluationNodeFunction::NOT, "NOT"); pNot->addChild(pTmpResult); } andItems.push_back(pTmpResult); } ++it2; } if (!andItems.empty()) { if (error == false) { if (andItems.size() == 1) { pResult = *andItems.begin(); } else { std::vector<CEvaluationNode>::iterator andit = andItems.begin(), andendit = andItems.end(); CEvaluationNode* pAndNode = new CEvaluationNodeLogical(CEvaluationNodeLogical::AND, "AND"); pResult = pAndNode; while (andit != andendit) { pAndNode->addChild(<em>andit); pAndNode->addChild(new CEvaluationNodeLogical(CEvaluationNodeLogical::AND, "AND")); pAndNode = dynamic_cast<CEvaluationNodeLogical>(pAndNode->getChild()->getSibling()); ++andit; } replace the parent of the current pAndNode with its first child; CEvaluationNode* pGrandParent = dynamic_cast<CEvaluationNode*>(pAndNode->getParent()); pGrandParent->removeChild(pAndNode->getParent()); pAndNode = dynamic_cast<CEvaluationNode*>(pAndNode->getParent()); CEvaluationNode* pChild = dynamic_cast<CEvaluationNode*>(pAndNode->getChild()); pAndNode->removeChild(pChild); pGrandParent->addChild(pChild); delete pAndNode; } } else { an error has occured, we need to free the memory taken by all andItems std::vector<CEvaluationNode*>::iterator andit = andItems.begin(), andendit = andItems.end(); while (andit != andendit) { delete (*andit); ++andit; } } } if (pResult != NULL) { if (logical.isNegated() == true) { pNot = new CEvaluationNodeFunction(CEvaluationNodeFunction::NOT, "NOT"); pNot->addChild(pResult); pResult = pNot; } pResult->compile(NULL); } return pResult; }

Definition at line 2245 of file ConvertToCEvaluationNode.cpp.

References CEvaluationNode::CHOICE, createLogical(), createNormalRepresentation(), CCopasiNode< _Data >::getChild(), CEvaluationNode::getType(), pResult, CNormalChoice::setCondition(), CNormalChoice::setFalseExpression(), CNormalChoice::setTrueExpression(), and CEvaluationNode::type().

Referenced by createItemPower(), and createItemPowerItem().

2246 {
2247  CNormalChoice* pResult = NULL;
2248 
2249  if (pNode != NULL && CEvaluationNode::type(pNode->getType()) == CEvaluationNode::CHOICE)
2250  {
2251  CNormalLogical* pLogical = createLogical(dynamic_cast<const CEvaluationNode*>(pNode->getChild()));
2252 
2253  if (pLogical != NULL)
2254  {
2255  CNormalFraction* pTrueFraction = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(pNode->getChild()->getSibling()));
2256 
2257  if (pTrueFraction != NULL)
2258  {
2259  // the false branch is optional
2260  const CEvaluationNode* pFalseBranch = dynamic_cast<const CEvaluationNode*>(pNode->getChild()->getSibling()->getSibling());
2261 
2262  if (pFalseBranch != NULL)
2263  {
2264  CNormalFraction* pFalseFraction = createNormalRepresentation(pFalseBranch);
2265 
2266  if (pFalseFraction != NULL)
2267  {
2268  pResult = new CNormalChoice();
2269  pResult->setCondition(*pLogical);
2270  pResult->setTrueExpression(*pTrueFraction);
2271  pResult->setFalseExpression(*pFalseFraction);
2272  delete pFalseFraction;
2273  }
2274  }
2275  else
2276  {
2277  CNormalFraction* pFalseFraction = new CNormalFraction();
2278  pResult = new CNormalChoice();
2279  pResult->setCondition(*pLogical);
2280  pResult->setTrueExpression(*pTrueFraction);
2281  pResult->setFalseExpression(*pFalseFraction);
2282  delete pFalseFraction;
2283  }
2284 
2285  delete pTrueFraction;
2286  }
2287 
2288  delete pLogical;
2289  }
2290  }
2291 
2292  return pResult;
2293 }
CNormalLogical * createLogical(const CEvaluationNode *pNode)
bool setTrueExpression(const CNormalFraction &branch)
const Type & getType() const
bool setFalseExpression(const CNormalFraction &branch)
static Type type(const Type &type)
bool setCondition(const CNormalLogical &cond)
const CArrayAnnotation * pResult
CNormalFraction * createNormalRepresentation(const CEvaluationNode *node)
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CNormalFraction* createFraction ( const CEvaluationNode node)

Create a fraction from a node. node is necessarily a DIVIDE operator if not the root node of the tree.

Returns
CNormalFraction*, pointer to newly created fraction.

Definition at line 308 of file ConvertToCEvaluationNode.cpp.

References CNormalSum::add(), CNormalFraction::cancel(), CNormalTranslation::createChain(), createSum(), CCopasiNode< _Data >::getData(), CNormalTranslation::ONE_NODE, CNormalFraction::setDenominator(), CNormalFraction::setNumerator(), CNormalTranslation::splitProduct(), and CNormalTranslation::TIMES_NODE.

Referenced by createItemPowerItem(), and createNormalRepresentation().

309 {
310  CNormalFraction* pFraction = new CNormalFraction();
311 
312  if (node->getData() == "/")
313  {// always executed except on root node possibly not
314  // find a product chain and create new temporary nodes for the
315  // numerator and denominator which are then converted to sums
316  std::vector<const CEvaluationNode*> multiplications, divisions;
317  CNormalTranslation::splitProduct(node, multiplications, divisions, false);
318  std::vector<CEvaluationNode*> tmp;
319  std::vector<const CEvaluationNode*>::const_iterator it = multiplications.begin(), endit = multiplications.end();
320 
321  while (it != endit)
322  {
323  tmp.push_back((*it)->copyBranch());
324  ++it;
325  }
326 
328  assert(pTmpNode != NULL);
329  CNormalSum* pNum = createSum(pTmpNode);
330  assert(pNum != NULL);
331  delete pTmpNode;
332  tmp.clear();
333  it = divisions.begin();
334  endit = divisions.end();
335 
336  while (it != endit)
337  {
338  tmp.push_back((*it)->copyBranch());
339  ++it;
340  }
341 
343  assert(pTmpNode != NULL);
344  CNormalSum* pDenom = createSum(pTmpNode);
345  assert(pDenom != NULL);
346  delete pTmpNode;
347  pFraction->setNumerator(*pNum);
348  pFraction->setDenominator(*pDenom);
349  //pFraction->cancel();
350  delete pNum;
351  delete pDenom;
352  }
353  else
354  {// only possible for root node
355  CNormalSum* pNum = createSum(node);
356  CNormalSum* pDenom = new CNormalSum();
357  CNormalProduct* pProduct = new CNormalProduct();
358  pDenom->add(*pProduct);
359  pFraction->setNumerator(*pNum);
360  pFraction->setDenominator(*pDenom);
361  pFraction->cancel();
362  delete pProduct;
363  delete pNum;
364  delete pDenom;
365  }
366 
367  return pFraction;
368 };
CNormalSum * createSum(const CEvaluationNode *node)
bool add(const CNormalProduct &product)
Definition: CNormalSum.cpp:156
static const CEvaluationNode ONE_NODE
bool setDenominator(const CNormalSum &denominator)
static void splitProduct(const CEvaluationNode *pRoot, std::vector< const CEvaluationNode * > &multiplications, std::vector< const CEvaluationNode * > &divisions, bool division)
bool setNumerator(const CNormalSum &numerator)
static const CEvaluationNode TIMES_NODE
virtual const Data & getData() const
Definition: CCopasiNode.h:118
static CEvaluationNode * createChain(const CEvaluationNode *pLink, const CEvaluationNode *pNeutralElement, const std::vector< const CEvaluationNode * > &elements)
CNormalFunction* createFunction ( const CEvaluationNode node)

Create an function from an evaluation node.

Returns
CNormalFunction*, pointer to newly created function

Definition at line 1503 of file ConvertToCEvaluationNode.cpp.

References CNormalFunction::ABS, CEvaluationNodeFunction::ABS, CNormalFunction::ARCCOS, CEvaluationNodeFunction::ARCCOS, CNormalFunction::ARCCOSH, CEvaluationNodeFunction::ARCCOSH, CNormalFunction::ARCCOT, CEvaluationNodeFunction::ARCCOT, CNormalFunction::ARCCOTH, CEvaluationNodeFunction::ARCCOTH, CNormalFunction::ARCCSC, CEvaluationNodeFunction::ARCCSC, CNormalFunction::ARCCSCH, CEvaluationNodeFunction::ARCCSCH, CNormalFunction::ARCSEC, CEvaluationNodeFunction::ARCSEC, CNormalFunction::ARCSECH, CEvaluationNodeFunction::ARCSECH, CNormalFunction::ARCSIN, CEvaluationNodeFunction::ARCSIN, CNormalFunction::ARCSINH, CEvaluationNodeFunction::ARCSINH, CNormalFunction::ARCTAN, CEvaluationNodeFunction::ARCTAN, CNormalFunction::ARCTANH, CEvaluationNodeFunction::ARCTANH, CNormalFunction::CEIL, CEvaluationNodeFunction::CEIL, CNormalFunction::COS, CEvaluationNodeFunction::COS, CNormalFunction::COSH, CEvaluationNodeFunction::COSH, CNormalFunction::COT, CEvaluationNodeFunction::COT, CNormalFunction::COTH, CEvaluationNodeFunction::COTH, createNormalRepresentation(), CNormalFunction::CSC, CEvaluationNodeFunction::CSC, CNormalFunction::CSCH, CEvaluationNodeFunction::CSCH, CNormalFunction::EXP, CEvaluationNodeFunction::EXP, CNormalFunction::FACTORIAL, CEvaluationNodeFunction::FACTORIAL, CNormalFunction::FLOOR, CEvaluationNodeFunction::FLOOR, CEvaluationNode::FUNCTION, CCopasiNode< _Data >::getChild(), CEvaluationNode::getType(), CEvaluationNodeFunction::INVALID, CNormalFunction::INVALID, CNormalFunction::LOG, CEvaluationNodeFunction::LOG, CNormalFunction::LOG10, CEvaluationNodeFunction::LOG10, CNormalFunction::SEC, CEvaluationNodeFunction::SEC, CNormalFunction::SECH, CEvaluationNodeFunction::SECH, CNormalFunction::setFraction(), CNormalFunction::setType(), CNormalFunction::SIN, CEvaluationNodeFunction::SIN, CNormalFunction::SINH, CEvaluationNodeFunction::SINH, CNormalFunction::SQRT, CEvaluationNodeFunction::SQRT, CEvaluationNode::subType(), CNormalFunction::TAN, CEvaluationNodeFunction::TAN, CNormalFunction::TANH, CEvaluationNodeFunction::TANH, and CEvaluationNode::type().

Referenced by createItemPower(), and createItemPowerItem().

1504 {
1505  CNormalFunction* pFun = NULL;
1507 
1508  if (type == CEvaluationNode::FUNCTION)
1509  {
1511 
1513  {
1515  type = CNormalFunction::LOG;
1516  break;
1518  type = CNormalFunction::LOG10;
1519  break;
1521  type = CNormalFunction::EXP;
1522  break;
1524  type = CNormalFunction::SIN;
1525  break;
1527  type = CNormalFunction::COS;
1528  break;
1530  type = CNormalFunction::TAN;
1531  break;
1533  type = CNormalFunction::SEC;
1534  break;
1536  type = CNormalFunction::CSC;
1537  break;
1539  type = CNormalFunction::COT;
1540  break;
1542  type = CNormalFunction::SINH;
1543  break;
1545  type = CNormalFunction::COSH;
1546  break;
1548  type = CNormalFunction::TANH;
1549  break;
1551  type = CNormalFunction::SECH;
1552  break;
1554  type = CNormalFunction::CSCH;
1555  break;
1557  type = CNormalFunction::COTH;
1558  break;
1560  type = CNormalFunction::ARCSIN;
1561  break;
1563  type = CNormalFunction::ARCCOS;
1564  break;
1566  type = CNormalFunction::ARCTAN;
1567  break;
1569  type = CNormalFunction::ARCSEC;
1570  break;
1572  type = CNormalFunction::ARCCSC;
1573  break;
1575  type = CNormalFunction::ARCCOT;
1576  break;
1578  type = CNormalFunction::ARCSINH;
1579  break;
1581  type = CNormalFunction::ARCCOSH;
1582  break;
1584  type = CNormalFunction::ARCTANH;
1585  break;
1587  type = CNormalFunction::ARCSECH;
1588  break;
1590  type = CNormalFunction::ARCCSCH;
1591  break;
1593  type = CNormalFunction::ARCCOTH;
1594  break;
1596  type = CNormalFunction::SQRT;
1597  break;
1599  type = CNormalFunction::ABS;
1600  break;
1602  type = CNormalFunction::FLOOR;
1603  break;
1605  type = CNormalFunction::CEIL;
1606  break;
1609  break;
1611  default:
1612  assert(false);
1613  break;
1614  }
1615 
1616  if (type != CNormalFunction::INVALID)
1617  {
1618  CNormalFraction* pFrac = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(node->getChild()));
1619 
1620  if (pFrac != NULL)
1621  {
1622  pFun = new CNormalFunction();
1623  pFun->setType(type);
1624  pFun->setFraction(*pFrac);
1625  delete pFrac;
1626  }
1627  }
1628  }
1629 
1630  return pFun;
1631 }
const Type & getType() const
void setFraction(const CNormalFraction &frac)
static Type type(const Type &type)
void setType(Type type)
static Type subType(const Type &type)
CNormalFraction * createNormalRepresentation(const CEvaluationNode *node)
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CNormalGeneralPower* createGeneralPower ( const CEvaluationNode node)

Create an general power from an evaluation node. Node MUST BE a POWER operator with second child (exponent) of type not NUMBER !!

Returns
CNormalItemPower*, pointer to newly created general power (or modulo).

Create an general power from an evaluation node. if it is a power node, create a for each child and set base and exponent, else only create the base from the node and set the exponent to 1

Returns
CNormalItemPower*, pointer to newly created general power (or modulo).

Definition at line 1378 of file ConvertToCEvaluationNode.cpp.

References createNormalRepresentation(), CEvaluationNodeNumber::DOUBLE, CCopasiNode< _Data >::getChild(), CEvaluationNode::getType(), CNormalGeneralPower::MODULO, CEvaluationNodeOperator::MODULUS, CEvaluationNode::OPERATOR, CNormalGeneralPower::POWER, CEvaluationNodeOperator::POWER, CNormalGeneralPower::setLeft(), CNormalGeneralPower::setRight(), CNormalGeneralPower::setType(), CEvaluationNode::subType(), and CEvaluationNode::type().

Referenced by createItemPower(), and createItemPowerItem().

1379 {
1380  CNormalGeneralPower* pPow = NULL;
1381 
1382  if (node != NULL)
1383  {
1385  {
1387  {
1388  pPow = new CNormalGeneralPower();
1390  }
1392  {
1393  pPow = new CNormalGeneralPower();
1395  }
1396 
1397  if (pPow != NULL)
1398  {
1399  // add the left and the right side
1400  CNormalFraction* pBase = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(node->getChild()));
1401  CNormalFraction* pExponent = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(node->getChild()->getSibling()));
1402  assert(pBase != NULL);
1403  assert(pExponent != NULL);
1404  pPow->setLeft(*pBase);
1405  pPow->setRight(*pExponent);
1406  delete pBase;
1407  delete pExponent;
1408  }
1409  else
1410  {
1411  // create a fraction for the base and a unit fraction for the exponent
1412  pPow = new CNormalGeneralPower();
1414  CNormalFraction* pBase = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(node));
1416  CNormalFraction* pExponent = createNormalRepresentation(pTmpNode);
1417  delete pTmpNode;
1418  assert(pBase != NULL);
1419  assert(pExponent != NULL);
1420  pPow->setLeft(*pBase);
1421  pPow->setRight(*pExponent);
1422  delete pBase;
1423  delete pExponent;
1424  }
1425  }
1426  else
1427  {
1428  // create a fraction for the base and a unit fraction for the exponent
1429  pPow = new CNormalGeneralPower();
1431  CNormalFraction* pBase = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(node));
1433  CNormalFraction* pExponent = createNormalRepresentation(pTmpNode);
1434  delete pTmpNode;
1435  assert(pBase != NULL);
1436  assert(pExponent != NULL);
1437  pPow->setLeft(*pBase);
1438  pPow->setRight(*pExponent);
1439  delete pBase;
1440  delete pExponent;
1441  }
1442  }
1443 
1444  return pPow;
1445 }
const Type & getType() const
static Type type(const Type &type)
void setRight(const CNormalFraction &right)
static Type subType(const Type &type)
CNormalFraction * createNormalRepresentation(const CEvaluationNode *node)
void setLeft(const CNormalFraction &left)
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CNormalItem* createItem ( const CEvaluationNode pNode)

Create an item from an evaluation node that need not be of specific type.

Returns
CNormalItem*, pointer to newly created item.

Definition at line 374 of file ConvertToCEvaluationNode.cpp.

References CEvaluationNode::buildInfix(), CNormalItem::CONSTANT, CEvaluationNode::CONSTANT, CEvaluationNode::getType(), CEvaluationNode::type(), CNormalItem::VARIABLE, and CEvaluationNode::VARIABLE.

Referenced by createItemPower(), and createItemPowerItem().

375 {
376  CNormalItem* pItem = NULL;
377 
378  switch (CEvaluationNode::type(pNode->getType()))
379  {
381  pItem = new CNormalItem(pNode->buildInfix(), CNormalItem::VARIABLE);
382  break;
384  pItem = new CNormalItem(pNode->buildInfix(), CNormalItem::CONSTANT);
385  break;
386  /*
387  case CEvaluationNode::OPERATOR:
388  if (((CEvaluationNodeOperator::SubType)CEvaluationNode::subType(pNode->getType()))==CEvaluationNodeOperator::POWER
389  || ((CEvaluationNodeOperator::SubType)CEvaluationNode::subType(pNode->getType()))==CEvaluationNodeOperator::MODULUS)
390  {
391  // calling createItem will add the wrong pNode for the
392  // string into the lookup table
393  CNormalItem * child1 = createItem(dynamic_cast<const CEvaluationNode*>(pNode->getChild()));
394  CNormalItem * child2 = createItem(dynamic_cast<const CEvaluationNode*>(pNode->getChild()->getSibling()));
395 
396  std::stringstream tmp;
397  if ((child1->getType() == CNormalItem::VARIABLE) || (child1->getType() == CNormalItem::CONSTANT))
398  tmp << *child1;
399  else
400  {
401  tmp << "(" << *child1 << ")";
402  }
403  tmp << pNode->getData();
404  if ((child2->getType() == CNormalItem::VARIABLE) || (child2->getType() == CNormalItem::CONSTANT))
405  tmp << *child2;
406  else
407  {
408  tmp << "(" << *child2 << ")";
409  }
410 
411  pItem = new CNormalItem(tmp.str(), CNormalItem::FUNCTION);
412  std::string s=tmp.str();
413  std::map<std::string,const CEvaluationNode*>::const_iterator pos=str2eval.find(tmp.str());
414  if(pos==str2eval.end())
415  {
416  CEvaluationNodeOperator::SubType type=CEvaluationNodeOperator::POWER;
417  std::string s("^");
418  if(pNode->getData()=="%")
419  {
420  type=CEvaluationNodeOperator::MODULUS;
421  s="%";
422  }
423  CEvaluationNodeOperator* pNode=new CEvaluationNodeOperator(type,s);
424  // when the child pNode is converted, the wrongly added
425  // pNode from above is returned
426 
427  pNode->addChild(convertToCEvaluationNode(*child1));
428  pNode->addChild(convertToCEvaluationNode(*child2));
429  //pNode->printRecursively(std::cerr);
430  str2eval[tmp.str()]=pNode;
431  }
432  delete child1;
433  delete child2;
434  }
435  else // can be called only by createItem('OPERATOR pNode')
436  {
437  CNormalFraction * normedNode = createFraction(pNode);
438  normedNode->simplify();
439  CEvaluationNode* pTmpNode=convertToCEvaluationNode(*normedNode);
440  std::stringstream tmp;
441  tmp << *normedNode;
442  pItem = new CNormalItem(tmp.str(), CNormalItem::FUNCTION);
443  std::map<std::string,const CEvaluationNode*>::const_iterator pos=str2eval.find(normedNode->toString());
444  if(pos==str2eval.end())
445  {
446  str2eval[tmp.str()]=pTmpNode;
447  }
448 
449  delete normedNode;
450  }
451  break;
452  */
453  default: //cases CALL, CHOICE, LOGICAL, OBJECT, VECTOR. NUMBER should not occur!
454  throw std::exception();
455  break;
456  }
457 
458  return pItem;
459 }
const Type & getType() const
std::string buildInfix() const
static Type type(const Type &type)
CNormalItemPower* createItemPower ( const CEvaluationNode node)

Create an item power from an evaluation node. Node MUST BE a POWER operator with second child (exponent) of type NUMBER !!

Returns
CNormalItemPower*, pointer to newly created item power.

Create an item power from an evaluation node. Depending on the given node, we have to create different items. Either we have to create a CNormalItem, a CNormalGeneralPower, a function or a choice.

Definition at line 467 of file ConvertToCEvaluationNode.cpp.

References CCopasiNode< _Data >::addChild(), C_FLOAT64, CEvaluationNode::CALL, CEvaluationNode::CHOICE, CEvaluationNode::CONSTANT, createCall(), createChoice(), createFunction(), createGeneralPower(), createItem(), createItemPower(), createItemPowerItem(), CEvaluationNode::DELAY, CEvaluationNodeNumber::DOUBLE, CEvaluationNode::FUNCTION, CCopasiNode< _Data >::getChild(), CEvaluationNode::getType(), CEvaluationNode::LOGICAL, CEvaluationNodeFunction::MINUS, CEvaluationNodeOperator::MULTIPLY, CEvaluationNode::NUMBER, CEvaluationNode::OBJECT, CEvaluationNode::OPERATOR, CEvaluationNodeOperator::POWER, CNormalItemPower::setExp(), CNormalItemPower::setItem(), CEvaluationNode::subType(), CEvaluationNode::type(), and CEvaluationNode::VARIABLE.

Referenced by createItemPower(), createItemPowerItem(), and createProduct().

468 {
469  // make sure we create the correct item for the given node
470  CNormalItemPower * pItemPower = new CNormalItemPower();
471 
473  {
474  // check if the second child is a number
475  if (CEvaluationNode::type(dynamic_cast<const CEvaluationNode*>(node->getChild()->getSibling())->getType()) == CEvaluationNode::NUMBER)
476  {
477  // we set the exponent to that number
478  pItemPower->setExp((C_FLOAT64)dynamic_cast<const CEvaluationNodeNumber*>(node->getChild()->getSibling())->getValue());
479  // check if we can create a CNormalItem object for the fist child, else we
480  // create a general power with exponent 1
481  CEvaluationNode::Type type = CEvaluationNode::type(dynamic_cast<const CEvaluationNode*>(node->getChild())->getType());
482 
484  {
485  CNormalBase* pItem = createItemPowerItem(dynamic_cast<const CEvaluationNode*>(node->getChild()));
486  assert(pItem != NULL);
487  pItemPower->setItem(*pItem);
488  delete pItem;
489  }
490  else
491  {
492  // create a general power for the child node
493  CNormalGeneralPower* pGeneralPower = createGeneralPower(dynamic_cast<const CEvaluationNode*>(node->getChild()));
494  assert(pGeneralPower != NULL);
495  pItemPower->setItem(*pGeneralPower);
496  delete pGeneralPower;
497  }
498  }
499  else
500  {
501  // create a general power for the node
502  CNormalGeneralPower* pGeneralPower = createGeneralPower(node);
503  assert(pGeneralPower != NULL);
504  pItemPower->setItem(*pGeneralPower);
505  pItemPower->setExp(1.0);
506  delete pGeneralPower;
507  }
508  }
510  {
512  {
513  // multiply the second node by -1 and call createItempower with the
514  // result
517  pOperatorNode->addChild(pNumberNode);
518  pOperatorNode->addChild(dynamic_cast<const CEvaluationNode*>(node->getChild())->copyBranch());
519  // delete the old item power object
520  delete pItemPower;
521  // create a new item power object by calling this method again with
522  // the newly created multiplication node
523  pItemPower = createItemPower(pOperatorNode);
524  // delete the multiplication node
525  delete pOperatorNode;
526  }
527  else
528  {
529  CNormalFunction* pFunction = createFunction(node);
530  assert(pFunction != NULL);
531  pItemPower->setItem(*pFunction);
532  delete pFunction;
533  pItemPower->setExp(1.0);
534  }
535  }
537  {
538  CNormalCall* pCall = createCall(node);
539  assert(pCall != NULL);
540  pItemPower->setItem(*pCall);
541  delete pCall;
542  pItemPower->setExp(1.0);
543  }
545  {
546  CNormalChoice* pChoice = createChoice(node);
547  assert(pChoice != NULL);
548  pItemPower->setItem(*pChoice);
549  delete pChoice;
550  pItemPower->setExp(1.0);
551  }
553  {
554  CNormalItem* pItem = createItem(node);
555  assert(pItem != NULL);
556  pItemPower->setItem(*pItem);
557  delete pItem;
558  pItemPower->setExp(1.0);
559  }
561  {
562  CNormalBase* pItem = createItemPowerItem(node);
563  assert(pItem != NULL);
564  pItemPower->setItem(*pItem);
565  delete pItem;
566  pItemPower->setExp(1.0);
567  }
568  else
569  {
570  // create a general power for the node
571  CNormalGeneralPower* pGeneralPower = createGeneralPower(node);
572  assert(pGeneralPower != NULL);
573  pItemPower->setItem(*pGeneralPower);
574  pItemPower->setExp(1.0);
575  delete pGeneralPower;
576  }
577 
578  return pItemPower;
579 }
CNormalItem * createItem(const CEvaluationNode *pNode)
const Type & getType() const
CNormalChoice * createChoice(const CEvaluationNode *pNode)
bool setItem(const CNormalBase &item)
static Type type(const Type &type)
CNormalBase * createItemPowerItem(const CEvaluationNode *pNode)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CNormalItemPower * createItemPower(const CEvaluationNode *node)
static Type subType(const Type &type)
#define C_FLOAT64
Definition: copasi.h:92
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CNormalGeneralPower * createGeneralPower(const CEvaluationNode *node)
CNormalFunction * createFunction(const CEvaluationNode *node)
bool setExp(const C_FLOAT64 &number)
CNormalCall * createCall(const CEvaluationNode *node)
CNormalBase* createItemPowerItem ( const CEvaluationNode pNode)

Definition at line 1660 of file ConvertToCEvaluationNode.cpp.

References CEvaluationNode::CALL, CEvaluationNode::CHOICE, CEvaluationNode::CONSTANT, createCall(), createChoice(), createFraction(), createFunction(), createGeneralPower(), createItem(), createItemPower(), createLogical(), CEvaluationNode::FUNCTION, CCopasiNode< _Data >::getChild(), CEvaluationNode::getType(), CEvaluationNode::LOGICAL, CEvaluationNodeOperator::MODULUS, CEvaluationNode::NUMBER, CEvaluationNode::OPERATOR, CEvaluationNodeOperator::POWER, pResult, CEvaluationNode::subType(), CEvaluationNode::type(), and CEvaluationNode::VARIABLE.

Referenced by createItemPower().

1661 {
1662  CNormalBase* pResult = NULL;
1665 
1666  switch (type)
1667  {
1670 
1671  if (subType == CEvaluationNodeOperator::POWER)
1672  {
1673  if ((CEvaluationNode::type(dynamic_cast<const CEvaluationNode*>(pNode->getChild()->getSibling())->getType())) == CEvaluationNode::NUMBER)
1674  {
1675  pResult = createItemPower(pNode);
1676  }
1677  else
1678  {
1679  pResult = createGeneralPower(pNode);
1680  }
1681  }
1683  {
1684  pResult = createGeneralPower(pNode);
1685  }
1686  else
1687  {
1688  pResult = createFraction(pNode);
1689  }
1690 
1691  break;
1693  pResult = createItem(pNode);
1694  break;
1696  pResult = createFunction(pNode);
1697  break;
1698  case CEvaluationNode::CALL:
1699  pResult = createCall(pNode);
1700  break;
1702  pResult = createChoice(pNode);
1703  break;
1705  pResult = createLogical(pNode);
1706  break;
1708  pResult = createItem(pNode);
1709  break;
1711  pResult = createItem(pNode);
1712  break;
1713  default:
1714  break;
1715  }
1716 
1717  return pResult;
1718 }
CNormalItem * createItem(const CEvaluationNode *pNode)
CNormalLogical * createLogical(const CEvaluationNode *pNode)
const Type & getType() const
CNormalChoice * createChoice(const CEvaluationNode *pNode)
static Type type(const Type &type)
CNormalFraction * createFraction(const CEvaluationNode *node)
CNormalItemPower * createItemPower(const CEvaluationNode *node)
const CArrayAnnotation * pResult
static Type subType(const Type &type)
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CNormalGeneralPower * createGeneralPower(const CEvaluationNode *node)
CNormalFunction * createFunction(const CEvaluationNode *node)
CNormalCall * createCall(const CEvaluationNode *node)
CNormalLogical* createLogical ( const CEvaluationNode pNode)

Definition at line 2345 of file ConvertToCEvaluationNode.cpp.

References CCopasiNode< _Data >::addChild(), CEvaluationNodeLogical::AND, CEvaluationNode::CHOICE, CEvaluationNode::CONSTANT, CEvaluationNode::copyBranch(), CNormalLogical::copySet(), createLogical(), createLogicalChoice(), createLogicalItem(), CEvaluationNodeLogical::EQ, CEvaluationNodeConstant::FALSE, CEvaluationNode::FUNCTION, CEvaluationNodeLogical::GE, CNormalLogical::getAndSets(), CCopasiNode< _Data >::getChild(), CNormalLogical::getChoices(), CCopasiNode< _Data >::getSibling(), CEvaluationNode::getType(), CEvaluationNodeLogical::GT, CEvaluationNodeLogical::LE, CEvaluationNode::LOGICAL, CEvaluationNodeLogical::LT, CEvaluationNodeLogical::NE, CNormalLogical::negate(), CEvaluationNodeFunction::NOT, CEvaluationNodeLogical::OR, pResult, CNormalLogical::simplify(), CEvaluationNode::subType(), CEvaluationNodeConstant::TRUE, CEvaluationNode::type(), and CEvaluationNodeLogical::XOR.

Referenced by createChoice(), createItemPowerItem(), createLogical(), and createLogicalChoice().

2346 {
2347  CNormalLogical* pResult = NULL;
2348 
2349  if (pNode != NULL)
2350  {
2351  CEvaluationNode::Type type = pNode->getType();
2352 
2354  {
2356  {
2357  CNormalLogicalItem* pLogicalItem = createLogicalItem(pNode);
2358 
2359  if (pLogicalItem != NULL)
2360  {
2361  pResult = new CNormalLogical();
2363  tmp.insert(std::make_pair(pLogicalItem, false));
2364  pResult->getAndSets().insert(std::make_pair(tmp, false));
2365  }
2366  }
2367  }
2369  {
2370  CNormalLogicalItem* pLogicalItem = NULL;
2371  CEvaluationNode* pOrNode = NULL;
2372  CEvaluationNode* pAndNode = NULL;
2373  const CEvaluationNode* pA = NULL;
2374  const CEvaluationNode* pB = NULL;
2375  CEvaluationNode* pNotNode = NULL;
2376  CNormalLogical* pLeftLogical = NULL;
2377  CNormalLogical::ChoiceSetOfSets::const_iterator it, endit;
2378  CNormalLogical::ItemSetOfSets::const_iterator it2, endit2;
2379 
2381  {
2388  pLogicalItem = createLogicalItem(pNode);
2389 
2390  if (pLogicalItem != NULL)
2391  {
2392  pResult = new CNormalLogical();
2394  tmp.insert(std::make_pair(pLogicalItem, false));
2395  pResult->getAndSets().insert(std::make_pair(tmp, false));
2396  }
2397 
2398  break;
2400  // replace A xor B by A OR B AND NOT(A AND B)
2401  pA = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
2402  pB = dynamic_cast<const CEvaluationNode*>(pA->getSibling());
2403  pAndNode = new CEvaluationNodeLogical(CEvaluationNodeLogical::AND, "AND");
2404  pAndNode->addChild(pA->copyBranch());
2405  pAndNode->addChild(pB->copyBranch());
2407  pNotNode->addChild(pAndNode);
2409  pOrNode->addChild(pA->copyBranch());
2410  pOrNode->addChild(pB->copyBranch());
2411  pAndNode = new CEvaluationNodeLogical(CEvaluationNodeLogical::AND, "AND");
2412  pAndNode->addChild(pOrNode);
2413  pAndNode->addChild(pNotNode);
2414  pResult = createLogical(pAndNode);
2415  delete pAndNode;
2416  break;
2418  pLeftLogical = createLogical(dynamic_cast<const CEvaluationNode*>(pNode->getChild()));
2419 
2420  if (pLeftLogical != NULL)
2421  {
2422  pLeftLogical->simplify();
2423  CNormalLogical* pRightLogical = createLogical(dynamic_cast<const CEvaluationNode*>(pNode->getChild()->getSibling()));
2424 
2425  if (pRightLogical != NULL)
2426  {
2427  pRightLogical->simplify();
2428  // integrate the items into a new logical item
2429  // we have to create an AND set for every
2430  // combination between two AND Sets from the
2431  // two logicals
2432  pResult = new CNormalLogical();
2433  CNormalLogical::ChoiceSetOfSets::const_iterator it = pLeftLogical->getChoices().begin(), endit = pLeftLogical->getChoices().end();
2434 
2435  while (it != endit)
2436  {
2437  CNormalLogical::ChoiceSetOfSets::const_iterator it2 = pRightLogical->getChoices().begin(), endit2 = pRightLogical->getChoices().end();
2438 
2439  if ((*it).second == true) throw std::exception();
2440 
2441  while (it2 != endit2)
2442  {
2443  // create an AND set from the two, but only
2444  // if both don't have the NOT flag set
2445  // which should always be the case since we
2446  // called simplify on the items.
2447  if ((*it2).second == true) throw std::exception();
2448 
2450  CNormalLogical::ChoiceSet::const_iterator innerit = (*it).first.begin(), innerendit = (*it).first.end();
2451 
2452  while (innerit != innerendit)
2453  {
2454  tmp.insert(std::make_pair(new CNormalChoiceLogical(*(*innerit).first), (*innerit).second));
2455  ++innerit;
2456  }
2457 
2458  innerit = (*it2).first.begin(), innerendit = (*it2).first.end();
2459 
2460  while (innerit != innerendit)
2461  {
2462  tmp.insert(std::make_pair(new CNormalChoiceLogical(*(*innerit).first), (*innerit).second));
2463  ++innerit;
2464  }
2465 
2466  pResult->getChoices().insert(std::make_pair(tmp, false));
2467  ++it2;
2468  }
2469 
2470  ++it;
2471  }
2472 
2473  CNormalLogical::ItemSetOfSets::const_iterator it2 = pLeftLogical->getAndSets().begin(), endit2 = pLeftLogical->getAndSets().end();
2474 
2475  while (it2 != endit2)
2476  {
2477  CNormalLogical::ItemSetOfSets::const_iterator it3 = pRightLogical->getAndSets().begin(), endit3 = pRightLogical->getAndSets().end();
2478 
2479  if ((*it2).second == true) throw std::exception();
2480 
2481  while (it3 != endit3)
2482  {
2483  // create an AND set from the two, but only
2484  // if both don't have the NOT flag set
2485  // which should always be the case since we
2486  // called simplify on the items.
2487  if ((*it3).second == true) throw std::exception();
2488 
2490  CNormalLogical::ItemSet::const_iterator innerit = (*it2).first.begin(), innerendit = (*it2).first.end();
2491 
2492  while (innerit != innerendit)
2493  {
2494  tmp.insert(std::make_pair(new CNormalLogicalItem(*(*innerit).first), (*innerit).second));
2495  ++innerit;
2496  }
2497 
2498  innerit = (*it3).first.begin(), innerendit = (*it3).first.end();
2499 
2500  while (innerit != innerendit)
2501  {
2502  tmp.insert(std::make_pair(new CNormalLogicalItem(*(*innerit).first), (*innerit).second));
2503  ++innerit;
2504  }
2505 
2506  pResult->getAndSets().insert(std::make_pair(tmp, false));
2507  ++it3;
2508  }
2509 
2510  ++it2;
2511  }
2512 
2513  delete pLeftLogical;
2514  delete pRightLogical;
2515  }
2516  else
2517  {
2518  delete pLeftLogical;
2519  }
2520  }
2521 
2522  break;
2524  // 1. create two logicals, one for the left side and one for the
2525  // right side
2526  pResult = createLogical(dynamic_cast<const CEvaluationNode*>(pNode->getChild()));
2527  pLeftLogical = createLogical(dynamic_cast<const CEvaluationNode*>(pNode->getChild()->getSibling()));
2528  // 2. add all or items from the second logical to the first and
2529  // delete the second
2530  it = pLeftLogical->getChoices().begin(), endit = pLeftLogical->getChoices().end();
2531 
2532  while (it != endit)
2533  {
2535  CNormalLogical::copySet((*it).first, tmpSet);
2536  pResult->getChoices().insert(std::make_pair(tmpSet, (*it).second));
2537  ++it;
2538  }
2539 
2540  it2 = pLeftLogical->getAndSets().begin(), endit2 = pLeftLogical->getAndSets().end();
2541 
2542  while (it2 != endit2)
2543  {
2544  CNormalLogical::ItemSet tmpSet;
2545  CNormalLogical::copySet((*it2).first, tmpSet);
2546  pResult->getAndSets().insert(std::make_pair(tmpSet, (*it2).second));
2547  ++it2;
2548  }
2549 
2550  delete pLeftLogical;
2551  break;
2552  default:
2553  break;
2554  }
2555  }
2557  {
2558  pResult = createLogical(dynamic_cast<const CEvaluationNode*>(pNode->getChild()));
2559 
2560  if (pResult != NULL)
2561  {
2562  pResult->negate();
2563  }
2564  }
2566  {
2567  CNormalChoiceLogical* pLogicalChoice = createLogicalChoice(pNode);
2568 
2569  if (pLogicalChoice != NULL)
2570  {
2572  tmp.insert(std::make_pair(pLogicalChoice, false));
2573  pResult = new CNormalLogical();
2574  pResult->getChoices().insert(std::make_pair(tmp, false));
2575  }
2576  }
2577  }
2578 
2579  return pResult;
2580 }
CNormalLogicalItem * createLogicalItem(const CEvaluationNode *pNode)
CNormalLogical * createLogical(const CEvaluationNode *pNode)
CEvaluationNode * copyBranch() const
ChoiceSetOfSets & getChoices()
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
CNormalChoiceLogical * createLogicalChoice(const CEvaluationNode *pNode)
const Type & getType() const
virtual bool simplify()
static Type type(const Type &type)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
const CArrayAnnotation * pResult
static Type subType(const Type &type)
static void copySet(const TemplateSet< TYPE > &source, TemplateSet< TYPE > &target)
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
ItemSetOfSets & getAndSets()
CNormalChoiceLogical* createLogicalChoice ( const CEvaluationNode pNode)

Definition at line 2295 of file ConvertToCEvaluationNode.cpp.

References CEvaluationNode::CHOICE, createLogical(), CCopasiNode< _Data >::getChild(), CEvaluationNode::getType(), pResult, CNormalChoiceLogical::setCondition(), CNormalChoiceLogical::setFalseExpression(), CNormalChoiceLogical::setTrueExpression(), and CEvaluationNode::type().

Referenced by createLogical().

2296 {
2297  CNormalChoiceLogical* pResult = NULL;
2298 
2299  if (pNode != NULL && CEvaluationNode::type(pNode->getType()) == CEvaluationNode::CHOICE)
2300  {
2301  CNormalLogical* pLogical = createLogical(dynamic_cast<const CEvaluationNode*>(pNode->getChild()));
2302 
2303  if (pLogical != NULL)
2304  {
2305  CNormalLogical* pTrueLogical = createLogical(dynamic_cast<const CEvaluationNode*>(pNode->getChild()->getSibling()));
2306 
2307  if (pTrueLogical != NULL)
2308  {
2309  // the false branch is optional
2310  const CEvaluationNode* pFalseBranch = dynamic_cast<const CEvaluationNode*>(pNode->getChild()->getSibling()->getSibling());
2311 
2312  if (pFalseBranch != NULL)
2313  {
2314  CNormalLogical* pFalseLogical = createLogical(pFalseBranch);
2315 
2316  if (pFalseLogical != NULL)
2317  {
2318  pResult = new CNormalChoiceLogical();
2319  pResult->setCondition(*pLogical);
2320  pResult->setTrueExpression(*pTrueLogical);
2321  pResult->setFalseExpression(*pFalseLogical);
2322  delete pFalseLogical;
2323  }
2324  }
2325  else
2326  {
2327  pResult = new CNormalChoiceLogical();
2328  pResult->setCondition(*pLogical);
2329  pResult->setTrueExpression(*pTrueLogical);
2330  CNormalLogical* pFalseLogical = new CNormalLogical();
2331  pResult->setFalseExpression(*pFalseLogical);
2332  delete pFalseLogical;
2333  }
2334 
2335  delete pTrueLogical;
2336  }
2337 
2338  delete pLogical;
2339  }
2340  }
2341 
2342  return pResult;
2343 }
CNormalLogical * createLogical(const CEvaluationNode *pNode)
const Type & getType() const
bool setTrueExpression(const CNormalLogical &branch)
static Type type(const Type &type)
bool setFalseExpression(const CNormalLogical &branch)
const CArrayAnnotation * pResult
bool setCondition(const CNormalLogical &cond)
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CNormalLogicalItem* createLogicalItem ( const CEvaluationNode pNode)

Definition at line 2582 of file ConvertToCEvaluationNode.cpp.

References CEvaluationNode::CONSTANT, createNormalRepresentation(), CNormalLogicalItem::EQ, CEvaluationNodeLogical::EQ, CNormalLogicalItem::FALSE, CEvaluationNodeConstant::FALSE, CNormalLogicalItem::GE, CEvaluationNodeLogical::GE, CCopasiNode< _Data >::getChild(), CEvaluationNode::getType(), CNormalLogicalItem::GT, CEvaluationNodeLogical::GT, CNormalLogicalItem::LE, CEvaluationNodeLogical::LE, CEvaluationNode::LOGICAL, CNormalLogicalItem::LT, CEvaluationNodeLogical::LT, CNormalLogicalItem::NE, CEvaluationNodeLogical::NE, pResult, CNormalLogicalItem::setLeft(), CNormalLogicalItem::setRight(), CNormalLogicalItem::setType(), CEvaluationNode::subType(), CNormalLogicalItem::TRUE, CEvaluationNodeConstant::TRUE, and CEvaluationNode::type().

Referenced by createLogical().

2583 {
2584  CNormalLogicalItem* pResult = NULL;
2585 
2586  if (pNode != NULL)
2587  {
2588  CEvaluationNode::Type type = pNode->getType();
2589 
2591  {
2593  {
2594  pResult = new CNormalLogicalItem();
2596  }
2598  {
2599  pResult = new CNormalLogicalItem();
2601  }
2602  }
2603 
2605  {
2606  CNormalFraction* pFrac1 = NULL;
2607  CNormalFraction* pFrac2 = NULL;
2608 
2610  {
2612  pResult = new CNormalLogicalItem();
2613  pResult->setType(CNormalLogicalItem::EQ);
2614  pFrac1 = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(pNode->getChild()));
2615 
2616  if (pFrac1 != NULL)
2617  {
2618  pFrac2 = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(pNode->getChild()->getSibling()));
2619 
2620  if (pFrac2 != NULL)
2621  {
2622  pResult->setLeft(*pFrac1);
2623  pResult->setRight(*pFrac2);
2624  delete pFrac1;
2625  delete pFrac2;
2626  }
2627  else
2628  {
2629  delete pFrac1;
2630  pFrac1 = NULL;
2631  }
2632  }
2633 
2634  break;
2636  pResult = new CNormalLogicalItem();
2637  pResult->setType(CNormalLogicalItem::NE);
2638  pFrac1 = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(pNode->getChild()));
2639 
2640  if (pFrac1 != NULL)
2641  {
2642  pFrac2 = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(pNode->getChild()->getSibling()));
2643 
2644  if (pFrac2 != NULL)
2645  {
2646  pResult->setLeft(*pFrac1);
2647  pResult->setRight(*pFrac2);
2648  delete pFrac1;
2649  delete pFrac2;
2650  }
2651  else
2652  {
2653  delete pFrac1;
2654  pFrac1 = NULL;
2655  }
2656  }
2657 
2658  break;
2660  pResult = new CNormalLogicalItem();
2661  pResult->setType(CNormalLogicalItem::GT);
2662  pFrac1 = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(pNode->getChild()));
2663 
2664  if (pFrac1 != NULL)
2665  {
2666  pFrac2 = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(pNode->getChild()->getSibling()));
2667 
2668  if (pFrac2 != NULL)
2669  {
2670  pResult->setLeft(*pFrac1);
2671  pResult->setRight(*pFrac2);
2672  delete pFrac1;
2673  delete pFrac2;
2674  }
2675  else
2676  {
2677  delete pFrac1;
2678  pFrac1 = NULL;
2679  }
2680  }
2681 
2682  break;
2684  pResult = new CNormalLogicalItem();
2685  pResult->setType(CNormalLogicalItem::LT);
2686  pFrac1 = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(pNode->getChild()));
2687 
2688  if (pFrac1 != NULL)
2689  {
2690  pFrac2 = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(pNode->getChild()->getSibling()));
2691 
2692  if (pFrac2 != NULL)
2693  {
2694  pResult->setLeft(*pFrac1);
2695  pResult->setRight(*pFrac2);
2696  delete pFrac1;
2697  delete pFrac2;
2698  }
2699  else
2700  {
2701  delete pFrac1;
2702  pFrac1 = NULL;
2703  }
2704  }
2705 
2706  break;
2708  pResult = new CNormalLogicalItem();
2709  pResult->setType(CNormalLogicalItem::GE);
2710  pFrac1 = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(pNode->getChild()));
2711 
2712  if (pFrac1 != NULL)
2713  {
2714  pFrac2 = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(pNode->getChild()->getSibling()));
2715 
2716  if (pFrac2 != NULL)
2717  {
2718  pResult->setLeft(*pFrac1);
2719  pResult->setRight(*pFrac2);
2720  delete pFrac1;
2721  delete pFrac2;
2722  }
2723  else
2724  {
2725  delete pFrac1;
2726  pFrac1 = NULL;
2727  }
2728  }
2729 
2730  break;
2732  pResult = new CNormalLogicalItem();
2733  pResult->setType(CNormalLogicalItem::LE);
2734  pFrac1 = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(pNode->getChild()));
2735 
2736  if (pFrac1 != NULL)
2737  {
2738  pFrac2 = createNormalRepresentation(dynamic_cast<const CEvaluationNode*>(pNode->getChild()->getSibling()));
2739 
2740  if (pFrac2 != NULL)
2741  {
2742  pResult->setLeft(*pFrac1);
2743  pResult->setRight(*pFrac2);
2744  delete pFrac1;
2745  delete pFrac2;
2746  }
2747  else
2748  {
2749  delete pFrac1;
2750  pFrac1 = NULL;
2751  }
2752  }
2753 
2754  break;
2755  default:
2756  break;
2757  }
2758  }
2759  }
2760 
2761  return pResult;
2762 }
bool setRight(const CNormalFraction &right)
const Type & getType() const
bool setLeft(const CNormalFraction &left)
static Type type(const Type &type)
const CArrayAnnotation * pResult
static Type subType(const Type &type)
CNormalFraction * createNormalRepresentation(const CEvaluationNode *node)
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CNormalFraction* createNormalRepresentation ( const CEvaluationNode node)

Create an item power from an evaluation node. Must be a CEvaluationNodeChoice.

Returns
CNormalChoice*, pointer to newly created choice node. CNormalChoice * createChoice(const CEvaluationNode* node); Create an item power from an evaluation node.
CNormalBase*, pointer to newly created normal base object power.

Create an item power from an evaluation node. Must be a CEvaluationNodeChoice.

Returns
CNormalChoice*, pointer to newly created choice node. CNormalChoice * createChoice(const CEvaluationNode* node) { there are two kinds of choice nodes, one where mpTrue and mpFalse are fractions and one where they are choice or logical if the child node directly is a logical or a comparison, we create the Logical, otherwise we create the fraction. CNormalChoice* pChoice=NULL; const CEvaluationNodeChoice* pChoiceNode=dynamic_cast<const CEvaluationNodeChoice*>(node); if(pChoiceNode!=NULL) { pChoice=new CNormalChoice(); const CEvaluationNode* pTmpNode=dynamic_cast<const CEvaluationNode*>(pChoiceNode->getChild()); if(pTmpNode!=NULL) { check if this subtree is a logical expression CNormalLogical* pLogic=createLogical(pTmpNode); if(pLogicc) { pChoice->setCondition(<em>pLogic); delete pLogic; pTmpNode=dynamic_cast<const CEvaluationNode>(pTmpNode->getSibling()); if(pTmpNode!=NULL) { if(isLogical(pTmpNode)) { pLogic=createLogical(pTmpNode); if(pLogic!=NULL) { pChoice->setTrueExpression(pLogic); delete pLogic; pTmpNode=dynamic_cast<const CEvaluationNode*>(pTmpNode->getSibling()); if(pTmpNode!=NULL && isLogical(pTmpNode)) { pLogical=createLogical(pTmpNode); if(pLogical!=NULL) { pChoice->setFalseExpression(<em>pLogic); delete pLogic; } else { delete pChoice; pChoice=NULL; } } else { delete pChoice; pChoice=NULL; } } else { delete pChoice; pChoice=NULL; delete pLogic; } } else { CNormalFraction pFrac=createNormalRepresentation(pTmpNode); if(pFrac) { pChoice->setTrueExpression(<em>pFrac); delete pFrac; pTmpNode=dynamic_cast<const CEvaluationNode>(pTmpNode->getSibling()); if(pTmpNode!=NULL) { CNormalFraction* pFrac=createNormalRepresentation(pTmpNode); if(pFrac) { pChoice->setFalseExpression(*pFrac); delete pFrac; } else { delete pChoice; pChoice=NULL; } } else { delete pChoice; pChoice=NULL; } } else { delete pChoice; pChoice=NULL; } } } else { delete pChoice; pChoice=NULL; } } else { delete pChoice; pChoice=NULL; } } else { delete pChoice; pChoice=NULL; } } return pChoice; } Create an item power from an evaluation node.
CNormalBase*, pointer to newly created normal base object power.

Definition at line 1038 of file ConvertToCEvaluationNode.cpp.

References CEvaluationNode::CALL, CEvaluationNode::CHOICE, CEvaluationNode::CONSTANT, CEvaluationNode::copyBranch(), createFraction(), CEvaluationNode::DELAY, CNormalTranslation::expandProducts(), CEvaluationNode::FUNCTION, CEvaluationNode::getType(), CEvaluationNode::LOGICAL, CNormalTranslation::newEvaluateNumbers(), CEvaluationNode::NUMBER, CEvaluationNode::OPERATOR, CEvaluationNode::type(), and CEvaluationNode::VARIABLE.

Referenced by create_normalform(), createCall(), createChoice(), createFunction(), createGeneralPower(), createLogicalItem(), CNormalTranslation::elementaryEliminationDivide(), CNormalTranslation::elementaryEliminationMinus(), CNormalTranslation::elementaryEliminationModulus(), CNormalTranslation::matchPowerBases(), CNormalTranslation::matchSummands(), and CNormalTranslation::normAndSimplify().

1039 {
1040  CNormalFraction* pFrac = NULL;
1041  CEvaluationNode* pTmp2 = node->copyBranch();
1043 
1044  if (pTmp != NULL)
1045  {
1046  delete pTmp2;
1047  }
1048  else
1049  {
1050  pTmp = pTmp2;
1051  }
1052 
1054 
1055  if (pTmp2 != NULL)
1056  {
1057  delete pTmp;
1058  }
1059  else
1060  {
1061  pTmp2 = pTmp;
1062  }
1063 
1065 
1066  switch (type)
1067  {
1075  case CEvaluationNode::CALL:
1077  pFrac = createFraction(pTmp2);
1078  break;
1079  default:
1080  assert(false);
1081  break;
1082  }
1083 
1084  if (pTmp2 != NULL)
1085  {
1086  delete pTmp2;
1087  }
1088 
1089  return pFrac;
1090 }
CEvaluationNode * copyBranch() const
const Type & getType() const
static Type type(const Type &type)
CNormalFraction * createFraction(const CEvaluationNode *node)
static CEvaluationNode * newEvaluateNumbers(const CEvaluationNode *pOrig)
static CEvaluationNode * expandProducts(const CEvaluationNode *pOrig)
CNormalProduct* createProduct ( const CEvaluationNode node)

Create a product from an evaluation node that is not necessarily a multiply operator.

Returns
CNormalProduct*, pointer to newly created product.

Definition at line 585 of file ConvertToCEvaluationNode.cpp.

References CCopasiNode< _Data >::addChild(), CEvaluationNode::copyBranch(), CNormalTranslation::createChain(), createItemPower(), CEvaluationNodeOperator::DIVIDE, CEvaluationNode::getType(), CEvaluationNode::getValue(), CEvaluationNodeOperator::MULTIPLY, CNormalProduct::multiply(), CEvaluationNode::NUMBER, CNormalTranslation::ONE_NODE, CEvaluationNode::OPERATOR, CNormalProduct::setFactor(), CNormalTranslation::splitProduct(), CEvaluationNode::subType(), CNormalTranslation::TIMES_NODE, and CEvaluationNode::type().

Referenced by createSum().

586 {
587  CNormalProduct * pProduct = new CNormalProduct();
588 
590  {
591  // find the product chain, if there are divisions, we have to create a
592  // general power, else we create a product with as many items as the
593  // multiplication vector has entries
594  std::vector<const CEvaluationNode*> multiplications, divisions;
595  CNormalTranslation::splitProduct(node, multiplications, divisions, false);
596  double factor = 1.0;
597 
598  if (divisions.empty())
599  {
600  std::vector<const CEvaluationNode*>::const_iterator it = multiplications.begin(), endit = multiplications.end();
601  CNormalItemPower* pItemPower = NULL;
602 
603  while (it != endit)
604  {
605  // check if the node is a pure number
606  // if so, use it to update the factor
607  // instead of creating an item for it
608  if (CEvaluationNode::type((*it)->getType()) == CEvaluationNode::NUMBER)
609  {
610  factor *= dynamic_cast<const CEvaluationNodeNumber*>(*it)->getValue();
611  }
612  else
613  {
614  pItemPower = createItemPower(*it);
615  assert(pItemPower != NULL);
616  pProduct->multiply(*pItemPower);
617  delete pItemPower;
618  }
619 
620  ++it;
621  }
622  }
623  else
624  {
626  std::vector<CEvaluationNode*> tmp;
627  std::vector<const CEvaluationNode*>::const_iterator it = multiplications.begin(), endit = multiplications.end();
628  // check if the multiplications and divisions contain only numbers
629  // in that case, done create a general item
630  bool empty = false;
631 
632  while (it != endit)
633  {
634  // check if the node is a pure number
635  // if so, use it to update the factor
636  // instead of adding it to the factor
637  if (CEvaluationNode::type((*it)->getType()) == CEvaluationNode::NUMBER)
638  {
639  factor *= dynamic_cast<const CEvaluationNodeNumber*>(*it)->getValue();
640  }
641  else
642  {
643  tmp.push_back((*it)->copyBranch());
644  }
645 
646  ++it;
647  }
648 
649  empty = tmp.empty();
650  CEvaluationNode* pTmpNode1 = NULL;
651 
652  // if we have non number nodes, we need to combine those again into a
653  // multiplication chain
654  // otherwise the numerator is 1
655  if (!empty)
656  {
658  }
659  else
660  {
662  }
663 
664  pTmpOperator->addChild(pTmpNode1);
665  tmp.clear();
666  it = divisions.begin();
667  endit = divisions.end();
668 
669  while (it != endit)
670  {
671  // check if the node is a pure number
672  // if so, use it to update the factor
673  // instead of adding it to the vector
674  if (CEvaluationNode::type((*it)->getType()) == CEvaluationNode::NUMBER)
675  {
676  factor /= dynamic_cast<const CEvaluationNodeNumber*>(*it)->getValue();
677  }
678  else
679  {
680  tmp.push_back((*it)->copyBranch());
681  }
682 
683  ++it;
684  }
685 
686  // if tmp was empty both times, empty must be true
687  empty = (empty & tmp.empty());
688 
689  if (!empty)
690  {
691  CNormalItemPower* pItemPower = NULL;
692 
693  if (!tmp.empty())
694  {
696  pTmpOperator->addChild(pTmpNode1);
697  pItemPower = createItemPower(pTmpOperator);
698  }
699  else
700  {
701  pItemPower = createItemPower(pTmpNode1);
702  }
703 
704  assert(pItemPower != NULL);
705  pProduct->multiply(*pItemPower);
706  delete pItemPower;
707  }
708 
709  delete pTmpOperator;
710  }
711 
712  pProduct->setFactor(factor);
713  }
715  {
716  double factor = dynamic_cast<const CEvaluationNodeNumber*>(node)->getValue();
717  // set the factor
718  pProduct->setFactor(factor);
719  }
720  else
721  {
722  // we create the appropriate item
723  CNormalItemPower* pItemPower = createItemPower(node);
724  assert(pItemPower != NULL);
725  pProduct->multiply(*pItemPower);
726  delete pItemPower;
727  }
728 
729  return pProduct;
730 }
CEvaluationNode * copyBranch() const
const C_FLOAT64 & getValue() const
const Type & getType() const
static Type type(const Type &type)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
static const CEvaluationNode ONE_NODE
CNormalItemPower * createItemPower(const CEvaluationNode *node)
bool setFactor(const C_FLOAT64 &number)
static void splitProduct(const CEvaluationNode *pRoot, std::vector< const CEvaluationNode * > &multiplications, std::vector< const CEvaluationNode * > &divisions, bool division)
static Type subType(const Type &type)
static const CEvaluationNode TIMES_NODE
static CEvaluationNode * createChain(const CEvaluationNode *pLink, const CEvaluationNode *pNeutralElement, const std::vector< const CEvaluationNode * > &elements)
bool multiply(const C_FLOAT64 &number)
CNormalSum* createSum ( const CEvaluationNode node)

Create a sum from an evaluation node -node does not need to be a PLUS operator!

Returns
CNormalSum*, pointer to newly created sum

THIS CODE should be obsolete, RG (06/04/6.2008) Create a product from an evaluation node that is not necessarily a multiply operator.

Returns
CNormalProduct*, pointer to newly created product. Create a sum from an evaluation node -node does not need to be a PLUS operator!
CNormalSum*, pointer to newly created sum

Definition at line 842 of file ConvertToCEvaluationNode.cpp.

References CNormalSum::add(), createProduct(), CNormalProduct::getFactor(), CEvaluationNode::getType(), CEvaluationNodeOperator::MINUS, CEvaluationNode::OPERATOR, CEvaluationNodeOperator::PLUS, CNormalProduct::setFactor(), CNormalTranslation::splitSum(), CEvaluationNode::subType(), and CEvaluationNode::type().

Referenced by createFraction().

843 {
844  CNormalSum* pSum = new CNormalSum();
845 
847  {
848  // find a summation chain and create a product node for each addition and
849  // subtraction node
850  std::vector<const CEvaluationNode*> additions, subtractions;
851  CNormalTranslation::splitSum(node, additions, subtractions, false);
852  std::vector<const CEvaluationNode*>::iterator it = additions.begin(), endit = additions.end();
853  CNormalProduct* pProduct = NULL;
854 
855  while (it != endit)
856  {
857  pProduct = createProduct(*it);
858  assert(pProduct != NULL);
859  pSum->add(*pProduct);
860  delete pProduct;
861  ++it;
862  }
863 
864  it = subtractions.begin(), endit = subtractions.end();
865 
866  while (it != endit)
867  {
868  pProduct = createProduct(*it);
869  assert(pProduct != NULL);
870  // since these are subtractions, we need to set the factor the -1.0
871  // times the old factor
872  pProduct->setFactor(-1.0 * pProduct->getFactor());
873  pSum->add(*pProduct);
874  delete pProduct;
875  ++it;
876  }
877  }
878  else
879  {
880  // create a sum and add the product made from the given node
881  CNormalProduct* pProduct = createProduct(node);
882  assert(pProduct != NULL);
883  pSum->add(*pProduct);
884  delete pProduct;
885  /* This code should be obsolete, RG (4.6.2008)
886  if (node->getData() == "/")
887  {
888  CNormalFraction* fraction = createFraction(node);
889  sum->add(*fraction);
890  delete fraction;
891  return sum;
892  }
893  else
894  {
895  CNormalProduct* product = createProduct(node);
896  if (product != NULL)
897  {
898  sum->add(*product);
899  delete product;
900  }
901  else
902  {
903  CNormalFraction* pFraction = createFraction(node);
904  sum->add(*pFraction);
905  delete pFraction;
906  }
907  return sum;
908  }
909  */
910  }
911 
912  return pSum;
913 }
static void splitSum(const CEvaluationNode *pRoot, std::vector< CEvaluationNode * > &additions, std::vector< CEvaluationNode * > &substractions, bool minus)
const Type & getType() const
bool add(const CNormalProduct &product)
Definition: CNormalSum.cpp:156
static Type type(const Type &type)
bool setFactor(const C_FLOAT64 &number)
const C_FLOAT64 & getFactor() const
static Type subType(const Type &type)
CNormalProduct * createProduct(const CEvaluationNode *node)
bool isLogical ( const CEvaluationNode pNode)

Create an logical node from an evaluation node. Must be a CEvaluationNodeLogical or the not function.

Returns
CNormalLogical*, pointer to newly created logical node. CNormalLogical* createLogical(const CEvaluationNode* node);

Definition at line 1633 of file ConvertToCEvaluationNode.cpp.

References CEvaluationNode::CONSTANT, CEvaluationNodeConstant::FALSE, CEvaluationNode::FUNCTION, CCopasiNode< _Data >::getChild(), CCopasiNode< _Data >::getSibling(), CEvaluationNode::getType(), isLogical(), CEvaluationNode::LOGICAL, CEvaluationNodeFunction::NOT, CEvaluationNode::subType(), CEvaluationNodeConstant::TRUE, and CEvaluationNode::type().

Referenced by isLogical().

1634 {
1635  bool result = false;
1636 
1637  // go through the tree until one of the following is encountered:
1638  // CEvaluationNodeLogical, CEvaluationNodeFunction::NOT or
1639  // CEvaluationNodeConstant::(TRUE|FALSE)
1642  (CEvaluationNode::type(pNode->getType()) == CEvaluationNode::CONSTANT && ((((CEvaluationNodeConstant::SubType)CEvaluationNode::subType(pNode->getType())) == CEvaluationNodeConstant::TRUE) || (((CEvaluationNodeConstant::SubType)CEvaluationNode::subType(pNode->getType())) == CEvaluationNodeConstant::FALSE)))
1643  )
1644 
1645  {
1646  result = true;
1647  }
1648 
1649  const CEvaluationNode* pChild = dynamic_cast<const CEvaluationNode*>(pNode->getChild());
1650 
1651  while (result == false && pChild != NULL)
1652  {
1653  result = isLogical(pChild);
1654  pChild = dynamic_cast<const CEvaluationNode*>(pChild->getSibling());
1655  }
1656 
1657  return result;
1658 }
#define TRUE
Definition: CGA.h:25
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
const Type & getType() const
#define FALSE
Definition: CGA.h:26
static Type type(const Type &type)
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
bool isLogical(const CEvaluationNode *pNode)

Variable Documentation

std::map<std::string, const CEvaluationNode*> str2eval

Definition at line 64 of file ConvertToCEvaluationNode.cpp.