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

The class for handling a chemical kinetic function. More...

#include <CFunction.h>

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

Public Member Functions

bool addVariable (const std::string &name, CFunctionParameter::Role usage=CFunctionParameter::VARIABLE, const CFunctionParameter::DataType &type=CFunctionParameter::FLOAT64)
 
virtual const C_FLOAT64calcValue (const CCallParameters< C_FLOAT64 > &callParameters)
 
 CFunction (const std::string &name="NoName", const CCopasiContainer *pParent=NULL, const Type &type=Function)
 
 CFunction (const CFunction &src, const CCopasiContainer *pParent=NULL)
 
CFunctioncreateCopy () const
 
void createListOfParametersForMathML (std::vector< std::vector< std::string > > &env)
 
virtual bool dependsOn (const C_FLOAT64 *parameter, const CCallParameters< C_FLOAT64 > &callParameters) const
 
const std::string & getKey () const
 
const std::string & getSBMLId () const
 
virtual size_t getVariableIndex (const std::string &name) const
 
CFunctionParametersgetVariables ()
 
const CFunctionParametersgetVariables () const
 
virtual const C_FLOAT64getVariableValue (const size_t &index) const
 
const TriLogicisReversible () const
 
bool isSuitable (const size_t noSubstrates, const size_t noProducts, const TriLogic reversible)
 
virtual void load (CReadConfig &configBuffer, CReadConfig::Mode mode=CReadConfig::SEARCH)
 
bool operator== (const CFunction &rhs) const
 
virtual bool setInfix (const std::string &infix)
 
virtual bool setInfix (const std::string &infix, bool compile)
 
void setReversible (const TriLogic &reversible)
 
void setSBMLId (const std::string &id)
 
std::pair< CFunction
*, CFunction * > 
splitFunction (const CEvaluationNode *node, const std::string &name1, const std::string &name2) const
 
virtual void writeMathML (std::ostream &out, size_t l=0) const
 
virtual std::string writeMathML (const std::vector< std::vector< std::string > > &variables, bool expand=true, bool fullExpand=true) const
 
virtual ~CFunction ()
 
- Public Member Functions inherited from CEvaluationTree
bool calls (std::set< std::string > &list) const
 
 CEvaluationTree (const std::string &name="NoName", const CCopasiContainer *pParent=NULL, const Type &type=Function)
 
 CEvaluationTree (const CEvaluationTree &src, const CCopasiContainer *pParent=NULL)
 
virtual bool compile ()
 
bool dependsOnTree (const std::string &name) const
 
CCopasiObject::DataObjectSet getDeletedObjects () const
 
std::string::size_type getErrorPosition () const
 
const std::string & getInfix () const
 
const std::vector
< CEvaluationNode * > & 
getNodeList () const
 
CEvaluationNodegetRoot ()
 
const CEvaluationNodegetRoot () const
 
const CEvaluationTree::TypegetType () const
 
bool hasCircularDependency () const
 
bool hasDiscontinuity () const
 
bool isBoolean () const
 
bool isUsable () const
 
bool operator== (const CEvaluationTree &rhs) const
 
virtual bool setRoot (CEvaluationNode *pRootNode)
 
bool setTree (const ASTNode &pRootNode)
 
virtual ASTNode * toAST (const CCopasiDataModel *pDataModel) const
 
bool updateTree ()
 
virtual ~CEvaluationTree ()
 
- 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
 
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 ()
 
- Public Member Functions inherited from CAnnotation
bool addUnsupportedAnnotation (const std::string &name, const std::string &xml)
 
 CAnnotation ()
 
 CAnnotation (const CAnnotation &src)
 
const std::string & getMiriamAnnotation () const
 
const std::string & getNotes () const
 
UnsupportedAnnotationgetUnsupportedAnnotations ()
 
const UnsupportedAnnotationgetUnsupportedAnnotations () const
 
bool operator== (const CAnnotation &rhs) const
 
bool removeUnsupportedAnnotation (const std::string &name)
 
bool replaceUnsupportedAnnotation (const std::string &name, const std::string &xml)
 
void setMiriamAnnotation (const std::string &miriamAnnotation, const std::string &newId, const std::string &oldId)
 
void setNotes (const std::string &notes)
 
virtual ~CAnnotation ()
 

Static Public Member Functions

static bool completeFunctionList (std::vector< CFunction * > &list, const size_t &added=0)
 
- Static Public Member Functions inherited from CEvaluationTree
static CEvaluationTreecopy (const CEvaluationTree &src)
 
static CEvaluationTreecreate (CEvaluationTree::Type type)
 
static CEvaluationNodefromAST (const ASTNode *pASTNode)
 
- 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 Member Functions inherited from CAnnotation
static CAnnotationcastObject (CCopasiObject *pObject)
 
static const CAnnotationcastObject (const CCopasiObject *pObject)
 

Protected Member Functions

bool initVariables ()
 
- Protected Member Functions inherited from CEvaluationTree
void buildCalculationSequence ()
 
void calculate ()
 
bool compileNodes ()
 
bool parse ()
 
void setType (const CEvaluationTree::Type &type)
 
- 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)
 

Private Attributes

CCallParameters< C_FLOAT64 >
::const_iterator 
mCallParametersBegin
 
TriLogic mReversible
 
std::string mSBMLId
 
CFunctionParameters mVariables
 

Friends

std::ostream & operator<< (std::ostream &os, const CFunction &f)
 

Additional Inherited Members

- Public Types inherited from CEvaluationTree
enum  Type {
  Function = 0, MassAction, PreDefined, UserDefined,
  Expression, MathExpression
}
 
- 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
 
- Public Types inherited from CAnnotation
typedef std::map< std::string,
std::string > 
UnsupportedAnnotation
 
- Static Public Attributes inherited from CEvaluationTree
static const std::string TypeName []
 
static const char * XMLType []
 
- 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 Attributes inherited from CEvaluationTree
std::vector< CEvaluationNode * > mCalculationSequence
 
std::string mInfix
 
std::vector< CEvaluationNode * > * mpNodeList
 
CEvaluationNodempRoot
 
CEvaluationTree::Type mType
 
bool mUsable
 
C_FLOAT64 mValue
 
- Protected Attributes inherited from CCopasiContainer
objectMap mObjects
 
- Protected Attributes inherited from CAnnotation
std::string mKey
 
- Static Protected Attributes inherited from CCopasiObject
static CRenameHandlersmpRenameHandler = NULL
 

Detailed Description

The class for handling a chemical kinetic function.

This class is designed to handle all about a given chemical kinetic function from editing and displaying (with help of MathML) the function to calculating the function value.

Definition at line 29 of file CFunction.h.

Constructor & Destructor Documentation

CFunction::CFunction ( const std::string &  name = "NoName",
const CCopasiContainer pParent = NULL,
const Type type = Function 
)

Default constructor

Parameters
conststd::string & name (default: "NoName")
constCEvaluationTree::Type & type (default: Function)
constCCopasiContainer * pParent (default: NULL)

Definition at line 25 of file CFunction.cpp.

References CKeyFactory::add(), CCopasiRootContainer::getKeyFactory(), and CAnnotation::mKey.

Referenced by createCopy(), and splitFunction().

27  :
28  CEvaluationTree(name, pParent, type),
29  CAnnotation(),
30  mSBMLId(""),
31  mVariables("Function Parameters", this),
34 {
35  mKey = CCopasiRootContainer::getKeyFactory()->add("Function", this);
36 }
CFunctionParameters mVariables
Definition: CFunction.h:210
std::string mSBMLId
Definition: CFunction.h:203
std::string mKey
Definition: CAnnotation.h:119
TriLogic mReversible
Definition: CFunction.h:220
std::string add(const std::string &prefix, CCopasiObject *pObject)
static CKeyFactory * getKeyFactory()
CCallParameters< C_FLOAT64 >::const_iterator mCallParametersBegin
Definition: CFunction.h:215
CEvaluationTree(const std::string &name="NoName", const CCopasiContainer *pParent=NULL, const Type &type=Function)
CFunction::CFunction ( const CFunction src,
const CCopasiContainer pParent = NULL 
)

Copy constructor

Parameters
constCFunction & src
constCCopasiContainer * pParent (default: NULL)

Definition at line 38 of file CFunction.cpp.

References CKeyFactory::add(), CEvaluationTree::compile(), CCopasiRootContainer::getKeyFactory(), CAnnotation::getMiriamAnnotation(), CAnnotation::mKey, and CAnnotation::setMiriamAnnotation().

39  :
40  CEvaluationTree(src, pParent),
41  CAnnotation(src),
42  mSBMLId(src.mSBMLId),
43  mVariables(src.mVariables, this),
46 {
47  mKey = CCopasiRootContainer::getKeyFactory()->add("Function", this);
48 
50  compile();
51 }
CFunctionParameters mVariables
Definition: CFunction.h:210
std::string mSBMLId
Definition: CFunction.h:203
void setMiriamAnnotation(const std::string &miriamAnnotation, const std::string &newId, const std::string &oldId)
const std::string & getMiriamAnnotation() const
std::string mKey
Definition: CAnnotation.h:119
TriLogic mReversible
Definition: CFunction.h:220
std::string add(const std::string &prefix, CCopasiObject *pObject)
static CKeyFactory * getKeyFactory()
CCallParameters< C_FLOAT64 >::const_iterator mCallParametersBegin
Definition: CFunction.h:215
virtual bool compile()
CEvaluationTree(const std::string &name="NoName", const CCopasiContainer *pParent=NULL, const Type &type=Function)
CFunction::~CFunction ( )
virtual

Destructor

Definition at line 53 of file CFunction.cpp.

References CCopasiRootContainer::getKeyFactory(), CAnnotation::mKey, and CKeyFactory::remove().

54 {
56 }
bool remove(const std::string &key)
std::string mKey
Definition: CAnnotation.h:119
static CKeyFactory * getKeyFactory()

Member Function Documentation

bool CFunction::addVariable ( const std::string &  name,
CFunctionParameter::Role  usage = CFunctionParameter::VARIABLE,
const CFunctionParameter::DataType type = CFunctionParameter::FLOAT64 
)

Function to add the description of a variable.

Parameters
conststring & name
conststring & usage (Default: VARIABLE)
constCFunctionParameters::DataType & type (Default: value)
Returns
bool success

Definition at line 154 of file CFunction.cpp.

References CFunctionParameters::add(), and mVariables.

Referenced by SBMLImporter::createCFunctionFromFunctionTree(), and CReaction::setFunctionFromExpressionTree().

157 {return mVariables.add(name, type, usage);}
CFunctionParameters mVariables
Definition: CFunction.h:210
void add(const CFunctionParameter &parameter)
const C_FLOAT64 & CFunction::calcValue ( const CCallParameters< C_FLOAT64 > &  callParameters)
virtual

Function to calculate the value of the function

Parameters
constCCallParameters<C_FLOAT64> & callParameters
Returns
const C_FLOAT64 & result

Reimplemented in CMassAction.

Definition at line 159 of file CFunction.cpp.

References CCallParameters< Type >::begin(), CEvaluationTree::calculate(), mCallParametersBegin, and CEvaluationTree::mValue.

Referenced by CEvaluationNodeCall::calculate(), CReaction::calculate(), CReaction::calculatePartialDerivative(), and main().

160 {
161  mCallParametersBegin = callParameters.begin();
162 
163  calculate();
164 
165  return mValue;
166 }
const_iterator begin() const
CCallParameters< C_FLOAT64 >::const_iterator mCallParametersBegin
Definition: CFunction.h:215
bool CFunction::completeFunctionList ( std::vector< CFunction * > &  list,
const size_t &  added = 0 
)
static

Complete the list of evaluation tree such that all called trees are includes.

Parameters
std::vector<CFunction * > & list
constsize_t & added (Default: list.size())
Returns
bool success

Definition at line 303 of file CFunction.cpp.

References C_INVALID_INDEX, CEvaluationNode::CALL, CCopasiRootContainer::getFunctionList(), CCopasiVectorN< CType >::getIndex(), CEvaluationTree::getNodeList(), and CFunctionDB::loadedFunctions().

Referenced by CFunctionDB::getUsedFunctions().

305 {
306  unsigned Added = 0;
307 
308  size_t i, imax = list.size();
309  size_t Index;
310 
311  CEvaluationTree * pTree;
312  std::vector< CEvaluationNode * >::const_iterator it;
313  std::vector< CEvaluationNode * >::const_iterator end;
314 
315  CCopasiVectorN< CFunction > & Functions =
317 
318  for (i = (added) ? imax - added : 0; i < imax; i++)
319  {
320  pTree = list[i];
321 
322  for (it = pTree->getNodeList().begin(), end = pTree->getNodeList().end(); it != end; ++it)
323  {
324  if (((*it)->getType() & 0xFF000000) == CEvaluationNode::CALL &&
325  (Index = Functions.getIndex((*it)->getData())) != C_INVALID_INDEX &&
326  list.end() == std::find(list.begin(), list.end(), Functions[Index]))
327  {
328  list.push_back(Functions[Index]);
329  Added++;
330  }
331  }
332  }
333 
334  if (Added)
335  return completeFunctionList(list, Added);
336  else
337  return true;
338 }
CCopasiVectorN< CFunction > & loadedFunctions()
static bool completeFunctionList(std::vector< CFunction * > &list, const size_t &added=0)
Definition: CFunction.cpp:303
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual size_t getIndex(const std::string &name) const
static CFunctionDB * getFunctionList()
const std::vector< CEvaluationNode * > & getNodeList() const
CFunction * CFunction::createCopy ( ) const

Function to duplicate itself

Definition at line 428 of file CFunction.cpp.

References CFunction(), CEvaluationNode::copyBranch(), CEvaluationTree::mpRoot, mReversible, and CEvaluationTree::setRoot().

429 {
430  CFunction* newFunction = new CFunction();
431 
432  //newFunction->mVariables = this->mVariables; //WRONG! only shallow copy!!
433  newFunction->mReversible = this->mReversible;
434 
435  if (this->mpRoot)
436  newFunction->setRoot(this->mpRoot->copyBranch());
437 
438  //newFunction->mInfix = newFunction->mpRoot->getInfix();
439 
440  return newFunction;
441 }
virtual bool setRoot(CEvaluationNode *pRootNode)
CEvaluationNode * copyBranch() const
TriLogic mReversible
Definition: CFunction.h:220
CFunction(const std::string &name="NoName", const CCopasiContainer *pParent=NULL, const Type &type=Function)
Definition: CFunction.cpp:25
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
CEvaluationNode * mpRoot
void CFunction::createListOfParametersForMathML ( std::vector< std::vector< std::string > > &  env)

Function to create a list of the names of the function parameters in MathML format. This list can be passed as the env argument to the writeMathML() method.

Parameters
std::vector<std::vector<std::string>> & env

Definition at line 340 of file CFunction.cpp.

References CMathMl::fixName(), CCopasiObject::getObjectName(), getVariables(), and CFunctionParameters::size().

Referenced by CQExpressionWidget::writeMathML().

341 {
342  size_t i, imax = getVariables().size();
343 
344  env.clear();
345  env.resize(imax);
346 
347  for (i = 0; i < imax; ++i)
348  {
349  env[i].push_back("<mi>" + CMathMl::fixName(getVariables()[i]->getObjectName()) + "</mi>");
350  }
351 }
const std::string & getObjectName() const
static std::string fixName(const std::string &name)
Definition: copasimathml.h:33
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
bool CFunction::dependsOn ( const C_FLOAT64 parameter,
const CCallParameters< C_FLOAT64 > &  callParameters 
) const
virtual

Function to return whether it depends on the given parameter

Parameters
constvoid * parameter
constCCallParameters<C_FLOAT64> & callParameters
booldependsOn

Reimplemented in CMassAction.

Definition at line 168 of file CFunction.cpp.

References CCallParameters< Type >::begin(), and CCallParameters< Type >::end().

Referenced by CReaction::calculatePartialDerivative().

170 {
172  CCallParameters<C_FLOAT64>::const_iterator end = callParameters.end();
173 
174  while (it != end && parameter != it->value) it++;
175 
176  if (it != end)
177  return true;
178  else
179  return false;
180 }
const_iterator begin() const
const_iterator end() const
const std::string & CFunction::getKey ( ) const
virtual
const std::string & CFunction::getSBMLId ( ) const
size_t CFunction::getVariableIndex ( const std::string &  name) const
virtual

Function to retrieve the index to the value of the named variable.

Parameters
conststd::string & name
Returns
size_t index

Reimplemented from CEvaluationTree.

Definition at line 133 of file CFunction.cpp.

References CFunctionParameters::findParameterByName(), and mVariables.

Referenced by CODEExporter::exportKineticFunction(), and CODEExporter::exportSingleFunction().

134 {
135  CFunctionParameter::DataType VariableType;
136  return mVariables.findParameterByName(name, VariableType);
137 }
CFunctionParameters mVariables
Definition: CFunction.h:210
size_t findParameterByName(const std::string &name, CFunctionParameter::DataType &dataType) const
CFunctionParameters & CFunction::getVariables ( )

Function to retrive the definition of the parameters

Returns
CFunctionParameters & variables

Definition at line 148 of file CFunction.cpp.

References mVariables.

Referenced by SBMLImporter::areEqualFunctions(), CFunctionAnalyzer::checkKineticFunction(), CEvaluationNodeCall::compile(), FunctionWidget1::copyFunctionContentsToFunction(), SBMLImporter::createCReactionFromReaction(), SBMLImporter::createExpressionFromFunction(), CSBMLExporter::createKineticExpression(), createListOfParametersForMathML(), CKinFunction::createParameters(), SBMLImporter::doMapping(), CCopasiXMLParser::ListOfParameterDescriptionsElement::end(), CCopasiXMLParser::FunctionElement::end(), CFunctionAnalyzer::evaluateNode(), expand_function_call(), CODEExporter::exportKineticFunction(), CODEExporterC::exportSingleFunction(), SBMLImporter::findCorrespondingFunction(), CFindDimensions::findDimensions(), FunctionWidget1::functionParametersChanged(), CReactionInterface::getDeletedParameters(), CReactionInterface::initFromReaction(), CReactionInterface::initMapping(), FunctionWidget1::loadParameterTable(), FunctionWidget1::loadUsageTable(), CCopasiXML::saveFunctionList(), SBMLImporter::setCorrectUsage(), CReaction::setFunction(), CReaction::setFunctionFromExpressionTree(), CMassAction::setInfix(), CFindDimensions::setupDimensions(), FunctionWidget1::slotTableValueChanged(), splitFunction(), CCopasiXMLParser::ParameterDescriptionElement::start(), test_compare_utilities::test_copasi_function_expansion(), test000078::test_l2v4_import_unordered_functions(), CReaction::variable2object(), CReactionInterface::writeBackToReaction(), and writeMathML().

149 {return mVariables;}
CFunctionParameters mVariables
Definition: CFunction.h:210
const CFunctionParameters & CFunction::getVariables ( ) const

Function to retrive the definition of the parameters

Returns
const CFunctionParameters & variables

Definition at line 151 of file CFunction.cpp.

References mVariables.

152 {return mVariables;}
CFunctionParameters mVariables
Definition: CFunction.h:210
const C_FLOAT64 & CFunction::getVariableValue ( const size_t &  index) const
virtual

Function to retrieve the value of the indexed variable.

Note this function is only usable during calcValue, since the values of the call parameters are only defined during that time.

Parameters
constsize_t & index
Returns
const C_FLOAT64 & variableValue

Reimplemented from CEvaluationTree.

Definition at line 139 of file CFunction.cpp.

References mCallParametersBegin.

140 {return *(mCallParametersBegin + index)->value;}
CCallParameters< C_FLOAT64 >::const_iterator mCallParametersBegin
Definition: CFunction.h:215
bool CFunction::initVariables ( )
protected

Function to initialize the parameters

Returns
bool success

Definition at line 219 of file CFunction.cpp.

References CFunctionParameters::add(), C_INVALID_INDEX, CFunctionParameters::findParameterByName(), CFunctionParameter::FLOAT64, CCopasiObject::getObjectName(), CEvaluationTree::mInfix, CEvaluationTree::mpNodeList, mVariables, CFunctionParameters::remove(), CFunctionParameters::size(), CEvaluationNode::type(), CEvaluationNode::VARIABLE, and CFunctionParameter::VARIABLE.

Referenced by setInfix(), and splitFunction().

220 {
221  if (mpNodeList == NULL && mInfix != "") return false;
222 
223  CFunctionParameters NewVariables;
224 
225  if (mInfix != "")
226  {
227  //first add all variables to the existing list
228  std::vector< CEvaluationNode * >::iterator it = mpNodeList->begin();
229  std::vector< CEvaluationNode * >::iterator end = mpNodeList->end();
230 
231  for (; it != end; ++it)
232  if (CEvaluationNode::type((*it)->getType()) == CEvaluationNode::VARIABLE)
233  {
234  mVariables.add((*it)->getData(),
237  NewVariables.add((*it)->getData(),
240  }
241  }
242 
243  //now remove all variables that are not in the tree anymore
245  size_t i;
246 
247  for (i = mVariables.size() - 1; i != C_INVALID_INDEX; i--)
250 
251  return true;
252 }
CFunctionParameters mVariables
Definition: CFunction.h:210
std::vector< CEvaluationNode * > * mpNodeList
const std::string & getObjectName() const
size_t findParameterByName(const std::string &name, CFunctionParameter::DataType &dataType) const
#define C_INVALID_INDEX
Definition: copasi.h:222
std::string mInfix
static Type type(const Type &type)
void add(const CFunctionParameter &parameter)
void remove(const std::string &name)
const TriLogic & CFunction::isReversible ( ) const
bool CFunction::isSuitable ( const size_t  noSubstrates,
const size_t  noProducts,
const TriLogic  reversible 
)

Function to determine whether it is suitable for a reaction with the given number of substrates and products and reversibility

Definition at line 254 of file CFunction.cpp.

References C_INVALID_INDEX, CFunctionParameters::getNumberOfParametersByUsage(), isReversible(), CFunctionParameters::isVector(), mVariables, CFunctionParameter::PRODUCT, CFunctionParameter::SUBSTRATE, TriTrue, TriUnspecified, and CFunctionParameter::VARIABLE.

Referenced by SBMLImporter::createCReactionFromReaction(), and CFunctionDB::suitableFunctions().

257 {
258  // A function which in neither restricted to reversible nor to irreversible reactions is always suitable
259  // independent from the number of substrates or products
260  if (isReversible() == TriUnspecified)
261  return true;
262 
263  //first reversibility:
264  if (reversible != isReversible())
265  return false;
266 
267  //check substrates
269  {
270  if (noSubstrates == 0 || noSubstrates == C_INVALID_INDEX)
271  return false;
272  }
273  else //is no vector
274  {
276  noSubstrates != C_INVALID_INDEX)
277  return false;
278  }
279 
280  //check products
281  if (reversible == TriTrue)
282  {
284  {
285  if (noProducts == 0 || noProducts == C_INVALID_INDEX)
286  return false;
287  }
288  else //is no vector
289  {
291  noProducts != C_INVALID_INDEX)
292  return false;
293  }
294  }
295 
296  //no VARIABLE variables allowed for kinetic functions
298  return false;
299 
300  return true;
301 }
CFunctionParameters mVariables
Definition: CFunction.h:210
bool isVector(CFunctionParameter::Role role) const
size_t getNumberOfParametersByUsage(CFunctionParameter::Role usage) const
#define C_INVALID_INDEX
Definition: copasi.h:222
const TriLogic & isReversible() const
Definition: CFunction.cpp:145
void CFunction::load ( CReadConfig configBuffer,
CReadConfig::Mode  mode = CReadConfig::SEARCH 
)
virtual

Function to load an object with data coming from a CReadConfig object. (CReadConfig object reads an input stream)

Parameters
CReadConfig &configBuffer
CReadConfig::Modemode (default: CReadConfig::SEARCH)
Returns
Fail

Definition at line 182 of file CFunction.cpp.

References C_INT32, fatalError, CReadConfig::getVariable(), mReversible, CReadConfig::SEARCH, setInfix(), CCopasiObject::setObjectName(), CEvaluationTree::setType(), and CEvaluationTree::UserDefined.

Referenced by CFunctionDB::load().

184 {
185  // cleanup();
186 
187  C_INT32 Type;
188 
189  mode = CReadConfig::SEARCH;
190  configBuffer.getVariable("User-defined", "C_INT32", &Type, mode);
191 
192  switch (Type)
193  {
194  case 1:
196  break;
197 
198  default:
199  fatalError();
200  break;
201  }
202 
203  configBuffer.getVariable("Reversible", "C_INT32", &mReversible);
204 
205  mode = CReadConfig::SEARCH;
206 
207  std::string tmp;
208  configBuffer.getVariable("FunctionName", "string", &tmp, mode);
209  setObjectName(tmp);
210 
211  configBuffer.getVariable("Description", "string", &tmp);
212  setInfix(tmp);
213 
214  // For older file version the parameters have to be build from information
215  // dependend on the function type. Luckilly, only user defined functions are
216  // the only ones occuring in those files.
217 }
void setType(const CEvaluationTree::Type &type)
#define fatalError()
#define C_INT32
Definition: copasi.h:90
virtual bool setInfix(const std::string &infix)
Definition: CFunction.cpp:73
TriLogic mReversible
Definition: CFunction.h:220
C_INT32 getVariable(const std::string &name, const std::string &type, void *pout, CReadConfig::Mode mode=CReadConfig::NEXT)
Definition: CReadConfig.cpp:81
bool setObjectName(const std::string &name)
bool CFunction::operator== ( const CFunction rhs) const

Comparison operator

Parameters
constCFunction & rhs
Returns
bool equal

Definition at line 119 of file CFunction.cpp.

References mVariables.

120 {
121  if (!(*static_cast< const CEvaluationTree * >(this) == rhs))
122  return false;
123 
124  if (!(*static_cast< const CAnnotation * >(this) == rhs))
125  return false;
126 
127  if (!(mVariables == rhs.mVariables))
128  return false;
129 
130  return true;
131 }
CFunctionParameters mVariables
Definition: CFunction.h:210
bool CFunction::setInfix ( const std::string &  infix)
virtual
bool CFunction::setInfix ( const std::string &  infix,
bool  compile 
)
virtual

Function to set the infix description of the tree and (optionally) compile it.

Parameters
conststd::string & infix
boolcompile, boolean indicating whether the expression ought to be compiled
Returns
bool success

Definition at line 78 of file CFunction.cpp.

References CEvaluationNode::CALL, CEvaluationTree::compileNodes(), CEvaluationNode::DELAY, CEvaluationNodeCall::EXPRESSION, initVariables(), CEvaluationTree::mpNodeList, CEvaluationNode::OBJECT, CEvaluationTree::setInfix(), CEvaluationNode::subType(), and CEvaluationNode::type().

79 {
80  if (!CEvaluationTree::setInfix(infix)) return false;
81 
82  if (mpNodeList == NULL) return true;
83 
84  // We need to check that the function does not contain any objects, calls to expression
85  // or delay nodes.
86  std::vector< CEvaluationNode * >::const_iterator it = mpNodeList->begin();
87  std::vector< CEvaluationNode * >::const_iterator end = mpNodeList->end();
88 
89  for (; it != end; ++it)
90  {
91  switch (CEvaluationNode::type((*it)->getType()))
92  {
95  return false;
96  break;
97 
99 
101  {
102  return false;
103  }
104 
105  break;
106 
107  default:
108  break;
109  }
110  }
111 
112  if (!initVariables()) return false;
113 
114  if (compile) compileNodes();
115 
116  return true;
117 }
std::vector< CEvaluationNode * > * mpNodeList
bool initVariables()
Definition: CFunction.cpp:219
static Type type(const Type &type)
static Type subType(const Type &type)
virtual bool compile()
virtual bool setInfix(const std::string &infix)
void CFunction::setReversible ( const TriLogic reversible)
void CFunction::setSBMLId ( const std::string &  id)
std::pair< CFunction *, CFunction * > CFunction::splitFunction ( const CEvaluationNode node,
const std::string &  name1,
const std::string &  name2 
) const

Function to split

Parameters
constCEvaluationNode* node
conststd::string & name1
conststd::string & name2

Definition at line 445 of file CFunction.cpp.

References CFunction(), CEvaluationTree::compile(), CFunctionAnalyzer::constructCallParameters(), CEvaluationNode::findTopMinus(), getVariables(), initVariables(), CFunctionParameter::MODIFIER, CEvaluationTree::mpRoot, mReversible, mVariables, CFunctionParameter::PRODUCT, CCopasiObject::setObjectName(), CEvaluationTree::setRoot(), CFunctionParameters::size(), CEvaluationNode::splitBranch(), CFunctionParameter::SUBSTRATE, TriFalse, and TriTrue.

Referenced by CFunctionAnalyzer::checkKineticFunction(), and CModel::convert2NonReversible().

448 {
449  if (!this->mpRoot) return std::pair<CFunction *, CFunction *>((CFunction*)NULL, (CFunction*)NULL);
450 
451  if (this->mReversible != TriTrue) return std::pair<CFunction *, CFunction *>((CFunction*)NULL, (CFunction*)NULL);
452 
453  //create 2 new functions
454  CFunction* newFunction1 = new CFunction();
455  newFunction1->setObjectName(name1);
456 
457  CFunction* newFunction2 = new CFunction();
458  newFunction2->setObjectName(name2);
459 
460  //when searching for a split point we need to analyze subtrees. For
461  //doing this a representation of the call parameters in the format
462  //used by CFunctionAnalyzer is needed.
463  std::vector<CFunctionAnalyzer::CValue> callParameters;
464  CFunctionAnalyzer::constructCallParameters(this->getVariables(), callParameters, true);
465  // find the split point
466  const CEvaluationNode* splitnode = this->mpRoot->findTopMinus(callParameters);
467 
468  if (!splitnode) return std::pair<CFunction *, CFunction *>((CFunction*)NULL, (CFunction*)NULL);
469 
470  //create the 2 split trees
471  CEvaluationNode* tmpRoots1 = this->mpRoot->splitBranch(splitnode, true); //left side
472  CEvaluationNode* tmpRoots2 = this->mpRoot->splitBranch(splitnode, false); //right side
473 
474  if (tmpRoots1)
475  newFunction1->setRoot(tmpRoots1);
476 
477  if (tmpRoots2)
478  newFunction2->setRoot(tmpRoots2);
479 
480  newFunction1->mVariables = this->mVariables; //copy the parameter list
481  newFunction1->initVariables(); //remove unused parameters
482  newFunction1->mReversible = TriFalse;
483 
484  newFunction2->mVariables = this->mVariables; //copy the parameter list
485  newFunction2->initVariables(); //remove unused parameters
486  newFunction2->mReversible = TriFalse;
487 
488  //update the roles
489  size_t i, imax;
490 
491  imax = newFunction1->mVariables.size();
492 
493  for (i = 0; i < imax; ++i)
494  {
495  if (newFunction1->mVariables[i]->getUsage() == CFunctionParameter::PRODUCT)
496  newFunction1->mVariables[i]->setUsage(CFunctionParameter::MODIFIER);
497  }
498 
499  imax = newFunction2->mVariables.size();
500 
501  for (i = 0; i < imax; ++i)
502  {
503  if (newFunction2->mVariables[i]->getUsage() == CFunctionParameter::PRODUCT)
504  newFunction2->mVariables[i]->setUsage(CFunctionParameter::SUBSTRATE);
505  else if (newFunction2->mVariables[i]->getUsage() == CFunctionParameter::SUBSTRATE)
506  newFunction2->mVariables[i]->setUsage(CFunctionParameter::MODIFIER);
507  }
508 
509  newFunction1->compile();
510  newFunction2->compile();
511  return std::pair<CFunction *, CFunction *>(newFunction1, newFunction2);
512 }
virtual bool setRoot(CEvaluationNode *pRootNode)
CFunctionParameters mVariables
Definition: CFunction.h:210
bool initVariables()
Definition: CFunction.cpp:219
TriLogic mReversible
Definition: CFunction.h:220
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
if(!yymsg) yymsg
bool setObjectName(const std::string &name)
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
CEvaluationNode * mpRoot
void CFunction::writeMathML ( std::ostream &  out,
size_t  l = 0 
) const
virtual

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Parameters
std::ostream& out
size_tl

Definition at line 389 of file CFunction.cpp.

References CMathMl::fixName(), CCopasiObject::getObjectName(), getVariables(), CFunctionParameters::size(), and SPC.

Referenced by CEvaluationNodeCall::getMMLString(), CQExpressionWidget::writeMathML(), and CMMLOutput::writeRHS().

390 {
391  //out << "<math>" << std::endl;
392 
393  out << SPC(l) << "<mrow>" << std::endl;
394  out << SPC(l + 1) << CMathMl::fixName(getObjectName()) << std::endl;
395  out << SPC(l + 1) << "<mfenced>" << std::endl;
396 
397  size_t i, imax = getVariables().size();
398 
399  for (i = 0; i < imax; ++i)
400  {
401  out << SPC(l + 2) << "<mi>" << CMathMl::fixName(getVariables()[i]->getObjectName()) << "</mi>" << std::endl;
402  }
403 
404  out << SPC(l + 1) << "</mfenced>" << std::endl;
405  out << SPC(l) << "</mrow>" << std::endl;
406 
407  //out << "</math>" << std::endl;
408 }
const std::string & getObjectName() const
static std::string fixName(const std::string &name)
Definition: copasimathml.h:33
#define SPC(level)
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
std::string CFunction::writeMathML ( const std::vector< std::vector< std::string > > &  variables,
bool  expand = true,
bool  fullExpand = true 
) const
virtual

Function to write the mathematical formula in format of MathML.

Parameters
std::ostream& out
conststd::vector< std::vector< std::string > > & variables
boolexpand = true
boolfullExpand
Returns
std::string

Reimplemented in CMassAction.

Definition at line 354 of file CFunction.cpp.

References CEvaluationNode::buildMMLString(), CMathMl::fixName(), CCopasiObject::getObjectName(), and CEvaluationTree::mpRoot.

356 {
357  std::ostringstream out;
358 
359  if (expand && mpRoot)
360  {
361  bool flag = false; //TODO include check if parentheses are necessary
362 
363  if (flag) out << "<mfenced>" << std::endl;
364 
365  out << mpRoot->buildMMLString(fullExpand, variables);
366 
367  if (flag) out << "</mfenced>" << std::endl;
368  }
369  else //no expand
370  {
371  out << "<mrow>" << std::endl;
372  out << CMathMl::fixName(getObjectName()) << std::endl;
373  out << "<mfenced>" << std::endl;
374 
375  size_t i, imax = variables.size();
376 
377  for (i = 0; i < imax; ++i)
378  {
379  out << variables[i][0] << std::endl;
380  }
381 
382  out << "</mfenced>" << std::endl;
383  out << "</mrow>" << std::endl;
384  }
385 
386  return out.str();
387 }
const std::string & getObjectName() const
static std::string fixName(const std::string &name)
Definition: copasimathml.h:33
long int flag
Definition: f2c.h:52
std::string buildMMLString(bool expand, const std::vector< std::vector< std::string > > &variables) const
CEvaluationNode * mpRoot

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const CFunction f 
)
friend

Insert operator

Definition at line 410 of file CFunction.cpp.

411 {
412  os << "CFunction: " << f.getObjectName() << " ";
413 
414  if (f.mReversible == TriUnspecified)
415  os << "(general)";
416  else if (f.mReversible == TriFalse)
417  os << "(irreversible)";
418  else
419  os << "(reversible)";
420 
421  os << std::endl;
422  os << f.mVariables;
423  os << f.getInfix() << std::endl;
424 
425  return os;
426 }
CFunctionParameters mVariables
Definition: CFunction.h:210
const std::string & getObjectName() const
TriLogic mReversible
Definition: CFunction.h:220
const std::string & getInfix() const

Member Data Documentation

CCallParameters< C_FLOAT64 >::const_iterator CFunction::mCallParametersBegin
private

A pointer to the call parameters during calculation.

Definition at line 215 of file CFunction.h.

Referenced by calcValue(), and getVariableValue().

TriLogic CFunction::mReversible
private

Whether the function is reversible

Definition at line 220 of file CFunction.h.

Referenced by createCopy(), isReversible(), load(), operator<<(), setReversible(), and splitFunction().

std::string CFunction::mSBMLId
private

The id of the corresponding function in an SBML file. This value is either set upon importing an SBML file, or when the object is first exported to an SBML file.

Definition at line 203 of file CFunction.h.

Referenced by getSBMLId(), and setSBMLId().

CFunctionParameters CFunction::mVariables
private

The description of the variables of the function. It describes which variables need to be passed to the function for evaluation and its eventual type.

Definition at line 210 of file CFunction.h.

Referenced by addVariable(), getVariableIndex(), getVariables(), initVariables(), isSuitable(), operator<<(), operator==(), and splitFunction().


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