C_FLOAT64 CStochNextReactionMethod::doSingleStep(C_FLOAT64 C_UNUSED(time), C_FLOAT64 endTime)
{
  C_FLOAT64 steptime = mPQ.topKey();

  if (steptime >= endTime)
    {
      return endTime;
    }
  else
    {
      C_INT32 reaction_index = mPQ.topIndex();
      updateSystemState(reaction_index);
      updatePriorityQueue(reaction_index, steptime);
      //printDebugInfo();
      return steptime;
    }
}
Пример #2
0
/**
 *  Simulates the system over the next interval of time. The new time after
 *  this step is returned.
 *
 *  @param  currentTime A C_FLOAT64 specifying the current time
 *  @param  endTime A C_FLOAT64 specifying the endTime of the current step()
 *  @return A C_FLOAT giving the new time
 */
C_FLOAT64 CHybridMethod::doSingleStep(C_FLOAT64 currentTime, C_FLOAT64 endTime)
{
  size_t rIndex = 0;
  C_FLOAT64 ds = endTime;

  // if there are stochastic reactions
  if (mPQ.size() != 0) // there is at least one stochastic reaction
    {
      getStochTimeAndIndex(ds, rIndex);

      if (ds <= endTime) // ds is an absolute time value!
        {
          // if there are deterministic reactions
          if (mFirstReactionFlag != NULL) // there is at least one deterministic reaction
            {
              integrateDeterministicPart(ds - currentTime);
            }

          mReactions[rIndex].fire();
          *mpContainerStateTime = ds;
          stateChange(CMath::State);

          if (++mStepsAfterPartitionSystem >= mPartitioningInterval)
            {
              partitionSystem();
              mStepsAfterPartitionSystem = 0;
            }

          updatePriorityQueue(rIndex, ds);
        }
      else
        {
          ds = endTime;

          // if there are deterministic reactions
          if (mFirstReactionFlag != NULL) // there is at least one deterministic reaction
            {
              integrateDeterministicPart(ds - currentTime);
            }

          *mpContainerStateTime = ds;

          if (++mStepsAfterPartitionSystem >= mPartitioningInterval)
            {
              partitionSystem();
              mStepsAfterPartitionSystem = 0;
            }

          updatePriorityQueue(C_INVALID_INDEX, endTime);
        }
    }
  else // there is no stochastic reaction
    {
      // if there are deterministic reactions
      if (mFirstReactionFlag != NULL) // there is at least one deterministic reaction
        {
          integrateDeterministicPart(ds - currentTime);
        }

      *mpContainerStateTime = ds;

      if (++mStepsAfterPartitionSystem >= mPartitioningInterval)
        {
          partitionSystem();
          mStepsAfterPartitionSystem = 0;
        }

      updatePriorityQueue(C_INVALID_INDEX, ds);
    }

  return ds;
}