c++ - Boost Graph Library - 来自外部 vector 的权重属性

标签 c++ templates boost boost-graph

我做错了什么?

#include <vector>

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>

using namespace std;

typedef boost::adjacency_list<> Graph;

void dijkstra(Graph &g, vector<double> &edge_weights, int source, vector<double> &dist,   vector<int> &prev) {
boost::dijkstra_shortest_paths(g, source,
                                 boost::weight_map(boost::make_iterator_property_map(edge_weights.begin(), get(boost::edge_index, g))));

}

(编译:g++ main.cc -L/usr/local/boost/)

错误:

/usr/include/boost/graph/detail/adjacency_list.hpp:2665: error: invalid initialization of non-const reference of type ‘boost::detail::error_property_not_found&’ from a temporary of type ‘boost::detail::error_property_not_found’

我认为问题可能在于没有从边到整数的默认映射。如果是这样,我该如何定义?

最佳答案

您的图表没有您在创建 iterator_property_map 时使用的 edge_index 属性。您需要将这样的属性添加到您的图形中并填写它。参见 Boost Graph Library: Bundled Properties and iterating across edgesedge_index zero for all edges?对于需要做的事情。

关于c++ - Boost Graph Library - 来自外部 vector 的权重属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10628882/

相关文章:

c++ - 打印一组 STL 列表

C++ 编写大型二进制文件的任何更快的方法?

c++ - 修改 Boost Multi-Index 项 : modify vs mutable 的非索引字段的最佳方法

c++ - 具有 boost 变体的段错误

c++ - 部分特化不特化任何模板参数

c++ - 对象的变量类型

Django 模板针对不同的 url 呈现不同的方式

c++ - 使用正确的重载集调用多个函数的对象

c++ - 推断成员函数的返回类型

c++ - 在 boost-build (b2) 项目中构建基于 makefile 的依赖项