Example #1
0
bool CFunction::isSuitable(const unsigned C_INT32 noSubstrates,
                           const unsigned C_INT32 noProducts,
                           const TriLogic reversible)
{
  // A function which in neither restricted to reversible nor to irreversible reactions is always suitable
  // independent from the number of substrates or products
  if (isReversible() == TriUnspecified)
    return true;

  //first reversibility:
  if (reversible != isReversible())
    return false;

  //check substrates
  if (mVariables.isVector(CFunctionParameter::SUBSTRATE))
    {
      if (noSubstrates == 0 || noSubstrates == C_INVALID_INDEX)
        return false;
    }
  else //is no vector
    {
      if (mVariables.getNumberOfParametersByUsage(CFunctionParameter::SUBSTRATE) != noSubstrates &&
          noSubstrates != C_INVALID_INDEX)
        return false;
    }

  //check products
  if (reversible == TriTrue)
    {
      if (mVariables.isVector(CFunctionParameter::PRODUCT))
        {
          if (noProducts == 0 || noProducts == C_INVALID_INDEX)
            return false;
        }
      else //is no vector
        {
          if (mVariables.getNumberOfParametersByUsage(CFunctionParameter::PRODUCT) != noProducts &&
              noProducts != C_INVALID_INDEX)
            return false;
        }
    }

  //no VARIABLE variables allowed for kinetic functions
  if (mVariables.getNumberOfParametersByUsage(CFunctionParameter::VARIABLE) != 0)
    return false;

  return true;
}
Example #2
0
bool CMassAction::setInfix(const std::string & infix)
{
  if (infix == "k1*PRODUCT<substrate_i>-k2*PRODUCT<product_j>")
    setReversible(TriTrue);
  else if (infix == "k1*PRODUCT<substrate_i>")
    setReversible(TriFalse);
  else
    return false;

  CFunction::setInfix(infix);
  getVariables().cleanup();

  getVariables().add("k1",
                     CFunctionParameter::FLOAT64,
                     CFunctionParameter::PARAMETER);
  getVariables().add("substrate",
                     CFunctionParameter::VFLOAT64,
                     CFunctionParameter::SUBSTRATE);

  if (isReversible() == TriTrue)
    {
      getVariables().add("k2",
                         CFunctionParameter::FLOAT64,
                         CFunctionParameter::PARAMETER);
      getVariables().add("product",
                         CFunctionParameter::VFLOAT64,
                         CFunctionParameter::PRODUCT);
    }

  return true;
}
Example #3
0
int main()
{
    long long ret = 0, i=10;
    while( i++ < N){
        if(isReversible(i)==0) ++ret;        
    }
    printf("ans is %lld\n", ret);
    return 0;
}
Example #4
0
// virtual
std::string CMassAction::writeMathML(const std::vector< std::vector< std::string > > & variables,
                                     bool /* expand */, bool /* fullExpand */) const
{
  std::ostringstream out;

  bool rev = (isReversible() == TriTrue);

  if (rev)
    out << "<mfenced>" << std::endl;

  out << "<mrow>" << std::endl;

  out << variables[0][0] << std::endl;

  size_t i, imax = variables[1].size();

  for (i = 0; i < imax; ++i)
    {
      out << "<mo>&CenterDot;</mo>" << std::endl;
      out << variables[1][i] << std::endl;
    }

  if (rev)
    {
      out << "<mo>-</mo>" << std::endl;
      out << variables[2][0] << std::endl;

      size_t i, imax = variables[3].size();

      for (i = 0; i < imax; ++i)
        {
          out << "<mo>&CenterDot;</mo>" << std::endl;
          out << variables[3][i] << std::endl;
        }
    }

  out << "</mrow>" << std::endl;

  if (rev)
    out << "</mfenced>" << std::endl;

  return out.str();
}
Example #5
0
std::vector< std::string > CReactionInterface::getListOfPossibleFunctions() const
{
  TriLogic reversible;

  if (isReversible() == false)
    reversible = TriFalse;
  else
    reversible = TriTrue;

  std::vector<CFunction*> functionVector =
    CCopasiRootContainer::getFunctionList()->suitableFunctions(
      mChemEqI.getMolecularity(CFunctionParameter::SUBSTRATE),
      mChemEqI.getMolecularity(CFunctionParameter::PRODUCT),
      reversible);

  std::vector<std::string> ret;
  size_t i, imax = functionVector.size();

  for (i = 0; i < imax; ++i)
    ret.push_back(functionVector[i]->getObjectName());

  return ret;
}
Example #6
0
const C_FLOAT64 & CMassAction::calcValue(const CCallParameters<C_FLOAT64> & callParameters)
{
  CCallParameters<C_FLOAT64>::const_iterator pCallParameters = callParameters.begin();

  CCallParameters<C_FLOAT64>::const_iterator Factor = (pCallParameters + 1)->vector->begin();
  CCallParameters<C_FLOAT64>::const_iterator End = (pCallParameters + 1)->vector->end();

  mValue = 0.0;

  if (Factor != End)
    {
      mValue = *(pCallParameters + 0)->value   // k1
               * *(Factor++)->value;      // first substrate.

      while (Factor != End)
        mValue *= *(Factor++)->value;
    }

  if (isReversible() == TriFalse)
    return mValue;

  C_FLOAT64 Products = 0.0;

  Factor = (pCallParameters + 3)->vector->begin();
  End = (pCallParameters + 3)->vector->end();

  if (Factor != End)
    {
      Products = *(pCallParameters + 2)->value // k2
                 * *(Factor++)->value;    // first product.

      while (Factor != End)
        Products *= *(Factor++)->value;
    }

  return mValue -= Products;
}
Example #7
0
bool CMassAction::dependsOn(const C_FLOAT64 * parameter,
                            const CCallParameters<C_FLOAT64> & callParameters) const
{
  if (parameter == callParameters[0].value) return true;

  CCallParameters<C_FLOAT64>::const_iterator it;
  CCallParameters<C_FLOAT64>::const_iterator end;

  it = callParameters[1].vector->begin();
  end = callParameters[1].vector->end();

  for (; it != end; it++) if (parameter == it->value) return true;

  if (isReversible() != TriTrue) return false;

  if (parameter == callParameters[2].value) return true;

  it = callParameters[3].vector->begin();
  end = callParameters[3].vector->end();

  for (; it != end; it++) if (parameter == it->value) return true;

  return false;
}