如何在boost图中禁止重复的顶点?
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);
}发布于 2019-03-18 05:34:34
属性包不是顶点相等定义的一部分。顶点描述符是,它们是不同的:
auto v1 = add_vertex("m", interference);
auto v2 = add_vertex("m", interference);
assert(v1 != v2);如果您想要按名称查找,则必须自己为其添加索引(使用map/bimap)。如果只需要命名顶点,请考虑使用labeled_graph适配器(https://www.boost.org/doc/libs/1_69_0/libs/graph/example/labeled_graph.cpp)。遗憾的是,该适配器不是文档库的一部分。我在过去写了几个使用它的答案。
https://stackoverflow.com/questions/55197527
复制相似问题