【发布时间】:2018-05-15 13:10:20
【问题描述】:
我是 boost 图表库的新手,我正在尝试使用 boost 图表库在图表中找到从一个顶点到另一个顶点的最短路径。我找到了一些关于如何使用前任地图的说明来做到这一点,但它对我不起作用。当我尝试调用 p[some_vertex] 时,我收到一条错误消息,指出 [] 运算符未定义。谁能告诉我为什么以及我做错了什么?
typedef property<edge_weight_t, double, property<edge_index_t, tElementIDVector>> tEdgeProperty;
typedef property<vertex_index_t, tElementID> VertexIDPorperty;
typedef adjacency_list<vecS, setS, directedS, VertexIDPorperty, tEdgeProperty> tGraph;
typedef tGraph::vertex_descriptor tVertex;
typedef tGraph::edge_descriptor tEdge;
vector<tVertex> p(num_vertices(graph));
vector<double> d(num_vertices(graph));
// call dijkstra algorithm from boost to find shortest path
dijkstra_shortest_paths(graph, s,
predecessor_map(&p[0]).
distance_map(boost::make_iterator_property_map(d.begin(), get(boost::vertex_index, graph))));
//find path from start to end vertex
list<tVertex> pathVertices;
tVertex current = goal;
while (current != start)
{
pathVertices.push_front(current);
current = p[current]; //this is where the error occures
}
【问题讨论】:
标签: c++ boost graph shortest-path