Exemple #1
0
bool CExperimentSet::compile(const CMathContainer * pMathContainer)
{
  bool success = true;

  // First we need to sort the experiments so that we can make use of continued
  // file reading.
  sort();

  CObjectInterface::ObjectSet DependentObjects;

  std::ifstream in;
  std::string CurrentFileName("");
  size_t CurrentLineNumber = 1;

  std::vector< CExperiment * >::iterator it = mpExperiments->begin() + mNonExperiments;
  std::vector< CExperiment * >::iterator end = mpExperiments->end();

  for (; it != end; ++it)
    {
      if (CurrentFileName != (*it)->getFileName())
        {
          CurrentFileName = (*it)->getFileName();
          CurrentLineNumber = 1;

          if (in.is_open())
            {
              in.close();
              in.clear();
            }

          in.open(CLocaleString::fromUtf8(CurrentFileName).c_str(), std::ios::binary);

          if (in.fail())
            {
              CCopasiMessage(CCopasiMessage::ERROR, MCFitting + 8, CurrentFileName.c_str());
              return false; // File can not be opened.
            }
        }

      if (!(*it)->read(in, CurrentLineNumber))
        {
          return false;
        }

      if (!(*it)->compile(pMathContainer))
        {
          return false;
        }

      const std::map< const CObjectInterface *, size_t > & ExpDependentObjects = (*it)->getDependentObjectsMap();
      std::map< const CObjectInterface *, size_t >::const_iterator itObject  = ExpDependentObjects.begin();
      std::map< const CObjectInterface *, size_t >::const_iterator endObject = ExpDependentObjects.end();

      for (; itObject != endObject; ++itObject)
        {
          DependentObjects.insert(itObject->first);
        }
    }

  mDependentObjects.resize(DependentObjects.size());
  const CObjectInterface ** ppInsert = mDependentObjects.array();
  CObjectInterface::ObjectSet::const_iterator itObject = DependentObjects.begin();
  CObjectInterface::ObjectSet::const_iterator endObject = DependentObjects.end();

  for (; itObject != endObject; ++itObject, ++ppInsert)
    *ppInsert = *itObject;

  // Allocation and initialization of statistical information
  mDependentObjectiveValues.resize(mDependentObjects.size());
  mDependentObjectiveValues = std::numeric_limits<C_FLOAT64>::quiet_NaN();

  mDependentRMS.resize(mDependentObjects.size());
  mDependentRMS = std::numeric_limits<C_FLOAT64>::quiet_NaN();

  mDependentErrorMean.resize(mDependentObjects.size());
  mDependentErrorMean = std::numeric_limits<C_FLOAT64>::quiet_NaN();

  mDependentErrorMeanSD.resize(mDependentObjects.size());
  mDependentErrorMeanSD = std::numeric_limits<C_FLOAT64>::quiet_NaN();

  mDependentDataCount.resize(mDependentObjects.size());
  mDependentDataCount = std::numeric_limits<size_t>::quiet_NaN();

  return success;
}
bool CMathDependencyGraph::getUpdateSequence(const CMath::SimulationContextFlag & context,
    const CObjectInterface::ObjectSet & changedObjects,
    const CObjectInterface::ObjectSet & requestedObjects,
    CObjectInterface::UpdateSequence & updateSequence)
{

  bool success = true;

  iterator found;
  iterator notFound = mObjects2Nodes.end();

  updateSequence.clear();

  CObjectInterface::ObjectSet::const_iterator it = changedObjects.begin();
  CObjectInterface::ObjectSet::const_iterator end = changedObjects.end();

  const_iterator itCheck = mObjects2Nodes.begin();
  const_iterator endCheck = mObjects2Nodes.end();

  // Mark all nodes which are changed or need to be calculated
  for (; it != end && success; ++it)
    {
      found = mObjects2Nodes.find(*it);

      if (found != notFound)
        {
          success &= found->second->updateDependentState(context, changedObjects);
          continue;
        }

      success = false;
    }

  if (!success) goto finish;

  it = requestedObjects.begin();
  end = requestedObjects.end();

  // Mark all nodes which are requested and its prerequisites.
  for (; it != end && success; ++it)
    {
      found = mObjects2Nodes.find(*it);

      if (found != notFound)
        {
          found->second->setRequested(true);
          success &= found->second->updatePrerequisiteState(context, changedObjects);
          continue;
        }

      success = false;
    }

#ifdef COPASI_DEBUG_TRACE
{
  std::ofstream GetUpdateSequence("GetUpdateSequence.dot");
  exportDOTFormat(GetUpdateSequence, "GetUpdateSequence");
  GetUpdateSequence.close();
}
#endif //COPASI_DEBUG_TRACE

  if (!success) goto finish;

  it = requestedObjects.begin();
  end = requestedObjects.end();

  for (; it != end && success; ++it)
    {
      found = mObjects2Nodes.find(*it);

      if (found != notFound)
        {
          success &= found->second->buildUpdateSequence(context, updateSequence);
          continue;
        }

      success = false;
    }

  if (!success) goto finish;

  for (; itCheck != endCheck; ++itCheck)
    {
      // Reset the dependency nodes for the next call.
      itCheck->second->setChanged(false);
      itCheck->second->setRequested(false);
    }

finish:

  if (!success)
    {
      updateSequence.clear();

      CCopasiMessage(CCopasiMessage::ERROR, MCMathModel + 3, (*it)->getCN().c_str());
    }

#ifdef XXXX
  CObjectInterface::UpdateSequence::const_iterator itSeq = updateSequence.begin();
  CObjectInterface::UpdateSequence::const_iterator endSeq = updateSequence.end();

  std::cout << std::endl <<  "Start" << std::endl;

  for (; itSeq != endSeq; ++itSeq)
    {
      if (dynamic_cast< const CMathObject * >(*itSeq))
        {
          std::cout << *static_cast< const CMathObject * >(*itSeq);
        }
      else
        {
          std::cout << (*itSeq)->getCN() << std::endl;
        }
    }

  std::cout << "End" << std::endl;
#endif //

  return success;
}