Beispiel #1
0
  bool comb_inc(std::vector<IndexT> & comb, vcl_size_t n)
  {
    vcl_size_t m;
    vcl_size_t k;

    m = static_cast<vcl_size_t>(comb.size());
    // calculate k as highest possible index such that (*comb)[k-1] can be incremented
    k = m;
    while ( (k > 0) && ( ((k == m) && (comb[k-1] == static_cast<IndexT>(n)-1)) ||
                         ((k <  m) && (comb[k-1] == comb[k] - 1) )) )
    {
      k--;
    }

    if (k == 0) // no further increment of comb possible -> return false
      return false;

    comb[k-1] += 1;

    // and all higher index positions of comb are calculated just as directly following integer values
    // Example (1, 4, 7) -> (1, 5, 6) -> (1, 5, 7) -> (1, 6, 7) -> done   for n=7
    for (vcl_size_t i = k; i < m; i++)
      comb[i] = comb[k-1] + IndexT(i - k);
    return true;
  }
Beispiel #2
0
  void nodes_of_strongly_connected_component(MatrixT const & matrix,
                                             std::vector<IndexT> & node_list)
  {
    std::vector<bool> node_visited_already(matrix.size(), false);
    std::deque<IndexT> node_queue;

    //
    // Step 1: Push root nodes to queue:
    //
    for (typename std::vector<IndexT>::iterator it  = node_list.begin();
         it != node_list.end();
         it++)
    {
      node_queue.push_back(*it);
    }
    node_list.resize(0);

    //
    // Step 2: Fill with remaining nodes of strongly connected compontent
    //
    while (!node_queue.empty())
    {
      vcl_size_t node_id = static_cast<vcl_size_t>(node_queue.front());
      node_queue.pop_front();

      if (!node_visited_already[node_id])
      {
        node_list.push_back(IndexT(node_id));
        node_visited_already[node_id] = true;

        for (typename MatrixT::value_type::const_iterator it  = matrix[node_id].begin();
             it != matrix[node_id].end();
             it++)
        {
          vcl_size_t neighbor_node_id = static_cast<vcl_size_t>(it->first);
          if (neighbor_node_id == node_id) continue;
          if (node_visited_already[neighbor_node_id]) continue;

          node_queue.push_back(IndexT(neighbor_node_id));
        }
      }
    }

  }
bool exportToGraphvizFormat_Nodal(
  const GraphT & g,
  std::ostream & os)
{
  os << "graph 1 {" << std::endl;
  os << "node [shape=circle]" << std::endl;
  //Export node label
  for(typename GraphT::NodeIt n(g); n!= lemon::INVALID; ++n)
  {
    os << "  n" << g.id(n) << std::endl;
  }

  //-- Export arc (as the graph is bi-directional, export arc only one time)

  std::map< std::pair<IndexT, IndexT>, IndexT > map_arcs;
  for(typename GraphT::ArcIt e(g); e!=lemon::INVALID; ++e) {
    if( map_arcs.end() == map_arcs.find(std::make_pair(IndexT(g.id(g.source(e))), IndexT(g.id(g.target(e)))))
      &&
      map_arcs.end() == map_arcs.find(std::make_pair(IndexT(g.id(g.target(e))), IndexT(g.id(g.source(e))))))
    {
      map_arcs[std::make_pair(IndexT(g.id(g.source(e))),IndexT(g.id(g.target(e)))) ] = 1;
    }
  }
  //os << "edge [style=bold]" << endl;
  for (std::map< std::pair<IndexT, IndexT>, IndexT >::const_iterator iter = map_arcs.begin();
    iter != map_arcs.end();
    ++iter)
  {
    os << "  n" << iter->first.first << " -- " << " n" << iter->first.second << std::endl;
  }

  os << "}" << std::endl;
  return os.good();
}
bool exportToGraphvizFormat_Image(
  const GraphT & g,
  const NodeMap & nodeMap,
  const EdgeMap & edgeMap,
  std::ostream & os, bool bWeightedEdge = false)
{
  os << "graph 1 {" << std::endl;
  os << "node [shape=none]" << std::endl;
  //Export node label
  for(typename GraphT::NodeIt n(g); n!=lemon::INVALID; ++n)
  {
    os << "  n" << g.id(n)
      << "[ label ="
      << "< "<< std::endl
      << "<table>" << std::endl
      << "<tr><td>" << "\"" << nodeMap[n] << "\"" << "</td></tr>" << std::endl
      << "<tr><td><img src=\"" << nodeMap[n] << "\"/></td></tr>" << std::endl
      << "</table>" << std::endl
      << ">, cluster=1];" << std::endl;

    //os << "  n" << g.id(n)
    //  << " [ "
    //  << " image=\"" << nodeMap[n] << "\" cluster=1]; " << endl;
  }

  //Export arc value
  std::map< std::pair<IndexT, IndexT>, IndexT > map_arcs;
  for(typename GraphT::ArcIt e(g); e!=lemon::INVALID; ++e) {
    if( map_arcs.end() == map_arcs.find(std::make_pair(IndexT(g.id(g.source(e))), IndexT(g.id(g.target(e)))))
      &&
      map_arcs.end() == map_arcs.find(std::make_pair(IndexT(g.id(g.target(e))), IndexT(g.id(g.source(e))))))
    {
      map_arcs[std::make_pair(IndexT(g.id(g.source(e))),
        IndexT(g.id(g.target(e)))) ] = edgeMap[e];
    }
  }

  os << "edge [style=bold]" << std::endl;
  for ( std::map< std::pair<IndexT,IndexT>, IndexT>::const_iterator iter = map_arcs.begin();
    iter != map_arcs.end();
    ++iter)
  {
    if (bWeightedEdge)
    {
      os << "  n" << iter->first.first << " -- " << " n" << iter->first.second
        << " [label=\"" << iter->second << "\"]" << std::endl;
    }
    else
    {
      os << "  n" << iter->first.first << " -- " << " n" << iter->first.second << std::endl;
    }
  }
  os << "}" << std::endl;
  return os.good();
}