不同提升图的权重相同
Same weights for different boost graphs
本文关键字:权重 更新时间:2023-10-16
我刚刚意识到我还不明白如何使用提升图库。我有这个代码:
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
using namespace std;
using namespace boost;
typedef unsigned int WeightType;
typedef adjacency_list<listS, vecS, bidirectionalS,
no_property, property<edge_weight_t, WeightType>> Graph;
typedef graph_traits<Graph>::vertex_descriptor Vertex;
typedef graph_traits<Graph>::edge_descriptor Edge;
typedef property_map<Graph, edge_weight_t>::type WeightMap;
typedef property_map<Graph, edge_weight_t>::const_type ConstWeightMap;
const WeightType infinity = numeric_limits<WeightType>::max();
int main() {
Graph g(4);
Graph g2(4);
for (uint i = 0; i < 3; ++i) {
add_edge(i, i+1, i, g);
add_edge(i, i+1, i*10, g2);
}
WeightMap m = get(edge_weight, g);
WeightMap m2 = get(edge_weight, g2);
for (auto e : make_iterator_range(edges(g))) {
cout << m[e] << endl;
}
cout << endl;
for (auto e : make_iterator_range(edges(g))) {
cout << m2[e] << endl;
}
}
我希望输出如下:"0 1 2 , 0 10 20"。但输出是"0 1 2, 0 1 2"。每个图都有其权重属性图,不是吗?我的错误在哪里?
你在第二个 for 循环中打错了字:
for (auto e : make_iterator_range(edges(g))) {
应该是:
for (auto e : make_iterator_range(edges(g2))) {
因此,您将第一个图表的内容打印了两次,而不是第一个,然后是第二个。
相关文章:
- D3D11-将混合权重和索引传递到顶点着色器
- 提升如何在图形可视化中写入边缘的权重?
- OpenCV 3 中的神经网络权重
- 我对 MyGraph 属性顶点名称和边权重有问题
- 生成具有均匀汉明权重 (popcount) c++ 的整数
- 保存在(Python)tensorflow中的权重未加载到C++tf中
- 我不确定如何引用此神经网络训练方法中的权重
- 多部分基准测试的权重是多少?
- BGL 获取图形的权重图
- 计算圆圈中权重的乘积(图形)
- C++带有权重的随机非重复整数
- 如何从TensorFlow .pb模型中获取权重格式?
- 如何使用所有其他文件信息来编译代码,例如HAAR级联训练的权重的XML文件
- 素数算法:通过边权重的总和显示相关边
- 有没有一种方法可以使用弗洛伊德-沃歇尔算法给出最短路径,其中存在负权重循环而不允许重叠边缘?
- 用于计算统一子字符串权重的代码
- std::d iscrete_distribution() 是否允许零权重
- 具有恒定权重的 Dijkstra 最短路径算法
- OpenCV 是否用零初始化权重矩阵,cv::ml::ANN_MLP
- QLineEdit 在激活时更改文本权重