如何禁止Boost Graph中的重复顶点



如何禁止Boost Graph中的重复顶点?

using graph_t = boost::adjacency_list<boost::listS, boost::setS, boost::bidirectionalS>;

但我仍然在图中看到重复的节点。对于Vertexlist而言,不足以 setS足够吗?

void doGraph() {
      using graph_t =
         boost::adjacency_list<boost::setS, boost::setS, boost::directedS, std::string>;
      graph_t interference;
      add_vertex("m", interference);
      add_vertex("m", interference);
      // prints 2, why?
      std::cout << "vert #" << num_vertices(interference);
  }

属性束不是顶点的平等定义的一部分。顶点描述符是,并且它们不是相同的:

  auto v1 = add_vertex("m", interference);
  auto v2 = add_vertex("m", interference);
  assert(v1 != v2);

如果您想通过名称查找,则必须自己添加索引(使用地图/BIMAP)。如果您只想命名顶点,请考虑使用labeled_graph Adapter(https://www.boost.org/doc/libs/1_69_0/libs/graph/graph/example/labeled_graph.cpp)。可悲的是,该适配器不是记录的库的一部分。我写了几个过去使用的答案。

最新更新