0
我想與頂點的composant拿到頂點描述符,這樣的頂點描述:BGL:獲取數據
struct WayPoint{
std::pair<float, float> pos; // with this composant
};
的adjency列表:
typedef boost::adjacency_list<
boost::listS,
boost::vecS,
boost::undirectedS,
WayPoint,
WayPointConnection
> WayPointGraph;
typedef WayPointGraph::vertex_descriptor WayPointID;
typedef WayPointGraph::edge_descriptor WayPointConnectionID;
我建我的圖表和創建所有的頂點/邊... ....目標是在圖上應用astar。
void PathFinding::findMeAPath(std::pair<float, float>begin, std::pair<float, float>end)
{
std::vector<WayPointID> p(boost::num_vertices(graphe));
std::vector<float> d(boost::num_vertices(graphe));
WayPointID start = // I want to find the WayPointID with begin
WayPointID goal = //same with end;
shortest_path.clear();
try {
boost::astar_search
(
graphe,
start,
boost::astar_heuristic<WayPointGraph, float>(),
boost::predecessor_map(&p[0]).distance_map(&d[0]).visitor(astar_goal_visitor(goal)).weight_map(boost::get(&WayPointConnection::dist, graphe))
);
} catch(found_goal fg) {
for(WayPointID v = goal;; v = p[v]) {
shortest_path.push_front(v);
if(p[v] == v)
break;
}
}
}
首先,d應該使用num_edges,而不是num_vertices。其次,真正的問題是什麼? –