23 #include "sbml/math/ASTNode.h"
26 CRandom * CEvaluationNodeFunction::mpRandom = NULL;
276 mpFunction(src.mpFunction),
277 mpFunction2(src.mpFunction2),
278 mpFunction4(src.mpFunction4),
291 if (
mpArg1 == NULL)
return false;
298 if (
mpArg2 == NULL)
return false;
306 if (
mpArg3 == NULL)
return false;
310 if (
mpArg4 == NULL)
return false;
318 if (const_cast<CEvaluationNodeFunction *>(
this)->
compile(NULL))
319 switch (
mType & 0x00FFFFFF)
330 return mData +
"(" + children[0] +
"," + children[1] +
")";
333 return mData +
"(" + children[0] +
")";
339 return mData +
"(" + children[0] +
")";
348 if (const_cast<CEvaluationNodeFunction *>(
this)->
compile(NULL))
349 switch (
mType & 0x00FFFFFF)
360 return mData +
"(" + children[0] +
"," + children[1] +
")";
363 return mData +
"(" + children[0] +
")";
369 return mData +
"(" + children[0] +
")";
378 if (const_cast<CEvaluationNodeFunction *>(
this)->
compile(NULL))
380 std::string data =
"";
524 data =
"user_provided_uniform";
528 data =
"user_provided_normal";
532 data =
"user_provided_normal";
536 data =
"user_provided_normal";
552 switch (
mType & 0x00FFFFFF)
555 return "(" + data + children[0] +
")";
568 return data +
"(" + children[0] +
"," + children[1] +
")";
571 return data +
"(" + children[0] +
")";
582 std::string data =
"";
584 if (const_cast<CEvaluationNodeFunction *>(
this)->
compile(NULL))
640 data =
"ILLEGAL FUNCTION";
644 switch (
mType & 0x00FFFFFF)
647 return "(" + data + children[0] +
")";
660 return data +
"(" + children[0] +
"," + children[1] +
")";
663 return data +
"(" + children[0] +
")";
674 std::string data =
"";
676 if (const_cast<CEvaluationNodeFunction *>(
this)->
compile(NULL))
739 switch (
mType & 0x00FFFFFF)
742 return "(" + data + children[0] +
")";
754 return data +
"(" + children[0] +
"," + children[1] +
")";
757 return data +
"(" + children[0] +
")";
769 assert(pASTNode->getNumChildren() == children.size());
771 size_t iMax = children.size();
773 int type = (int)pASTNode->getType();
775 std::string data =
"";
777 if (type == AST_FUNCTION_ROOT)
806 else if (type == AST_FUNCTION_LOG && iMax == 2)
827 case AST_FUNCTION_ABS:
832 case AST_FUNCTION_ARCCOS:
837 case AST_FUNCTION_ARCCOSH:
842 case AST_FUNCTION_ARCCOT:
847 case AST_FUNCTION_ARCCOTH:
852 case AST_FUNCTION_ARCCSC:
857 case AST_FUNCTION_ARCCSCH:
862 case AST_FUNCTION_ARCSEC:
867 case AST_FUNCTION_ARCSECH:
872 case AST_FUNCTION_ARCSIN:
877 case AST_FUNCTION_ARCSINH:
882 case AST_FUNCTION_ARCTAN:
887 case AST_FUNCTION_ARCTANH:
892 case AST_FUNCTION_CEILING:
897 case AST_FUNCTION_COS:
902 case AST_FUNCTION_COSH:
907 case AST_FUNCTION_COT:
912 case AST_FUNCTION_COTH:
917 case AST_FUNCTION_CSC:
922 case AST_FUNCTION_CSCH:
927 case AST_FUNCTION_EXP:
932 case AST_FUNCTION_FACTORIAL:
937 case AST_FUNCTION_FLOOR:
942 case AST_FUNCTION_LN:
947 case AST_FUNCTION_LOG:
952 case AST_FUNCTION_SEC:
957 case AST_FUNCTION_SECH:
962 case AST_FUNCTION_SIN:
967 case AST_FUNCTION_SINH:
972 case AST_FUNCTION_TAN:
977 case AST_FUNCTION_TANH:
982 case AST_LOGICAL_NOT:
996 if (!children.empty())
1018 ASTNode* node =
new ASTNode();
1019 bool needFirstArg =
true;
1027 node->setType(AST_FUNCTION_LN);
1033 node->setType(AST_FUNCTION_LOG);
1035 ASTNode* logBase =
new ASTNode();
1036 logBase->setType(AST_INTEGER);
1037 logBase->setValue(10);
1038 node->addChild(logBase);
1044 node->setType(AST_FUNCTION_EXP);
1048 node->setType(AST_FUNCTION_SIN);
1052 node->setType(AST_FUNCTION_COS);
1056 node->setType(AST_FUNCTION_TAN);
1060 node->setType(AST_FUNCTION_SEC);
1064 node->setType(AST_FUNCTION_CSC);
1068 node->setType(AST_FUNCTION_COT);
1072 node->setType(AST_FUNCTION_SINH);
1076 node->setType(AST_FUNCTION_COSH);
1080 node->setType(AST_FUNCTION_TANH);
1084 node->setType(AST_FUNCTION_SECH);
1088 node->setType(AST_FUNCTION_CSCH);
1092 node->setType(AST_FUNCTION_COTH);
1096 node->setType(AST_FUNCTION_ARCSIN);
1100 node->setType(AST_FUNCTION_ARCCOS);
1104 node->setType(AST_FUNCTION_ARCTAN);
1108 node->setType(AST_FUNCTION_ARCSEC);
1112 node->setType(AST_FUNCTION_ARCCSC);
1116 node->setType(AST_FUNCTION_ARCCOT);
1120 node->setType(AST_FUNCTION_ARCSINH);
1124 node->setType(AST_FUNCTION_ARCCOSH);
1128 node->setType(AST_FUNCTION_ARCTANH);
1132 node->setType(AST_FUNCTION_ARCSECH);
1136 node->setType(AST_FUNCTION_ARCCSCH);
1140 node->setType(AST_FUNCTION_ARCCOTH);
1144 node->setType(AST_FUNCTION_ROOT);
1148 node->setType(AST_FUNCTION_ABS);
1152 node->setType(AST_FUNCTION_CEILING);
1156 node->setType(AST_FUNCTION_FLOOR);
1160 node->setType(AST_FUNCTION_FACTORIAL);
1164 node->setType(AST_MINUS);
1175 node->setType(AST_LOGICAL_NOT);
1180 needFirstArg =
false;
1181 node->setType(AST_FUNCTION);
1182 node->setName(
"RUNIFORM");
1186 node->addChild(sibling->
toAST(pDataModel));
1192 needFirstArg =
false;
1193 node->setType(AST_FUNCTION);
1194 node->setName(
"RNORMAL");
1198 node->addChild(sibling->
toAST(pDataModel));
1204 needFirstArg =
false;
1205 node->setType(AST_FUNCTION);
1206 node->setName(
"RGAMMA");
1210 node->addChild(sibling->
toAST(pDataModel));
1216 needFirstArg =
false;
1217 node->setType(AST_FUNCTION);
1218 node->setName(
"RPOISSON");
1226 needFirstArg =
false;
1227 node->setType(AST_FUNCTION);
1228 node->setName(
"MAX");
1232 node->addChild(sibling->
toAST(pDataModel));
1238 needFirstArg =
false;
1239 node->setType(AST_FUNCTION);
1240 node->setName(
"MIN");
1244 node->addChild(sibling->
toAST(pDataModel));
1258 if (subType ==
SQRT)
1261 ASTNode* pDegreeNode =
new ASTNode();
1262 pDegreeNode->setType(AST_INTEGER);
1263 pDegreeNode->setValue(2);
1264 node->addChild(pDegreeNode);
1279 assert(children.size() > 0);
1282 switch (
mType & 0x00FFFFFF)
1300 newnode->
addChild(newchild1, NULL);
1301 newnode->
addChild(newchild2, newchild1);
1302 newchild1->
addChild(grandchild, NULL);
1316 newnode->
addChild(newchild1, NULL);
1317 newnode->
addChild(newchild2, newchild1);
1318 newchild1->
addChild(grandchild1, NULL);
1319 newchild2->
addChild(grandchild2, NULL);
1334 if (child1->getData() ==
"-")
1349 std::stringstream tmp;
1350 tmp << child1->getValue() *(-1.0);
1372 newnode->
addChild(newchild2, child1);
1392 Result =
mData +
"(" + str +
")";
1397 Result =
"(" +
mData + str +
")";
1401 Result =
mData + str;
1413 if ((T & 0xFF000000) ==
LOGICAL)
1415 Result +=
"(" + str +
")";
1433 const std::vector< std::vector< std::string > > & )
const
1435 std::ostringstream out;
1437 std::string data =
"";
1438 std::string ldata =
"";
1439 std::string rdata =
"";
1447 switch (
mType & 0x00FFFFFF)
1593 out <<
"<mrow>" << std::endl;
1595 switch (
mType & 0x00FFFFFF)
1603 if (flag) out <<
"<mfenced>" << std::endl;
1607 if (flag) out <<
"</mfenced>" << std::endl;
1617 flag1 = ((T & 0xFF000000) ==
OPERATOR &&
1618 this == static_cast<const CEvaluationNode *>(pParent->
getChild()->getSibling()));
1622 if (flag1) out <<
"<mfenced>" << std::endl;
1624 if (flag1) out <<
"<mrow>" << std::endl;
1627 out <<
"<mo>" <<
"-" <<
"</mo>" << std::endl;
1629 if (!flag) out <<
"<mfenced>" << std::endl;
1633 if (!flag) out <<
"</mfenced>" << std::endl;
1635 if (flag1) out <<
"</mrow>" << std::endl;
1637 if (flag1) out <<
"</mfenced>" << std::endl;
1643 if (!flag) out <<
"<mfenced>" << std::endl;
1647 if (!flag) out <<
"</mfenced>" << std::endl;
1649 out <<
"<mo>" <<
"!" <<
"</mo>" << std::endl;
1656 out << ldata << std::endl;
1660 out << rdata << std::endl;
1666 out <<
"<msup>" << std::endl;
1667 out <<
"<mo> e </mo>" << std::endl;
1671 out <<
"</msup>" << std::endl;
1677 out <<
"<msub>" << std::endl;
1678 out <<
"<mo>" <<
"log" <<
"</mo>" << std::endl;
1679 out <<
"<mn>" <<
"10" <<
"</mn>" << std::endl;
1681 out <<
"</msub>" << std::endl;
1684 out <<
"<mspace width=\"0.3em\"/>" << std::endl;
1686 out <<
"<mfenced>" << std::endl;
1690 if (!flag) out <<
"</mfenced>" << std::endl;
1696 out <<
"<mi> " << data <<
" </mi>" << std::endl;
1698 out <<
"<mfenced>" << std::endl;
1702 out <<
"</mfenced>" << std::endl;
1711 out <<
"<mrow>" << std::endl;
1713 out <<
"<mi>" <<
mData <<
"</mi>" << std::endl;
1714 out <<
"<mrow>" << std::endl;
1715 out <<
"<mo>(</mo>" << std::endl;
1716 out <<
"<mrow>" << std::endl;
1720 out <<
"<mo> , </mo>" << std::endl;
1724 out <<
"</mrow>" << std::endl;
1725 out <<
"<mo>) </mo>" << std::endl;
1727 out <<
"</mrow>" << std::endl;
1728 out <<
"</mrow>" << std::endl;
1732 out <<
"<mrow>" << std::endl;
1734 out <<
"<mi>" <<
mData <<
"</mi>" << std::endl;
1735 out <<
"<mrow>" << std::endl;
1736 out <<
"<mo>(</mo>" << std::endl;
1737 out <<
"<mrow>" << std::endl;
1741 out <<
"</mrow>" << std::endl;
1742 out <<
"<mo>) </mo>" << std::endl;
1744 out <<
"</mrow>" << std::endl;
1745 out <<
"</mrow>" << std::endl;
1750 out <<
"<mi> " << data <<
" </mi>" << std::endl;
1753 out <<
"<mspace width=\"0.3em\"/>" << std::endl;
1755 out <<
"<mfenced>" << std::endl;
1759 if (!flag) out <<
"</mfenced>" << std::endl;
1764 out <<
"</mrow>" << std::endl;
static C_FLOAT64 factorial(C_FLOAT64 value)
virtual ASTNode * toAST(const CCopasiDataModel *pDataModel) const
CEvaluationNode * copyBranch() const
virtual bool isBoolean() const
static C_FLOAT64 sech(C_FLOAT64 value)
static C_FLOAT64 min(const C_FLOAT64 &x1, const C_FLOAT64 &x2)
static C_FLOAT64 coth(C_FLOAT64 value)
CCopasiNode< Data > * getSibling()
std::string handleNot(const std::string &str) const
static C_FLOAT64 acsch(C_FLOAT64 value)
static C_FLOAT64 arccot(C_FLOAT64 value)
static C_FLOAT64 plus(C_FLOAT64 value)
virtual C_FLOAT64 getRandomNormal(const C_FLOAT64 &mean, const C_FLOAT64 &sd)
CEvaluationNode * copyNode(CEvaluationNode *child1, CEvaluationNode *child2) const
static CRandom * mpRandom
virtual C_FLOAT64 getRandomOO()
static C_FLOAT64 arcsec(C_FLOAT64 value)
virtual ~CEvaluationNodeFunction()
static C_FLOAT64 rnormal(const C_FLOAT64 &mean, const C_FLOAT64 &sd)
const Type & getType() const
static CEvaluationNode * create(const Type &type, const Data &data)
virtual bool compile(const CEvaluationTree *pTree)
virtual std::string getBerkeleyMadonnaString(const std::vector< std::string > &children) const
static CEvaluationNode * fromAST(const ASTNode *pASTNode, const std::vector< CEvaluationNode * > &children)
C_FLOAT64(* mpFunction2)(const C_FLOAT64 &arg1, const C_FLOAT64 &arg2)
static C_FLOAT64 csch(C_FLOAT64 value)
virtual std::string getDisplayString(const std::vector< std::string > &children) const
CEvaluationNodeFunction()
static Type type(const Type &type)
static C_FLOAT64 copasiNot(C_FLOAT64 value)
virtual std::string getCCodeString(const std::vector< std::string > &children) const
#define PRECEDENCE_FUNCTION
static CRandom * createGenerator(CRandom::Type type=CRandom::mt19937, unsigned C_INT32 seed=0)
virtual C_FLOAT64 getRandomPoisson(const C_FLOAT64 &mean)
virtual std::string getXPPString(const std::vector< std::string > &children) const
static C_FLOAT64 asech(C_FLOAT64 value)
C_FLOAT64(* mpFunction)(C_FLOAT64 arg1)
static C_FLOAT64 sec(C_FLOAT64 value)
virtual CEvaluationNode * simplifyNode(const std::vector< CEvaluationNode * > &children) const
static C_FLOAT64 runiform(const C_FLOAT64 &lowerBound, const C_FLOAT64 &upperBound)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
static C_FLOAT64 csc(C_FLOAT64 value)
static C_FLOAT64 rgamma(const C_FLOAT64 &shape, const C_FLOAT64 &scale)
static C_FLOAT64 rpoisson(const C_FLOAT64 mu)
static C_FLOAT64 arccsc(C_FLOAT64 value)
virtual ASTNode * toAST(const CCopasiDataModel *pDataModel) const
static Type subType(const Type &type)
static C_FLOAT64 max(const C_FLOAT64 &x1, const C_FLOAT64 &x2)
class CEvaluationNode::CPrecedence mPrecedence
CCopasiNode< Data > * getParent()
static C_FLOAT64 cot(C_FLOAT64 value)
static C_FLOAT64 acoth(C_FLOAT64 value)
virtual C_FLOAT64 getRandomGamma(C_FLOAT64 shape, C_FLOAT64 scale)
#define PRECEDENCE_NUMBER
virtual std::string getInfix(const std::vector< std::string > &children) const
virtual std::string getMMLString(const std::vector< std::string > &children, bool expand, const std::vector< std::vector< std::string > > &variables) const
static C_FLOAT64 minus(C_FLOAT64 value)
CCopasiNode< Data > * getChild()
CEvaluationNode * getLeft()
std::string handleSign(const std::string &str) const