本文整理汇总了C++中PathType::push_front方法的典型用法代码示例。如果您正苦于以下问题:C++ PathType::push_front方法的具体用法?C++ PathType::push_front怎么用?C++ PathType::push_front使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathType
的用法示例。
在下文中一共展示了PathType::push_front方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getPath
PathType getPath(const GraphAdapterType& graphAdapter, const NodeAdapterType& start, const std::function<bool(const NodeAdapterType&)>& endCondition) const {
PathType resultPath;
struct NodePositionComparator {
bool operator() (const NodeAdapterType& lhs, const NodeAdapterType& rhs) {
return lhs.position < rhs.position;
}
};
std::set<NodeAdapterType> open = { start };
std::set<NodeAdapterType, NodePositionComparator> closed;
std::map<NodeAdapterType, NodeAdapterType, NodePositionComparator> came_from;
typename std::set<NodeAdapterType>::iterator current;
while(open.empty() == false) {
current = open.begin();
if(endCondition(*current) == true) {
// Goal found, recreating path from 'goal' node to 'start' node
resultPath.push_front(current->position);
auto pathCurrent = came_from.find(*current);
if(pathCurrent != came_from.end()) {
while(pathCurrent->second.position != start.position) {
resultPath.push_front(pathCurrent->second.position);
pathCurrent = came_from.find(pathCurrent->second);
}
}
return resultPath;
}
closed.insert(*current);
std::vector<NodeAdapterType> neighbours = graphAdapter.getNeighboursOf(*current);
for(NodeAdapterType& neighbour : neighbours) {
if(graphAdapter.isAvailable(neighbour.position)) {
typename std::set<NodeAdapterType>::iterator cIter, oIter;
cIter = closed.find(neighbour);
if(cIter != closed.end()) {
continue;
}
neighbour.g(current->g() + 1);
neighbour.h(graphAdapter.getHeuristicCostLeft(neighbour, neighbour));
oIter = open.find(neighbour);
if(oIter == open.end() || neighbour.g() < oIter->g()) {
if(oIter != open.end()) {
open.erase(oIter);
}
auto cameFromIter = came_from.find(neighbour);
if(cameFromIter != came_from.end()) {
if(cameFromIter->second.g() > neighbour.g()) {
came_from.erase(cameFromIter);
}
}
came_from.emplace(std::pair<NodeAdapterType, NodeAdapterType>(neighbour, *current));
open.insert(neighbour);
}
}
}
open.erase(current);
}
// If algorithm comes here, no path was found, and return value of this method will be empty vector
return resultPath;
}