Esempio n. 1
0
// virtual
bool CEvent::mustBeDeleted(const CCopasiObject::DataObjectSet & deletedObjects) const
{
  bool MustBeDeleted = false;

  CCopasiObject::DataObjectSet ChildObjects;

  if (mpTriggerExpression != NULL)
    {
      ChildObjects.insert(mpTriggerExpression);
    }

  if (mpDelayExpression != NULL)
    {
      ChildObjects.insert(mpDelayExpression);
    }

  if (mpPriorityExpression != NULL)
    {
      ChildObjects.insert(mpPriorityExpression);
    }

  // We need to add all assignment targets and expressions
  CCopasiVector< CEventAssignment >::const_iterator itAssignment = mAssignments.begin();
  CCopasiVector< CEventAssignment >::const_iterator endAssignment = mAssignments.end();

  for (; itAssignment != endAssignment; ++itAssignment)
    {
      if (itAssignment->getTargetObject() != NULL)
        {
          ChildObjects.insert(itAssignment->getTargetObject());
        }

      if (itAssignment->getExpressionPtr() != NULL)
        {
          ChildObjects.insert(itAssignment->getExpressionPtr());
        }
    }

  DataObjectSet::const_iterator it = ChildObjects.begin();
  DataObjectSet::const_iterator end = ChildObjects.end();

  for (; it != end; ++it)
    {
      if ((*it)->mustBeDeleted(deletedObjects))
        {
          MustBeDeleted = true;
          break;
        }
    }

  return MustBeDeleted;
}
Esempio n. 2
0
// virtual
bool CCopasiObject::mustBeDeleted(const CCopasiObject::DataObjectSet & deletedObjects) const
{
  bool MustBeDeleted = false;

  DataObjectSet::const_iterator it = mDependencies.begin();
  DataObjectSet::const_iterator end = mDependencies.end();

  for (; it != end; ++it)
    {
      if (deletedObjects.find(*it) != deletedObjects.end())
        {
          MustBeDeleted = true;
          break;
        }
    }

  return MustBeDeleted;
}
Esempio n. 3
0
//static
std::vector< Refresh * >
CCopasiObject::buildUpdateSequence(const CCopasiObject::DataObjectSet & objects,
                                   const CCopasiObject::DataObjectSet & uptoDateObjects,
                                   const CCopasiObject::DataObjectSet & context)
{
  CCopasiObject::DataObjectSet DependencySet;
  CCopasiObject::DataObjectSet VerifiedSet;

  CCopasiObject::DataObjectSet::const_iterator itSet;
  CCopasiObject::DataObjectSet::const_iterator endSet = objects.end();
  std::pair<CCopasiObject::DataObjectSet::iterator, bool> InsertedObject;

  assert(objects.count(NULL) == 0);

  // Check whether we have any circular dependencies
  for (itSet = objects.begin(); itSet != endSet; ++itSet)
    if ((*itSet)->hasCircularDependencies(DependencySet, VerifiedSet, context))
      CCopasiMessage(CCopasiMessage::EXCEPTION, MCObject + 1, (*itSet)->getCN().c_str());

  // Build the complete set of dependencies
  for (itSet = objects.begin(); itSet != endSet; ++itSet)
    {
      // At least the object itself needs to be up to date.
      InsertedObject = DependencySet.insert(*itSet);

      // Add all its dependencies
      if (InsertedObject.second)
        (*itSet)->getAllDependencies(DependencySet, context);
    }

  // Remove all objects which do not have any refresh method as they will
  // be ignored anyway, i.e., no need to sort them.
  for (itSet = DependencySet.begin(), endSet = DependencySet.end(); itSet != endSet;)
    if ((*itSet)->getRefresh() == NULL ||
        ((dynamic_cast< const CParticleReference * >(*itSet) != NULL ||
          dynamic_cast< const CConcentrationReference * >(*itSet) != NULL) &&
         (*itSet)->getDirectDependencies(context).size() == 0))
      {
        const CCopasiObject * pObject = *itSet;
        ++itSet;
        DependencySet.erase(pObject);
      }
    else
      ++itSet;

  // Build the list of all up to date objects
  CCopasiObject::DataObjectSet UpToDateSet;

  for (itSet = uptoDateObjects.begin(), endSet = uptoDateObjects.end(); itSet != endSet; ++itSet)
    {
      // At least the object itself is up to date.
      InsertedObject = UpToDateSet.insert(*itSet);

      // Add all its dependencies too
      if (InsertedObject.second)
        (*itSet)->getAllDependencies(UpToDateSet, context);
    }

  // Now remove all objects in the dependency set which are up to date
  for (itSet = UpToDateSet.begin(), endSet = UpToDateSet.end(); itSet != endSet; ++itSet)
    DependencySet.erase(*itSet);

  // Create a properly sorted list.
  std::list< const CCopasiObject * > SortedList =
    sortObjectsByDependency(DependencySet.begin(), DependencySet.end(), context);

  std::list< const CCopasiObject * >::iterator itList;
  std::list< const CCopasiObject * >::iterator endList;

  // Build the vector of pointers to refresh methods
  Refresh * pRefresh;

  std::vector< Refresh * > UpdateVector;
  std::vector< Refresh * >::const_iterator itUpdate;
  std::vector< Refresh * >::const_iterator endUpdate;

  itList = SortedList.begin();
  endList = SortedList.end();

  for (; itList != endList; ++itList)
    {
      pRefresh = (*itList)->getRefresh();
      itUpdate = UpdateVector.begin();
      endUpdate = UpdateVector.end();

      while (itUpdate != endUpdate && !(*itUpdate)->isEqual(pRefresh)) ++itUpdate;

      if (itUpdate == endUpdate)
        UpdateVector.push_back(pRefresh);
    }

  return UpdateVector;
}