BGL:listS和index_map中的顶点
BGL: vertices in listS and index_map
我是BGL的新手,几天来我一直在努力实现一个带有顶点移除的图,直到我发现了一个特别有用的SO问题(这个问题),这才让我度过了一天。
现在我的代码是这样构造的(下面的简化代码):
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行出现分段错误——,除非我重新进行索引分配。这样做会让一切都完美,但在我创造的心理画面中毫无意义。
有人会吗
- 给我一个很好的参考,用外行的术语解释所有这些index_map"诡计"?好吧,有很多官方文档,但它们对我来说太复杂了(我是一名C程序员)。我计划学习高级C++,但我目前必须为我的工作实现这个图算法,而且在开始真正的代码之前,我不能花3个月的时间学习C++。。。(我已经花了大约10个小时完成了上面的代码,我本可以在这么长的时间内轻松地在C中重新实现上面的所有内容…)
- 解释我为什么要这样做(或者我在这里做错了什么)
提前感谢,祝您今天愉快!
R
connected_contensions函数构造了一个默认的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.
相关文章:
- 如何循环打印顶点结构
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 使用一个考虑到std::map中键值的滚动或换行的键
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 允许从 std::map 的密钥窃取资源?
- D3D11-将混合权重和索引传递到顶点着色器
- 有没有办法对std::unordered_set、std::unrdered_map、std::set、std::map
- 将重物插入std::map
- 从返回的顶点缓冲区查询顶点结构
- Vulkan 中的动态顶点缓冲区格式设置
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 使用通用值初始化 std::map,不重复
- 仅包含可移动 std::map 的类的移动构造函数不起作用
- C++:当所有条目都保证是唯一时,替代 std::map
- 使用模板化的键类型定义 std::map,该键类型基于作为参数接收的函数
- 如果 KEY 是 std::list 或 std::vector 而不是值,那么 std::map 的默认行为是什么?
- 使用字符数组作为 Map 中的键
- 如何将一半传递给顶点着色器?
- C++如何创建 std::map