- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 BGL 的新手,几天来我一直在用头撞墙试图实现一个带有顶点移除的图形,直到我发现一个特别有用的 SO 问题(this 一个)保存我的一天。
现在我的代码结构是这样的(下面是简化的代码):
struct NodeProperties
{
int32_t data;
};
typedef property<edge_weight_t, uint32_t> EdgeProperties;
typedef adjacency_list<listS, listS, bidirectionalS,
property<vertex_index_t, int, NodeProperties>,
EdgeProperties> Graph;
/* In the graph initialization function */
Graph graph;
/* many add_vertex() and add_edge() here */
/* Assign indices */
int i = 0;
BGL_FORALL_VERTICES(v, graph, Graph) {
get(vertex_index, graph)[v] = i++;
}
/* Make many manipulations, in particular, edge/vertex removal according
to certain criteria, NO add_vertex (though some edge are created) */
/* In another function */
vector<int32_t> component(num_vertices(graph));
int num = connected_components(graph, make_iterator_property_map(component.begin(), get(vertex_index, graph), component[0]));
就我目前所了解的而言,对顶点使用 listS 可防止 boost 使用每个节点的位置作为索引,因此我必须使用一种“添加的属性”自行提供此索引。
我对此很好,但上面的代码不 工作——在 connected_components 行出现段错误——除非我重做索引分配。这样做会使一切都完美运行,但在我创建的心理画面中毫无意义。
有人能
提前致谢,祝您有愉快的一天!
R
最佳答案
connected_components 函数构造一个默认的 color_map,其大小为 num_vertices(g),在您的图形中它小于您指定的最大顶点索引。当算法尝试为索引大于 num_vertices(g) 的顶点之一写入颜色时,将访问无效内存。
当您重新分配所有索引时,它们都在 num_vertices(g) 范围内。
要快速引用属性,您应该阅读 http://www.boost.org/doc/libs/1_63_0/libs/graph/doc/quick_tour.html 中的“为图形添加一些颜色” .
关于c++ - BGL : vertices in listS and index_map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42022703/
我是 BGL 的新手,几天来我一直在用头撞墙试图实现一个带有顶点移除的图形,直到我发现一个特别有用的 SO 问题(this 一个)保存我的一天。 现在我的代码结构是这样的(下面是简化的代码): str
我是一名优秀的程序员,十分优秀!