This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/nav/dijkstra/DijkstraStructs.h
kazu cdf97322f8 added new data-structures
added new test-cases
added flexible dijkstra calculation
added debugging log
modified: plotting, grid-generation, grid-importance,
refactoring
2016-01-22 18:47:06 +01:00

78 lines
1.8 KiB
C++

#ifndef DIJKSTRANODE_H
#define DIJKSTRANODE_H
/**
* wrapper around a user data structure
* adds additional fields needed for dijkstra calculation
*/
template <typename T> struct DijkstraNode {
/** pos infinity */
static constexpr float INF = +99999999;
/** the user-element this node describes */
const T* element;
/** the previous dijkstra node (navigation path) */
DijkstraNode<T>* previous;
/** the weight from the start up to this element */
float cumWeight;
// /** ctor */
// DijkstraNode() : element(nullptr), previous(), cumWeight(INF) {;}
/** ctor */
DijkstraNode(const T* element) : element(element), previous(), cumWeight(INF) {;}
/** equal? (bi-dir) */
bool operator == (const DijkstraNode<T>& other) {
return element == other.element;
}
};
/**
* data structure describing the connection between two nodes
* only used to track already processed connections!
*/
template <typename T> struct DijkstraEdge {
/** the edge's source */
const DijkstraNode<T>* src;
/** the edge's destination */
const DijkstraNode<T>* dst;
/** ctor */
DijkstraEdge(const DijkstraNode<T>* src, const DijkstraNode<T>* dst) : src(src), dst(dst) {;}
/** equal? (bi-dir) */
bool operator == (const DijkstraEdge& other) const {
return ((dst == other.dst) && (src == other.src)) ||
((src == other.dst) && (dst == other.src));
}
};
//template <typename T> struct DijkstraEdgeWeighted : public DijkstraEdge<T> {
// /** the edge's weight */
// float weight;
// DijkstraEdgeWeighted(const DijkstraNode<T>* src, const DijkstraNode<T>* dst, const float weight) : DijkstraEdge<T>(src,dst), weight(weight) {;}
//};
namespace std {
template <typename T> struct hash<DijkstraEdge<T>>{
size_t operator()(const DijkstraEdge<T>& e) const {
return hash<size_t>()( (size_t)e.src^(size_t)e.dst);
}
};
}
#endif // DIJKSTRANODE_H