HOG2
OptimisticSearch.h
Go to the documentation of this file.
1 //
2 // OptimisitcSearch.h
3 // HOG2 Demos
4 //
5 // Created by Nathan Sturtevant on 5/24/16.
6 // Copyright © 2016 NS Software. All rights reserved.
7 //
8 
9 #ifndef OptimisitcSearch_h
10 #define OptimisitcSearch_h
11 
12 
13 #include <iostream>
14 #include "FPUtil.h"
15 #include <unordered_map>
16 #include "AStarOpenClosed.h"
17 #include "BucketOpenClosed.h"
18 #include "TemplateAStar.h"
19 //#include "SearchEnvironment.h" // for the SearchEnvironment class
20 #include "float.h"
21 #include <algorithm> // for vector reverse
22 #include "GenericSearchAlgorithm.h"
23 
24 template<typename state>
26 public:
28  OptimisticOpenClosedData(const state &theData, double gCost, double hCost, uint64_t parent, uint64_t openLoc, dataLocation location)
29  :data(theData), g(gCost), h(hCost), parentID(parent), openLocation(openLoc), where(location)
30  { reopened = false; openedFromF = false; }
31  state data;
32  double g;
33  double h;
35  uint64_t parentID;
36  uint64_t openLocation;
37  bool reopened;
39 };
40 
41 template <class state>
43  // returns true if i2 is preferred over i1
45  {
46  if (fequal(i1.g+i1.h, i2.g+i2.h))
47  {
48  return (fless(i1.g, i2.g));
49  }
50  return fgreater(i1.g+i1.h, i2.g+i2.h);
51  }
52 };
53 
57 template <class state, class action, class environment>
58 class OptimisticSearch : public GenericSearchAlgorithm<state,action,environment> {
59 public:
61  virtual ~OptimisticSearch() {}
62  void GetPath(environment *env, const state& from, const state& to, std::vector<state> &thePath);
63  void GetPath(environment *, const state& , const state& , std::vector<action> & );
64 
66  // uses admissible heuristic (regular A* search)
68  // uses inadmissible heuristic
70  state goal, start;
71 
72  bool InitializeSearch(environment *env, const state& from, const state& to, std::vector<state> &thePath);
73  bool DoSingleSearchStep(std::vector<state> &thePath);
74  void AddAdditionalStartState(state& newState);
75  void AddAdditionalStartState(state& newState, double cost);
76 
77  state CheckNextNode();
78  void ExtractPathToStart(state &node, std::vector<state> &thePath)
79  { uint64_t theID; fhat.Lookup(env->GetStateHash(node), theID); ExtractPathToStartFromID(theID, thePath); }
80  void ExtractPathToStartFromID(uint64_t node, std::vector<state> &thePath);
81  const state &GetParent(const state &s);
82  virtual const char *GetName();
83 
84  void PrintStats();
87  int GetMemoryUsage();
88 
89  bool GetClosedListGCost(const state &val, double &gCost) const;
90  bool GetOpenListGCost(const state &val, double &gCost) const;
91  bool GetFocalListGCost(const state &val, double &gCost) const;
92  bool GetClosedItem(const state &s, OptimisticOpenClosedData<state> &);
93  unsigned int GetNumOpenItems() { return f.OpenSize(); }
94  inline const OptimisticOpenClosedData<state> &GetOpenItem(unsigned int which) { return f.Lookat(f.GetOpenItem(which)); }
95  unsigned int GetNumFocalItems() { return fhat.OpenSize(); }
96  inline const OptimisticOpenClosedData<state> &GetFocalItem(unsigned int which) { return fhat.Lookat(fhat.GetOpenItem(which)); }
97 
99  {
100  uint64_t key = f.Peek();
101  return f.Lookup(key).data;
102  }
104  {
105  uint64_t key = fhat.Peek();
106  return fhat.Lookup(key).data;
107  }
108 
109 
110  inline const int GetNumItems() { return fhat.size(); }
111  inline const OptimisticOpenClosedData<state> &GetItem(unsigned int which) { return fhat.Lookat(which); }
112  bool HaveExpandedState(const state &val)
113  { uint64_t key; return fhat.Lookup(env->GetStateHash(val), key) != kNotFound; }
114  dataLocation GetStateLocation(const state &val)
115  { uint64_t key; return fhat.Lookup(env->GetStateHash(val), key); }
116 
117  void SetReopenNodes(bool re) { reopenNodes = re; }
118  bool GetReopenNodes() { return reopenNodes; }
119 
121 
122  uint64_t GetNodesExpanded() const { return nodesExpanded; }
123  uint64_t GetNodesTouched() const { return nodesTouched; }
124 
126 
127  void OpenGLDraw() const;
128  void Draw(Graphics::Display &d) const;
129 
130  void SetWeight(double w) {weight = w;}
131  double GetWeight() { return weight; }
132  void SetOptimalityBound(double w) {bound = w;}
133  double GetOptimalityBound() {return bound;}
134 private:
136 
137  std::vector<state> neighbors;
138 // std::vector<uint64_t> neighborID;
139 // std::vector<double> edgeCosts;
140 // std::vector<dataLocation> neighborLoc;
141  environment *env;
142  double bestSolution;
143  double weight;
144  double bound;
148 };
149 
150 //static const bool verbose = false;
151 
160 template <class state, class action, class environment>
162 {
163  static char name[32];
164  sprintf(name, "OptimisticSearch[%1.2f, %1.2f]", bound, weight);
165  return name;
166 }
167 
179 template <class state, class action, class environment>
180 void OptimisticSearch<state,action,environment>::GetPath(environment *_env, const state& from, const state& to, std::vector<state> &thePath)
181 {
182  //discardcount=0;
183  if (!InitializeSearch(_env, from, to, thePath))
184  {
185  return;
186  }
187  while (!DoSingleSearchStep(thePath))
188  {
189  // if (0 == nodesExpanded%100000)
190  // printf("%" PRId64 " nodes expanded\n", nodesExpanded);
191  }
192 }
193 
194 template <class state, class action, class environment>
195 void OptimisticSearch<state,action,environment>::GetPath(environment *_env, const state& from, const state& to, std::vector<action> &path)
196 {
197  std::vector<state> thePath;
198  if (!InitializeSearch(_env, from, to, thePath))
199  {
200  return;
201  }
202  path.resize(0);
203  while (!DoSingleSearchStep(thePath))
204  {
205  }
206  for (int x = 0; x < thePath.size()-1; x++)
207  {
208  path.push_back(_env->GetAction(thePath[x], thePath[x+1]));
209  }
210 }
211 
212 
223 template <class state, class action, class environment>
224 bool OptimisticSearch<state,action,environment>::InitializeSearch(environment *_env, const state& from, const state& to, std::vector<state> &thePath)
225 {
226 
227  if (theHeuristic == 0)
228  theHeuristic = _env;
229  thePath.resize(0);
230  env = _env;
231  fhat.Reset(env->GetMaxHash());
232  f.Reset(env->GetMaxHash());
233  ResetNodeCount();
234  start = from;
235  goal = to;
236 
237  if (env->GoalTest(from, to)) //assumes that from and to are valid states
238  {
239  return false;
240  }
241 
242  // 1. openf ← {initial}
243  // 2. openfhat ← {initial}
244  // 3. incumbent ← ∞
245  fhat.AddOpenNode(start, env->GetStateHash(start), 0, weight*theHeuristic->HCost(start, goal));
246  f.AddOpenNode(start, env->GetStateHash(start), 0, theHeuristic->HCost(start, goal));
247  bestSolution = DBL_MAX;
248 
249  return true;
250 }
251 
257 template <class state, class action, class environment>
259 {
260  fhat.AddOpenNode(newState, env->GetStateHash(newState), 0, weight*theHeuristic->HCost(start, goal));
261  f.AddOpenNode(newState, env->GetStateHash(newState), 0, theHeuristic->HCost(start, goal));
262 }
263 
269 template <class state, class action, class environment>
271 {
272  fhat.AddOpenNode(newState, env->GetStateHash(newState), cost, weight*theHeuristic->HCost(start, goal));
273  f.AddOpenNode(newState, env->GetStateHash(newState), cost, theHeuristic->HCost(start, goal));
274 }
275 
286 template <class state, class action, class environment>
288 {
289  if (fhat.OpenSize() == 0)
290  {
291  printf("No path\n");
292  thePath.resize(0); // no path found!
293  //closedList.clear();
294  return true;
295  }
296 
297  // 4. repeat until bound · f (first on openf ) ≥ f (incumbent):
298  if (bound*(f.Lookat(f.Peek()).g+f.Lookat(f.Peek()).h) >= bestSolution)
299  {
300  // proven within bound
301  printf("Best solution %1.2f\n", bestSolution);
302  printf("Best on open %1.2f - bound is %1.2f\n", f.Lookat(f.Peek()).g+f.Lookat(f.Peek()).h,
303  (f.Lookat(f.Peek()).g+f.Lookat(f.Peek()).h)*bound);
304  ExtractPathToStart(goal, thePath);
305  // Path is backwards - reverse
306  reverse(thePath.begin(), thePath.end());
307  return true;
308  }
309 
310  uint64_t nodeOnFHat;
311  uint64_t nodeOnF;
312  // only reopen states taken from f, not fhat
313  bool reopen = true;
314  double oldF = f.Lookat(f.Peek()).g+f.Lookat(f.Peek()).h;
315 
316  // 5. if f (first on open fhat) < f (incumbent) then
317  if (fless(fhat.Lookat(fhat.Peek()).g+fhat.Lookat(fhat.Peek()).h, bestSolution))
318  {
319  // 6. n ← remove first on openfhat
320  // 7. remove n from openf
321  nodeOnFHat = fhat.Close();
322  reopen = false;
323  dataLocation d = f.Lookup(env->GetStateHash(fhat.Lookup(nodeOnFHat).data), nodeOnF);
324  assert(d != kNotFound);
325 
326  // 10. add n to closed
327  f.Close(nodeOnF);
328  }
329  else {
330  // 8. else n ← remove first on openf
331  // 9. remove n from openfhat
332 
333  nodeOnF = f.Close();
334  f.Lookup(nodeOnF).openedFromF = true;
335  reopen = true;
336  dataLocation d = fhat.Lookup(env->GetStateHash(f.Lookup(nodeOnF).data), nodeOnFHat);
337  assert(d != kNotFound);
338  if (d == kOpenList)
339  {
340  fhat.Close(nodeOnFHat);
341  d = fhat.Lookup(env->GetStateHash(f.Lookup(nodeOnF).data), nodeOnFHat);
342  assert(d == kClosedList);
343  }
344  }
345 
346  if (bestSolution != DBL_MAX && !fequal(oldF, f.Lookat(f.Peek()).g+f.Lookat(f.Peek()).h))
347  {
348  // Show when we push the bound up from openf
349  printf("Best solution %1.2f\n", bestSolution);
350  printf("Best on open %1.2f - lower bound is %1.2f\n", f.Lookat(f.Peek()).g+f.Lookat(f.Peek()).h,
351  (f.Lookat(f.Peek()).g+f.Lookat(f.Peek()).h)*bound);
352  }
353 
354  if (!fhat.Lookup(nodeOnFHat).reopened)
355  uniqueNodesExpanded++;
356  nodesExpanded++;
357 
358  // 11. if n is a goal then
359  // 12. incumbent ← n
360  if (env->GoalTest(fhat.Lookup(nodeOnFHat).data, goal))
361  {
362  // Actually extract the path, since the cost may not actually be the g-cost
363  ExtractPathToStartFromID(nodeOnFHat, thePath);
364  bestSolution = env->GetPathLength(thePath);
365  thePath.resize(0);
366  printf("Best solution %1.2f\n", bestSolution);
367  printf("Best on open %1.2f - lower bound is %1.2f\n", f.Lookat(f.Peek()).g+f.Lookat(f.Peek()).h,
368  (f.Lookat(f.Peek()).g+f.Lookat(f.Peek()).h)*bound);
369 
370  return false; // check on next iteration through the loop
371  }
372 
373 
374  // std::cout << "Expanding: " << fhat.Lookup(nodeOnFHat).data << " with f:";
375  // std::cout << fhat.Lookup(nodeid).g+fhat.Lookup(nodeOnFHat).h << std::endl;
376 
377  env->GetSuccessors(fhat.Lookup(nodeOnFHat).data, neighbors);
378 
379  // iterate again updating costs and writing out to memory
380  // 13. else for each child c of n
381  for (int x = 0; x < neighbors.size(); x++)
382  {
383  uint64_t childID_fhat, childID_f;
384  dataLocation d_fhat, d_f;
385 
386  d_fhat = fhat.Lookup(env->GetStateHash(neighbors[x]), childID_fhat);
387  d_f = f.Lookup(env->GetStateHash(neighbors[x]), childID_f);
388  double edgeCost = env->GCost(fhat.Lookup(nodeOnFHat).data, neighbors[x]);
389 
390  nodesTouched++;
391 
392 
393  if (d_f == kOpenList) // update cost if on open in
394  {
395  // 14. if c is duplicated in openf then
396  // 15. if c is better than the duplicate then
397  // 16. replace copies in openf and openfhat
398  //assert(d_fhat == kOpenList);
399 
400  if (fless(f.Lookup(nodeOnF).g+edgeCost, f.Lookup(childID_f).g))
401  {
402  // update in open
403  f.Lookup(childID_f).parentID = nodeOnF;
404  f.Lookup(childID_f).g = f.Lookup(nodeOnF).g+edgeCost;
405  f.Lookup(childID_f).data = neighbors[x];
406  f.KeyChanged(childID_f);
407 
408  // update in open_hat
409  fhat.Lookup(childID_fhat).parentID = nodeOnFHat;
410  fhat.Lookup(childID_fhat).g = f.Lookup(nodeOnF).g+edgeCost;//fhat.Lookup(nodeOnFHat).g+edgeCost;
411  fhat.Lookup(childID_fhat).data = neighbors[x];
412  if (d_fhat == kOpenList)
413  fhat.KeyChanged(childID_fhat);
414  else if (d_fhat == kClosedList)// && reopen)
415  fhat.Reopen(childID_fhat);
416  }
417  }
418  // 17. else if c is duplicated in closed then
419  else if (d_f == kClosedList)
420  {
421 
422  assert(d_fhat == kClosedList);
423  if (fless(f.Lookup(nodeOnF).g+edgeCost, f.Lookup(childID_f).g))// && reopen)
424  {
425  // 18. if c is better than the duplicate then
426  // 19. add c to openf and openfhat
427  f.Lookup(childID_f).parentID = nodeOnF;
428  f.Lookup(childID_f).g = f.Lookup(nodeOnF).g+edgeCost;
429  f.Reopen(childID_f);
430  f.Lookup(childID_f).data = neighbors[x];
431 
432  fhat.Lookup(childID_fhat).parentID = nodeOnFHat;
433  fhat.Lookup(childID_fhat).g = fhat.Lookup(nodeOnFHat).g+edgeCost;
434  fhat.Lookup(childID_fhat).data = neighbors[x];
435  fhat.Reopen(childID_fhat);
436  }
437  }
438  else {
439  // 20. else add c to openf and openfhat
440  assert(d_fhat == kNotFound);
441  assert(d_f == kNotFound);
442  fhat.AddOpenNode(neighbors[x],
443  env->GetStateHash(neighbors[x]),
444  fhat.Lookup(nodeOnFHat).g+edgeCost,
445  weight*theHeuristic->HCost(neighbors[x], goal),
446  nodeOnFHat);
447 
448  f.AddOpenNode(neighbors[x],
449  env->GetStateHash(neighbors[x]),
450  f.Lookup(nodeOnF).g+edgeCost,
451  theHeuristic->HCost(neighbors[x], goal),
452  nodeOnF);
453  }
454  }
455  return false;
456 }
457 
465 template <class state, class action, class environment>
467 {
468  uint64_t key = fhat.Peek();
469  return fhat.Lookup(key).data;
470  //assert(false);
471  //return openQueue.top().currNode;
472 }
473 
474 
483 template <class state, class action,class environment>
485  std::vector<state> &thePath)
486 {
487  do {
488  thePath.push_back(fhat.Lookup(node).data);
489  node = fhat.Lookup(node).parentID;
490  } while (fhat.Lookup(node).parentID != node);
491  thePath.push_back(fhat.Lookup(node).data);
492 }
493 
494 template <class state, class action,class environment>
496 {
497  uint64_t theID;
498  fhat.Lookup(env->GetStateHash(s), theID);
499  theID = fhat.Lookup(theID).parentID;
500  return fhat.Lookup(theID).data;
501 }
502 
509 template <class state, class action, class environment>
511 {
512  printf("%u items in closed list\n", (unsigned int)fhat.ClosedSize());
513  printf("%u items in open queue\n", (unsigned int)fhat.OpenSize());
514 }
515 
523 template <class state, class action, class environment>
525 {
526  return fhat.size();
527 }
528 
539 template <class state, class action, class environment>
540 bool OptimisticSearch<state, action,environment>::GetClosedListGCost(const state &val, double &gCost) const
541 {
542  uint64_t theID;
543  dataLocation loc = fhat.Lookup(env->GetStateHash(val), theID);
544  if (loc == kClosedList)
545  {
546  gCost = fhat.Lookat(theID).g;
547  return true;
548  }
549  return false;
550 }
551 
552 template <class state, class action, class environment>
553 bool OptimisticSearch<state, action,environment>::GetOpenListGCost(const state &val, double &gCost) const
554 {
555  uint64_t theID;
556  dataLocation loc = f.Lookup(env->GetStateHash(val), theID);
557  if (loc == kOpenList)
558  {
559  gCost = f.Lookat(theID).g;
560  return true;
561  }
562  return false;
563 }
564 
565 template <class state, class action, class environment>
566 bool OptimisticSearch<state, action,environment>::GetFocalListGCost(const state &val, double &gCost) const
567 {
568  uint64_t theID;
569  dataLocation loc = fhat.Lookup(env->GetStateHash(val), theID);
570  if (loc == kOpenList)
571  {
572  gCost = fhat.Lookat(theID).g;
573  return true;
574  }
575  return false;
576 }
577 
578 template <class state, class action, class environment>
580 {
581  uint64_t theID;
582  dataLocation loc = fhat.Lookup(env->GetStateHash(s), theID);
583  if (loc == kClosedList)
584  {
585  result = fhat.Lookat(theID);
586  return true;
587  }
588  return false;
589 
590 }
591 
592 
599 template <class state, class action, class environment>
601 {
602  double transparency = 1.0;
603  if (fhat.size() == 0)
604  return;
605  uint64_t top = -1;
606  double bound = DBL_MAX;
607 
608  // double minf = 1e9, maxf = 0;
609  if (fhat.OpenSize() > 0)
610  {
611  top = fhat.Peek();
612  const auto &i = f.Lookat(f.Peek());
613  bound = i.g+i.h;
614  printf("Lowest f on open: %f\n", bound);
615  }
616  for (unsigned int x = 0; x < fhat.size(); x++)
617  {
618  const auto &data = fhat.Lookat(x);
619  if (x == top)
620  {
621  env->SetColor(1.0, 1.0, 0.0, transparency);
622  env->OpenGLDraw(data.data);
623  }
624  if ((data.where == kClosedList && !fgreater(data.g+data.h/weight, bound)))
625  {
626  env->SetColor(0.0, 0.0, 1.0, transparency);
627  env->OpenGLDraw(data.data);
628  }
629  else if ((data.where == kOpenList) && (data.reopened))
630  {
631  env->SetColor(0.0, 0.5, 0.5, transparency);
632  env->OpenGLDraw(data.data);
633  }
634  else if (data.where == kOpenList)
635  {
636  env->SetColor(0.0, 1.0, 0.0, transparency);
637  env->OpenGLDraw(data.data);
638  }
639  else if ((data.where == kClosedList) && (data.reopened))
640  {
641  env->SetColor(0.5, 0.0, 0.5, transparency);
642  env->OpenGLDraw(data.data);
643  }
644  else if (data.where == kClosedList)
645  {
646  // if (top != -1)
647  // {
648  // env->SetColor((data.g+data.h-minf)/(maxf-minf), 0.0, 0.0, transparency);
649  // }
650  // else {
651  if (data.parentID == x)
652  env->SetColor(1.0, 0.5, 0.5, transparency);
653  else
654  env->SetColor(1.0, 0.0, 0.0, transparency);
655  // }
656  env->OpenGLDraw(data.data);
657  }
658  }
659  env->SetColor(1.0, 0.5, 1.0, 0.5);
660  env->OpenGLDraw(goal);
661 }
662 
663 template <class state, class action, class environment>
665 {
666  double transparency = 1.0;
667  if (fhat.size() == 0)
668  return;
669  uint64_t top = -1;
670  double bound = DBL_MAX;
671 
672  // double minf = 1e9, maxf = 0;
673  if (fhat.OpenSize() > 0)
674  {
675  top = fhat.Peek();
676  const auto &i = f.Lookat(f.Peek());
677  bound = i.g+i.h;
678 // printf("Lowest f on open: %f\n", bound);
679  }
680  for (unsigned int x = 0; x < fhat.size(); x++)
681  {
682  const auto &data = fhat.Lookat(x);
683  if (x == top)
684  {
685  env->SetColor(1.0, 1.0, 0.0, transparency);
686  env->Draw(d, data.data);
687  }
688 // if ((data.where == kClosedList && !fgreater(data.g+data.h/weight, bound)))
689 // {
690 // env->SetColor(0.0, 0.0, 1.0, transparency);
691 // env->Draw(d, data.data);
692 // }
693  if ((data.where == kOpenList) && (data.reopened))
694  {
695  env->SetColor(0.0, 0.5, 0.5, transparency);
696  env->Draw(d, data.data);
697  }
698  else if (data.where == kOpenList)
699  {
700  env->SetColor(0.0, 1.0, 0.0, transparency);
701  env->Draw(d, data.data);
702  }
703  else if ((data.where == kClosedList) && (data.reopened))
704  {
705  env->SetColor(0.5, 0.0, 0.5, transparency);
706  env->Draw(d, data.data);
707  }
708  else if (data.where == kClosedList)
709  {
710  // if (top != -1)
711  // {
712  // env->SetColor((data.g+data.h-minf)/(maxf-minf), 0.0, 0.0, transparency);
713  // }
714  // else {
715  if (data.parentID == x)
716  env->SetColor(1.0, 0.5, 0.5, transparency);
717  else
718  env->SetColor(1.0, 0.0, 0.0, transparency);
719  // }
720  env->Draw(d, data.data);
721  }
722  }
723  for (unsigned int x = 0; x < f.size(); x++)
724  {
725  const auto &data = f.Lookat(x);
726  if (data.openedFromF)
727  {
728  env->SetColor(0.0, 0.0, 1.0, transparency);
729  env->Draw(d, data.data);
730  }
731 
732  }
733  env->SetColor(1.0, 0.5, 1.0, 0.5);
734  env->Draw(d, goal);
735 }
736 
737 #endif /* OptimisticSearch_h */
OptimisticSearch::DoSingleSearchStep
bool DoSingleSearchStep(std::vector< state > &thePath)
Expand a single node.
Definition: OptimisticSearch.h:287
OptimisticSearch::GetReopenNodes
bool GetReopenNodes()
Definition: OptimisticSearch.h:118
OptimisticSearch::CheckNextNode
state CheckNextNode()
Returns the next state on the open list (but doesn't pop it off the queue).
Definition: OptimisticSearch.h:466
GenericSearchAlgorithm.h
An interface for generic search algorithms.
BucketOpenClosed.h
OptimisticSearch::GetClosedListGCost
bool GetClosedListGCost(const state &val, double &gCost) const
Get state from the closed list.
Definition: OptimisticSearch.h:540
OptimisticSearch::nodesExpanded
uint64_t nodesExpanded
Definition: OptimisticSearch.h:135
OptimisticSearch::GetWeight
double GetWeight()
Definition: OptimisticSearch.h:131
OptimisticSearch::bestSolution
double bestSolution
Definition: OptimisticSearch.h:142
OptimisticSearch::~OptimisticSearch
virtual ~OptimisticSearch()
Definition: OptimisticSearch.h:61
Heuristic
Definition: Heuristic.h:30
OptimisticSearch::GetOpenItem
const OptimisticOpenClosedData< state > & GetOpenItem(unsigned int which)
Definition: OptimisticSearch.h:94
AStarOpenClosed.h
d
mcData d[]
Definition: MotionCaptureMovement.cpp:21
OptimisticCompare::operator()
bool operator()(const OptimisticOpenClosedData< state > &i1, const OptimisticOpenClosedData< state > &i2) const
Definition: OptimisticSearch.h:44
OptimisticSearch::openList
AStarOpenClosed< state, OptimisticCompare< state >, OptimisticOpenClosedData< state > > openList
Definition: OptimisticSearch.h:65
OptimisticSearch::HaveExpandedState
bool HaveExpandedState(const state &val)
Definition: OptimisticSearch.h:112
AStarOpenClosed::Lookat
const dataStructure & Lookat(uint64_t objKey) const
Definition: AStarOpenClosed.h:87
OptimisticSearch
A templated version of A*, based on HOG genericAStar.
Definition: OptimisticSearch.h:58
OptimisticSearch::ExtractPathToStartFromID
void ExtractPathToStartFromID(uint64_t node, std::vector< state > &thePath)
Get the path from a goal state to the start state.
Definition: OptimisticSearch.h:484
OptimisticSearch::bound
double bound
Definition: OptimisticSearch.h:144
OptimisticSearch::PrintStats
void PrintStats()
A function that prints the number of states in the closed list and open queue.
Definition: OptimisticSearch.h:510
OptimisticSearch::fhat
openList fhat
Definition: OptimisticSearch.h:69
FPUtil.h
OptimisticSearch::GetUniqueNodesExpanded
uint64_t GetUniqueNodesExpanded()
Definition: OptimisticSearch.h:85
OptimisticSearch::SetHeuristic
void SetHeuristic(Heuristic< state > *h)
Definition: OptimisticSearch.h:120
OptimisticSearch::ResetNodeCount
void ResetNodeCount()
Definition: OptimisticSearch.h:86
AStarOpenClosed::size
size_t size() const
Definition: AStarOpenClosed.h:103
OptimisticSearch::SetReopenNodes
void SetReopenNodes(bool re)
Definition: OptimisticSearch.h:117
OptimisticSearch::env
environment * env
Definition: OptimisticSearch.h:141
OptimisticSearch::GetClosedItem
bool GetClosedItem(const state &s, OptimisticOpenClosedData< state > &)
Definition: OptimisticSearch.h:579
OptimisticSearch::GetOpenListGCost
bool GetOpenListGCost(const state &val, double &gCost) const
Definition: OptimisticSearch.h:553
OptimisticSearch::uniqueNodesExpanded
uint64_t uniqueNodesExpanded
Definition: OptimisticSearch.h:146
OptimisticOpenClosedData::parentID
uint64_t parentID
Definition: OptimisticSearch.h:35
OptimisticSearch::ExtractPathToStart
void ExtractPathToStart(state &node, std::vector< state > &thePath)
Definition: OptimisticSearch.h:78
GenericSearchAlgorithm
Definition: GenericSearchAlgorithm.h:35
OptimisticOpenClosedData::openedFromF
bool openedFromF
Definition: OptimisticSearch.h:34
OptimisticSearch::reopenNodes
bool reopenNodes
Definition: OptimisticSearch.h:145
OptimisticSearch::goal
state goal
Definition: OptimisticSearch.h:70
loc
Definition: MapGenerators.cpp:296
OptimisticSearch::GetStateLocation
dataLocation GetStateLocation(const state &val)
Definition: OptimisticSearch.h:114
AStarOpenClosed
Definition: AStarOpenClosed.h:74
OptimisticSearch::GetPath
void GetPath(environment *env, const state &from, const state &to, std::vector< state > &thePath)
Perform an A* search between two states.
Definition: OptimisticSearch.h:180
OptimisticSearch::GetNumOpenItems
unsigned int GetNumOpenItems()
Definition: OptimisticSearch.h:93
OptimisticSearch::GetOptimalityBound
double GetOptimalityBound()
Definition: OptimisticSearch.h:133
OptimisticSearch::GetNodesExpanded
uint64_t GetNodesExpanded() const
Definition: OptimisticSearch.h:122
Graphics::Display
Definition: Graphics.h:146
OptimisticOpenClosedData::reopened
bool reopened
Definition: OptimisticSearch.h:37
fless
bool fless(double a, double b)
Definition: FPUtil.h:28
OptimisticSearch::GetNodesTouched
uint64_t GetNodesTouched() const
Definition: OptimisticSearch.h:123
OptimisticSearch::f
openList f
Definition: OptimisticSearch.h:67
dataLocation
dataLocation
Definition: AStarOpenClosed.h:27
OptimisticOpenClosedData::h
double h
Definition: OptimisticSearch.h:33
TemplateAStar.h
OptimisticSearch::Draw
void Draw(Graphics::Display &d) const
Definition: OptimisticSearch.h:664
OptimisticOpenClosedData::g
double g
Definition: OptimisticSearch.h:32
OptimisticSearch::weight
double weight
Definition: OptimisticSearch.h:143
fgreater
bool fgreater(double a, double b)
Definition: FPUtil.h:29
OptimisticSearch::CheckNextFocalNode
state CheckNextFocalNode()
Definition: OptimisticSearch.h:103
AStarOpenClosed::Peek
uint64_t Peek() const
Peek at the next item to be expanded.
Definition: AStarOpenClosed.h:280
OptimisticSearch::InitializeSearch
bool InitializeSearch(environment *env, const state &from, const state &to, std::vector< state > &thePath)
Initialize the A* search.
Definition: OptimisticSearch.h:224
OptimisticSearch::GetMemoryUsage
int GetMemoryUsage()
Return the amount of memory used by OptimisticSearch.
Definition: OptimisticSearch.h:524
AStarOpenClosed::OpenSize
size_t OpenSize() const
Definition: AStarOpenClosed.h:101
OptimisticSearch::GetNumItems
const int GetNumItems()
Definition: OptimisticSearch.h:110
kOpenList
@ kOpenList
Definition: AStarOpenClosed.h:28
OptimisticSearch::OptimisticSearch
OptimisticSearch()
Definition: OptimisticSearch.h:60
StatCollection
The StatCollection class is for collecting stats across different parts of the simulation.
Definition: StatCollection.h:34
AStarOpenClosed::GetOpenItem
uint64_t GetOpenItem(unsigned int which)
Definition: AStarOpenClosed.h:100
OptimisticSearch::neighbors
std::vector< state > neighbors
Definition: OptimisticSearch.h:137
OptimisticSearch::theHeuristic
Heuristic< state > * theHeuristic
Definition: OptimisticSearch.h:147
OptimisticSearch::CheckNextOpenNode
state CheckNextOpenNode()
Definition: OptimisticSearch.h:98
OptimisticOpenClosedData::OptimisticOpenClosedData
OptimisticOpenClosedData(const state &theData, double gCost, double hCost, uint64_t parent, uint64_t openLoc, dataLocation location)
Definition: OptimisticSearch.h:28
OptimisticSearch::AddAdditionalStartState
void AddAdditionalStartState(state &newState)
Add additional start state to the search.
Definition: OptimisticSearch.h:258
AStarOpenClosed::Lookup
dataLocation Lookup(uint64_t hashKey, uint64_t &objKey) const
Returns location of object as well as object key.
Definition: AStarOpenClosed.h:263
OptimisticSearch::start
state start
Definition: OptimisticSearch.h:70
OptimisticSearch::GetParent
const state & GetParent(const state &s)
Definition: OptimisticSearch.h:495
OptimisticSearch::nodesTouched
uint64_t nodesTouched
Definition: OptimisticSearch.h:135
OptimisticSearch::GetItem
const OptimisticOpenClosedData< state > & GetItem(unsigned int which)
Definition: OptimisticSearch.h:111
OptimisticSearch::GetFocalListGCost
bool GetFocalListGCost(const state &val, double &gCost) const
Definition: OptimisticSearch.h:566
OptimisticSearch::GetName
virtual const char * GetName()
Return the name of the algorithm.
Definition: OptimisticSearch.h:161
kNotFound
@ kNotFound
Definition: AStarOpenClosed.h:30
OptimisticOpenClosedData::openLocation
uint64_t openLocation
Definition: OptimisticSearch.h:36
path
A linked list of nodes which form a continuous path.
Definition: Path.h:20
OptimisticSearch::OpenGLDraw
void OpenGLDraw() const
Draw the open/closed list.
Definition: OptimisticSearch.h:600
OptimisticOpenClosedData::data
state data
Definition: OptimisticSearch.h:31
OptimisticSearch::SetOptimalityBound
void SetOptimalityBound(double w)
Definition: OptimisticSearch.h:132
OptimisticCompare
Definition: OptimisticSearch.h:42
OptimisticSearch::GetFocalItem
const OptimisticOpenClosedData< state > & GetFocalItem(unsigned int which)
Definition: OptimisticSearch.h:96
OptimisticSearch::GetNumFocalItems
unsigned int GetNumFocalItems()
Definition: OptimisticSearch.h:95
fequal
bool fequal(double a, double b, double tolerance=TOLERANCE)
Definition: FPUtil.h:32
OptimisticOpenClosedData::where
dataLocation where
Definition: OptimisticSearch.h:38
OptimisticOpenClosedData::OptimisticOpenClosedData
OptimisticOpenClosedData()
Definition: OptimisticSearch.h:27
OptimisticOpenClosedData
Definition: OptimisticSearch.h:25
kClosedList
@ kClosedList
Definition: AStarOpenClosed.h:29
OptimisticSearch::LogFinalStats
void LogFinalStats(StatCollection *)
Definition: OptimisticSearch.h:125
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
OptimisticSearch::SetWeight
void SetWeight(double w)
Definition: OptimisticSearch.h:130