也许这是一个愚蠢的问题,但我正在尝试使用 BGL dijkstra_shortest_paths
,特别是使用我的 Edge 捆绑属性的字段作为权重图。我的尝试目前导致了数十页的编译器错误,所以我希望有人知道如何帮助我。这基本上就是我的代码的样子:
struct GraphEdge {
float length;
// other cruft
};
struct GraphVertex {
...
};
typedef boost::adjacency_list
<boost::vecS, boost::vecS, boost::directedS,
GraphVertex, GraphEdge> GraphType;
我可以毫无问题地填充图表,但是在调用时dijkstra_shortest_paths
,我遇到了麻烦。我想使用该length
字段。具体来说,我想知道在这样的电话中需要什么提升巫术:
GraphType m_graph;
vector<int> predecessor(num_vertices(m_graph));
vector<float> distances(num_vertices(m_graph), 0.0f);
vector<int> vertex_index_map(num_vertices(m_graph));
for (size_t i=0; i<vertex_index_map.size(); ++i) {
vertex_index_map[i] = i;
}
dijkstra_shortest_paths(m_graph, vertex_from, predecessor, distances,
weightmap, vertex_index_map,
std::less<float>(), closed_plus<float>(),
(std::numeric_limits<float>::max)(), 0.0f,
default_dijkstra_visitor());
// How do I write the right version of weightmap here?
这样 weightmap 将以某种方式将我的图形的特定边缘与length
属性中的相应字段相关联。我确信有一种简单的方法可以做到这一点,但是 BGL 的文档对我来说非常不透明。如果您能告诉我该示例在文档中的哪个位置进行了描述,我也会很高兴。
先感谢您!