/** * Sets up the dependency graph. */ void CHybridMethod::setupDependencyGraph() { mDG.clear(); size_t numReactions = mReactions.size(); size_t i, j; CObjectInterface::ObjectSet PropensityObjects; for (i = 0; i < numReactions; i++) { PropensityObjects.insert(mReactions[i].getPropensityObject()); } // Do for each reaction: for (i = 0; i < numReactions; i++) { CObjectInterface::ObjectSet ChangedObjects; CMathReaction & reaction = mReactions[i]; CMathReaction::ObjectBalance::const_iterator itBalance = reaction.getObjectBalance().begin(); CMathReaction::ObjectBalance::const_iterator endBalance = reaction.getObjectBalance().end(); for (; itBalance != endBalance; ++itBalance) { ChangedObjects.insert(itBalance->first); } mpContainer->getTransientDependencies().getUpdateSequence(mUpdateSequences[i], CMath::Default, ChangedObjects, PropensityObjects); for (j = 0; j < numReactions; j++) { if (mpContainer->getTransientDependencies().dependsOn(mReactions[j].getPropensityObject(), CMath::Default, ChangedObjects)) { mDG.addDependent(i, j); } } } return; }
void CMathDelay::createUpdateSequences() { // The requested objects are all delay values CObjectInterface::ObjectSet Requested; CMathObject **pObject = mValueObjects.array(); CMathObject **pObjectEnd = pObject + mValueObjects.size(); for (; pObject != pObjectEnd; ++pObject) if (*pObject != NULL) { Requested.insert(*pObject); } mpContainer->getTransientDependencies().getUpdateSequence(mValueSequence, CMath::DelayValues, mpContainer->getStateObjects(false), Requested); mpContainer->getTransientDependencies().getUpdateSequence(mValueSequenceReduced, CMath::UseMoieties | CMath::DelayValues, mpContainer->getStateObjects(true), Requested); }
void CStochDirectMethod::start() { CTrajectoryMethod::start(); /* get configuration data */ mMaxSteps = getValue< C_INT32 >("Max Internal Steps"); mpRandomGenerator = &mpContainer->getRandomGenerator(); if (getValue< bool >("Use Random Seed")) { mpRandomGenerator->initialize(getValue< unsigned C_INT32 >("Random Seed")); } //mpCurrentState is initialized. This state is not used internally in the //stochastic solver, but it is used for returning the result after each step. //========Initialize Roots Related Arguments======== mNumRoot = mpContainer->getRoots().size(); mRootsFound.resize(mNumRoot); mRootsA.resize(mNumRoot); mRootsB.resize(mNumRoot); mpRootValueNew = &mRootsA; mpRootValueOld = &mRootsB; mRootsNonZero.resize(mNumRoot); mRootsNonZero = 0.0; CMathObject * pRootObject = mpContainer->getMathObject(mpContainer->getRoots().array()); CMathObject * pRootObjectEnd = pRootObject + mNumRoot; CObjectInterface::ObjectSet Requested; for (; pRootObject != pRootObjectEnd; ++pRootObject) { Requested.insert(pRootObject); } CObjectInterface::ObjectSet Changed; // Determine whether we have time dependent roots; CObjectInterface * pTimeObject = mpContainer->getMathObject(mpContainerStateTime); Changed.insert(pTimeObject); mpContainer->getTransientDependencies().getUpdateSequence(mUpdateTimeDependentRoots, CMath::Default, Changed, Requested); mHaveTimeDependentRoots = (mUpdateTimeDependentRoots.size() > 0); // Build the reaction dependencies mReactions.initialize(mpContainer->getReactions()); mNumReactions = mReactions.size(); mAmu.initialize(mpContainer->getPropensities()); mPropensityObjects.initialize(mAmu.size(), mpContainer->getMathObject(mAmu.array())); mUpdateSequences.resize(mNumReactions); CMathReaction * pReaction = mReactions.array(); CMathReaction * pReactionEnd = pReaction + mNumReactions; CObjectInterface::UpdateSequence * pUpdateSequence = mUpdateSequences.array(); CMathObject * pPropensityObject = mPropensityObjects.array(); CMathObject * pPropensityObjectEnd = pPropensityObject + mPropensityObjects.size(); for (; pPropensityObject != pPropensityObjectEnd; ++pPropensityObject) { Requested.insert(pPropensityObject); } pPropensityObject = mPropensityObjects.array(); for (; pReaction != pReactionEnd; ++pReaction, ++pUpdateSequence, ++pPropensityObject) { Changed = pReaction->getChangedObjects(); // The time is always updated Changed.insert(pTimeObject); pUpdateSequence->clear(); mpContainer->getTransientDependencies().getUpdateSequence(*pUpdateSequence, CMath::Default, Changed, Requested); } mMaxStepsReached = false; mTargetTime = *mpContainerStateTime; mNextReactionTime = *mpContainerStateTime; mNextReactionIndex = C_INVALID_INDEX; stateChange(CMath::State); return; }
// virtual void CTrajectoryMethodDsaLsodar::start() { CLsodaMethod::start(); mReactions.initialize(mpContainer->getReactions()); mNumReactions = mReactions.size(); mAmu.initialize(mpContainer->getPropensities()); mPropensityObjects.initialize(mNumReactions, mpContainer->getMathObject(mAmu.array())); mUpdateSequences.resize(mNumReactions); mFirstReactionSpeciesIndex = mpContainer->getCountFixedEventTargets() + 1 /* Time */ + mpContainer->getCountODEs(); // Create a local copy of the state where the particle number species determined // by reactions are rounded to integers. C_FLOAT64 * pValue = mContainerState.array() + mFirstReactionSpeciesIndex; C_FLOAT64 * pValueEnd = pValue + mpContainer->getCountIndependentSpecies() + mpContainer->getCountDependentSpecies(); for (; pValue != pValueEnd; ++pValue) { *pValue = floor(*pValue + 0.5); } // The container state is now up to date we just need to calculate all values needed for simulation. mpContainer->updateSimulatedValues(false); CMathObject * pTimeObject = mpContainer->getMathObject(mpContainer->getModel().getValueReference()); // Build the reaction dependencies mReactions.initialize(mpContainer->getReactions()); mNumReactions = mReactions.size(); mAmu.initialize(mpContainer->getPropensities()); mPropensityObjects.initialize(mAmu.size(), mpContainer->getMathObject(mAmu.array())); mUpdateSequences.resize(mNumReactions); C_FLOAT64 * pAmu = mAmu.array(); mA0 = 0.0; CMathReaction * pReaction = mReactions.array(); CMathReaction * pReactionEnd = pReaction + mNumReactions; CCore::CUpdateSequence * pUpdateSequence; CMathObject * pPropensityObject = mPropensityObjects.array(); CMathObject * pPropensityObjectEnd = pPropensityObject + mPropensityObjects.size(); CObjectInterface::ObjectSet Requested; for (; pPropensityObject != pPropensityObjectEnd; ++pPropensityObject) { Requested.insert(pPropensityObject); } pPropensityObject = mPropensityObjects.array(); for (; pReaction != pReactionEnd; ++pReaction, ++pUpdateSequence, ++pPropensityObject, ++pAmu) { // Update the propensity pPropensityObject->calculateValue(); mA0 += *pAmu; CObjectInterface::ObjectSet Changed; // The time is always updated Changed.insert(pTimeObject); const CMathReaction::SpeciesBalance * itBalance = pReaction->getNumberBalance().array(); const CMathReaction::SpeciesBalance * endBalance = itBalance + pReaction->getNumberBalance().size(); for (; itBalance != endBalance; ++itBalance) { Changed.insert(mpContainer->getMathObject(itBalance->first)); } pUpdateSequence->clear(); mpContainer->getTransientDependencies().getUpdateSequence(*pUpdateSequence, CCore::SimulationContext::Default, Changed, Requested); } mPartition.intialize(mpContainer, *mpLowerLimit, *mpUpperLimit); return; }
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; }