COPASI API  4.16.103
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CMathTrigger Class Reference

#include <CMathTrigger.h>

Inheritance diagram for CMathTrigger:
Inheritance graph
[legend]
Collaboration diagram for CMathTrigger:
Collaboration graph
[legend]

Classes

class  CRootFinder
 

Public Member Functions

void applyInitialValues ()
 
bool calculate ()
 
void calculateInitialActivity ()
 
void calculateTrueValue ()
 
 CMathTrigger (const CCopasiContainer *pParent=NULL)
 
 CMathTrigger (const CMathTrigger &src, const CCopasiContainer *pParent=NULL)
 
bool compile (const CExpression *pTriggerExpression, std::vector< CCopasiContainer * > listOfContainer)
 
CCopasiVector< CRootFinder > & getRootFinders ()
 
virtual ~CMathTrigger ()
 
- Public Member Functions inherited from CCopasiContainer
virtual bool add (CCopasiObject *pObject, const bool &adopt=true)
 
 CCopasiContainer (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &type="CN", const unsigned C_INT32 &flag=CCopasiObject::Container)
 
 CCopasiContainer (const CCopasiContainer &src, const CCopasiContainer *pParent=NULL)
 
virtual std::string getChildObjectUnits (const CCopasiObject *pObject) const
 
virtual const CObjectInterfacegetObject (const CCopasiObjectName &cn) const
 
virtual const objectMapgetObjects () const
 
virtual std::string getUnits () const
 
virtual const CCopasiObjectgetValueObject () const
 
virtual bool remove (CCopasiObject *pObject)
 
virtual ~CCopasiContainer ()
 
- Public Member Functions inherited from CCopasiObject
void addDirectDependency (const CCopasiObject *pObject)
 
 CCopasiObject (const CCopasiObject &src, const CCopasiContainer *pParent=NULL)
 
void clearDirectDependencies ()
 
void clearRefresh ()
 
bool dependsOn (DataObjectSet candidates, const DataObjectSet &context=DataObjectSet()) const
 
void getAllDependencies (DataObjectSet &dependencies, const DataObjectSet &context) const
 
virtual CCopasiObjectName getCN () const
 
virtual const DataObjectSetgetDirectDependencies (const DataObjectSet &context=DataObjectSet()) const
 
virtual const std::string & getKey () const
 
CCopasiContainergetObjectAncestor (const std::string &type) const
 
CCopasiDataModelgetObjectDataModel ()
 
const CCopasiDataModelgetObjectDataModel () const
 
virtual std::string getObjectDisplayName (bool regular=true, bool richtext=false) const
 
const std::string & getObjectName () const
 
CCopasiContainergetObjectParent () const
 
const std::string & getObjectType () const
 
virtual const
CObjectInterface::ObjectSet
getPrerequisites () const
 
virtual RefreshgetRefresh () const
 
UpdateMethodgetUpdateMethod () const
 
virtual voidgetValuePointer () const
 
bool hasCircularDependencies (DataObjectSet &candidates, DataObjectSet &verified, const DataObjectSet &context) const
 
bool hasUpdateMethod () const
 
bool isArray () const
 
bool isContainer () const
 
bool isDataModel () const
 
bool isMatrix () const
 
bool isNameVector () const
 
bool isNonUniqueName () const
 
virtual bool isPrerequisiteForContext (const CObjectInterface *pObject, const CMath::SimulationContextFlag &context, const CObjectInterface::ObjectSet &changedObjects) const
 
bool isReference () const
 
bool isRoot () const
 
bool isSeparator () const
 
bool isStaticString () const
 
bool isValueBool () const
 
bool isValueDbl () const
 
bool isValueInt () const
 
bool isValueInt64 () const
 
bool isValueString () const
 
bool isVector () const
 
virtual bool mustBeDeleted (const DataObjectSet &deletedObjects) const
 
virtual void print (std::ostream *ostream) const
 
void removeDirectDependency (const CCopasiObject *pObject)
 
void setDirectDependencies (const DataObjectSet &directDependencies)
 
bool setObjectName (const std::string &name)
 
virtual bool setObjectParent (const CCopasiContainer *pParent)
 
void setObjectValue (const C_FLOAT64 &value)
 
void setObjectValue (const C_INT32 &value)
 
void setObjectValue (const bool &value)
 
template<class CType >
void setRefresh (CType *pType, void(CType::*method)(void))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const C_FLOAT64 &))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const C_INT32 &))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const bool &))
 
virtual ~CCopasiObject ()
 
- Public Member Functions inherited from CObjectInterface
 CObjectInterface ()
 
virtual ~CObjectInterface ()
 

Private Member Functions

bool compile (const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
 
bool compileAND (const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
 
bool compileEQ (const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
 
bool compileEXPRESSION (const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
 
bool compileFUNCTION (const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
 
bool compileGE (const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
 
bool compileGT (const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
 
bool compileLE (const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
 
bool compileLT (const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
 
bool compileNE (const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
 
bool compileNOT (const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
 
bool compileOR (const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
 
bool compileVARIABLE (const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
 
bool compileXOR (const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
 
CEvaluationNodecopyBranch (const CEvaluationNode *pSource)
 

Private Attributes

std::stack< std::vector< const
CEvaluationNode * > > 
mFunctionVariableMap
 
CCopasiVector< CRootFindermRootFinders
 
CExpression mTrueExpression
 

Additional Inherited Members

- Public Types inherited from CCopasiContainer
typedef std::multimap
< std::string, CCopasiObject * > 
objectMap
 
- Public Types inherited from CCopasiObject
typedef std::set< const
CCopasiObject * > 
DataObjectSet
 
typedef std::vector< Refresh * > DataUpdateSequence
 
- Public Types inherited from CObjectInterface
typedef std::set< const
CObjectInterface * > 
ObjectSet
 
typedef std::vector
< CObjectInterface * > 
UpdateSequence
 
- Static Public Member Functions inherited from CCopasiObject
static std::vector< Refresh * > buildUpdateSequence (const DataObjectSet &objects, const DataObjectSet &uptoDateObjects, const DataObjectSet &context=DataObjectSet())
 
static void setRenameHandler (CRenameHandler *rh)
 
- Static Public Attributes inherited from CCopasiContainer
static const std::vector
< CCopasiContainer * > 
EmptyList
 
- Protected Types inherited from CCopasiObject
enum  Flag {
  Container = 0x1, Vector = 0x2, Matrix = 0x4, NameVector = 0x8,
  Reference = 0x10, ValueBool = 0x20, ValueInt = 0x40, ValueInt64 = 0x80,
  ValueDbl = 0x100, NonUniqueName = 0x200, StaticString = 0x400, ValueString = 0x800,
  Separator = 0x1000, ModelEntity = 0x2000, Array = 0x4000, DataModel = 0x8000,
  Root = 0x10000, Gui = 0x20000
}
 
- Protected Member Functions inherited from CCopasiContainer
template<class CType >
CCopasiObjectaddMatrixReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
template<class CType >
CCopasiObjectaddObjectReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
template<class CType >
CCopasiObjectaddVectorReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
void initObjects ()
 
- Protected Member Functions inherited from CCopasiObject
 CCopasiObject ()
 
 CCopasiObject (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &type="CN", const unsigned C_INT32 &flag=0)
 
- Protected Attributes inherited from CCopasiContainer
objectMap mObjects
 
- Static Protected Attributes inherited from CCopasiObject
static CRenameHandlersmpRenameHandler = NULL
 

Detailed Description

Definition at line 13 of file CMathTrigger.h.

Constructor & Destructor Documentation

CMathTrigger::CMathTrigger ( const CCopasiContainer pParent = NULL)

Default constructor

Parameters
constCCopasiContainer * pParent (default: NULL)

Definition at line 165 of file CMathTrigger.cpp.

165  :
166  CCopasiContainer("MathTrigger", pParent, "MathTrigger"),
167  mTrueExpression("TrueExpression", this),
168  mRootFinders("ListOfRoots", this),
170 {}
CCopasiVector< CRootFinder > mRootFinders
Definition: CMathTrigger.h:250
CExpression mTrueExpression
Definition: CMathTrigger.h:245
std::stack< std::vector< const CEvaluationNode * > > mFunctionVariableMap
Definition: CMathTrigger.h:256
CMathTrigger::CMathTrigger ( const CMathTrigger src,
const CCopasiContainer pParent = NULL 
)

Copy constructor

Parameters
const CMathTrigger &src
"constCCopasiContainer * pParent (default: NULL)

Definition at line 172 of file CMathTrigger.cpp.

173  :
174  CCopasiContainer(src, pParent),
175  mTrueExpression(src.mTrueExpression, this),
176  mRootFinders(src.mRootFinders, this),
178 {}
CCopasiVector< CRootFinder > mRootFinders
Definition: CMathTrigger.h:250
CExpression mTrueExpression
Definition: CMathTrigger.h:245
std::stack< std::vector< const CEvaluationNode * > > mFunctionVariableMap
Definition: CMathTrigger.h:256
CMathTrigger::~CMathTrigger ( )
virtual

Destructor

Definition at line 180 of file CMathTrigger.cpp.

181 {}

Member Function Documentation

void CMathTrigger::applyInitialValues ( )

Initialize all values of the math model with their initial values.

Definition at line 183 of file CMathTrigger.cpp.

References mRootFinders.

184 {
185  // Calculate the initial truth value for the root finders
188 
189  for (; itRoot != endRoot; ++itRoot)
190  {
191  (*itRoot)->applyInitialValues();
192  }
193 }
CCopasiVector< CRootFinder > mRootFinders
Definition: CMathTrigger.h:250
std::vector< CType * >::iterator iterator
Definition: CCopasiVector.h:56
bool CMathTrigger::calculate ( void  )

Calculate the current trigger value.

Returns
value

Definition at line 207 of file CMathTrigger.cpp.

References CExpression::calcValue(), and mTrueExpression.

Referenced by CMathModel::processRoots().

208 {
209  return mTrueExpression.calcValue() > 0.0;
210 }
CExpression mTrueExpression
Definition: CMathTrigger.h:245
virtual const C_FLOAT64 & calcValue()
void CMathTrigger::calculateInitialActivity ( )

Determine the activity for the initial conditions.

void CMathTrigger::calculateTrueValue ( )

Determine the true value for the initial conditions.

Definition at line 195 of file CMathTrigger.cpp.

References mRootFinders.

Referenced by CMathTrigger::CRootFinder::applyInitialValues().

196 {
197  // Calculate the current truth value for the root finders
200 
201  for (; itRoot != endRoot; ++itRoot)
202  {
203  (*itRoot)->calculateTrueValue();
204  }
205 }
CCopasiVector< CRootFinder > mRootFinders
Definition: CMathTrigger.h:250
std::vector< CType * >::iterator iterator
Definition: CCopasiVector.h:56
bool CMathTrigger::compile ( const CExpression pTriggerExpression,
std::vector< CCopasiContainer * >  listOfContainer 
)

Compile the trigger

Parameters
constCExpression * pTriggerExpression
std::vector<CCopasiContainer * > listOfContainer
Returns
bool success

Definition at line 212 of file CMathTrigger.cpp.

References CExpression::compile(), CEvaluationTree::getRoot(), CEvaluationNode::isBoolean(), mFunctionVariableMap, mRootFinders, mTrueExpression, CExpression::setInfix(), and CEvaluationTree::setRoot().

Referenced by CMathEvent::compile(), compileAND(), compileEQ(), compileEXPRESSION(), compileFUNCTION(), compileNOT(), compileOR(), compileVARIABLE(), and compileXOR().

214 {
215  if (pTriggerExpression == NULL)
216  return false;
217 
218  const CEvaluationNode * pRoot = pTriggerExpression->getRoot();
219 
220  if (pRoot == NULL)
221  return false;
222 
223  // This is a boolean expression thus the root node must be a logical operator.
224  if (!pRoot->isBoolean())
225  return false;
226 
228  mRootFinders.clear();
229 
230  CEvaluationNode * pTrueExpression = NULL;
231 
232  bool success = compile(pRoot, pTrueExpression);
233 
234  // Build the true expression
235  mTrueExpression.setRoot(pTrueExpression);
236  success &= mTrueExpression.compile(listOfContainer);
237 
238  // Compile all root finder
241 
242  for (; it != end; ++it)
243  {
244  success &= (*it)->compile(listOfContainer);
245  }
246 
247  assert(mFunctionVariableMap.empty());
248 
249  return success;
250 }
CCopasiVector< CRootFinder > mRootFinders
Definition: CMathTrigger.h:250
virtual bool setRoot(CEvaluationNode *pRootNode)
virtual bool setInfix(const std::string &infix)
Definition: CExpression.cpp:63
virtual bool compile(std::vector< CCopasiContainer * > listOfContainer=CCopasiContainer::EmptyList)
Definition: CExpression.cpp:97
CExpression mTrueExpression
Definition: CMathTrigger.h:245
std::stack< std::vector< const CEvaluationNode * > > mFunctionVariableMap
Definition: CMathTrigger.h:256
virtual bool isBoolean() const
std::vector< CType * >::iterator iterator
Definition: CCopasiVector.h:56
CEvaluationNode * getRoot()
bool compile(const CExpression *pTriggerExpression, std::vector< CCopasiContainer * > listOfContainer)
bool CMathTrigger::compile ( const CEvaluationNode pSource,
CEvaluationNode *&  pTrueExpression 
)
private

Definition at line 257 of file CMathTrigger.cpp.

References CEvaluationNodeLogical::AND, CEvaluationNodeVariable::ANY, CEvaluationNode::CALL, compileAND(), compileEQ(), compileEXPRESSION(), compileFUNCTION(), compileGE(), compileGT(), compileLE(), compileLT(), compileNE(), compileNOT(), compileOR(), compileVARIABLE(), compileXOR(), CEvaluationNode::CONSTANT, CEvaluationNodeLogical::EQ, CEvaluationNodeCall::EXPRESSION, CEvaluationNodeConstant::FALSE, CEvaluationNodeCall::FUNCTION, CEvaluationNode::FUNCTION, CEvaluationNodeLogical::GE, CEvaluationNode::getType(), CEvaluationNodeLogical::GT, CEvaluationNodeLogical::LE, CEvaluationNode::LOGICAL, CEvaluationNodeLogical::LT, CEvaluationNodeLogical::NE, CEvaluationNodeFunction::NOT, CEvaluationNodeLogical::OR, CEvaluationNode::subType(), CEvaluationNodeConstant::TRUE, CEvaluationNode::type(), CEvaluationNode::VARIABLE, and CEvaluationNodeLogical::XOR.

259 {
260  bool success = true;
261  const CEvaluationNode::Type & Type = pNode->getType();
262 
263  switch (CEvaluationNode::type(Type))
264  {
266 
267  switch ((int) CEvaluationNode::subType(Type))
268  {
270  success = compileAND(pNode, pTrueExpression);
271  break;
272 
274  success = compileOR(pNode, pTrueExpression);
275  break;
276 
278  success = compileXOR(pNode, pTrueExpression);
279  break;
280 
282  success = compileEQ(pNode, pTrueExpression);
283  break;
284 
286  success = compileNE(pNode, pTrueExpression);
287  break;
288 
290  success = compileLE(pNode, pTrueExpression);
291  break;
292 
294  success = compileLT(pNode, pTrueExpression);
295  break;
296 
298  success = compileGE(pNode, pTrueExpression);
299  break;
300 
302  success = compileGT(pNode, pTrueExpression);
303  break;
304 
305  default:
306  success = false;
307  break;
308  }
309 
310  break;
311 
313 
314  switch ((int) CEvaluationNode::subType(Type))
315  {
317  success = compileNOT(pNode, pTrueExpression);
318  break;
319 
320  default:
321  success = false;
322  break;
323  }
324 
325  break;
326 
328 
329  switch ((int) CEvaluationNode::subType(Type))
330  {
332  success = compileFUNCTION(pNode, pTrueExpression);
333  break;
334 
336  success = compileEXPRESSION(pNode, pTrueExpression);
337  break;
338 
339  default:
340  success = false;
341  break;
342  }
343 
344  break;
345 
347 
348  switch ((int) CEvaluationNode::subType(Type))
349  {
351  success = compileVARIABLE(pNode, pTrueExpression);
352  break;
353 
354  default:
355  success = false;
356  break;
357  }
358 
359  break;
360 
362 
363  switch ((int) CEvaluationNode::subType(Type))
364  {
366  pTrueExpression = new CEvaluationNodeConstant(CEvaluationNodeConstant::TRUE, "TRUE");
367  success = true;
368  break;
369 
371  pTrueExpression = new CEvaluationNodeConstant(CEvaluationNodeConstant::FALSE, "FALSE");
372  success = true;
373  break;
374 
375  default:
376  success = false;
377  break;
378  }
379 
380  break;
381 
382  default:
383  success = false;
384  break;
385  }
386 
387  return success;
388 }
bool compileNE(const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
bool compileOR(const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
bool compileFUNCTION(const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
bool compileNOT(const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
static Type type(const Type &type)
bool compileLT(const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
bool compileEXPRESSION(const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
bool compileGT(const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
bool compileAND(const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
bool compileLE(const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
bool compileGE(const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
bool compileVARIABLE(const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
static Type subType(const Type &type)
bool compileXOR(const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
bool compileEQ(const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
bool CMathTrigger::compileAND ( const CEvaluationNode pSource,
CEvaluationNode *&  pTrueExpression 
)
private

Definition at line 390 of file CMathTrigger.cpp.

References CCopasiNode< _Data >::addChild(), CEvaluationNodeLogical::AND, compile(), CCopasiNode< _Data >::getChild(), and CCopasiNode< _Data >::getSibling().

Referenced by compile(), and compileEQ().

392 {
393  bool success = true;
394 
395  const CEvaluationNode * pLeft = static_cast<const CEvaluationNode *>(pSource->getChild());
396  const CEvaluationNode * pRight = static_cast<const CEvaluationNode *>(pLeft->getSibling());
397 
398  CEvaluationNode * pLeftTrueExpression = NULL;
399 
400  success &= compile(pLeft, pLeftTrueExpression);
401 
402  CEvaluationNode * pRightTrueExpression = NULL;
403 
404  success &= compile(pRight, pRightTrueExpression);
405 
406  pTrueExpression = new CEvaluationNodeLogical(CEvaluationNodeLogical::AND, "AND");
407  pTrueExpression->addChild(pLeftTrueExpression);
408  pTrueExpression->addChild(pRightTrueExpression);
409 
410  return success;
411 }
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
bool compile(const CExpression *pTriggerExpression, std::vector< CCopasiContainer * > listOfContainer)
bool CMathTrigger::compileEQ ( const CEvaluationNode pSource,
CEvaluationNode *&  pTrueExpression 
)
private

Definition at line 459 of file CMathTrigger.cpp.

References CCopasiNode< _Data >::addChild(), CEvaluationNodeLogical::AND, compile(), compileAND(), copyBranch(), CEvaluationNodeLogical::EQ, CEvaluationNodeLogical::GE, CCopasiNode< _Data >::getChild(), CCopasiNode< _Data >::getSibling(), CEvaluationNode::getType(), CEvaluationNode::LOGICAL, pdelete, and CEvaluationNode::type().

Referenced by compile().

461 {
462  bool success = true;
463 
464  const CEvaluationNode * pLeft = static_cast<const CEvaluationNode *>(pSource->getChild());
465  const CEvaluationNode * pRight = static_cast<const CEvaluationNode *>(pLeft->getSibling());
466 
467  // Equality can be determined between Boolean and double values.
469  {
470  // We treat x EQ y as (x GE y) AND (y GE x)
471 
472  // Create a temporary expression and compile it.
475  pGE->addChild(copyBranch(pLeft));
476  pGE->addChild(copyBranch(pRight));
477  pAND->addChild(pGE);
478 
480  pGE->addChild(copyBranch(pRight));
481  pGE->addChild(copyBranch(pLeft));
482  pAND->addChild(pGE);
483 
484  success &= compileAND(pAND, pTrueExpression);
485 
486  // Delete the temporary
487  pdelete(pAND);
488  }
489  else
490  {
491  CEvaluationNode * pLeftTrueExpression = NULL;
492 
493  success &= compile(pLeft, pLeftTrueExpression);
494 
495  CEvaluationNode * pRightTrueExpression = NULL;
496 
497  success &= compile(pRight, pRightTrueExpression);
498 
499  pTrueExpression = new CEvaluationNodeLogical(CEvaluationNodeLogical::EQ, "EQ");
500  pTrueExpression->addChild(pLeftTrueExpression);
501  pTrueExpression->addChild(pRightTrueExpression);
502  }
503 
504  return success;
505 }
#define pdelete(p)
Definition: copasi.h:215
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
CEvaluationNode * copyBranch(const CEvaluationNode *pSource)
const Type & getType() const
static Type type(const Type &type)
bool compileAND(const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
bool compile(const CExpression *pTriggerExpression, std::vector< CCopasiContainer * > listOfContainer)
bool CMathTrigger::compileEXPRESSION ( const CEvaluationNode pSource,
CEvaluationNode *&  pTrueExpression 
)
private

Definition at line 680 of file CMathTrigger.cpp.

References compile(), and CEvaluationNode::isBoolean().

Referenced by compile().

682 {
683  if (!pSource->isBoolean())
684  return false;
685 
686  const CEvaluationNode * pNode =
687  static_cast< const CEvaluationNodeCall * >(pSource)->getCalledTree()->getRoot();
688 
689  return compile(pNode, pTrueExpression);
690 }
virtual bool isBoolean() const
bool compile(const CExpression *pTriggerExpression, std::vector< CCopasiContainer * > listOfContainer)
bool CMathTrigger::compileFUNCTION ( const CEvaluationNode pSource,
CEvaluationNode *&  pTrueExpression 
)
private

Definition at line 649 of file CMathTrigger.cpp.

References compile(), CEvaluationNodeCall::getCalledTree(), CCopasiNode< _Data >::getChild(), CEvaluationTree::getRoot(), CCopasiNode< _Data >::getSibling(), CEvaluationNode::isBoolean(), and mFunctionVariableMap.

Referenced by compile().

651 {
652  if (!pSource->isBoolean())
653  return false;
654 
655  const CEvaluationNodeCall * pSrc =
656  static_cast< const CEvaluationNodeCall * >(pSource);
657 
658  std::vector< const CEvaluationNode * > Variables;
659 
660  const CEvaluationNode * pChild =
661  static_cast< const CEvaluationNode * >(pSrc->getChild());
662 
663  while (pChild != NULL)
664  {
665  Variables.push_back(pChild);
666  pChild = static_cast< const CEvaluationNode * >(pChild->getSibling());
667  }
668 
669  mFunctionVariableMap.push(Variables);
670 
671  const CEvaluationNode * pNode = pSrc->getCalledTree()->getRoot();
672 
673  bool success = compile(pNode, pTrueExpression);
674 
675  mFunctionVariableMap.pop();
676 
677  return success;
678 }
const CEvaluationTree * getCalledTree() const
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
std::stack< std::vector< const CEvaluationNode * > > mFunctionVariableMap
Definition: CMathTrigger.h:256
virtual bool isBoolean() const
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CEvaluationNode * getRoot()
bool compile(const CExpression *pTriggerExpression, std::vector< CCopasiContainer * > listOfContainer)
bool CMathTrigger::compileGE ( const CEvaluationNode pSource,
CEvaluationNode *&  pTrueExpression 
)
private

Definition at line 582 of file CMathTrigger.cpp.

References CCopasiNode< _Data >::addChild(), copyBranch(), CCopasiNode< _Data >::getChild(), CCopasiNode< _Data >::getSibling(), CMathTrigger::CRootFinder::getTrueExpression(), CMathTrigger::CRootFinder::mEquality, CEvaluationNodeOperator::MINUS, CMathTrigger::CRootFinder::mRoot, mRootFinders, and CEvaluationTree::setRoot().

Referenced by compile().

584 {
585  bool success = true;
586 
587  const CEvaluationNode * pLeft = static_cast<const CEvaluationNode *>(pSource->getChild());
588  const CEvaluationNode * pRight = static_cast<const CEvaluationNode *>(pLeft->getSibling());
589 
590  CEvaluationNode * pNode;
591 
592  // We need to create a root finding structures
594  pNode->addChild(copyBranch(pLeft));
595  pNode->addChild(copyBranch(pRight));
596 
597  CRootFinder * pRootFinder = new CRootFinder();
598  pRootFinder->mRoot.setRoot(pNode);
599  pRootFinder->mEquality = true;
600  mRootFinders.add(pRootFinder, true);
601 
602  pTrueExpression = pRootFinder->getTrueExpression();
603 
604  return success;
605 }
CCopasiVector< CRootFinder > mRootFinders
Definition: CMathTrigger.h:250
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
CEvaluationNode * copyBranch(const CEvaluationNode *pSource)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
bool CMathTrigger::compileGT ( const CEvaluationNode pSource,
CEvaluationNode *&  pTrueExpression 
)
private

Definition at line 607 of file CMathTrigger.cpp.

References CCopasiNode< _Data >::addChild(), copyBranch(), CCopasiNode< _Data >::getChild(), CCopasiNode< _Data >::getSibling(), CMathTrigger::CRootFinder::getTrueExpression(), CMathTrigger::CRootFinder::mEquality, CEvaluationNodeOperator::MINUS, CMathTrigger::CRootFinder::mRoot, mRootFinders, and CEvaluationTree::setRoot().

Referenced by compile().

609 {
610  bool success = true;
611 
612  const CEvaluationNode * pLeft = static_cast<const CEvaluationNode *>(pSource->getChild());
613  const CEvaluationNode * pRight = static_cast<const CEvaluationNode *>(pLeft->getSibling());
614 
615  CEvaluationNode * pNode;
616 
617  // We need to create a root finding structures
619  pNode->addChild(copyBranch(pLeft));
620  pNode->addChild(copyBranch(pRight));
621 
622  CRootFinder * pRootFinder = new CRootFinder();
623  pRootFinder->mRoot.setRoot(pNode);
624  pRootFinder->mEquality = false;
625  mRootFinders.add(pRootFinder, true);
626 
627  pTrueExpression = pRootFinder->getTrueExpression();
628 
629  return success;
630 }
CCopasiVector< CRootFinder > mRootFinders
Definition: CMathTrigger.h:250
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
CEvaluationNode * copyBranch(const CEvaluationNode *pSource)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
bool CMathTrigger::compileLE ( const CEvaluationNode pSource,
CEvaluationNode *&  pTrueExpression 
)
private

Definition at line 532 of file CMathTrigger.cpp.

References CCopasiNode< _Data >::addChild(), copyBranch(), CCopasiNode< _Data >::getChild(), CCopasiNode< _Data >::getSibling(), CMathTrigger::CRootFinder::getTrueExpression(), CMathTrigger::CRootFinder::mEquality, CEvaluationNodeOperator::MINUS, CMathTrigger::CRootFinder::mRoot, mRootFinders, and CEvaluationTree::setRoot().

Referenced by compile().

534 {
535  bool success = true;
536 
537  const CEvaluationNode * pLeft = static_cast<const CEvaluationNode *>(pSource->getChild());
538  const CEvaluationNode * pRight = static_cast<const CEvaluationNode *>(pLeft->getSibling());
539 
540  CEvaluationNode * pNode;
541 
542  // We need to create a root finding structures
544  pNode->addChild(copyBranch(pRight));
545  pNode->addChild(copyBranch(pLeft));
546 
547  CRootFinder * pRootFinder = new CRootFinder();
548  pRootFinder->mRoot.setRoot(pNode);
549  pRootFinder->mEquality = true;
550  mRootFinders.add(pRootFinder, true);
551 
552  pTrueExpression = pRootFinder->getTrueExpression();
553 
554  return success;
555 }
CCopasiVector< CRootFinder > mRootFinders
Definition: CMathTrigger.h:250
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
CEvaluationNode * copyBranch(const CEvaluationNode *pSource)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
bool CMathTrigger::compileLT ( const CEvaluationNode pSource,
CEvaluationNode *&  pTrueExpression 
)
private

Definition at line 557 of file CMathTrigger.cpp.

References CCopasiNode< _Data >::addChild(), copyBranch(), CCopasiNode< _Data >::getChild(), CCopasiNode< _Data >::getSibling(), CMathTrigger::CRootFinder::getTrueExpression(), CMathTrigger::CRootFinder::mEquality, CEvaluationNodeOperator::MINUS, CMathTrigger::CRootFinder::mRoot, mRootFinders, and CEvaluationTree::setRoot().

Referenced by compile().

559 {
560  bool success = true;
561 
562  const CEvaluationNode * pLeft = static_cast<const CEvaluationNode *>(pSource->getChild());
563  const CEvaluationNode * pRight = static_cast<const CEvaluationNode *>(pLeft->getSibling());
564 
565  CEvaluationNode * pNode;
566 
567  // We need to create a root finding structures
569  pNode->addChild(copyBranch(pRight));
570  pNode->addChild(copyBranch(pLeft));
571 
572  CRootFinder * pRootFinder = new CRootFinder();
573  pRootFinder->mRoot.setRoot(pNode);
574  pRootFinder->mEquality = false;
575  mRootFinders.add(pRootFinder, true);
576 
577  pTrueExpression = pRootFinder->getTrueExpression();
578 
579  return success;
580 }
CCopasiVector< CRootFinder > mRootFinders
Definition: CMathTrigger.h:250
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
CEvaluationNode * copyBranch(const CEvaluationNode *pSource)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
bool CMathTrigger::compileNE ( const CEvaluationNode pSource,
CEvaluationNode *&  pTrueExpression 
)
private

Definition at line 507 of file CMathTrigger.cpp.

References CCopasiNode< _Data >::addChild(), compileNOT(), CEvaluationNode::copyBranch(), CEvaluationNodeLogical::EQ, CCopasiNode< _Data >::getChild(), CCopasiNode< _Data >::getSibling(), and CEvaluationNodeFunction::NOT.

Referenced by compile().

509 {
510  bool success = true;
511 
512  const CEvaluationNode * pLeft = static_cast<const CEvaluationNode *>(pSource->getChild());
513  const CEvaluationNode * pRight = static_cast<const CEvaluationNode *>(pLeft->getSibling());
514 
515  // We treat this as NOT and EQ.
516  // For this we create a modified copy of the current node.
517 
520  pEqNode->addChild(pLeft->copyBranch());
521  pEqNode->addChild(pRight->copyBranch());
522  pNotNode->addChild(pEqNode);
523 
524  success &= compileNOT(pNotNode, pTrueExpression);
525 
526  // Delete the temporary
527  delete pNotNode;
528 
529  return success;
530 }
CEvaluationNode * copyBranch() const
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
bool compileNOT(const CEvaluationNode *pSource, CEvaluationNode *&pTrueExpression)
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
bool CMathTrigger::compileNOT ( const CEvaluationNode pSource,
CEvaluationNode *&  pTrueExpression 
)
private

Definition at line 632 of file CMathTrigger.cpp.

References CCopasiNode< _Data >::addChild(), compile(), CCopasiNode< _Data >::getChild(), and CEvaluationNodeFunction::NOT.

Referenced by compile(), and compileNE().

634 {
635  bool success = true;
636 
637  const CEvaluationNode * pLeft = static_cast<const CEvaluationNode *>(pSource->getChild());
638 
639  CEvaluationNode * pLeftTrueExpression = NULL;
640 
641  success &= compile(pLeft, pLeftTrueExpression);
642 
643  pTrueExpression = new CEvaluationNodeFunction(CEvaluationNodeFunction::NOT, "NOT");
644  pTrueExpression->addChild(pLeftTrueExpression);
645 
646  return success;
647 }
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
bool compile(const CExpression *pTriggerExpression, std::vector< CCopasiContainer * > listOfContainer)
bool CMathTrigger::compileOR ( const CEvaluationNode pSource,
CEvaluationNode *&  pTrueExpression 
)
private

Definition at line 413 of file CMathTrigger.cpp.

References CCopasiNode< _Data >::addChild(), compile(), CCopasiNode< _Data >::getChild(), CCopasiNode< _Data >::getSibling(), and CEvaluationNodeLogical::OR.

Referenced by compile().

415 {
416  bool success = true;
417 
418  const CEvaluationNode * pLeft = static_cast<const CEvaluationNode *>(pSource->getChild());
419  const CEvaluationNode * pRight = static_cast<const CEvaluationNode *>(pLeft->getSibling());
420 
421  CEvaluationNode * pLeftTrueExpression = NULL;
422 
423  success &= compile(pLeft, pLeftTrueExpression);
424 
425  CEvaluationNode * pRightTrueExpression = NULL;
426 
427  success &= compile(pRight, pRightTrueExpression);
428 
429  pTrueExpression = new CEvaluationNodeLogical(CEvaluationNodeLogical::OR, "OR");
430  pTrueExpression->addChild(pLeftTrueExpression);
431  pTrueExpression->addChild(pRightTrueExpression);
432 
433  return success;
434 }
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
bool compile(const CExpression *pTriggerExpression, std::vector< CCopasiContainer * > listOfContainer)
bool CMathTrigger::compileVARIABLE ( const CEvaluationNode pSource,
CEvaluationNode *&  pTrueExpression 
)
private

Definition at line 692 of file CMathTrigger.cpp.

References compile(), CEvaluationNode::isBoolean(), and mFunctionVariableMap.

Referenced by compile().

694 {
695  assert(!mFunctionVariableMap.empty());
696 
697  size_t Index =
698  static_cast< const CEvaluationNodeVariable * >(pSource)->getIndex();
699 
700  const CEvaluationNode * pNode = mFunctionVariableMap.top()[Index];
701 
702  if (!pNode->isBoolean())
703  return false;
704 
705  return compile(pNode, pTrueExpression);
706 }
std::stack< std::vector< const CEvaluationNode * > > mFunctionVariableMap
Definition: CMathTrigger.h:256
virtual bool isBoolean() const
bool compile(const CExpression *pTriggerExpression, std::vector< CCopasiContainer * > listOfContainer)
bool CMathTrigger::compileXOR ( const CEvaluationNode pSource,
CEvaluationNode *&  pTrueExpression 
)
private

Definition at line 436 of file CMathTrigger.cpp.

References CCopasiNode< _Data >::addChild(), compile(), CCopasiNode< _Data >::getChild(), CCopasiNode< _Data >::getSibling(), and CEvaluationNodeLogical::XOR.

Referenced by compile().

438 {
439  bool success = true;
440 
441  const CEvaluationNode * pLeft = static_cast<const CEvaluationNode *>(pSource->getChild());
442  const CEvaluationNode * pRight = static_cast<const CEvaluationNode *>(pLeft->getSibling());
443 
444  CEvaluationNode * pLeftTrueExpression = NULL;
445 
446  success &= compile(pLeft, pLeftTrueExpression);
447 
448  CEvaluationNode * pRightTrueExpression = NULL;
449 
450  success &= compile(pRight, pRightTrueExpression);
451 
452  pTrueExpression = new CEvaluationNodeLogical(CEvaluationNodeLogical::XOR, "XOR");
453  pTrueExpression->addChild(pLeftTrueExpression);
454  pTrueExpression->addChild(pRightTrueExpression);
455 
456  return success;
457 }
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
bool compile(const CExpression *pTriggerExpression, std::vector< CCopasiContainer * > listOfContainer)
CEvaluationNode * CMathTrigger::copyBranch ( const CEvaluationNode pSource)
private

Definition at line 708 of file CMathTrigger.cpp.

References CEvaluationNodeConstant::_NaN, C_INVALID_INDEX, CEvaluationNode::copyBranch(), CCopasiNode< _Data >::getData(), CEvaluationNode::getType(), mFunctionVariableMap, and CEvaluationNode::VARIABLE.

Referenced by compileEQ(), compileGE(), compileGT(), compileLE(), and compileLT().

709 {
710  if (pSource->getType() == CEvaluationNode::VARIABLE)
711  {
712  if (!mFunctionVariableMap.empty())
713  {
714  size_t Index = static_cast< const CEvaluationNodeVariable * >(pSource)->getIndex();
715 
716  if (Index != C_INVALID_INDEX &&
717  Index < mFunctionVariableMap.top().size())
718  {
719  return mFunctionVariableMap.top()[Index]->copyBranch();
720  }
721  }
722 
723  // We have an invalid variables and therefore create an constant node with the
724  // variable name and value NaN.
726  }
727 
728  return pSource->copyBranch();
729 }
CEvaluationNode * copyBranch() const
const Type & getType() const
#define C_INVALID_INDEX
Definition: copasi.h:222
std::stack< std::vector< const CEvaluationNode * > > mFunctionVariableMap
Definition: CMathTrigger.h:256
virtual const Data & getData() const
Definition: CCopasiNode.h:118
CCopasiVector< CMathTrigger::CRootFinder > & CMathTrigger::getRootFinders ( )

Retrieve the list of root finders

Returns
CCopasiVector< CRootFinder > & rootFinders

Definition at line 252 of file CMathTrigger.cpp.

References mRootFinders.

Referenced by CMathModel::compile().

253 {
254  return mRootFinders;
255 }
CCopasiVector< CRootFinder > mRootFinders
Definition: CMathTrigger.h:250

Member Data Documentation

std::stack< std::vector< const CEvaluationNode * > > CMathTrigger::mFunctionVariableMap
private

A stack to map variable nodes to the value nodes provided in the function call

Definition at line 256 of file CMathTrigger.h.

Referenced by compile(), compileFUNCTION(), compileVARIABLE(), and copyBranch().

CCopasiVector< CRootFinder > CMathTrigger::mRootFinders
private

A vector containing the root expression.

Definition at line 250 of file CMathTrigger.h.

Referenced by applyInitialValues(), calculateTrueValue(), compile(), compileGE(), compileGT(), compileLE(), compileLT(), and getRootFinders().

CExpression CMathTrigger::mTrueExpression
private

This expression evaluates whether the trigger value is true.

Definition at line 245 of file CMathTrigger.h.

Referenced by calculate(), and compile().


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