- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想打印所有顶点及其相邻顶点。我在网上找到了一些关于如何做到这一点的例子,但它对我不起作用。我收到错误,++ 运算符不能用于 ai。另外我认为它需要是 vertex_idMap[*ai]
而不是 vertex_idMap[ai]
但这会提示错误。有谁知道为什么这是错误的?
typedef adjacency_list<vecS, listS, directedS, VertexIDPorperty, EdgeWeight> Graph; //the type of g
graph_traits <Graph>::vertex_iterator i, end;
graph_traits <Graph>::adjacency_iterator ai, a_end;
for (boost::tie(i, end) = vertices(g); i != end; ++i) {
std::cout << vertex_idMap[*i];
for (; ai != a_end; ++ai) { //the ++ai seems to be wrong?
std::cout << vertex_idMap[ai];
if (boost::next(ai) != a_end)
std::cout << ", ";
}
std::cout << std::endl;
最佳答案
观察:
ai
和 a_end
未初始化(也许您实际上并不是说代码无法编译,这就是您的全部问题)vertex_idMap[ai]
将无法编译,因为 vertex_iterator
不是有效的 vertex_descriptor
这是一个固定的示例,其中包含想象中的缺失位:
#include <boost/graph/adjacency_list.hpp>
#include <iostream>
using VertexIDPorperty = boost::property<boost::vertex_index_t, int>;
using EdgeWeight = boost::property<boost::edge_weight_t, double>;
typedef boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, VertexIDPorperty, EdgeWeight> Graph;
Graph sample();
int main() {
Graph g = sample();
auto vertex_idMap = get(boost::vertex_index, g);
boost::graph_traits <Graph>::vertex_iterator i, end;
boost::graph_traits <Graph>::adjacency_iterator ai, a_end;
for (boost::tie(i, end) = vertices(g); i != end; ++i) {
std::cout << vertex_idMap[*i] << ": ";
for (boost::tie(ai, a_end) = adjacent_vertices(*i, g); ai != a_end; ++ai) {
std::cout << vertex_idMap[*ai];
if (boost::next(ai) != a_end)
std::cout << ", ";
}
std::cout << std::endl;
}
}
实现 sample()
来创建一个随机图:
#include <boost/graph/random.hpp>
#include <random>
Graph sample() {
Graph g;
std::mt19937 prng { std::random_device{}() };
generate_random_graph(g, 10, 20, prng);
int id = 0;
for (auto vd : boost::make_iterator_range(vertices(g))) {
put(boost::vertex_index, g, vd, ++id);
}
return g;
}
它打印出类似的东西:
1: 9, 9, 4
2: 6
3:
4:
5: 9, 9, 8, 9
6: 9, 3, 1
7: 2, 10
8: 6
9: 8
10: 7, 3, 8, 1, 4
打印图表可以更简单:
#include <boost/graph/graph_utility.hpp>
// ...
int main() {
print_graph(sample());
}
1 -->
2 --> 3 10 9 6 6 10
3 --> 8
4 -->
5 --> 4
6 --> 1 5 8
7 --> 4 9 2 2 1
8 --> 6
9 --> 5 7
10 --> 7
关于c++ - boost 图 : Iterating through all vertices and printing adjacent vertices,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50406886/
我将 bxSlider 用于轮播。它提供水平和垂直模式,这很好。 唯一的问题是在垂直显示时,箭头仍然保持在水平位置。 HTML 代码: JS $('.sliderLo
我有一个包含数百个 STL 网格的文件夹,我想使用 flatten 命令将它们合并到 meshlab 中。 我使用的是常规 GUI,当我打开文件并选择所有这些 STL 文件时,如果我想“统一重复顶点”
我有 2 个表,其中包含一组数据,如下所示,我想获得结果,该结果将在字段 balance 中进行计算: 我卡在了 balance 字段,如何让 balance 运行? tblIn in_date
我想打印所有顶点及其相邻顶点。我在网上找到了一些关于如何做到这一点的例子,但它对我不起作用。我收到错误,++ 运算符不能用于 ai。另外我认为它需要是 vertex_idMap[*ai] 而不是 ve
运行 ./gradlew lint 向我报告一个令人困惑的错误: 39: Must be one of: RecyclerView.HORIZONTAL, RecyclerView.VERTICAL
你好,我无法弄清楚为什么传递 GLfloat 位置数组 (xyz) 的第一个元素突然为缓冲区提供该数组的所有元素。 glBufferData(GL_ARRAY_BUFFER, sizeof(Verte
抱歉打死马,但我无法理解为什么下面的方法不起作用。 设置line-height: 50px 设置vertical-align: top 据我了解,这应该使行框高 50 像素,然后 vertical-a
所以,我正在查看 Bootstrap 文档以寻找解决这个问题的方法,但没有找到任何东西。有没有办法,使用bootstrap组件,一个接一个垂直显示按钮组? 这是我目前所拥有的: but
目标:我需要通过移动现有顶点而不是添加新顶点来编辑矢量图层,因为我有一个表格,其中显示每个顶点的坐标。当我移动一个顶点时,我必须更新表格。 调查:我查看了 openlayers 4.6.5 的文档 I
这两个属性是一样的还是有不同的用法?vertical-align:top 和 vertical-align:text-top 最佳答案 区别可以通过line-height属性来解释。 MDN Sour
我有一些关于视觉内容的问题,可以在附件(在 Firefox 中使用 CTRL-+ 查看放大的视觉内容在左侧生成它的代码)。让我们命名视觉从上到下用数字 1、2、3、4、5 和 6 列出的内容。我对这种
XCode 建议我在创建的动态大小单元格中为约束设置垂直压缩和拥抱优先级。虽然单元格总是正确显示,但错误仍然存在,所以这不是问题,但我需要删除错误才能将更新提交到 App Store。 我在多标签
显示部分幻灯片的垂直 Flexslider。幻灯片从上到下剪切。这是不同图像尺寸的问题。 这是代码: $(window).load(function(){ $('.flexslider').f
我正在尝试 CSS multi-columns spec 并想出了 column-axis。但我不明白它的作用是什么?看起来 column-axis: horizontal; 是 regular
在思考这个问题时,我一直在挠头。我有 3 个 div。顶部和底部的 div 有一个最小高度,中间的 div 有未知的高度(按内容扩展)但应该在页面中居中。顶部和底部的 div 应填充剩余的顶部和底部空
我有一个包含文本的 div,line-height 大于文本的高度。这意味着每行文本的顶部和下方都有空间。 右侧有一个垂直边框,我希望其顶部与文本顶部对齐。我需要以某种方式将文本与其行的顶部对齐。 这
嗯,我得到了这个结构: #parent{ max-width: 800px; height: auto; margin: auto;
我这里有两个可能很简单的 CSS 问题: http://web288.merkur.ibone.ch/klingler/ 如何让页脚中的 © Klingler Fahrzeugtechnik AG 2
假设我们有一组 JSON 格式的人。每个实体大约有 100 个属性。使用 ng-repeat 的标准方法: ... Attribute1 Attribute2 ... Attribu
我正在尝试用点语言绘制一个稀疏矩阵,实际上节点连接是可以的,但问题是这些节点的垂直对齐,我尝试使用 pos 并放置具有 x 和 y 值的节点,但只是没有t 工作(我认为是因为默认布局)。如果你能帮助我
我是一名优秀的程序员,十分优秀!