我做错了什么?
#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 edges和 edge_index zero for all edges?对于需要做的事情。
关于c++ - Boost Graph Library - 来自外部 vector 的权重属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10628882/