HOG2
IncrementalBFS.h
Go to the documentation of this file.
1 //
2 // IncrementalBFS.h
3 // hog2 glut
4 //
5 // Created by Nathan Sturtevant on 3/24/16.
6 // Copyright © 2016 University of Denver. All rights reserved.
7 //
8 
9 #ifndef IncrementalBFS_h
10 #define IncrementalBFS_h
11 
12 #include <deque>
13 
14 template <class state, class action>
16 public:
17  void GetPath(SearchEnvironment<state, action> *env, state from, state to,
18  std::vector<state> &thePath);
19  void GetPath(SearchEnvironment<state, action> *env, state from, state to,
20  std::vector<action> &thePath);
21  bool DoSingleSearchStep(SearchEnvironment<state, action> *env, state from, state to,
22  std::vector<state> &thePath);
23  uint64_t GetNodesExpanded() { return nodesExpanded; }
24  uint64_t GetNodesTouched() { return nodesTouched; }
26  void Reset() { history.clear(); }
27  void OpenGLDraw();
28  void Draw(Graphics::Display &display) const;
29 private:
30  unsigned long nodesExpanded, nodesTouched;
31 
33  state parent, state currState,
34  std::vector<state> &thePath, double bound, double g);
36  action forbiddenAction, state &currState,
37  std::vector<action> &thePath, double bound, double g);
38 
39  std::deque<std::pair<state, int>> history;
40  state goal;
42  std::vector<state> succ;
43 };
44 
45 template <class state, class action>
47  std::vector<state> &thePath)
48 {
49  while (!DoSingleSearchStep(env, from, to, thePath))
50  {}
51 }
52 
53 template <class state, class action>
55  std::vector<action> &thePath)
56 {
57 
58 }
59 
60 template <class state, class action>
62  std::vector<state> &thePath)
63 {
64  if (history.size() == 0)
65  {
66  history.push_back({from, 0});
67  }
68 
69  this->env = env;
70  int depth = history.front().second;
71  env->GetSuccessors(history.front().first, succ);
72 
73  // Later than normal - for the purposes of drawing nicely
74  if (env->GoalTest(history.front().first, to))
75  return true;
76 
77  history.pop_front();
78  for (int x = 0; x < succ.size(); x++)
79  {
80  history.push_back({succ[x], depth+1});
81  }
82  return false;
83 }
84 
85 template <class state, class action>
87 {
88  for (auto x : history)
89  env->OpenGLDraw(x.first);
90 }
91 
92 template <class state, class action>
94 {
95  for (auto x : history)
96  env->Draw(display, x.first);
97 }
98 
99 
100 #endif /* IncrementalBFS_h */
IncrementalBFS::nodesTouched
unsigned long nodesTouched
Definition: IncrementalBFS.h:30
IncrementalBFS::DoIteration
bool DoIteration(SearchEnvironment< state, action > *env, state parent, state currState, std::vector< state > &thePath, double bound, double g)
IncrementalBFS::env
SearchEnvironment< state, action > * env
Definition: IncrementalBFS.h:41
IncrementalBFS::history
std::deque< std::pair< state, int > > history
Definition: IncrementalBFS.h:39
IncrementalBFS::goal
state goal
Definition: IncrementalBFS.h:40
IncrementalBFS::ResetNodeCount
void ResetNodeCount()
Definition: IncrementalBFS.h:25
IncrementalBFS::GetPath
void GetPath(SearchEnvironment< state, action > *env, state from, state to, std::vector< state > &thePath)
Definition: IncrementalBFS.h:46
Graphics::Display
Definition: Graphics.h:146
SearchEnvironment::GetSuccessors
virtual void GetSuccessors(const state &nodeID, std::vector< state > &neighbors) const =0
IncrementalBFS::succ
std::vector< state > succ
Definition: IncrementalBFS.h:42
IncrementalBFS::Draw
void Draw(Graphics::Display &display) const
Definition: IncrementalBFS.h:93
IncrementalBFS::nodesExpanded
unsigned long nodesExpanded
Definition: IncrementalBFS.h:30
IncrementalBFS::DoSingleSearchStep
bool DoSingleSearchStep(SearchEnvironment< state, action > *env, state from, state to, std::vector< state > &thePath)
Definition: IncrementalBFS.h:61
IncrementalBFS::GetNodesExpanded
uint64_t GetNodesExpanded()
Definition: IncrementalBFS.h:23
IncrementalBFS::Reset
void Reset()
Definition: IncrementalBFS.h:26
IncrementalBFS::GetNodesTouched
uint64_t GetNodesTouched()
Definition: IncrementalBFS.h:24
SearchEnvironment::GoalTest
virtual bool GoalTest(const state &node, const state &goal) const =0
IncrementalBFS
Definition: IncrementalBFS.h:15
SearchEnvironment
Definition: SearchEnvironment.h:30
IncrementalBFS::OpenGLDraw
void OpenGLDraw()
Definition: IncrementalBFS.h:86