41 if ((from == 0) || (to == 0) || (!aMap->
Pathable(from, to)) || (from == to))
46 printf(
"praStar: from == 0\n");
48 printf(
"praStar: to == 0\n");
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);
58 std::vector<node *> fromChain;
59 std::vector<node *> toChain;
64 printf(
"At nodes #%d and %d\n", from->
GetNum(), to->
GetNum());
82 if (
verbose) printf(
"Checking cache\n");
91 while ((fromChain.back() != (*cache)->n) && (fromChain.size() > 0))
96 if (fromChain.size() == 0)
97 { printf(
"Cache invalid; not in first node.\n"); std::cout << *(*cache)->n; exit(10); }
99 if (
verbose) printf(
"Setting last path to cache\n");
102 fromChain.pop_back();
109 while (((
int)fromChain.size() > 1) && ((
int)toChain.size() >
fixedPlanLevel + 1))
112 fromChain.pop_back();
119 unsigned int previousSize = fromChain.size();
121 while ((fromChain.size() > 2) && ((fromChain.size() > (previousSize)/2) ||
126 fromChain.pop_back();
132 else if (lastPath == 0)
139 lastPath =
new path(fromChain.back(),
new path(toChain.back()));
142 fromChain.pop_back();
145 lengths.resize(fromChain.size());
147 unsigned int destParent = 0xFFFFFFFF;
151 from = fromChain.back();
156 fromChain.pop_back();
159 printf(
"Building path from %d to %d (%ld/%ld)\n",
162 std::vector<unsigned int> eligibleNodeParents;
169 path *trav = lastPath;
176 destParent = trav->
n->
GetNum();
183 if (
verbose) printf(
"Setting target parent to %d\n", destParent);
195 for (
path *trav = lastPath; trav; trav = trav->
next)
200 for (
edge *e = trav->n->edgeIterNext(ei); e; e = trav->n->edgeIterNext(ei))
202 if (e->getFrom() == trav->n->GetNum())
203 eligibleNodeParents.push_back(e->getTo());
205 eligibleNodeParents.push_back(e->getFrom());
208 eligibleNodeParents.push_back(trav->n->GetNum());
211 if ((lastPath == 0) && (
cache))
215 from->
GetNum(), destParent, eligibleNodeParents,
225 from->
GetNum(), destParent, eligibleNodeParents,
229 }
while (fromChain.size() > 0);
235 std::vector<unsigned int> &eligibleNodeParents,
int LABEL,
241 unsigned int current =
astar(g, source, destParent, eligibleNodeParents, LABEL, dest);
242 if (current == source)
return 0;
246 if (
verbose) printf(
"%d <- ", current);
253 current = e->
getTo();
258 if (
verbose) printf(
"%d\n", current);
276 std::vector<unsigned int> &eligibleNodeParents,
int LABEL,
280 Heap *nodeHeap =
new Heap(eligibleNodeParents.size());
281 std::vector<node *> expandedNodes(100);
284 bool expandedAnything =
false;
285 unsigned int openNode = source;
290 for (
unsigned int x = 0; x < eligibleNodeParents.size(); x++)
297 if (
verbose) printf(
"Starting on %d with cost %1.4f\n", source, n->
GetLabelF(LABEL));
301 expandedNodes.push_back(n);
302 n->
key = expandedNodes.size()-1;
305 printf(
"really working on %d with cost %1.4f\n", n->
GetNum(), n->
GetLabelF(LABEL));
313 if ((which = e->getFrom()) == openNode) which = e->getTo();
314 if (
verbose) printf(
"considering neighbor %d\n", which);
317 if (nodeHeap->
IsIn(currNode))
320 relaxEdge(nodeHeap, g, e, openNode, which, dest, LABEL);
323 else if (
rp && (absLayer==0) && (currNode->
GetNum() != dest) &&
327 expandedNodes.push_back(currNode);
328 currNode->
key = expandedNodes.size()-1;
336 expandedNodes.push_back(currNode);
337 currNode->
key = expandedNodes.size()-1;
341 else if ((currNode->
key >= expandedNodes.size()) ||
342 (expandedNodes[currNode->
key] != currNode))
350 if ((eligibleNodeParents.size() == 0) ||
351 ((parentKey < eligibleNodeParents.size()) &&
352 (eligibleNodeParents[parentKey] == whichParent)))
357 nodeHeap->
Add(currNode);
359 printf(
"Adding neighbor %d\n", which);
361 relaxEdge(nodeHeap, g, e, openNode, which, dest, LABEL);
363 else {
if (
verbose) printf(
"%d not eligible\n", currNode->
GetNum()); }
365 else {
if (
verbose) printf(
"%d already expanded\n", currNode->
GetNum()); }
371 if (
verbose) printf(
"Error: We expanded every possible node!\n");
374 expandedAnything =
true;
377 if (openNode == dest) {
break; }
379 if (
verbose) printf(
"working on %d with cost %1.4f\n", openNode, n->
GetLabelF(LABEL));
408 if (!expandedAnything)
return source;
410 if ((currBest) && (openNode != dest))
412 dest = currBest->
GetNum();
415 if (
verbose) printf(
"Error: We somehow didn't end up in our parent...\n");
432 printf(
"Updating %d to %1.4f from %1.4f\n", nextNode, weight, to->
GetLabelF(LABEL));