HOG2
DelayedHeuristicAStar.h
Go to the documentation of this file.
1 
11 #ifndef DelayedHeuristicAStar_H
12 #define DelayedHeuristicAStar_H
13 
14 // Borrow most data structures from A*
15 #include "TemplateAStar.h"
16 
17 
18 template <class state, class Environment>
20 public:
22  {
23  e = 0;
24  }
25  void Reset(Environment *env, const state &goal, unsigned int nodeLimit)
26  {
27  e = env;
28  this->goal = goal;
29  this->nodeLimit = nodeLimit;
30  }
31 
32  bool HitNodeLimit()
33  {
34  return states.size() >= nodeLimit;
35  }
36 
37  void Add(state &s)
38  {
39  states.push_back(s);
40  }
41 
42  const std::vector<int> &Evaluate()
43  {
44  results.resize(states.size());
45  for (int x = 0; x < states.size(); x++)
46  results[x] = e->HCost(states[x], goal);
47  states.resize(0);
48  return results;
49  }
50 private:
51  Environment *e;
52  state goal;
53  std::vector<state> states;
54  std::vector<int> results;
55  int nodeLimit;
56 };
57 
58 
62 template <class state, class action, class environment, class batchHeuristic = HeuristicLookupBuffer<state, environment>, class openList = AStarOpenClosed<state, AStarCompareWithF<state>, AStarOpenClosedDataWithF<state>> >
63 class DelayedHeuristicAStar : public GenericSearchAlgorithm<state,action,environment> {
64 public:
67  {
68  ResetNodeCount(); env = 0; stopAfterGoal = true; weight=1; reopenNodes = false; theHeuristic = 0; directed = false;
69  theConstraint = 0;
70  phi = [](double h, double g){ return g+h; };
71  }
73  void GetPath(environment *env, const state& from, const state& to, std::vector<state> &thePath);
74  void GetPath(environment *, const state&, const state&, std::vector<action> & );
75 
76  openList openClosedList;
77  state goal, start;
78 
79  bool InitializeSearch(environment *env, const state& from, const state& to, std::vector<state> &thePath);
80  bool DoSingleSearchStep(std::vector<state> &thePath);
81 
82  state CheckNextNode();
83  void ExtractPathToStart(state &node, std::vector<state> &thePath)
84  {
85  thePath.clear();
86  uint64_t theID;
87  if (openClosedList.Lookup(env->GetStateHash(node), theID) != kNotFound)
88  ExtractPathToStartFromID(theID, thePath);
89  }
90  void ExtractPathToStartFromID(uint64_t node, std::vector<state> &thePath);
91  const state &GetParent(const state &s);
92  virtual const char *GetName();
93 
94  void PrintStats();
97  int GetMemoryUsage();
98 
99  bool GetClosedListGCost(const state &val, double &gCost) const;
100  bool GetOpenListGCost(const state &val, double &gCost) const;
101  bool GetHCost(const state &val, double &hCost) const;
102  bool GetClosedItem(const state &s, AStarOpenClosedDataWithF<state> &);
103  unsigned int GetNumOpenItems() { return openClosedList.OpenSize(); }
104  inline const AStarOpenClosedDataWithF<state> &GetOpenItem(unsigned int which) { return openClosedList.Lookat(openClosedList.GetOpenItem(which)); }
105  inline const int GetNumItems() { return openClosedList.size(); }
106  inline const AStarOpenClosedDataWithF<state> &GetItem(unsigned int which) { return openClosedList.Lookat(which); }
107  bool HaveExpandedState(const state &val)
108  { uint64_t key; return openClosedList.Lookup(env->GetStateHash(val), key) != kNotFound; }
109  dataLocation GetStateLocation(const state &val)
110  { uint64_t key; return openClosedList.Lookup(env->GetStateHash(val), key); }
111 
112  void SetReopenNodes(bool re) { reopenNodes = re; }
113  bool GetReopenNodes() { return reopenNodes; }
114 
115  // Only necessary for BPMX computation
116  void SetDirected(bool d) { directed = d; }
117 
120 
121  uint64_t GetNodesExpanded() const { return nodesExpanded; }
122  uint64_t GetNodesTouched() const { return nodesTouched; }
123  uint64_t GetNecessaryExpansions() const;
125 
126  void SetStopAfterGoal(bool val) { stopAfterGoal = val; }
127  bool GetStopAfterGoal() { return stopAfterGoal; }
128 
129  void FullBPMX(uint64_t nodeID, int distance);
130 
131  void OpenGLDraw() const;
132  void Draw(Graphics::Display &disp) const;
133  std::string SVGDraw() const;
134  std::string SVGDrawDetailed() const;
135 
137  void SetPhi(std::function<double(double, double)> p)
138  {
139  phi = p;
140  }
141  double Phi(double h, double g)
142  {
143  return phi(h, g);
144  }
145  void SetWeight(double w)
146  {
147  weight = w;
148  phi = [=](double h, double g){ return g+weight*h; };
149  }
150  double GetWeight() { return weight; }
151 private:
152  void HandleBatchedStates();
154 
155  std::vector<state> neighbors;
156  std::vector<uint64_t> neighborID;
157  std::vector<double> edgeCosts;
158  std::vector<dataLocation> neighborLoc;
159  environment *env;
161 
162  double goalFCost;
163  double weight;
164  std::function<double(double, double)> phi;
165  bool directed;
168  environment *radEnv;
171  struct tempData {
172 // tempData(state s, uint64_t hash, double g, uint64_t parent)
173 // :s(s), hash(hash), g(g), parent(parent) {}
174  state s;
175  uint64_t hash;
176  double g;
177  uint64_t parent;
178  };
179  std::vector<tempData> delayedStates;
181  batchHeuristic batch;
183 };
184 
193 template <class state, class action, class environment, class batchHeuristic, class openList>
195 {
196  static char name[32];
197  sprintf(name, "DelayedHeuristicAStar[]");
198  return name;
199 }
200 
212 template <class state, class action, class environment, class batchHeuristic, class openList>
213 void DelayedHeuristicAStar<state,action,environment,batchHeuristic,openList>::GetPath(environment *_env, const state& from, const state& to, std::vector<state> &thePath)
214 {
215  if (!InitializeSearch(_env, from, to, thePath))
216  {
217  return;
218  }
219  while (!DoSingleSearchStep(thePath))
220  {
221 // if (0 == nodesExpanded%100000)
222 // printf("%" PRId64 " nodes expanded, %" PRId64 " generated\n", nodesExpanded, nodesTouched);
223  }
224 }
225 
226 template <class state, class action, class environment, class batchHeuristic, class openList>
227 void DelayedHeuristicAStar<state,action,environment,batchHeuristic,openList>::GetPath(environment *_env, const state& from, const state& to, std::vector<action> &path)
228 {
229  std::vector<state> thePath;
230  if (!InitializeSearch(_env, from, to, thePath))
231  {
232  return;
233  }
234  path.resize(0);
235  while (!DoSingleSearchStep(thePath))
236  {
237  }
238  for (size_t x = 0; x < thePath.size()-1; x++)
239  {
240  path.push_back(_env->GetAction(thePath[x], thePath[x+1]));
241  }
242 }
243 
244 
255 template <class state, class action, class environment, class batchHeuristic, class openList>
256 bool DelayedHeuristicAStar<state,action,environment,batchHeuristic,openList>::InitializeSearch(environment *_env, const state& from, const state& to, std::vector<state> &thePath)
257 {
258  if (theHeuristic == 0)
259  theHeuristic = _env;
260  thePath.resize(0);
261  env = _env;
262  openClosedList.Reset(env->GetMaxHash());
263  ResetNodeCount();
264  start = from;
265  goal = to;
266 
267  currentCostLimit = 0;
268  delayedStates.resize(0);
269  batch.Reset(_env, to, batchLookupSize);
270 
271  if (env->GoalTest(from, to) && (stopAfterGoal)) //assumes that from and to are valid states
272  {
273  return false;
274  }
275 
276  // No purpose in looking up the heuristic of the start state.
277  // It is never used.
278  double h = 0;//theHeuristic->HCost(start, goal);
279  openClosedList.AddOpenNode(start, env->GetStateHash(start), phi(h, 0), 0, h);
280 
281  return true;
282 }
283 
294 template <class state, class action, class environment, class batchHeuristic, class openList>
296 {
297  if (openClosedList.OpenSize() == 0)
298  {
299  HandleBatchedStates();
300  }
301  if (openClosedList.OpenSize() == 0)
302  {
303  thePath.resize(0); // no path found!
304  //closedList.clear();
305  return true;
306  }
307  if (fgreater(openClosedList.Lookup(openClosedList.Peek()).f, currentCostLimit))
308  HandleBatchedStates();
309 
310  uint64_t nodeid = openClosedList.Close();
311 // if (openClosedList.Lookup(nodeid).g+openClosedList.Lookup(nodeid).h > lastF)
312 // { lastF = openClosedList.Lookup(nodeid).g+openClosedList.Lookup(nodeid).h;
313 // //printf("Updated limit to %f\n", lastF);
314 // }
315  if (!openClosedList.Lookup(nodeid).reopened)
316  uniqueNodesExpanded++;
317  nodesExpanded++;
318 
319  if ((stopAfterGoal) && (env->GoalTest(openClosedList.Lookup(nodeid).data, goal)))
320  {
321  ExtractPathToStartFromID(nodeid, thePath);
322  // Path is backwards - reverse
323  reverse(thePath.begin(), thePath.end());
324  goalFCost = openClosedList.Lookup(nodeid).f;// + openClosedList.Lookup(nodeid).h;
325  return true;
326  }
327 
328  neighbors.resize(0);
329  edgeCosts.resize(0);
330  neighborID.resize(0);
331  neighborLoc.resize(0);
332 
333 // std::cout << "Expanding: " << openClosedList.Lookup(nodeid).data << " with f:";
334 // std::cout << openClosedList.Lookup(nodeid).g+openClosedList.Lookup(nodeid).h << std::endl;
335 
336  env->GetSuccessors(openClosedList.Lookup(nodeid).data, neighbors);
337  double bestH = openClosedList.Lookup(nodeid).h;
338  double lowHC = DBL_MAX;
339  // 1. load all the children
340  for (unsigned int x = 0; x < neighbors.size(); x++)
341  {
342  uint64_t theID;
343  neighborLoc.push_back(openClosedList.Lookup(env->GetStateHash(neighbors[x]), theID));
344  neighborID.push_back(theID);
345  edgeCosts.push_back(env->GCost(openClosedList.Lookup(nodeid).data, neighbors[x]));
346  }
347 
348  // iterate again updating costs and writing out to memory
349  for (size_t x = 0; x < neighbors.size(); x++)
350  {
351  nodesTouched++;
352 
353  if (theConstraint &&
354  theConstraint->ShouldNotGenerate(start, openClosedList.Lookup(nodeid).data, neighbors[x],
355  openClosedList.Lookup(nodeid).g+edgeCosts[x], goal))
356  continue;
357 
358  switch (neighborLoc[x])
359  {
360  case kClosedList:
361  if (reopenNodes)
362  {
363  if (fless(openClosedList.Lookup(nodeid).g+edgeCosts[x], openClosedList.Lookup(neighborID[x]).g))
364  {
365  auto &i = openClosedList.Lookup(neighborID[x]);
366  i.parentID = nodeid;
367  i.g = openClosedList.Lookup(nodeid).g+edgeCosts[x];
368  i.f = phi(i.h, i.g);
369  openClosedList.Reopen(neighborID[x]);
370  // This line isn't normally needed, but in some state spaces we might have
371  // equality but different meta information, so we need to make sure that the
372  // meta information is also copied, since this is the most generic A* implementation
373  i.data = neighbors[x];
374  }
375  }
376  break;
377  case kOpenList:
378  //edgeCost = env->GCost(openClosedList.Lookup(nodeid).data, neighbors[x]);
379  if (fless(openClosedList.Lookup(nodeid).g+edgeCosts[x], openClosedList.Lookup(neighborID[x]).g))
380  {
381  auto &i = openClosedList.Lookup(neighborID[x]);
382  i.parentID = nodeid;
383  i.g = openClosedList.Lookup(nodeid).g+edgeCosts[x];
384  i.f = phi(i.h, i.g);
385  // This line isn't normally needed, but in some state spaces we might have
386  // equality but different meta information, so we need to make sure that the
387  // meta information is also copied, since this is the most generic A* implementation
388  i.data = neighbors[x];
389  openClosedList.KeyChanged(neighborID[x]);
390 // std::cout << " Reducing cost to " << openClosedList.Lookup(nodeid).g+edgeCosts[x] << "\n";
391  // TODO: unify the KeyChanged calls.
392  }
393  case kNotFound:
394  { // add node to open list
395  //double edgeCost = env->GCost(openClosedList.Lookup(nodeid).data, neighbors[x]);
396 // std::cout << " adding to open ";
397 // std::cout << double(theHeuristic->HCost(neighbors[x], goal)+openClosedList.Lookup(nodeid).g+edgeCosts[x]);
398 // std::cout << " \n";
399  delayedStates.push_back({neighbors[x],
400  env->GetStateHash(neighbors[x]),
401  openClosedList.Lookup(nodeid).g+edgeCosts[x],
402  nodeid});
403  batch.Add(neighbors[x]);
404  if (batch.HitNodeLimit())
405  HandleBatchedStates();
406 // double h = theHeuristic->HCost(neighbors[x], goal);
407 // openClosedList.AddOpenNode(neighbors[x],
408 // env->GetStateHash(neighbors[x]),
409 // phi(h, openClosedList.Lookup(nodeid).g+edgeCosts[x]),
410 // openClosedList.Lookup(nodeid).g+edgeCosts[x],
411 // h,
412 // nodeid);
413  }
414  }
415  }
416 
417  return false;
418 }
419 
420 template <class state, class action, class environment, class batchHeuristic, class openList>
422 {
423  if (delayedStates.size() == 0)
424  return;
425  auto vec = batch.Evaluate();
426  for (int x = 0; x < delayedStates.size(); x++)
427  {
428  double h = vec.at(x);
429  openClosedList.AddOpenNode(delayedStates[x].s,
430  delayedStates[x].hash,
431  phi(h, delayedStates[x].g),
432  delayedStates[x].g,
433  h,
434  delayedStates[x].parent);
435  }
436  delayedStates.resize(0);
437  currentCostLimit = openClosedList.Lookup(openClosedList.Peek()).f;
438 // batch.Reset(_env, to, batchLookupSize);
439 // batch.
440 }
441 
449 template <class state, class action, class environment, class batchHeuristic, class openList>
451 {
452  uint64_t key = openClosedList.Peek();
453  return openClosedList.Lookup(key).data;
454  //assert(false);
455  //return openQueue.top().currNode;
456 }
457 
465 template <class state, class action, class environment, class batchHeuristic, class openList>
467 {
468  if (distance <= 0)
469  return;
470 
471  nodesExpanded++;
472  std::vector<state> succ;
473  env->GetSuccessors(openClosedList.Lookup(nodeID).data, succ);
474  double parentH = openClosedList.Lookup(nodeID).h;
475 
476  // load all the children and push parent heuristic value to children
477  for (unsigned int x = 0; x < succ.size(); x++)
478  {
479  uint64_t theID;
480  dataLocation loc = openClosedList.Lookup(env->GetStateHash(succ[x]), theID);
481  double edgeCost = env->GCost(openClosedList.Lookup(nodeID).data, succ[x]);
482  double newHCost = parentH-edgeCost;
483 
484  switch (loc)
485  {
486  case kClosedList:
487  {
488  if (fgreater(newHCost, openClosedList.Lookup(theID).h))
489  {
490  openClosedList.Lookup(theID).h = newHCost;
491  FullBPMX(theID, distance-1);
492  }
493  }
494  case kOpenList:
495  {
496  if (fgreater(newHCost, openClosedList.Lookup(theID).h))
497  {
498  openClosedList.Lookup(theID).h = newHCost;
499  openClosedList.KeyChanged(theID);
500  }
501  }
502  case kNotFound: break;
503  }
504  }
505 }
506 
507 
516 template <class state, class action, class environment, class batchHeuristic, class openList>
518  std::vector<state> &thePath)
519 {
520  do {
521  thePath.push_back(openClosedList.Lookup(node).data);
522  node = openClosedList.Lookup(node).parentID;
523  } while (openClosedList.Lookup(node).parentID != node);
524  thePath.push_back(openClosedList.Lookup(node).data);
525 }
526 
527 template <class state, class action, class environment, class batchHeuristic, class openList>
529 {
530  uint64_t theID;
531  openClosedList.Lookup(env->GetStateHash(s), theID);
532  theID = openClosedList.Lookup(theID).parentID;
533  return openClosedList.Lookup(theID).data;
534 }
535 
536 template <class state, class action, class environment, class batchHeuristic, class openList>
538 {
539  uint64_t n = 0;
540  for (unsigned int x = 0; x < openClosedList.size(); x++)
541  {
542  const auto &data = openClosedList.Lookat(x);
543  if (fless(data.g + data.h, goalFCost))
544  n++;
545  }
546  return n;
547 }
548 
549 
556 template <class state, class action, class environment, class batchHeuristic, class openList>
558 {
559  printf("%u items in closed list\n", (unsigned int)openClosedList.ClosedSize());
560  printf("%u items in open queue\n", (unsigned int)openClosedList.OpenSize());
561 }
562 
570 template <class state, class action, class environment, class batchHeuristic, class openList>
572 {
573  return openClosedList.size();
574 }
575 
586 template <class state, class action, class environment, class batchHeuristic, class openList>
588 {
589  uint64_t theID;
590  dataLocation loc = openClosedList.Lookup(env->GetStateHash(val), theID);
591  if (loc == kClosedList)
592  {
593  gCost = openClosedList.Lookat(theID).g;
594  return true;
595  }
596  return false;
597 }
598 
599 template <class state, class action, class environment, class batchHeuristic, class openList>
601 {
602  uint64_t theID;
603  dataLocation loc = openClosedList.Lookup(env->GetStateHash(val), theID);
604  if (loc == kOpenList)
605  {
606  gCost = openClosedList.Lookat(theID).g;
607  return true;
608  }
609  return false;
610 }
611 
612 template <class state, class action, class environment, class batchHeuristic, class openList>
614 {
615  uint64_t theID;
616  dataLocation loc = openClosedList.Lookup(env->GetStateHash(val), theID);
617  if (loc != kNotFound)
618  {
619  hCost = openClosedList.Lookat(theID).h;
620  return true;
621  }
622  return false;
623 }
624 
625 template <class state, class action, class environment, class batchHeuristic, class openList>
627 {
628  uint64_t theID;
629  dataLocation loc = openClosedList.Lookup(env->GetStateHash(s), theID);
630  if (loc == kClosedList)
631  {
632  result = openClosedList.Lookat(theID);
633  return true;
634  }
635  return false;
636 
637 }
638 
639 
646 template <class state, class action, class environment, class batchHeuristic, class openList>
648 {
649  double transparency = 1.0;
650  if (openClosedList.size() == 0)
651  return;
652  uint64_t top = -1;
653 // double minf = 1e9, maxf = 0;
654  if (openClosedList.OpenSize() > 0)
655  {
656  top = openClosedList.Peek();
657  }
658 // for (unsigned int x = 0; x < openClosedList.size(); x++)
659 // {
660 // const AStarOpenClosedData<state> &data = openClosedList.Lookat(x);
661 // double f = data.g+data.h;
662 // if (f > maxf)
663 // maxf = f;
664 // if (f < minf)
665 // minf = f;
666 // }
667  for (unsigned int x = 0; x < openClosedList.size(); x++)
668  {
669  const auto &data = openClosedList.Lookat(x);
670  if (x == top)
671  {
672  env->SetColor(1.0, 1.0, 0.0, transparency);
673  env->OpenGLDraw(data.data);
674  }
675  if ((data.where == kOpenList) && (data.reopened))
676  {
677  env->SetColor(0.0, 0.5, 0.5, transparency);
678  env->OpenGLDraw(data.data);
679  }
680  else if (data.where == kOpenList)
681  {
682  env->SetColor(0.0, 1.0, 0.0, transparency);
683  env->OpenGLDraw(data.data);
684  }
685  else if ((data.where == kClosedList) && (data.reopened))
686  {
687  env->SetColor(0.5, 0.0, 0.5, transparency);
688  env->OpenGLDraw(data.data);
689  }
690  else if (data.where == kClosedList)
691  {
692 // if (top != -1)
693 // {
694 // env->SetColor((data.g+data.h-minf)/(maxf-minf), 0.0, 0.0, transparency);
695 // }
696 // else {
697  if (data.parentID == x)
698  env->SetColor(1.0, 0.5, 0.5, transparency);
699  else
700  env->SetColor(1.0, 0.0, 0.0, transparency);
701 // }
702  env->OpenGLDraw(data.data);
703  }
704  }
705  env->SetColor(1.0, 0.5, 1.0, 0.5);
706  env->OpenGLDraw(goal);
707 }
708 
715 template <class state, class action, class environment, class batchHeuristic, class openList>
717 {
718  double transparency = 1.0;
719  if (openClosedList.size() == 0)
720  return;
721  uint64_t top = -1;
722  // double minf = 1e9, maxf = 0;
723  if (openClosedList.OpenSize() > 0)
724  {
725  top = openClosedList.Peek();
726  }
727  for (unsigned int x = 0; x < openClosedList.size(); x++)
728  {
729  const auto &data = openClosedList.Lookat(x);
730  if (x == top)
731  {
732  env->SetColor(1.0, 1.0, 0.0, transparency);
733  env->Draw(disp, data.data);
734  }
735  else if ((data.where == kOpenList) && (data.reopened))
736  {
737  env->SetColor(0.0, 0.5, 0.5, transparency);
738  env->Draw(disp, data.data);
739  }
740  else if (data.where == kOpenList)
741  {
742  env->SetColor(0.0, 1.0, 0.0, transparency);
743  env->Draw(disp, data.data);
744  }
745  else if ((data.where == kClosedList) && (data.reopened))
746  {
747  env->SetColor(0.5, 0.0, 0.5, transparency);
748  env->Draw(disp, data.data);
749  }
750  else if (data.where == kClosedList)
751  {
752  // if (top != -1)
753  // {
754  // env->SetColor((data.g+data.h-minf)/(maxf-minf), 0.0, 0.0, transparency);
755  // }
756  // else {
757  if (data.parentID == x)
758  env->SetColor(1.0, 0.5, 0.5, transparency);
759  else
760  env->SetColor(1.0, 0.0, 0.0, transparency);
761  // }
762  env->Draw(disp, data.data);
763  }
764  }
765  env->SetColor(1.0, 0.5, 1.0, 0.5);
766  env->Draw(disp, goal);
767  for (unsigned int x = 0; x < delayedStates.size(); x++)
768  {
769  env->SetColor(Colors::blue);
770  env->Draw(disp, delayedStates[x].s);
771  }
772 }
773 
774 template <class state, class action, class environment, class batchHeuristic, class openList>
776 {
777  std::string s;
778  double transparency = 1.0;
779  if (openClosedList.size() == 0)
780  return s;
781  uint64_t top = -1;
782 
783  if (openClosedList.OpenSize() > 0)
784  {
785  top = openClosedList.Peek();
786  }
787  for (unsigned int x = 0; x < openClosedList.size(); x++)
788  {
789  const auto &data = openClosedList.Lookat(x);
790 
791  if (x == top)
792  {
793  env->SetColor(1.0, 1.0, 0.0, transparency);
794  s+=env->SVGDraw(data.data);
795  }
796  else if ((data.where == kOpenList) && (data.reopened))
797  {
798  env->SetColor(0.0, 0.5, 0.5, transparency);
799  s+=env->SVGDraw(data.data);
800  }
801  else if (data.where == kOpenList)
802  {
803  env->SetColor(0.0, 1.0, 0.0, transparency);
804  s+=env->SVGDraw(data.data);
805  }
806  else if ((data.where == kClosedList) && (data.reopened))
807  {
808  env->SetColor(0.5, 0.0, 0.5, transparency);
809  s+=env->SVGDraw(data.data);
810  }
811  else if (data.where == kClosedList)
812  {
813  env->SetColor(1.0, 0.0, 0.0, transparency);
814  s+=env->SVGDraw(data.data);
815  }
816  }
817  return s;
818 }
819 
820 template <class state, class action, class environment, class batchHeuristic, class openList>
822 {
823  std::string s;
824  //double transparency = 1.0;
825  if (openClosedList.size() == 0)
826  return s;
827  uint64_t top = -1;
828 
829  if (openClosedList.OpenSize() > 0)
830  {
831  top = openClosedList.Peek();
832  }
833  for (unsigned int x = 0; x < openClosedList.size(); x++)
834  {
835  const auto &data = openClosedList.Lookat(x);
836 
837 // if (x == top)
838 // {
839 // env->SetColor(1.0, 1.0, 0.0, transparency);
840 // s+=env->SVGDraw(data.data);
841 // }
842 // else if ((data.where == kOpenList) && (data.reopened))
843 // {
844 // env->SetColor(0.0, 0.5, 0.5, transparency);
845 // s+=env->SVGDraw(data.data);
846 // }
847 // else if (data.where == kOpenList)
848 // {
849 // env->SetColor(0.0, 1.0, 0.0, transparency);
850 // s+=env->SVGDraw(data.data);
851 // }
852 // else if ((data.where == kClosedList) && (data.reopened))
853 // {
854 // env->SetColor(0.5, 0.0, 0.5, transparency);
855 // s+=env->SVGDraw(data.data);
856 // }
857 // else if (data.where == kClosedList)
858 // {
859 // env->SetColor(1.0, 0.0, 0.0, transparency);
860 // s+=env->SVGDraw(data.data);
861 // }
862  env->SetColor(0.0, 0.0, 0.0);
863  char d[32];
864  sprintf(d, "%1.1f", data.g+data.h);
865  s+=env->SVGLabelState(data.data, d, 0.35, -0.6, -1.1);
866  sprintf(d, "g:%1.1f", data.g);
867  s+=env->SVGLabelState(data.data, d, 0.25, -0.6, -0.75);
868  sprintf(d, "h:%1.1f", data.h);
869  s+=env->SVGLabelState(data.data, d, 0.25, -0.6, -0.48);
870  }
871  return s;
872 }
873 
874 
875 #endif
DelayedHeuristicAStar::GetMemoryUsage
int GetMemoryUsage()
Return the amount of memory used by DelayedHeuristicAStar.
Definition: DelayedHeuristicAStar.h:571
DelayedHeuristicAStar::ExtractPathToStartFromID
void ExtractPathToStartFromID(uint64_t node, std::vector< state > &thePath)
Get the path from a goal state to the start state.
Definition: DelayedHeuristicAStar.h:517
DelayedHeuristicAStar::GetNumOpenItems
unsigned int GetNumOpenItems()
Definition: DelayedHeuristicAStar.h:103
DelayedHeuristicAStar::uniqueNodesExpanded
uint64_t uniqueNodesExpanded
Definition: DelayedHeuristicAStar.h:167
DelayedHeuristicAStar::GetOpenItem
const AStarOpenClosedDataWithF< state > & GetOpenItem(unsigned int which)
Definition: DelayedHeuristicAStar.h:104
DelayedHeuristicAStar::neighborLoc
std::vector< dataLocation > neighborLoc
Definition: DelayedHeuristicAStar.h:158
DelayedHeuristicAStar::reopenNodes
bool reopenNodes
Definition: DelayedHeuristicAStar.h:166
DelayedHeuristicAStar::HaveExpandedState
bool HaveExpandedState(const state &val)
Definition: DelayedHeuristicAStar.h:107
Constraint
Definition: Constraint.h:13
DelayedHeuristicAStar::GetParent
const state & GetParent(const state &s)
Definition: DelayedHeuristicAStar.h:528
DelayedHeuristicAStar::DoSingleSearchStep
bool DoSingleSearchStep(std::vector< state > &thePath)
Expand a single node.
Definition: DelayedHeuristicAStar.h:295
HeuristicLookupBuffer::Reset
void Reset(Environment *env, const state &goal, unsigned int nodeLimit)
Definition: DelayedHeuristicAStar.h:25
DelayedHeuristicAStar::CheckNextNode
state CheckNextNode()
Returns the next state on the open list (but doesn't pop it off the queue).
Definition: DelayedHeuristicAStar.h:450
HeuristicLookupBuffer::goal
state goal
Definition: DelayedHeuristicAStar.h:52
Heuristic
Definition: Heuristic.h:30
HeuristicLookupBuffer::e
Environment * e
Definition: DelayedHeuristicAStar.h:51
HeuristicLookupBuffer::states
std::vector< state > states
Definition: DelayedHeuristicAStar.h:53
HeuristicLookupBuffer::HitNodeLimit
bool HitNodeLimit()
Definition: DelayedHeuristicAStar.h:32
d
mcData d[]
Definition: MotionCaptureMovement.cpp:21
DelayedHeuristicAStar::tempData::hash
uint64_t hash
Definition: DelayedHeuristicAStar.h:175
DelayedHeuristicAStar::DelayedHeuristicAStar
DelayedHeuristicAStar(int batchLookupSize)
Definition: DelayedHeuristicAStar.h:65
DelayedHeuristicAStar::SetHeuristic
void SetHeuristic(Heuristic< state > *h)
Definition: DelayedHeuristicAStar.h:118
DelayedHeuristicAStar::edgeCosts
std::vector< double > edgeCosts
Definition: DelayedHeuristicAStar.h:157
AStarOpenClosedDataWithF
Definition: AStarOpenClosed.h:36
DelayedHeuristicAStar::GetPath
void GetPath(environment *env, const state &from, const state &to, std::vector< state > &thePath)
Perform an A* search between two states.
Definition: DelayedHeuristicAStar.h:213
DelayedHeuristicAStar::OpenGLDraw
void OpenGLDraw() const
Draw the open/closed list.
Definition: DelayedHeuristicAStar.h:647
DelayedHeuristicAStar::SetStopAfterGoal
void SetStopAfterGoal(bool val)
Definition: DelayedHeuristicAStar.h:126
DelayedHeuristicAStar::theHeuristic
Heuristic< state > * theHeuristic
Definition: DelayedHeuristicAStar.h:169
DelayedHeuristicAStar::GetWeight
double GetWeight()
Definition: DelayedHeuristicAStar.h:150
HeuristicLookupBuffer::nodeLimit
int nodeLimit
Definition: DelayedHeuristicAStar.h:55
DelayedHeuristicAStar::GetOpenListGCost
bool GetOpenListGCost(const state &val, double &gCost) const
Definition: DelayedHeuristicAStar.h:600
DelayedHeuristicAStar::LogFinalStats
void LogFinalStats(StatCollection *)
Definition: DelayedHeuristicAStar.h:124
DelayedHeuristicAStar::goal
state goal
Definition: DelayedHeuristicAStar.h:77
DelayedHeuristicAStar::directed
bool directed
Definition: DelayedHeuristicAStar.h:165
DelayedHeuristicAStar::GetNumItems
const int GetNumItems()
Definition: DelayedHeuristicAStar.h:105
DelayedHeuristicAStar::SetDirected
void SetDirected(bool d)
Definition: DelayedHeuristicAStar.h:116
DelayedHeuristicAStar::GetClosedListGCost
bool GetClosedListGCost(const state &val, double &gCost) const
Get state from the closed list.
Definition: DelayedHeuristicAStar.h:587
DelayedHeuristicAStar::GetUniqueNodesExpanded
uint64_t GetUniqueNodesExpanded()
Definition: DelayedHeuristicAStar.h:95
DelayedHeuristicAStar::batch
batchHeuristic batch
Definition: DelayedHeuristicAStar.h:181
DelayedHeuristicAStar::SetConstraint
void SetConstraint(Constraint< state > *c)
Definition: DelayedHeuristicAStar.h:119
DelayedHeuristicAStar::SetReopenNodes
void SetReopenNodes(bool re)
Definition: DelayedHeuristicAStar.h:112
DelayedHeuristicAStar::~DelayedHeuristicAStar
virtual ~DelayedHeuristicAStar()
Definition: DelayedHeuristicAStar.h:72
GenericSearchAlgorithm
Definition: GenericSearchAlgorithm.h:35
DelayedHeuristicAStar::start
state start
Definition: DelayedHeuristicAStar.h:77
DelayedHeuristicAStar::GetItem
const AStarOpenClosedDataWithF< state > & GetItem(unsigned int which)
Definition: DelayedHeuristicAStar.h:106
loc
Definition: MapGenerators.cpp:296
DelayedHeuristicAStar::weight
double weight
Definition: DelayedHeuristicAStar.h:163
DelayedHeuristicAStar::neighbors
std::vector< state > neighbors
Definition: DelayedHeuristicAStar.h:155
DelayedHeuristicAStar::stopAfterGoal
bool stopAfterGoal
Definition: DelayedHeuristicAStar.h:160
DelayedHeuristicAStar::tempData::s
state s
Definition: DelayedHeuristicAStar.h:174
DelayedHeuristicAStar::env
environment * env
Definition: DelayedHeuristicAStar.h:159
DelayedHeuristicAStar::FullBPMX
void FullBPMX(uint64_t nodeID, int distance)
Perform a full bpmx propagation.
Definition: DelayedHeuristicAStar.h:466
DelayedHeuristicAStar::ResetNodeCount
void ResetNodeCount()
Definition: DelayedHeuristicAStar.h:96
DelayedHeuristicAStar::PrintStats
void PrintStats()
A function that prints the number of states in the closed list and open queue.
Definition: DelayedHeuristicAStar.h:557
HeuristicLookupBuffer::HeuristicLookupBuffer
HeuristicLookupBuffer()
Definition: DelayedHeuristicAStar.h:21
Graphics::Display
Definition: Graphics.h:146
fless
bool fless(double a, double b)
Definition: FPUtil.h:28
dataLocation
dataLocation
Definition: AStarOpenClosed.h:27
HeuristicLookupBuffer::results
std::vector< int > results
Definition: DelayedHeuristicAStar.h:54
DelayedHeuristicAStar::GetHCost
bool GetHCost(const state &val, double &hCost) const
Definition: DelayedHeuristicAStar.h:613
DelayedHeuristicAStar::GetName
virtual const char * GetName()
Return the name of the algorithm.
Definition: DelayedHeuristicAStar.h:194
TemplateAStar.h
DelayedHeuristicAStar::tempData::g
double g
Definition: DelayedHeuristicAStar.h:176
DelayedHeuristicAStar::delayedStates
std::vector< tempData > delayedStates
Definition: DelayedHeuristicAStar.h:179
DelayedHeuristicAStar::theConstraint
Constraint< state > * theConstraint
Definition: DelayedHeuristicAStar.h:170
DelayedHeuristicAStar
A templated version of A*, based on TemplateAStar, which delays heuristic lookups as long as possible...
Definition: DelayedHeuristicAStar.h:63
DelayedHeuristicAStar::currentCostLimit
double currentCostLimit
Definition: DelayedHeuristicAStar.h:180
DelayedHeuristicAStar::SetPhi
void SetPhi(std::function< double(double, double)> p)
Setting this function.
Definition: DelayedHeuristicAStar.h:137
DelayedHeuristicAStar::GetNodesExpanded
uint64_t GetNodesExpanded() const
Definition: DelayedHeuristicAStar.h:121
fgreater
bool fgreater(double a, double b)
Definition: FPUtil.h:29
DelayedHeuristicAStar::tempData::parent
uint64_t parent
Definition: DelayedHeuristicAStar.h:177
DelayedHeuristicAStar::SetWeight
void SetWeight(double w)
Definition: DelayedHeuristicAStar.h:145
DelayedHeuristicAStar::HandleBatchedStates
void HandleBatchedStates()
Definition: DelayedHeuristicAStar.h:421
DelayedHeuristicAStar::GetReopenNodes
bool GetReopenNodes()
Definition: DelayedHeuristicAStar.h:113
HeuristicLookupBuffer::Add
void Add(state &s)
Definition: DelayedHeuristicAStar.h:37
kOpenList
@ kOpenList
Definition: AStarOpenClosed.h:28
DelayedHeuristicAStar::GetStopAfterGoal
bool GetStopAfterGoal()
Definition: DelayedHeuristicAStar.h:127
DelayedHeuristicAStar::ExtractPathToStart
void ExtractPathToStart(state &node, std::vector< state > &thePath)
Definition: DelayedHeuristicAStar.h:83
StatCollection
The StatCollection class is for collecting stats across different parts of the simulation.
Definition: StatCollection.h:34
DelayedHeuristicAStar::openClosedList
openList openClosedList
Definition: DelayedHeuristicAStar.h:76
DelayedHeuristicAStar::InitializeSearch
bool InitializeSearch(environment *env, const state &from, const state &to, std::vector< state > &thePath)
Initialize the A* search.
Definition: DelayedHeuristicAStar.h:256
DelayedHeuristicAStar::Phi
double Phi(double h, double g)
Definition: DelayedHeuristicAStar.h:141
DelayedHeuristicAStar::nodesTouched
uint64_t nodesTouched
Definition: DelayedHeuristicAStar.h:153
DelayedHeuristicAStar::SVGDraw
std::string SVGDraw() const
Definition: DelayedHeuristicAStar.h:775
DelayedHeuristicAStar::radEnv
environment * radEnv
Definition: DelayedHeuristicAStar.h:168
DelayedHeuristicAStar::phi
std::function< double(double, double)> phi
Definition: DelayedHeuristicAStar.h:164
DelayedHeuristicAStar::GetStateLocation
dataLocation GetStateLocation(const state &val)
Definition: DelayedHeuristicAStar.h:109
Colors::blue
const rgbColor blue
Definition: Colors.h:142
DelayedHeuristicAStar::batchLookupSize
int batchLookupSize
Definition: DelayedHeuristicAStar.h:182
kNotFound
@ kNotFound
Definition: AStarOpenClosed.h:30
HeuristicLookupBuffer::Evaluate
const std::vector< int > & Evaluate()
Definition: DelayedHeuristicAStar.h:42
path
A linked list of nodes which form a continuous path.
Definition: Path.h:20
DelayedHeuristicAStar::tempData
Definition: DelayedHeuristicAStar.h:171
DelayedHeuristicAStar::Draw
void Draw(Graphics::Display &disp) const
Draw the open/closed list.
Definition: DelayedHeuristicAStar.h:716
DelayedHeuristicAStar::SVGDrawDetailed
std::string SVGDrawDetailed() const
Definition: DelayedHeuristicAStar.h:821
DelayedHeuristicAStar::nodesExpanded
uint64_t nodesExpanded
Definition: DelayedHeuristicAStar.h:153
DelayedHeuristicAStar::GetNecessaryExpansions
uint64_t GetNecessaryExpansions() const
Definition: DelayedHeuristicAStar.h:537
DelayedHeuristicAStar::neighborID
std::vector< uint64_t > neighborID
Definition: DelayedHeuristicAStar.h:156
kClosedList
@ kClosedList
Definition: AStarOpenClosed.h:29
DelayedHeuristicAStar::goalFCost
double goalFCost
Definition: DelayedHeuristicAStar.h:162
HeuristicLookupBuffer
Definition: DelayedHeuristicAStar.h:19
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
DelayedHeuristicAStar::GetClosedItem
bool GetClosedItem(const state &s, AStarOpenClosedDataWithF< state > &)
Definition: DelayedHeuristicAStar.h:626
DelayedHeuristicAStar::GetNodesTouched
uint64_t GetNodesTouched() const
Definition: DelayedHeuristicAStar.h:122
Graphics::Display::data
Definition: Graphics.h:226