HOG2
PRAStar.cpp
Go to the documentation of this file.
1 /*
2  * $Id: praStar.cpp
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 9/28/04.
6  * Modified by Nathan Sturtevant on 02/29/20.
7  *
8  * This file is part of HOG2. See https://github.com/nathansttt/hog2 for licensing information.
9  *
10  */
11 
12 #include "FPUtil.h"
13 #include "PRAStar.h"
14 
15 using namespace GraphAbstractionConstants;
16 const static bool verbose = false;
17 
20 {
21  partialLimit = -1;
22  fixedPlanLevel = -1;
23  sprintf(algName,"PRA*(%d)", partialLimit);
24  expandSearchRadius = true; planFromMiddle = true;
25  cache = 0;
26 }
27 
29 {
30  cache = p;
31 }
32 
34 {
35  lengths.resize(0);
36  rp = _rp;
37  // Reset the number of states expanded
38  nodesExpanded = 0;
39  nodesTouched = 0;
40 
41  if ((from == 0) || (to == 0) || (!aMap->Pathable(from, to)) || (from == to))
42  {
43  if (verbose)
44  {
45  if (!from)
46  printf("praStar: from == 0\n");
47  if (!to)
48  printf("praStar: to == 0\n");
49  if (from == to)
50  printf("praStar: from == to\n");
51  if (from && to && (!aMap->Pathable(from, to)))
52  printf("praStar: no path from %p to %p\n", (void*)from, (void*)to);
53  //cout << "praStar: no path from " << *from << " to " << *to << endl;
54  }
55  return 0;
56  }
57 
58  std::vector<node *> fromChain;
59  std::vector<node *> toChain;
60 
61  map = aMap;
62 
63  if (verbose)
64  printf("At nodes #%d and %d\n", from->GetNum(), to->GetNum());
65  if (aMap->GetAbstractGraph(0)->FindEdge(from->GetNum(), to->GetNum())) { // we are 1 step away
66  if ((cache) && (*cache))
67  {
68  delete *cache;
69  *cache = 0;
70  }
71  //printf("We're just 1 step away! (or is it 2?)\n");
72  return new path(from, new path(to));
73  }
74 
75  aMap->GetNumAbstractGraphs(from, to, fromChain, toChain);
76  // assert(aMap->GetAbstractGraph(fromChain.back()->GetLabelL(kAbstractionLevel))->
77  // FindEdge(fromChain.back()->GetNum(), toChain.back()->GetNum()));
78 
79  path *lastPath = 0;
80  if (cache && ((*cache) != 0))
81  {
82  if (verbose) printf("Checking cache\n");
83  // check to see if cache is consistent with the planning we're going
84  // to do by finding the first node in the abstraction hierarchy
85  if (fromChain.back()->GetLabelL(kAbstractionLevel) < (*cache)->n->GetLabelL(kAbstractionLevel))
86  {
87  delete (*cache);
88  *cache = 0;
89  }
90  else {
91  while ((fromChain.back() != (*cache)->n) && (fromChain.size() > 0))
92  {
93  toChain.pop_back();
94  fromChain.pop_back();
95  }
96  if (fromChain.size() == 0)
97  { printf("Cache invalid; not in first node.\n"); std::cout << *(*cache)->n; exit(10); }
98  // if we find it, we set it to be our lastPath
99  if (verbose) printf("Setting last path to cache\n");
100  lastPath = *cache;
101  toChain.pop_back();
102  fromChain.pop_back();
103  }
104 
105  }
106  if (fixedPlanLevel != -1)
107  {
108  //while (((int)fromChain.size() > 2) && ((int)toChain.size() > fixedPlanLevel + 1))
109  while (((int)fromChain.size() > 1) && ((int)toChain.size() > fixedPlanLevel + 1))
110  {
111  toChain.pop_back();
112  fromChain.pop_back();
113  }
114 
115  //std::cout << "top praStar level: " << (toChain.size() - 1) << std::endl;
116  }
117  else if ((planFromMiddle) && (lastPath == 0))
118  {
119  unsigned int previousSize = fromChain.size();
120  int minNode = (int)(2*sqrt(aMap->GetAbstractGraph(aMap->GetAbstractionLevel(fromChain[0]))->GetNumNodes()));
121  while ((fromChain.size() > 2) && ((fromChain.size() > (previousSize)/2) ||
122  (aMap->GetAbstractGraph(fromChain.size())->GetNumNodes() < minNode)))
123  {
124 // printf("At size %d, %d nodes\n", fromChain.size(), aMap->GetAbstractGraph(fromChain.size())->GetNumNodes());
125  toChain.pop_back();
126  fromChain.pop_back();
127  }
128 // printf("Previous size: %d, nodes: %d, limit: %d now: %d\n", previousSize,
129 // (aMap->GetAbstractGraph(aMap->GetAbstractionLevel(fromChain[0]))->GetNumNodes()),
130 // minNode, toChain.size());
131  }
132  else if (lastPath == 0)
133  {
134  // there should be an edge directly from the last nodes here....
135  // assert(aMap->GetAbstractGraph(fromChain.back()->GetLabelL(kAbstractionLevel))->
136  // FindEdge(fromChain.back()->GetNum(), toChain.back()->GetNum()));
137  // it's possible this will be a path from the node back to itself
138  // but if that's the case, we'll still be ok.
139  lastPath = new path(fromChain.back(), new path(toChain.back()));
140  //printf("%d <- %d (start)\n", toChain.back()->GetNum(), fromChain.back()->GetNum());
141  toChain.pop_back();
142  fromChain.pop_back();
143  }
144 
145  lengths.resize(fromChain.size());
146  do {
147  unsigned int destParent = 0xFFFFFFFF;
148  unsigned int dest;
149 
150  to = toChain.back();
151  from = fromChain.back();
152  dest = to->GetNum();
153  if (verbose)
154  printf("Expanded %d nodes before doing level %d\n", nodesExpanded, (int)from->GetLabelL(kAbstractionLevel));
155  toChain.pop_back();
156  fromChain.pop_back();
157 
158  if (verbose)
159  printf("Building path from %d to %d (%ld/%ld)\n",
160  from->GetNum(), to->GetNum(), from->GetLabelL(kParent), to->GetLabelL(kParent));
161 
162  std::vector<unsigned int> eligibleNodeParents;
163 
164  if (lastPath)
165  {
166  // cut path down to size of partial path limit
167  if (partialLimit > 0)
168  {
169  path *trav = lastPath;
170  //for (int x = 0; x < partialLimit*(from->GetLabelL(kAbstractionLevel)+1); x++)
171  for (int x = 0; x < partialLimit; x++)
172  if (trav->next)
173  trav = trav->next;
174  if ((trav->next != 0) || (trav->n->GetNum() != (unsigned)to->GetLabelL(kParent)))
175  {
176  destParent = trav->n->GetNum();
177  if (trav->next)
178  dest = trav->next->n->GetLabelL(kFirstData);
179  else
180  dest = trav->n->GetLabelL(kFirstData);
181  delete trav->next;
182  trav->next = 0;
183  if (verbose) printf("Setting target parent to %d\n", destParent);
184  }
185  // set actual target to any node in destParent
186  // if (trav->next)
187  // to = aMap->GetAbstractGraph(trav->next->n->GetLabelL(kAbstractionLevel)
188  // -1)->GetNode(trav->n->GetLabelL(kFirstData));
189  // later try for best h value to actual target
190  //for (unsigned int x = 1; x < trav->n->GetLabelL(kNumAbstractedNodes); x++)
191 
192  }
193 
194  // find eligible nodes for lower level expansions
195  for (path *trav = lastPath; trav; trav = trav->next)
196  {
197  if (expandSearchRadius)
198  {
199  edge_iterator ei = trav->n->getEdgeIter();
200  for (edge *e = trav->n->edgeIterNext(ei); e; e = trav->n->edgeIterNext(ei))
201  {
202  if (e->getFrom() == trav->n->GetNum())
203  eligibleNodeParents.push_back(e->getTo());
204  else
205  eligibleNodeParents.push_back(e->getFrom());
206  }
207  }
208  eligibleNodeParents.push_back(trav->n->GetNum());
209  }
210  }
211  if ((lastPath == 0) && (cache))
212  {
213  lastPath = getAbstractPath(map->GetAbstractGraph((unsigned int)from->
214  GetLabelL(kAbstractionLevel)),
215  from->GetNum(), destParent, eligibleNodeParents,
216  kTemporaryLabel, dest);
217  *cache = lastPath;
218  lengths[fromChain.size()] = lastPath->length();
219  }
220  else {
221  if ((cache && ((*cache) != lastPath)) || (!cache))
222  delete lastPath;
223  lastPath = getAbstractPath(map->GetAbstractGraph((unsigned int)from->
224  GetLabelL(kAbstractionLevel)),
225  from->GetNum(), destParent, eligibleNodeParents,
226  kTemporaryLabel, dest);
227  lengths[fromChain.size()] = lastPath->length();
228  }
229  } while (fromChain.size() > 0);
230  cache = 0;
231  return lastPath;
232 }
233 
234 path *praStar::getAbstractPath(Graph *g, unsigned int source, unsigned int destParent,
235  std::vector<unsigned int> &eligibleNodeParents, int LABEL,
236  unsigned int dest)
237 {
238  path *p = 0;
239  edge *e;
240  // extract actual path out
241  unsigned int current = astar(g, source, destParent, eligibleNodeParents, LABEL, dest);
242  if (current == source) return 0;
243 
244  while ((e = g->GetNode(current)->getMarkedEdge()))
245  {
246  if (verbose) printf("%d <- ", current);
247  p = new path(g->GetNode(current), p);
248 
249  e->setMarked(true);
250  //dest = current;
251 
252  if (e->getFrom() == current)
253  current = e->getTo();
254  else
255  current = e->getFrom();
256  }
257  p = new path(g->GetNode(current), p);
258  if (verbose) printf("%d\n", current);
259  return p;
260 }
261 
262 // for each primitive action, apply it as long as we can, checking to see if
263 // we ever hit our path again. If so, we can use the repeated primitive operator
264 // as a replacement for our path
265 
266 // this should move into algorithm.cpp
268 {
269  // 1. add path to vector so we can detect it
270  // 2. go each direction and see if we hit the path
271  // 3. replace segment of previous path
272  return p;
273 }
274 
275 unsigned int praStar::astar(Graph *g, unsigned int source, unsigned int destParent,
276  std::vector<unsigned int> &eligibleNodeParents, int LABEL,
277  unsigned int dest)
278 {
279  node *n=0;
280  Heap *nodeHeap = new Heap(eligibleNodeParents.size());
281  std::vector<node *> expandedNodes(100);
282  edge_iterator ei;
283  node *currBest = 0;
284  bool expandedAnything = false;
285  unsigned int openNode = source;
286 
287  int absLayer = g->GetNode(source)->GetLabelL(kAbstractionLevel);
288 
289  // mark location of eligible nodes
290  for (unsigned int x = 0; x < eligibleNodeParents.size(); x++)
291  map->GetAbstractGraph(absLayer+1)->GetNode(eligibleNodeParents[x])->key = x;
292 
293  // label start node cost 0
294  n = g->GetNode(source);
295  n->SetLabelF(LABEL, map->h(n, g->GetNode(dest)));
296  n->markEdge(0);
297  if (verbose) printf("Starting on %d with cost %1.4f\n", source, n->GetLabelF(LABEL));
298  while (1)
299  {
300  nodesExpanded++;
301  expandedNodes.push_back(n);
302  n->key = expandedNodes.size()-1;
303 
304  if (verbose)
305  printf("really working on %d with cost %1.4f\n", n->GetNum(), n->GetLabelF(LABEL));
306 
307  ei = n->getEdgeIter();
308 
309  for (edge *e = n->edgeIterNext(ei); e; e = n->edgeIterNext(ei))
310  {
311  nodesTouched++;
312  unsigned int which;
313  if ((which = e->getFrom()) == openNode) which = e->getTo();
314  if (verbose) printf("considering neighbor %d\n", which);
315  node *currNode = g->GetNode(which);
316 
317  if (nodeHeap->IsIn(currNode))
318  {
319  //nodesExpanded++;
320  relaxEdge(nodeHeap, g, e, openNode, which, dest, LABEL);
321  }
322 #ifdef LOCAL_PATH
323  else if (rp && (absLayer==0) && (currNode->GetNum() != dest) &&
324  rp->nodeOccupied(currNode))
325  {
326  //printf("Can't path to %d, %d\n", (unsigned int)nextChild->GetLabelL(kFirstData), (unsigned int)nextChild->GetLabelL(kFirstData+1));
327  expandedNodes.push_back(currNode);
328  currNode->key = expandedNodes.size()-1;
329  // ignore this tile if occupied.
330  }
331 #else
332  //else if (currNode->GetLabelL(kNodeBlocked) > 0)
333  else if (((n->GetNum() != source) && (e->GetLabelL(kEdgeCapacity) <= 0)) ||
334  ((n->GetNum() == source) && (e->GetLabelL(kEdgeCapacity) < 0)))
335  {
336  expandedNodes.push_back(currNode);
337  currNode->key = expandedNodes.size()-1;
338  }
339 #endif
340  // this node is unexpanded if (1) it isn't on the expanded list
341  else if ((currNode->key >= expandedNodes.size()) ||
342  (expandedNodes[currNode->key] != currNode))
343  {
344 
345  unsigned int whichParent = (unsigned int)currNode->GetLabelL(kParent);
346  unsigned int parentKey = map->GetAbstractGraph(absLayer+1)->GetNode(whichParent)->key;
347 
348  // this node is unexpanded if (2) it's parent is in the eligible parent list
349  // (3) or having no eligible parents means we can search anywhere!
350  if ((eligibleNodeParents.size() == 0) ||
351  ((parentKey < eligibleNodeParents.size()) &&
352  (eligibleNodeParents[parentKey] == whichParent)))
353  {
354  currNode->SetLabelF(LABEL, MAXINT);
355  currNode->SetKeyLabel(LABEL);
356  currNode->markEdge(0);
357  nodeHeap->Add(currNode);
358  if (verbose)
359  printf("Adding neighbor %d\n", which);
360  //nodesExpanded++;
361  relaxEdge(nodeHeap, g, e, openNode, which, dest, LABEL);
362  }
363  else { if (verbose) printf("%d not eligible\n", currNode->GetNum()); }
364  }
365  else { if (verbose) printf("%d already expanded\n", currNode->GetNum()); }
366  }
367 
368  n = (node*)nodeHeap->Remove();
369  if (n == 0)
370  {
371  if (verbose) printf("Error: We expanded every possible node!\n");
372  break;
373  }
374  expandedAnything = true;
375 
376  openNode = n->GetNum();
377  if (openNode == dest) { /*printf("Found goal %d\n", dest);*/ break; }
378 
379  if (verbose) printf("working on %d with cost %1.4f\n", openNode, n->GetLabelF(LABEL));
380 
381  if (currBest)
382  {
383  if (currBest->GetLabelL(kParent) == n->GetLabelL(kParent))
384  {
385  // these lines cause us to take the node with the best h() value
386  // instead of the first explored node by A* in the abstraction
387  if (currBest->GetLabelF(LABEL) > n->GetLabelF(LABEL))
388  currBest = n;
389  }
390  else if (n->GetLabelL(kParent) == (long)destParent)
391  {
392  currBest = n;
393  //printf("Exited 'cause we're in our parent %ld/%d (2)\n", n->GetLabelL(kParent), destParent);
394  break;
395  }
396  } else {
397  currBest = n;
398  if (n->GetLabelL(kParent) == (long)destParent)
399  {
400  //printf("Exited 'cause we're in our parent %ld/%d (1)\n", n->GetLabelL(kParent), destParent);
401  break;
402  }
403  }
404  }
405 
406  delete nodeHeap;
407 
408  if (!expandedAnything) return source;
409 
410  if ((currBest) && (openNode != dest))
411  {
412  dest = currBest->GetNum();
413  if ((partialLimit > 0) && (currBest->GetLabelL(kParent) != (long)destParent))
414  {
415  if (verbose) printf("Error: We somehow didn't end up in our parent...\n");
416  }
417  }
418  return dest;
419 }
420 
421 void praStar::relaxEdge(Heap *nodeHeap, Graph *g, edge *e, int source, int nextNode, int dest,
422  int LABEL)
423 {
424  double weight;
425  node *from = g->GetNode(source);
426  node *to = g->GetNode(nextNode);
427  node *d = g->GetNode(dest);
428  weight = from->GetLabelF(LABEL)-map->h(from, d)+map->h(to, d)+e->GetWeight();
429  if (fless(weight, to->GetLabelF(LABEL)))
430  {
431  if (verbose)
432  printf("Updating %d to %1.4f from %1.4f\n", nextNode, weight, to->GetLabelF(LABEL));
433  //weight -= 0.001*(weight-map->h(to, d)); // always lower g-cost slightly so that we tie break in favor of higher g cost
434  to->SetLabelF(LABEL, weight);
435  nodeHeap->DecreaseKey(to);
436  // this is the edge used to get to this node in the min. path tree
437  to->markEdge(e);
438  }
439 }
440 
441 
442 //void praStar::addAbstractedNodesToHeap(Heap *nodeHeap, Graph *g, node *p, unsigned int source,
443 // int LABEL)
444 //{
445 // for (int cnt = 0; cnt < p->GetLabelL(kNumAbstractedNodes); cnt++) {
446 // node *childNode = g->GetNode((unsigned int)p->GetLabelL(kFirstData+cnt));
447 // if (nodeHeap->IsIn(childNode)) continue;
448 // if (verbose) printf("%d ", childNode->GetNum());
449 // childNode->setKeyLabel(LABEL);
450 // childNode->SetLabelF(LABEL, MAXINT);
451 // childNode->markEdge(0);
452 // if (childNode->GetNum() != source) nodeHeap->Add(childNode);
453 // }
454 // if (verbose) printf("\n");
455 //}
456 //
457 //void praStar::addAbstractedNodesAndNeighborsToHeap(Heap *nodeHeap, Graph *g, node *p,
458 // unsigned int source, int LABEL)
459 //{
460 // for (int cnt = 0; cnt < p->GetLabelL(kNumAbstractedNodes); cnt++) {
461 // unsigned int childNum;
462 // node *childNode = g->GetNode(childNum = (unsigned int)p->GetLabelL(kFirstData+cnt));
463 // childNode->setKeyLabel(LABEL);
464 // childNode->SetLabelF(LABEL, MAXINT);
465 // childNode->markEdge(0);
466 // if ((childNode->GetNum() != source) && (!nodeHeap->IsIn(childNode))) {
467 // if (verbose) printf("%d ", childNode->GetNum());
468 // nodeHeap->Add(childNode);
469 // }
470 //
471 // edge_iterator ei = childNode->getEdgeIter();
472 // for (edge *e = childNode->edgeIterNext(ei); e; e = childNode->edgeIterNext(ei)) {
473 // node *neighbor;
474 // unsigned int which;
475 // if ((which = e->getFrom()) == childNum) which = e->getTo();
476 // neighbor = g->GetNode(which);
477 // if (!nodeHeap->IsIn(neighbor)) {
478 // neighbor->setKeyLabel(LABEL);
479 // neighbor->SetLabelF(LABEL, MAXINT);
480 // neighbor->markEdge(0);
481 // if (neighbor->GetNum() != source) {
482 // if (verbose) printf("%d ", neighbor->GetNum());
483 // nodeHeap->Add(neighbor);
484 // }
485 // }
486 // }
487 // }
488 // if (verbose) printf("\n");
489 //}
490 
491 
492 
493 //void praStar::doLibraryRandomPath(bool repeat, bool optimal)
494 //{
495 // static double lastLength, lastTime;
496 // static node *r1, *r2;
497 // if (verbose)
498 // cout << "Clearing marked nodes" << endl;
499 // ClearMarkedNodes();
500 //
501 // if (!repeat)
502 // {
503 // do {
504 // do {
505 // r1 = abstractions[0]->GetRandomNode();
506 // } while (m->GetTerrainType((long)r1->GetLabelL(kFirstData), (long)r1->GetLabelL(kFirstData+1)) == kOutOfBounds);
507 // do {
508 // r2 = abstractions[0]->GetRandomNode();
509 // } while (m->GetTerrainType((long)r2->GetLabelL(kFirstData), (long)r2->GetLabelL(kFirstData+1)) == kOutOfBounds);
510 // } while (!Pathable(r1, r2));
511 // }
512 //
513 // if (verbose)
514 // {
515 // cout << "Attempting path between nodes:" << endl;
516 // cout << (*r1) << endl << (*r2) << endl;
517 // }
518 //
519 // // while (r1 != r2)
520 // // {
521 // // r1 = getPathStep(r1, r2);
522 // // if (verbose)
523 // // cout << "Stepping to " << (*r1) << endl;
524 // // }
525 //
526 // // ignoring return value! Leaking memory!
527 //
528 //#ifdef OS_MAC
529 // AbsoluteTime startTime = UpTime();
530 //#else
531 // clock_t startTime, endTime;
532 // long double duration;
533 // startTime = clock();
534 //
535 //#endif
536 //
537 //
538 // path *p;
539 //
540 // if (optimal)
541 // p = getLibraryPath(r1, r2);
542 // else
543 // p = getApproximatePath(r1, r2);
544 // // getPathStep(r1, r2);
545 //
546 //
547 //#ifdef OS_MAC
548 //
549 // AbsoluteTime stopTime = UpTime();
550 // Nanoseconds diff = AbsoluteDeltaToNanoseconds(stopTime, startTime);
551 // uint64_t nanosecs = UnsignedWideToUInt64(diff);
552 // cout << nanosecs << " ns elapsed (" << (double)nanosecs/1000000.0 << " ms)" << endl;
553 //#else
554 // endTime = clock();
555 // duration=(long double)(endTime-startTime)/CLOCKS_PER_SEC;
556 // cout << duration << " seconds elapsed" << endl;
557 //
558 //#endif
559 //
560 // int cnt = 0;
561 // double length = 0;
562 // for (path *q = p; q; q = q->next)
563 // {
564 // if (q && q->next)
565 // {
566 // double t1, t2;
567 // t1 = q->n->GetLabelL(kFirstData)-q->next->n->GetLabelL(kFirstData);
568 // t2 = q->n->GetLabelL(kFirstData+1)-q->next->n->GetLabelL(kFirstData+1);
569 // length += sqrt(t1*t1+t2*t2);
570 // }
571 // cnt++;
572 // }
573 //
574 //#ifdef OS_MAC
575 // cout << "Path length " << cnt << " steps, " << length << ", " << (double)nanosecs/(1000*cnt) << " µs per step, ";
576 // cout << (double)nanosecs/(1000*length) << " µs per distance" << endl;
577 //
578 //
579 // if (!repeat)
580 // {
581 // lastLength = length;
582 // lastTime = (double)nanosecs/1000000.0;
583 // }
584 // else {
585 // cout << "Comparison: " << lastLength/length << "x longer; but " << ((double)nanosecs/1000000.0)/lastTime << "x faster." << endl;
586 // }
587 //#else
588 // cout << "Path length " << cnt << " steps, " << length << endl;
589 //
590 // if (!repeat)
591 // {
592 // lastLength = length;
593 // }
594 // else {
595 // cout << "Comparison: " << lastLength/length << "x longer" << endl;
596 // }
597 //#endif
598 //
599 // clearDisplayLists();
600 //}
601 //
602 //
603 //using namespace PathFind;
604 //
605 //typedef AStar<MarkerFastClear, AStarOpenBuckets<MarkerFastClear, AStarCompareF>, AStarClosedLookup<MarkerFastClear> > ASTAR;
606 //
607 //path* praStar::getLibraryPath(node* from, node* to)
608 //{
609 // printf("Getting the library path\n");
610 // static ASTAR *search = new ASTAR();
611 //
612 // //auto_ptr<Search> search(theAStar);
613 // //search.reset(theAStar);
614 //
615 // search->setNodesLimit(100000000L);
616 //
617 // int start, target;
618 // //path *p = 0;
619 // MapEnv me(this, m, abstractions[0]);
620 // // MapEnv me(m);
621 //
622 // //me.getStartTarget(&start, &target);
623 // start = from->GetNum();
624 // target = to->GetNum();
625 //
626 // // SearchUtils searchUtils;
627 // //
628 // // if (searchUtils.checkPathExists(me, start, target))
629 // // printf("Search Utils -> Path exists\n");
630 // // else
631 // // printf("Search Utils -> Path does not exist\n");
632 //
633 // search->findPath(me, start, target);
634 //
635 // const vector<int>& resultPath = search->GetPath();
636 //
637 // while(resultPath.size() < 1) {
638 // printf("Bad library path!\n");
639 // //return;
640 // me.getStartTarget(&start, &target);
641 //
642 // search->findPath(me, start, target);
643 //
644 // resultPath = search->GetPath();
645 // }
646 //
647 // //Display the path
648 // path *p = 0;
649 // edge *e;
650 //
651 // for (vector<int>::const_iterator i = resultPath.begin(); i != resultPath.end()-1; ++i) {
652 // e = abstractions[0]->FindEdge(*(i+1), *i);
653 //
654 // if (!e) {
655 // e = abstractions[0]->FindEdge(*i, *(i+1));
656 //
657 // if (!e)
658 // printf("Error, invalid edge: From (*i) = %d, To: (*(i+1)) = %d\n", *i, *(i+1));
659 // else {
660 // e->setMarked(true);
661 // }
662 // }
663 // else {
664 // e->setMarked(true);
665 // }
666 // p = new path(abstractions[0]->GetNode(*i), p);
667 // }
668 // return p;
669 //}
670 //
GraphAbstraction
A generic class for basic operations on Graph abstractions.
Definition: GraphAbstraction.h:63
GraphAbstractionConstants
Definition: GraphAbstraction.h:22
edge::GetWeight
double GetWeight()
Definition: Graph.h:140
node::getMarkedEdge
edge * getMarkedEdge()
Definition: Graph.h:228
node::SetLabelF
void SetLabelF(unsigned int index, double val) const
Definition: Graph.cpp:687
edge::getFrom
unsigned int getFrom() const
Definition: Graph.h:146
edge::getTo
unsigned int getTo() const
Definition: Graph.h:147
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
GraphAbstraction::GetAbstractGraph
Graph * GetAbstractGraph(int level)
return the abstract Graph at the given level
Definition: GraphAbstraction.h:74
graph_object::key
unsigned int key
Definition: Graph.h:54
verbose
const static bool verbose
Definition: PRAStar.cpp:16
praStar::praStar
praStar()
Definition: PRAStar.cpp:18
d
mcData d[]
Definition: MotionCaptureMovement.cpp:21
praStar::algName
char algName[30]
Definition: PRAStar.h:57
edge::setMarked
void setMarked(bool marked)
Definition: Graph.h:149
path::n
node * n
Definition: Path.h:22
edge_iterator
std::vector< edge * >::const_iterator edge_iterator
Definition: Graph.h:30
FPUtil.h
SearchAlgorithm::nodesTouched
uint32_t nodesTouched
Definition: SearchAlgorithm.h:37
GraphAbstractionConstants::kEdgeCapacity
@ kEdgeCapacity
Definition: GraphAbstraction.h:53
Heap::DecreaseKey
void DecreaseKey(graph_object *val)
Indicate that the key for a particular object has decreased.
Definition: Heap.cpp:47
Graph
A generic Graph class.
Definition: Graph.h:66
praStar::setCache
void setCache(path **p)
Definition: PRAStar.cpp:28
Graph::GetNode
node * GetNode(unsigned long num)
Definition: Graph.cpp:152
node::markEdge
void markEdge(edge *e)
Definition: Graph.h:227
praStar::planFromMiddle
bool planFromMiddle
Definition: PRAStar.h:60
GraphAbstraction::GetAbstractionLevel
long GetAbstractionLevel(node *which)
Definition: GraphAbstraction.h:92
node::getEdgeIter
edge_iterator getEdgeIter() const
Definition: Graph.cpp:749
GraphAbstraction::h
virtual double h(node *a, node *b)=0
heuristic cost between any two nodes
praStar::astar
unsigned int astar(Graph *g, unsigned int source, unsigned int destParent, std::vector< unsigned int > &eligibleNodeParents, int LABEL, unsigned int dest)
Definition: PRAStar.cpp:275
praStar::cache
path ** cache
Definition: PRAStar.h:54
node::SetKeyLabel
void SetKeyLabel(int which)
Definition: Graph.h:208
praStar::GetPath
virtual path * GetPath(GraphAbstraction *aMap, node *from, node *to, reservationProvider *rp=0)
Definition: PRAStar.cpp:33
GraphAbstraction::Pathable
virtual bool Pathable(node *from, node *to)=0
is there a legal path between these 2 nodes?
praStar::getAbstractPath
path * getAbstractPath(Graph *g, unsigned int source, unsigned int destParent, std::vector< unsigned int > &eligibleNodeParents, int LABEL, unsigned int dest)
Definition: PRAStar.cpp:234
GraphAbstractionConstants::kFirstData
@ kFirstData
Definition: GraphAbstraction.h:34
path::length
unsigned length(void)
returns the number of steps along the path
Definition: Path.cpp:15
praStar::rp
reservationProvider * rp
Definition: PRAStar.h:62
fless
bool fless(double a, double b)
Definition: FPUtil.h:28
praStar::fixedPlanLevel
int fixedPlanLevel
Definition: PRAStar.h:56
praStar::lengths
std::vector< int > lengths
Definition: PRAStar.h:63
SearchAlgorithm::nodesExpanded
uint32_t nodesExpanded
Definition: SearchAlgorithm.h:36
GraphAbstractionConstants::kAbstractionLevel
@ kAbstractionLevel
Definition: GraphAbstraction.h:25
praStar::relaxEdge
void relaxEdge(Heap *nodeHeap, Graph *g, edge *e, int source, int nextNode, int dest, int LABEL)
Definition: PRAStar.cpp:421
praStar::smoothPath
path * smoothPath(path *p)
Definition: PRAStar.cpp:267
Heap::Remove
graph_object * Remove()
Remove the item with the lowest key from the Heap & re-heapify.
Definition: Heap.cpp:66
Graph::GetNumNodes
int GetNumNodes()
Definition: Graph.cpp:403
Heap::Add
void Add(graph_object *val)
Add object into Heap.
Definition: Heap.cpp:36
path
std::vector< xyLoc > path
Definition: Sample.cpp:43
GraphAbstraction::GetNumAbstractGraphs
void GetNumAbstractGraphs(node *from, node *to, std::vector< node * > &fromChain, std::vector< node * > &toChain)
given 2 nodes, find as much of their hierarchy that exists in the Graph
Definition: GraphAbstraction.cpp:39
node::GetLabelF
double GetLabelF(unsigned int index) const
Definition: Graph.h:215
PRAStar.h
Heap
A simple & efficient Heap class which uses Graph objects.
Definition: Heap.h:27
node::GetNum
unsigned int GetNum() const
Definition: Graph.h:176
MAXINT
#define MAXINT
Definition: Graph.h:24
GraphAbstractionConstants::kTemporaryLabel
@ kTemporaryLabel
Definition: GraphAbstraction.h:29
reservationProvider
Definition: ReservationProvider.h:33
SearchAlgorithm
A generic algorithm which can be used for pathfinding.
Definition: SearchAlgorithm.h:25
GraphAbstractionConstants::kParent
@ kParent
Definition: GraphAbstraction.h:27
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
reservationProvider::nodeOccupied
virtual bool nodeOccupied(node *)=0
praStar::map
GraphAbstraction * map
Definition: PRAStar.h:58
node::edgeIterNext
edge * edgeIterNext(edge_iterator &) const
Definition: Graph.cpp:754
praStar::partialLimit
int partialLimit
Definition: PRAStar.h:55
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
Heap::IsIn
bool IsIn(graph_object *val)
Returns true if the object is in the Heap.
Definition: Heap.cpp:55
praStar::expandSearchRadius
bool expandSearchRadius
Definition: PRAStar.h:59
edge
Edge class for connections between node in a Graph.
Definition: Graph.h:129