HOG2
AStarDelay.cpp
Go to the documentation of this file.
1 /*
2  * AStarDelay.cpp
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 9/27/07.
6  * Copyright 2007 __MyCompanyName__. All rights reserved.
7  *
8  */
9 
10 #include <sys/time.h>
11 #include <math.h>
12 #include <cstring>
13 #include "AStarDelay.h"
14 
15 using namespace AStarDelayUtil;
16 using namespace GraphSearchConstants;
17 
18 const static bool verbose = false;//true;
19 
20 //static unsigned long tickStart;
21 //
22 //static unsigned long tickGen;
23 
24 void AStarDelay::GetPath(GraphEnvironment *_env, Graph* _g, graphState from, graphState to, std::vector<graphState> &thePath)
25 {
26  if (!InitializeSearch(_env,_g,from,to,thePath))
27  return;
28 
29  struct timeval t0,t1;
30 
31  gettimeofday(&t0,0);
32 
33  while(!DoSingleSearchStep(thePath))
34  {}
35 
36  gettimeofday(&t1,0);
37 
38 // double usedtime = t1.tv_sec-t0.tv_sec + (t1.tv_usec-t0.tv_usec)/1000000.0;
39 
40  //if (thePath.size() > 0)
41  // printf("\nNodes expanded=%ld, Nodes touched=%ld, Reopenings=%ld.\n",GetNodesExpanded(),GetNodesTouched(),GetNodesReopened());
42 
43  //printf("Algorithm AStarDelay, time used=%lf sec, N/sec=%lf, solution cost=%lf, solution edges=%d.\n",usedtime, GetNodesExpanded()/usedtime,solutionCost,pathSize);
44 }
45 
46 bool AStarDelay::InitializeSearch(GraphEnvironment *_env, Graph* _g, graphState from, graphState to, std::vector<graphState> &thePath)
47 {
48  env = _env;
49  g = _g;
50  nodesTouched = nodesExpanded = nodesReopened = 0;
51  metaexpanded = 0;
52  closedSize = 0;
53  start = from;
54  goal = to;
55 
56  closedList.clear();
57  openQueue.reset();
58  delayQueue.reset();
59 // fQueue.reset();
60 
61  thePath.clear();
62 
63  //tickNewExp = tickReExp = tickBPMX = 0;
64  //nNewExp = nReExp = nBPMX = 0;
65 
66  //strcpy(algname,"AStarDelay");
67 
68  if ((from == UINT32_MAX) || (to == UINT32_MAX) || (from == to))
69  {
70  thePath.resize(0);
71  return false;
72  }
73 
74  // step (1)
75  SearchNode first(env->HCost(start, goal), 0, start, start);
76  openQueue.Add(first);
77 
78  F = 0;
79 
80  return true;
81 }
82 
83 bool AStarDelay::DoSingleSearchStep(std::vector<graphState> &thePath)
84 {
85  static int reopenCount = 0;
86 
87  SearchNode topNode;
88  graphState temp;
89  bool found = false;
90 
91 // printf("Reopen count: %d. Unique nodes: %ld. Log2 = %f\n",
92 // reopenCount, nodesExpanded-nodesReopened, log2(nodesExpanded-nodesReopened));
93 // printf("Delay queue: %d Open queue: %d goal? %s\n",
94 // delayQueue.size(), openQueue.size(),
95 // (env->GoalTest(temp = openQueue.top().currNode, goal))?"yes":"no");
96  // if we are about to open the goal off open, but the delay queue has
97  // lower costs, go to the delay queue first, no matter if we're allowed to
98  // or not
99  if ((delayQueue.size() > 0) && (openQueue.size() > 0) &&
100  (env->GoalTest(temp = openQueue.top().currNode, goal)) &&
101  (fless(delayQueue.top().gCost, openQueue.top().fCost)))
102  {
103  do { // throw out nodes with higher cost than goal
104  topNode = delayQueue.Remove();
105  } while (fgreater(topNode.fCost, openQueue.top().fCost));
106  //reopenCount = 0;
107  nodesReopened++;
108  found = true;
109  }
110  else if ((reopenCount < fDelay(nodesExpanded-nodesReopened)) && (delayQueue.size() > 0) && (openQueue.size() > 0))
111  {
112  //SearchNodeCompare cmpkey;
113 
114  if (fless(delayQueue.top().gCost, openQueue.top().fCost) )
115  {
116  topNode = delayQueue.Remove();
117  reopenCount++;
118  nodesReopened++;
119  }
120  else {
121  topNode = openQueue.Remove();
122  reopenCount = 0;
123  }
124  found = true;
125  }
126  else if ((reopenCount < fDelay(nodesExpanded-nodesReopened)) && (delayQueue.size() > 0))
127  {
128  nodesReopened++;
129  topNode = delayQueue.Remove();
130  reopenCount++;
131  found = true;
132  }
133 // else if (fQueue.size() > 0)
134 // {
135 // topNode = fQueue.Remove();
136 // canReopen = true;
137 // found = true;
138 // }
139  else if ((openQueue.size() > 0))
140  {
141  F = topNode.fCost;
142  topNode = openQueue.Remove();
143  reopenCount = 0;
144  found = true;
145  }
146 
147  if (found)
148  {
149  return DoSingleStep(topNode, thePath);
150  }
151  else {
152  thePath.resize(0); // no path found!
153  closedList.clear();
154  openQueue.reset();
155  env = 0;
156  return true;
157  }
158  return false;
159 }
160 
161 /* The steps refer to the pseudo codes of the corresponding algorithms */
162 
164  std::vector<graphState> &thePath)
165 {
166  nodesExpanded += 1;
167 
168  //if (topNode.rxp)
169  // nReExp++;
170  //else
171  // nNewExp++;
172 
173  if (verbose)
174  {
175  printf("Expanding node %ld , gcost=%lf, h=%lf, f=%lf.\n",
176  topNode.currNode, topNode.gCost, topNode.fCost-topNode.gCost, topNode.fCost);
177  }
178 
179 // unsigned long tickTmp ;//= clock();
180 
181  // and if there are no lower f-costs on the other open lists...
182  // otherwise we need to delay this node
183  if (env->GoalTest(topNode.currNode, goal))
184  {
185  //printf("Found path to goal!\n");
186  closedList[topNode.currNode] = topNode; // this is necessary for ExtractPathToStart()
187  ExtractPathToStart(topNode.currNode, thePath);
188  return true;
189  }
190 
191  // step (5), computing gi is delayed
192  neighbors.resize(0);
193  env->GetSuccessors(topNode.currNode, neighbors);
194 
195  //tickGen = clock() - tickTmp;
196 
197  bool doBPMX = false;
198  int ichild = 0;
199 _BPMX:
200  if (bpmxLevel >= 1)
201  if (doBPMX) {
202  ReversePropX1(topNode);
203 
204  // counting supplement
205  //if (nodesExpanded%2) {
206  // nodesExpanded += 1;
207 
208  // if (topNode.rxp)
209  // nReExp++;
210  // else
211  // nNewExp++;
212  //}
213 
214  //nodesExpanded += 1; //ichild / (double)neighbors.size();
215  }
216 
217 
218  //tickStart = clock();
219 
220  double minCost = DBL_MAX;
221  unsigned int x;
222  for (x = 0,ichild=1; x < neighbors.size(); x++,ichild++)
223  {
224  nodesTouched++;
225 
226  double cost;
227 
228  if (bpmxLevel >= 1) {
229  cost = HandleNeighborX(neighbors[x], topNode);
230  if (cost == 0) {
231 
232  //if (topNode.rxp) {
233  // tickReExp += clock() - tickStart + tickGen;
234  // tickGen = 0;
235  //}
236  //else {
237  // tickNewExp += clock() - tickStart + tickGen;
238  // tickGen = 0;
239  //}
240 
241  doBPMX = true;
242  goto _BPMX;
243  }
244  if (fless(cost, minCost))
245  minCost = cost;
246  }
247  else {
248  HandleNeighbor(neighbors[x], topNode);
249  }
250  }
251 
252  //if (topNode.rxp) {
253  // tickReExp += clock() - tickStart + tickGen;
254  //}
255  //else {
256  // tickNewExp += clock() - tickStart + tickGen;
257  //}
258 
259  // path max rule (i or ii?) // this is Mero rule (b), min rule -- allen
260  if (bpmxLevel >= 1)
261  if (fless(topNode.fCost-topNode.gCost, minCost))
262  topNode.fCost = topNode.gCost+minCost;
263  closedList[topNode.currNode] = topNode;
264 
265  if (bpmxLevel >= 1)
266  if (fifo.size() > 0) {
267  Broadcast(1,fifo.size()); // (level, levelcount)
268  }
269 
270  return false;
271 }
272 
273 // for BPMX
275 {
276  //tickStart = clock();
277 
278  double maxh = topNode.fCost - topNode.gCost;
279  for (unsigned int x=0;x<neighbors.size();x++)
280  {
281  graphState neighbor = neighbors[x];
282  SearchNode neighborNode = openQueue.find(SearchNode(neighbor));
283  if (neighborNode.currNode == neighbor) {
284  maxh = max(maxh, (neighborNode.fCost - neighborNode.gCost) - env->GCost(topNode.currNode,neighbor));
285  }
286  else {
287  neighborNode = delayQueue.find(SearchNode(neighbor));
288  if (neighborNode.currNode == neighbor) {
289  maxh = max(maxh, (neighborNode.fCost - neighborNode.gCost) - env->GCost(topNode.currNode, neighbor));
290  }
291  else {
292  NodeLookupTable::iterator iter = closedList.find(neighbor);
293  if (iter != closedList.end()) {
294  neighborNode = iter->second;
295  double oh = maxh;
296  maxh = max(maxh, (neighborNode.fCost - neighborNode.gCost) - env->GCost(topNode.currNode,neighbor));
297 
298  if (bpmxLevel > 1 && oh < maxh) {
299  fifo.push_back(neighbor);
300  }
301  }
302  else {
303  maxh = max(maxh, env->HCost(neighbor,goal) - env->GCost(topNode.currNode,neighbor));
304  }
305  }
306  }
307  }
308 
309  //nBPMX++;
310  //tickBPMX += clock() - tickStart;
311 
312  metaexpanded += 1; //
313  nodesExpanded += 1;
314  nodesTouched += neighbors.size();
315  topNode.fCost = maxh + topNode.gCost;
316 }
317 
318 // multi level BPMX in *closed* list
319 /* BPMX can only center around closed nodes, but open nodes can get updated as well*/
320 // a recursive function
321 void AStarDelay::Broadcast(int level, int levelcount)
322 { // we will only enque the newly updated (neighbor) nodes; or neighbor nodes being able to update others
323  NodeLookupTable::iterator iter;
324  SearchNode frontNode;
325  //tickStart = clock();
326 
327  for (int i=0;i<levelcount;i++) {
328  graphState front = fifo.front();
329  fifo.pop_front();
330 
331  iter = closedList.find(front);
332  if (iter == closedList.end()) {
333  frontNode = delayQueue.find(SearchNode(front));
334  if (frontNode.currNode != front)
335  continue;
336  }
337  else
338  frontNode = iter->second;
339  double frontH = frontNode.fCost - frontNode.gCost;
340 
341  myneighbors.clear();
342  env->GetSuccessors(front, myneighbors);
343 
344  // backward pass
345  for (unsigned int x = 0; x < myneighbors.size(); x++)
346  {
347  graphState neighbor = myneighbors[x];
348  iter = closedList.find(neighbor);
349  if (iter != closedList.end()) {
350  double edgeWeight = env->GCost(front,neighbor);
351  SearchNode neighborNode = iter->second;
352 
353  double neighborH = neighborNode.fCost - neighborNode.gCost;
354 
355  if (fgreater(neighborH - edgeWeight, frontH)) {
356  frontH = neighborH - edgeWeight;
357  frontNode.fCost = frontNode.gCost + frontH;
358  fifo.push_back(neighbor);
359  }
360  }
361  else {
362  SearchNode neighborNode = openQueue.find(SearchNode(neighbor));
363  if (neighborNode.currNode == neighbor) {
364  double edgeWeight = env->GCost(front,neighbor);
365 
366  double neighborH = neighborNode.fCost - neighborNode.gCost;
367 
368  if (fgreater(neighborH - edgeWeight, frontH)) {
369  frontH = neighborH - edgeWeight;
370  frontNode.fCost = frontNode.gCost + frontH;
371  }
372  }
373  else {
374  neighborNode = delayQueue.find(SearchNode(neighbor));
375  if (neighborNode.currNode == neighbor) {
376  double edgeWeight = env->GCost(front,neighbor);
377 
378  double neighborH = neighborNode.fCost - neighborNode.gCost;
379 
380  if (fgreater(neighborH - edgeWeight, frontH)) {
381  frontH = neighborH - edgeWeight;
382  frontNode.fCost = frontNode.gCost + frontH;
383  fifo.push_back(neighbor);
384  }
385  }
386  }
387  }
388  }
389  // store frontNode
390  closedList[front] = frontNode;
391 
392  // forward pass
393  for (unsigned int x = 0; x < myneighbors.size(); x++)
394  {
395  graphState neighbor = myneighbors[x];
396  NodeLookupTable::iterator theIter = closedList.find(neighbor);
397  if (theIter != closedList.end())
398  {
399  double edgeWeight = env->GCost(front,neighbor);
400  SearchNode neighborNode = theIter->second;
401 
402  double neighborH = neighborNode.fCost - neighborNode.gCost;
403 
404  if (fgreater(frontH - edgeWeight, neighborH)) {
405  neighborNode.fCost = neighborNode.gCost + frontH - edgeWeight; // store neighborNode
406  closedList[neighbor] = neighborNode;
407  fifo.push_back(neighbor);
408  }
409  }
410  else {
411  SearchNode neighborNode = openQueue.find(SearchNode(neighbor));
412  if (neighborNode.currNode == neighbor) {
413  double edgeWeight = env->GCost(front,neighbor);
414 
415  double neighborH = neighborNode.fCost - neighborNode.gCost;
416 
417  if (fgreater(frontH - edgeWeight, neighborH)) {
418  neighborNode.fCost = neighborNode.gCost + frontH - edgeWeight;
419  openQueue.IncreaseKey(neighborNode);
420  }
421  }
422  else {
423  neighborNode = delayQueue.find(SearchNode(neighbor));
424  if (neighborNode.currNode == neighbor) {
425  double edgeWeight = env->GCost(front,neighbor);
426 
427  double neighborH = neighborNode.fCost - neighborNode.gCost;
428 
429  if (fgreater(frontH - edgeWeight, neighborH)) {
430  neighborNode.fCost = neighborNode.gCost + frontH - edgeWeight;
431  delayQueue.IncreaseKey(neighborNode);
432  fifo.push_back(neighbor);
433  }
434  }
435  }
436  }
437  }
438  }
439 
440  //nBPMX += 2;
441  //tickBPMX += clock() - tickStart;
442 
443  metaexpanded += 2; //
444  nodesExpanded += 2;
445  nodesTouched += 2*levelcount;
446 
447  level++;
448  if (level < bpmxLevel && fifo.size() > 0)
449  Broadcast(level, fifo.size());
450 }
451 
453 {
454  if (openQueue.IsIn(SearchNode(neighbor))) // in OPEN
455  {
456  return UpdateOpenNode(neighbor, topNode);
457  }
458  else if (closedList.find(neighbor) != closedList.end()) // in CLOSED
459  {
460  return UpdateClosedNode(neighbor, topNode);
461  }
462  else if (delayQueue.IsIn(SearchNode(neighbor))) // in DELAY
463  {
464  return UpdateDelayedNode(neighbor, topNode);
465  }
466 // else if (fQueue.IsIn(SearchNode(neighbor))) // in low g-cost!
467 // {
468 // return UpdateLowGNode(neighbor, topNode);
469 // }
470  else { // not opened yet
471  return AddNewNode(neighbor, topNode);
472  }
473  return 0;
474 }
475 
477 {
478  SearchNode neighborNode;
479  NodeLookupTable::iterator iter;
480  double edge = env->GCost(topNode.currNode,neighbor);
481  double hTop = topNode.fCost - topNode.gCost;
482 
483  if ((neighborNode = openQueue.find(SearchNode(neighbor))).currNode == neighbor) // in OPEN
484  {
485  if (fgreater(neighborNode.fCost - neighborNode.gCost - edge , hTop)) {
486  return 0;
487  }
488 
489  return UpdateOpenNode(neighbor, topNode);
490  }
491  else if ((iter = closedList.find(neighbor)) != closedList.end()) // in CLOSED
492  {
493  neighborNode = iter->second;
494  if (fgreater(neighborNode.fCost - neighborNode.gCost - edge , hTop)) {
495  return 0;
496  }
497 
498  return UpdateClosedNode(neighbor, topNode);
499  }
500  else if ((neighborNode = delayQueue.find(SearchNode(neighbor))).currNode == neighbor) // in DELAY
501  {
502  if (fgreater(neighborNode.fCost - neighborNode.gCost - edge , hTop)) {
503  return 0;
504  }
505 
506  return UpdateDelayedNode(neighbor, topNode);
507  }
508 // else if (fQueue.IsIn(SearchNode(neighbor))) // in low g-cost!
509 // {
510 // return UpdateLowGNode(neighbor, topNode);
511 // }
512  else { // not opened yet
513  if (fgreater( env->HCost(neighbor,goal) - edge , hTop)) {
514  return 0;
515  }
516 
517  return AddNewNode(neighbor, topNode);
518  }
519  return 0;
520 }
521 
522 // return edge cost + h cost
524 {
525  graphState topNodeID = topNode.currNode;
526  double edgeCost = env->GCost(topNodeID,neighbor);
527  double gcost = topNode.gCost + edgeCost;
528  double h = max(env->HCost(neighbor,goal), topNode.fCost - topNode.gCost - edgeCost);
529  double fcost = gcost + h;
530 
531  SearchNode n(fcost, gcost, neighbor, topNodeID);
532  n.isGoal = (neighbor == goal);
533 // if (fless(fcost, F))
534 // {
535 // fQueue.Add(n); // nodes with cost < F
536 // }
537 // else {
538  openQueue.Add(n);
539 // }
540  return edgeCost+n.fCost-n.gCost;
541 }
542 
543 // return edge cost + h cost
545 {
546  // lookup node
547  SearchNode n;
548  n = openQueue.find(SearchNode(neighbor));
549  double edgeCost = env->GCost(topNode.currNode, neighbor);
550 
551  double oldf = n.fCost;
552  if (bpmxLevel >= 1)
553  n.fCost = max(n.fCost , topNode.fCost - topNode.gCost - edgeCost + n.gCost);
554 
555  if (fless(topNode.gCost+edgeCost, n.gCost))
556  {
557  n.fCost -= n.gCost;
558  n.gCost = topNode.gCost+edgeCost;
559  n.fCost += n.gCost;
560  n.prevNode = topNode.currNode;
561  if (n.fCost < oldf)
562  openQueue.DecreaseKey(n);
563  else
564  openQueue.IncreaseKey(n);
565  }
566  else if (n.fCost > oldf)
567  openQueue.IncreaseKey(n);
568 
569  // return value for pathmax
570  return edgeCost+n.fCost-n.gCost;
571 }
572 
573 // return edge cost + h cost
575 {
576  // lookup node
577  SearchNode n = closedList[neighbor];
578  double edgeCost = env->GCost(topNode.currNode, neighbor);
579  // check if we should update cost
580  if (fless(topNode.gCost+edgeCost, n.gCost))
581  {
582  double hCost = n.fCost - n.gCost;
583  n.gCost = topNode.gCost+edgeCost;
584 
585  // do pathmax here -- update child-h to parent-h - edge cost
586  if (bpmxLevel >= 1)
587  hCost = max(topNode.fCost-topNode.gCost-edgeCost, hCost);
588 
589  n.fCost = n.gCost + hCost;
590  n.prevNode = topNode.currNode;
591 
592  // put into delay list if we can open it
593  closedList.erase(neighbor); // delete from CLOSED
594 
595  //n.rxp = true;
596  delayQueue.Add(n); // add to delay list
597  //openQueue.Add(n);
598  }
599  else if (bpmxLevel >= 1)
600  if (fgreater(topNode.fCost-topNode.gCost-edgeCost, n.fCost-n.gCost)) // pathmax
601  {
602  n.fCost = topNode.fCost-topNode.gCost-edgeCost;
603  n.fCost += n.gCost;
604  closedList[neighbor] = n;
605 
606  if (bpmxLevel > 1) {
607  fifo.push_back(neighbor);
608  }
609  }
610  // return value for pathmax
611  return edgeCost+n.fCost-n.gCost;
612 }
613 
614 // return edge cost + h cost
616 {
617  // lookup node
618  SearchNode n;
619  n = delayQueue.find(SearchNode(neighbor));
620  double edgeCost = env->GCost(topNode.currNode, neighbor);
621 
622  double oldf = n.fCost;
623  if (bpmxLevel >= 1)
624  n.fCost = max(n.fCost , topNode.fCost - topNode.gCost - edgeCost + n.gCost);
625 
626  if (fless(topNode.gCost+edgeCost, n.gCost))
627  {
628  n.fCost -= n.gCost;
629  n.gCost = topNode.gCost+edgeCost;
630  n.fCost += n.gCost;
631  n.prevNode = topNode.currNode;
632  //if (n.fCost < oldf)
633  delayQueue.DecreaseKey(n);
634  //else
635  // delayQueue.IncreaseKey(n);
636  }
637  else if (n.fCost > oldf)
638  delayQueue.IncreaseKey(n);
639 
640  // return value for pathmax
641  return edgeCost+n.fCost-n.gCost;
642 }
643 
644 
645 
646 void AStarDelay::ExtractPathToStart(graphState goalNode, std::vector<graphState> &thePath)
647 {
648  SearchNode n;
649 
650  closedSize = closedList.size();
651 
652  if (closedList.find(goalNode) != closedList.end())
653  {
654  n = closedList[goalNode];
655  }
656  else {
657  n = openQueue.find(SearchNode(goalNode));
658  }
659 
660  solutionCost = n.gCost;
661  do {
662  //solutionCost += env->GCost(n.prevNode,n.currNode);
663 
664  thePath.push_back(n.currNode);
665  n = closedList[n.prevNode];
666  } while (n.currNode != n.prevNode);
667  //thePath.push_back(n.currNode);
668  pathSize = thePath.size();
669 }
670 
671 //
672 //void AStarDelay::OpenGLDraw(int)
673 //{
674 // OpenGLDraw();
675 //}
676 
678 {
679 // //float r,gcost,b;
680 // double x,y,z;
681 // SearchNode sn;
682 // graphState nodeID;
683 // SearchNode topn;
684 // char buf[100];
685 //
686 // // draw nodes
687 // node_iterator ni = g->getNodeIter();
688 // for (node* n = g->nodeIterNext(ni); n; n = g->nodeIterNext(ni))
689 // {
690 // x = n->GetLabelF(kXCoordinate);
691 // y = n->GetLabelF(kYCoordinate);
692 // z = n->GetLabelF(kZCoordinate);
693 //
694 // nodeID = (graphState) n->GetNum();
695 //
696 // // if in closed
697 // NodeLookupTable::iterator hiter;
698 // if ((hiter = closedList.find(nodeID)) != closedList.end())
699 // {
700 // sn = hiter->second;
701 //
702 // memset(buf,0,100);
703 // sprintf(buf,"C %1.0f=%1.0f+%1.0f", sn.fCost, sn.gCost, (sn.fCost - sn.gCost));
704 // DrawText(x,y,z+0.05,0,0,0,buf);
705 //
706 // glColor3f(1,0,0); // red
707 // }
708 // // if in open
709 // else if (openQueue.IsIn(SearchNode(nodeID)))
710 // {
711 // sn = openQueue.find(SearchNode(nodeID));
712 // memset(buf,0,100);
713 // sprintf(buf,"O %1.0f=%1.0f+%1.0f", sn.fCost, sn.gCost, (sn.fCost - sn.gCost));
714 // DrawText(x,y,z+0.05,0,0,0,buf);
715 //
716 // glColor3f(0,0,1); // blue
717 // }
727 // else if (delayQueue.IsIn(SearchNode(nodeID)))
728 // {
729 // sn = delayQueue.find(SearchNode(nodeID));
730 // memset(buf,0,100);
731 // sprintf(buf,"D %1.0f=%1.0f+%1.0f", sn.fCost, sn.gCost, (sn.fCost - sn.gCost));
732 // DrawText(x,y,z+0.05,0,0,0,buf);
733 //
734 // glColor3f(1,0,1); // purple
735 // }
736 // // neither in open nor closed, white
737 // else
738 // {
739 // glColor3f(1,1,1); // white
740 // }
741 // DrawSphere(x,y,z,0.025);
742 //
743 // // draw the text info, in black
744 // //DrawText(x,y,z+0.05,0,0,0,buf);
745 // }
746 //
748 // edge_iterator ei = g->getEdgeIter();
749 // for (edge* e = g->edgeIterNext(ei); e; e = g->edgeIterNext(ei))
750 // {
751 // DrawEdge(e->getFrom(), e->getTo(), e->GetWeight());
752 // }
753 }
754 
755 void AStarDelay::DrawText(double x, double y, double z, float r, float gg, float b, char* str)
756 {
757  //glPushMatrix();
758  // rotate ?
759 
760  glPushMatrix();
761  glColor3f(r,gg,b);
762  glTranslatef(x,y,z);
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);
766 
767  int i=0;
768  while(str[i])
769  {
770 // glutStrokeCharacter(GLUT_STROKE_ROMAN,str[i]);
771  i++;
772  }
773  glPopMatrix();
774 }
775 
776 void AStarDelay::DrawEdge(unsigned int from, unsigned int to, double weight)
777 {
778  double x1,y1,z1;
779  double x2,y2,z2;
780  char buf[100] = {0};
781 
782  node* nfrom = g->GetNode(from);
783  node* nto = g->GetNode(to);
784 
785  x1 = nfrom->GetLabelF(kXCoordinate);
786  y1 = nfrom->GetLabelF(kYCoordinate);
787  z1 = nfrom->GetLabelF(kZCoordinate);
788  x2 = nto->GetLabelF(kXCoordinate);
789  y2 = nto->GetLabelF(kYCoordinate);
790  z2 = nto->GetLabelF(kZCoordinate);
791 
792  // draw line segment
793  glBegin(GL_LINES);
794  glColor3f(1,1,0); // yellow
795  glVertex3f(x1,y1,z1);
796  glVertex3f(x2,y2,z2);
797  glEnd();
798 
799  // draw weight info
800  sprintf(buf,"%ld",(long)weight);
801  DrawText((x1+x2)/2, (y1+y2)/2, (z1+z2)/2 + 0.05, 1, 0, 0, buf); // in red
802 }
AStarDelayUtil::SearchNode::currNode
graphState currNode
Definition: AStarDelay.h:57
graphMove
Definition: GraphEnvironment.h:34
AStarDelay::UpdateDelayedNode
double UpdateDelayedNode(graphState neighbor, AStarDelayUtil::SearchNode &topNode)
Definition: AStarDelay.cpp:615
AStarDelay.h
graphState
unsigned long graphState
Definition: GraphEnvironment.h:32
AStarDelayUtil
Definition: AStarDelay.h:37
GraphSearchConstants
Definition: GraphEnvironment.cpp:838
AStarDelayUtil::SearchNode::gCost
double gCost
Definition: AStarDelay.h:56
AStarDelay::AddNewNode
double AddNewNode(graphState neighbor, AStarDelayUtil::SearchNode &topNode)
Definition: AStarDelay.cpp:523
neighbor
graphMove neighbor
Definition: RoadMap.h:17
Graph
A generic Graph class.
Definition: Graph.h:66
GraphAbstractionConstants::kZCoordinate
@ kZCoordinate
Definition: GraphAbstraction.h:32
AStarDelay::OpenGLDraw
void OpenGLDraw() const
Definition: AStarDelay.cpp:677
AStarDelay::DrawEdge
void DrawEdge(unsigned int from, unsigned int to, double weight)
Definition: AStarDelay.cpp:776
AStarDelayUtil::SearchNode::prevNode
graphState prevNode
Definition: AStarDelay.h:58
AStarDelay::UpdateOpenNode
double UpdateOpenNode(graphState neighbor, AStarDelayUtil::SearchNode &topNode)
Definition: AStarDelay.cpp:544
AStarDelay::HandleNeighbor
double HandleNeighbor(graphState neighbor, AStarDelayUtil::SearchNode &topNode)
Definition: AStarDelay.cpp:452
fless
bool fless(double a, double b)
Definition: FPUtil.h:28
DrawText
void DrawText(double x, double y, double z, double scale, const char *str)
Definition: GLUtil.cpp:526
AStarDelayUtil::SearchNode
Definition: AStarDelay.h:39
AStarDelay::DrawText
void DrawText(double x, double y, double z, float r, float g, float b, char *str)
Definition: AStarDelay.cpp:755
AStarDelay::DoSingleSearchStep
bool DoSingleSearchStep(std::vector< graphState > &thePath)
Definition: AStarDelay.cpp:83
GraphAbstractionConstants::kYCoordinate
@ kYCoordinate
Definition: GraphAbstraction.h:31
AStarDelay::GetPath
void GetPath(GraphEnvironment *env, Graph *_g, graphState from, graphState to, std::vector< graphState > &thePath)
Definition: AStarDelay.cpp:24
fgreater
bool fgreater(double a, double b)
Definition: FPUtil.h:29
max
#define max(a, b)
Definition: MinimalSectorAbstraction.cpp:40
AStarDelay::Broadcast
void Broadcast(int level, int levelcount)
Definition: AStarDelay.cpp:321
GraphAbstractionConstants::kXCoordinate
@ kXCoordinate
Definition: GraphAbstraction.h:30
UINT32_MAX
#define UINT32_MAX
Definition: GenericAStar.h:22
AStarDelay::ReversePropX1
void ReversePropX1(AStarDelayUtil::SearchNode &topNode)
Definition: AStarDelay.cpp:274
node::GetLabelF
double GetLabelF(unsigned int index) const
Definition: Graph.h:215
AStarDelay::HandleNeighborX
double HandleNeighborX(graphState neighbor, AStarDelayUtil::SearchNode &topNode)
Definition: AStarDelay.cpp:476
AStarDelay::DoSingleStep
bool DoSingleStep(AStarDelayUtil::SearchNode &topNode, std::vector< graphState > &thePath)
Definition: AStarDelay.cpp:163
AStarDelay::InitializeSearch
bool InitializeSearch(GraphEnvironment *env, Graph *g, graphState from, graphState to, std::vector< graphState > &thePath)
Definition: AStarDelay.cpp:46
AStarDelayUtil::SearchNode::fCost
double fCost
Definition: AStarDelay.h:55
AStarDelayUtil::SearchNode::isGoal
bool isGoal
Definition: AStarDelay.h:59
verbose
const static bool verbose
Definition: AStarDelay.cpp:18
AStarDelay::ExtractPathToStart
void ExtractPathToStart(graphState goalNode, std::vector< graphState > &thePath)
Definition: AStarDelay.cpp:646
AStarDelay::UpdateClosedNode
double UpdateClosedNode(graphState neighbor, AStarDelayUtil::SearchNode &topNode)
Definition: AStarDelay.cpp:574
GraphEnvironment
Definition: GraphEnvironment.h:291
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