HOG2
AbstractWeightedSearchAlgorithm.h
Go to the documentation of this file.
1 
27 #ifndef ABSTRACTWEIGHTEDSEARCHALGORITHM_H
28 #define ABSTRACTWEIGHTEDSEARCHALGORITHM_H
29 
30 #include "GraphEnvironment.h"
31 #include "Map2DEnvironment.h"
32 #include "TemplateAStar.h"
33 #include "GraphAbstraction.h"
34 
39 class GraphOccupancyInterface : public OccupancyInterface<graphState,graphMove>
40 {
41 public:
44  virtual void SetStateOccupied(const graphState &gs, bool b )
45  { xyLoc s = Convert(gs); boi->SetStateOccupied(s,b); }
46  virtual bool GetStateOccupied(const graphState &gs)
47  { xyLoc s = Convert(gs); return boi->GetStateOccupied(s);}
48  virtual bool CanMove(const graphState &gs1, const graphState &gs2)
49  { xyLoc s1 = Convert(gs1); xyLoc s2 = Convert(gs2);return boi->CanMove(s1,s2);}
50  virtual void MoveUnitOccupancy(const graphState &gs1, const graphState &gs2)
51  { xyLoc s1 = Convert(gs1); xyLoc s2 = Convert(gs2); boi->MoveUnitOccupancy(s1, s2);}
52 
53 private:
55  {
56  node* n = g->GetNode(gs);
57 
58  xyLoc returnme;
61  return returnme;
62  }
63 
65  //BitVector *bitvec; /// For each map position, set if occupied
66 
67  //long mapWidth; /// Used to compute index into bitvector
68  //long mapHeight; /// used to compute index into bitvector
69 
70  long CalculateIndex(uint16_t x, uint16_t y);
71 
72  Graph* g;
73 };
74 
78 {
79 public:
80  AbsGraphEnvironment(Graph *_g, GraphHeuristic *gh, AbsMapEnvironment *me, BaseMapOccupancyInterface *bmoi)
81  :GraphEnvironment(_g,gh){g = _g; h = gh;wenv = 0; regenv = me; goi = new GraphOccupancyInterface(bmoi,g); exactGoal = false; SetDirected(false); noDummyGoal = false;}
82  void SetAbsGraph(Graph *_g){abs=_g;};
85  //void SetBaseMapOccupancyInterface(BaseMapOccupancyInterface *bmoi){
87 
88 /* void OutputXY(graphState &n)
89  {
90  node* s1 = g->GetNode(n);
91  // std::cout<<"("<<s1->GetLabelL(GraphAbstractionConstants::kFirstData)<<","
92  // <<s1->GetLabelL(GraphAbstractionConstants::kFirstData+1)<<")";
93 
94  }*/
95 
97  void SetFindExactGoal(bool b) { exactGoal = b; }
98 
101  bool GoalTest(const graphState &state, const graphState &goal)
102  {
103  if (noDummyGoal)
104  return false;
105 
106  if (exactGoal)
107  {
108  //std::cout<<"exact\n";
109  return (state == goal);
110  }
111  //std::cout<<"Not exact\n";
112  //std::cout<<"state "<<state<<" goal "<<goal<<std::endl;
113  node *n = g->GetNode(state);
114 
116 
117  node *gn = g->GetNode(goal);
119 
120  //std::cout<<"Parents: "<<nParent<<" "<<goalParent<<std::endl;
121 
122  // if parent of node & goal are the same, return true
123  if (nParent == goalParent)
124  {
125  return true;
126  }
127  return false;
128  }
129 
130  double HCost(const graphState &state1, const graphState &state2) const
131  {
132  if (h)
133  {
134  if (exactGoal || noDummyGoal)
135  {
136  // Print(state1);
137  // std::cout<<" to ";
138  // Print(state2);
139  //std::cout<<"Exact goal\n";
140  // std::cout<<" Returning "<<h->HCost(state1,state2)<<std::endl;
141  return h->HCost(state1,state2);
142  }
143  // if not exact goal, return distance to middle of abstract sector
144  // Get parent of state2
145  node *n = g->GetNode(state2);
147  node* par = abs->GetNode(nParent);
148 
149  // get tile in middle
150  int parx, pary;
151  regenv->GetMapAbstraction()->GetTileUnderLoc(parx,pary,regenv->GetMapAbstraction()->GetNodeLoc(par));
152  //std::cout<<"parx "<<parx<<" pary: "<<pary<<std::endl;
153 
154  //Get coordinates for state1
155  node *n1 = g->GetNode(state1);
156  xyLoc st1;
159 
160  //std::cout<<"HCOST ABSGRAPHENV\n";
161  return sqrt(pow(st1.x-parx,2) + pow(st1.y-pary,2));
162 
163  }
164  return 0;
165 
166  }
167 
168  void Print(graphState &s)
169  {
170  node *n = g->GetNode(s);
173  }
174 
175 // double Distance(graphState &state1, graphState &state2)
176 // {
177 // node* from = g->GetNode(state1);
178 //
179 // node* to = g->GetNode(state2);
180 //
181 // int x1 = from->GetLabelL(GraphAbstractionConstants::kFirstData);
182 // int y1 = from->GetLabelL(GraphAbstractionConstants::kFirstData+1);
183 // int x2 = to->GetLabelL(GraphAbstractionConstants::kFirstData);
184 // int y2 = to->GetLabelL(GraphAbstractionConstants::kFirstData+1);
185 //
186 // //int x1 = g->GetNode(state1)->GetLabelL(GraphAbstractionConstants::kXCoordinate);
187 // //int y1 = g->GetNode(state1)->GetLabelL(GraphSearchConstants::kMapY);
188 // //int x2 = g->GetNode(state2)->GetLabelL(GraphSearchConstants::kMapX);
189 // //int y2 = g->GetNode(state2)->GetLabelL(GraphSearchConstants::kMapY);
190 //
191 // //std::cout<<"x1 "<<x1<<" y1 "<<y1<<" x2 "<<x2<<" y2 "<<y2<<std::endl;
192 //
193 // //std::cout<<"Straight returning "<<sqrt(pow(x1-x2,2) + pow(y1-y2,2))<<std::endl;
194 // return sqrt(pow(x1-x2,2) + pow(y1-y2,2));
195 // }
196 
197  virtual double GCost(const graphState &state1, const graphMove &state2)
198  {
199  return AbsGraphEnvironment::GCost(state1, state2);
200  }
201 
203  double GCost(const graphState &state1, const graphState &state2)
204  {
205 
206  //std::cout<<"Using GCost in new env\n";
207  // Get the GCost from the weighted environment
208  node* s1 = g->GetNode(state1);
209  node* s2 = g->GetNode(state2);
210 
212  xyLoc from, to;
215 
218  //std::cout<<to<<" "<<from<<std::endl;
219  //std::cout<<"wenv "<<wenv<<std::endl;
220  //std::cout<<"GCOST "<<wenv->GCost(from,to)<<std::endl;
221  return wenv->GCost(from,to);
222 
223 
224  }
225 
226  /* SetNoDummyGoal should be set to true for the dummy environment.
227 
228  */
229  void SetNoDummyGoal(bool b) {noDummyGoal = b;}
230 
231  virtual void StoreGoal(graphState &) {}
232  virtual void ClearGoal() {}
233  virtual bool IsGoalStored() const {return false;}
234 
235  virtual double HCost(const graphState &) const {
236  fprintf(stderr, "ERROR: Single State HCost not implemented for AbsGraphEnvironment\n");
237  exit(1); return -1.0;}
238 
239  bool GoalTest(const graphState &){
240  fprintf(stderr, "ERROR: Single State Goal Test not implemented for AbsGraphEnvironment\n");
241  exit(1); return false;}
242 
243 private:
248  AbsMapEnvironment *regenv;
250  bool exactGoal;
252 };
253 
255 public:
257  :m(map), g(graph), mapgraph(mg) {}
258  Graph *GetGraph() { return g; }
259  double HCost(const graphState &state1, const graphState &state2) const
260  {
261  //std::cout<<"state1 "<<state1<<" state2 "<<state2<<std::endl;
262  //modified for abstract nodes
263 
264  // Get child nodes and find distance between them. Sigh.
265  node* from = g->GetNode(state1);
267 
268  node* to = g->GetNode(state2);
270 
275 
276  //int x1 = g->GetNode(state1)->GetLabelL(GraphAbstractionConstants::kXCoordinate);
277  //int y1 = g->GetNode(state1)->GetLabelL(GraphSearchConstants::kMapY);
278  //int x2 = g->GetNode(state2)->GetLabelL(GraphSearchConstants::kMapX);
279  //int y2 = g->GetNode(state2)->GetLabelL(GraphSearchConstants::kMapY);
280 
281  //std::cout<<"x1 "<<x1<<" y1 "<<y1<<" x2 "<<x2<<" y2 "<<y2<<std::endl;
282 
283  //std::cout<<"Straight returning "<<sqrt(pow(x1-x2,2) + pow(y1-y2,2))<<std::endl;
284  return sqrt(pow(x1-x2,2) + pow(y1-y2,2));
285  }
286 private:
287  Map *m;
290 };
291 
293 public:
294  OctileHeuristic(Map *map, Graph *graph)
295  :m(map), g(graph) {}
296  Graph *GetGraph() { return g; }
297  double HCost(const graphState &state1, const graphState &state2) const
298  {
303 
304  double a = ((x1>x2)?(x1-x2):(x2-x1));
305  double b = ((y1>y2)?(y1-y2):(y2-y1));
306  //std::cout<<"Octile returning "<<(a>b)?(b*ROOT_TWO+a-b):(a*ROOT_TWO+b-a);
307  return (a>b)?(b*ROOT_TWO+a-b):(a*ROOT_TWO+b-a);
308  }
309 private:
310  Map *m;
312 };
313 
319 template <class state, class action, class environment>
320 class AbstractWeightedSearchAlgorithm : public GenericSearchAlgorithm<state,action,environment>
321 {
322  public:
323 
326  bool InitializeSearch(environment *env, const state& from, const state& to, std::vector<state> &thePath);
327  virtual void GetPath(environment *env, const state& from, const state& to, std::vector<state> &thePath);
328  virtual void GetPath(environment *, const state &, const state &, std::vector<action> &) {}
329  virtual const char *GetName() {return "AbstractWeightedSearchAlgorihm";}
330  virtual uint64_t GetNodesExpanded() const {return nodesExpanded;}
331  virtual uint64_t GetNodesTouched() const {return nodesTouched;}
332  virtual void LogFinalStats(StatCollection *) {}
333 
338 
343  void SetSkipAbsNode(double pathPerc) { assert((pathPerc > 0) && (pathPerc <= 1)); partialSkip = true; refinePart = pathPerc; }
344 
345  private:
346  uint64_t nodesExpanded;
347  uint64_t nodesTouched;
349 
351  double refinePart;
352 };
353 
354 template<class state, class action, class environment>
356 {
357  partialSkip = false;
358 }
359 
360 template<class state, class action, class environment>
362 {
363 
364 }
365 
366 template<class state, class action, class environment>
367 bool AbstractWeightedSearchAlgorithm<state,action,environment>::InitializeSearch(environment *, const state& , const state& , std::vector<state> &)
368 {
369  nodesExpanded = 0;
370  nodesTouched = 0;
371  return true;
372 }
373 
374 template<class state, class action, class environment>
375 void AbstractWeightedSearchAlgorithm<state,action,environment>::GetPath(environment *theEnv, const state& from, const state& to, std::vector<state> &thePath)
376 {
377 
378  //std::cout<<"path from "<<from<<std::endl;
379  // get abs path
380  // if neighbour is child of next abs node, skip this one
381 
382  InitializeSearch(theEnv, from, to, thePath);
383  //std::cout<<"NodesExpanded before starting "<<nodesExpanded<<std::endl;
384  thePath.clear();
385 
386  MapAbstraction* ma = theEnv->GetMapAbstraction();
387  Graph *abs = ma->GetAbstractGraph(1);
388  Graph *g = ma->GetAbstractGraph(0);
389 
390  //Find parent of "from"
391  node* fromnode = ma->GetNodeFromMap(from.x, from.y);
393  graphState fromGs = fromnode->GetNum();
394 
395  //Find parent of "to"
396  node* tonode = theEnv->GetMapAbstraction()->GetNodeFromMap(to.x,to.y);
398  graphState toGs = tonode->GetNum();
399 
400  // Check if we're already in the same abstract node
401  if (fromPar == toPar)
402  {
403  // std::cout<<"in same parent\n";
404  // Do straight planning on lower level, using the direction map
405  std::vector<graphState> refpath;
406  OctileHeuristic *heuri = new OctileHeuristic(ma->GetMap(),g);
407 
408  AbsGraphEnvironment *graphenv = new AbsGraphEnvironment(g,heuri,theEnv,theEnv->GetOccupancyInfo());
409  graphenv->SetFindExactGoal(true); // We don't want just any child of the parent of the goal state
410  graphenv->SetWeightedEnvironment(wenv);
411  graphenv->SetAbsGraph(abs);
412 
414  astar.GetPath(graphenv,fromGs,toGs,refpath);
415 
416  nodesExpanded += astar.GetNodesExpanded();
417  nodesTouched += astar.GetNodesTouched();
418  // std::cout<<"No abs path. "<<fromGs<<" to "<<toGs<<" required "<<astar->GetNodesExpanded()<<" nodes exp.\n";
419 
420  // Copy the path into thePath, as xyLoc
421  for (unsigned int j=0; j<refpath.size(); j++)
422  {
423  node* newnode = g->GetNode(refpath[j]);
424  xyLoc newloc;
427  thePath.push_back(newloc);
428  }
429 
430 // std::cout<<"In final sector ";
431 // for (int i=0; i<thePath.size(); i++)
432 // {
433 // std::cout<<thePath[i]<<" ";
434 // }
435 // std::cout<<std::endl<<std::endl;
436 //
437  return;
438  }
439  else // fromPar != toPar
440  {
441  //Find abstract path
442  std::vector<graphState> abspath;
443 
444  GraphStraightLineHeuristic *heur = new GraphStraightLineHeuristic(ma->GetMap(),abs, g);
445 
446  GraphEnvironment *graphenv = new GraphEnvironment(abs,heur);
447  graphenv->SetDirected(false);
449 
450  astar.DoAbstractSearch(); // Don't want to use radius & occupancy interface at abstract level
451  astar.GetPath(graphenv,fromPar,toPar,abspath);
452 
453  nodesExpanded += astar.GetNodesExpanded();
454  nodesTouched += astar.GetNodesTouched();
455  // std::cout<<"Abs path "<<fromPar<<" to "<<toPar<<" required "<<astar->GetNodesExpanded()<<" nodes exp.\n";
456  // for (int i=0; i<abspath.size(); i++)
457  // {
458  // std::cout<<abspath[i]<<" ";
459  // }
460  // std::cout<<std::endl;
461 
462  //Refinement
463  //GraphStraightLineHeuristic *heur2 = new GraphStraightLineHeuristic(ma->GetMap(),g);
464 
465  OctileHeuristic *heur2 = new OctileHeuristic(ma->GetMap(),g);
466  AbsGraphEnvironment *age = new AbsGraphEnvironment(g,heur2,theEnv,theEnv->GetOccupancyInfo());
467  age->SetWeightedEnvironment(wenv);
468  age->SetAbsGraph(abs);
469 
470  //Create a 'dummy' environment for A* to use to check radius
471  OctileHeuristic *heurbla = new OctileHeuristic(ma->GetMap(),g);
472  AbsGraphEnvironment *agebla = new AbsGraphEnvironment(g,heurbla,theEnv,theEnv->GetOccupancyInfo());
473  agebla->SetWeightedEnvironment(wenv);
474  agebla->SetAbsGraph(abs);
475  agebla->SetNoDummyGoal(true);
476 
477  graphState start = fromGs;
478 
480  astar2.SetRadiusEnvironment(agebla);
481 
482 // graphState lastloc;
483 
484  std::vector<graphState> refpath;
485  assert(abspath.size() != 0);
486 
487  xyLoc nl;
490  //std::cout<<newloc<<" ";
491  thePath.push_back(nl);
492 
493  // if partialSkip is true, we find a path to the one-after-next abstract node, and cut off the path
494  // after some percentage (skipPerc is a value between 0 and 1, indicating the proportion to keep)
495  if (partialSkip)
496  {
497 
498  //if absPath's length is 2, want to do straight planning to goal (no cut off)
499  if (abspath.size()==2)
500  {
501 
502  // std::cout<<"Size 2\n";
503  // Do straight planning on lower level, using the direction map
504  std::vector<graphState> refPath;
505  OctileHeuristic *heuri = new OctileHeuristic(ma->GetMap(),g);
506 
507  AbsGraphEnvironment *graphEnv = new AbsGraphEnvironment(g,heuri,theEnv,theEnv->GetOccupancyInfo());
508  graphEnv->SetFindExactGoal(true); // We don't want just any child of the parent of the goal state
509  graphEnv->SetWeightedEnvironment(wenv);
510  graphEnv->SetAbsGraph(abs);
511 
513  AStar.GetPath(graphEnv,fromGs,toGs,refPath);
514 
515  nodesExpanded += AStar.GetNodesExpanded();
516  nodesTouched += AStar.GetNodesTouched();
517 
518  // Copy the path into thePath, as xyLoc
519  for (unsigned int j=1; j<refPath.size(); j++)
520  {
521  node* newnode = g->GetNode(refPath[j]);
522  xyLoc newloc;
525  thePath.push_back(newloc);
526  }
527 
528 /* std::cout<<"Abs path length 2, partialskip ";
529  for (int i=0; i<thePath.size(); i++)
530  {
531  std::cout<<thePath[i]<<" ";
532  }
533  std::cout<<std::endl<<std::endl;
534  */
535  delete age;
536  delete graphEnv;
537  return;
538  }
539  else // abs path not length 2
540  {
541  // std::cout<<"Abs longer than 2\n";
542  // path to second next abstract node and cut off the path
544 
545  refpath.clear();
546 
547  astar2.GetPath(age,start,end,refpath);
548  nodesExpanded += astar2.GetNodesExpanded();
549  nodesTouched += astar2.GetNodesTouched();
550 
551  if (refpath.size()>0)
552  {
553  for (unsigned int j=1; j<refpath.size(); j++)
554  {
555  node* newnode = g->GetNode(refpath[j]);
556 
557  xyLoc newloc;
560  thePath.push_back(newloc);
561  }
562  //start = refpath[refpath.size()-1];
563  }
564 
565 
566 // // Do the last one separate - need to get to exact goal
567 //
568 // OctileHeuristic *heur3 = new OctileHeuristic(ma->GetMap(),g);
569 //
570 // AbsGraphEnvironment *absgraphenv2 = new AbsGraphEnvironment(g,heur3,theEnv,theEnv->GetOccupancyInfo());
571 // absgraphenv2->SetFindExactGoal(true);
572 // absgraphenv2->SetWeightedEnvironment(wenv);
573 // absgraphenv2->SetAbsGraph(abs);
574 //
575 // refpath.clear();
576 //
577 // TemplateAStar<graphState,graphMove,GraphEnvironment> *astar3 = new TemplateAStar<graphState, graphMove,GraphEnvironment>();
578 // astar3->GetPath(absgraphenv2,start,toGs,refpath);
579 // nodesExpanded += astar3->GetNodesExpanded();
580 // nodesTouched += astar3->GetNodesTouched();
581 //
582 // for (int j=1; j<refpath.size(); j++)
583 // {
584 // node* newnode = g->GetNode(refpath[j]);
585 // xyLoc newloc;
586 // newloc.x = newnode->GetLabelL(GraphAbstractionConstants::kFirstData);
587 // newloc.y = newnode->GetLabelL(GraphAbstractionConstants::kFirstData+1);
588 // thePath.push_back(newloc);
589 // }
590  // Chop off the path
591  int desiredLength = (int)(refinePart * thePath.size());
592 
593  if (desiredLength>3)
594  thePath.resize(desiredLength);
595 
596  // std::cout<<"desiredlength is "<<desiredLength<<" total is "<<thePath.size()<<std::endl;
597  //int oldsize = thePath.size();
598  //for (int i=desiredLength; i<oldsize; i++)
599  //{
600  // thePath.pop_back();
601  //}
602 
603 // std::cout<<"I'm at "<<nl<<std::endl;
604  /*std::cout<<"Partial skip ";
605  for (int i=0; i<thePath.size(); i++)
606  {
607  std::cout<<thePath[i]<<" ";
608  }
609  std::cout<<std::endl<<std::endl;
610 
611 // */ //td::cout<<"after "<<thePath.size()<<std::endl;
612  delete age;
613  return;
614  } // end else (length of abs path > 2)
615 
616 
617 
618  } // end if (partialSkip)
619  else//not partialskip
620  {
621  for (unsigned int i=1; i<abspath.size()-1; i++)
622  //for (unsigned int i=1; i<2; i++)
623  {
624  //if any of my neighbours is a child of this abs node - skip it
625  std::vector<graphState> nb;
626  age->GetSuccessors(start, nb);
627 
628  bool skip = false;
629  for (unsigned int k=0; k<nb.size(); k++)
630  {
631  node* neigh = g->GetNode(nb[k]);
632  if (neigh->GetLabelL(GraphAbstractionConstants::kParent) == (long)abspath[i])
633  skip = true;
634  }
635 
636  if (skip)
637  {
638  //std::cout<<"skipping\n";
639  continue;
640  }
641 
642  //Refine the path
643  //Path to first any child - will get 'fixed' in GoalTest in environment
645  //std::cout<<"abs end "<<abspath[i]<<std::endl;
646  //std::cout<<"end is "<<end<<std::endl;
647  //ma->GetAbstractGraph(0)->GetNode(abspath[i]);
648 
649  refpath.clear();
650 
651  /*********DEBUG********/
652 /* node* debug = g->GetNode(start);
653  xyLoc d;
654  d.x = debug->GetLabelL(GraphAbstractionConstants::kFirstData);
655  d.y = debug->GetLabelL(GraphAbstractionConstants::kFirstData+1);
656 
657  debug = g->GetNode(end);
658  xyLoc d2;
659  d2.x = debug->GetLabelL(GraphAbstractionConstants::kFirstData);
660  d2.y = debug->GetLabelL(GraphAbstractionConstants::kFirstData+1);
661  */
662  // std::cout<<"searching from "<<d<<" to "<<d2<<std::endl;
663 
664  /*****END DEBUG****/
665 
666 
667  astar2.GetPath(age,start,end,refpath);
668 
669  nodesExpanded += astar2.GetNodesExpanded();
670  nodesTouched += astar2.GetNodesTouched();
671 
672  //std::cout<<start<<" to "<<end<<" required "<<astar2->GetNodesExpanded()<<" nodes exp.\n";
673  //std::cout<<"Refining nodes expanded now "<<nodesExpanded<<std::endl;
674 
675  if (refpath.size()>0)
676  {
677  for (unsigned int j=1; j<refpath.size(); j++)
678  {
679  node* newnode = g->GetNode(refpath[j]);
680  //std::cout<<newnode->GetNum()<<std::endl;
681  xyLoc newloc;
684  // std::cout<<newloc<<" ";
685  thePath.push_back(newloc);
686  }
687  //std::cout<<std::endl;
688  //std::cout<<Refpath size is zero!!!\n";
689  start = refpath[refpath.size()-1];
690  }
691  }
692 
693  // Do the last one separate - need to get to exact goal
694 
695  OctileHeuristic *heur3 = new OctileHeuristic(ma->GetMap(),g);
696 
697  AbsGraphEnvironment *absgraphenv2 = new AbsGraphEnvironment(g,heur3,theEnv,theEnv->GetOccupancyInfo());
698  absgraphenv2->SetFindExactGoal(true);
699  absgraphenv2->SetWeightedEnvironment(wenv);
700  absgraphenv2->SetAbsGraph(abs);
701 
702  refpath.clear();
703 
705  astar3.GetPath(absgraphenv2,start,toGs,refpath);
706  nodesExpanded += astar3.GetNodesExpanded();
707  nodesTouched += astar3.GetNodesTouched();
708  //std::cout<<start<<" to "<<toGs<<" required "<<astar3->GetNodesExpanded()<<" nodes exp.\n";
709  //Transfer the path to thePath, as series of xyLoc
710  // std::cout<<"last bit "<<std::endl;
711  for (unsigned int j=1; j<refpath.size(); j++)
712  {
713  node* newnode = g->GetNode(refpath[j]);
714  xyLoc newloc;
717  //std::cout<<newloc<<" ";
718  thePath.push_back(newloc);
719  }
720 
721 // std::cout<<"Regular ";
722 // for (int i=0; i<thePath.size(); i++)
723 // {
724 // std::cout<<thePath[i]<<" ";
725 // }
726 // std::cout<<std::endl<<std::endl;
727 //
728  delete age;
729  delete absgraphenv2;
730  return;
731  }// end else --> not partialSkip
732 
733 
734 
735 
736  } // end else --> start and goal not same parent
737 }
738 
739 #endif
AbstractWeightedSearchAlgorithm::SetWeightedEnvironment
void SetWeightedEnvironment(WeightedMap2DEnvironment *w)
Set the weighted environment This must be set for the algorithm to work.
Definition: AbstractWeightedSearchAlgorithm.h:337
AbsGraphEnvironment::GetOccupancyInfo
GraphOccupancyInterface * GetOccupancyInfo()
Definition: AbstractWeightedSearchAlgorithm.h:86
AbstractWeightedSearchAlgorithm::refinePart
double refinePart
Definition: AbstractWeightedSearchAlgorithm.h:351
GraphStraightLineHeuristic::GraphStraightLineHeuristic
GraphStraightLineHeuristic(Map *map, Graph *graph, Graph *mg)
Definition: AbstractWeightedSearchAlgorithm.h:256
graphMove
Definition: GraphEnvironment.h:34
GraphOccupancyInterface::SetStateOccupied
virtual void SetStateOccupied(const graphState &gs, bool b)
Definition: AbstractWeightedSearchAlgorithm.h:44
AbsGraphEnvironment::GoalTest
bool GoalTest(const graphState &)
Definition: AbstractWeightedSearchAlgorithm.h:239
GraphOccupancyInterface::CanMove
virtual bool CanMove(const graphState &gs1, const graphState &gs2)
Definition: AbstractWeightedSearchAlgorithm.h:48
OctileHeuristic::g
Graph * g
Definition: AbstractWeightedSearchAlgorithm.h:311
AbsGraphEnvironment::goi
GraphOccupancyInterface * goi
Definition: AbstractWeightedSearchAlgorithm.h:249
WeightedMap2DEnvironment::GCost
virtual double GCost(const xyLoc &node1, const xyLoc &node2) const
Definition: WeightedMap2DEnvironment.cpp:379
graphState
unsigned long graphState
Definition: GraphEnvironment.h:32
BaseMapOccupancyInterface::GetStateOccupied
virtual bool GetStateOccupied(const xyLoc &)
Returns the occupancy of a state.
Definition: Map2DEnvironment.cpp:1593
BaseMapOccupancyInterface
Definition: Map2DEnvironment.h:82
OctileHeuristic::HCost
double HCost(const graphState &state1, const graphState &state2) const
Definition: AbstractWeightedSearchAlgorithm.h:297
AbstractWeightedSearchAlgorithm::InitializeSearch
bool InitializeSearch(environment *env, const state &from, const state &to, std::vector< state > &thePath)
Definition: AbstractWeightedSearchAlgorithm.h:367
TemplateAStar::GetNodesExpanded
uint64_t GetNodesExpanded() const
Definition: TemplateAStar.h:134
xyLoc::y
uint16_t y
Definition: Map2DEnvironment.h:42
AbstractWeightedSearchAlgorithm::LogFinalStats
virtual void LogFinalStats(StatCollection *)
Definition: AbstractWeightedSearchAlgorithm.h:332
AbsGraphEnvironment::Print
void Print(graphState &s)
Definition: AbstractWeightedSearchAlgorithm.h:168
AbstractWeightedSearchAlgorithm
A search algorithm which combines direction maps with abstraction.
Definition: AbstractWeightedSearchAlgorithm.h:320
AbsGraphEnvironment::SetWeightedEnvironment
void SetWeightedEnvironment(WeightedMap2DEnvironment *w)
Definition: AbstractWeightedSearchAlgorithm.h:83
AbstractWeightedSearchAlgorithm::wenv
WeightedMap2DEnvironment * wenv
Definition: AbstractWeightedSearchAlgorithm.h:348
AbsGraphEnvironment::GoalTest
bool GoalTest(const graphState &state, const graphState &goal)
If exactGoal is set, GoalTest returns true when state is the same as goal.
Definition: AbstractWeightedSearchAlgorithm.h:101
AbsGraphEnvironment::noDummyGoal
bool noDummyGoal
Definition: AbstractWeightedSearchAlgorithm.h:251
AbsGraphEnvironment::HCost
double HCost(const graphState &state1, const graphState &state2) const
Heuristic value between two arbitrary nodes.
Definition: AbstractWeightedSearchAlgorithm.h:130
GraphEnvironment::GetSuccessors
virtual void GetSuccessors(const graphState &stateID, std::vector< graphState > &neighbors) const
Definition: GraphEnvironment.cpp:75
GraphOccupancyInterface
Occupancy interface which works with graphState and graphMove A wrapper to use with an exisitng BaseM...
Definition: AbstractWeightedSearchAlgorithm.h:39
BaseMapOccupancyInterface::MoveUnitOccupancy
virtual void MoveUnitOccupancy(const xyLoc &, const xyLoc &)
Updates the occupancy interface when a unit moves.
Definition: Map2DEnvironment.cpp:1629
xyLoc
Definition: Map2DEnvironment.h:37
GraphOccupancyInterface::CalculateIndex
long CalculateIndex(uint16_t x, uint16_t y)
GraphStraightLineHeuristic::GetGraph
Graph * GetGraph()
Definition: AbstractWeightedSearchAlgorithm.h:258
Map2DEnvironment.h
AbsGraphEnvironment::wenv
WeightedMap2DEnvironment * wenv
Definition: AbstractWeightedSearchAlgorithm.h:246
GraphOccupancyInterface::GraphOccupancyInterface
GraphOccupancyInterface(BaseMapOccupancyInterface *b, Graph *_g)
Definition: AbstractWeightedSearchAlgorithm.h:42
Graph
A generic Graph class.
Definition: Graph.h:66
AbstractWeightedSearchAlgorithm::GetPath
virtual void GetPath(environment *, const state &, const state &, std::vector< action > &)
Definition: AbstractWeightedSearchAlgorithm.h:328
GraphOccupancyInterface::Convert
xyLoc Convert(const graphState &gs)
Definition: AbstractWeightedSearchAlgorithm.h:54
AbstractWeightedSearchAlgorithm::GetName
virtual const char * GetName()
Definition: AbstractWeightedSearchAlgorithm.h:329
Graph::GetNode
node * GetNode(unsigned long num)
Definition: Graph.cpp:152
GraphStraightLineHeuristic::HCost
double HCost(const graphState &state1, const graphState &state2) const
Definition: AbstractWeightedSearchAlgorithm.h:259
xyLoc::x
uint16_t x
Definition: Map2DEnvironment.h:41
TemplateAStar::GetPath
void GetPath(environment *env, const state &from, const state &to, std::vector< state > &thePath)
Perform an A* search between two states.
Definition: TemplateAStar.h:214
AbsGraphEnvironment::StoreGoal
virtual void StoreGoal(graphState &)
Stores the goal for use by single-state HCost.
Definition: AbstractWeightedSearchAlgorithm.h:231
OctileHeuristic::GetGraph
Graph * GetGraph()
Definition: AbstractWeightedSearchAlgorithm.h:296
GenericSearchAlgorithm
Definition: GenericSearchAlgorithm.h:35
GraphEnvironment::SetDirected
void SetDirected(bool b)
Definition: GraphEnvironment.h:303
AbsGraphEnvironment::g
Graph * g
Definition: AbstractWeightedSearchAlgorithm.h:244
AbsGraphEnvironment::h
GraphHeuristic * h
Definition: AbstractWeightedSearchAlgorithm.h:247
AbstractWeightedSearchAlgorithm::partialSkip
bool partialSkip
Definition: AbstractWeightedSearchAlgorithm.h:350
WeightedMap2DEnvironment
Definition: WeightedMap2DEnvironment.h:120
AbstractWeightedSearchAlgorithm::~AbstractWeightedSearchAlgorithm
virtual ~AbstractWeightedSearchAlgorithm()
Definition: AbstractWeightedSearchAlgorithm.h:361
AbsGraphEnvironment::AbsGraphEnvironment
AbsGraphEnvironment(Graph *_g, GraphHeuristic *gh, AbsMapEnvironment *me, BaseMapOccupancyInterface *bmoi)
Definition: AbstractWeightedSearchAlgorithm.h:80
GraphOccupancyInterface::MoveUnitOccupancy
virtual void MoveUnitOccupancy(const graphState &gs1, const graphState &gs2)
Definition: AbstractWeightedSearchAlgorithm.h:50
AbstractWeightedSearchAlgorithm::nodesTouched
uint64_t nodesTouched
Definition: AbstractWeightedSearchAlgorithm.h:347
GraphAbstractionConstants::kFirstData
@ kFirstData
Definition: GraphAbstraction.h:34
TemplateAStar::GetNodesTouched
uint64_t GetNodesTouched() const
Definition: TemplateAStar.h:135
GraphStraightLineHeuristic
Definition: AbstractWeightedSearchAlgorithm.h:254
OctileHeuristic::m
Map * m
Definition: AbstractWeightedSearchAlgorithm.h:310
ROOT_TWO
static const double ROOT_TWO
Definition: GLUtil.h:61
TemplateAStar
A templated version of A*, based on HOG genericAStar.
Definition: TemplateAStar.h:73
GraphAbstractionConstants::kAbstractionLevel
@ kAbstractionLevel
Definition: GraphAbstraction.h:25
GraphOccupancyInterface::GetStateOccupied
virtual bool GetStateOccupied(const graphState &gs)
Definition: AbstractWeightedSearchAlgorithm.h:46
TemplateAStar.h
AbsGraphEnvironment::HCost
virtual double HCost(const graphState &) const
Heuristic value between node and the stored goal.
Definition: AbstractWeightedSearchAlgorithm.h:235
AbstractWeightedSearchAlgorithm::nodesExpanded
uint64_t nodesExpanded
Definition: AbstractWeightedSearchAlgorithm.h:346
AbstractWeightedSearchAlgorithm::AbstractWeightedSearchAlgorithm
AbstractWeightedSearchAlgorithm()
Definition: AbstractWeightedSearchAlgorithm.h:355
AbstractWeightedSearchAlgorithm::SetSkipAbsNode
void SetSkipAbsNode(double pathPerc)
Set skip abstract nodes, and partial path refinement If set to 'true', the algorithm plans to the one...
Definition: AbstractWeightedSearchAlgorithm.h:343
OctileHeuristic::OctileHeuristic
OctileHeuristic(Map *map, Graph *graph)
Definition: AbstractWeightedSearchAlgorithm.h:294
GraphStraightLineHeuristic::mapgraph
Graph * mapgraph
Definition: AbstractWeightedSearchAlgorithm.h:289
AbsGraphEnvironment
A graph environment to use with the a graph abstraction.
Definition: AbstractWeightedSearchAlgorithm.h:77
AbsGraphEnvironment::GCost
virtual double GCost(const graphState &state1, const graphMove &state2)
Definition: AbstractWeightedSearchAlgorithm.h:197
AbsGraphEnvironment::SetNoDummyGoal
void SetNoDummyGoal(bool b)
Definition: AbstractWeightedSearchAlgorithm.h:229
AbsGraphEnvironment::SetAbsGraph
void SetAbsGraph(Graph *_g)
Definition: AbstractWeightedSearchAlgorithm.h:82
StatCollection
The StatCollection class is for collecting stats across different parts of the simulation.
Definition: StatCollection.h:34
AbsGraphEnvironment::regenv
AbsMapEnvironment * regenv
Definition: AbstractWeightedSearchAlgorithm.h:248
AbsGraphEnvironment::IsGoalStored
virtual bool IsGoalStored() const
Definition: AbstractWeightedSearchAlgorithm.h:233
AbstractWeightedSearchAlgorithm::GetNodesTouched
virtual uint64_t GetNodesTouched() const
Definition: AbstractWeightedSearchAlgorithm.h:331
node::GetNum
unsigned int GetNum() const
Definition: Graph.h:176
BaseMapOccupancyInterface::SetStateOccupied
virtual void SetStateOccupied(const xyLoc &, bool)
Sets the occupancy of a state.
Definition: Map2DEnvironment.cpp:1576
AbsGraphEnvironment::~AbsGraphEnvironment
~AbsGraphEnvironment()
Definition: AbstractWeightedSearchAlgorithm.h:84
AbsGraphEnvironment::GCost
double GCost(const graphState &state1, const graphState &state2)
GCost returns a weighted GCost from the WeightedMap2DEnvironment.
Definition: AbstractWeightedSearchAlgorithm.h:203
AbsGraphEnvironment::abs
Graph * abs
Definition: AbstractWeightedSearchAlgorithm.h:245
AbstractWeightedSearchAlgorithm::GetNodesExpanded
virtual uint64_t GetNodesExpanded() const
Definition: AbstractWeightedSearchAlgorithm.h:330
GraphStraightLineHeuristic::m
Map * m
Definition: AbstractWeightedSearchAlgorithm.h:287
GraphAbstractionConstants::kParent
@ kParent
Definition: GraphAbstraction.h:27
GraphStraightLineHeuristic::g
Graph * g
Definition: AbstractWeightedSearchAlgorithm.h:288
node::GetLabelL
long GetLabelL(unsigned int index) const
Definition: Graph.h:220
GraphHeuristic::HCost
virtual double HCost(const graphState &state1, const graphState &state2) const =0
AbsGraphEnvironment::ClearGoal
virtual void ClearGoal()
Clears the goal from memory.
Definition: AbstractWeightedSearchAlgorithm.h:232
OctileHeuristic
Definition: AbstractWeightedSearchAlgorithm.h:292
AbsGraphEnvironment::SetFindExactGoal
void SetFindExactGoal(bool b)
Set to true when we want to find the exact goal rather than any child of the parent of the goal.
Definition: AbstractWeightedSearchAlgorithm.h:97
GraphOccupancyInterface::boi
BaseMapOccupancyInterface * boi
Definition: AbstractWeightedSearchAlgorithm.h:64
GraphOccupancyInterface::g
Graph * g
Definition: AbstractWeightedSearchAlgorithm.h:72
GraphOccupancyInterface::~GraphOccupancyInterface
virtual ~GraphOccupancyInterface()
Definition: AbstractWeightedSearchAlgorithm.h:43
GraphEnvironment
Definition: GraphEnvironment.h:291
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
Map
A tile-based representation of the world.
Definition: Map.h:142
GraphAbstraction.h
AbstractWeightedSearchAlgorithm::GetPath
virtual void GetPath(environment *env, const state &from, const state &to, std::vector< state > &thePath)
Definition: AbstractWeightedSearchAlgorithm.h:375
GraphHeuristic
Definition: GraphEnvironment.h:77
AbsGraphEnvironment::exactGoal
bool exactGoal
Definition: AbstractWeightedSearchAlgorithm.h:250
BaseMapOccupancyInterface::CanMove
virtual bool CanMove(const xyLoc &, const xyLoc &)
Definition: Map2DEnvironment.cpp:1635
GraphEnvironment.h
OccupancyInterface
Definition: OccupancyInterface.h:36