added new helper methods

worked on gridWalker v3
This commit is contained in:
2017-10-17 13:01:26 +02:00
parent 556bbe8829
commit 3807c621c7
8 changed files with 299 additions and 42 deletions

View File

@@ -30,11 +30,16 @@ public:
}
/** get the dijkstra-pendant for the given user-node. null if none matches */
const inline DijkstraNode<T>* getNode(const T& userNode) const {
inline const DijkstraNode<T>* getNode(const T& userNode) const {
auto it = nodes.find(&userNode);
return (unlikely(it == nodes.end())) ? (nullptr) : (it->second);
}
/** get all constructed dijkstra-nodes and their original pendant */
inline const std::unordered_map<const T*, DijkstraNode<T>*>& getNodes() const {
return nodes;
}
/** calculate all shortest paths from ANY node to the given destination */
template <typename Access> void build(const T* end, const Access& acc) {
build(end, nullptr, acc, NAN);
@@ -80,7 +85,7 @@ public:
if (end != nullptr && dnSrc->element == end) {Log::add("Dijkstra", "reached target node"); break;}
// when a maximum weight is given, stop when current cum-dist > maxWeight
if (maxWeight != 0 && dnSrc->cumWeight > maxWeight) {Log::add("Dijkstra", "reached distance limit"); break;}
if (maxWeight != 0 && dnSrc->cumWeight > maxWeight) {Log::add("Dijkstra", "reached weight limit: " + std::to_string(maxWeight)); break;}
// visit (and maybe update) each neighbor of the current element
for (int i = 0; i < acc.getNumNeighbors(*dnSrc->element); ++i) {