예제 #1
0
CEvaluationNode * CEvaluationNode::copyBranch() const
{
  CEvaluationNode * pNode = NULL;
  CNodeContextIterator< const CEvaluationNode, std::vector< CEvaluationNode * > > itNode(this);

  while (itNode.next() != itNode.end())
    {
      if (*itNode == NULL)
        {
          continue;
        }

      if (itNode.parentContextPtr() != NULL)
        {
          itNode.parentContextPtr()->push_back(itNode->copyNode(itNode.context()));
        }
      else
        {
          assert(*itNode == this);
          pNode = itNode->copyNode(itNode.context());
        }
    }

  return pNode;
}
예제 #2
0
bool List_Triplets(const GraphT & g, std::vector< Triplet > & vec_triplets)
{
  // Algorithm
  //
  //-- For each node
  //    - list the outgoing not visited edge
  //    -  for each tuple of edge
  //       - if their end are connected
  //          Detected cyle of length 3
  //          Mark first edge as visited

  typedef typename GraphT::OutArcIt OutArcIt;
  typedef typename GraphT::NodeIt NodeIterator;
  typedef typename GraphT::template EdgeMap<bool> BoolEdgeMap;

  BoolEdgeMap map_edge(g, false); // Visited edge map

  // For each nodes
  for (NodeIterator itNode(g); itNode != INVALID; ++itNode)
  {
    // For each edges (list the not visited outgoing edges)
    std::vector<OutArcIt> vec_edges;
    for (OutArcIt e(g, itNode); e!=INVALID; ++e)
    {
      if (!map_edge[e]) // If not visited
        vec_edges.push_back(e);
    }

    // For all tuples look of ends of edges are linked
    while(vec_edges.size()>1)
    {
      OutArcIt itPrev = vec_edges[0]; // For all tuple (0,Inth)
      for(size_t i=1; i < vec_edges.size(); ++i)
      {
        // Check if the extremity is linked
        typename GraphT::Arc cycleEdge = findArc(g, g.target(itPrev), g.target(vec_edges[i]));
        if (cycleEdge!= INVALID && !map_edge[cycleEdge])
        {
          // Elementary cycle found (make value follow a monotonic ascending serie)
          int triplet[3] = {
            g.id(itNode),
            g.id(g.target(itPrev)),
            g.id(g.target(vec_edges[i]))};
          std::sort(&triplet[0], &triplet[3]);
          vec_triplets.push_back(Triplet(triplet[0],triplet[1],triplet[2]));
        }
      }
      // Mark the current ref edge as visited
      map_edge[itPrev] = true;
      // remove head to list remaining tuples
      vec_edges.erase(vec_edges.begin());
    }
  }
  return (!vec_triplets.empty());
}
예제 #3
0
파일: CDerive.cpp 프로젝트: jonasfoe/COPASI
CEvaluationNode * CDerive::copyBranch_var2obj(const CEvaluationNode* node, std::vector<const CEvaluationNode*> & env)
{
  CEvaluationNode * pNode = NULL;
  CNodeContextIterator< const CEvaluationNode, std::vector< CEvaluationNode * > > itNode(node);

  while (itNode.next() != itNode.end())
    {
      if (*itNode == NULL)
        {
          continue;
        }

      if (itNode.parentContextPtr() != NULL)
        {
          if (itNode->getType() == CEvaluationNode::VARIABLE)
            {
              //expand variable nodes
              const CEvaluationNodeVariable* tmpVar = dynamic_cast<const CEvaluationNodeVariable*>(*itNode);
              itNode.parentContextPtr()->push_back(env[tmpVar->getIndex()]->copyBranch());
            }
          else
            itNode.parentContextPtr()->push_back(itNode->copyNode(itNode.context()));
        }
      else
        {
          assert(*itNode == node);

          if (itNode->getType() == CEvaluationNode::VARIABLE)
            {
              //expand variable nodes
              const CEvaluationNodeVariable* tmpVar = dynamic_cast<const CEvaluationNodeVariable*>(*itNode);
              pNode = env[tmpVar->getIndex()]->copyBranch();
            }
          else
            pNode = itNode->copyNode(itNode.context());
        }
    }

  return pNode;
}
예제 #4
0
const CEvaluationNode * CEvaluationNode::findTopMinus(const std::vector<CFunctionAnalyzer::CValue> & callParameters) const
{
  CNodeContextIterator< const CEvaluationNode, std::vector< const CEvaluationNode * > > itNode(this);
  itNode.setProcessingModes(CNodeIteratorMode::Before | CNodeIteratorMode::After);
  const CEvaluationNode * pMinus = NULL;

  while (itNode.next() != itNode.end())
    {
      if (*itNode == NULL)
        {
          continue;
        }

#ifdef COPASI_DEBUG
      std::cout << itNode->getData() << std::endl;
#endif

      switch (itNode.processingMode())
        {
          case CNodeIteratorMode::Before:

            if (itNode->getType() == (OPERATOR | CEvaluationNodeOperator::MINUS))
              {
                // We found a minus no need to go down the tree.
                itNode.skipChildren();
                pMinus = *itNode;

                if (itNode.parentContextPtr() != NULL)
                  {
                    itNode.parentContextPtr()->push_back(pMinus);
                  }
              }

            break;

          case CNodeIteratorMode::After:

            if (itNode->getType() == (OPERATOR | CEvaluationNodeOperator::MULTIPLY))
              {
                // Left child
                if (itNode.context()[0] != NULL)
                  {
                    // Both children contain a minus, this is not a valid split point.

                    if (itNode.context()[1] != NULL)
                      {
                        pMinus = NULL;
                      }
                    // Check whether the right is positive
                    else if (CFunctionAnalyzer::evaluateNode(static_cast< const CEvaluationNode *>(itNode->getChild(1)),
                             callParameters, CFunctionAnalyzer::NOOBJECT).isPositive())
                      {
                        pMinus = itNode.context()[0];
                      }
                    else
                      {
                        pMinus = NULL;
                      }
                  }
                // Right child
                else if (itNode.context()[1] != NULL)
                  {
                    // Check whether the left is positive
                    if (CFunctionAnalyzer::evaluateNode(static_cast< const CEvaluationNode *>(itNode->getChild(0)),
                                                        callParameters, CFunctionAnalyzer::NOOBJECT).isPositive())
                      pMinus = itNode.context()[1];
                    else
                      pMinus = NULL;
                  }
                else
                  {
                    pMinus = NULL;
                  }
              }
            else if (itNode->getType() == (OPERATOR | CEvaluationNodeOperator::DIVIDE))
              {
                // Left child
                pMinus = itNode.context()[0];
              }
            else
              {
                pMinus = NULL;
              }

            if (itNode.parentContextPtr() != NULL)
              {
                itNode.parentContextPtr()->push_back(pMinus);
              }

            break;

          default:
            // This will never happen
            break;
        }
    }

  return pMinus;
}
예제 #5
0
bool CModelParameterSet::saveToStream(std::ostream & os,
                                      const CModelParameter::Framework & framework,
                                      const std::string & mode,
                                      const std::string & separator)
{
  bool success = true;

  CNodeIterator< const CModelParameter > itNode(this);

  if (mode == "report")
    {
      itNode.setProcessingModes(CNodeIteratorMode::Before);

      while (itNode.next() != itNode.end())
        {
          if (*itNode != NULL)
            {
              for (unsigned int i = 1; i < itNode.level(); i++)
                {
                  os << separator;
                }

              os << itNode->getName();

              for (unsigned int i = itNode.level(); i < 6; i++)
                {
                  os << separator;
                }

              if (itNode->getType() != Group &&
                  itNode->getType() != Set)
                {
                  os << itNode->getValue(framework) << " " << itNode->getUnit(framework);
                }

              os << std::endl;
            }
        }
    }
  else if (mode == "table")
    {
      itNode.setProcessingModes(CNodeIteratorMode::After);

      while (itNode.next() != itNode.end())
        {
          if (*itNode != NULL)
            {
              if (itNode->getType() != Group &&
                  itNode->getType() != Set)
                {
                  os << itNode->getName() << " " << itNode->getUnit(framework) << separator;
                }
            }
        }

      os << std::endl;

      itNode = CNodeIterator< const CModelParameter >(this);
      itNode.setProcessingModes(CNodeIteratorMode::After);

      while (itNode.next() != itNode.end())
        {
          if (*itNode != NULL)
            {
              if (itNode->getType() != Group &&
                  itNode->getType() != Set)
                {
                  os << itNode->getValue(framework) << separator;
                }
            }
        }

      os << std::endl;
    }
  else
    {
      success = false;
    }

  return success;
}