使用listS增强强成分

问题描述 投票:1回答:1

对于在listS而不是vecS上建立强连接组件的图形,没有太多示例。这是vecS的等效示例

#include <boost/config.hpp>
#include <vector>
#include <iostream>
#include <boost/graph/strong_components.hpp>
#include <boost/graph/adjacency_list.hpp>

int
main()
{
  using namespace boost;
  typedef adjacency_list < vecS, vecS, directedS > Graph;
  const int N = 6;
  Graph G(N);
  add_edge(0, 1, G);
  add_edge(1, 1, G);
  add_edge(1, 3, G);
  add_edge(1, 4, G);
  add_edge(3, 4, G);
  add_edge(3, 0, G);
  add_edge(4, 3, G);
  add_edge(5, 2, G);

  std::vector<int> c(N);

  int num = strong_components
    (G, make_iterator_property_map(c.begin(), get(vertex_index, G), c[0]));

    auto l=get(vertex_index, G);

  std::cout << "Total number of components: " << num << std::endl;
  std::vector < int >::iterator i;
  for (i = c.begin(); i != c.end(); ++i)
    std::cout << "Vertex " << i - c.begin()
      << " is in component " << *i << std::endl;
  return EXIT_SUCCESS;
}

但是当我从vecS更改为listS时,它坏了。我知道问题是由于顶点索引和输出向量索引中的某种不匹配而引起的,但是我无法确切地提出解决问题的方法。最接近的答案是Which VertexList types are valid for depth_first_search,但这是为了DFS,无法推断到SCC。

boost boost-graph strongly-connected-graph
1个回答
0
投票

对于在listS而不是vecS上建立强连接组件的图形,没有太多示例。这是vecS的等效示例

© www.soinside.com 2019 - 2024. All rights reserved.