HOG2
NaryTree.h
Go to the documentation of this file.
1 /*
2  * NaryTree.h
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 10/20/10.
6  * Copyright 2010 University of Denver. All rights reserved.
7  *
8  */
9 
10 
11 #include "SearchEnvironment.h"
12 #include <vector>
13 #include "Graphics.h"
14 
15 #ifndef NARYTREE_H
16 #define NARTTREE_H
17 
18 typedef uint64_t NaryState;
19 typedef int NaryAction;
20 
21 class NaryTree : public SearchEnvironment<NaryState, NaryAction>
22 {
23 public:
24  NaryTree(int branchingFactor, int depth);
25  int GetBranchingFactor() { return b; }
26  NaryState GetLastNode() { return totalNodesAtDepth.back()-1; }
27  NaryState GetParent(NaryState s) const;
28  virtual void GetSuccessors(const NaryState &nodeID, std::vector<NaryState> &neighbors) const;
29  virtual void GetActions(const NaryState &nodeID, std::vector<NaryAction> &actions) const;
30  //virtual int GetNumSuccessors(const NaryState &stateID) const;
31  virtual NaryAction GetAction(const NaryState &s1, const NaryState &s2) const;
32  virtual void ApplyAction(NaryState &s, NaryAction a) const;
33 
34  virtual void GetNextState(const NaryState &, NaryAction , NaryState &) const;
35 
36  virtual bool InvertAction(NaryAction &a) const;
37 
39  virtual double HCost(const NaryState &node1, const NaryState &node2) const;
40 
43  virtual double HCost(const NaryState &node) const
44  { assert(bValidSearchGoal); return HCost(node, searchGoal); }
45 
46  virtual double GCost(const NaryState &node1, const NaryState &node2) const;
47  virtual double GCost(const NaryState &node, const NaryAction &act) const;
48  virtual bool GoalTest(const NaryState &node, const NaryState &goal) const;
49 
51  virtual bool GoalTest(const NaryState &node) const
52  { return bValidSearchGoal&&(node == searchGoal); }
53 
54  virtual uint64_t GetStateHash(const NaryState &node) const;
55  virtual uint64_t GetActionHash(NaryAction act) const;
56 
57  //virtual double GetPathLength(std::vector<NaryState> &neighbors);
58  void SetWidthScale(double v) { scaleWidth = v;}
59  virtual void OpenGLDraw() const;
60  virtual void OpenGLDraw(const NaryState&) const;
62  virtual void OpenGLDraw(const NaryState&, const NaryState&, float) const;
63  virtual void OpenGLDraw(const NaryState&, const NaryAction&) const;
64  //virtual void GLLabelState(const state&, const char *) const {} // draw label over state
65  void GLDrawLine(const NaryState &x, const NaryState &y) const;
66 
67  virtual void Draw(Graphics::Display &display) const;
68  virtual void Draw(Graphics::Display &display, const NaryState &s) const;
69  virtual void DrawLine(Graphics::Display &display, const NaryState &, const NaryState &, float width) const;
70 
71 
72  NaryState GetClosestNode(float x, float y);
73 private:
74  int GetDepth(const NaryState s) const;
75  float GetDepthRadius(int depth) const;
76  uint64_t GetOffset(const NaryState s) const;
77  void GetLocation(const NaryState &s, float &x, float &y) const;
78  int b, d;
79  std::vector<uint64_t> nodesAtDepth;
80  std::vector<uint64_t> totalNodesAtDepth;
81  double scaleWidth;
82 };
83 
84 #endif
NaryTree::OpenGLDraw
virtual void OpenGLDraw() const
Definition: NaryTree.cpp:163
NaryTree::d
int d
Definition: NaryTree.h:78
NaryTree::HCost
virtual double HCost(const NaryState &node1, const NaryState &node2) const
Heuristic value between two arbitrary nodes.
Definition: NaryTree.cpp:84
NaryTree::GetOffset
uint64_t GetOffset(const NaryState s) const
Definition: NaryTree.cpp:144
NaryTree::DrawLine
virtual void DrawLine(Graphics::Display &display, const NaryState &, const NaryState &, float width) const
Definition: NaryTree.cpp:263
NaryTree::GetClosestNode
NaryState GetClosestNode(float x, float y)
Definition: NaryTree.cpp:106
NaryTree::GetLocation
void GetLocation(const NaryState &s, float &x, float &y) const
Definition: NaryTree.cpp:124
NaryTree::Draw
virtual void Draw(Graphics::Display &display) const
Definition: NaryTree.cpp:211
NaryTree::totalNodesAtDepth
std::vector< uint64_t > totalNodesAtDepth
Definition: NaryTree.h:80
width
int width
Definition: SFML_HOG.cpp:54
NaryTree::HCost
virtual double HCost(const NaryState &node) const
Heuristic value between node and the stored goal.
Definition: NaryTree.h:43
NaryTree::GetBranchingFactor
int GetBranchingFactor()
Definition: NaryTree.h:25
NaryTree::GetDepth
int GetDepth(const NaryState s) const
Definition: NaryTree.cpp:135
NaryTree::GetActions
virtual void GetActions(const NaryState &nodeID, std::vector< NaryAction > &actions) const
Definition: NaryTree.cpp:42
NaryTree::ApplyAction
virtual void ApplyAction(NaryState &s, NaryAction a) const
Definition: NaryTree.cpp:59
NaryTree::b
int b
Definition: NaryTree.h:78
NaryTree::SetWidthScale
void SetWidthScale(double v)
Definition: NaryTree.h:58
SearchEnvironment< NaryState, NaryAction >::searchGoal
NaryState searchGoal
Definition: SearchEnvironment.h:113
NaryTree::GoalTest
virtual bool GoalTest(const NaryState &node) const
Goal Test if the goal is stored.
Definition: NaryTree.h:51
SearchEnvironment< NaryState, NaryAction >::bValidSearchGoal
bool bValidSearchGoal
Definition: SearchEnvironment.h:112
NaryTree::nodesAtDepth
std::vector< uint64_t > nodesAtDepth
Definition: NaryTree.h:79
Graphics::Display
Definition: Graphics.h:146
NaryTree
Definition: NaryTree.h:21
NaryTree::GCost
virtual double GCost(const NaryState &node1, const NaryState &node2) const
Definition: NaryTree.cpp:87
NaryTree::GetDepthRadius
float GetDepthRadius(int depth) const
Definition: NaryTree.cpp:245
NaryTree::GetActionHash
virtual uint64_t GetActionHash(NaryAction act) const
Definition: NaryTree.cpp:98
NaryTree::GetStateHash
virtual uint64_t GetStateHash(const NaryState &node) const
Definition: NaryTree.cpp:95
NaryTree::GoalTest
virtual bool GoalTest(const NaryState &node, const NaryState &goal) const
Definition: NaryTree.cpp:91
NaryState
uint64_t NaryState
Definition: NaryTree.h:18
NaryTree::GetLastNode
NaryState GetLastNode()
Definition: NaryTree.h:26
Graphics.h
NaryTree::InvertAction
virtual bool InvertAction(NaryAction &a) const
Definition: NaryTree.cpp:80
NaryAction
int NaryAction
Definition: NaryTree.h:19
NaryTree::GetNextState
virtual void GetNextState(const NaryState &, NaryAction, NaryState &) const
Definition: NaryTree.cpp:70
NaryTree::scaleWidth
double scaleWidth
Definition: NaryTree.h:81
NaryTree::GLDrawLine
void GLDrawLine(const NaryState &x, const NaryState &y) const
Definition: NaryTree.cpp:195
NaryTree::NaryTree
NaryTree(int branchingFactor, int depth)
Definition: NaryTree.cpp:14
NaryTree::GetSuccessors
virtual void GetSuccessors(const NaryState &nodeID, std::vector< NaryState > &neighbors) const
Definition: NaryTree.cpp:32
NaryTree::GetParent
NaryState GetParent(NaryState s) const
Definition: NaryTree.cpp:156
SearchEnvironment
Definition: SearchEnvironment.h:30
NaryTree::GetAction
virtual NaryAction GetAction(const NaryState &s1, const NaryState &s2) const
Definition: NaryTree.cpp:53
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
SearchEnvironment.h