Exemple #1
0
std::string CArrayAnnotation::getObjectDisplayName() const
{
  std::string part;

  if (getObjectParent() && getObjectParent()->getObjectType() != "Model")
    part = getObjectParent()->getObjectDisplayName() + ".";

  return part + getObjectName() + "[[]]";
}
C_FLOAT64 CExperimentObjectMap::CDataColumn::getDefaultScale() const
{
  if (mpObjectCN == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  CCopasiParameterGroup *pGroup =
    dynamic_cast< CCopasiParameterGroup * >(getObjectParent());

  if (pGroup == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  const CExperiment *pExperiment =
    dynamic_cast<const CExperiment * >(pGroup->getObjectParent());

  if (pExperiment == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  CObjectInterface::ContainerList ListOfContainer;
  ListOfContainer.push_back(getObjectDataModel());

  const CCopasiObject * pObject = CObjectInterface::DataObject(CObjectInterface::GetObjectFromCN(ListOfContainer, *mpObjectCN));

  if (pObject == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  return pExperiment->getDefaultScale(pObject);
}
Exemple #3
0
bool CEFMMethod::initialize()
{
  CEFMTask * pTask = dynamic_cast< CEFMTask * >(getObjectParent());

  if (pTask == NULL)
    {
      CCopasiMessage(CCopasiMessage::ERROR, MCEFMAnalysis + 1);
      return false;
    }

  CEFMProblem * pProblem = dynamic_cast< CEFMProblem *>(pTask->getProblem());

  if (pProblem == NULL)
    {
      CCopasiMessage(CCopasiMessage::ERROR, MCEFMAnalysis + 2);
      return false;
    }

  mpFluxModes = & pProblem->getFluxModes();
  mpReorderedReactions = & pProblem->getReorderedReactions();

  mpReorderedReactions->clear();
  mpFluxModes->clear();

  return true;
}
Exemple #4
0
void CLyapProblem::printResult(std::ostream * ostream) const
  {
    CLyapTask* parent = dynamic_cast<CLyapTask*>(getObjectParent());
    if (!parent) return;

    parent->printResult(ostream);
  }
Exemple #5
0
CMetab::CMetab(const std::string & name,
               const CCopasiContainer * pParent):
  CModelEntity(name, pParent, "Metabolite",
               CCopasiObject::NonUniqueName),
  mConc(std::numeric_limits<C_FLOAT64>::quiet_NaN()),
  mIConc(0.0),
  mConcRate(0.0),
  mIntensiveNoise(std::numeric_limits<C_FLOAT64>::quiet_NaN()),
  mTT(0.0),
  mpCompartment(NULL),
  mpMoiety(NULL),
  mIsInitialConcentrationChangeAllowed(true)
{
  mKey = CCopasiRootContainer::getKeyFactory()->add("Metabolite", this);
  initObjects();

  setStatus(REACTIONS);

  if (getObjectParent())
    {
      initCompartment(NULL);

      setInitialConcentration(1.0);
      setConcentration(1.0);
    }

  CONSTRUCTOR_TRACE;
}
Exemple #6
0
bool COptMethod::initialize()
{
  if (!mpOptProblem)
    return false;

  if (!(mpOptItem = &mpOptProblem->getOptItemList()))
    return false;

  if (!(mpOptContraints = &mpOptProblem->getConstraintList()))
    return false;

  if (!(mpSetCalculateVariable = &mpOptProblem->getCalculateVariableUpdateMethods()))
    return false;

  mpParentTask = dynamic_cast<COptTask *>(getObjectParent());

  if (!mpParentTask) return false;

  /*if (pTask &&
      (mpReport = &pTask->getReport()) &&
      !mpReport->getStream())
    mpReport = NULL;*/

  return true;
}
C_FLOAT64 CExperimentObjectMap::CDataColumn::getDefaultScale() const
{
  if (mpObjectCN == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  CCopasiParameterGroup *pGroup =
    dynamic_cast< CCopasiParameterGroup * >(getObjectParent());

  if (pGroup == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  const CExperiment *pExperiment =
    dynamic_cast<const CExperiment * >(pGroup->getObjectParent());

  if (pExperiment == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  const CCopasiDataModel* pDataModel = getObjectDataModel();
  assert(pDataModel != NULL);
  const CCopasiObject * pObject = pDataModel->getDataObject(*mpObjectCN);

  if (pObject == NULL)
    return std::numeric_limits<C_FLOAT64>::quiet_NaN();

  return pExperiment->getDefaultScale(pObject);
}
Exemple #8
0
void CLNAProblem::printResult(std::ostream * ostream) const
{
  //this functionality is expected from the problem. However it is implemented in
  //the task.

  CLNATask* parent = dynamic_cast<CLNATask*>(getObjectParent());

  if (!parent) return;

  parent->printResult(ostream);
}
Exemple #9
0
// virtual
const CObjectInterface::ObjectSet & CParticleReference::getPrerequisites() const
{
  mPrerequisites = * reinterpret_cast< const CObjectInterface::ObjectSet * >(&CCopasiObjectReference< C_FLOAT64 >::getDirectDependencies());
  const CMoiety * pMoiety = static_cast< const CMetab * >(getObjectParent())->getMoiety();

  if (pMoiety != NULL)
    {
      mPrerequisites.insert(pMoiety->getDependentNumberReference());
    }

  return mPrerequisites;
}
/**
 * This instructs the method to calculate a the steady state
 * starting with the initialState given.
 * The steady state is returned in the object pointed to by steadyState.
 * @param CState * steadyState
 * @param const CState * initialState
 * @param C_FLOAT64 * jacobian
 * @param CEigen * eigenValues
 * @return CSteadyStateMethod::ReturnCode returnCode
 */
CSteadyStateMethod::ReturnCode
CSteadyStateMethod::process(CVectorCore< C_FLOAT64 > & State,
                            CMatrix< C_FLOAT64 > & jacobianX,
                            CProcessReport * handler)
{
  mpParentTask = dynamic_cast<CSteadyStateTask *>(getObjectParent());
  assert(mpParentTask);

  mSteadyState.initialize(State);
  mpJacobianX = & jacobianX;
  mpCallBack = handler;

  return processInternal();
}
Exemple #11
0
CCopasiContainer *
CCopasiObject::getObjectAncestor(const std::string & type) const
{
  CCopasiContainer * p = getObjectParent();

  while (p)
    {
      if (p->getObjectType() == type) return p;

      p = p->getObjectParent();
    }

  return NULL;
}
bool CBitPatternTreeMethod::initialize()
{
  if (!CEFMMethod::initialize())
    {
      return false;
    }

  pdelete(mpStepMatrix);
  mReactionForward.clear();

  mContinueCombination = true;

  CEFMTask * pTask = dynamic_cast< CEFMTask *>(getObjectParent());

  if (pTask == NULL) return false;

  mpModel = pTask->getProblem()->getModel();

  if (mpModel == NULL) return false;

  // We first build the kernel matrix
  CMatrix< C_INT64 > KernelMatrix;
  buildKernelMatrix(KernelMatrix);
#ifdef COPASI_DEBUG
  DebugFile << "Original Kernel Matrix:" << std::endl;
  DebugFile << KernelMatrix << std::endl;
#endif // COPASI_DEBUG
  mMinimumSetSize = KernelMatrix.numCols() - 2;
#ifdef COPASI_DEBUG
  DebugFile << "MinSetSize = " << mMinimumSetSize << std::endl;
#endif // COPASI_DEBUG

  // Now we create the initial step matrix
  mpStepMatrix = new CStepMatrix(KernelMatrix);

  mProgressCounter = 0;
  mProgressCounterMax = mpStepMatrix->getNumUnconvertedRows();

  if (mpCallBack)
    mhProgressCounter =
      mpCallBack->addItem("Current Step",
                          CCopasiParameter::UINT,
                          & mProgressCounter,
                          & mProgressCounterMax);

  return true;
}
Exemple #13
0
// virtual
const CCopasiObject::DataObjectSet &
CParticleReference::getDirectDependencies(const CCopasiObject::DataObjectSet & context) const
{
  // If the particle number was changed in the context it has no further dependencies
  if (context.count(this) > 0)
    {
      return EmptyDependencies;
    }

  const CMetab * pSpecies = static_cast< const CMetab * >(getObjectParent());

  // In an assignment the particles (initial or transient) have always dependencies
  if (pSpecies == NULL ||
      pSpecies->getStatus() == CModelEntity::ASSIGNMENT)
    {
      return CCopasiObjectReference< C_FLOAT64 >::getDirectDependencies();
    }

  // We need to distinguish between initial and transient value.
  const CCopasiObject * pConcentrationReference = NULL;

  if (getObjectName() == "InitialParticleNumber")
    {
      // If we have an initial expression the initial particle number has dependencies.
      if (pSpecies->getInitialExpression() != "")
        return CCopasiObjectReference< C_FLOAT64 >::getDirectDependencies();

      pConcentrationReference = pSpecies->getInitialConcentrationReference();
    }
  else
    {
      pConcentrationReference = pSpecies->getConcentrationReference();
    }

  // In other cases we need to find out whether the concentration was changed in
  // the context.

  if (pConcentrationReference != NULL &&
      context.count(pConcentrationReference) > 0)
    {
      return CCopasiObjectReference< C_FLOAT64 >::getDirectDependencies();
    }

  return EmptyDependencies;
}
Exemple #14
0
bool CEventAssignment::setObjectParent(const CCopasiContainer * pParent)
{
  if (pParent != getObjectParent() &&
      mpModel != NULL)
    {
      mpModel->setCompileFlag(true);
    }

  bool success = CCopasiContainer::setObjectParent(pParent);
  mpModel = static_cast<CModel *>(getObjectAncestor("Model"));

  if (mpModel != NULL)
    {
      mpModel->setCompileFlag(true);
    }

  return success;
}
Exemple #15
0
void CEFMAlgorithm::calculateFluxModes()
{
  bool Continue = true;

  if (mStoi.size())
    {
      /* initialize the current tableau matrix */
      pdelete(mpCurrentTableau);
      mpCurrentTableau = new CTableauMatrix(mStoi, mReversible);

      /* Do the iteration */
      mIndexSet.resize(mMaxStep);

      for (mStep = 0; mStep < mMaxStep; mStep++)
        mIndexSet[mStep] = mStep;

      while (findMinimalCombinationIndex() && Continue)
        {
          calculateNextTableau();
          mStepProcess++;

          if (mpCallBack)
            Continue &= mpCallBack->progressItem(mhSteps);

          static_cast<CCopasiTask *>(getObjectParent())->output(COutputInterface::DURING);
        }

      /* Build the elementary flux modes to be returned */
      if (Continue)
        buildFluxModes();

      /* Delete the current / final tableau matrix */
      pdelete(mpCurrentTableau);
    }

  if (mpCallBack)
    Continue &= mpCallBack->finishItem(mhSteps);
}
Exemple #16
0
// virtual
bool CParticleReference::isPrerequisiteForContext(const CObjectInterface * pObject,
    const CMath::SimulationContextFlag & context ,
    const CObjectInterface::ObjectSet & changedObjects) const
{
  const CMetab * pSpecies = static_cast< const CMetab * >(getObjectParent());

  if ((context & CMath::UseMoieties) &&
      pSpecies->isDependent())
    {
      return true;
    }

  // If the value is changed it must not be recalculated, i.e., it does not depend on the object.
  if (changedObjects.find(this) != changedObjects.end())
    return false;

  // Amounts which are determine by assignment need to be recalculated.
  if (pSpecies->getStatus() == CModelEntity::ASSIGNMENT)
    return true;

  const CConcentrationReference * pConcentrationReference = NULL;

  if (getObjectName() != "ParticleNumber")
    {
      pConcentrationReference = pSpecies->getInitialConcentrationReference();
    }
  else
    {
      pConcentrationReference = pSpecies->getConcentrationReference();
    }

  // If the concentration was changed in the context we need to recalculate.
  if (changedObjects.find(pConcentrationReference) != changedObjects.end())
    return true;

  return false;
}
Exemple #17
0
bool CEFMAlgorithm::initialize()
{
  if (!CEFMMethod::initialize())
    {
      return false;
    }

  CEFMTask * pTask = dynamic_cast< CEFMTask *>(getObjectParent());

  if (pTask == NULL) return false;

  mpModel = pTask->getProblem()->getModel();

  if (mpModel == NULL) return false;

  mpFluxModes->clear();

  /* ModelStoi is the transpose of the models stoichiometry matrix */
  const CTransposeView< CMatrix< C_FLOAT64 > > ModelStoi(mpModel->getStoi());

  size_t row, numRows = ModelStoi.numRows();
  size_t col, numCols = ModelStoi.numCols();

  /* Size the stoichiometry matrix passed to the algorithm */
  mStoi.resize(numRows);
  std::vector< std::vector< C_FLOAT64 > >::iterator it = mStoi.begin();
  std::vector< std::vector< C_FLOAT64 > >::iterator end = mStoi.end();

  for (; it != end; ++it)
    it->resize(numCols);

  /* Get the reactions from the model */
  /* Note: We have as many reactions as we have rows in ModelStoi */
  const CCopasiVectorNS < CReaction > & Reaction = mpModel->getReactions();

  /* Vector to keep track of the rearrangements necessary to put the */
  /* reversible reactions to the top of stoichiometry matrix */
  mpReorderedReactions->resize(numRows);

  /* Reversible reaction counter */
  mReversible = 0;
  size_t Insert;
  size_t InsertReversible = 0;
  size_t InsertIrreversible = numRows - 1;

  /* Build the transpose of the stoichiometry matrix, */

  /* sort reversible reactions to the top, count them */

  /* and keep track of the rearrangement */
  for (row = 0; row < numRows; row++)
    {
      if (Reaction[row]->isReversible())
        {
          Insert = InsertReversible++;
          mReversible++;
        }
      else
        Insert = InsertIrreversible--;

      (*mpReorderedReactions)[Insert] = Reaction[row];

      for (col = 0; col < numCols; col++)
        mStoi[Insert][col] = ModelStoi(row, col);
    }

  mStep = 0;
  mStepProcess = 0;
  mMaxStep = (unsigned C_INT32) numCols;

  if (mpCallBack)
    mhSteps =
      mpCallBack->addItem("Current Step",
                          mStepProcess,
                          & mMaxStep);

  return true;
}
Exemple #18
0
//this starts with current state
bool CLyapWolfMethod::calculate()
{
  //get the pointer to the parent task. It's needed for output
  mpTask = dynamic_cast<CLyapTask*>(getObjectParent());
  assert(mpTask);

  //initialize LSODA
  start();

  C_FLOAT64 stepSize = getValue< C_FLOAT64 >("Orthonormalization Interval");
  C_FLOAT64 transientTime = mpProblem->getTransientTime() + *mpContainerStateTime;
  C_FLOAT64 endTime = *mpContainerStateTime + getValue< C_FLOAT64 >("Overall time");
  C_FLOAT64 startTime = *mpContainerStateTime;

  bool flagProceed = true;
  C_FLOAT64 handlerFactor = 100.0 / (endTime - startTime);

  //** do the transient **
  C_FLOAT64 CompareTime = transientTime - 100.0 * fabs(transientTime) * std::numeric_limits< C_FLOAT64 >::epsilon();

  if (*mpContainerStateTime < CompareTime)
    {
      do
        {
          step(transientTime - *mpContainerStateTime);

          if (*mpContainerStateTime > CompareTime) break;

          /* Here we will do conditional event processing */

          /* Currently this is correct since no events are processed. */
          //CCopasiMessage(CCopasiMessage::EXCEPTION, MCTrajectoryMethod + 12);

          flagProceed &= mpTask->methodCallback((*mpContainerStateTime - startTime) * handlerFactor, true);
        }
      while (flagProceed);

      //mpLyapProblem->getModel()->setState(*mpCurrentState);
      //mpLyapProblem->getModel()->updateSimulatedValues();
    }
  else
    {
    }

  //copy state to model and do output
  mpContainer->updateSimulatedValues(mReducedModel);
  mpTask->methodCallback((*mpContainerStateTime - startTime) * handlerFactor, false);
  //********

  orthonormalize();

  if (mDoDivergence)
    *(mVariables.array() + mVariables.size() - 1) = 0; //divergence

  mLsodaStatus = 1; //the state has changed, we need to restart lsoda

  size_t i;

  C_FLOAT64 realStepSize;

  do
    {
      realStepSize = step(stepSize);

      orthonormalize();
      mLsodaStatus = 1; //the state has changed, we need to restart lsoda

      //process results of orthonormalisation
      for (i = 0; i < mNumExp; ++i)
        {
          mpTask->mLocalExponents[i] = log(mNorms[i]);
          mSumExponents[i] += mpTask->mLocalExponents[i];
          mpTask->mLocalExponents[i] = mpTask->mLocalExponents[i] / realStepSize;
          mpTask->mExponents[i] = mSumExponents[i] / (*mpContainerStateTime - transientTime);
        }

      //process result of divergence integration
      if (mDoDivergence)
        {
          mSumDivergence += *(mVariables.array() + mVariables.size() - 1);
          mpTask->mIntervalDivergence = *(mVariables.array() + mVariables.size() - 1) / realStepSize;
          *(mVariables.array() + mVariables.size() - 1) = 0;
          mpTask->mAverageDivergence = mSumDivergence / (*mpContainerStateTime - transientTime);
        }

      flagProceed &= mpTask->methodCallback((*mpContainerStateTime - startTime) * handlerFactor, false);
    }
  while ((*mpContainerStateTime < endTime) && flagProceed);

  return flagProceed;
}
Exemple #19
0
void CEFMProblem::printResult(std::ostream * ostream) const
{
  CEFMTask * pTask = dynamic_cast< CEFMTask * >(getObjectParent());

  if (pTask)
    {
      const std::vector< CFluxMode > & FluxModes = pTask->getFluxModes();

      // List
      *ostream << "\tNumber of Modes:\t" << FluxModes.size() << std::endl;

      // Column header
      *ostream << "#\t\tReactions\tEquations" << std::endl;

      std::vector< CFluxMode >::const_iterator itMode = FluxModes.begin();
      std::vector< CFluxMode >::const_iterator endMode = FluxModes.end();

      unsigned C_INT32 j;

      for (j = 0; itMode != endMode; ++itMode, j++)
        {
          *ostream << j + 1;

          if (itMode->isReversible() == true)
            *ostream << "\tReversible";
          else
            *ostream << "\tIrreversible";

          std::string Description = pTask->getFluxModeDescription(*itMode);
          CFluxMode::const_iterator itReaction = itMode->begin();
          CFluxMode::const_iterator endReaction = itMode->end();

          std::string::size_type start = 0;
          std::string::size_type end = 0;

          for (; itReaction != endReaction; ++itReaction)
            {
              if (itReaction != itMode->begin())
                *ostream << "\t";

              end = Description.find("\n", start);
              *ostream << "\t" << Description.substr(start, end - start);
              start = end + 1;
              *ostream << "\t" << pTask->getReactionEquation(itReaction) << std::endl;
            }
        }

      *ostream << std::endl;

      // Net Reactions
      // Column header
      *ostream << "#\tNet Reaction\tInternal Species" << std::endl;

      itMode = FluxModes.begin();

      for (j = 0; itMode != endMode; ++itMode, j++)
        {
          *ostream << j + 1;
          *ostream << "\t" << pTask->getNetReaction(*itMode);
          *ostream << "\t" << pTask->getInternalSpecies(*itMode) << std::endl;
        }

      *ostream << std::endl;

      // EFM vs Reaction
      std::vector< const CReaction * >::const_iterator itReaction = mReorderedReactions.begin();
      std::vector< const CReaction * >::const_iterator endReaction = mReorderedReactions.end();

      // Column header
      *ostream << "#";

      for (; itReaction != endReaction; ++itReaction)
        {
          *ostream << "\t" << (*itReaction)->getObjectName();
        }

      *ostream << std::endl;

      itMode = FluxModes.begin();
      size_t k;

      for (j = 0; itMode != endMode; ++itMode, j++)
        {
          itReaction = mReorderedReactions.begin();

          *ostream << j + 1;

          for (k = 0; itReaction != endReaction; ++itReaction, k++)
            {
              *ostream << "\t" << itMode->getMultiplier(k);
            }

          *ostream << std::endl;
        }

      *ostream << std::endl;

      if (mpModel == NULL) return;

      // EFM vs Species
      std::vector< CMetab * >::const_iterator itSpecies = mpModel->getMetabolites().begin();
      std::vector< CMetab * >::const_iterator endSpecies = mpModel->getMetabolites().end();
      // Column header
      *ostream << "#";

      for (; itSpecies != endSpecies; ++itSpecies)
        {
          *ostream << "\t" << CMetabNameInterface::getDisplayName(mpModel, **itSpecies);
        }

      *ostream << std::endl;

      itMode = FluxModes.begin();

      for (j = 0; itMode != endMode; ++itMode, j++)
        {
          itSpecies = mpModel->getMetabolites().begin();

          *ostream << j + 1;

          for (; itSpecies != endSpecies; ++itSpecies)
            {
              std::pair< C_FLOAT64, C_FLOAT64 > Changes =
                pTask->getSpeciesChanges(*itMode, **itSpecies);

              *ostream << "\t";

              if (Changes.first > 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon() ||
                  Changes.second > 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon())
                {
                  *ostream << "-" << Changes.first << " | +" << Changes.second;
                }
            }

          *ostream << std::endl;
        }

      *ostream << std::endl;
    }
}
Exemple #20
0
bool CFitProblem::initialize()
{
  mHaveStatistics = false;

  if (!COptProblem::initialize())
    {
      while (CCopasiMessage::peekLastMessage().getNumber() == MCOptimization + 5 ||
             CCopasiMessage::peekLastMessage().getNumber() == MCOptimization + 7)
        CCopasiMessage::getLastMessage();

      if (CCopasiMessage::getHighestSeverity() > CCopasiMessage::WARNING &&
          CCopasiMessage::peekLastMessage().getNumber() != MCCopasiMessage + 1)
        return false;
    }

  std::vector< CCopasiContainer * > ContainerList;
  ContainerList.push_back(getObjectAncestor("Vector"));
  CCopasiDataModel* pDataModel = getObjectDataModel();
  assert(pDataModel != NULL);
  mpSteadyState =
    dynamic_cast< CSteadyStateTask * >(pDataModel->ObjectFromName(ContainerList, *mpParmSteadyStateCN));

  if (mpSteadyState == NULL)
    mpSteadyState =
      static_cast<CSteadyStateTask *>((*pDataModel->getTaskList())["Steady-State"]);

  // We only need to initialize the steady-state task if steady-state data is present.
  if (mpExperimentSet->hasDataForTaskType(CCopasiTask::steadyState))
    {
      mpSteadyState->initialize(CCopasiTask::NO_OUTPUT, NULL, NULL);
    }

  mpTrajectory =
    dynamic_cast< CTrajectoryTask * >(pDataModel->ObjectFromName(ContainerList, *mpParmTimeCourseCN));

  if (mpTrajectory == NULL)
    mpTrajectory =
      static_cast<CTrajectoryTask *>((*pDataModel->getTaskList())["Time-Course"]);

  // We only need to initialize the trajectory task if time course data is present.
  if (mpExperimentSet->hasDataForTaskType(CCopasiTask::timeCourse))
    {
      mpTrajectory->initialize(CCopasiTask::NO_OUTPUT, NULL, NULL);
    }

  ContainerList.clear();

  ContainerList.push_back(mpModel);

  CFitTask * pTask = dynamic_cast<CFitTask *>(getObjectParent());

  if (pTask)
    {
      ContainerList.push_back(pTask);
      ContainerList.push_back(mpSteadyState);
      ContainerList.push_back(mpTrajectory);
    }

  if (!mpExperimentSet->compile(ContainerList)) return false;

  // Build a matrix of experiment and experiment local items.
  mExperimentUpdateMethods.resize(mpExperimentSet->getExperimentCount(),
                                  mpOptItems->size());
  mExperimentUpdateMethods = NULL;
  mExperimentInitialRefreshes.resize(mpExperimentSet->getExperimentCount());

  std::vector< std::set< const CCopasiObject * > > ObjectSet;
  ObjectSet.resize(mpExperimentSet->getExperimentCount());

  std::vector<COptItem * >::iterator it = mpOptItems->begin();
  std::vector<COptItem * >::iterator end = mpOptItems->end();

  std::vector<COptItem * >::iterator itTmp;

  CFitItem * pItem;
  unsigned C_INT32 i, imax;
  unsigned C_INT32 j;
  unsigned C_INT32 Index;

  imax = mSolutionVariables.size();

  mFisher.resize(imax, imax);
  mpFisherMatrix->resize();
  mCorrelation.resize(imax, imax);
  mpCorrelationMatrix->resize();

  for (j = 0; it != end; ++it, j++)
    {
      pItem = static_cast<CFitItem *>(*it);
      pItem->updateBounds(mpOptItems->begin());

      std::string Annotation = pItem->getObjectDisplayName();

      imax = pItem->getExperimentCount();

      if (imax == 0)
        {
          for (i = 0, imax = mpExperimentSet->getExperimentCount(); i < imax; i++)
            {
              mExperimentUpdateMethods(i, j) = pItem->COptItem::getUpdateMethod();
              ObjectSet[i].insert(pItem->getObject());
            }
        }
      else
        {
          Annotation += "; {" + pItem->getExperiments() + "}";

          for (i = 0; i < imax; i++)
            {
              if ((Index = mpExperimentSet->keyToIndex(pItem->getExperiment(i))) == C_INVALID_INDEX)
                return false;

              mExperimentUpdateMethods(Index, j) = pItem->COptItem::getUpdateMethod();
              ObjectSet[Index].insert(pItem->getObject());
            };
        }

      mpFisherMatrix->setAnnotationString(0, j, Annotation);
      mpFisherMatrix->setAnnotationString(1, j, Annotation);
      mpCorrelationMatrix->setAnnotationString(0, j, Annotation);
      mpCorrelationMatrix->setAnnotationString(1, j, Annotation);
    }

  for (i = 0, imax = mpExperimentSet->getExperimentCount(); i < imax; i++)
    mExperimentInitialRefreshes[i] = mpModel->buildInitialRefreshSequence(ObjectSet[i]);

  // Build a matrix of experiment and constraint items;
  mExperimentConstraints.resize(mpExperimentSet->getExperimentCount(),
                                mpConstraintItems->size());
  mExperimentConstraints = NULL;
  mExperimentConstraintRefreshes.resize(mpExperimentSet->getExperimentCount());
  ObjectSet.clear();
  ObjectSet.resize(mpExperimentSet->getExperimentCount());

  it = mpConstraintItems->begin();
  end = mpConstraintItems->end();

  CFitConstraint * pConstraint;
  std::set< const CCopasiObject * >::const_iterator itDepend;
  std::set< const CCopasiObject * >::const_iterator endDepend;

  for (j = 0; it != end; ++it, j++)
    {
      pConstraint = static_cast<CFitConstraint *>(*it);
      itDepend = pConstraint->getDirectDependencies().begin();
      endDepend = pConstraint->getDirectDependencies().end();
      imax = pConstraint->getExperimentCount();

      if (imax == 0)
        {
          for (i = 0, imax = mpExperimentSet->getExperimentCount(); i < imax; i++)
            {
              mExperimentConstraints(i, j) = pConstraint;
              ObjectSet[i].insert(itDepend, endDepend);
            }
        }
      else
        {
          for (i = 0; i < imax; i++)
            {
              if ((Index = mpExperimentSet->keyToIndex(pConstraint->getExperiment(i))) == C_INVALID_INDEX)
                return false;

              mExperimentConstraints(Index, j) = pConstraint;
              ObjectSet[Index].insert(itDepend, endDepend);
            };
        }
    }

  for (i = 0, imax = mpExperimentSet->getExperimentCount(); i < imax; i++)
    mExperimentConstraintRefreshes[i] = CCopasiObject::buildUpdateSequence(ObjectSet[i], mpModel->getUptoDateObjects());

  mExperimentDependentValues.resize(mpExperimentSet->getDataPointCount());


  if (!mpSteadyState)
    {
      mpSteadyState =
        dynamic_cast< CSteadyStateTask * >((*pDataModel->getTaskList())["Steady-State"]);

      if (mpSteadyState == NULL) fatalError();

      setValue("Steady-State", mpSteadyState->getKey());
      mpSteadyState->initialize(CCopasiTask::NO_OUTPUT, NULL, NULL);
      ContainerList.push_back(mpSteadyState);
    }

  if (!mpTrajectory)
    {
      mpTrajectory =
        dynamic_cast< CTrajectoryTask * >((*pDataModel->getTaskList())["Time-Course"]);

      if (mpTrajectory == NULL) fatalError();

      setValue("Time-Course", mpTrajectory->getKey());
      mpTrajectory->initialize(CCopasiTask::NO_OUTPUT, NULL, NULL);
      ContainerList.push_back(mpTrajectory);
    }

  pdelete(mpTrajectoryProblem);
  mpTrajectoryProblem =
    new CTrajectoryProblem(*static_cast<CTrajectoryProblem *>(mpTrajectory->getProblem()));

  static_cast<CTrajectoryProblem *>(mpTrajectory->getProblem())->setStepNumber(1);

  pdelete(mpInitialState);
  mpInitialState = new CState(mpModel->getInitialState());

  return true;
}