HOG2
IRAStar.h
Go to the documentation of this file.
1 /*
2  * IRAStar.h
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 10/12/07.
6  * Copyright 2007 Nathan Sturtevant, University of Alberta. All rights reserved.
7  *
8  */
9 
10 #ifndef IRAStar_H
11 #define IRAStar_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 
21 namespace IRAStarConstants {
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  //kCachedHCost1 = 4, // this is a DOUBLE label
30  //kCachedHCost2 = 5, // this is a DOUBLE label
31  //kIteration = 6, // this is a LONG label
32  // kOptimalFlag = 4, // this is a LONG label
33  // kInOpenList = 5 // this is a LONG label
34  };
35 
37  enum Caching {
41  };
42 
43  struct GNode {
44  GNode(node *nn) :n(nn) {}
45  GNode() :n(0) {}
46  node *n;
47  };
48 
49  struct NodeEqual {
50  bool operator()(const GNode &i1, const GNode &i2) const
51  { return (i1.n->getUniqueID() == i2.n->getUniqueID()); }
52  };
53 
54  struct NodeCompare {
55  // return true if we prefer i2 over i1
56  bool operator()(const GNode &i1, const GNode &i2) const
57  {
58  // return true if node1 has higher f-cost
59  return (fgreater(i1.n->GetLabelF(kGCost)+i1.n->GetLabelF(kHCost),
60  i2.n->GetLabelF(kGCost)+i2.n->GetLabelF(kHCost)));
61  }
62  };
63 
64  struct NodeHash {
65  size_t operator()(const GNode &x) const
66  { return (size_t)(x.n->getUniqueID()); }
67  };
68 
69  typedef OpenClosedList<GNode, NodeHash,
71 
72  typedef std::unordered_map<uint32_t, GNode> NodeLookupTable;
73 }
74 
75 
76 // variables starting with "a" are in the abstraction
77 // variables starting with "g" are in the defined search graph
78 class IRAStar : public SearchAlgorithm {
79 public:
80  //IRAStar( );
82  virtual ~IRAStar();
83  virtual const char *GetName();
84  virtual path *GetPath(GraphAbstraction *aMap, node *from, node *to, reservationProvider *rp = 0);
86  bool InitializeSearch(GraphAbstraction *aMap, node *from, node *to);
87  void OpenGLDraw() const;
88  int GetNodesRefined() { return nodesRefined; }
89 private:
90  node *FindTopLevelNode(node *one, node *two, GraphAbstraction *aMap);
91  void SetInitialValues(node *gNewNode, node *aRealNode, node *gParent);
92  // void UpdateNode(node *gNode);
93  // void UpdateH(node *gNode);
94  // void UpdateG(node *gNode);
95  // void UpdateOptH(node *gNode);
96  // void MakeNeighborsOpen(node *gNode);
97  void RefineNode(node *gNode);
98  node *GetRealNode(node *gNode) const;
99  bool ShouldAddEdge(node *aLowerNode, node *aHigherNode);
100 
101  void GetAllSolutionNodes(node *goal, std::vector<node*> &nodes);
102  bool Inconsistent(node *gNode);
103  void ExpandNeighbors(node *gNode);
105  path *GetSolution(node *gNode);
106  void SetHValues(int f);
107  double GetHCost(node *) const;
108  void SetHCost(node *, double);
109  //double GetCachedHCost(node *);
110  //void SetCachedHCost(node *, double);
111  double GetGCost(node *) const;
112  void SetGCost(node *, double);
113  double GetFCost(node *) const;
114 
124  std::vector<double> iterationLimits;
125  bool done;
126 };
127 
128 
129 #endif
GraphAbstraction
A generic class for basic operations on Graph abstractions.
Definition: GraphAbstraction.h:63
IRAStar::SetHCost
void SetHCost(node *, double)
Definition: IRAStar.cpp:629
IRAStarConstants::PQueue
OpenClosedList< GNode, NodeHash, NodeEqual, NodeCompare > PQueue
Definition: IRAStar.h:70
IRAStar::ExpandNeighbors
void ExpandNeighbors(node *gNode)
Definition: IRAStar.cpp:230
Graph.h
IRAStar::g
Graph * g
Definition: IRAStar.h:120
IRAStar::GetAllSolutionNodes
void GetAllSolutionNodes(node *goal, std::vector< node * > &nodes)
Definition: IRAStar.cpp:335
IRAStar::aGoal
node * aGoal
Definition: IRAStar.h:117
IRAStar::gGoal
node * gGoal
Definition: IRAStar.h:118
IRAStar::caching
IRAStarConstants::Caching caching
Definition: IRAStar.h:123
IRAStar::GetGCost
double GetGCost(node *) const
Definition: IRAStar.cpp:657
IRAStarConstants::GNode
Definition: IRAStar.h:43
IRAStar::gStart
node * gStart
Definition: IRAStar.h:118
SearchAlgorithm.h
IRAStar::absGraph
GraphAbstraction * absGraph
Definition: IRAStar.h:119
IRAStar::done
bool done
Definition: IRAStar.h:125
IRAStar::Inconsistent
bool Inconsistent(node *gNode)
Definition: IRAStar.cpp:192
IRAStarConstants::NodeCompare
Definition: IRAStar.h:54
IRAStarConstants
Definition: IRAStar.h:21
FPUtil.h
IRAStar::GetRealNode
node * GetRealNode(node *gNode) const
Definition: IRAStar.cpp:470
OpenClosedList.h
IRAStar::currentIteration
int currentIteration
Definition: IRAStar.h:122
Graph
A generic Graph class.
Definition: Graph.h:66
IRAStarConstants::OPTIMAL_PATH_CACHING
@ OPTIMAL_PATH_CACHING
Definition: IRAStar.h:39
IRAStar::SetInitialValues
void SetInitialValues(node *gNewNode, node *aRealNode, node *gParent)
Definition: IRAStar.cpp:155
IRAStar::GetHCost
double GetHCost(node *) const
Definition: IRAStar.cpp:619
IRAStarConstants::kGCost
@ kGCost
Definition: IRAStar.h:27
IRAStar::GetPath
virtual path * GetPath(GraphAbstraction *aMap, node *from, node *to, reservationProvider *rp=0)
Definition: IRAStar.cpp:34
IRAStar
Definition: IRAStar.h:78
IRAStarConstants::GNode::n
node * n
Definition: IRAStar.h:46
IRAStar::GetFCost
double GetFCost(node *) const
Definition: IRAStar.cpp:667
IRAStar::OpenGLDraw
void OpenGLDraw() const
Definition: IRAStar.cpp:487
IRAStarConstants::NodeLookupTable
std::unordered_map< uint32_t, GNode > NodeLookupTable
Definition: IRAStar.h:72
IRAStar::GetNodesRefined
int GetNodesRefined()
Definition: IRAStar.h:88
IRAStar::FindTopLevelNode
node * FindTopLevelNode(node *one, node *two, GraphAbstraction *aMap)
Definition: IRAStar.cpp:132
IRAStarConstants::Caching
Caching
Definitions for the constructor.
Definition: IRAStar.h:37
IRAStar::SetHValues
void SetHValues(int f)
Definition: IRAStar.cpp:599
IRAStar::SetGCost
void SetGCost(node *, double)
Definition: IRAStar.cpp:662
IRAStar::GetName
virtual const char * GetName()
Definition: IRAStar.cpp:29
node::getUniqueID
int getUniqueID() const
Definition: Graph.h:177
OpenClosedList
A simple Heap class.
Definition: OpenClosedList.h:27
IRAStarConstants::NodeHash::operator()
size_t operator()(const GNode &x) const
Definition: IRAStar.h:65
IRAStarConstants::P_G_CACHING
@ P_G_CACHING
Definition: IRAStar.h:40
IRAStar::nodesRefined
int nodesRefined
Definition: IRAStar.h:121
IRAStar::InitializeSearch
bool InitializeSearch(GraphAbstraction *aMap, node *from, node *to)
Definition: IRAStar.cpp:106
IRAStarConstants::NodeHash
Definition: IRAStar.h:64
IRAStarConstants::NO_CACHING
@ NO_CACHING
Definition: IRAStar.h:38
fgreater
bool fgreater(double a, double b)
Definition: FPUtil.h:29
IRAStarConstants::kCorrespondingNode
@ kCorrespondingNode
Definition: IRAStar.h:26
IRAStar::~IRAStar
virtual ~IRAStar()
Definition: IRAStar.cpp:25
IRAStarConstants::NodeEqual
Definition: IRAStar.h:49
IRAStar::GetSolution
path * GetSolution(node *gNode)
Definition: IRAStar.cpp:363
IRAStarConstants::GNode::GNode
GNode()
Definition: IRAStar.h:45
IRAStar::ExtractAndRefinePath
path * ExtractAndRefinePath()
Definition: IRAStar.cpp:281
node::GetLabelF
double GetLabelF(unsigned int index) const
Definition: Graph.h:215
IRAStar::RefineNode
void RefineNode(node *gNode)
Definition: IRAStar.cpp:383
IRAStar::ShouldAddEdge
bool ShouldAddEdge(node *aLowerNode, node *aHigherNode)
Definition: IRAStar.cpp:475
IRAStarConstants::kAbstractionLevel
@ kAbstractionLevel
Definition: IRAStar.h:25
reservationProvider
Definition: ReservationProvider.h:33
SearchAlgorithm
A generic algorithm which can be used for pathfinding.
Definition: SearchAlgorithm.h:25
IRAStar::q
IRAStarConstants::PQueue q
Definition: IRAStar.h:115
IRAStarConstants::NodeCompare::operator()
bool operator()(const GNode &i1, const GNode &i2) const
Definition: IRAStar.h:56
path
A linked list of nodes which form a continuous path.
Definition: Path.h:20
IRAStar::IRAStar
IRAStar(IRAStarConstants::Caching caching=IRAStarConstants::P_G_CACHING)
Definition: IRAStar.cpp:19
IRAStarConstants::NodeEqual::operator()
bool operator()(const GNode &i1, const GNode &i2) const
Definition: IRAStar.h:50
IRAStar::aStart
node * aStart
Definition: IRAStar.h:117
IRAStar::iterationLimits
std::vector< double > iterationLimits
Definition: IRAStar.h:124
IRAStarConstants::kHCost
@ kHCost
Definition: IRAStar.h:28
IRAStar::closedList
IRAStarConstants::NodeLookupTable closedList
Definition: IRAStar.h:116
IRAStar::DoOneSearchStep
path * DoOneSearchStep()
Definition: IRAStar.cpp:47
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
GraphAbstraction.h
IRAStarConstants::GNode::GNode
GNode(node *nn)
Definition: IRAStar.h:44