26 if (!InitializeSearch(_env,_g,from,to,thePath))
33 while(!DoSingleSearchStep(thePath))
50 nodesTouched = nodesExpanded = nodesReopened = 0;
75 SearchNode first(env->HCost(start, goal), 0, start, start);
85 static int reopenCount = 0;
99 if ((delayQueue.size() > 0) && (openQueue.size() > 0) &&
100 (env->GoalTest(temp = openQueue.top().currNode, goal)) &&
101 (
fless(delayQueue.top().gCost, openQueue.top().fCost)))
104 topNode = delayQueue.Remove();
110 else if ((reopenCount < fDelay(nodesExpanded-nodesReopened)) && (delayQueue.size() > 0) && (openQueue.size() > 0))
114 if (
fless(delayQueue.top().gCost, openQueue.top().fCost) )
116 topNode = delayQueue.Remove();
121 topNode = openQueue.Remove();
126 else if ((reopenCount < fDelay(nodesExpanded-nodesReopened)) && (delayQueue.size() > 0))
129 topNode = delayQueue.Remove();
139 else if ((openQueue.size() > 0))
142 topNode = openQueue.Remove();
149 return DoSingleStep(topNode, thePath);
164 std::vector<graphState> &thePath)
175 printf(
"Expanding node %ld , gcost=%lf, h=%lf, f=%lf.\n",
183 if (env->GoalTest(topNode.
currNode, goal))
186 closedList[topNode.
currNode] = topNode;
187 ExtractPathToStart(topNode.
currNode, thePath);
193 env->GetSuccessors(topNode.
currNode, neighbors);
202 ReversePropX1(topNode);
220 double minCost = DBL_MAX;
222 for (x = 0,ichild=1; x < neighbors.size(); x++,ichild++)
228 if (bpmxLevel >= 1) {
229 cost = HandleNeighborX(neighbors[x], topNode);
244 if (
fless(cost, minCost))
248 HandleNeighbor(neighbors[x], topNode);
263 closedList[topNode.
currNode] = topNode;
266 if (fifo.size() > 0) {
267 Broadcast(1,fifo.size());
279 for (
unsigned int x=0;x<neighbors.size();x++)
292 NodeLookupTable::iterator iter = closedList.find(
neighbor);
293 if (iter != closedList.end()) {
294 neighborNode = iter->second;
298 if (bpmxLevel > 1 && oh < maxh) {
314 nodesTouched += neighbors.size();
323 NodeLookupTable::iterator iter;
327 for (
int i=0;i<levelcount;i++) {
331 iter = closedList.find(front);
332 if (iter == closedList.end()) {
333 frontNode = delayQueue.find(
SearchNode(front));
338 frontNode = iter->second;
339 double frontH = frontNode.
fCost - frontNode.
gCost;
342 env->GetSuccessors(front, myneighbors);
345 for (
unsigned int x = 0; x < myneighbors.size(); x++)
349 if (iter != closedList.end()) {
350 double edgeWeight = env->GCost(front,
neighbor);
353 double neighborH = neighborNode.
fCost - neighborNode.
gCost;
355 if (
fgreater(neighborH - edgeWeight, frontH)) {
356 frontH = neighborH - edgeWeight;
364 double edgeWeight = env->GCost(front,
neighbor);
366 double neighborH = neighborNode.
fCost - neighborNode.
gCost;
368 if (
fgreater(neighborH - edgeWeight, frontH)) {
369 frontH = neighborH - edgeWeight;
376 double edgeWeight = env->GCost(front,
neighbor);
378 double neighborH = neighborNode.
fCost - neighborNode.
gCost;
380 if (
fgreater(neighborH - edgeWeight, frontH)) {
381 frontH = neighborH - edgeWeight;
390 closedList[front] = frontNode;
393 for (
unsigned int x = 0; x < myneighbors.size(); x++)
396 NodeLookupTable::iterator theIter = closedList.find(
neighbor);
397 if (theIter != closedList.end())
399 double edgeWeight = env->GCost(front,
neighbor);
402 double neighborH = neighborNode.
fCost - neighborNode.
gCost;
404 if (
fgreater(frontH - edgeWeight, neighborH)) {
405 neighborNode.
fCost = neighborNode.
gCost + frontH - edgeWeight;
406 closedList[
neighbor] = neighborNode;
413 double edgeWeight = env->GCost(front,
neighbor);
415 double neighborH = neighborNode.
fCost - neighborNode.
gCost;
417 if (
fgreater(frontH - edgeWeight, neighborH)) {
418 neighborNode.
fCost = neighborNode.
gCost + frontH - edgeWeight;
419 openQueue.IncreaseKey(neighborNode);
425 double edgeWeight = env->GCost(front,
neighbor);
427 double neighborH = neighborNode.
fCost - neighborNode.
gCost;
429 if (
fgreater(frontH - edgeWeight, neighborH)) {
430 neighborNode.
fCost = neighborNode.
gCost + frontH - edgeWeight;
431 delayQueue.IncreaseKey(neighborNode);
445 nodesTouched += 2*levelcount;
448 if (level < bpmxLevel && fifo.size() > 0)
449 Broadcast(level, fifo.size());
456 return UpdateOpenNode(
neighbor, topNode);
458 else if (closedList.find(
neighbor) != closedList.end())
460 return UpdateClosedNode(
neighbor, topNode);
464 return UpdateDelayedNode(
neighbor, topNode);
471 return AddNewNode(
neighbor, topNode);
479 NodeLookupTable::iterator iter;
489 return UpdateOpenNode(
neighbor, topNode);
491 else if ((iter = closedList.find(
neighbor)) != closedList.end())
493 neighborNode = iter->second;
498 return UpdateClosedNode(
neighbor, topNode);
506 return UpdateDelayedNode(
neighbor, topNode);
517 return AddNewNode(
neighbor, topNode);
526 double edgeCost = env->GCost(topNodeID,
neighbor);
527 double gcost = topNode.
gCost + edgeCost;
529 double fcost = gcost + h;
551 double oldf = n.
fCost;
562 openQueue.DecreaseKey(n);
564 openQueue.IncreaseKey(n);
566 else if (n.
fCost > oldf)
567 openQueue.IncreaseKey(n);
599 else if (bpmxLevel >= 1)
622 double oldf = n.
fCost;
633 delayQueue.DecreaseKey(n);
637 else if (n.
fCost > oldf)
638 delayQueue.IncreaseKey(n);
650 closedSize = closedList.size();
652 if (closedList.find(goalNode) != closedList.end())
654 n = closedList[goalNode];
660 solutionCost = n.
gCost;
668 pathSize = thePath.size();
763 glScalef(1.0/(20*120.0), 1.0/(20*120.0), 1);
764 glRotatef(180, 0.0, 0.0, 1.0);
765 glRotatef(180, 0.0, 1.0, 0.0);
782 node* nfrom = g->GetNode(from);
783 node* nto = g->GetNode(to);
795 glVertex3f(x1,y1,z1);
796 glVertex3f(x2,y2,z2);
800 sprintf(buf,
"%ld",(
long)weight);
801 DrawText((x1+x2)/2, (y1+y2)/2, (z1+z2)/2 + 0.05, 1, 0, 0, buf);