HOG2
IRAStar.cpp
Go to the documentation of this file.
1 /*
2  * IRAStar.cpp
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 10/12/07.
6  * Copyright 2007 Nathan Sturtevant, University of Alberta. All rights reserved.
7  *
8  */
9 
10 #include "IRAStar.h"
11 #include <vector>
12 
13 #define HEURISTIC_COLOR
14 #define MAX_HEURISTIC_VALUE 50.0
15 #define PATHMAX // Not necessary, but improves performance for inconsistent heuristics
16 
17 using namespace IRAStarConstants;
18 
20 :SearchAlgorithm(), caching(_caching)
21 {
22  g = 0;
23 }
24 
26 {
27 }
28 
29 const char *IRAStar::GetName()
30 {
31  return "IRAStar";
32 }
33 
35 {
36  if (!InitializeSearch(aMap, from, to))
37  return 0;
38  path *p = 0;
39  while (p == 0)
40  {
41  p = DoOneSearchStep();
42  //g->Print(std::cout);
43  }
44  return p;
45 }
46 
48 {
49  if (q.size() == 0)
50  return 0;
51  node *gNext = q.top().n;
52  q.pop();
53  //printf("---\nAnalyzing %d next g:%f h:%f\n", gNext->GetNum(), GetGCost(gNext), GetHCost(gNext));
54  //std::cout << *gNext << std::endl;
55 
56 #ifdef PATHMAX
57  // PATHMAX: Check for and corrects Inconsistencies
59  if ( Inconsistent(gNext) )
60  {
61  // Do not expand, just put back on open list with new h value
62  q.Add(GNode(gNext));
63  //closedList.remove(gNext);
64  return 0;
65  }
66 #endif
67 
68  if (gNext == gGoal) // we found the goal
69  {
70  if ((q.size() > 0) &&
72  {
73  node *temp = gNext;
74  gNext = q.top().n;
75  q.pop();
76  q.Add(GNode(temp));
77  //printf("+++\nAnalyzing %d next g:%f h:%f\n", gNext->GetNum(), GetGCost(gNext), GetHCost(gNext));
78  }
79  else {
80  //SetCachedHCost(gNext, GetGCost(gNext));
81  closedList[gNext->GetNum()] = GNode(gNext);
83  if (done)
84  {
85  //printf("%d refined nodes %d expanded nodes with pathlength %u \n", nodesRefined, nodesExpanded, p->length() );
86  assert(p);
87  return p;
88  }
89  if (p)
90  {
91  q.reset();
92  closedList.clear();
93  }
94  return p;
95  }
96  }
97 
98  nodesExpanded++;
99  ExpandNeighbors(gNext);
100  //SetCachedHCost(gNext, GetGCost(gNext));
101  closedList[gNext->GetNum()] = GNode(gNext);
102 
103  return 0;
104 }
105 
107 {
108  closedList.clear();
109  q.reset();
110 
111  currentIteration = 0;
112  gStart = 0;
113  absGraph = aMap;
114  aStart = from;
115  aGoal = to;
116  delete g;
117  g = new Graph();
119 
120  // find most abstract node in Graph
121  node *top = FindTopLevelNode(from, to, aMap);
122  if (top == 0)
123  return false;
124  node *newTop = new node("top");
125  gStart = gGoal = newTop;
126  g->AddNode(newTop);
127  SetInitialValues(newTop, top, 0);
128  q.Add(GNode(newTop));
129  return true;
130 }
131 
133 {
134  if ((one == 0) || (two == 0))
135  return 0;
136  if (aMap->GetAbstractionLevel(one) >= (int)aMap->getNumAbstractGraphs())
137  return 0;
138  if (aMap->GetAbstractionLevel(one) == (int)aMap->getNumAbstractGraphs() - 1)
139  {
140  if (one == two)
141  return one;
142  return 0;
143  }
144  node *tmp = FindTopLevelNode(aMap->GetParent(one), aMap->GetParent(two), aMap);
145  if ((tmp == 0) && (one == two))
146  return one;
147  return tmp;
148 }
149 
150 /*
151  * aRealNode is the node inside the absGraph
152  * gNewNode is the node about to be added to Graph
153  * gParent is the parent inside the Graph
154  */
155 void IRAStar::SetInitialValues(node *gNewNode, node *aRealNode, node *gParent)
156 {
158  gNewNode->SetLabelL(kCorrespondingNode, aRealNode->GetNum());
159  if (gParent)
160  {
161  SetGCost(gNewNode, 0);
162  SetHCost(gNewNode, GetHCost(gParent) );
163  //std::cout << " " << GetHCost(gNewNode) ;
164  //gNewNode->SetLabelF(kCachedHCost1, gParent->GetLabelF(kCachedHCost1));
165  //gNewNode->SetLabelF(kCachedHCost2, gParent->GetLabelF(kCachedHCost2));
166  }
167  else {
168  //gNewNode->SetLabelL(kIteration, -1);
169  SetGCost(gNewNode, 0);
170  SetHCost(gNewNode, 0);
171  //gNewNode->SetLabelF(kCachedHCost1, 0);
172  //gNewNode->SetLabelF(kCachedHCost2, 0);
173  }
174 // gNewNode->SetLabelL(kOptimalFlag, 0);
175 // gNewNode->SetLabelL(kInOpenList, 1);
176 
177  if (absGraph->IsParentOf(aRealNode, aStart) || (aRealNode == aStart))
178  {
179  //std::cout << "Assigning start to " << *gNewNode << std::endl;
180  gStart = gNewNode;
181  }
182  if (absGraph->IsParentOf(aRealNode, aGoal) || (aRealNode == aGoal))
183  {
184  //std::cout << "Assigning goal to " << *gNewNode << std::endl;
185  gGoal = gNewNode;
186  }
187 }
188 
189 /*
190  * return true if inconsistency caused gNode to change heuristic value
191  */
193 {
194  neighbor_iterator ni ;
195  node *gNeighbor ;
196  edge *e ;
197  bool changedNodeH = false;
198 
199  ni = gNode->getNeighborIter();
200  for (int next = gNode->nodeNeighborNext(ni); next != -1; next = gNode->nodeNeighborNext(ni))
201  {
202  gNeighbor = g->GetNode(next);
203  e = g->FindEdge(gNode->GetNum(), gNeighbor->GetNum());
204  assert( e != 0 );
205  // Correct the heuristic value of neighboring nodes
206  if ( fless(GetHCost(gNeighbor), GetHCost(gNode)-e->GetWeight()) )
207  {
208  SetHCost( gNeighbor, GetHCost(gNode)-e->GetWeight());
209  // remove from queue and add in again (with new priority)
210  if ( q.IsIn(GNode(gNeighbor)) )
211  q.DecreaseKey(GNode(gNeighbor));
212  }
213  // Correct the heuristic value of node
214  if ( fless(GetHCost(gNode), GetHCost(gNeighbor)-e->GetWeight()) )
215  {
216 
217  //printf("%f < %f - %f \n", GetHCost(gNode), GetHCost(gNeighbor), e->GetWeight());
218  SetHCost( gNode, GetHCost(gNeighbor)-e->GetWeight());
219  // Put back on the open list instead of closed list (in main loop)
220  changedNodeH = true;
221  }
222  }
223  return changedNodeH;
224 }
225 
226 /*
227  * return true if node was expanded.
228  * return false if an inconsistency was found and we had to update gNode's heuristic value.
229  */
231 {
232  neighbor_iterator ni ;
233  node *gNeighbor ;
234  edge *e;
235 
236 // printf("Expanding %5d f-cost is %1.2f, g-cost is %1.2f\n", gNode->GetNum(), GetFCost(gNode), GetGCost(gNode));
237 
238  ni = gNode->getNeighborIter();
239  for (int next = gNode->nodeNeighborNext(ni); next != -1; next = gNode->nodeNeighborNext(ni))
240  {
241  nodesTouched++;
242  gNeighbor = g->GetNode(next);
243  e = g->FindEdge(gNode->GetNum(), gNeighbor->GetNum());
244 
245  assert( e != 0 );
246  // If already in open list
247  if (q.IsIn(GNode(gNeighbor))) // check for lower cost
248  {
249  if (fless(GetGCost(gNode)+e->GetWeight() /*1.0*/,
250  GetGCost(gNeighbor)))
251  {
252  //printf("Updating neighbor %d to gCost %f\n", gNeighbor->GetNum(), GetGCost(gNode)+1);
253  SetGCost(gNeighbor, GetGCost(gNode)+e->GetWeight()/*1.0*/);
254  //gNeighbor->SetLabelL(kIteration, -1);
255  q.DecreaseKey(GNode(gNeighbor));
256  }
257  }
258  // if already in closed list (do nothing if consistent heuristic)
259  else if (closedList.find(gNeighbor->GetNum()) != closedList.end())
260  {
261  // when using an INCONSISTENT HEURISTIC, we might have closed a node with the wrong g-value.
262  // if this is the case, re-open the node
264  if (fless(GetGCost(gNode)+e->GetWeight(), GetGCost(gNeighbor) ))
265  {
266  //printf("Re-opening neighbor with g=%f to g=%f\n", GetGCost(gNeighbor), GetGCost(gNode)+e->GetWeight());
267  SetGCost(gNeighbor, GetGCost(gNode)+e->GetWeight()/*1.0*/);
268  q.Add(GNode(gNeighbor));
269  }
270  }
271  else { // add to open list
272  //SetHCost(gNeighbor, GetCachedHCost(gNeighbor));
273  SetGCost(gNeighbor, GetGCost(gNode)+e->GetWeight()/*1.0*/);
274  q.Add(GNode(gNeighbor));
275 // printf("Adding neighbor %d with gCost %f, hCost %f\n",
276 // gNeighbor->GetNum(), GetGCost(gNode)+1, GetHCost(gNeighbor));
277  }
278  }
279 }
280 
282 {
283  done = true;
284 
285  path *p = GetSolution(gGoal);
286 
288  SetHValues( p->length() - 1 ); // set heuristic values for all nodes on closed list
289  // path p contains all nodes (not the edges), so the number of edges is slightly less.
290 
291  iterationLimits.push_back(GetGCost(gGoal));
292  for (path *i = p; i; i = i->next)
293  {
294  if (i->n->GetLabelL(kAbstractionLevel) != 0)
295  {
296  done = false;
297  }
298 
300  if ( i->n != gGoal )
301  SetHCost( i->n, p->length()-1 - GetGCost(i->n) );
302  }
303  if (done)
304  return p;
305 
306  std::vector<node*> nodes;
307  GetAllSolutionNodes(gGoal, nodes);
308  for (unsigned int x = 0; x < nodes.size(); x++)
309  {
310  //printf("## Refining %d\n", nodes[x]->GetNum());
311  RefineNode(nodes[x]);
312  }
313  //printf("%d refined nodes %d expanded nodes on iteration %d with pathlength %u \n", nodesRefined, nodesExpanded, currentIteration, p->length() );
314  closedList.clear();
315  q.reset();
316 
318 // // never switch search directions
319 // //if ( gStart->GetLabelL(kAbstractionLevel)%2 == 0 ) // Always switch diretions on base level
320 // {
321 // node *tmp = gStart;
322 // gStart = gGoal;
323 // gGoal = tmp;
324 // }
325  SetGCost(gStart, 0);
326  //SetHCost(gStart, GetCachedHCost(gStart));
327  q.Add(GNode(gStart));
328 
329  if (done)
330  return p;
331  delete p;
332  return 0;
333 }
334 
335 void IRAStar::GetAllSolutionNodes(node *goal, std::vector<node*> &nodes)
336 {
337  nodes.push_back(goal);
338  closedList.erase(goal->GetNum());
339  for (unsigned int x = 0; x < nodes.size(); x++)
340  {
341  node *gNode = nodes[x];
342 
343  neighbor_iterator ni = gNode->getNeighborIter();
344  for (int next = gNode->nodeNeighborNext(ni); next != -1; next = gNode->nodeNeighborNext(ni))
345  {
346  node *gNeighbor = g->GetNode(next);
347  if (closedList.find(gNeighbor->GetNum()) != closedList.end())
348  {
349 // printf("Neighbor (%d) has g-cost %1.2f, solution path through (%d) has cost %1.2f\n",
350 // gNeighbor->GetNum(), gNeighbor->GetLabelF(kGCost),
351 // gNode->GetNum(), gNode->GetLabelF(kGCost));
352  if (!fgreater(GetGCost(gNeighbor)+1.0, GetGCost(gNode)))
353  {
354 // printf("Adding to list!\n");
355  closedList.erase(gNeighbor->GetNum());
356  nodes.push_back(gNeighbor);
357  }
358  }
359  }
360  }
361 }
362 
364 {
365  neighbor_iterator ni = gNode->getNeighborIter();
366  for (int next = gNode->nodeNeighborNext(ni); next != -1; next = gNode->nodeNeighborNext(ni))
367  {
368  node *gNeighbor = g->GetNode(next);
369  edge *e = g->FindEdge(gNode->GetNum(), gNeighbor->GetNum());
370  assert( e != 0 );
371  if (closedList.find(gNeighbor->GetNum()) != closedList.end())
372  {
373  node* n = closedList[gNeighbor->GetNum()].n; // silly!
374  if (fequal(GetGCost(n) + e->GetWeight(), GetGCost(gNode)))
375  {
376  return new path(gNode, GetSolution(n));
377  }
378  }
379  }
380  return new path(gNode, 0);
381 }
382 
384 {
385  if (absGraph->GetAbstractionLevel(gNode) == 0)
386  {
387  if (GetRealNode(gNode) == aStart)
388  gStart = gNode;
389  if (GetRealNode(gNode) == aGoal)
390  gStart = gNode;
391  return;
392  }
393  nodesRefined++;
394  std::vector<node *> aChildren;
395  std::vector<node *> gChildren;
396  node *aNode = GetRealNode(gNode);
397  for (int x = 0; x < absGraph->GetNumChildren(aNode); x++)
398  {
399  aChildren.push_back(absGraph->GetNthChild(aNode, x));
400  }
401 
402  // first, add children to graph g
403  for (unsigned int x = 0; x < aChildren.size(); x++)
404  {
405  gChildren.push_back(new node("child"));
406  g->AddNode(gChildren[x]);
407  SetInitialValues(gChildren[x], aChildren[x], gNode);
408  //q.Add(GNode(gChildren[x]));
409 // std::cout << "Adding child:" << std::endl;
410 // std::cout << *gChildren[x] << std::endl;
411  }
412 
413  // first, connect children to each other
414  Graph *aGraph = absGraph->GetAbstractGraph(absGraph->GetAbstractionLevel(aChildren[0]));
415  for (unsigned int x = 0; x < gChildren.size(); x++)
416  {
417  for (unsigned int y = 0; y < gChildren.size(); y++)
418  {
419  if (x != y)
420  {
421  edge *e;
422  if ((e = aGraph->findDirectedEdge(aChildren[x]->GetNum(), aChildren[y]->GetNum())) != 0)
423  {
424  g->AddEdge(new edge(gChildren[x]->GetNum(), gChildren[y]->GetNum(), 1.0));
425  //(absGraph->GetAbstractionLevel(aChildren[0])==0)?e->GetWeight():1.5));
426  }
427  }
428  }
429  }
430 
431  // check neighbors of original node
432  neighbor_iterator ni = gNode->getNeighborIter();
433  for (int next = gNode->nodeNeighborNext(ni); next != -1; next = gNode->nodeNeighborNext(ni))
434  {
435  node *gNeighbor = g->GetNode(next);
436  if (gNeighbor->GetLabelL(kAbstractionLevel) == gNode->GetLabelL(kAbstractionLevel)-1)
437  {
438  // same level
439  for (unsigned int x = 0; x < gChildren.size(); x++)
440  {
441  edge *e;
442  if ((e = aGraph->FindEdge(aChildren[x]->GetNum(), GetRealNode(gNeighbor)->GetNum())) != 0)
443  {
444  g->AddEdge(new edge(gChildren[x]->GetNum(), gNeighbor->GetNum(), 1.0));
445  //(absGraph->GetAbstractionLevel(aChildren[0])==0)?e->GetWeight():1.5));
446  }
447  }
448  }
449  else if (gNeighbor->GetLabelL(kAbstractionLevel) < gNode->GetLabelL(kAbstractionLevel)-1)
450  { // neighbor is lower
451  for (unsigned int x = 0; x < aChildren.size(); x++)
452  {
453  if (ShouldAddEdge(GetRealNode(gNeighbor), aChildren[x]))
454  g->AddEdge(new edge(gChildren[x]->GetNum(), gNeighbor->GetNum(), 1.0));
455  }
456  }
457  else { // neighbor is higher
458  for (unsigned int x = 0; x < aChildren.size(); x++)
459  {
460  if (ShouldAddEdge(aChildren[x], GetRealNode(gNeighbor)))
461  g->AddEdge(new edge(gChildren[x]->GetNum(), gNeighbor->GetNum(), 1.0));
462  }
463  }
464  }
465 
466  // last thing we do!
467  g->RemoveNode(gNode);
468 }
469 
471 {
473 }
474 
475 bool IRAStar::ShouldAddEdge(node *aLowerNode, node *aHigherNode)
476 {
477  neighbor_iterator ni = aLowerNode->getNeighborIter();
478  for (int next = aLowerNode->nodeNeighborNext(ni); next != -1; next = aLowerNode->nodeNeighborNext(ni))
479  {
480  node *aNeighbor = absGraph->GetAbstractGraph(absGraph->GetAbstractionLevel(aLowerNode))->GetNode(next);
481  if (absGraph->IsParentOf(aHigherNode, aNeighbor))
482  return true;
483  }
484  return false;
485 }
486 
488 {
489  if ((g == 0) || (g->GetNumNodes() == 0))
490  {
491  return;
492  }
493 
494  glLineWidth(3.0);
495  glBegin(GL_LINES);
496  glNormal3f(0, 1, 0);
497  edge_iterator ei = g->getEdgeIter();
498  for (edge *e = g->edgeIterNext(ei); e; e = g->edgeIterNext(ei))
499  {
500  node *n;
501  n = g->GetNode(e->getFrom());
502 #ifdef HEURISTIC_COLOR
503  if (q.peek().n == n)
504  glColor3f( GetHCost(n)*0.6/MAX_HEURISTIC_VALUE+0.4,
505  0.0,
506  GetHCost(n)*0.6/MAX_HEURISTIC_VALUE+0.4);
507  else if (n == gStart)
508  glColor3f( 0,
509  0,
510  GetHCost(n)*0.6/MAX_HEURISTIC_VALUE+0.4);
511  else if (n == gGoal)
512  glColor3f( 0,
513  GetHCost(n)*0.6/MAX_HEURISTIC_VALUE+0.4,
514  0);
515  else if (closedList.find(n->GetNum()) != closedList.end()) // on closed list
516  glColor3f( GetHCost(n),
517  GetHCost(n),
518  GetHCost(n));
519  else if (q.IsIn(GNode(n)))
520  glColor3f( GetHCost(n)*1.0/MAX_HEURISTIC_VALUE,
523  else
524  glColor3f( GetHCost(n)*1.0/MAX_HEURISTIC_VALUE,
527 
529  glVertex3f(rv.x, rv.y, rv.z);
530 
531  n = g->GetNode(e->getTo());
532  if (q.peek().n == n)
533  glColor3f( GetHCost(n)*0.6/MAX_HEURISTIC_VALUE+0.4,
534  0.0,
535  GetHCost(n)*0.6/MAX_HEURISTIC_VALUE+0.4);
536  else if (n == gStart)
537  glColor3f( 0,
538  0,
539  GetHCost(n)*0.6/MAX_HEURISTIC_VALUE+0.4);
540  else if (n == gGoal)
541  glColor3f( 0,
542  GetHCost(n)*0.6/MAX_HEURISTIC_VALUE+0.4,
543  0);
544  else if (closedList.find(n->GetNum()) != closedList.end()) // on closed list
545  glColor3f( GetHCost(n),
546  GetHCost(n),
547  GetHCost(n));
548  else if (q.IsIn(GNode(n)))
549  glColor3f( GetHCost(n)*1.0/MAX_HEURISTIC_VALUE,
552  else
553  glColor3f( GetHCost(n)*1.0/MAX_HEURISTIC_VALUE,
556 #else
557  if (q.top().n == n)
558  glColor3f(1.0, 0.0, 1.0);
559  else if (n == gStart)
560  glColor3f(0, 0, 1);
561  else if (n == gGoal)
562  glColor3f(0, 1, 0);
563  else if (closedList.find(n->GetNum()) != closedList.end()) // on closed list
564  glColor3f(1.0, 1.0, 0);
565  else if (q.IsIn(GNode(n)))
566  glColor3f(0.5, 0.5, 0.5);
567  else
568  glColor3f(1, 1, 1);
569 
571  glVertex3f(rv.x, rv.y, rv.z);
572 
573  n = g->GetNode(e->getTo());
574  if (q.top().n == n)
575  glColor3f(1.0, 0.0, 1.0);
576  else if (n == gStart)
577  glColor3f(0, 0, 1);
578  else if (n == gGoal)
579  glColor3f(0, 1, 0);
580  else if (closedList.find(n->GetNum()) != closedList.end()) // on closed list
581  glColor3f(1.0, 1.0, 0);
582  else if (q.IsIn(GNode(n)))
583  glColor3f(0.5, 0.5, 0.5);
584  else
585  glColor3f(1, 1, 1);
586 #endif
587 
588  rv = absGraph->GetNodeLoc(GetRealNode(n));
589 
590  glVertex3f(rv.x, rv.y, rv.z);
591  }
592 
593  glEnd();
594  glLineWidth(1.0);
595 
596 }
597 
598 // Set heuristic values of all nodes on closed list according to P-g caching (h = f-g)
599 void IRAStar::SetHValues( int f )
600 {
601  NodeLookupTable::iterator ni ;
602  //typedef std::unordered_map<uint32_t, GNode> NodeLookupTable;
603 
604  for ( ni = closedList.begin(); ni != closedList.end(); ni++ )
605  {
606  node * n = ni->second.n;
607  //node* n = closedList[gNeighbor->GetNum()].n; // silly!
608 
609  // h = f - g
610  //n->SetLabelF(kHCost, val);
611  //std::cout << " f " << f
612  // << " g " << GetGCost(n)
613  // << " h " << f - GetGCost(n) << std::endl;
614  //SetCachedHCost( n, std::max( 0.0, (double) f - GetGCost(n) ) );
615  SetHCost( n, (double)f - GetGCost(n) );
616  }
617 }
618 
619 double IRAStar::GetHCost(node *n) const
620 {
621 // if (n->GetLabelL(kIteration) < currentIteration-1)
622 // return std::max(iterationLimits.back(), val);
623  //return max( n->GetLabelF(kHCost), absGraph->h(n,aGoal) );
624  //return absGraph->h(n,aGoal);
625  return n->GetLabelF(kHCost);
626  //return std::max( n->GetLabelF(kHCost), GetCachedHCost(n) );
627 }
628 
629 void IRAStar::SetHCost(node *n, double val)
630 {
631  n->SetLabelF(kHCost, val);
632 }
633 
634 //double IRAStar::GetCachedHCost(node *n)
635 //{
636 // double val = 0;
637 // val = n->GetLabelF(kCachedHCost1); // one search direction
639 // if ( gStart->GetLabelL(kAbstractionLevel)%2 == 0 ) // Always switch diretions on base level
640 // val = n->GetLabelF(kCachedHCost2);
641 // else
642 // val = n->GetLabelF(kCachedHCost1);
643 // */
644 //}
645 //
646 //void IRAStar::SetCachedHCost(node *n, double val)
647 //{
648 // n->SetLabelF(kCachedHCost1, val); // one search direction
649 //
651 // n->SetLabelF(kCachedHCost1, val);
652 // else
653 // n->SetLabelF(kCachedHCost2, val);
654 // */
655 //}
656 
657 double IRAStar::GetGCost(node *n) const
658 {
659  return n->GetLabelF(kGCost);
660 }
661 
662 void IRAStar::SetGCost(node *n, double val)
663 {
664  n->SetLabelF(kGCost, val);
665 }
666 
667 double IRAStar::GetFCost(node *n) const
668 {
669  return n->GetLabelF(kGCost)+n->GetLabelF(kHCost);
670 }
Graph::AddNode
int AddNode(node *)
Definition: Graph.cpp:136
GraphAbstraction
A generic class for basic operations on Graph abstractions.
Definition: GraphAbstraction.h:63
node::SetLabelL
void SetLabelL(unsigned int index, long val) const
Definition: Graph.cpp:702
edge::GetWeight
double GetWeight()
Definition: Graph.h:140
IRAStar::SetHCost
void SetHCost(node *, double)
Definition: IRAStar.cpp:629
IRAStar::ExpandNeighbors
void ExpandNeighbors(node *gNode)
Definition: IRAStar.cpp:230
node::SetLabelF
void SetLabelF(unsigned int index, double val) const
Definition: Graph.cpp:687
IRAStar::g
Graph * g
Definition: IRAStar.h:120
Graph::RemoveNode
node * RemoveNode(node *, unsigned int &)
Definition: Graph.cpp:356
IRAStar::GetAllSolutionNodes
void GetAllSolutionNodes(node *goal, std::vector< node * > &nodes)
Definition: IRAStar.cpp:335
IRAStar::aGoal
node * aGoal
Definition: IRAStar.h:117
Graph::FindEdge
edge * FindEdge(unsigned int from, unsigned int to)
Finds an edge between nodes with ids from and to, no matter which direction.
Definition: Graph.cpp:230
recVec
A generic vector (essentially the same as a point, but offers normalization)
Definition: GLUtil.h:78
IRAStar::gGoal
node * gGoal
Definition: IRAStar.h:118
neighbor_iterator
unsigned int neighbor_iterator
Definition: Graph.h:34
GraphAbstraction::GetAbstractGraph
Graph * GetAbstractGraph(int level)
return the abstract Graph at the given level
Definition: GraphAbstraction.h:74
recVec::z
GLdouble z
Definition: GLUtil.h:98
IRAStar::caching
IRAStarConstants::Caching caching
Definition: IRAStar.h:123
IRAStar::GetGCost
double GetGCost(node *) const
Definition: IRAStar.cpp:657
IRAStarConstants::GNode
Definition: IRAStar.h:43
IRAStar::gStart
node * gStart
Definition: IRAStar.h:118
OpenClosedList::DecreaseKey
void DecreaseKey(OBJ val)
Indicate that the key for a particular object has decreased.
Definition: OpenClosedList.h:96
IRAStar::absGraph
GraphAbstraction * absGraph
Definition: IRAStar.h:119
MAX_HEURISTIC_VALUE
#define MAX_HEURISTIC_VALUE
Definition: IRAStar.cpp:14
IRAStar::done
bool done
Definition: IRAStar.h:125
Graph::AddEdge
void AddEdge(edge *)
Definition: Graph.cpp:170
IRAStar::Inconsistent
bool Inconsistent(node *gNode)
Definition: IRAStar.cpp:192
IRAStarConstants
Definition: IRAStar.h:21
edge_iterator
std::vector< edge * >::const_iterator edge_iterator
Definition: Graph.h:30
IRAStar::GetRealNode
node * GetRealNode(node *gNode) const
Definition: IRAStar.cpp:470
SearchAlgorithm::nodesTouched
uint32_t nodesTouched
Definition: SearchAlgorithm.h:37
OpenClosedList::top
OBJ top()
Definition: OpenClosedList.h:39
IRAStar::currentIteration
int currentIteration
Definition: IRAStar.h:122
GraphAbstraction::GetNthChild
node * GetNthChild(node *which, int n)
Definition: GraphAbstraction.h:88
OpenClosedList::IsIn
bool IsIn(const OBJ val) const
Returns true if the object is in the OpenClosedList.
Definition: OpenClosedList.h:121
Graph
A generic Graph class.
Definition: Graph.h:66
Graph::GetNode
node * GetNode(unsigned long num)
Definition: Graph.cpp:152
CFOptimalRefinementConstants::kHCost
@ kHCost
Definition: CFOptimalRefinement.h:28
IRAStarConstants::OPTIMAL_PATH_CACHING
@ OPTIMAL_PATH_CACHING
Definition: IRAStar.h:39
Graph::edgeIterNext
edge * edgeIterNext(edge_iterator &) const
Definition: Graph.cpp:320
IRAStar::SetInitialValues
void SetInitialValues(node *gNewNode, node *aRealNode, node *gParent)
Definition: IRAStar.cpp:155
IRAStar::GetHCost
double GetHCost(node *) const
Definition: IRAStar.cpp:619
IRAStar::GetPath
virtual path * GetPath(GraphAbstraction *aMap, node *from, node *to, reservationProvider *rp=0)
Definition: IRAStar.cpp:34
IRAStarConstants::GNode::n
node * n
Definition: IRAStar.h:46
IRAStar::GetFCost
double GetFCost(node *) const
Definition: IRAStar.cpp:667
GraphAbstraction::GetAbstractionLevel
long GetAbstractionLevel(node *which)
Definition: GraphAbstraction.h:92
IRAStar::OpenGLDraw
void OpenGLDraw() const
Definition: IRAStar.cpp:487
Graph::getEdgeIter
edge_iterator getEdgeIter() const
Definition: Graph.cpp:315
IRAStar::FindTopLevelNode
node * FindTopLevelNode(node *one, node *two, GraphAbstraction *aMap)
Definition: IRAStar.cpp:132
OpenClosedList::Add
void Add(OBJ val)
Add object into OpenClosedList.
Definition: OpenClosedList.h:77
path::length
unsigned length(void)
returns the number of steps along the path
Definition: Path.cpp:15
fless
bool fless(double a, double b)
Definition: FPUtil.h:28
GraphAbstraction::GetNumChildren
long GetNumChildren(node *which)
Definition: GraphAbstraction.h:87
IRAStarConstants::Caching
Caching
Definitions for the constructor.
Definition: IRAStar.h:37
SearchAlgorithm::nodesExpanded
uint32_t nodesExpanded
Definition: SearchAlgorithm.h:36
IRAStar::SetHValues
void SetHValues(int f)
Definition: IRAStar.cpp:599
IRAStar::SetGCost
void SetGCost(node *, double)
Definition: IRAStar.cpp:662
GraphAbstractionConstants::kAbstractionLevel
@ kAbstractionLevel
Definition: GraphAbstraction.h:25
IRAStar::GetName
virtual const char * GetName()
Definition: IRAStar.cpp:29
OpenClosedList::pop
void pop()
Definition: OpenClosedList.h:37
IRAStarConstants::P_G_CACHING
@ P_G_CACHING
Definition: IRAStar.h:40
IRAStar::nodesRefined
int nodesRefined
Definition: IRAStar.h:121
IRAStar::InitializeSearch
bool InitializeSearch(GraphAbstraction *aMap, node *from, node *to)
Definition: IRAStar.cpp:106
fgreater
bool fgreater(double a, double b)
Definition: FPUtil.h:29
Graph::GetNumNodes
int GetNumNodes()
Definition: Graph.cpp:403
CFOptimalRefinementConstants::kGCost
@ kGCost
Definition: CFOptimalRefinement.h:27
CFOptimalRefinementConstants::kCorrespondingNode
@ kCorrespondingNode
Definition: CFOptimalRefinement.h:26
node::nodeNeighborNext
int nodeNeighborNext(neighbor_iterator &) const
Definition: Graph.cpp:807
GraphAbstraction::getNumAbstractGraphs
unsigned int getNumAbstractGraphs()
return the total number of graphs in the hierarchy
Definition: GraphAbstraction.h:76
IRAStar.h
path
std::vector< xyLoc > path
Definition: Sample.cpp:43
IRAStar::~IRAStar
virtual ~IRAStar()
Definition: IRAStar.cpp:25
IRAStar::GetSolution
path * GetSolution(node *gNode)
Definition: IRAStar.cpp:363
IRAStar::ExtractAndRefinePath
path * ExtractAndRefinePath()
Definition: IRAStar.cpp:281
node::GetLabelF
double GetLabelF(unsigned int index) const
Definition: Graph.h:215
IRAStar::RefineNode
void RefineNode(node *gNode)
Definition: IRAStar.cpp:383
node::GetNum
unsigned int GetNum() const
Definition: Graph.h:176
IRAStar::ShouldAddEdge
bool ShouldAddEdge(node *aLowerNode, node *aHigherNode)
Definition: IRAStar.cpp:475
reservationProvider
Definition: ReservationProvider.h:33
SearchAlgorithm
A generic algorithm which can be used for pathfinding.
Definition: SearchAlgorithm.h:25
IRAStar::q
IRAStarConstants::PQueue q
Definition: IRAStar.h:115
GraphAbstraction::IsParentOf
bool IsParentOf(node *parent, node *child)
return true if the first node is a parent of or is equal two the second node
Definition: GraphAbstraction.cpp:78
GraphAbstraction::GetNodeLoc
virtual recVec GetNodeLoc(node *) const
Definition: GraphAbstraction.h:120
path::next
path * next
Definition: Path.h:23
node::GetLabelL
long GetLabelL(unsigned int index) const
Definition: Graph.h:220
path
A linked list of nodes which form a continuous path.
Definition: Path.h:20
node::getNeighborIter
neighbor_iterator getNeighborIter() const
Definition: Graph.cpp:802
IRAStar::IRAStar
IRAStar(IRAStarConstants::Caching caching=IRAStarConstants::P_G_CACHING)
Definition: IRAStar.cpp:19
recVec::y
GLdouble y
Definition: GLUtil.h:98
Graph::findDirectedEdge
edge * findDirectedEdge(unsigned int from, unsigned int to)
Definition: Graph.cpp:189
fequal
bool fequal(double a, double b, double tolerance=TOLERANCE)
Definition: FPUtil.h:32
IRAStar::aStart
node * aStart
Definition: IRAStar.h:117
OpenClosedList::size
unsigned size()
Definition: OpenClosedList.h:42
GraphAbstraction::GetParent
node * GetParent(node *which)
Definition: GraphAbstraction.h:86
IRAStar::iterationLimits
std::vector< double > iterationLimits
Definition: IRAStar.h:124
recVec::x
GLdouble x
Definition: GLUtil.h:98
OpenClosedList::peek
const OBJ peek() const
Definition: OpenClosedList.h:38
OpenClosedList::reset
void reset()
Remove all objects from queue.
Definition: OpenClosedList.h:67
IRAStar::closedList
IRAStarConstants::NodeLookupTable closedList
Definition: IRAStar.h:116
IRAStar::DoOneSearchStep
path * DoOneSearchStep()
Definition: IRAStar.cpp:47
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
edge
Edge class for connections between node in a Graph.
Definition: Graph.h:129