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

#include <CMathDependencyNode.h>

Collaboration diagram for CMathDependencyNode:
Collaboration graph
[legend]

Public Member Functions

void addDependent (CMathDependencyNode *pNode)
 
void addPrerequisite (CMathDependencyNode *pNode)
 
bool buildUpdateSequence (const CMath::SimulationContextFlag &context, CObjectInterface::UpdateSequence &updateSequence)
 
 CMathDependencyNode (const CObjectInterface *pObject)
 
std::vector
< CMathDependencyNode * > & 
getDependents ()
 
const CObjectInterfacegetObject () const
 
std::vector
< CMathDependencyNode * > & 
getPrerequisites ()
 
const bool & isChanged () const
 
const bool & isRequested () const
 
void setChanged (const bool &changed)
 
void setRequested (const bool &requested)
 
bool updateDependentState (const CMath::SimulationContextFlag &context, const CObjectInterface::ObjectSet &changedObjects)
 
bool updatePrerequisiteState (const CMath::SimulationContextFlag &context, const CObjectInterface::ObjectSet &changedObjects)
 
 ~CMathDependencyNode (void)
 

Private Member Functions

 CMathDependencyNode (void)
 

Private Attributes

bool mChanged
 
std::vector
< CMathDependencyNode * > 
mDependents
 
const CObjectInterfacempObject
 
std::vector
< CMathDependencyNode * > 
mPrerequisites
 
bool mRequested
 

Detailed Description

Definition at line 15 of file CMathDependencyNode.h.

Constructor & Destructor Documentation

CMathDependencyNode::CMathDependencyNode ( void  )
private

Definition at line 14 of file CMathDependencyNode.cpp.

14  :
15  mpObject(NULL),
17  mDependents(),
18  mChanged(false),
19  mRequested(false)
20 {}
const CObjectInterface * mpObject
std::vector< CMathDependencyNode * > mDependents
std::vector< CMathDependencyNode * > mPrerequisites
CMathDependencyNode::CMathDependencyNode ( const CObjectInterface pObject)

Specific constructor

Parameters
constCObjectInterface * pObject

Definition at line 22 of file CMathDependencyNode.cpp.

22  :
23  mpObject(pObject),
25  mDependents(),
26  mChanged(false),
27  mRequested(false)
28 {}
const CObjectInterface * mpObject
std::vector< CMathDependencyNode * > mDependents
std::vector< CMathDependencyNode * > mPrerequisites
CMathDependencyNode::~CMathDependencyNode ( void  )

Destructor

Definition at line 30 of file CMathDependencyNode.cpp.

31 {}

Member Function Documentation

void CMathDependencyNode::addDependent ( CMathDependencyNode pNode)

Add a dependent

Parameters
CMathDependencyNode* pNode

Definition at line 48 of file CMathDependencyNode.cpp.

References mDependents.

49 {
50  mDependents.push_back(pObject);
51 }
std::vector< CMathDependencyNode * > mDependents
void CMathDependencyNode::addPrerequisite ( CMathDependencyNode pNode)

Add a prerequisite

Parameters
CMathDependencyNode* pNode

Definition at line 38 of file CMathDependencyNode.cpp.

References mPrerequisites.

39 {
40  mPrerequisites.push_back(pObject);
41 }
std::vector< CMathDependencyNode * > mPrerequisites
bool CMathDependencyNode::buildUpdateSequence ( const CMath::SimulationContextFlag context,
CObjectInterface::UpdateSequence updateSequence 
)

Build the sequence of objects which need to be updated to calculate the object value.

Parameters
constCMath::SimulationContextFlag & context
CObjectInterface::UpdateSequence& updateSequence
Returns
bool success

Definition at line 142 of file CMathDependencyNode.cpp.

References CMathDependencyNodeIterator::After, CMathDependencyNodeIterator::Before, CMath::Dependent, CMathDependencyNodeIterator::End, getObject(), CCopasiObject::getObjectParent(), CMathObject::getSimulationType(), CMathObject::getValueType(), isChanged(), isRequested(), mChanged, mRequested, CMathDependencyNodeIterator::next(), CMathDependencyNodeIterator::Prerequisites, setChanged(), CMathDependencyNodeIterator::setProcessingModes(), CMathDependencyNodeIterator::skipChildren(), CMathDependencyNodeIterator::state(), CMath::UseMoieties, and CMath::Value.

144 {
145  if (!mChanged || !mRequested)
146  return true;
147 
150 
151  while (itNode.next())
152  {
153  switch (itNode.state())
154  {
156 
157  if (!itNode->isChanged() || !itNode->isRequested())
158  {
159  itNode.skipChildren();
160  }
161 
162  break;
163 
165 
166  // This check is not needed as unchanged or unrequested nodes
167  // are skipped in Before processing.
168  if (itNode->isChanged() && itNode->isRequested())
169  {
170  const CObjectInterface * pObject = itNode->getObject();
171  const CMathObject * pMathObject = NULL;
172  const CParticleReference * pParticleNumber = NULL;
173 
174  // For an extensive transient value of a dependent species we have 2
175  // possible assignments depending on the context.
176  // 1) Conversion from the intensive property
177  // 2) Dependent mass off a moiety
178  //
179  // The solution is that the moiety automatically updates the value in conjunction
180  // with the dependency graph omitting the value in the update sequence if the context
181  // is CMath::UseMoieties.
182 
183  if (!(context & CMath::UseMoieties) ||
184  ((pMathObject = dynamic_cast< const CMathObject *>(pObject)) == NULL &&
185  (pParticleNumber = dynamic_cast< const CParticleReference *>(pObject)) == NULL) ||
186  (pMathObject != NULL &&
187  (pMathObject->getSimulationType() != CMath::Dependent ||
188  pMathObject->getValueType() != CMath::Value)) ||
189  (pParticleNumber != NULL &&
190  !static_cast< const CMetab * >(pParticleNumber->getObjectParent())->isDependent()))
191  {
192  updateSequence.push_back(const_cast< CObjectInterface * >(itNode->getObject()));
193  itNode->setChanged(false);
194  }
195  }
196 
197  break;
198 
199  default:
200  break;
201  }
202  }
203 
204  mChanged = false;
205 
206  return itNode.state() == CMathDependencyNodeIterator::End;
207 }
const CMath::SimulationType & getSimulationType() const
Definition: CMetab.h:178
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const =0
const CMath::ValueType & getValueType() const
CCopasiContainer * getObjectParent() const
std::vector< CMathDependencyNode * > & CMathDependencyNode::getDependents ( )

Retrieve the dependents

Returns
std::vector< CMathDependencyNode * > dependents

Definition at line 53 of file CMathDependencyNode.cpp.

References mDependents.

Referenced by CMathDependencyNodeIterator::CStackElement::CStackElement().

54 {
55  return mDependents;
56 }
std::vector< CMathDependencyNode * > mDependents
const CObjectInterface * CMathDependencyNode::getObject ( ) const

Retrieve a pointer to the object the node is representing

Returns
const CObjectInterface * pObject

Definition at line 33 of file CMathDependencyNode.cpp.

References mpObject.

Referenced by buildUpdateSequence(), updateDependentState(), and updatePrerequisiteState().

34 {
35  return mpObject;
36 }
const CObjectInterface * mpObject
std::vector< CMathDependencyNode * > & CMathDependencyNode::getPrerequisites ( )

Retrieve the prerequisites

Returns
std::vector< CMathDependencyNode * > prerequisites

Definition at line 43 of file CMathDependencyNode.cpp.

References mPrerequisites.

Referenced by CMathDependencyNodeIterator::CStackElement::CStackElement().

44 {
45  return mPrerequisites;
46 }
std::vector< CMathDependencyNode * > mPrerequisites
const bool & CMathDependencyNode::isChanged ( ) const

Check whether the current nodes value is changed

Returns
const bool & isChanged

Definition at line 214 of file CMathDependencyNode.cpp.

References mChanged.

Referenced by buildUpdateSequence(), and updateDependentState().

215 {
216  return mChanged;
217 }
const bool & CMathDependencyNode::isRequested ( ) const

Check whether the current node's value is requested

Parameters
constbool & isRequested

Definition at line 224 of file CMathDependencyNode.cpp.

References mRequested.

Referenced by buildUpdateSequence(), and updatePrerequisiteState().

225 {
226  return mRequested;
227 }
void CMathDependencyNode::setChanged ( const bool &  changed)

Set whether the current node has changed its value

Parameters
constbool & changed

Definition at line 209 of file CMathDependencyNode.cpp.

References mChanged.

Referenced by buildUpdateSequence(), and updateDependentState().

210 {
211  mChanged = changed;
212 }
void CMathDependencyNode::setRequested ( const bool &  requested)

Set whether the current node's value is requested

Parameters
constbool & requested

Definition at line 219 of file CMathDependencyNode.cpp.

References mRequested.

Referenced by updatePrerequisiteState().

220 {
221  mRequested = requested;
222 }
bool CMathDependencyNode::updateDependentState ( const CMath::SimulationContextFlag context,
const CObjectInterface::ObjectSet changedObjects 
)

Update the state of all dependents (and dependents thereof) to changed,

Parameters
constCMath::SimulationContextFlag & context
constCObjectInterface::ObjectSet & changedObjects
Returns
bool success

Definition at line 58 of file CMathDependencyNode.cpp.

References CMathDependencyNodeIterator::Before, CMathDependencyNodeIterator::Dependents, CMathDependencyNodeIterator::End, getObject(), isChanged(), CObjectInterface::isPrerequisiteForContext(), CMathDependencyNodeIterator::next(), CMathDependencyNodeIterator::parent(), CMathDependencyNodeIterator::Recursive, setChanged(), CMathDependencyNodeIterator::setProcessingModes(), CMathDependencyNodeIterator::skipChildren(), and CMathDependencyNodeIterator::state().

60 {
62  itNode.setProcessingModes(CMathDependencyNodeIterator::Before);
63 
64  while (itNode.next())
65  {
66  // If we have a recursive dependency we need make sure that this is due to
67  // an intensive/extensive value pair
68  if (itNode.state() == CMathDependencyNodeIterator::Recursive)
69  {
70  if (itNode->getObject()->isPrerequisiteForContext(itNode.parent()->getObject(), context, changedObjects))
71  {
72  return false;
73  }
74 
75  continue;
76  }
77 
78  // The node itself is not modified.
79  if (*itNode == this)
80  {
81  continue;
82  }
83 
84  // We are guaranteed that the current node has a parent as the only node without is this,
85  // which is handled above.
86  if (!itNode->isChanged() &&
87  itNode->getObject()->isPrerequisiteForContext(itNode.parent()->getObject(), context, changedObjects))
88  {
89  itNode->setChanged(true);
90  }
91  else
92  {
93  itNode.skipChildren();
94  }
95  }
96 
97  return itNode.state() == CMathDependencyNodeIterator::End;
98 }
bool CMathDependencyNode::updatePrerequisiteState ( const CMath::SimulationContextFlag context,
const CObjectInterface::ObjectSet changedObjects 
)

Update the state of all prerequisites (and prerequisites thereof) to requested.

Parameters
constCMath::SimulationContextFlag & context
constCObjectInterface::ObjectSet & changedObjects
Returns
bool success

Definition at line 100 of file CMathDependencyNode.cpp.

References CMathDependencyNodeIterator::Before, CMathDependencyNodeIterator::End, getObject(), CObjectInterface::isPrerequisiteForContext(), isRequested(), CMathDependencyNodeIterator::next(), CMathDependencyNodeIterator::parent(), CMathDependencyNodeIterator::Prerequisites, CMathDependencyNodeIterator::Recursive, CMathDependencyNodeIterator::setProcessingModes(), setRequested(), CMathDependencyNodeIterator::skipChildren(), and CMathDependencyNodeIterator::state().

102 {
104  itNode.setProcessingModes(CMathDependencyNodeIterator::Before);
105 
106  while (itNode.next())
107  {
108  // If we have a recursive dependency we need make sure that this is due to
109  // an intensive/extensive value pair
110  if (itNode.state() == CMathDependencyNodeIterator::Recursive)
111  {
112  if (itNode.parent()->getObject()->isPrerequisiteForContext(itNode->getObject(), context, changedObjects))
113  {
114  return false;
115  }
116 
117  continue;
118  }
119 
120  // The node itself is not modified.
121  if (*itNode == this)
122  {
123  continue;
124  }
125 
126  // We are guaranteed that the current node has a parent as the only node without is this,
127  // which is handled above.
128  if (!itNode->isRequested() &&
129  itNode.parent()->getObject()->isPrerequisiteForContext(itNode->getObject(), context, changedObjects))
130  {
131  itNode->setRequested(true);
132  }
133  else
134  {
135  itNode.skipChildren();
136  }
137  }
138 
139  return itNode.state() == CMathDependencyNodeIterator::End;
140 }

Member Data Documentation

bool CMathDependencyNode::mChanged
private

Definition at line 119 of file CMathDependencyNode.h.

Referenced by buildUpdateSequence(), isChanged(), and setChanged().

std::vector< CMathDependencyNode * > CMathDependencyNode::mDependents
private

Definition at line 118 of file CMathDependencyNode.h.

Referenced by addDependent(), and getDependents().

const CObjectInterface* CMathDependencyNode::mpObject
private

Definition at line 116 of file CMathDependencyNode.h.

Referenced by getObject().

std::vector< CMathDependencyNode * > CMathDependencyNode::mPrerequisites
private

Definition at line 117 of file CMathDependencyNode.h.

Referenced by addPrerequisite(), and getPrerequisites().

bool CMathDependencyNode::mRequested
private

Definition at line 120 of file CMathDependencyNode.h.

Referenced by buildUpdateSequence(), isRequested(), and setRequested().


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