HOG2
IRDijkstra.h
Go to the documentation of this file.
1 /*
2  * IRDijkstra.h
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 10/9/07.
6  * Copyright 2007 Nathan Sturtevant, University of Alberta. All rights reserved.
7  *
8  */
9 
10 #ifndef IRDijkstra_H
11 #define IRDijkstra_H
12 
13 #include "SearchAlgorithm.h"
14 #include "OpenClosedList.h"
15 #include "FPUtil.h"
16 #include "Graph.h"
17 #include "GraphAbstraction.h"
18 
19 #include <unordered_map>
20 
22 
24  enum {
25  kAbstractionLevel = 0, // this is a LONG label
26  kCorrespondingNode = 1, // this is a LONG label
27  kGCost = 2, // this is a DOUBLE label
28 // kHCost = 3, // this is a DOUBLE label
29 // kOptimalFlag = 4, // this is a LONG label
30 // kInOpenList = 5 // this is a LONG label
31  };
32 
33  struct GNode {
34  GNode(node *nn) :n(nn) {}
35  GNode() :n(0) {}
36  node *n;
37  };
38 
39  struct NodeEqual {
40  bool operator()(const GNode &i1, const GNode &i2) const
41  { return (i1.n->getUniqueID() == i2.n->getUniqueID()); }
42  };
43 
44  struct NodeCompare {
45  // return true if we prefer i2 over i1
46  bool operator()(const GNode &i1, const GNode &i2) const
47  {
48  // return true if node1 has higher g-cost
49  return (fgreater(i1.n->GetLabelF(kGCost),
50  i2.n->GetLabelF(kGCost)));
51  }
52  };
53 
54  struct NodeHash {
55  size_t operator()(const GNode &x) const
56  { return (size_t)(x.n->getUniqueID()); }
57  };
58 
59  typedef OpenClosedList<GNode, NodeHash,
61 
62  typedef std::unordered_map<uint32_t, GNode> NodeLookupTable;
63 }
64 
65 
66 // variables starting with "a" are in the abstraction
67 // variables starting with "g" are in the defined search graph
68 class IRDijkstra : public SearchAlgorithm {
69 public:
70  IRDijkstra();
71  virtual ~IRDijkstra();
72  virtual const char *GetName();
73  virtual path *GetPath(GraphAbstraction *aMap, node *from, node *to, reservationProvider *rp = 0);
75  bool InitializeSearch(GraphAbstraction *aMap, node *from, node *to);
76  void OpenGLDraw() const;
77  int GetNodesRefined() { return nodesRefined; }
78 private:
79  node *FindTopLevelNode(node *one, node *two, GraphAbstraction *aMap);
80  void SetInitialValues(node *gNewNode, node *aRealNode, node *gParent);
81 // void UpdateNode(node *gNode);
82 // void UpdateH(node *gNode);
83 // void UpdateG(node *gNode);
84 // void UpdateOptH(node *gNode);
85 // void MakeNeighborsOpen(node *gNode);
86  void RefineNode(node *gNode);
87  node *GetRealNode(node *gNode) const;
88  bool ShouldAddEdge(node *aLowerNode, node *aHigherNode);
89 
90  void GetAllSolutionNodes(node *goal, std::vector<node*> &nodes);
91  void ExpandNeighbors(node *gNode);
93  path *GetSolution(node *gNode);
94 
95 
103  bool done;
104 };
105 
106 
107 #endif
IRDijkstraConstants::GNode::n
node * n
Definition: IRDijkstra.h:36
IRDijkstra::aStart
node * aStart
Definition: IRDijkstra.h:98
GraphAbstraction
A generic class for basic operations on Graph abstractions.
Definition: GraphAbstraction.h:63
Graph.h
IRDijkstra::closedList
IRDijkstraConstants::NodeLookupTable closedList
Definition: IRDijkstra.h:97
IRDijkstra::gGoal
node * gGoal
Definition: IRDijkstra.h:99
IRDijkstraConstants::NodeHash::operator()
size_t operator()(const GNode &x) const
Definition: IRDijkstra.h:55
IRDijkstra
Definition: IRDijkstra.h:68
IRDijkstra::done
bool done
Definition: IRDijkstra.h:103
SearchAlgorithm.h
IRDijkstra::FindTopLevelNode
node * FindTopLevelNode(node *one, node *two, GraphAbstraction *aMap)
Definition: IRDijkstra.cpp:113
IRDijkstraConstants::kGCost
@ kGCost
Definition: IRDijkstra.h:27
FPUtil.h
IRDijkstra::g
Graph * g
Definition: IRDijkstra.h:101
OpenClosedList.h
IRDijkstra::gStart
node * gStart
Definition: IRDijkstra.h:99
IRDijkstra::GetNodesRefined
int GetNodesRefined()
Definition: IRDijkstra.h:77
Graph
A generic Graph class.
Definition: Graph.h:66
IRDijkstra::ShouldAddEdge
bool ShouldAddEdge(node *aLowerNode, node *aHigherNode)
Definition: IRDijkstra.cpp:457
IRDijkstra::aGoal
node * aGoal
Definition: IRDijkstra.h:98
IRDijkstraConstants::PQueue
OpenClosedList< GNode, NodeHash, NodeEqual, NodeCompare > PQueue
Definition: IRDijkstra.h:60
IRDijkstraConstants
Definition: IRDijkstra.h:21
IRDijkstraConstants::kAbstractionLevel
@ kAbstractionLevel
Definition: IRDijkstra.h:25
IRDijkstraConstants::NodeEqual
Definition: IRDijkstra.h:39
IRDijkstraConstants::NodeCompare::operator()
bool operator()(const GNode &i1, const GNode &i2) const
Definition: IRDijkstra.h:46
IRDijkstra::IRDijkstra
IRDijkstra()
Definition: IRDijkstra.cpp:15
IRDijkstra::q
IRDijkstraConstants::PQueue q
Definition: IRDijkstra.h:96
node::getUniqueID
int getUniqueID() const
Definition: Graph.h:177
OpenClosedList
A simple Heap class.
Definition: OpenClosedList.h:27
IRDijkstra::DoOneSearchStep
path * DoOneSearchStep()
Definition: IRDijkstra.cpp:43
IRDijkstra::OpenGLDraw
void OpenGLDraw() const
Definition: IRDijkstra.cpp:469
fgreater
bool fgreater(double a, double b)
Definition: FPUtil.h:29
IRDijkstraConstants::NodeHash
Definition: IRDijkstra.h:54
IRDijkstra::absGraph
GraphAbstraction * absGraph
Definition: IRDijkstra.h:100
IRDijkstraConstants::GNode
Definition: IRDijkstra.h:33
IRDijkstra::InitializeSearch
bool InitializeSearch(GraphAbstraction *aMap, node *from, node *to)
Definition: IRDijkstra.cpp:88
IRDijkstraConstants::NodeEqual::operator()
bool operator()(const GNode &i1, const GNode &i2) const
Definition: IRDijkstra.h:40
IRDijkstraConstants::NodeLookupTable
std::unordered_map< uint32_t, GNode > NodeLookupTable
Definition: IRDijkstra.h:62
IRDijkstra::ExtractAndRefinePath
path * ExtractAndRefinePath()
Definition: IRDijkstra.cpp:190
node::GetLabelF
double GetLabelF(unsigned int index) const
Definition: Graph.h:215
IRDijkstra::RefineNode
void RefineNode(node *gNode)
Definition: IRDijkstra.cpp:373
IRDijkstra::~IRDijkstra
virtual ~IRDijkstra()
Definition: IRDijkstra.cpp:21
IRDijkstra::nodesRefined
int nodesRefined
Definition: IRDijkstra.h:102
IRDijkstra::GetName
virtual const char * GetName()
Definition: IRDijkstra.cpp:25
IRDijkstra::GetSolution
path * GetSolution(node *gNode)
Definition: IRDijkstra.cpp:251
reservationProvider
Definition: ReservationProvider.h:33
IRDijkstraConstants::NodeCompare
Definition: IRDijkstra.h:44
SearchAlgorithm
A generic algorithm which can be used for pathfinding.
Definition: SearchAlgorithm.h:25
IRDijkstraConstants::GNode::GNode
GNode(node *nn)
Definition: IRDijkstra.h:34
path
A linked list of nodes which form a continuous path.
Definition: Path.h:20
IRDijkstraConstants::kCorrespondingNode
@ kCorrespondingNode
Definition: IRDijkstra.h:26
IRDijkstra::ExpandNeighbors
void ExpandNeighbors(node *gNode)
Definition: IRDijkstra.cpp:164
IRDijkstra::GetRealNode
node * GetRealNode(node *gNode) const
Definition: IRDijkstra.cpp:452
IRDijkstra::SetInitialValues
void SetInitialValues(node *gNewNode, node *aRealNode, node *gParent)
Definition: IRDijkstra.cpp:136
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
GraphAbstraction.h
IRDijkstraConstants::GNode::GNode
GNode()
Definition: IRDijkstra.h:35
IRDijkstra::GetAllSolutionNodes
void GetAllSolutionNodes(node *goal, std::vector< node * > &nodes)
Definition: IRDijkstra.cpp:223
IRDijkstra::GetPath
virtual path * GetPath(GraphAbstraction *aMap, node *from, node *to, reservationProvider *rp=0)
Definition: IRDijkstra.cpp:30