24 # pragma warning (disable: 4786)
25 # pragma warning (disable: 4243)
27 # pragma warning (disable: 4355)
64 std::map<std::string, const CEvaluationNode*>
str2eval;
101 else if (item.
getName() ==
"EXPONENTIALE" || item.
getName() ==
"exponentiale")
113 else if (item.
getName() ==
"INFINITY" || item.
getName() ==
"infinity")
138 if (fabs(itemPower.
getExp() - 1.0) < 1e-12)
144 std::ostringstream sstream;
148 sstream << itemPower.
getExp();
150 pResult = pPowerNode;
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();
168 assert(pMult != NULL);
177 const std::vector<CNormalSum*>& sums = lcm.
getSums();
179 std::vector<CNormalSum*>::const_iterator it2 = sums.begin();
181 std::vector<CNormalSum*>::const_iterator itEnd2 = sums.end();
183 while (it2 != itEnd2)
185 assert(pMult != NULL);
202 assert(pParent != NULL);
206 assert(pMult != NULL);
208 pMult->
addChild(dynamic_cast<CEvaluationNode*>(pParent->
getChild())->copyBranch());
218 std::ostringstream sstream;
222 sstream.precision(18);
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();
232 std::vector<CEvaluationNode*> products;
237 products.push_back(pChild);
241 if (fabs(product.
getFactor() - 1.0) >= 1e-12)
243 sstream.precision(18);
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;
265 summands.push_back(pChild);
269 const std::set<CNormalProduct*, compareProducts >& products = sum.
getProducts();
271 std::set<CNormalProduct*, compareProducts >::const_iterator it2 = products.begin();
273 std::set<CNormalProduct*, compareProducts >::const_iterator itEnd2 = products.end();
275 while (it2 != itEnd2)
278 summands.push_back(pChild);
284 if (!summands.empty())
293 std::vector<const CEvaluationNode*>::iterator vIt = summands.begin(), vEndit = summands.end();
295 while (vIt != vEndit)
316 std::vector<const CEvaluationNode*> multiplications, divisions;
318 std::vector<CEvaluationNode*> tmp;
319 std::vector<const CEvaluationNode*>::const_iterator it = multiplications.begin(), endit = multiplications.end();
323 tmp.push_back((*it)->copyBranch());
328 assert(pTmpNode != NULL);
330 assert(pNum != NULL);
333 it = divisions.begin();
334 endit = divisions.end();
338 tmp.push_back((*it)->copyBranch());
343 assert(pTmpNode != NULL);
345 assert(pDenom != NULL);
358 pDenom->
add(*pProduct);
454 throw std::exception();
478 pItemPower->
setExp((
C_FLOAT64)dynamic_cast<const CEvaluationNodeNumber*>(node->
getChild()->getSibling())->getValue());
486 assert(pItem != NULL);
494 assert(pGeneralPower != NULL);
495 pItemPower->
setItem(*pGeneralPower);
496 delete pGeneralPower;
503 assert(pGeneralPower != NULL);
504 pItemPower->
setItem(*pGeneralPower);
506 delete pGeneralPower;
517 pOperatorNode->
addChild(pNumberNode);
518 pOperatorNode->
addChild(dynamic_cast<const CEvaluationNode*>(node->
getChild())->copyBranch());
525 delete pOperatorNode;
530 assert(pFunction != NULL);
531 pItemPower->
setItem(*pFunction);
539 assert(pCall != NULL);
547 assert(pChoice != NULL);
555 assert(pItem != NULL);
563 assert(pItem != NULL);
572 assert(pGeneralPower != NULL);
573 pItemPower->
setItem(*pGeneralPower);
575 delete pGeneralPower;
594 std::vector<const CEvaluationNode*> multiplications, divisions;
598 if (divisions.empty())
600 std::vector<const CEvaluationNode*>::const_iterator it = multiplications.begin(), endit = multiplications.end();
615 assert(pItemPower != NULL);
626 std::vector<CEvaluationNode*> tmp;
627 std::vector<const CEvaluationNode*>::const_iterator it = multiplications.begin(), endit = multiplications.end();
643 tmp.push_back((*it)->copyBranch());
666 it = divisions.begin();
667 endit = divisions.end();
680 tmp.push_back((*it)->copyBranch());
687 empty = (empty & tmp.empty());
704 assert(pItemPower != NULL);
724 assert(pItemPower != NULL);
850 std::vector<const CEvaluationNode*> additions, subtractions;
852 std::vector<const CEvaluationNode*>::iterator it = additions.begin(), endit = additions.end();
858 assert(pProduct != NULL);
859 pSum->
add(*pProduct);
864 it = subtractions.begin(), endit = subtractions.end();
869 assert(pProduct != NULL);
873 pSum->
add(*pProduct);
882 assert(pProduct != NULL);
883 pSum->
add(*pProduct);
1096 if (dynamic_cast<const CNormalItem*>(&base) != NULL)
1100 else if (dynamic_cast<const CNormalItemPower*>(&base) != NULL)
1104 else if (dynamic_cast<const CNormalGeneralPower*>(&base) != NULL)
1108 else if (dynamic_cast<const CNormalFunction*>(&base) != NULL)
1112 else if (dynamic_cast<const CNormalCall*>(&base) != NULL)
1116 else if (dynamic_cast<const CNormalFraction*>(&base) != NULL)
1120 else if (dynamic_cast<const CNormalProduct*>(&base) != NULL)
1124 else if (dynamic_cast<const CNormalSum*>(&base) != NULL)
1128 else if (dynamic_cast<const CNormalLogical*>(&base) != NULL)
1132 else if (dynamic_cast<const CNormalChoice*>(&base) != NULL)
1156 if (pResult != NULL)
1180 if (call.
getName().find_first_not_of(
"\t\r\n ") != std::string::npos)
1204 const std::vector<CNormalFraction*>& children = call.
getFractions();
1206 std::vector<CNormalFraction*>::const_iterator it = children.begin(), endit = children.end();
1211 assert(pChild != NULL);
1402 assert(pBase != NULL);
1403 assert(pExponent != NULL);
1418 assert(pBase != NULL);
1419 assert(pExponent != NULL);
1435 assert(pBase != NULL);
1436 assert(pExponent != NULL);
1464 while (pChild != NULL)
1467 assert(pFraction != NULL);
1468 pCall->
add(*pFraction);
1635 bool result =
false;
1651 while (result ==
false && pChild != NULL)
1727 if (pChild1 != NULL)
1731 if (pChild2 != NULL)
1735 if (pChild3 != NULL)
1755 if (pChild1 != NULL)
1759 if (pChild2 != NULL)
1763 if (pChild3 != NULL)
1816 if (pChild1 == NULL)
1818 delete pLogicalNode;
1819 pLogicalNode = NULL;
1825 if (pChild2 == NULL)
1827 delete pLogicalNode;
1828 pLogicalNode = NULL;
1839 return pLogicalNode;
1853 std::vector<CEvaluationNode*> andElements;
1854 std::vector<CEvaluationNode*> orElements;
1855 CNormalLogical::ChoiceSetOfSets::const_iterator cIt = logical.
getChoices().begin(), cEndit = logical.
getChoices().end();
1857 while (cIt != cEndit)
1859 CNormalLogical::ChoiceSet::const_iterator cInnerIt = (*cIt).first.begin(), cInnerEndit = (*cIt).first.end();
1861 while (cInnerIt != cInnerEndit)
1864 assert(pNode != NULL);
1866 if ((*cInnerIt).second ==
true)
1888 andElements.push_back(pNode);
1894 assert(pNode != NULL);
1895 andElements.clear();
1898 if ((*cIt).second ==
true)
1920 orElements.push_back(pNode);
1925 if (!orElements.empty())
1928 assert(pNode != NULL);
1935 CNormalLogical::ItemSetOfSets::const_iterator iIt = logical.
getAndSets().begin(), iEndit = logical.
getAndSets().end();
1937 while (iIt != iEndit)
1939 CNormalLogical::ItemSet::const_iterator iInnerIt = (*iIt).first.begin(), iInnerEndit = (*iIt).first.end();
1941 while (iInnerIt != iInnerEndit)
1944 assert(pNode != NULL);
1946 if ((*iInnerIt).second ==
true)
1969 andElements.push_back(pNode);
1975 assert(pNode != NULL);
1976 andElements.clear();
1979 if ((*iIt).second ==
true)
2002 orElements.push_back(pNode);
2007 if (!orElements.empty())
2010 assert(pNode != NULL);
2014 if (pResult == NULL)
2017 assert(pResult != NULL);
2045 assert(pResult != NULL);
2253 if (pLogical != NULL)
2257 if (pTrueFraction != NULL)
2262 if (pFalseBranch != NULL)
2266 if (pFalseFraction != NULL)
2272 delete pFalseFraction;
2282 delete pFalseFraction;
2285 delete pTrueFraction;
2303 if (pLogical != NULL)
2307 if (pTrueLogical != NULL)
2312 if (pFalseBranch != NULL)
2316 if (pFalseLogical != NULL)
2322 delete pFalseLogical;
2332 delete pFalseLogical;
2335 delete pTrueLogical;
2359 if (pLogicalItem != NULL)
2363 tmp.insert(std::make_pair(pLogicalItem,
false));
2364 pResult->
getAndSets().insert(std::make_pair(tmp,
false));
2377 CNormalLogical::ChoiceSetOfSets::const_iterator it, endit;
2378 CNormalLogical::ItemSetOfSets::const_iterator it2, endit2;
2390 if (pLogicalItem != NULL)
2394 tmp.insert(std::make_pair(pLogicalItem,
false));
2395 pResult->
getAndSets().insert(std::make_pair(tmp,
false));
2420 if (pLeftLogical != NULL)
2425 if (pRightLogical != NULL)
2433 CNormalLogical::ChoiceSetOfSets::const_iterator it = pLeftLogical->
getChoices().begin(), endit = pLeftLogical->
getChoices().end();
2437 CNormalLogical::ChoiceSetOfSets::const_iterator it2 = pRightLogical->
getChoices().begin(), endit2 = pRightLogical->
getChoices().end();
2439 if ((*it).second ==
true)
throw std::exception();
2441 while (it2 != endit2)
2447 if ((*it2).second ==
true)
throw std::exception();
2450 CNormalLogical::ChoiceSet::const_iterator innerit = (*it).first.begin(), innerendit = (*it).first.end();
2452 while (innerit != innerendit)
2458 innerit = (*it2).first.begin(), innerendit = (*it2).first.end();
2460 while (innerit != innerendit)
2466 pResult->
getChoices().insert(std::make_pair(tmp,
false));
2473 CNormalLogical::ItemSetOfSets::const_iterator it2 = pLeftLogical->
getAndSets().begin(), endit2 = pLeftLogical->
getAndSets().end();
2475 while (it2 != endit2)
2477 CNormalLogical::ItemSetOfSets::const_iterator it3 = pRightLogical->
getAndSets().begin(), endit3 = pRightLogical->
getAndSets().end();
2479 if ((*it2).second ==
true)
throw std::exception();
2481 while (it3 != endit3)
2487 if ((*it3).second ==
true)
throw std::exception();
2490 CNormalLogical::ItemSet::const_iterator innerit = (*it2).first.begin(), innerendit = (*it2).first.end();
2492 while (innerit != innerendit)
2494 tmp.insert(std::make_pair(
new CNormalLogicalItem(*(*innerit).first), (*innerit).second));
2498 innerit = (*it3).first.begin(), innerendit = (*it3).first.end();
2500 while (innerit != innerendit)
2502 tmp.insert(std::make_pair(
new CNormalLogicalItem(*(*innerit).first), (*innerit).second));
2506 pResult->
getAndSets().insert(std::make_pair(tmp,
false));
2513 delete pLeftLogical;
2514 delete pRightLogical;
2518 delete pLeftLogical;
2527 pLeftLogical =
createLogical(dynamic_cast<const CEvaluationNode*>(pNode->
getChild()->getSibling()));
2536 pResult->
getChoices().insert(std::make_pair(tmpSet, (*it).second));
2542 while (it2 != endit2)
2546 pResult->
getAndSets().insert(std::make_pair(tmpSet, (*it2).second));
2550 delete pLeftLogical;
2560 if (pResult != NULL)
2569 if (pLogicalChoice != NULL)
2572 tmp.insert(std::make_pair(pLogicalChoice,
false));
2574 pResult->
getChoices().insert(std::make_pair(tmp,
false));
static void splitSum(const CEvaluationNode *pRoot, std::vector< CEvaluationNode * > &additions, std::vector< CEvaluationNode * > &substractions, bool minus)
std::map< std::string, const CEvaluationNode * > str2eval
CNormalItem * createItem(const CEvaluationNode *pNode)
CNormalSum & getNumerator()
CNormalLogicalItem * createLogicalItem(const CEvaluationNode *pNode)
CNormalLogical * createLogical(const CEvaluationNode *pNode)
CEvaluationNode * copyBranch() const
static const CEvaluationNode NEUTRAL_ELEMENT_AND
ChoiceSetOfSets & getChoices()
CNormalSum * createSum(const CEvaluationNode *node)
CCopasiNode< Data > * getSibling()
CNormalChoiceLogical * createLogicalChoice(const CEvaluationNode *pNode)
const C_FLOAT64 & getValue() const
const CNormalFraction & getTrueExpression() const
bool setRight(const CNormalFraction &right)
CNormalFraction & getLeft()
bool setTrueExpression(const CNormalFraction &branch)
const Type & getType() const
const CNormalLogical & getCondition() const
void setFraction(const CNormalFraction &frac)
const std::string & getName() const
CNormalFraction & getLeft()
std::string buildInfix() const
const std::vector< CNormalSum * > & getSums() const
CEvaluationNode * convertToCEvaluationNode(const CNormalFraction &fraction)
const CNormalLogical & getFalseExpression() const
const CNormalLogical & getCondition() const
const std::vector< CNormalFraction * > & getFractions() const
bool setFalseExpression(const CNormalFraction &branch)
const CNormalLogical & getTrueExpression() const
bool setLeft(const CNormalFraction &left)
void setName(const std::string &name)
CNormalChoice * createChoice(const CEvaluationNode *pNode)
bool add(const CNormalProduct &product)
bool setTrueExpression(const CNormalLogical &branch)
const CNormalFraction & getFalseExpression() const
bool setItem(const CNormalBase &item)
static Type type(const Type &type)
const std::set< CNormalFraction * > & getFractions() const
const Type & getType() const
static const CEvaluationNode NEUTRAL_ELEMENT_OR
bool setFalseExpression(const CNormalLogical &branch)
CNormalBase * createItemPowerItem(const CEvaluationNode *pNode)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
static const CEvaluationNode ONE_NODE
CNormalSum & getDenominator()
bool setDenominator(const CNormalSum &denominator)
const std::set< CNormalItemPower *, compareItemPowers > & getItemPowers() const
bool setCondition(const CNormalLogical &cond)
CNormalFraction * createFraction(const CEvaluationNode *node)
static const char * NAMES[]
CNormalFraction & getRight()
static const CEvaluationNode ZERO_NODE
CNormalItemPower * createItemPower(const CEvaluationNode *node)
bool setFactor(const C_FLOAT64 &number)
const C_FLOAT64 & getExp() const
bool add(const CNormalFraction &fraction)
static void splitProduct(const CEvaluationNode *pRoot, std::vector< const CEvaluationNode * > &multiplications, std::vector< const CEvaluationNode * > &divisions, bool division)
const C_FLOAT64 & getFactor() const
void setRight(const CNormalFraction &right)
static CEvaluationNode * newEvaluateNumbers(const CEvaluationNode *pOrig)
static Type subType(const Type &type)
bool checkDenominatorOne() const
bool setNumerator(const CNormalSum &numerator)
CNormalFraction * createNormalRepresentation(const CEvaluationNode *node)
bool setCondition(const CNormalLogical &cond)
CCopasiNode< Data > * getParent()
static void copySet(const TemplateSet< TYPE > &source, TemplateSet< TYPE > &target)
virtual bool compile(const CEvaluationTree *pTree)
static CEvaluationNode * expandProducts(const CEvaluationNode *pOrig)
void setLeft(const CNormalFraction &left)
static const CEvaluationNode TIMES_NODE
virtual bool removeChild(CCopasiNode< Data > *pChild)
const std::string getName() const
virtual const Data & getData() const
static CEvaluationNode * createChain(const CEvaluationNode *pLink, const CEvaluationNode *pNeutralElement, const std::vector< const CEvaluationNode * > &elements)
bool multiply(const C_FLOAT64 &number)
static const CEvaluationNode PLUS_NODE
CCopasiNode< Data > * getChild()
CNormalGeneralPower * createGeneralPower(const CEvaluationNode *node)
CNormalFraction & getFraction()
const std::set< CNormalProduct *, compareProducts > & getProducts() const
const std::set< CNormalItemPower *, compareItemPowers > & getItemPowers() const
CNormalFunction * createFunction(const CEvaluationNode *node)
CNormalProduct * createProduct(const CEvaluationNode *node)
CNormalFraction & getRight()
ItemSetOfSets & getAndSets()
bool setExp(const C_FLOAT64 &number)
bool isLogical(const CEvaluationNode *pNode)
CNormalCall * createCall(const CEvaluationNode *node)