本文整理汇总了C++中PathType::rbegin方法的典型用法代码示例。如果您正苦于以下问题:C++ PathType::rbegin方法的具体用法?C++ PathType::rbegin怎么用?C++ PathType::rbegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathType
的用法示例。
在下文中一共展示了PathType::rbegin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: searchGraph
/**
* @brief Search the graph for a minimun path between originVertex and targetVertex. Returns the path
*
* @param originVertex ...
* @param targetVertex ...
* @param vertexPath std::vector of Vertex with the path
* @return bool
*/
bool PlannerPRM::searchGraph(const Vertex &originVertex, const Vertex &targetVertex, std::vector<Vertex> &vertexPath)
{
qDebug() << __FUNCTION__ << "Searching the graph between " << graph[originVertex].pose << "and " << graph[targetVertex].pose;
// Create things for Dijkstra
std::vector<Vertex> predecessors(boost::num_vertices(graph)); // To store parents
std::vector<float> distances(boost::num_vertices(graph)); // To store distances
//Create a vertex_index property map, since VertexList is listS
typedef std::map<Vertex, size_t>IndexMap;
IndexMap indexMap;
boost::associative_property_map<IndexMap> propmapIndex(indexMap);
//indexing the vertices
int i=0;
BGL_FORALL_VERTICES(v, graph, Graph)
boost::put(propmapIndex, v, i++);
auto predecessorMap = boost::make_iterator_property_map(&predecessors[0], propmapIndex);
auto distanceMap = boost::make_iterator_property_map(&distances[0], propmapIndex);
boost::dijkstra_shortest_paths(graph, originVertex, boost::weight_map(boost::get(&EdgePayload::dist, graph))
.vertex_index_map(propmapIndex)
.predecessor_map(predecessorMap)
.distance_map(distanceMap));
//////////////////////////
// Extract a shortest path
//////////////////////////
PathType path;
Vertex v = targetVertex;
//////////////////////////
// Start by setting 'u' to the destintaion node's predecessor |||// Keep tracking the path until we get to the source
/////////////////////////
for( Vertex u = predecessorMap[v]; u != v; v = u, u = predecessorMap[v]) // Set the current vertex to the current predecessor, and the predecessor to one level up
{
std::pair<Graph::edge_descriptor, bool> edgePair = boost::edge(u, v, graph);
Graph::edge_descriptor edge = edgePair.first;
path.push_back( edge );
}
qDebug() << __FUNCTION__ << " Path found with length: " << path.size() << "steps and length " << distanceMap[targetVertex];
;
Vertex lastVertex;
if(path.size() > 0)
{
vertexPath.clear();
for(PathType::reverse_iterator pathIterator = path.rbegin(); pathIterator != path.rend(); ++pathIterator)
{
vertexPath.push_back(boost::source(*pathIterator, graph));
lastVertex = boost::target(*pathIterator, graph);
}
vertexPath.push_back(lastVertex);
return true;
}
else
{
qDebug() << "Path no found between nodes";
return false;
}
}