rrt.c
Go to the documentation of this file.
1 #include "rrt.h"
2 
3 #include "defines.h"
4 #include "algebra.h"
5 #include "random.h"
6 #include "samples.h"
7 #include "filename.h"
8 
9 #include <string.h>
10 #include <math.h>
11 
29 void NewRRTBranch(TRRTStatistics *rst);
30 
40 
50 
61 
69 void NewRRTStep(TRRTStatistics *rst);
70 
81 void NewRRTDistanceQrand(double dqr,TRRTStatistics *rst);
82 
91 
100 
109 void NewRRTHighCost(TRRTStatistics *rst);
110 
119 
128 
138 
147 void NewRRTTooFar(TRRTStatistics *rst);
148 
157 void NewRRTStalled(TRRTStatistics *rst);
158 
167 void NewRRTSample(TRRTStatistics *rst);
168 
175 
182 
189 
190 
191 /******************************************************************************/
192 /******************************************************************************/
193 /******************************************************************************/
194 
196 {
197  if (rst!=NULL)
198  {
199  rst->n=0;
200 
201  rst->nBranch=0;
202  rst->nNoEmptyBranch=0;
203 
204  rst->nTreeConnection=0;
205  rst->nNoEmptyTreeConnection=0;
206 
207  rst->nStep=0;
208  rst->dQrand=0.0;
209 
210  rst->nQrandReached=0;
211  rst->nConvergenceError=0;
212  rst->nHighCost=0;
213  rst->nOutOfDomain=0;
214  rst->nDistanceIncreases=0;
215  rst->nCollision=0;
216  rst->nTooFar=0;
217  rst->nStalled=0;
218 
219  rst->nSample=0;
220 
221  rst->nRandom=0;
222  rst->nRejections=0;
223 
224  rst->nCollisionChecks=0;
225  }
226 }
227 
229 {
230  if (rst!=NULL) rst->nBranch++;
231 }
232 
234 {
235  if (rst!=NULL) rst->nNoEmptyBranch++;
236 }
237 
239 {
240  if (rst!=NULL) rst->nTreeConnection++;
241 }
242 
244 {
245  if (rst!=NULL) rst->nNoEmptyTreeConnection++;
246 }
247 
248 void NewRRTDistanceQrand(double dqr,TRRTStatistics *rst)
249 {
250  if (rst!=NULL) rst->dQrand+=dqr;
251 }
252 
254 {
255  if (rst!=NULL) rst->nStep++;
256 }
257 
259 {
260  if (rst!=NULL) rst->nQrandReached++;
261 }
262 
264 {
265  if (rst!=NULL) rst->nConvergenceError++;
266 }
267 
269 {
270  if (rst!=NULL) rst->nHighCost++;
271 }
272 
274 {
275  if (rst!=NULL) rst->nOutOfDomain++;
276 }
277 
279 {
280  if (rst!=NULL) rst->nDistanceIncreases++;
281 }
282 
284 {
285  if (rst!=NULL) rst->nCollision++;
286 }
287 
289 {
290  if (rst!=NULL) rst->nTooFar++;
291 }
292 
294 {
295  if (rst!=NULL) rst->nStalled++;
296 }
297 
299 {
300  if (rst!=NULL) rst->nSample++;
301 }
302 
304 {
305  if (rst!=NULL) rst->nRandom++;
306 }
307 
309 {
310  if (rst!=NULL) rst->nRejections++;
311 }
312 
314 {
315  if (rst!=NULL) rst->nCollisionChecks++;
316 }
317 
319 {
320  if ((rst1!=NULL)&&(rst2!=NULL))
321  {
322  if (rst1->n==0)
323  rst2->n++;
324  else
325  rst2->n+=rst1->n;
326 
327  rst2->nBranch+=rst1->nBranch;
328  rst2->nNoEmptyBranch+=rst1->nNoEmptyBranch;
329 
330  rst2->nTreeConnection+=rst1->nTreeConnection;
332 
333  rst2->nStep+=rst1->nStep;
334  rst2->dQrand+=rst1->dQrand;
335 
336  rst2->nQrandReached+=rst1->nQrandReached;
337  rst2->nOutOfDomain+=rst1->nOutOfDomain;
339  rst2->nCollision+=rst1->nCollision;
340  rst2->nTooFar+=rst1->nTooFar;
341  rst2->nStalled+=rst1->nStalled;
342 
343  rst2->nSample+=rst1->nSample;
344 
345  rst2->nRandom+=rst1->nRandom;
346  rst2->nRejections+=rst1->nRejections;
347 
348  rst2->nCollisionChecks+=rst1->nCollisionChecks;
349  }
350 }
351 
353 {
354  if (rst!=NULL)
355  {
356  unsigned int m,nExt;
357 
358  if (rst->n==0)
359  rst->n=1;
360 
361  nExt=rst->nBranch+rst->nTreeConnection;
362 
363  fprintf(stderr,"%% **************************************************\n");
364  if (rst->n>1)
365  fprintf(stderr,"RRT Statistics (averaged over %u repetitions)\n",rst->n);
366  else
367  fprintf(stderr,"RRT Statistics\n\n");
368  fprintf(stderr," Num. random samples : %.2f\n",
369  (double)rst->nRandom/(double)rst->n);
370  fprintf(stderr," Num. rejected random samples : %.2f (%.2f)\n",
371  (double)rst->nRejections/(double)rst->n,
372  (double)rst->nRejections/(double)rst->nRandom);
373  fprintf(stderr," Num. accepted random samples : %.2f (%.2f)\n",
374  (double)(rst->nRandom-rst->nRejections)/(double)rst->n,
375  (double)(rst->nRandom-rst->nRejections)/(double)rst->nRandom);
376 
377  if ((rst->n==1)&&(rrt!=NULL)&&(DynamicDomainRRT(rrt)))
378  {
379  unsigned int i,n;
380  double miDD,maDD,avDD,r;
381 
382  miDD=+INF;
383  maDD=-INF;
384  avDD=0.0;
385  n=0;
386  for(i=0;i<rrt->ns;i++)
387  {
388  r=GetDynamicDomainRadius(i,rrt);
389  if (r>0)
390  {
391  if (r<miDD)
392  miDD=r;
393  if (r>maDD)
394  maDD=r;
395  avDD+=r;
396  n++;
397  }
398  }
399  if (n==0)
400  fprintf(stderr," No dynamic domain effect.");
401  else
402  fprintf(stderr," Dynamic domain radius : %.2f <-- %.2f --> %.2f (%u/%u)\n",
403  miDD,avDD/(double)n,maDD,n,rrt->ns);
404  }
405  fprintf(stderr," Average distance to Qrand : %.2f\n",
406  rst->dQrand/(double)rst->nBranch);
407 
408  if (rst->nTreeConnection>0)
409  {
410  fprintf(stderr," Num. direct RRT extensions : %.2f\n",
411  (double)rst->nBranch/(double)rst->n);
412 
413  m=rst->nNoEmptyBranch;
414  fprintf(stderr," Num. no-empty direct extensions : %.2f (%.2f)\n",
415  (double)m/(double)rst->n,
416  (double)m/(double)rst->nBranch);
417 
418  fprintf(stderr," Num. RRT connections : %.2f\n",
419  (double)rst->nTreeConnection/(double)rst->n);
420  m=rst->nNoEmptyTreeConnection;
421  fprintf(stderr," Num. no-empty RRT connections : %.2f (%.2f)\n",
422  (double)m/(double)rst->n,
423  (double)m/(double)rst->nTreeConnection);
424 
425  fprintf(stderr," Total branches : %.2f\n",
426  (double)nExt/(double)rst->n);
428  fprintf(stderr," Total no-empty branches : %.2f (%.2f)\n",
429  (double)m/(double)rst->n,
430  (double)m/(double)nExt);
431  }
432  else
433  {
434  fprintf(stderr," Total branches : %.2f\n",
435  (double)rst->nBranch/(double)rst->n);
436  m=rst->nNoEmptyBranch;
437  fprintf(stderr," Total no-empty branches : %.2f (%.2f)\n",
438  (double)m/(double)rst->n,
439  (double)m/(double)rst->nBranch);
440  }
441  fprintf(stderr," Reasons to stop the branch/connection\n");
442  m=rst->nQrandReached;
443  fprintf(stderr," q_rand reached : %.2f (%.2f)\n",
444  (double)m/(double)rst->n,
445  (double)m/(double)nExt);
446 
447  m=rst->nConvergenceError;
448  fprintf(stderr," Convergence errors : %.2f (%.2f)\n",
449  (double)m/(double)rst->n,
450  (double)m/(double)nExt);
451 
452  m=rst->nHighCost;
453  fprintf(stderr," High cost configurations : %.2f (%.2f)\n",
454  (double)m/(double)rst->n,
455  (double)m/(double)nExt);
456 
457  m=rst->nOutOfDomain;
458  fprintf(stderr," Out of domain : %.2f (%.2f)\n",
459  (double)m/(double)rst->n,
460  (double)m/(double)nExt);
461 
462  m=rst->nDistanceIncreases;
463  fprintf(stderr," Distance to q_rand increases : %.2f (%.2f)\n",
464  (double)m/(double)rst->n,
465  (double)m/(double)nExt);
466 
467  m=rst->nCollision;
468  fprintf(stderr," Collision : %.2f (%.2f)\n",
469  (double)m/(double)rst->n,
470  (double)m/(double)nExt);
471 
472  m=rst->nTooFar;
473  fprintf(stderr," Too far from previous sample : %.2f (%.2f)\n",
474  (double)m/(double)rst->n,
475  (double)m/(double)nExt);
476 
477  m=rst->nStalled;
478  fprintf(stderr," Stalled branch : %.2f (%.2f)\n",
479  (double)m/(double)rst->n,
480  (double)m/(double)nExt);
481 
482 
483  fprintf(stderr," Num. extension steps : %.2f\n",
484  (double)rst->nStep/(double)rst->n);
485  fprintf(stderr," Num. steps per branch : %.2f\n",
486  (double)rst->nStep/(double)nExt);
487 
488  fprintf(stderr," Num. collision checks : %.2f\n",
489  (double)rst->nCollisionChecks/(double)rst->n);
490 
491 
492  fprintf(stderr," Num. samples in (bi)RRT : %.2f\n",
493  (double)rst->nSample/(double)rst->n);
494  fprintf(stderr," Samples per non-empty extens. : %.2f\n",
495  (double)rst->nSample/(double)(rst->nNoEmptyBranch+rst->nNoEmptyTreeConnection));
496  }
497 }
498 
500 {
501 }
502 
503 
504 /******************************************************************************/
505 /******************************************************************************/
506 /******************************************************************************/
507 
508 
517 void SetRRTTopology(Tparameters *pr,Trrt *rrt);
518 
555 boolean AddBranchToRRT(Tparameters *pr,boolean ccRRT,
556  unsigned int tree,unsigned int i_near,
557  double *q_rand,double *goal,
558  unsigned int *lastSample,
559  double (*costF)(Tparameters*, boolean , double*, void*),
560  void *costData,
561  TRRTStatistics *rst,Trrt *rrt);
562 
582 unsigned int ReconstructRRTPath(Tparameters *pr,unsigned int sID,
583  double *pl,double* pc,unsigned int *ns,
584  double ***path,Trrt *rrt);
585 
604 unsigned int Steps2PathinRRT(Tparameters *pr,Tvector *steps,double *pl,double* pc,
605  unsigned int *ns,double ***path,Trrt *rrt);
606 
618 double RRTPathLength(Tparameters *pr,unsigned int sID,Trrt *rrt);
619 
646 unsigned int AddStepToRRTstar(Tparameters *pr,unsigned int i_near,
647  double *q_rand,double *goal,
648  unsigned int *i_goal,
649  TRRTStatistics *rst,Trrt *rrt);
675 void WireRRTstar(Tparameters *pr,unsigned int id_new,unsigned int i_near,
676  double gamma,unsigned int nn,unsigned int *n,double **c,
677  double h,Theap *q,unsigned int *t,
678  TRRTStatistics *rst,Trrt *rrt);
679 
700 void ReWireRRTstar(Tparameters *pr,
701  unsigned int id_new,double gamma,
702  unsigned int nn,unsigned int *n,double *c,
703  Tvector *steps,double *l,
704  Trrt *rrt);
705 
721 void RRTstarCloseIteration(unsigned int it,unsigned int id_goal,
722  double time,double gamma,
723  double *times,double *costs,
724  Trrt *rrt);
725 
741 void BiRRTstarCloseIteration(unsigned int it,double l,
742  double time,double gamma,
743  double *times,double *costs,
744  Trrt *rrt);
745 
746 /**********************************************************************************/
747 /**********************************************************************************/
748 /**********************************************************************************/
749 
750 void CopyRRTStep(void *a,void *b)
751 {
752  ((TRRTStep *)a)->id=((TRRTStep *)b)->id;
753  ((TRRTStep *)a)->cost=((TRRTStep *)b)->cost;
754 }
755 
756 
758 {
759  boolean hasS;
760  unsigned int i;
761 
762  if (CS_WD_GET_SIMP_TOPOLOGY(pr,&(rrt->tp),rrt->w)!=rrt->m)
763  Error("Missmatch number of variables in SetRRTTopology");
764 
765  /* Search for a "circular" variable */
766  hasS=FALSE;
767  i=0;
768  while((i<rrt->m)&&(!hasS))
769  {
770  hasS=(rrt->tp[i]==TOPOLOGY_S);
771  i++;
772  }
773  if (!hasS)
774  {
775  /* if all variables are real no need to consider topology */
776  free(rrt->tp);
777  rrt->tp=NULL;
778  }
779 }
780 
781 void AddEdgeToRRT(unsigned int i,unsigned int j,double c,Trrt *rrt)
782 {
783  if (rrt->graph)
784  {
785  TRRTSampleInfo *si;
786  unsigned int k;
787 
788  if ((i>=rrt->ns)||(j>=rrt->ns))
789  Error("Nodes out of range in AddEdgeToRRT");
790 
791  for(k=0;k<2;k++)
792  {
793  si=(k==0?rrt->si[i]:rrt->si[j]);
794  if (si->nn==si->m)
795  {
796  MEM_DUP(si->n,si->m,unsigned int);
797  MEM_EXPAND(si->cn,si->m,double);
798  }
799  si->n[si->nn]=(k==0?j:i);
800  si->cn[si->nn]=c;
801  si->nn++;
802  }
803  }
804 }
805 
806 boolean TransitionTestRRT(Tparameters *pr,unsigned int parent,double* q_next,double deltaStep,double *cost,
807  double (*costF)(Tparameters*,boolean,double*,void*),void *costData,Trrt *rrt)
808 {
809  double prevCost;
810  double threshold;
811  boolean success;
812  double epsilon;
813  double coefTemp;
814  double nFailMax;
815 
816  *cost=costF(pr,TRUE,q_next,costData);
817  prevCost=rrt->si[parent]->cost;
818 
819  epsilon=GetParameter(CT_EPSILON,pr);
820 
821  if ((prevCost+epsilon)>(*cost))
822  return(TRUE);
823  else
824  {
825  threshold=exp((prevCost-(*cost))/(rrt->temperature*deltaStep));
826  coefTemp=GetParameter(CT_COEF_TEMP,pr);
827  success=(randomDouble()<threshold);
828  if(success)
829  {
830  rrt->nFail=0;
831  rrt->temperature=rrt->temperature/pow(coefTemp,((*cost)-prevCost)/10);
832  }
833  else
834  {
835  rrt->nFail=rrt->nFail+1;
836  nFailMax=GetParameter(CT_NFAIL_MAX,pr);
837  if (rrt->nFail>nFailMax)
838  {
839  rrt->temperature=rrt->temperature*coefTemp;
840  rrt->nFail=0;
841  }
842  }
843  return(success);
844  }
845 }
846 
847 boolean AddBranchToRRT(Tparameters *pr,boolean ccRRT,
848  unsigned int tree,unsigned int i_near,
849  double *q_rand,double *goal,
850  unsigned int *lastSample,
851  double (*costF)(Tparameters*,boolean,double*,void*),
852  void *costData,
853  TRRTStatistics *rst,Trrt *rrt)
854 {
855  double epsilon;
856  boolean validSample,inDomain,inCollision,goalReached,distanceDecrease,tooFar,
857  qRandReached,tooClose;
858  unsigned int it;
859  double d,d1,dp;
860  #if (!EXPLORATION_RRT)
861  double dg;
862  #endif
863  double *v,*q_near,*q_next,*q_tmp;
864  unsigned int parent;
865  double eps;
866  boolean trans;
867  double cost;
868 
869  epsilon=GetParameter(CT_EPSILON,pr);
870  if (ccRRT)
871  eps=0;
872  else
873  eps=rrt->delta/50.0; /* for delta = 0.05 -> eps= 0.001 (value used in original cbirrt2) */
874 
875  q_near=rrt->si[i_near]->samples;
876 
877  NEW(v,rrt->m,double);
878  NEW(q_next,rrt->m,double);
879  NEW(q_tmp,rrt->m,double);
880  memcpy(q_next,q_near,rrt->m*sizeof(double)); /* start from q_near */
881  parent=i_near; /* inear will be parent for 1st sample if any */
882  *lastSample=i_near;
883 
884  DifferenceVectorTopology(rrt->m,rrt->tp,q_rand,q_next,v); /* q_next=q_near */
885  d1=Norm(rrt->m,v);
886  if (d1>rrt->delta)
887  ScaleVector(rrt->delta/d1,rrt->m,v);
888 
889  #if (_DEBUG>1)
890  printf(" Distance q_rand-tree: %f (%.12f)\n",d1,rrt->delta);
891  #endif
892 
893  goalReached=FALSE;
894  validSample=TRUE;
895  inDomain=TRUE;
896  inCollision=FALSE;
897  distanceDecrease=TRUE;
898  tooFar=FALSE;
899  tooClose=FALSE;
900  qRandReached=FALSE;
901  trans=TRUE;
902 
903  it=1;
904  while((!goalReached)&&(validSample)&&(!qRandReached)&&(inDomain)&&(trans)&&
905  (!inCollision)&&(distanceDecrease)&&(!tooFar)&&(!tooClose))
906  {
907  if (ccRRT)
908  SumVectorScale(rrt->m,q_near,(double)it,v,q_next);
909  else
910  AccumulateVector(rrt->m,v,q_next);
911 
912  if (rrt->n>0)
913  validSample=(CS_WD_NEWTON_IN_SIMP(pr,q_next,rrt->w)!=DIVERGED);
914 
915  if (validSample)
916  {
917  /* Compute the distance to previous sample */
918  dp=DistanceTopology(rrt->m,rrt->tp,rrt->si[parent]->samples,q_next);
919 
920  /* Distance to previous sample should not be too small */
921  tooClose=(dp<eps);
922  if (!tooClose)
923  {
924  /* Distance to previous sample should not too large */
925  tooFar=(dp>2*rrt->delta);
926  if (!tooFar)
927  {
928  /* Distance to q_rand should not increase */
929  d=d1;
930  d1=DistanceTopology(rrt->m,rrt->tp,q_rand,q_next);
931  distanceDecrease=(d1<d); /* new < previous */
932 
933  if (distanceDecrease)
934  {
935  /* before checking the inDomain condition, we have to
936  move the ranges to [-pi,pi], if necessary*/
937  inDomain=((PointInBoxTopology(NULL,FALSE,rrt->m,q_next,epsilon,rrt->tp,rrt->ambient))&&
938  (CS_WD_SIMP_INEQUALITIES_HOLD(pr,q_next,rrt->w)));
939  if (inDomain)
940  {
941  if(costF!=NULL)
942  trans=TransitionTestRRT(pr,parent,q_next,dp,&cost,costF,costData,rrt);
943 
944  if(trans)
945  {
946  CS_WD_IN_COLLISION(inCollision,pr,q_next,rrt->si[parent]->samples,rrt->w);
947  #if (GET_RRT_STATISTICS)
949  #endif
950  if (!inCollision)
951  {
952  // fprintf(stderr," exp Step: %f \n",dp);
953  qRandReached=AddNodeToRRT(pr,tree,parent,q_next,q_rand,
954  lastSample,NULL,dp,cost,rst,rrt);
955  #if (GET_RRT_STATISTICS)
956  if (qRandReached)
957  NewRRTQrandReached(rst);
958  #endif
959 
960  /* currentNode will be parent for next iteration,
961  if any */
962  parent=*lastSample;
963 
964  #if (!EXPLORATION_RRT)
965  dg=DistanceTopology(rrt->m,rrt->tp,q_next,goal);
966  goalReached=(dg<rrt->delta);
967  #endif
968 
969  if ((!ccRRT)&&(!goalReached))
970  {
971  DifferenceVectorTopology(rrt->m,rrt->tp,
972  q_rand,q_next,v);
973  /* d1 computed above =
974  distance(q_rand_q_next)*/
975  if (d1>rrt->delta)
976  ScaleVector(rrt->delta/d1,rrt->m,v);
977  }
978  }
979  #if ((RRT_VERBOSE)||(GET_RRT_STATISTICS))
980  else
981  {
982  #if (GET_RRT_STATISTICS)
983  NewRRTCollision(rst);
984  #endif
985  #if (RRT_VERBOSE)
986  fprintf(stderr," Configuration in collision.\n");
987  #endif
988  }
989  #endif
990  }
991  #if ((RRT_VERBOSE)||(GET_RRT_STATISTICS))
992  else
993  {
994  #if (GET_RRT_STATISTICS)
995  NewRRTHighCost(rst);
996  #endif
997  #if (RRT_VERBOSE)
998  fprintf(stderr," Configuration cost too high.\n");
999  #endif
1000  }
1001  #endif
1002  }
1003  #if ((RRT_VERBOSE)||(GET_RRT_STATISTICS))
1004  else
1005  {
1006  #if (GET_RRT_STATISTICS)
1007  NewRRTOutOfDomain(rst);
1008  #endif
1009  #if (RRT_VERBOSE)
1010  fprintf(stderr," Configuration not in domain.\n");
1011  #endif
1012  }
1013  #endif
1014  }
1015  #if ((RRT_VERBOSE)||(GET_RRT_STATISTICS))
1016  else
1017  {
1018  #if (GET_RRT_STATISTICS)
1020  #endif
1021  #if (RRT_VERBOSE)
1022  fprintf(stderr," Distance to q_rand increases (or stalled)\n");
1023  #endif
1024  }
1025  #endif
1026  }
1027  #if ((RRT_VERBOSE)||(GET_RRT_STATISTICS))
1028  else
1029  {
1030  #if (GET_RRT_STATISTICS)
1031  NewRRTTooFar(rst);
1032  #endif
1033  #if (RRT_VERBOSE)
1034  fprintf(stderr," Previous configuration is too far (too large advance step)\n");
1035  #endif
1036  }
1037  #endif
1038  }
1039  #if ((RRT_VERBOSE)||(GET_RRT_STATISTICS))
1040  else
1041  {
1042  #if (GET_RRT_STATISTICS)
1043  NewRRTStalled(rst);
1044  #endif
1045  #if (RRT_VERBOSE)
1046  fprintf(stderr," Previous configuration is too close (small advance step)\n");
1047  #endif
1048  }
1049  #endif
1050  }
1051  #if ((RRT_VERBOSE)||(GET_RRT_STATISTICS))
1052  else
1053  {
1054  #if (GET_RRT_STATISTICS)
1056  #endif
1057  #if (RRT_VERBOSE)
1058  fprintf(stderr," Sample does not converge to manifold.\n");
1059  #endif
1060  }
1061  #endif
1062  it++;
1063  }
1064 
1065  if (rrt->dd>0)
1066  AdjustDynamicDomain(i_near,inCollision,rrt);
1067 
1068  free(v);
1069  free(q_next);
1070  free(q_tmp);
1071 
1072  return(goalReached);
1073 }
1074 
1075 
1076 unsigned int ReconstructRRTPath(Tparameters *pr,unsigned int sID,double *pl,double *pc,
1077  unsigned int *ns,double ***path,Trrt *rrt)
1078 {
1079  Tvector steps;
1080  unsigned int nvs;
1081 
1082  RRTPathSteps(sID,&steps,rrt);
1083 
1084  nvs=Steps2PathinRRT(pr,&steps,pl,pc,ns,path,rrt);
1085  ReverseSamples(*ns,*path);
1086 
1087  DeleteVector(&steps);
1088 
1089  return(nvs);
1090 }
1091 
1092 
1093 unsigned int Steps2PathinRRT(Tparameters *pr,Tvector *steps,double *pl,double *pc,
1094  unsigned int *ns,double ***path,Trrt *rrt)
1095 {
1096  TRRTStep *st;
1097  unsigned int nv,nvs,ms,n,i,k,current,next;
1098  signed int j;
1099  double *o,c;
1100  boolean *systemVars;
1101  unsigned int lns;
1102  double **lpath;
1103  boolean reached,collision;
1104  double epsilon,dc;
1105 
1106  *pl=0; /* path length */
1107  if (pc!=NULL) /* path cost (mechanical work) */
1108  {
1109  *pc=0;
1110  epsilon=GetParameter(CT_EPSILON,pr);
1111  }
1112 
1113  /* Identify system variables */
1114  nv=CS_WD_GET_SYSTEM_VARS(&systemVars,rrt->w);
1115  nvs=0;
1116  for(i=0;i<nv;i++)
1117  {
1118  if (systemVars[i])
1119  nvs++;
1120  }
1121 
1122  InitSamples(&ms,ns,path);
1123 
1124  st=(TRRTStep *)GetVectorElement(0,steps);
1125  current=st->id;
1126  n=VectorSize(steps);
1127  k=1;
1128  while (k<n)
1129  {
1130  st=(TRRTStep *)GetVectorElement(k,steps);
1131  next=st->id;
1132 
1133  CS_WD_REGENERATE_ORIGINAL_POINT(pr,rrt->si[current]->samples,&o,rrt->w);
1134  AddSample2Samples(nv,o,nvs,systemVars,&ms,ns,path);
1135  free(o);
1136 
1137  c=ConnectSamples(pr,rrt->tp,NULL,rrt->ambient,rrt->m,rrt->n,
1138  rrt->si[current]->samples,rrt->si[next]->samples,INF,
1139  FALSE,NULL,&reached,&collision,NULL,&lns,&lpath,rrt->w);
1140  #if (RRT_VERBOSE)
1141  fprintf(stderr,"{%u->%u}[%g]",current,next,c);
1142  #endif
1143 
1144  (*pl)+=c; /* Update the path length */
1145  if(pc!=NULL) /* Update the path cost (mechanical work) */
1146  {
1147  dc=rrt->si[current]->cost-rrt->si[next]->cost;
1148  (*pc)+=(dc>0?dc:0)+epsilon*c;
1149  }
1150 
1151  if (!reached)
1152  Warning("Path segment could not be reconstructed in Steps2PathinRRT");
1153  else
1154  {
1155  for(j=0;j<lns;j++)
1156  {
1157  CS_WD_REGENERATE_ORIGINAL_POINT(pr,lpath[j],&o,rrt->w);
1158  AddSample2Samples(nv,o,nvs,systemVars,&ms,ns,path);
1159  free(o);
1160  }
1161  DeleteSamples(lns,lpath);
1162  }
1163 
1164  current=next;
1165  k++;
1166  }
1167  if (n>1)
1168  {
1169  /* Ensure that the last sample is also added (ConnectSamples stops close to the
1170  goal but not exactly on it) */
1171  CS_WD_REGENERATE_ORIGINAL_POINT(pr,rrt->si[current]->samples,&o,rrt->w);
1172  AddSample2Samples(nv,o,nvs,systemVars,&ms,ns,path);
1173  free(o);
1174  }
1175 
1176  free(systemVars);
1177 
1178  return(nvs);
1179 }
1180 
1181 double RRTPathLength(Tparameters *pr,unsigned int sID,Trrt *rrt)
1182 {
1183  unsigned int i;
1184  double pl;
1185 
1186  pl=0;
1187  i=sID;
1188  while (i!=NO_UINT)
1189  {
1190  if (rrt->si[i]->parent!=NO_UINT)
1191  pl+=DistanceTopology(rrt->m,rrt->tp,
1192  rrt->si[i]->samples,rrt->si[rrt->si[i]->parent]->samples);
1193  i=rrt->si[i]->parent;
1194  }
1195 
1196  return(pl);
1197 }
1198 
1199 /**********************************************************************************/
1200 /**********************************************************************************/
1201 /**********************************************************************************/
1202 
1203 void InitRRT(Tparameters *pr,boolean parallel,boolean simp,double *ps,
1204  unsigned int mode,boolean graph,double *pg,
1205  unsigned int m,TAtlasBase *w,Trrt *rrt)
1206 {
1207  double epsilon,er,*pWithDummies;
1208  unsigned int i;
1209  boolean collision=FALSE;
1210  unsigned int samplingMode;
1211  double dr;
1212 
1213  #if (EXPLORATION_RRT)
1214  if (mode!=ONE_TREE)
1215  Error("An EXPLORATION_RRT must be one directional");
1216  #endif
1217 
1218  /* Init the RRT structure */
1219  epsilon=GetParameter(CT_EPSILON,pr);
1220  samplingMode=(unsigned int)GetParameter(CT_SAMPLING,pr);
1222 
1223  /* Set up the possible parallel execution */
1224  rrt->parallel=FALSE; /* The default is not to execute in parallel */
1225  #ifdef _OPENMP
1226  if (parallel)
1227  {
1228  rrt->nCores=omp_get_max_threads();
1229  /* even if having many cores ans OpenMP we only execute in parallel
1230  large problems. */
1231  rrt->parallel=(rrt->nCores>1);
1232  }
1233  #endif
1234  //rrt->parallel=FALSE;
1235  if (!rrt->parallel)
1236  rrt->nCores=1;
1237 
1238  fprintf(stderr,"Number of computing cores (rrt) : %u\n",rrt->nCores);
1239 
1240  /* The base information with the equations, collions,... */
1241  rrt->w=w;
1242 
1243  /* one_tree two_trees, two_trees_with_swap */
1244  rrt->mode=mode;
1245  rrt->graph=graph;
1246  /* in kdtree sampling mode the dynamic domain is fixed
1247  by the kdtree, and not in the samples. */
1248  if (samplingMode==KDTREE_SAMPLING)
1249  rrt->dd=0.0;
1250  else
1251  rrt->dd=dr;
1252 
1253  /* only used for t-rrt */
1255  rrt->nFail=0;
1256 
1257  /* Information for each sample */
1258  rrt->ms=INIT_NUM_SAMPLES_RRT;
1259  rrt->ns=0;
1260  NEW(rrt->si,rrt->ms,TRRTSampleInfo*);
1261  for(i=0;i<rrt->ms;i++)
1262  rrt->si[i]=NULL;
1263 
1264  /* Initialize the collision detection, just in case */
1265  CS_WD_INIT_CD(pr,rrt->nCores,rrt->w);
1266 
1267  /* Box enclosing the part of the manifold to explore */
1268  NEW(rrt->ambient,1,Tbox);
1270 
1271  NEW(rrt->si[0],1,TRRTSampleInfo);
1272  if (simp)
1273  {
1274  /* If the input point is already in simplified form, use
1275  it directly. This is not the usual case. */
1276  rrt->m=m;
1277  NEW(rrt->si[0]->samples,rrt->m,double);
1278  memcpy(rrt->si[0]->samples,ps,sizeof(double)*rrt->m);
1279  if (rrt->mode!=ONE_TREE)
1280  {
1281  /* In bi-directional trees the goal is also added */
1282  NEW(rrt->si[1],1,TRRTSampleInfo);
1283  NEW(rrt->si[1]->samples,rrt->m,double);
1284  memcpy(rrt->si[1]->samples,pg,sizeof(double)*rrt->m);
1285  }
1286  }
1287  else
1288  {
1289  /* Simplify the input point and add it to the tree */
1290  CS_WD_REGENERATE_SOLUTION_POINT(pr,ps,&pWithDummies,rrt->w);
1291  rrt->m=CS_WD_GENERATE_SIMPLIFIED_POINT(pr,pWithDummies,
1292  &(rrt->si[0]->samples),rrt->w);
1293  free(pWithDummies);
1294 
1295  if (rrt->mode!=ONE_TREE)
1296  {
1297  /* In bi-directional trees the goal is also added */
1298  NEW(rrt->si[1],1,TRRTSampleInfo);
1299  CS_WD_REGENERATE_SOLUTION_POINT(pr,pg,&pWithDummies,rrt->w);
1300  CS_WD_GENERATE_SIMPLIFIED_POINT(pr,pWithDummies,
1301  &(rrt->si[1]->samples),rrt->w);
1302  free(pWithDummies);
1303  }
1304  }
1305 
1306  // rrt->m dimension of the ambient space
1307  rrt->k=(unsigned int)GetParameter(CT_N_DOF,pr); //dimension of the manifold
1308  rrt->n=rrt->m-rrt->k; //num of independent equations
1309  rrt->delta=GetParameter(CT_DELTA,pr);
1310 
1311  SetRRTTopology(pr,rrt);
1312 
1313  if ((!PointInBoxTopology(NULL,TRUE,rrt->m,rrt->si[0]->samples,epsilon,rrt->tp,rrt->ambient))||
1314  (!CS_WD_SIMP_INEQUALITIES_HOLD(pr,rrt->si[0]->samples,rrt->w)))
1315  Error("The start point is not in domain");
1316 
1317  /* Verify the start/goal samples, now that they are already simplified
1318  and added to the RRT */
1319  if (rrt->n==0)
1320  er=0;
1321  else
1322  er=CS_WD_ERROR_IN_SIMP_EQUATIONS(pr,rrt->si[0]->samples,rrt->w);
1323  if (er>epsilon)
1324  Error("The start point is not on the manifold");
1325 
1326  CS_WD_IN_COLLISION(collision,pr,rrt->si[0]->samples,NULL,rrt->w);
1327  if (collision)
1328  Error("Start point for the RRT is in collision");
1329 
1330  rrt->si[0]->costp=0.0;
1331  rrt->si[0]->cost=0.0;
1332  rrt->si[0]->ddr=0.0;
1333  rrt->si[0]->tree=START2GOAL;
1334  rrt->si[0]->parent=NO_UINT;
1335  if (rrt->graph)
1336  {
1337  rrt->si[0]->g=0;
1338  rrt->si[0]->m=10; /* initial space for 10 neighbours (extended when necessary) */
1339  rrt->si[0]->nn=0;
1340  NEW(rrt->si[0]->n,rrt->si[0]->m,unsigned int);
1341  NEW(rrt->si[0]->cn,rrt->si[0]->m,double);
1342  }
1343  rrt->ns=1;
1344 
1345  if (rrt->mode!=ONE_TREE)
1346  {
1347  rrt->si[1]->costp=0.0;
1348  rrt->si[1]->cost=0.0;
1349  rrt->si[1]->ddr=0.0;
1350  rrt->si[1]->tree=GOAL2START;
1351  rrt->si[1]->parent=NO_UINT;
1352  if (rrt->graph)
1353  {
1354  rrt->si[1]->g=0;
1355  rrt->si[1]->m=10; /* initial space for 10 neighbours (extended when necessary) */
1356  rrt->si[1]->nn=0;
1357  NEW(rrt->si[1]->n,rrt->si[1]->m,unsigned int);
1358  NEW(rrt->si[1]->cn,rrt->si[1]->m,double);
1359  }
1360  rrt->ns=2;
1361 
1362  if ((!PointInBoxTopology(NULL,TRUE,rrt->m,rrt->si[1]->samples,epsilon,rrt->tp,rrt->ambient))||
1363  (!CS_WD_SIMP_INEQUALITIES_HOLD(pr,rrt->si[1]->samples,rrt->w)))
1364  Error("The goal point is not in domain");
1365 
1366  if (rrt->n==0)
1367  er=0;
1368  else
1369  er=CS_WD_ERROR_IN_SIMP_EQUATIONS(pr,rrt->si[1]->samples,rrt->w);
1370  if (er>epsilon)
1371  Error("The goal point is not on the manifold");
1372 
1373  CS_WD_IN_COLLISION(collision,pr,rrt->si[1]->samples,NULL,rrt->w);
1374  if (collision)
1375  Error("Goal point for the RRT is in collision");
1376  }
1377 
1378  #if (_KDTREE==1)
1379  {
1380  unsigned int nd,i;
1381  Trectangle rec;
1382  Tinterval *range;
1383 
1384  nd=GetBoxNIntervals(rrt->ambient);
1385  InitRectangle(nd,NULL,NULL,&rec);
1386  for(i=0;i<nd;i++)
1387  {
1388  range=GetBoxInterval(i,rrt->ambient);
1389  SetRectangleLimits(i,LowerLimit(range),UpperLimit(range),&rec);
1390  }
1391  i=0;
1392  rrt->treeS2G=InitKDTree(&rec,rrt->tp,25,dr,1,&(rrt->si[0]->samples),&i);
1393 
1394  if (rrt->mode!=ONE_TREE)
1395  {
1396  i=1;
1397  if (rrt->mode==TWO_TREES)
1398  rrt->treeG2S=InitKDTree(&rec,rrt->tp,25,dr,1,&(rrt->si[1]->samples),&i);
1399  else
1400  /* TWO_TREES_WITH_SWAP -> only one tree is used */
1401  AddPoint2KDtree(rrt->si[1]->samples,i,&(rrt->treeS2G));
1402  }
1403  else
1404  rrt->treeG2S=NULL;
1405 
1406  DeleteRectangle(&rec);
1407  }
1408  #endif
1409 
1410  #if (_KDTREE==2)
1411  /* Create the start 2 goal tree */
1412  if ((!RRT_NN_TOPOLOGY)||(rrt->tp==NULL))
1413  rrt->treeS2G=CreateKDTree(rrt->m);
1414  else
1415  rrt->treeS2G=CreateKDTreeT(rrt->m,(int *)rrt->tp);
1416 
1417  AddPoint2KDTree(rrt->si[0]->samples,rrt->treeS2G);
1418  if (rrt->mode!=ONE_TREE)
1419  {
1420  /* and the goal to start, if necessary */
1421  if (rrt->mode==TWO_TREES)
1422  {
1423  if ((!RRT_NN_TOPOLOGY)||(rrt->tp==NULL))
1424  rrt->treeG2S=CreateKDTree(rrt->m);
1425  else
1426  rrt->treeG2S=CreateKDTreeT(rrt->m,(int *)rrt->tp);
1427 
1428  AddPoint2KDTree(rrt->si[1]->samples,rrt->treeG2S);
1429 
1430  rrt->maxNodesT1=rrt->ms;
1431  rrt->maxNodesT2=rrt->ms;
1432 
1433  NEW(rrt->t1ToId,rrt->maxNodesT1,unsigned int);
1434  NEW(rrt->t2ToId,rrt->maxNodesT2,unsigned int);
1435 
1436  rrt->t1ToId[0]=0;
1437  rrt->t2ToId[0]=1;
1438 
1439  rrt->nodesT1=1;
1440  rrt->nodesT2=1;
1441  }
1442  else
1443  {
1444  /* TWO_TREES_WITH_SWAP -> only one kd-tree is used
1445  to speed up the search for nearest neighbours,
1446  independent of the tree. Searches in a particular
1447  three, though, will be serial */
1448  AddPoint2KDTree(rrt->si[1]->samples,rrt->treeS2G);
1449  }
1450  }
1451  else
1452  {
1453  rrt->treeG2S=NULL;
1454  rrt->t1ToId=NULL;
1455  rrt->t2ToId=NULL;
1456  }
1457  #endif
1458 }
1459 
1461 {
1462  return(rrt->temperature);
1463 }
1464 
1465 boolean IsRRTGraph(Trrt *rrt)
1466 {
1467  return(rrt->graph);
1468 }
1469 
1470 boolean RRTSample(unsigned int samplingMode,unsigned int tree,
1471  double *goal,double *q_rand,
1472  TRRTStatistics *rst,Trrt *rrt)
1473 {
1474  boolean expand2Goal;
1475 
1476  #if (GET_RRT_STATISTICS)
1477  if (rst!=NULL)
1478  NewRRTRandomSample(rst);
1479  #endif
1480 
1481  expand2Goal=((goal!=NULL)&&(randomDouble()<0.01));
1482  if (expand2Goal)
1483  {
1484  memcpy(q_rand,goal,rrt->m*sizeof(double));
1485  #if (RRT_VERBOSE)
1486  fprintf(stderr," Expanding to goal----------------------------------\n");
1487  #endif
1488  }
1489  else
1490  {
1491  #if (_KDTREE==1)
1492  if (samplingMode==KDTREE_SAMPLING)
1493  {
1494  if ((rrt->mode==ONE_TREE)||(tree==START2GOAL)||
1495  ((tree==BOTHTREES)&&(randomDouble()<0.5)))
1496  SampleInKDtree(q_rand,rrt->treeS2G);
1497  else
1498  SampleInKDtree(q_rand,rrt->treeG2S);
1499  }
1500  else
1501  #endif
1502  /* samplingMode != KDTREE_SAMPLING (AMBIENT or TANGENT) */
1503  RandomPointInBox(NULL,q_rand,rrt->ambient);
1504  }
1505 
1506  return(expand2Goal);
1507 }
1508 
1509 boolean RRTValidateSample(Tparameters *pr,double *q_rand,unsigned int tree,boolean expand2goal,
1510  double *goal,double l,double *h,unsigned int *i_near,
1511  TRRTStatistics *rst,Trrt *rrt)
1512 {
1513  boolean validSample=TRUE;
1514 
1515  /* First check the optimality heuristics, if any */
1516  if ((expand2goal)||(goal==NULL))
1517  *h=0.0;
1518  else
1519  {
1520  *h=DistanceTopology(rrt->m,rrt->tp,q_rand,goal);
1521  if ((l<INF)&&((HEURISTIC_RRT_STAR)&(1)))
1522  validSample=((DistanceTopology(rrt->m,rrt->tp,rrt->si[0]->samples,q_rand)+*h)<=l);
1523  }
1524 
1525  /* Now check the domain */
1526  if (validSample)
1527  validSample=((expand2goal)||(CS_WD_SIMP_INEQUALITIES_HOLD(pr,q_rand,rrt->w)));
1528 
1529  /* Now the NN conditions (dynamic domain) */
1530  if (validSample)
1531  {
1532  *i_near=GetRRTNN(tree,q_rand,rrt);
1533 
1534  if (rrt->dd>0)
1535  validSample=InDynamicDomain(*i_near,q_rand,rrt);
1536  }
1537 
1538  #if (GET_RRT_STATISTICS)
1539  if (!validSample)
1540  NewRRTSampleRejection(rst);
1541  #endif
1542 
1543  return(validSample);
1544 }
1545 
1546 unsigned int GetRRTNN(unsigned int tree,double *q_rand,Trrt *rrt)
1547 {
1548  #if (_KDTREE==1)
1549  if ((rrt->mode!=TWO_TREES_WITH_SWAP)||(tree==BOTHTREES))
1550  {
1551  unsigned int inear;
1552 
1553  if (rrt->mode==TWO_TREES)
1554  {
1555  if (tree==START2GOAL)
1556  inear=NearestNeighbour(q_rand,rrt->treeS2G);
1557  else
1558  {
1559  if (tree==GOAL2START)
1560  inear=NearestNeighbour(q_rand,rrt->treeG2S);
1561  else
1562  {
1563  /* BOTHTREES */
1564  unsigned int inear1,inear2;
1565  double d1,d2;
1566 
1567  inear1=NearestNeighbour(q_rand,rrt->treeS2G);
1568  inear2=NearestNeighbour(q_rand,rrt->treeG2S);
1569 
1570  d1=SquaredDistanceTopology(rrt->m,rrt->tp,rrt->si[inear1]->samples,q_rand);
1571  d2=SquaredDistanceTopology(rrt->m,rrt->tp,rrt->si[inear2]->samples,q_rand);
1572 
1573  inear=(d1<d2?inear1:inear2);
1574  }
1575  }
1576  }
1577  else
1578  /* rrt->mode==ONE_TREE or (rrt->mode==TWO_TREES_WITH_SWAP and tree==BOTHTREES) */
1579  inear=NearestNeighbour(q_rand,rrt->treeS2G);
1580 
1581  return(inear);
1582  }
1583  else
1584  #endif
1585 
1586  #if (_KDTREE==2)
1587  if ((rrt->mode!=TWO_TREES_WITH_SWAP)||(tree==BOTHTREES))
1588  {
1589  double d;
1590  signed int inear;
1591 
1592  if (rrt->mode==TWO_TREES)
1593  {
1594  if (tree==START2GOAL)
1595  {
1596  QueryKDTree(q_rand,&inear,&d,rrt->treeS2G);
1597  inear=rrt->t1ToId[inear];
1598  }
1599  else
1600  {
1601  if (tree==GOAL2START)
1602  {
1603  QueryKDTree(q_rand,&inear,&d,rrt->treeG2S);
1604  inear=rrt->t2ToId[inear];
1605  }
1606  else
1607  {
1608  /* NN in any of the two trees */
1609  double d1,d2;
1610  signed int inear1,inear2;
1611 
1612  QueryKDTree(q_rand,&inear1,&d1,rrt->treeG2S);
1613  QueryKDTree(q_rand,&inear2,&d2,rrt->treeS2G);
1614 
1615  if (d1<d2)
1616  inear=rrt->t1ToId[inear1];
1617  else
1618  inear=rrt->t2ToId[inear2];
1619  }
1620  }
1621  }
1622  else
1623  /* rrt->mode==ONE_TREE or (rrt->mode==TWO_TREES_WITH_SWAP and tree==BOTHTREES) */
1624  QueryKDTree(q_rand,&inear,&d,rrt->treeS2G);
1625 
1626  return((unsigned int)inear);
1627  }
1628  else
1629  #endif
1630  {
1631  unsigned int j,inear;
1632  double d,d1;
1633 
1634  /* _KDTREE==0 or (BOTH_TREES_WITH_SWAP and tree!=BOTH_TREES) */
1635  d=INF;
1636  inear=NO_UINT;
1637  for(j=0;j<rrt->ns;j++)
1638  {
1639  if ((rrt->mode==ONE_TREE)||(rrt->si[j]->tree&tree))
1640  {
1641  d1=DistanceTopologyMin(d,rrt->m,rrt->tp,q_rand,rrt->si[j]->samples);
1642  if (d1<d)
1643  {
1644  d=d1;
1645  inear=j;
1646  }
1647  }
1648  }
1649  return(inear);
1650  }
1651 }
1652 
1653 void GetRRTNNInBall(unsigned int tree,double *q_rand,double r,
1654  unsigned int *nn,unsigned int **n,Trrt *rrt)
1655 {
1656  #if (_KDTREE==1)
1657  if ((rrt->mode!=TWO_TREES_WITH_SWAP)||(tree==BOTHTREES))
1658  {
1659  if (rrt->mode==TWO_TREES)
1660  {
1661  if (tree==START2GOAL)
1662  NeighboursInBall(q_rand,r,nn,n,rrt->treeS2G);
1663  else
1664  {
1665  if (tree==GOAL2START)
1666  NeighboursInBall(q_rand,r,nn,n,rrt->treeG2S);
1667  else
1668  {
1669  unsigned int i;
1670  unsigned int nn1,nn2;
1671  unsigned int *n1,*n2;
1672 
1673  NeighboursInBall(q_rand,r,&nn1,&n1,rrt->treeS2G);
1674  NeighboursInBall(q_rand,r,&nn2,&n2,rrt->treeG2S);
1675 
1676  *nn=nn1+nn2;
1677  NEW(*n,*nn,unsigned int);
1678  for(i=0;i<nn1;i++)
1679  (*n)[i]=n1[i];
1680 
1681  for(i=0;i<nn2;i++)
1682  (*n)[nn1+i]=n2[i];
1683  }
1684  }
1685  }
1686  else
1687  /* rrt->mode==ONE_TREE or (rrt->mode==TWO_TREES_WITH_SWAP and tree==BOTHTREES) */
1688  NeighboursInBall(q_rand,r,nn,n,rrt->treeS2G);
1689  }
1690  else
1691  #endif
1692  #if (_KDTREE==2)
1693  if ((rrt->mode!=TWO_TREES_WITH_SWAP)||(tree==BOTHTREES))
1694  {
1695  double *dst;
1696 
1697  if (rrt->mode==TWO_TREES)
1698  {
1699  unsigned int i;
1700 
1701  if (tree==START2GOAL)
1702  {
1703  QueryKDTreeR(q_rand,r,(int *)(nn),(int **)(n),&dst,rrt->treeS2G);
1704  free(dst);
1705 
1706  for(i=0;i<*nn;i++)
1707  (*n)[i]=rrt->t1ToId[(*n)[i]];
1708  }
1709  else
1710  {
1711  if (tree==GOAL2START)
1712  {
1713  QueryKDTreeR(q_rand,r,(int *)(nn),(int **)(n),&dst,rrt->treeG2S);
1714  free(dst);
1715 
1716  for(i=0;i<*nn;i++)
1717  (*n)[i]=rrt->t2ToId[(*n)[i]];
1718  }
1719  else
1720  {
1721  /* Both trees */
1722  unsigned int nn1,nn2;
1723  unsigned int *n1,*n2;
1724 
1725  QueryKDTreeR(q_rand,r,(int *)(&nn1),(int **)(&n1),&dst,rrt->treeS2G);
1726  free(dst);
1727  QueryKDTreeR(q_rand,r,(int *)(&nn2),(int **)(&n2),&dst,rrt->treeG2S);
1728  free(dst);
1729 
1730  *nn=nn1+nn2;
1731  NEW(*n,*nn,unsigned int);
1732  for(i=0;i<nn1;i++)
1733  (*n)[i]=rrt->t1ToId[n1[i]];
1734 
1735  for(i=0;i<nn2;i++)
1736  (*n)[nn1+i]=rrt->t2ToId[n2[i]];
1737  }
1738  }
1739  }
1740  else
1741  {
1742  /* rrt->mode==ONE_TREE or (rrt->mode==TWO_TREES_WITH_SWAP and tree==BOTHTREES) */
1743  QueryKDTreeR(q_rand,r,(int *)(nn),(int **)(n),&dst,rrt->treeS2G);
1744  free(dst);
1745  }
1746  }
1747  else
1748  #endif
1749  {
1750  unsigned int m,j;
1751  double d1;
1752 
1753  /* _KDTREE==0 or BOTH_TREES_WITH_SWAP and tree!=BOTH_TREES */
1754  m=10;
1755  *nn=0;
1756  NEW(*n,m,unsigned int);
1757  for(j=0;j<rrt->ns;j++)
1758  {
1759  if ((rrt->mode==ONE_TREE)||(rrt->si[j]->tree&tree))
1760  {
1761  d1=DistanceTopologyMin(r,rrt->m,rrt->tp,q_rand,rrt->si[j]->samples);
1762  if (d1<r)
1763  {
1764  if (*nn==m)
1765  MEM_DUP(*n,m,unsigned int);
1766  (*n)[*nn]=j;
1767  (*nn)++;
1768  }
1769  }
1770  }
1771  }
1772 }
1773 
1774 void GetRRTNNInBranch(unsigned int tree,
1775  unsigned int n1,unsigned int n2,
1776  unsigned int *n,unsigned int *nn,
1777  Trrt *rrt)
1778 {
1779  double md,cd;
1780  unsigned int cn;
1781  int cnn;
1782  boolean done;
1783 
1784  /* Conceptually this operation is used only in bi-directional trees (altough in practice
1785  it could be implemented in single-trees too */
1786  if (rrt->mode==ONE_TREE)
1787  Error("GetRRTNNInBranch is only defined for bidirectional RRTs");
1788 
1789  if (rrt->si[n1]->tree!=rrt->si[n2]->tree)
1790  Error("The two nodes defining the branch in GetRRTNNInBranch are not in the same tree");
1791 
1792  if (tree==rrt->si[n1]->tree)
1793  Error("Parameter missmatch in GetRRTNNInBranch (the branch is in the query tree)");
1794 
1795  if (tree==BOTHTREES)
1796  Error("Can not query both trees in GetRRTNNInBranch");
1797 
1798  cn=n2;
1799  md=INF;
1800  *n=NO_UINT;
1801  *nn=NO_UINT;
1802  done=FALSE;
1803  do {
1804  #if (_KDTREE==1)
1805  if (rrt->mode!=TWO_TREES_WITH_SWAP)
1806  {
1807  if (tree==START2GOAL)
1808  cnn=NearestNeighbour(rrt->si[cn]->samples,rrt->treeS2G);
1809  else
1810  /* tree==GOAL2START */
1811  cnn=NearestNeighbour(rrt->si[cn]->samples,rrt->treeG2S);
1812  }
1813  else
1814  #endif
1815 
1816  #if (_KDTREE==2)
1817  if (rrt->mode!=TWO_TREES_WITH_SWAP)
1818  {
1819  if (tree==START2GOAL)
1820  {
1821  QueryKDTree(rrt->si[cn]->samples,&cnn,&cd,rrt->treeS2G);
1822  cnn=rrt->t1ToId[cnn];
1823  }
1824  else
1825  {
1826  /* tree==GOAL2START */
1827  QueryKDTree(rrt->si[cn]->samples,&cnn,&cd,rrt->treeG2S);
1828  cnn=rrt->t2ToId[cnn];
1829  }
1830  }
1831  else
1832  #endif
1833  {
1834  unsigned int j;
1835  double d1;
1836 
1837  cd=INF;
1838  cnn=NO_UINT;
1839  for(j=0;j<rrt->ns;j++)
1840  {
1841  if (rrt->si[j]->tree==tree)
1842  {
1843  d1=DistanceTopologyMin(md,rrt->m,rrt->tp,rrt->si[cn]->samples,rrt->si[j]->samples);
1844  if (d1<cd)
1845  {
1846  cd=d1;
1847  cnn=j;
1848  }
1849  }
1850  }
1851  }
1852 
1853  if (cd<md)
1854  {
1855  md=cd;
1856  *n=cn;
1857  *nn=cnn;
1858  }
1859  done=(cn==n1);
1860  if (!done)
1861  cn=rrt->si[cn]->parent;
1862  } while((!done)||(cn==NO_UINT));
1863 
1864  if (cn==NO_UINT)
1865  Error("Wrongly delimited branch in GetRRTNNInBranch");
1866 }
1867 
1868 boolean AddNodeToRRT(Tparameters *pr,unsigned int tree,
1869  unsigned int i_near,double *sample,
1870  double *goal,unsigned int *lastSample,
1871  void *info,double costp,double cost,
1872  TRRTStatistics *rst,Trrt *rrt)
1873 {
1874  TRRTSampleInfo *si;
1875 
1876  #if (GET_RRT_STATISTICS)
1877  if (rst!=NULL)
1878  NewRRTSample(rst);
1879  #endif
1880 
1881  if (tree==BOTHTREES)
1882  Error("Samples must be assigned to a single tree in AddNodeToRRT");
1883 
1884  if (rrt->ns==rrt->ms)
1885  MEM_DUP(rrt->si,rrt->ms,TRRTSampleInfo *);
1886 
1887  NEW(rrt->si[rrt->ns],1,TRRTSampleInfo);
1888  si=rrt->si[rrt->ns];
1889 
1890  NEW(si->samples,rrt->m,double);
1891  memcpy(si->samples,sample,rrt->m*sizeof(double));
1892  if (rrt->tp!=NULL)
1893  ArrayPi2Pi(rrt->m,rrt->tp,si->samples);
1894 
1895  si->parent=i_near;
1896  si->userInfo=info;
1897  si->costp=costp;
1898  si->cost=cost;
1899 
1900  si->ddr=0.0; /* dynamic domain set to 0 -> infty. */
1901 
1902  /* the tree of the node can be different from that of its parent!!
1903  This can happen when loading a BiRRT* that is not fully updated
1904  (see \ref UpdateCostAndPath) */
1905  si->tree=tree;
1906 
1907  #if (_KDTREE==1)
1908  if (rrt->mode==TWO_TREES)
1909  {
1910  if (tree==START2GOAL)
1911  AddPoint2KDtree(si->samples,rrt->ns,&(rrt->treeS2G));
1912  else
1913  AddPoint2KDtree(si->samples,rrt->ns,&(rrt->treeG2S));
1914  }
1915  else
1916  AddPoint2KDtree(si->samples,rrt->ns,&(rrt->treeS2G));
1917  #endif
1918 
1919  #if (_KDTREE==2)
1920  if (rrt->mode==TWO_TREES)
1921  {
1922  if (tree==START2GOAL)
1923  {
1924  if (rrt->nodesT1==rrt->maxNodesT1)
1925  MEM_DUP(rrt->t1ToId,rrt->maxNodesT1,unsigned int);
1926  rrt->t1ToId[rrt->nodesT1]=rrt->ns;
1927  rrt->nodesT1++;
1928 
1929  AddPoint2KDTree(si->samples,rrt->treeS2G);
1930  }
1931  else
1932  {
1933  /* tree is GOAL2START */
1934  if (rrt->nodesT2==rrt->maxNodesT2)
1935  MEM_DUP(rrt->t2ToId,rrt->maxNodesT2,unsigned int);
1936  rrt->t2ToId[rrt->nodesT2]=rrt->ns;
1937  rrt->nodesT2++;
1938 
1939  AddPoint2KDTree(si->samples,rrt->treeG2S);
1940  }
1941  }
1942  else
1943  AddPoint2KDTree(si->samples,rrt->treeS2G);
1944  #endif
1945 
1946  *lastSample=rrt->ns;
1947  rrt->ns++;
1948 
1949  if (rrt->graph)
1950  {
1951  si->g=INF;
1952  si->m=10; /* initial space for 10 neighbours (extended when necessary) */
1953  si->nn=0;
1954  NEW(si->n,si->m,unsigned int);
1955  NEW(si->cn,si->m,double);
1956  AddEdgeToRRT(*lastSample,i_near,costp,rrt);
1957  }
1958 
1959  #if (_DEBUG>1)
1960  fprintf(stderr," New sample %u dp:%f\n",rrt->ns,
1961  DistanceTopology(rrt->m,rrt->tp,rrt->si[i_near]->samples,sample));
1962  #endif
1963 
1964  if (goal!=NULL)
1965  return(DistanceTopology(rrt->m,rrt->tp,sample,goal)<GetParameter(CT_EPSILON,pr));
1966  else
1967  return(FALSE);
1968 }
1969 
1970 unsigned int AddStepToRRTstar(Tparameters *pr,unsigned int i_near,
1971  double *q_rand,double *goal,
1972  unsigned int *i_goal,
1973  TRRTStatistics *rst,Trrt *rrt)
1974 {
1975  double *q_next,d;
1976  unsigned int i_next;
1977  boolean goalFound,collision,reached;
1978  unsigned int tree;
1979 
1980  NEW(q_next,rrt->m,double);
1981 
1982  d=ConnectSamples(pr,rrt->tp,NULL,rrt->ambient,
1983  rrt->m,rrt->n,rrt->si[i_near]->samples,q_rand,(double)INF,
1984  TRUE,NULL,&reached,&collision,q_next,NULL,NULL,rrt->w);
1985 
1986  if (rrt->dd>0)
1987  AdjustDynamicDomain(i_near,collision,rrt);
1988 
1989  i_next=NO_UINT;
1990 
1991  tree=rrt->si[i_near]->tree; /* the sample is assigned to the tree of the nearest-node */
1992 
1993  if (d>0)
1994  {
1995  goalFound=AddNodeToRRT(pr,tree,i_near,q_next,goal,&i_next,NULL,
1996  d,rrt->si[i_near]->cost+d,rst,rrt);
1997 
1998  if ((goal!=NULL)&&(i_goal!=NULL)&&(goalFound)&&(*i_goal==NO_UINT))
1999  {
2000  /* The first time we are close enough to the goal we add the goal as a
2001  node in the RRT */
2002  double d,epsilon;
2003 
2004  epsilon=GetParameter(CT_EPSILON,pr);
2005  d=DistanceTopology(rrt->m,rrt->tp,q_next,goal);
2006 
2007  if (d<epsilon)
2008  *i_goal=i_next;
2009  else
2010  AddNodeToRRT(pr,tree,i_next,goal,goal,i_goal,NULL,d,
2011  rrt->si[i_next]->cost+d,rst,rrt);
2012  #if (RRT_VERBOSE)
2013  fprintf(stderr," {%u->%u}[%g] **\n",*i_goal,rrt->si[*i_goal]->parent,
2014  rrt->si[*i_goal]->costp);
2015  #endif
2016  }
2017  }
2018  free(q_next);
2019 
2020  return(i_next);
2021 }
2022 
2023 void WireRRTstar(Tparameters *pr,unsigned int id_new,unsigned int i_near,
2024  double gamma,unsigned int nn,unsigned int *n,double **c,
2025  double h,Theap *q,unsigned int *t,
2026  TRRTStatistics *rst,Trrt *rrt)
2027 {
2028  unsigned int i;
2029  double ic,cn,c_new,epsilon,*q_new;
2030  boolean *reached;
2031  TRRTSampleInfo *sNew;
2032  TDoublePair pair;
2033  double *cost;
2034 
2035  epsilon=GetParameter(CT_EPSILON,pr);
2036 
2037  /*******************************************************************/
2038  /* Search for the lowest cost path to the new node */
2039  #if (RRT_VERBOSE)
2040  fprintf(stderr," Wire %u [nn:%u g:%g]\n",id_new,nn,gamma);
2041  #endif
2042  #if (RRTSTAR_SYMMETRIC_COST)
2043  if (!rrt->graph)
2044  NEW(*c,nn,double);
2045  #endif
2046  sNew=rrt->si[id_new];
2047  ic=sNew->costp; /*cost to i_near*/
2048  q_new=sNew->samples;
2049  *t=0; /* initially no tree in the set of neighbours */
2050 
2051  NEW(reached,nn,boolean);
2052  NEW(cost,nn,double);
2053 
2054  #pragma omp parallel for private(i) schedule(dynamic) if (rrt->parallel)
2055  for(i=0;i<nn;i++)
2056  {
2057  /* do not consider connection to itself */
2058  if (n[i]==id_new)
2059  reached[i]=FALSE;
2060  else
2061  {
2062  if (n[i]==i_near)
2063  {
2064  /* we already know the connection to i_near */
2065  cost[i]=ic;
2066  reached[i]=TRUE;
2067  }
2068  else
2069  {
2070  boolean collision;
2071 
2072  /* compute the connection to other samples */
2073  cost[i]=ConnectSamples(pr,rrt->tp,NULL,rrt->ambient,
2074  rrt->m,rrt->n,rrt->si[n[i]]->samples,q_new,gamma,
2075  TRUE,NULL,&(reached[i]),&collision,NULL,NULL,NULL,rrt->w);
2076  }
2077  }
2078  }
2079 
2080  for(i=0;i<nn;i++)
2081  {
2082  if (n[i]!=id_new)
2083  {
2084  #if (GET_RRT_STATISTICS)
2085  NewRRTBranch(rst);
2086  #endif
2087  (*t)|=rrt->si[n[i]]->tree; /* take note of the tree of this neighbour (even if not reached)*/
2088  }
2089 
2090  if (reached[i])
2091  {
2092  cn=cost[i];
2093 
2094  /* Ensure that cost and tree are correct before using this node */
2095  /* This might be unnecessary when in graph mode (but it's cheap) */
2096  #if (GET_RRT_STATISTICS)
2097  NewRRTNoEmptyBranch(rst);
2098  #endif
2099 
2100  #if (!RRTSTAR_UPDATE_COSTS)
2101  if (rrt->mode==TWO_TREES_WITH_SWAP)
2102  #endif
2103  UpdateCostAndTree(n[i],rrt);
2104 
2105  /* Add a bidirectional edge with the given cost. */
2106  if (rrt->graph)
2107  AddEdgeToRRT(id_new,n[i],cn,rrt);
2108 
2109  c_new=rrt->si[n[i]]->cost+cn;
2110  if (c_new<(sNew->cost-epsilon))
2111  {
2112  #if (RRT_VERBOSE)
2113  fprintf(stderr," {%u->%u}[%g] ->",id_new,sNew->parent,sNew->costp);
2114  #endif
2115 
2116  SetRRTCostAndParent(id_new,n[i],cn,c_new,rrt);
2117 
2118  #if (RRT_VERBOSE)
2119  fprintf(stderr,"{%u->%u}[%g]\n",id_new,sNew->parent,sNew->costp);
2120  #endif
2121  }
2122  }
2123  else
2124  cn=INF;
2125 
2126  #if (RRTSTAR_SYMMETRIC_COST)
2127  if (!rrt->graph) /* if graph, the cost are already stored in the graph edges. */
2128  (*c)[i]=cn;
2129  #endif
2130  }
2131  free(reached);
2132  free(cost);
2133 
2134  if (rrt->graph)
2135  {
2136  if (!q)
2137  Error("RRT must be in graph mode to use a heap");
2138  c_new=rrt->si[id_new]->cost;
2139  NewDoublePair(c_new+h,c_new,&pair);
2140  AddElement2Heap(id_new,(void *)&pair,q);
2141  }
2142 }
2143 
2145  Tvector *steps,double *l,
2146  Trrt *rrt)
2147 {
2148  unsigned int id_new,i;
2149  double c_new,epsilon,ct;
2150  TRRTSampleInfo *sNew,*sNear;
2151  TDoublePair pair;
2152 
2153  if (!rrt->graph)
2154  Error("RecursiveReWireRRTstar can only be used if RRT in graph mode");
2155 
2156  epsilon=GetParameter(CT_EPSILON,pr);
2157 
2158  #if (RRT_VERBOSE)
2159  fprintf(stderr," Rewire\n");
2160  #endif
2161  while ((!HeapEmpty(q))&&(FirstInPair((TDoublePair *)GetHeapElement(0,q))<=(*l)))
2162  {
2163  id_new=ExtractMinElement(&pair,q);
2164  if (id_new==NO_UINT)
2165  Error("Reading an inconsistent node from the priority queue in RecursiveReWireRRTstar");
2166 
2167  sNew=rrt->si[id_new];
2168  sNew->g=sNew->cost; /* convert the node to stationary */
2169 
2170  for(i=0;i<sNew->nn;i++)
2171  {
2172  sNear=rrt->si[sNew->n[i]];
2173 
2174  /* ensure that cost and tree are correct before using this node. This is already updated
2175  in the wire but might change during the re-wire */
2176  if (rrt->mode==TWO_TREES_WITH_SWAP)
2177  UpdateCostAndTree(sNew->n[i],rrt);
2178 
2179  /* cost to n[i] via id_new */
2180  c_new=sNew->cost+sNew->cn[i];
2181  if (c_new<(sNear->cost-epsilon)) /* recall that here, cost = rhs */
2182  {
2183  #if (RRT_VERBOSE)
2184  fprintf(stderr," {%u->%u}[%g %g] ->",sNew->n[i],sNear->parent,sNear->costp,sNear->cost);
2185  #endif
2186 
2187  /* sets 'rhs' (cost) but not 'g' -> inconsistent node */
2188  SetRRTCostAndParent(sNew->n[i],id_new,sNew->cn[i],c_new,rrt);
2189 
2190  ct=sNear->cost+DistanceTopology(rrt->m,rrt->tp,sNear->samples,g);
2191  NewDoublePair(ct,sNear->cost,&pair);
2192  UpdateHeapElement(sNew->n[i],(void *)&pair,q); /* updates/adds */
2193 
2194  #if (RRT_VERBOSE)
2195  fprintf(stderr,"{%u->%u}[%g %g]\n",sNew->n[i],sNear->parent,sNear->costp,sNear->cost);
2196  #endif
2197  }
2198  else
2199  {
2200  /* if the node is connected to a sample in a different tree, update the optimal path */
2201  if ((rrt->mode==TWO_TREES_WITH_SWAP)&&(steps!=NULL)&&(sNear->tree!=sNew->tree))
2202  {
2203  c_new+=sNear->cost; /* Total cost of start<->goal via this connection between trees.*/
2204  if (c_new<*l)
2205  *l=ChangeBiRRTSteps(sNew->n[i],id_new,sNew->cn[i],steps,rrt);
2206  }
2207  }
2208  }
2209  }
2210 }
2211 
2213  unsigned int id_new,double gamma,
2214  unsigned int nn,unsigned int *n,double *c,
2215  Tvector *steps,double *l,
2216  Trrt *rrt)
2217 {
2218  unsigned int i,parent;
2219  boolean reached;
2220  double cn,c_new,epsilon;
2221  TRRTSampleInfo *sNew,*sNear;
2222  #if (!RRTSTAR_SYMMETRIC_COST)
2223  double *q_new;
2224  boolean collision;
2225  #endif
2226 
2227  if (rrt->graph)
2228  Error("ReWireRRTstar must not be used if the RRT is in graph mode");
2229 
2230  epsilon=GetParameter(CT_EPSILON,pr);
2231 
2232  #if (RRT_VERBOSE)
2233  fprintf(stderr," Rewire\n");
2234  #endif
2235  sNew=rrt->si[id_new];
2236  #if (!RRTSTAR_SYMMETRIC_COST)
2237  /* if symmetric costs -> cost to neighbours given as parameters */
2238  q_new=sNew->samples;
2239  #endif
2240  parent=sNew->parent;
2241  for(i=0;i<nn;i++)
2242  {
2243  sNear=rrt->si[n[i]];
2244 
2245  /* There is no need to re-wire the best parent of the new node
2246  (it will produce an inf. loop) or the new node itself. */
2247  if ((n[i]==id_new)||(n[i]==parent))
2248  reached=FALSE;
2249  else
2250  {
2251  #if (RRTSTAR_SYMMETRIC_COST)
2252  cn=c[i];
2253  reached=(cn<INF);
2254  #else
2255  cn=ConnectSamples(pr,rrt->tp,NULL,rrt->ambient,
2256  rrt->m,rrt->n,q_new,sNear->samples,gamma,
2257  TRUE,NULL,&reached,&collision,NULL,NULL,NULL,rrt->w);
2258  #endif
2259  }
2260 
2261  if (reached)
2262  {
2263  /* Ensure that any previous-rewire is propagated to the currently tested node */
2264  if (rrt->mode==TWO_TREES_WITH_SWAP)
2265  UpdateCostAndTree(n[i],rrt);
2266 
2267  c_new=sNew->cost+cn;
2268  if (c_new<sNear->cost-epsilon)
2269  {
2270  #if (RRT_VERBOSE)
2271  fprintf(stderr," {%u->%u}[%g] ->",n[i],sNear->parent,sNear->costp);
2272  #endif
2273 
2274  SetRRTCostAndParent(n[i],id_new,cn,c_new,rrt);
2275 
2276  #if (RRT_VERBOSE)
2277  fprintf(stderr,"{%u->%u}[%g]\n",n[i],sNear->parent,sNear->costp);
2278  #endif
2279  }
2280  else
2281  {
2282  /* if the node is connected to a sample in a different tree, update the optimal path */
2283  if ((rrt->mode==TWO_TREES_WITH_SWAP)&&(steps!=NULL)&&(l!=NULL)&&(sNear->tree!=sNew->tree))
2284  {
2285  c_new+=sNear->cost; /* Total cost of start<->goal via this connection between trees.*/
2286  if (c_new<*l)
2287  *l=ChangeBiRRTSteps(n[i],id_new,cn,steps,rrt);
2288  }
2289  }
2290  }
2291  }
2292 }
2293 
2294 void RRTstarCloseIteration(unsigned int it,unsigned int id_goal,
2295  double time,double gamma,
2296  double *times,double *costs,
2297  Trrt *rrt)
2298 {
2299  if ((RRT_VERBOSE)||((it%1000)==0))
2300  {
2301  if (id_goal!=NO_UINT)
2302  {
2303  fprintf(stderr,"Iteration: %u (s:%u t:%g g:%g c:%g [%g])\n",it,rrt->ns,time,gamma,
2304  rrt->si[id_goal]->cost,CostToRoot(id_goal,rrt));
2305  }
2306  else
2307  fprintf(stderr,"Iteration: %u (s:%u t:%g)\n",it,rrt->ns,time);
2308  fflush(stdout);
2309  }
2310 
2311  if (times!=NULL)
2312  times[it]=time;
2313 
2314  if (costs!=NULL)
2315  {
2316  if (id_goal==NO_UINT)
2317  costs[it]=-1.0;
2318  else
2319  costs[it]=rrt->si[id_goal]->cost; //CostToRoot(id_goal,rrt);
2320  }
2321 }
2322 
2323 void BiRRTstarCloseIteration(unsigned int it,double l,
2324  double time,double gamma,
2325  double *times,double *costs,
2326  Trrt *rrt)
2327 {
2328  if ((RRT_VERBOSE)||((it%1000)==0))
2329  {
2330  if (l<INF)
2331  {
2332  fprintf(stderr,"Iteration: %u (s:%u t:%g g:%g c:%g)\n",it,rrt->ns,time,gamma,l);
2333  }
2334  else
2335  fprintf(stderr,"Iteration: %u (s:%u t:%g)\n",it,rrt->ns,time);
2336  fflush(stdout);
2337  }
2338 
2339  if (times!=NULL)
2340  times[it]=time;
2341 
2342  if (costs!=NULL)
2343  {
2344  if (l<INF)
2345  costs[it]=-1.0;
2346  else
2347  costs[it]=l;
2348  }
2349 }
2350 
2351 boolean RRTstar(Tparameters *pr,double *pg,
2352  unsigned int *it,double *times,double *costs,
2353  double *planningTime,double *pl,unsigned int *ns,double ***path,
2354  TRRTStatistics *grst,Trrt *rrt)
2355 {
2356  if (EXPLORATION_RRT)
2357  Error("RRTstar is not designed for exploration RRTs");
2358 
2359  if (rrt->mode!=ONE_TREE)
2360  return(BiRRTstar(pr,pg,it,times,costs,planningTime,pl,ns,path,grst,rrt));
2361  else
2362  {
2363  double *pWithDummies,*pgs,*q_rand;
2364  unsigned int samplingMode;
2365  unsigned int i_near;
2366  double epsilon;
2367  boolean expand2Goal;
2368  double er;
2369  Tstatistics st; /* used just to measure execution time */
2370  boolean collision;
2371  double time;
2372  double *c; /* if the cost function is symmetrical, we cache
2373  the evaluation of the cost to neighbour. */
2374  /* neighbours for each new node */
2375  unsigned int nn;
2376  unsigned int *n;
2377  /* distance q_rand,tree */
2378  double gamma,ct_gamma;
2379  unsigned int i,id_new,id_goal;
2380  double *q_new;
2381  boolean done,optimal,validSample;
2382  double maxTime;
2383  unsigned int maxIterations;
2384  double h,l;
2385  Theap q;
2386  unsigned int vt; /* trees in set of neighbours, only relevant in bi-RRTs */
2387  unsigned int numSamples;
2388  TRRTStatistics *rst;
2389 
2390  if (rrt->ns>1)
2391  Error("RRTstart must be used to a just initilized RRT");
2392 
2393  #if (GET_RRT_STATISTICS)
2394  {
2395  unsigned int i;
2396 
2397  NEW(rst,1,TRRTStatistics);
2398  InitRRTStatistics(rst);
2399 
2400  for(i=0;i<rrt->ns;i++)
2401  NewRRTSample(rst);
2402  }
2403  #endif
2404 
2405  /* Init the RRT structure */
2406  epsilon=GetParameter(CT_EPSILON,pr);
2407  ct_gamma=GetParameter(CT_GAMMA,pr);
2408  maxTime=GetParameter(CT_MAX_PLANNING_TIME,pr);
2409  maxIterations=(unsigned int)GetParameter(CT_MAX_PLANNING_ITERATIONS,pr);
2410  samplingMode=(unsigned int)GetParameter(CT_SAMPLING,pr);
2411 
2412 
2413  CS_WD_REGENERATE_SOLUTION_POINT(pr,pg,&pWithDummies,rrt->w);
2414  CS_WD_GENERATE_SIMPLIFIED_POINT(pr,pWithDummies,&pgs,rrt->w);
2415 
2416  if ((!PointInBoxTopology(NULL,TRUE,rrt->m,pgs,epsilon,rrt->tp,rrt->ambient))||
2417  (!CS_WD_SIMP_INEQUALITIES_HOLD(pr,pgs,rrt->w)))
2418  Error("The targed point for the RRTstar is not in domain");
2419 
2420  if (rrt->n==0)
2421  er=0;
2422  else
2423  er=CS_WD_ERROR_IN_SIMP_EQUATIONS(pr,pgs,rrt->w);
2424  if (er>epsilon)
2425  Error("The target point for the RRTstar is not on the manifold");
2426 
2427  collision=CS_WD_ORIGINAL_IN_COLLISION(pr,pWithDummies,NULL,rrt->w);
2428  if (collision)
2429  Error("The target point for the RRTstar is in collision");
2430  free(pWithDummies);
2431 
2432  /* Room for the randomly generated samples (and its correspoinding point
2433  on the manifold) */
2434  NEW(q_rand,rrt->m,double);
2435 
2436  /* Reset the output statistics (just in case maxIterations
2437  is not reached) */
2438  for(i=0;i<maxIterations;i++)
2439  {
2440  times[i]=0;
2441  costs[i]=-1;
2442  }
2443 
2444  if (rrt->graph)
2446  LessThanDoublePair,NULL,TRUE,rrt->ms,&q);
2447 
2448  gamma=ct_gamma;
2449  optimal=(gamma>0.0);
2450 
2451  id_goal=NO_UINT;
2452  *it=0;
2453 
2454  InitStatistics(rrt->nCores,0,&st);
2455  time=0.0;
2456  done=FALSE;
2457  l=INF; /* cost to goal (INF while goal not found) */
2458  c=NULL; /* default -> no cache of costs to neighbours */
2459 
2460  while ((!done)&&(time<maxTime)&&(*it<maxIterations))
2461  {
2462  #if (HEURISTIC_RRT_STAR&(1))
2463  /* keep the cost to goal up to date so that the heuristic
2464  is more effective*/
2465  if (id_goal!=NO_UINT)
2466  UpdateCostAndTree(id_goal,rrt);
2467  #endif
2468  /*******************************************************************/
2469  /* best estimation of the cost to goal (up to now) */
2470  if (id_goal==NO_UINT)
2471  l=INF;
2472  else
2473  l=rrt->si[id_goal]->cost;
2474 
2475  /*******************************************************************/
2476  /* Random sample */
2477  do {
2478  /* Generate a random sample */
2479  expand2Goal=RRTSample(samplingMode,START2GOAL,(id_goal==NO_UINT?pgs:NULL),
2480  q_rand,rst,rrt);
2481 
2482  /* Check if the sample is valid */
2483  validSample=RRTValidateSample(pr,q_rand,START2GOAL,expand2Goal,pgs,l,
2484  &h,&i_near,rst,rrt);
2485  time=GetElapsedTime(&st);
2486  } while((!validSample)&&(time<maxTime));
2487 
2488  if (time<maxTime)
2489  {
2490  /*******************************************************************/
2491  /* Extend the RRT from q_near to q_rand using the cbiRRT extend method */
2492  /* Note that here we try to reach q_rand but we do not add samples along the path */
2493  id_new=AddStepToRRTstar(pr,i_near,q_rand,pgs,&id_goal,rst,rrt);
2494 
2495  /*******************************************************************/
2496  if (!optimal)
2497  {
2498  if (id_goal!=NO_UINT)
2499  done=TRUE;
2500  }
2501  else
2502  {
2503  /* If we actually added something */
2504  if ((id_new!=NO_UINT)&&((((HEURISTIC_RRT_STAR)&(2))==0)||(id_goal!=NO_UINT)))
2505  {
2506  /* q_new is the last sample added to the tree */
2507  q_new=rrt->si[id_new]->samples;
2508  h=DistanceTopology(rrt->m,rrt->tp,q_new,pgs);
2509 
2510  /*******************************************************************/
2511  /* Search for the set of potential neighbours */
2512  numSamples=(rrt->ns<3?3:rrt->ns);
2513  gamma=ct_gamma*pow(log(numSamples)/numSamples,1/(double)rrt->k);
2514  gamma=(gamma<rrt->delta?rrt->delta:gamma);
2515 
2516  GetRRTNNInBall(START2GOAL,q_new,gamma,&nn,&n,rrt);
2517 
2518  /*******************************************************************/
2519  /* Wire: Search for the lowest cost path to the new node */
2520  WireRRTstar(pr,id_new,i_near,gamma,nn,n,&c,h,(rrt->graph?&q:NULL),&vt,rst,rrt);
2521 
2522  /*******************************************************************/
2523  /* Rewire the tree around the new point */
2524  if (rrt->graph)
2525  RecursiveReWireRRTstar(pr,&q,pgs,NULL,&l,rrt);
2526  else
2527  ReWireRRTstar(pr,id_new,gamma,nn,n,c,NULL,&l,rrt);
2528 
2529  /*******************************************************************/
2530  /* release the data (cost (if actually used) and neighbours) */
2531  if (c!=NULL)
2532  free(c);
2533  free(n);
2534  }
2535  #if (RRT_VERBOSE)
2536  else
2537  {
2538  if (id_new==NO_UINT)
2539  fprintf(stderr," Blocked [%u]\n",i_near);
2540  }
2541  #endif
2542  }
2543 
2544  /*******************************************************************/
2545  /* Conclude the iteration */
2546  time=GetElapsedTime(&st);
2547 
2548  RRTstarCloseIteration(*it,id_goal,time,gamma,times,costs,rrt);
2549 
2550  (*it)++;
2551  }
2552  }
2553 
2554  DeleteStatistics(&st);
2555  #if (GET_RRT_STATISTICS)
2556  if (grst==NULL)
2557  PrintRRTStatistics(rrt,rst);
2558  else
2559  AccumulateRRTStatistics(rst,grst);
2560  DeleteRRTStatistics(rst);
2561  free(rst);
2562  #endif
2563 
2564  if (rrt->graph)
2565  DeleteHeap(&q);
2566 
2567  *planningTime=GetElapsedTime(&st);
2568 
2569  fprintf(stderr,"Final number of samples: %u\n",rrt->ns);
2570 
2571  /* Reconstruct the path (if any) */
2572  if (id_goal!=NO_UINT)
2573  ReconstructRRTPath(pr,id_goal,pl,NULL,ns,path,rrt);
2574 
2575  /* Release memory */
2576  free(q_rand);
2577  free(pgs);
2578 
2579  return(id_goal!=NO_UINT);
2580  }
2581 }
2582 
2583 boolean BiRRTstar(Tparameters *pr,double *pg,
2584  unsigned int *it,double *times,double *costs,
2585  double *planningTime,double *pl,unsigned int *ns,double ***path,
2586  TRRTStatistics *grst,Trrt *rrt)
2587 {
2588  if (EXPLORATION_RRT)
2589  Error("RRTstar is not designed for exploration RRTs");
2590 
2591  if (rrt->mode!=TWO_TREES_WITH_SWAP)
2592  {
2593  if (rrt->mode!=ONE_TREE)
2594  Error("RRTstar operates on two-directional RRTs");
2595 
2596  return(RRTstar(pr,pg,it,times,costs,planningTime,pl,ns,path,grst,rrt));
2597  }
2598  else
2599  {
2600  double *q_rand,*g;
2601  unsigned int i_near;
2602  Tstatistics st; /* used just to measure execution time */
2603  double time;
2604  double *c; /* if the cost function is symmetrical, we cache
2605  the evaluation of the cost to neighbour. */
2606  /* neighbours for each new node */
2607  unsigned int nn;
2608  unsigned int *n;
2609  /* distance q_rand,tree */
2610  double gamma,ct_gamma;
2611  unsigned int i,id_new;
2612  double *q_new;
2613  boolean done,optimal,validSample;
2614  double l; /* length of the shortest path so far */
2615  Tvector steps;
2616  double maxTime;
2617  unsigned int maxIterations,samplingMode;
2618  Theap q;
2619  double h;
2620  unsigned int vt; /* trees in the set of neighbours. */
2621  unsigned int numSamples;
2622  double l1,c12;
2623  boolean connected,collision;
2624  TRRTStatistics *rst;
2625 
2626  if (rrt->ns>2)
2627  Error("RRTstart must be used to a just initilized RRT");
2628 
2629  #if (GET_RRT_STATISTICS)
2630  {
2631  unsigned int i;
2632 
2633  NEW(rst,1,TRRTStatistics);
2634  InitRRTStatistics(rst);
2635 
2636  for(i=0;i<rrt->ns;i++)
2637  NewRRTSample(rst);
2638  }
2639  #endif
2640 
2641  /* Init the RRT structure */
2642  ct_gamma=GetParameter(CT_GAMMA,pr);
2643  maxTime=GetParameter(CT_MAX_PLANNING_TIME,pr);
2644  maxIterations=(unsigned int)GetParameter(CT_MAX_PLANNING_ITERATIONS,pr);
2645  /* for BiRRTStart the sampling mode should be "ambient_sampling" but we accept
2646  other modes just for the sake of completeness. */
2647  samplingMode=(unsigned int)GetParameter(CT_SAMPLING,pr);
2648 
2649  /* Room for the randomly generated samples (and its correspoinding point
2650  on the manifold) */
2651  NEW(q_rand,rrt->m,double);
2652 
2653  /* Reset the output statistics (just in case maxIterations
2654  is not reached) */
2655  for(i=0;i<maxIterations;i++)
2656  {
2657  times[i]=0;
2658  costs[i]=-1;
2659  }
2660 
2661  if (rrt->graph)
2663  LessThanDoublePair,NULL,TRUE,rrt->ms,&q);
2664 
2665  gamma=ct_gamma;
2666  optimal=(gamma>0.0);
2667 
2668  *it=0;
2669 
2670  InitStatistics(rrt->nCores,0,&st);
2671  time=0.0;
2672  done=FALSE;
2673 
2674  InitVector(sizeof(TRRTStep),CopyRRTStep,NULL,100,&steps);
2675  l=INF;
2676  c=NULL; /* default not to use cache of cost to neighbours */
2677 
2678  while ((!done)&&(time<maxTime)&&(*it<maxIterations))
2679  {
2680  /* Keep the current path up to date (if any) */
2681  if (l<INF)
2682  l=UpdateBiRRTSteps(&steps,rrt);
2683 
2684  /*******************************************************************/
2685  do {
2686  /* Generate a random sample */
2687  RRTSample(samplingMode,BOTHTREES,NULL,q_rand,rst,rrt);
2688 
2689  /* Check if the sample is valid */
2690  validSample=RRTValidateSample(pr,q_rand,BOTHTREES,FALSE,rrt->si[1]->samples,l,
2691  &h,&i_near,rst,rrt);
2692  time=GetElapsedTime(&st);
2693  } while((!validSample)&&(time<maxTime));
2694 
2695  if (time<maxTime)
2696  {
2697  /*******************************************************************/
2698  /* heuristic w.r.t distance from q_rand to goal */
2699  if (rrt->si[i_near]->tree==START2GOAL)
2700  g=rrt->si[1]->samples;
2701  else
2702  g=rrt->si[0]->samples;
2703  h=DistanceTopology(rrt->m,rrt->tp,q_rand,g);
2704 
2705  /*******************************************************************/
2706  /* Extend the RRT from q_near to q_rand using the cbiRRT extend method */
2707  /* Note that here we use a extend strategy (we only add one sample) */
2708 
2709  id_new=AddStepToRRTstar(pr,i_near,q_rand,NULL,NULL,rst,rrt);
2710 
2711  /* If we actually added something */
2712  if ((id_new!=NO_UINT)&&((((HEURISTIC_RRT_STAR)&(2))==0)||(l<INF)))
2713  {
2714  /* q_new is the last samples added to the tree */
2715  q_new=rrt->si[id_new]->samples;
2716  h=DistanceTopology(rrt->m,rrt->tp,q_new,g);
2717 
2718  /*******************************************************************/
2719  /* Search for the set of potential neighbours */
2720  numSamples=(rrt->ns<3?3:rrt->ns);
2721  gamma=ct_gamma*pow(log(numSamples)/numSamples,1/(double)rrt->k);
2722  gamma=(gamma<rrt->delta?rrt->delta:gamma);
2723 
2724  GetRRTNNInBall(BOTHTREES,q_new,gamma,&nn,&n,rrt);
2725 
2726  /*******************************************************************/
2727  /* Wire: Search for the lowest cost path to the new node */
2728  WireRRTstar(pr,id_new,i_near,gamma,nn,n,&c,h,(rrt->graph?&q:NULL),&vt,rst,rrt);
2729 
2730  /*******************************************************************/
2731  /* Rewire the tree around the new point */
2732  if (rrt->graph)
2733  RecursiveReWireRRTstar(pr,&q,g,&steps,&l,rrt);
2734  else
2735  ReWireRRTstar(pr,id_new,gamma,nn,n,c,&steps,&l,rrt);
2736 
2737  /*******************************************************************/
2738  /* release the data (cost (if actually used) and neighbours) */
2739  if (c!=NULL)
2740  free(c);
2741  free(n);
2742 
2743  /*******************************************************************/
2744  /* If the set of neighbours does not include nodes in the two trees
2745  and we do not have a path start<->goal we try to connect the two
2746  trees (this is hardly used since when l=INF, gamma is large and
2747  the neighbours always include nodes in the two trees) */
2748  //if ((vt!=BOTHTREES)&&(l==INF))
2749  if (vt!=BOTHTREES)
2750  {
2751  /* In the re-wire the current sample might end up in tree 't2'
2752  and the connection must be always with the other tree */
2753  if (rrt->si[id_new]->tree==START2GOAL)
2754  i_near=GetRRTNN(GOAL2START,q_new,rrt);
2755  else
2756  i_near=GetRRTNN(START2GOAL,q_new,rrt);
2757 
2758  l1=rrt->si[id_new]->cost+rrt->si[i_near]->cost;
2759  c12=ConnectSamples(pr,rrt->tp,NULL,rrt->ambient,
2760  rrt->m,rrt->n,q_new,rrt->si[i_near]->samples,l-l1,
2761  TRUE,NULL,&connected,&collision,NULL,NULL,NULL,rrt->w);
2762  if (connected)
2763  {
2764  if (rrt->graph)
2765  AddEdgeToRRT(id_new,i_near,c12,rrt);
2766  l1+=c12;
2767  if (l1<l)
2768  l=ChangeBiRRTSteps(id_new,i_near,c12,&steps,rrt);
2769  }
2770  }
2771  }
2772  #if (RRT_VERBOSE)
2773  else
2774  {
2775  if (id_new==NO_UINT)
2776  fprintf(stderr," Blocked [%u]\n",i_near);
2777  }
2778  #endif
2779 
2780  if (!optimal)
2781  done=(l<INF);
2782 
2783  /*******************************************************************/
2784  /* Conclude the iteration */
2785  time=GetElapsedTime(&st);
2786 
2787  BiRRTstarCloseIteration(*it,l,time,gamma,times,costs,rrt);
2788 
2789  (*it)++;
2790  }
2791  }
2792 
2793  DeleteStatistics(&st);
2794  #if (GET_RRT_STATISTICS)
2795  if (grst==NULL)
2796  PrintRRTStatistics(rrt,rst);
2797  else
2798  AccumulateRRTStatistics(rst,grst);
2799  DeleteRRTStatistics(rst);
2800  free(rst);
2801  #endif
2802 
2803  if (rrt->graph)
2804  DeleteHeap(&q);
2805 
2806  *planningTime=GetElapsedTime(&st);
2807 
2808  fprintf(stderr,"Final number of samples: %u\n",rrt->ns);
2809 
2810  /* Reconstruct the path (if any) */
2811  if (l<INF)
2812  Steps2PathinRRT(pr,&steps,pl,NULL,ns,path,rrt);
2813 
2814  /* Release memory */
2815  free(q_rand);
2816  DeleteVector(&steps);
2817 
2818  return(l<INF);
2819  }
2820 }
2821 
2822 boolean ccTRRT(Tparameters *pr,double *pg,double *time,
2823  double *pl, double* pc, unsigned int *ns,double ***path,
2824  double (*costF)(Tparameters*,boolean,double*,void*),
2825  void *costData,
2826  TRRTStatistics *grst,Trrt *rrt)
2827 {
2828  double *pWithDummies,*pgs,*q_rand;
2829  unsigned int it,i_near;
2830  double epsilon;
2831  boolean pathFound,done,expand2Goal;
2832  unsigned int lastSample;
2833  double er,h;
2834  Tstatistics st; /* used just to measure execution time */
2835  boolean collision;
2836  double maxTime;
2837  unsigned int maxNodes;
2838  unsigned int samplingMode;
2839  boolean validSample;
2840  TRRTStatistics *rst;
2841 
2842  if(rrt->ns >1)
2843  Error("ccTRRT should only be initialized with the start config");
2844 
2845  if (rrt->mode!=ONE_TREE)
2846  Error("ccTRRT operates on one-directional RRTs");
2847 
2848  #if (GET_RRT_STATISTICS)
2849  {
2850  unsigned int i;
2851 
2852  NEW(rst,1,TRRTStatistics);
2853  InitRRTStatistics(rst);
2854 
2855  for(i=0;i<rrt->ns;i++)
2856  NewRRTSample(rst);
2857  }
2858  #endif
2859 
2860  /* Init the RRT structure */
2861  epsilon=GetParameter(CT_EPSILON,pr);
2862  maxTime=GetParameter(CT_MAX_PLANNING_TIME,pr);
2863  maxNodes=(unsigned int)GetParameter(CT_MAX_NODES_RRT,pr);
2864  samplingMode=(unsigned int)GetParameter(CT_SAMPLING,pr);
2865 
2866  CS_WD_REGENERATE_SOLUTION_POINT(pr,pg,&pWithDummies,rrt->w);
2867  CS_WD_GENERATE_SIMPLIFIED_POINT(pr,pWithDummies,&pgs,rrt->w);
2868 
2869  if ((!PointInBoxTopology(NULL,TRUE,rrt->m,pgs,epsilon,rrt->tp,rrt->ambient))||
2870  (!CS_WD_SIMP_INEQUALITIES_HOLD(pr,pgs,rrt->w)))
2871  Error("The targed point for the ccRRT is not in domain");
2872 
2873  if (rrt->n==0)
2874  er=0;
2875  else
2876  er=CS_WD_ERROR_IN_SIMP_EQUATIONS(pr,pgs,rrt->w);
2877  if (er>epsilon)
2878  Error("The target point for the ccRRT is not on the manifold");
2879 
2880  collision=CS_WD_ORIGINAL_IN_COLLISION(pr,pWithDummies,NULL,rrt->w);
2881  if (collision)
2882  Warning("The target point for the ccRRT is in collision");
2883  free(pWithDummies);
2884 
2885  /*init the cost of the first node*/
2886  rrt->si[0]->cost=costF(pr,TRUE,GetRRTNode(0,rrt),costData);
2887 
2888  /* Room for the randomly generated samples (and its correspoinding point
2889  on the manifold) */
2890  NEW(q_rand,rrt->m,double);
2891 
2892  done=FALSE;
2893  it=0;
2894 
2895  InitStatistics(rrt->nCores,0,&st);
2896  *time=0.0;
2897 
2898  while ((!done)&&(*time<maxTime)&&(rrt->ns<maxNodes))
2899  {
2900  if ((RRT_VERBOSE)||((it%1000)==0))
2901  {
2902  fprintf(stderr,"Iteration: %u (s:%u t:%g)\n",it,rrt->ns,*time);
2903  fflush(stdout);
2904  }
2905 
2906  /*******************************************************************/
2907  /* Sample in ambient space (with bias toward goal) */
2908  do {
2909  /* Generate a random sample */
2910  expand2Goal=RRTSample(samplingMode,START2GOAL,(EXPLORATION_RRT?NULL:pgs),
2911  q_rand,rst,rrt);
2912 
2913  /* Check if the sample is valid */
2914  validSample=RRTValidateSample(pr,q_rand,START2GOAL,expand2Goal,NULL,INF,
2915  &h,&i_near,rst,rrt);
2916 
2917  *time=GetElapsedTime(&st);
2918  } while((!validSample)&&(*time<maxTime));
2919 
2920  if (*time<maxTime)
2921  {
2922  /*******************************************************************/
2923  /* Extend the RRT from q_near to q_rand using the ccRRT extend method */
2924 
2925  #if (GET_RRT_STATISTICS)
2926  NewRRTBranch(rst);
2927  NewRRTDistanceQrand(DistanceTopology(rrt->m,rrt->tp,rrt->si[i_near]->samples,q_rand),rst);
2928  #endif
2929  done=AddBranchToRRT(pr,TRUE,START2GOAL,i_near,q_rand,pgs,&lastSample,
2930  costF,costData,rst,rrt);
2931  #if (GET_RRT_STATISTICS)
2932  if (lastSample!=i_near)
2933  NewRRTNoEmptyBranch(rst);
2934  #endif
2935 
2936  *time=GetElapsedTime(&st);
2937  it++;
2938  }
2939  }
2940 
2941  fprintf(stderr,"Final number of samples: %u\n",rrt->ns);
2942 
2943  /* Reconstruct the path (if any) */
2944  pathFound=PathStart2GoalInRRT(pr,pgs,NO_UINT,NO_UINT,pl,pc,ns,path,rrt);
2945  if((pathFound)&&(!EXPLORATION_RRT))
2946  rrt->si[rrt->ns-1]->cost=costF(pr,TRUE,GetRRTNode(rrt->ns-1,rrt),costData);
2947 
2948  /* Release memory */
2949  DeleteStatistics(&st);
2950  #if (GET_RRT_STATISTICS)
2951  if (grst==NULL)
2952  PrintRRTStatistics(rrt,rst);
2953  else
2954  AccumulateRRTStatistics(rst,grst);
2955  DeleteRRTStatistics(rst);
2956  free(rst);
2957  #endif
2958 
2959  free(q_rand);
2960  free(pgs);
2961 
2962  return(pathFound);
2963 }
2964 
2965 boolean ccRRT(Tparameters *pr,double *pg,
2966  double *time,
2967  double *pl,unsigned int *ns,double ***path,
2968  TRRTStatistics *grst,Trrt *rrt)
2969 {
2970  double *pWithDummies,*pgs,*q_rand;
2971  unsigned int it,i_near;
2972  double epsilon;
2973  boolean pathFound,done,expand2Goal;
2974  unsigned int lastSample;
2975  double er,h;
2976  Tstatistics st; /* used just to measure execution time */
2977  boolean collision;
2978  double maxTime;
2979  unsigned int maxNodes;
2980  unsigned int samplingMode;
2981  boolean validSample;
2982  TRRTStatistics *rst;
2983 
2984  if (rrt->mode!=ONE_TREE)
2985  Error("ccRRT operates on one-directional RRTs");
2986 
2987  #if (GET_RRT_STATISTICS)
2988  {
2989  unsigned int i;
2990 
2991  NEW(rst,1,TRRTStatistics);
2992  InitRRTStatistics(rst);
2993 
2994  for(i=0;i<rrt->ns;i++)
2995  NewRRTSample(rst);
2996  }
2997  #endif
2998 
2999  /* Init the RRT structure */
3000  epsilon=GetParameter(CT_EPSILON,pr);
3001  maxTime=GetParameter(CT_MAX_PLANNING_TIME,pr);
3002  maxNodes=(unsigned int)GetParameter(CT_MAX_NODES_RRT,pr);
3003  samplingMode=(unsigned int)GetParameter(CT_SAMPLING,pr);
3004 
3005  CS_WD_REGENERATE_SOLUTION_POINT(pr,pg,&pWithDummies,rrt->w);
3006  CS_WD_GENERATE_SIMPLIFIED_POINT(pr,pWithDummies,&pgs,rrt->w);
3007 
3008  if ((!PointInBoxTopology(NULL,TRUE,rrt->m,pgs,epsilon,rrt->tp,rrt->ambient))||
3009  (!CS_WD_SIMP_INEQUALITIES_HOLD(pr,pgs,rrt->w)))
3010  Error("The targed point for the ccRRT is not in domain");
3011 
3012  if (rrt->n==0)
3013  er=0;
3014  else
3015  er=CS_WD_ERROR_IN_SIMP_EQUATIONS(pr,pgs,rrt->w);
3016  if (er>epsilon)
3017  Error("The target point for the ccRRT is not on the manifold");
3018 
3019  collision=CS_WD_ORIGINAL_IN_COLLISION(pr,pWithDummies,NULL,rrt->w);
3020  if (collision)
3021  Warning("The target point for the ccRRT is in collision");
3022  free(pWithDummies);
3023 
3024  /* Room for the randomly generated samples (and its correspoinding point
3025  on the manifold) */
3026  NEW(q_rand,rrt->m,double);
3027 
3028  done=FALSE;
3029  it=0;
3030 
3031  InitStatistics(rrt->nCores,0,&st);
3032  *time=0.0;
3033 
3034  while ((!done)&&(*time<maxTime)&&(rrt->ns<maxNodes))
3035  {
3036  if ((RRT_VERBOSE)||((it%1000)==0))
3037  {
3038  fprintf(stderr,"Iteration: %u (s:%u t:%g)\n",it,rrt->ns,*time);
3039  fflush(stdout);
3040  }
3041 
3042  /*******************************************************************/
3043  /* Sample in ambient space (with bias toward goal) */
3044  do {
3045  /* Generate a random sample */
3046  expand2Goal=RRTSample(samplingMode,START2GOAL,(EXPLORATION_RRT?NULL:pgs),
3047  q_rand,rst,rrt);
3048 
3049  /* Check the sample is valid */
3050  validSample=RRTValidateSample(pr,q_rand,START2GOAL,expand2Goal,NULL,INF,
3051  &h,&i_near,rst,rrt);
3052 
3053  *time=GetElapsedTime(&st);
3054  } while((!validSample)&&(*time<maxTime));
3055 
3056  if (*time<maxTime)
3057  {
3058  /*******************************************************************/
3059  /* Extend the RRT from q_near to q_rand using the ccRRT extend method */
3060  #if (GET_RRT_STATISTICS)
3061  NewRRTBranch(rst);
3062  NewRRTDistanceQrand(DistanceTopology(rrt->m,rrt->tp,rrt->si[i_near]->samples,q_rand),rst);
3063  #endif
3064  done=AddBranchToRRT(pr,TRUE,START2GOAL,i_near,q_rand,pgs,&lastSample,
3065  NULL,NULL,rst,rrt);
3066  #if (GET_RRT_STATISTICS)
3067  if (lastSample!=i_near)
3068  NewRRTNoEmptyBranch(rst);
3069  #endif
3070 
3071  *time=GetElapsedTime(&st);
3072  it++;
3073  }
3074  }
3075 
3076  fprintf(stderr,"Final number of samples: %u\n",rrt->ns);
3077 
3078  /* Reconstruct the path (if any) */
3079  pathFound=PathStart2GoalInRRT(pr,pgs,NO_UINT,NO_UINT,pl,NULL,ns,path,rrt);
3080 
3081  /* Release memory */
3082  DeleteStatistics(&st);
3083  #if (GET_RRT_STATISTICS)
3084  if (grst==NULL)
3085  PrintRRTStatistics(rrt,rst);
3086  else
3087  AccumulateRRTStatistics(rst,grst);
3088  DeleteRRTStatistics(rst);
3089  free(rst);
3090  #endif
3091 
3092  free(q_rand);
3093  free(pgs);
3094 
3095  return(pathFound);
3096 }
3097 
3098 boolean cBiRRT(Tparameters *pr,double *pg,
3099  double *time,
3100  double *pl,unsigned int *ns,double ***path,
3101  TRRTStatistics *grst,Trrt *rrt)
3102 {
3103  double *pWithDummies,*pgs,*q_rand;
3104  unsigned int it,i_near;
3105  double epsilon;
3106  boolean pathFound;
3107  double er,h;
3108  unsigned int t1,t2;
3109  unsigned int lastSample1;
3110  unsigned int samplingMode;
3111  Tstatistics st; /* used just to measure execution time */
3112  boolean collision;
3113  unsigned int lastSample2;
3114  double maxTime;
3115  boolean validSample;
3116  TRRTStatistics *rst;
3117 
3118  #if (EXPLORATION_RRT)
3119  Error("cBiRRT can not be used in exploration mode.");
3120  #endif
3121 
3122  if (rrt->mode!=TWO_TREES)
3123  Error("cBiRRT operates on bidirectional RRTs");
3124 
3125  #if (GET_RRT_STATISTICS)
3126  {
3127  unsigned int i;
3128 
3129  NEW(rst,1,TRRTStatistics);
3130  InitRRTStatistics(rst);
3131 
3132  for(i=0;i<rrt->ns;i++)
3133  NewRRTSample(rst);
3134  }
3135  #endif
3136 
3137  /* Init the RRT structure */
3138  epsilon=GetParameter(CT_EPSILON,pr);
3139  maxTime=GetParameter(CT_MAX_PLANNING_TIME,pr);
3140  samplingMode=(unsigned int)GetParameter(CT_SAMPLING,pr);
3141 
3142  CS_WD_REGENERATE_SOLUTION_POINT(pr,pg,&pWithDummies,rrt->w);
3143  CS_WD_GENERATE_SIMPLIFIED_POINT(pr,pWithDummies,&pgs,rrt->w);
3144 
3145  if ((!PointInBoxTopology(NULL,TRUE,rrt->m,pgs,epsilon,rrt->tp,rrt->ambient))||
3146  (!CS_WD_SIMP_INEQUALITIES_HOLD(pr,pgs,rrt->w)))
3147  Error("The targed point is not in domain");
3148 
3149  if (rrt->n==0)
3150  er=0;
3151  else
3152  er=CS_WD_ERROR_IN_SIMP_EQUATIONS(pr,pgs,rrt->w);
3153  if (er>epsilon)
3154  Error("The target point for the RRT is not on the manifold");
3155 
3156  collision=CS_WD_ORIGINAL_IN_COLLISION(pr,pWithDummies,NULL,rrt->w);
3157  if (collision)
3158  Warning("The target point for the RRT is in collision");
3159  free(pWithDummies);
3160 
3161  /* Room for the randomly generated samples (and its correspoinding point
3162  on the manifold) */
3163  NEW(q_rand,rrt->m,double);
3164 
3165  pathFound=FALSE;
3166  it=0;
3167 
3168  /* The two trees. This is only used for bidirectiononal RRTs. In norma
3169  RRTs only the START2GOAL tree is extended*/
3170  t1=START2GOAL;
3171  t2=GOAL2START;
3172 
3173  InitStatistics(rrt->nCores,0,&st);
3174  *time=0.0;
3175 
3176  while ((!pathFound)&&(*time<maxTime))
3177  {
3178  if ((RRT_VERBOSE)||((it%1000)==0))
3179  {
3180  fprintf(stderr,"Iteration: %u (s:%u t:%g)\n",it,rrt->ns,*time);
3181  fflush(stdout);
3182  }
3183 
3184  /*******************************************************************/
3185  /* Sample */
3186  do {
3187  /* Generate a random sample */
3188  RRTSample(samplingMode,t1,NULL,q_rand,rst,rrt);
3189 
3190  /* Check the sample is valid */
3191  validSample=RRTValidateSample(pr,q_rand,t1,FALSE,NULL,INF,
3192  &h,&i_near,rst,rrt);
3193 
3194  *time=GetElapsedTime(&st);
3195  } while((!validSample)&&(*time<maxTime));
3196 
3197  if (*time<maxTime)
3198  {
3199  /*******************************************************************/
3200  /* Extend the first tree from q_near toward q_rand */
3201  #if (GET_RRT_STATISTICS)
3202  NewRRTBranch(rst);
3203  NewRRTDistanceQrand(DistanceTopology(rrt->m,rrt->tp,rrt->si[i_near]->samples,q_rand),rst);
3204  #endif
3205  AddBranchToRRT(pr,FALSE,t1,i_near,q_rand,q_rand,&lastSample1,
3206  NULL,NULL,rst,rrt);
3207  #if (GET_RRT_STATISTICS)
3208  if (lastSample1!=i_near)
3209  NewRRTNoEmptyBranch(rst);
3210  #endif
3211 
3212  /*******************************************************************/
3213  /* The last node added to t1 is used as random sample */
3214  memcpy(q_rand,rrt->si[lastSample1]->samples,rrt->m*sizeof(double));
3215 
3216  /*******************************************************************/
3217  /* Search for q_near in the second tree */
3218  i_near=GetRRTNN(t2,q_rand,rrt);
3219 
3220  /*******************************************************************/
3221  /* Extend t2 toward the last sample added to t1 */
3222  #if (GET_RRT_STATISTICS)
3223  NewRRTTreeConnection(rst);
3224  #endif
3225  pathFound=AddBranchToRRT(pr,FALSE,t2,i_near,q_rand,q_rand,&lastSample2,
3226  NULL,NULL,rst,rrt);
3227  #if (GET_RRT_STATISTICS)
3228  if (lastSample2!=i_near)
3230  #endif
3231 
3232  /*******************************************************************/
3233  /* Swap the trees (t1 and t2) */
3234  if ((it%2)==0)
3235  {
3236  t1=GOAL2START;
3237  t2=START2GOAL;
3238  }
3239  else
3240  {
3241  t1=START2GOAL;
3242  t2=GOAL2START;
3243  }
3244 
3245  *time=GetElapsedTime(&st);
3246  it++;
3247  }
3248  }
3249 
3250  fprintf(stderr,"Final number of samples: %u\n",rrt->ns);
3251 
3252  /* Reconstruct the path, if possible */
3253  if (pathFound)
3254  {
3255  if (!PathStart2GoalInRRT(pr,pgs,lastSample1,lastSample2,pl,NULL,ns,path,rrt))
3256  Error("Inconsitancy in cBiRRT pathFound");
3257  }
3258 
3259  /* Release memory */
3260  DeleteStatistics(&st);
3261  #if (GET_RRT_STATISTICS)
3262  if (grst==NULL)
3263  PrintRRTStatistics(rrt,rst);
3264  else
3265  AccumulateRRTStatistics(rst,grst);
3266  DeleteRRTStatistics(rst);
3267  free(rst);
3268  #endif
3269 
3270  free(q_rand);
3271  free(pgs);
3272 
3273  return(pathFound);
3274 }
3275 
3276 double RRTPathSteps(unsigned int sID,Tvector *path,Trrt *rrt)
3277 {
3278  TRRTStep st;
3279  unsigned int s;
3280  double l;
3281 
3282  InitVector(sizeof(TRRTStep),CopyRRTStep,NULL,100,path);
3283 
3284  s=sID;
3285  l=0;
3286  while (s!=NO_UINT)
3287  {
3288  st.id=s;
3289  st.cost=rrt->si[s]->costp;/* this is 0 for the root */
3290  NewVectorElement((void *)(&st),path);
3291  l+=st.cost;
3292  s=rrt->si[s]->parent; /* this is NO_UINT for the root */
3293  }
3294  return(l);
3295 }
3296 
3297 double ChangeBiRRTSteps(unsigned int l1,unsigned int l2,double c12,Tvector *steps,Trrt *rrt)
3298 {
3299  Tvector v1,v2;
3300  double lp1,lp2;
3301  unsigned int n;
3302  TRRTStep st,*st1,*st2;
3303  int i;
3304  double c;
3305 
3306  lp1=RRTPathSteps(l1,&v1,rrt);
3307  lp2=RRTPathSteps(l2,&v2,rrt);
3308  if (rrt->si[l1]->tree==START2GOAL)
3309  {
3310  /* reverse(v1) -> v2 */
3311  ResetVector(steps);
3312  n=VectorSize(&v1);
3313  for(i=n-1;i>=0;i--)
3314  {
3315  st1=(TRRTStep *)GetVectorElement(i,&v1);
3316  if (i==0)
3317  c=c12;
3318  else
3319  {
3320  st2=(TRRTStep *)GetVectorElement(i-1,&v1);
3321  c=st2->cost;
3322  }
3323  st.id=st1->id;
3324  st.cost=c;
3325  NewVectorElement((void*)&st,steps);
3326  }
3327  ConcatVectors(&v2,steps);
3328  }
3329  else
3330  {
3331  /* reverse(v2) -> v1 */
3332  ResetVector(steps);
3333  n=VectorSize(&v2);
3334  for(i=n-1;i>=0;i--)
3335  {
3336  st1=(TRRTStep *)GetVectorElement(i,&v2);
3337  if (i==0)
3338  c=c12;
3339  else
3340  {
3341  st2=(TRRTStep *)GetVectorElement(i-1,&v2);
3342  c=st2->cost;
3343  }
3344  st.id=st1->id;
3345  st.cost=c;
3346  NewVectorElement((void*)&st,steps);
3347  }
3348  ConcatVectors(&v1,steps);
3349  }
3350  DeleteVector(&v1);
3351  DeleteVector(&v2);
3352 
3353  return(lp1+c12+lp2);
3354 }
3355 
3356 double UpdateBiRRTSteps(Tvector *steps,Trrt *rrt)
3357 {
3358  TRRTStep *st;
3359  unsigned int i,n,current,next,id1,id2;
3360  double c12,l,ct;
3361 
3362  /* Ensure that all nodes in the path are correctly assigned
3363  to the trees (and that theirs costs are up to date) */
3364  n=VectorSize(steps);
3365  for(i=0;i<n;i++)
3366  {
3367  st=(TRRTStep *)GetVectorElement(i,steps);
3368  UpdateCostAndTree(st->id,rrt);
3369  }
3370 
3371  /* Search for the best transition between trees along the path */
3372  st=(TRRTStep *)GetVectorElement(0,steps);
3373  current=st->id;
3374  c12=st->cost;
3375  l=INF;
3376  id1=NO_UINT;
3377  id2=NO_UINT;
3378  for(i=1;i<n;i++)
3379  {
3380  st=(TRRTStep *)GetVectorElement(i,steps);
3381  next=st->id;
3382  if ((current==NO_UINT)||(next==NO_UINT))
3383  Error("Undefined node in path in BiRRT");
3384  if ((rrt->si[current]->tree!=rrt->si[next]->tree)&&
3385  ((rrt->si[current]->cost+c12+rrt->si[next]->cost)<l))
3386  {
3387  id1=current;
3388  id2=next;
3389  ct=c12;
3390  l=rrt->si[id1]->cost+ct+rrt->si[id2]->cost;
3391  }
3392  current=next;
3393  c12=st->cost;
3394  }
3395  if (id1==NO_UINT) /* (id2==NO_UINT) (l==INF) */
3396  Error("A global path in a BiRRT without transition between trees?");
3397 
3398  return(ChangeBiRRTSteps(id1,id2,ct,steps,rrt));
3399 }
3400 
3401 boolean PathStart2GoalInRRT(Tparameters *pr,double *pgs,
3402  unsigned int l1,unsigned int l2,
3403  double *pl,double* pc,unsigned int *ns,double ***path,
3404  Trrt *rrt)
3405 {
3406  boolean pathFound;
3407 
3408  #if (EXPLORATION_RRT)
3409  /* We reconstruct the path from root to last sample in the tree */
3410  pathFound=TRUE;
3411  ReconstructRRTPath(pr,rrt->ns-1,pl,pc,ns,path,rrt);
3412  #else
3413  double pl1,pl2,d12;
3414 
3415  if (rrt->mode!=ONE_TREE)
3416  {
3417  d12=DistanceTopology(rrt->m,rrt->tp,rrt->si[l1]->samples,rrt->si[l2]->samples);
3418  pathFound=(d12<2.0*rrt->delta);
3419 
3420  if (pathFound)
3421  {
3422  unsigned int ns1,ns2;
3423  double **p1,**p2;
3424  unsigned int nvs;
3425 
3426  nvs=ReconstructRRTPath(pr,l1,&pl1,pc,&ns1,&p1,rrt);
3427  ReconstructRRTPath(pr,l2,&pl2,pc,&ns2,&p2,rrt);
3428 
3429  if (rrt->si[l1]->tree==START2GOAL)
3430  ReverseConcatSamples(nvs,ns1,p1,ns2,p2,ns,path);
3431  else
3432  ReverseConcatSamples(nvs,ns2,p2,ns1,p1,ns,path);
3433 
3434  DeleteSamples(ns1,p1);
3435  DeleteSamples(ns2,p2);
3436 
3437  *pl=pl1+d12+pl2;
3438  }
3439  }
3440  else
3441  {
3442  unsigned int nn;
3443  double d;
3444 
3445  nn=GetRRTNN(START2GOAL,pgs,rrt);
3446  d=DistanceTopology(rrt->m,rrt->tp,rrt->si[nn]->samples,pgs);
3447  pathFound=(d<2.0*rrt->delta);
3448  if (pathFound)
3449  {
3450  unsigned int g;
3451 
3452  /* Todo : compute the cost of the goal if required*/
3453  AddNodeToRRT(pr,START2GOAL,nn,pgs,pgs,&g,NULL,d,0,NULL,rrt);
3454  ReconstructRRTPath(pr,g,pl,pc,ns,path,rrt);
3455  }
3456  }
3457  #endif
3458 
3459  return(pathFound);
3460 }
3461 
3462 boolean Bidirectional(Trrt *rrt)
3463 {
3464  return(rrt->mode!=ONE_TREE);
3465 }
3466 
3467 
3468 unsigned int GetRRTMode(Trrt *rrt)
3469 {
3470  return(rrt->mode);
3471 }
3472 
3473 boolean InDynamicDomain(unsigned int i,double *q,Trrt *rrt)
3474 {
3475  if ((rrt->dd>0)&&(rrt->si[i]->ddr>0.0))
3476  return(DistanceTopology(rrt->m,rrt->tp,rrt->si[i]->samples,q)<rrt->si[i]->ddr);
3477  else
3478  return(TRUE);
3479 }
3480 
3481 void AdjustDynamicDomain(unsigned int i,boolean collision,Trrt *rrt)
3482 {
3483  if (rrt->dd>0) /* If the dynamic domain is active */
3484  {
3485  if (rrt->si[i]->ddr==0.0)
3486  {
3487  /* The dynamic domain radius is not set yet. Set it if we
3488  detected a collision during branch extension. */
3489  if (collision)
3490  rrt->si[i]->ddr=rrt->dd; /* Set to the initial radius. */
3491  }
3492  /* up to here we have the basic dynamic domain technique where
3493  the radius is set after detecting the first collision and not
3494  modified latter on */
3495 #if (0)
3496  /* with the code below, the dydnamic domain radius is self-adjusted
3497  This is deactivated because it is not very effective,
3498  in our experience. */
3499  else
3500  {
3501  /* Adjust the radious according to the collision status.
3502  Branches interrupted by a collision -> decrease the radius
3503  Branches fully extended -> increase the radius */
3504  if (collision)
3505  rrt->si[i]->ddr*=(1.0-MOV_AVG_DOWN);
3506  else
3507  rrt->si[i]->ddr*=(1.0+MOV_AVG_UP);
3508  }
3509 #endif
3510  }
3511 }
3512 
3513 double GetDynamicDomainRadius(unsigned int i,Trrt *rrt)
3514 {
3515  if (rrt->dd>0)
3516  return(rrt->si[i]->ddr);
3517  else
3518  return(0.0);
3519 }
3520 
3521 boolean DynamicDomainRRT(Trrt *rrt)
3522 {
3523  return(rrt->dd>0);
3524 }
3525 
3526 unsigned int GetRRTNumNodes(Trrt *rrt)
3527 {
3528  return(rrt->ns);
3529 }
3530 
3531 double *GetRRTNode(unsigned int i,Trrt *rrt)
3532 {
3533  if (i>=rrt->ns)
3534  return(NULL);
3535  else
3536  return(rrt->si[i]->samples);
3537 }
3538 
3539 unsigned int GetRRTNodeTree(unsigned int i,Trrt *rrt)
3540 {
3541  if (i>=rrt->ns)
3542  return(NO_UINT);
3543  else
3544  {
3545  if (rrt->mode==ONE_TREE)
3546  return(START2GOAL);
3547  else
3548  return(rrt->si[i]->tree);
3549  }
3550 }
3551 
3552 unsigned int GetRRTParent(unsigned int i,Trrt *rrt)
3553 {
3554  if (i>=rrt->ns)
3555  return(NO_UINT);
3556  else
3557  return(rrt->si[i]->parent);
3558 }
3559 
3560 void SetRRTParent(unsigned int i,unsigned int p,Trrt *rrt)
3561 {
3562  if ((i>=rrt->ns)||(p>=rrt->ns))
3563  Error("Wrong node/parent in SetRRTParent");
3564 
3565  if (rrt->si[i]->parent==NO_UINT)
3566  Error("Can not change the parent of a root node");
3567 
3568  rrt->si[i]->parent=p;
3569  if (rrt->si[i]->tree!=rrt->si[p]->tree)
3570  {
3571  if (rrt->mode!=TWO_TREES_WITH_SWAP)
3572  Error("Nodes can only swap trees in TWO_TREES_WITH_SWAP RRTs");
3573  rrt->si[i]->tree=rrt->si[p]->tree;
3574  }
3575 }
3576 
3577 void *GetRRTNodeInfo(unsigned int i,Trrt *rrt)
3578 {
3579  if (i<rrt->ns)
3580  return(rrt->si[i]->userInfo);
3581  else
3582  return(NULL);
3583 }
3584 
3585 void SetRRTNodeInfo(unsigned int i,void *info,Trrt *rrt)
3586 {
3587  if (i<rrt->ns)
3588  rrt->si[i]->userInfo=info;
3589  else
3590  Error("RRT node out of range in SetRRTNodeInfo");
3591 }
3592 
3593 double GetRRTNodeCost(unsigned int i,Trrt *rrt)
3594 {
3595  if (i<rrt->ns)
3596  return(rrt->si[i]->cost);
3597  else
3598  return(0.0);
3599 }
3600 
3601 double GetRRTNodeCostFromParent(unsigned int i,Trrt *rrt)
3602 {
3603  if (i<rrt->ns)
3604  return(rrt->si[i]->costp);
3605  else
3606  return(0.0);
3607 }
3608 
3609 void SetRRTNodeCost(unsigned int i,double costp,double cost,Trrt *rrt)
3610 {
3611  if (i<rrt->ns)
3612  {
3613  rrt->si[i]->costp=costp;
3614  rrt->si[i]->cost=cost;
3615  }
3616  else
3617  Error("RRT node out of range in SetRRTNodeCost");
3618 }
3619 
3620 void SetRRTCostAndParent(unsigned int i,unsigned int p,double costp,double cost,Trrt *rrt)
3621 {
3622  if (i<rrt->ns)
3623  {
3624  rrt->si[i]->costp=costp;
3625  rrt->si[i]->cost=cost;
3626  rrt->si[i]->parent=p;
3627  if (rrt->si[i]->tree!=rrt->si[p]->tree)
3628  {
3629  if (rrt->mode!=TWO_TREES_WITH_SWAP)
3630  Error("A RRT node moved from one tree to another in SetRRTCostAndParent");
3631  rrt->si[i]->tree=rrt->si[p]->tree;
3632  }
3633  }
3634  else
3635  Error("RRT node out of range in SetRRTCostAndParent");
3636 }
3637 
3638 unsigned int *GetRRTTopology(Trrt *rrt)
3639 {
3640  return(rrt->tp);
3641 }
3642 
3643 double CostToRoot(unsigned int sID,Trrt* rrt)
3644 {
3645  double l;
3646  unsigned int s;
3647 
3648  l=0.0;
3649  s=sID;
3650  while (s!=NO_UINT)
3651  {
3652  l+=rrt->si[s]->costp;
3653  s=rrt->si[s]->parent;
3654  }
3655  return(l);
3656 }
3657 
3658 void UpdateCostToRoot(unsigned int sID,Trrt* rrt)
3659 {
3660  rrt->si[sID]->cost=CostToRoot(sID,rrt);
3661 }
3662 
3663 void UpdateTree(unsigned int sID,Trrt* rrt)
3664 {
3665  unsigned int s,p;
3666 
3667  if (rrt->mode!=TWO_TREES_WITH_SWAP)
3668  Error("Nodes can only change trees in TWO_TREES_WITH_SWAP mode");
3669 
3670  s=sID;
3671  p=NO_UINT; /* parent node */
3672  while (s!=NO_UINT)
3673  {
3674  p=s;
3675  s=rrt->si[s]->parent;
3676  }
3677  if (p==NO_UINT)
3678  Error("Undefined root node in UpdateTree");
3679 
3680  /* here p is the root of the tree including sample sID (0 or 1) */
3681  if (p>2)
3682  Error("Wrong root in UpdateTree");
3683 
3684  /* update the tree assigment for this node */
3685  /* alternatively we could update the tree assigment all along the branch */
3686  if (p==0)
3687  rrt->si[sID]->tree=START2GOAL;
3688  else
3689  rrt->si[sID]->tree=GOAL2START;
3690 }
3691 
3692 void UpdateCostAndTree(unsigned int sID,Trrt* rrt)
3693 {
3694  double l;
3695  unsigned int s,p;
3696 
3697  /* This is just cut+paste+joint of CostToRoot, UpdateCost, and UpdateTree
3698  defined to gain some efficiency. */
3699 
3700  l=0.0;
3701  s=sID;
3702  p=NO_UINT; /* previous node */
3703  while (s!=NO_UINT)
3704  {
3705  l+=rrt->si[s]->costp;
3706  p=s;
3707  s=rrt->si[s]->parent;
3708  }
3709 
3710  /* update the cost and the tree of the given node */
3711  rrt->si[sID]->cost=l;
3712  /* the update of the tree only has effect in TWO_TREES_WITH_SWAP mode */
3713  if (p==0)
3714  rrt->si[sID]->tree=START2GOAL;
3715  else
3716  rrt->si[sID]->tree=GOAL2START;
3717 }
3718 
3719 unsigned int StepsToRoot(unsigned int sID,Trrt* rrt)
3720 {
3721  unsigned int l;
3722  unsigned int s;
3723 
3724  l=0;
3725  s=sID;
3726  while (s!=NO_UINT)
3727  {
3728  l++;
3729  s=rrt->si[s]->parent;
3730  }
3731  return(l);
3732 }
3733 
3734 void PlotRRT(char *fname,int argc, char **arg,Tparameters *pr,
3735  unsigned int xID,unsigned int yID,unsigned int zID,Trrt *rrt)
3736 {
3737  Tplot3d p3d;
3738  unsigned int i;
3739  Tcolor color;
3740  double *o;
3741  double *px,*py,*pz;
3742  double x[2],y[2],z[2];
3743  double cx,cy,cz;
3744 
3745  if (rrt->mode==TWO_TREES_WITH_SWAP)
3746  {
3747  /* To obtain nicer plots we update the tree assigment for all nodes */
3748  for(i=0;i<rrt->ns;i++)
3749  UpdateTree(i,rrt);
3750  }
3751 
3752  cx=GetParameter(CT_CUT_X,pr);
3753  cy=GetParameter(CT_CUT_Y,pr);
3754  cz=GetParameter(CT_CUT_Z,pr);
3755 
3756  /* Project the RRT nodes */
3757  NEW(px,rrt->ns,double);
3758  NEW(py,rrt->ns,double);
3759  NEW(pz,rrt->ns,double);
3760 
3761  for(i=0;i<rrt->ns;i++)
3762  {
3763  CS_WD_REGENERATE_ORIGINAL_POINT(pr,rrt->si[i]->samples,&o,rrt->w);
3764 
3765  px[i]=o[xID];
3766  py[i]=o[yID];
3767  pz[i]=o[zID];
3768 
3769  if ((cx<0)&&(px[i]<cx))
3770  px[i]+=M_2PI;
3771  if ((cx>0)&&(px[i]>cx))
3772  px[i]-=M_2PI;
3773  if ((cy<0)&&(py[i]<cy))
3774  py[i]+=M_2PI;
3775  if ((cy>0)&&(py[i]>cy))
3776  py[i]-=M_2PI;
3777  if ((cz<0)&&(pz[i]<cz))
3778  pz[i]+=M_2PI;
3779  if ((cz>0)&&(pz[i]>cz))
3780  pz[i]-=M_2PI;
3781 
3782  free(o);
3783  }
3784 
3785  InitPlot3d(fname,FALSE,argc,arg,&p3d);
3786 
3787  NewColor(1,0,0,&color); /*red*/
3788  StartNew3dObject(&color,&p3d);
3789 
3790  for(i=((rrt->mode!=ONE_TREE)?2:1);i<rrt->ns;i++)
3791  {
3792  if ((rrt->mode==ONE_TREE)||(rrt->si[i]->tree==START2GOAL))
3793  {
3794  x[0]=px[i];
3795  y[0]=py[i];
3796  z[0]=pz[i];
3797 
3798  x[1]=px[rrt->si[i]->parent];
3799  y[1]=py[rrt->si[i]->parent];
3800  z[1]=pz[rrt->si[i]->parent];
3801 
3802  PlotVect3d(2,x,y,z,&p3d);
3803  }
3804  }
3805 
3806  DeleteColor(&color);
3807  Close3dObject(&p3d);
3808 
3809  if (rrt->mode!=ONE_TREE)
3810  {
3811  NewColor(0,1,0,&color); /*green*/
3812  StartNew3dObject(&color,&p3d);
3813 
3814  for(i=2;i<rrt->ns;i++)
3815  {
3816  if (rrt->si[i]->tree==GOAL2START)
3817  {
3818  x[0]=px[i];
3819  y[0]=py[i];
3820  z[0]=pz[i];
3821 
3822  x[1]=px[rrt->si[i]->parent];
3823  y[1]=py[rrt->si[i]->parent];
3824  z[1]=pz[rrt->si[i]->parent];
3825 
3826  PlotVect3d(2,x,y,z,&p3d);
3827  }
3828  }
3829 
3830  DeleteColor(&color);
3831  Close3dObject(&p3d);
3832  }
3833 
3834  #if (RRT_PLOT_NODES)
3835  /* Dots, one per node */
3836  NewColor(0,0,1,&color); /*blue*/
3837  StartNew3dObject(&color,&p3d);
3838 
3839  for(i=0;i<rrt->ns;i++)
3840  {
3841  x[0]=px[i]-0.01;
3842  y[0]=py[i];
3843  z[0]=pz[i];
3844 
3845  x[1]=px[i]+0.01;
3846  y[1]=py[i];
3847  z[1]=pz[i];
3848 
3849  PlotVect3d(2,x,y,z,&p3d);
3850 
3851  x[0]=px[i];
3852  y[0]=py[i]-0.01;
3853  z[0]=pz[i];
3854 
3855  x[1]=px[i];
3856  y[1]=py[i]+0.01;
3857  z[1]=pz[i];
3858 
3859  PlotVect3d(2,x,y,z,&p3d);
3860 
3861  x[0]=px[i];
3862  y[0]=py[i];
3863  z[0]=pz[i]-0.01;
3864 
3865  x[1]=px[i];
3866  y[1]=py[i];
3867  z[1]=pz[i]+0.01;
3868 
3869  PlotVect3d(2,x,y,z,&p3d);
3870  }
3871 
3872  DeleteColor(&color);
3873  Close3dObject(&p3d);
3874  #endif
3875 
3876  ClosePlot3d(FALSE,0,0,0,&p3d);
3877 
3878  free(px);
3879  free(py);
3880  free(pz);
3881 }
3882 
3883 void SaveRRTNodes(Tparameters *pr,char *fname,boolean saveWithDummies,Trrt *rrt)
3884 {
3885  double *o;
3886  unsigned int i,j,nv,nvs;
3887  boolean *systemVars;
3888  double *c;
3889  FILE *fo;
3890  Tfilename fsol;
3891 
3892  if (saveWithDummies)
3893  CreateFileName(NULL,fname,"_nodes",SOL_WITH_DUMMIES_EXT,&fsol);
3894  else
3895  CreateFileName(NULL,fname,"_nodes",SOL_EXT,&fsol);
3896  fprintf(stderr,"Writing boxes to : %s\n",GetFileFullName(&fsol));
3897  fo=fopen(GetFileFullName(&fsol),"w");
3898  if (!fo)
3899  Error("Could not open the file to store the boxes in SaveRRTNodes");
3900 
3901  nv=CS_WD_GET_SYSTEM_VARS(&systemVars,rrt->w);
3902  nvs=0;
3903  for(j=0;j<nv;j++)
3904  {
3905  if (systemVars[j])
3906  nvs++;
3907  }
3908 
3909  for(i=0;i<rrt->ns;i++)
3910  {
3911  c=rrt->si[i]->samples;
3912 
3913  CS_WD_REGENERATE_ORIGINAL_POINT(pr,c,&o,rrt->w);
3914 
3915  if (saveWithDummies)
3916  fprintf(fo,"%u { %u ",i,nv);
3917  else
3918  fprintf(fo,"%u { %u ",i,nvs);
3919  for(j=0;j<nv;j++)
3920  {
3921  if ((saveWithDummies)||(systemVars[j]))
3922  fprintf(fo,"[%.12g,%.12g] ",o[j],o[j]);
3923  }
3924  fprintf(fo,"}\n");
3925 
3926  free(o);
3927  }
3928 
3929  fclose(fo);
3930  free(systemVars);
3931  DeleteFileName(&fsol);
3932 }
3933 
3934 void SaveRRTCosts(Tparameters *pr,char *fname,Trrt *rrt)
3935 {
3936  unsigned int i;
3937  FILE *fo;
3938  Tfilename fcost;
3939  double ma,mi;
3940  unsigned int ima,imi;
3941  double c;
3942 
3943  CreateFileName(NULL,fname,"_nodes",COST_EXT,&fcost);
3944  fprintf(stderr,"Writing costs to : %s\n",GetFileFullName(&fcost));
3945 
3946  fo=fopen(GetFileFullName(&fcost),"w");
3947  if (!fo)
3948  Error("Could not open the file to store the costs in SaveRRTCosts");
3949 
3950  ma=-INF;
3951  mi=INF;
3952  for(i=0;i<rrt->ns;i++)
3953  {
3954  c=rrt->si[i]->cost;
3955  fprintf(fo,"%f\n",c);
3956  if (c>ma)
3957  {
3958  ma=c;
3959  ima=i;
3960  }
3961  if (c<mi)
3962  {
3963  mi=c;
3964  imi=i;
3965  }
3966  }
3967  fprintf(stderr," Extreme costs : %f (%u) -- %f (%u)\n",mi,imi,ma,ima);
3968 
3969  fclose(fo);
3970  DeleteFileName(&fcost);
3971 }
3972 
3973 unsigned int RRTMemSize(Trrt *rrt)
3974 {
3975  unsigned int b,i;
3976 
3977  /* The samples */
3978  b=sizeof(double)*rrt->m*rrt->ns;
3979 
3980  if (rrt->graph)
3981  {
3982  /* The neighbours */
3983  for(i=0;i<rrt->ns;i++)
3984  b+=rrt->si[i]->nn*(sizeof(double)+sizeof(unsigned int));
3985  }
3986 
3987  return(b);
3988 }
3989 
3990 void SaveRRT(Tfilename *fname,Trrt *rrt)
3991 {
3992  FILE *f;
3993  unsigned int i,j;
3994 
3995 
3996  f=fopen(GetFileFullName(fname),"w");
3997  if (!f)
3998  Error("Could not open file to store rrt");
3999 
4000  fprintf(f,"%u\n",rrt->graph);
4001  fprintf(f,"%u\n",rrt->mode);
4002  fprintf(f,"%f\n",rrt->dd);
4003  #if (_KDTREE==1)
4004  fprintf(f,"%f\n",KDtreeSamplingExpansion(rrt->treeS2G));
4005  #else
4006  fprintf(f,"0\n");
4007  #endif
4008 
4009  fprintf(f,"%u\n",rrt->m);
4010  fprintf(f,"%u\n",rrt->k);
4011  fprintf(f,"%u\n",rrt->n);
4012 
4013  fprintf(f,"%f\n",rrt->delta);
4014 
4015  fprintf(f,"%f\n",rrt->temperature);
4016  fprintf(f,"%u\n",rrt->nFail);
4017 
4018  fprintf(f,"%u\n",rrt->ms);
4019  fprintf(f,"%u\n",rrt->ns);
4020 
4021  for(i=0;i<rrt->ns;i++)
4022  {
4023  for(j=0;j<rrt->m;j++)
4024  fprintf(f,"%.12f ",rrt->si[i]->samples[j]);
4025  fprintf(f,"\n");
4026  fprintf(f,"%u %u %f %f %f\n",rrt->si[i]->parent,rrt->si[i]->tree,
4027  rrt->si[i]->costp,rrt->si[i]->cost,rrt->si[i]->ddr);
4028 
4029  if (rrt->graph)
4030  {
4031  fprintf(f,"%f %u %u",rrt->si[i]->g,rrt->si[i]->m,rrt->si[i]->nn);
4032  for(j=0;j<rrt->si[i]->nn;j++)
4033  fprintf(f," %u %f",rrt->si[i]->n[j],rrt->si[i]->cn[j]);
4034  fprintf(f,"\n");
4035  }
4036  }
4037 
4038  fclose(f);
4039 }
4040 
4041 void LoadRRT(Tparameters *pr,Tfilename *fname,TAtlasBase *w,Trrt *rrt)
4042 {
4043  FILE *f;
4044  unsigned int i,j;
4045  double dr;
4046 
4047  f=fopen(GetFileFullName(fname),"r");
4048  if (!f)
4049  Error("Could not open file to read the RRT");
4050 
4051  rrt->w=w;
4052 
4053  fscanf(f,"%u",&(rrt->graph));
4054  fscanf(f,"%u",&(rrt->mode));
4055  fscanf(f,"%lf",&(rrt->dd));
4056  fscanf(f,"%lf",&dr);
4057 
4058  fscanf(f,"%u",&(rrt->m));
4059  fscanf(f,"%u",&(rrt->k));
4060  fscanf(f,"%u",&(rrt->n));
4061 
4062  fscanf(f,"%lf",&(rrt->delta));
4063 
4064  fscanf(f,"%lf",&(rrt->temperature));
4065  fscanf(f,"%u",&(rrt->nFail));
4066 
4067  fscanf(f,"%u",&(rrt->ms));
4068  fscanf(f,"%u",&(rrt->ns));
4069 
4070  NEW(rrt->si,rrt->ms,TRRTSampleInfo*);
4071  for(i=0;i<rrt->ms;i++)
4072  rrt->si[i]=NULL;
4073 
4074  SetRRTTopology(pr,rrt);
4075 
4076  NEW(rrt->ambient,1,Tbox);
4078 
4079  #if (_KDTREE==1)
4080  {
4081  unsigned int nd,i;
4082  Trectangle rec;
4083  Tinterval *range;
4084 
4085  nd=GetBoxNIntervals(rrt->ambient);
4086  InitRectangle(nd,NULL,NULL,&rec);
4087  for(i=0;i<nd;i++)
4088  {
4089  range=GetBoxInterval(i,rrt->ambient);
4090  SetRectangleLimits(i,LowerLimit(range),UpperLimit(range),&rec);
4091  }
4092 
4093  rrt->treeS2G=InitKDTree(&rec,rrt->tp,25,dr,0,NULL,NULL);
4094  if (rrt->mode==TWO_TREES)
4095  rrt->treeG2S=InitKDTree(&rec,rrt->tp,25,dr,0,NULL,NULL);
4096 
4097  DeleteRectangle(&rec);
4098  }
4099  #endif
4100 
4101  #if (_KDTREE==2)
4102  if ((!RRT_NN_TOPOLOGY)||(rrt->tp==NULL))
4103  rrt->treeS2G=CreateKDTree(rrt->m);
4104  else
4105  rrt->treeS2G=CreateKDTreeT(rrt->m,(int *)rrt->tp);
4106 
4107  if (rrt->mode==TWO_TREES)
4108  {
4109  if ((!RRT_NN_TOPOLOGY)||(rrt->tp==NULL))
4110  rrt->treeG2S=CreateKDTree(rrt->m);
4111  else
4112  rrt->treeG2S=CreateKDTreeT(rrt->m,(int *)rrt->tp);
4113 
4114  rrt->maxNodesT1=rrt->ms;
4115  rrt->maxNodesT2=rrt->ms;
4116 
4117  NEW(rrt->t1ToId,rrt->maxNodesT1,unsigned int);
4118  NEW(rrt->t2ToId,rrt->maxNodesT2,unsigned int);
4119 
4120  rrt->nodesT1=0;
4121  rrt->nodesT2=0;
4122  }
4123  #endif
4124 
4125  for(i=0;i<rrt->ns;i++)
4126  {
4127  NEW(rrt->si[i],1,TRRTSampleInfo);
4128 
4129  NEW(rrt->si[i]->samples,rrt->m,double);
4130  for(j=0;j<rrt->m;j++) /* sample */
4131  fscanf(f,"%lf",&(rrt->si[i]->samples[j]));
4132 
4133  fscanf(f,"%u",&(rrt->si[i]->parent));
4134  fscanf(f,"%u",&(rrt->si[i]->tree));
4135  fscanf(f,"%lf",&(rrt->si[i]->costp));
4136  fscanf(f,"%lf",&(rrt->si[i]->cost));
4137  fscanf(f,"%lf",&(rrt->si[i]->ddr));
4138 
4139  rrt->si[i]->userInfo=NULL; /* This information is not stored :( */
4140 
4141  #if (_KDTREE==1)
4142  if (rrt->mode==TWO_TREES)
4143  {
4144  if (rrt->si[i]->tree==START2GOAL)
4145  AddPoint2KDtree(rrt->si[i]->samples,i,&(rrt->treeS2G));
4146  else
4147  AddPoint2KDtree(rrt->si[i]->samples,i,&(rrt->treeG2S));
4148  }
4149  else
4150  AddPoint2KDtree(rrt->si[i]->samples,i,&(rrt->treeS2G));
4151  #endif
4152 
4153  #if (_KDTREE==2)
4154  if (rrt->mode==TWO_TREES)
4155  {
4156  if (rrt->si[i]->tree==START2GOAL)
4157  {
4158  rrt->t1ToId[rrt->nodesT1]=i;
4159  rrt->nodesT1++;
4160  AddPoint2KDTree(rrt->si[i]->samples,rrt->treeS2G);
4161  }
4162  else
4163  {
4164  rrt->t2ToId[rrt->nodesT2]=i;
4165  rrt->nodesT2++;
4166  AddPoint2KDTree(rrt->si[i]->samples,rrt->treeG2S);
4167  }
4168  }
4169  else
4170  AddPoint2KDTree(rrt->si[i]->samples,rrt->treeS2G);
4171  #endif
4172 
4173  if (rrt->graph)
4174  {
4175  fscanf(f,"%lf",&(rrt->si[i]->g));
4176  fscanf(f,"%u",&(rrt->si[i]->m));
4177  fscanf(f,"%u",&(rrt->si[i]->nn));
4178  NEW(rrt->si[i]->n,rrt->si[i]->m,unsigned int);
4179  NEW(rrt->si[i]->cn,rrt->si[i]->m,double);
4180  for(j=0;j<rrt->si[i]->nn;j++)
4181  {
4182  fscanf(f,"%u",&(rrt->si[i]->n[j]));
4183  fscanf(f,"%lf",&(rrt->si[i]->cn[j]));
4184  }
4185  }
4186  }
4187 
4188  fclose(f);
4189 
4190  NEW(rrt->ambient,1,Tbox);
4191  /* The Jacobian is not saved but re-computed */
4193 
4194  /* The parallelism information is not stored! We de-activate it
4195  when loading an RRT (load is typically used for visualization
4196  and not for further processing)*/
4197  rrt->nCores=1;
4198  rrt->parallel=FALSE;
4199 }
4200 
4201 void DeleteRRT(Trrt *rrt)
4202 {
4203  unsigned int i;
4204 
4205  for(i=0;i<rrt->ns;i++)
4206  {
4207  free(rrt->si[i]->samples);
4208  if (rrt->graph)
4209  {
4210  free(rrt->si[i]->n);
4211  free(rrt->si[i]->cn);
4212  }
4213  free(rrt->si[i]);
4214  }
4215 
4216  if (rrt->ambient!=NULL)
4217  {
4218  DeleteBox(rrt->ambient);
4219  free(rrt->ambient);
4220  }
4221 
4222  free(rrt->si);
4223 
4224  if (rrt->tp!=NULL)
4225  free(rrt->tp);
4226 
4227  #if (_KDTREE==1)
4228  DeleteKDtree(rrt->treeS2G);
4229  if (rrt->mode==TWO_TREES)
4230  DeleteKDtree(rrt->treeG2S);
4231  #endif
4232  #if (_KDTREE==2)
4233  DeleteKDTree(rrt->treeS2G);
4234  if (rrt->mode==TWO_TREES)
4235  {
4236  DeleteKDTree(rrt->treeG2S);
4237 
4238  free(rrt->t1ToId);
4239  free(rrt->t2ToId);
4240  }
4241  #endif
4242 }
4243 
double GetRRTNodeCost(unsigned int i, Trrt *rrt)
Returns the cost associated with a node.
Definition: rrt.c:3593
TRRTSampleInfo ** si
Definition: rrt.h:347
unsigned int nFail
Definition: rrt.h:333
double * cn
Definition: rrt.h:307
boolean cBiRRT(Tparameters *pr, double *pg, double *time, double *pl, unsigned int *ns, double ***path, TRRTStatistics *grst, Trrt *rrt)
Extends a RRT until we reach a targed point.
Definition: rrt.c:3098
void PlotVect3d(unsigned int n, double *x, double *y, double *z, Tplot3d *p)
Adds a polyline to the current object.
Definition: plot3d.c:447
CBLAS_INLINE void ScaleVector(double f, unsigned int s, double *v)
Scales a vector.
Definition: basic_algebra.c:30
Statistics on the RRT construction.
Definition: rrt.h:201
void DeleteVector(void *vector)
Destructor.
Definition: vector.c:389
void AddEdgeToRRT(unsigned int i, unsigned int j, double c, Trrt *rrt)
Adds a neighbouring relation to an RRT.
Definition: rrt.c:781
unsigned int nCollisionChecks
Definition: rrt.h:232
Tinterval * GetBoxInterval(unsigned int n, Tbox *b)
Returns a pointer to one of the intervals defining the box.
Definition: box.c:270
unsigned int StepsToRoot(unsigned int sID, Trrt *rrt)
Computes the number of steps from a node to the root.
Definition: rrt.c:3719
boolean RRTSample(unsigned int samplingMode, unsigned int tree, double *goal, double *q_rand, TRRTStatistics *rst, Trrt *rrt)
Generates a random sample to expand the RRT.
Definition: rrt.c:1470
unsigned int id
Definition: rrt.h:249
unsigned int nRandom
Definition: rrt.h:227
void DeleteRRT(Trrt *rrt)
Destructor.
Definition: rrt.c:4201
unsigned int VectorSize(Tvector *vector)
Gets the number of elements in a vector.
Definition: vector.c:173
double temperature
Definition: rrt.h:332
void PrintRRTStatistics(Trrt *rrt, TRRTStatistics *rst)
Prints the summary of RRT statistics.
Definition: rrt.c:352
void SaveRRTNodes(Tparameters *pr, char *fname, boolean saveWithDummies, Trrt *rrt)
Stores the nodes of the RRT.
Definition: rrt.c:3883
#define CS_WD_ERROR_IN_SIMP_EQUATIONS(pr, p, wcs)
Computes the error in the simplified system for a given point.
Definition: wcs.h:509
#define CT_EPSILON
Numerical tolerance.
Definition: parameters.h:194
#define FALSE
FALSE.
Definition: boolean.h:30
unsigned int GetRRTParent(unsigned int i, Trrt *rrt)
Returns identifier of the parent of one of the nodes of the RRT.
Definition: rrt.c:3552
#define CS_WD_GENERATE_SIMPLIFIED_POINT(pr, p, r, wcs)
Generates a simplified point from an original one.
Definition: wcs.h:495
boolean BiRRTstar(Tparameters *pr, double *pg, unsigned int *it, double *times, double *costs, double *planningTime, double *pl, unsigned int *ns, double ***path, TRRTStatistics *grst, Trrt *rrt)
Optimal RRT on manifolds.
Definition: rrt.c:2583
double DistanceTopology(unsigned int s, unsigned int *tp, double *v1, double *v2)
Computes the distance of two points.
boolean ccRRT(Tparameters *pr, double *pg, double *time, double *pl, unsigned int *ns, double ***path, TRRTStatistics *grst, Trrt *rrt)
Extends a RRT until we reach a targed point.
Definition: rrt.c:2965
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
void GetRRTNNInBall(unsigned int tree, double *q_rand, double r, unsigned int *nn, unsigned int **n, Trrt *rrt)
Locates the all the sample closer than a given distance.
Definition: rrt.c:1653
Data structure to hold the information about the name of a file.
Definition: filename.h:271
void ArrayPi2Pi(unsigned int n, unsigned int *t, double *a)
Applies PI2PI to an array.
A pair of dubles.
Definition: vector.h:114
double RRTPathLength(Tparameters *pr, unsigned int sID, Trrt *rrt)
Path length from a sample to the root.
Definition: rrt.c:1181
void ConcatVectors(Tvector *vector1, Tvector *vector)
Concatenates two vectors.
Definition: vector.c:333
void ReWireRRTstar(Tparameters *pr, unsigned int id_new, double gamma, unsigned int nn, unsigned int *n, double *c, Tvector *steps, double *l, Trrt *rrt)
Rewires an RRT star.
Definition: rrt.c:2212
void SetRRTNodeInfo(unsigned int i, void *info, Trrt *rrt)
Changes the user info associated with a node.
Definition: rrt.c:3585
unsigned int nConvergenceError
Definition: rrt.h:216
boolean TransitionTestRRT(Tparameters *pr, unsigned int parent, double *q_next, double deltaStep, double *cost, double(*costF)(Tparameters *, boolean, double *, void *), void *costData, Trrt *rrt)
transition Test for Transition RRT
Definition: rrt.c:806
void WireRRTstar(Tparameters *pr, unsigned int id_new, unsigned int i_near, double gamma, unsigned int nn, unsigned int *n, double **c, double h, Theap *q, unsigned int *t, TRRTStatistics *rst, Trrt *rrt)
Wires a node to the RRT star.
Definition: rrt.c:2023
void * GetVectorElement(unsigned int i, Tvector *vector)
Returns a pointer to a vector element.
Definition: vector.c:270
unsigned int Steps2PathinRRT(Tparameters *pr, Tvector *steps, double *pl, double *pc, unsigned int *ns, double ***path, Trrt *rrt)
Defines a path from a vector of steps.
Definition: rrt.c:1093
unsigned int GetRRTNodeTree(unsigned int i, Trrt *rrt)
Returns the tree for a given node.
Definition: rrt.c:3539
#define CT_NFAIL_MAX
Number of successive trnasition test failues requiered before increasing the temperature.
Definition: parameters.h:460
#define RRT_VERBOSE
Vebosity of the RRT operations.
Definition: rrt.h:32
double g
Definition: rrt.h:301
unsigned int mode
Definition: rrt.h:349
void InitStatistics(unsigned int np, double v, Tstatistics *t)
Constructor.
Definition: statistics.c:21
CBLAS_INLINE double Norm(unsigned int s, double *v)
Computes the norm of a vector.
void SetRRTNodeCost(unsigned int i, double costp, double cost, Trrt *rrt)
Changes the cost associated with a node.
Definition: rrt.c:3609
#define CT_MAX_PLANNING_TIME
Maximum time for path planning.
Definition: parameters.h:475
void DifferenceVectorTopology(unsigned int s, unsigned int *tp, double *v1, double *v2, double *v)
Substracts two vectors.
void NewRRTHighCost(TRRTStatistics *rst)
A high cost configuration is reached.
Definition: rrt.c:268
void NewRRTQrandReached(TRRTStatistics *rst)
Random sample reached.
Definition: rrt.c:258
boolean AddNodeToRRT(Tparameters *pr, unsigned int tree, unsigned int i_near, double *sample, double *goal, unsigned int *lastSample, void *info, double costp, double cost, TRRTStatistics *rst, Trrt *rrt)
Adds a point to a RRT.
Definition: rrt.c:1868
CBLAS_INLINE void AccumulateVector(unsigned int s, double *v1, double *v2)
Adds a vector to another vectors.
Definition: basic_algebra.c:55
void NewRRTRandomSample(TRRTStatistics *rst)
New random sample.
Definition: rrt.c:303
#define CT_SAMPLING
Sampling mode.
Definition: parameters.h:563
double UpdateBiRRTSteps(Tvector *steps, Trrt *rrt)
Updates the current optimal path.
Definition: rrt.c:3356
Definition of the Tfilename type and the associated functions.
void LoadRRT(Tparameters *pr, Tfilename *fname, TAtlasBase *w, Trrt *rrt)
Defines a RRT from the information on a file.
Definition: rrt.c:4041
#define START2GOAL
One of the possible trees.
Definition: rrt.h:168
#define ONE_TREE
One of the modes for the RRT.
Definition: rrt.h:132
unsigned int tree
Definition: rrt.h:309
#define TEMPERATURE_INIT
Initial temperature used in Transition based rrt searches.
Definition: rrt.h:79
TAtlasBase * w
Definition: rrt.h:323
void InitPlot3d(char *name, boolean axes, int argc, char **arg, Tplot3d *p)
Constructor.
Definition: plot3d.c:41
unsigned int m
Definition: rrt.h:304
#define COST_EXT
File extension for arrays of costs.
Definition: filename.h:156
void NewRRTOutOfDomain(TRRTStatistics *rst)
The branch leaves the domain.
Definition: rrt.c:273
#define CT_GAMMA
Contant part of the search radius for nearest neightours in RRT*.
Definition: parameters.h:325
#define TRUE
TRUE.
Definition: boolean.h:21
void NewRRTStep(TRRTStatistics *rst)
New step in branch extension.
Definition: rrt.c:253
void Error(const char *s)
General error function.
Definition: error.c:80
void NewRRTTreeConnection(TRRTStatistics *rst)
New attempt to connect the two trees.
Definition: rrt.c:238
A color.
Definition: color.h:86
A RRT on a manifold.
Definition: rrt.h:322
unsigned int n
Definition: rrt.h:328
#define INIT_NUM_SAMPLES_RRT
Initial room for samples of an rrt.
Definition: rrt.h:125
unsigned int nStalled
Definition: rrt.h:222
boolean graph
Definition: rrt.h:351
void NewRRTBranch(TRRTStatistics *rst)
New branch creation.
Definition: rrt.c:228
boolean ccTRRT(Tparameters *pr, double *pg, double *time, double *pl, double *pc, unsigned int *ns, double ***path, double(*costF)(Tparameters *, boolean, double *, void *), void *costData, TRRTStatistics *grst, Trrt *rrt)
Extends a T-RRT until we reach a targed point.
Definition: rrt.c:2822
void RandomPointInBox(boolean *used, double *c, Tbox *b)
Returns the a random point along the selected dimensions.
Definition: box.c:706
#define CT_MAX_PLANNING_ITERATIONS
Maximum iterations for path planning.
Definition: parameters.h:483
unsigned int GetBoxNIntervals(Tbox *b)
Box dimensionality.
Definition: box.c:1016
double randomDouble()
Returns a random double in the [0,1] interval.
Definition: random.c:33
void NewRRTTooFar(TRRTStatistics *rst)
New large step.
Definition: rrt.c:288
void AddElement2Heap(unsigned int id, void *e, Theap *heap)
Adds an element to the heap.
Definition: heap.c:294
void DeleteDoublePair(void *a)
Destructor for pairs of doubles.
Definition: vector.c:77
Definition of a rrt on a manifold.
void ReverseConcatSamples(unsigned int nvs, unsigned int ns1, double **path1, unsigned int ns2, double **path2, unsigned int *ns, double ***path)
Reverses and concats a path.
Definition: samples.c:2727
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
A 3D plot.
Definition: plot3d.h:54
unsigned int ms
Definition: rrt.h:343
unsigned int GetRRTNN(unsigned int tree, double *q_rand, Trrt *rrt)
Locates the nearest sample in the tree of samples.
Definition: rrt.c:1546
#define CT_CUT_X
Limit of domain of the X dimension of 3d plots.
Definition: parameters.h:420
boolean RRTValidateSample(Tparameters *pr, double *q_rand, unsigned int tree, boolean expand2goal, double *goal, double l, double *h, unsigned int *i_near, TRRTStatistics *rst, Trrt *rrt)
Validates a sample generate with RRTSample.
Definition: rrt.c:1509
void RecursiveReWireRRTstar(Tparameters *pr, Theap *q, double *g, Tvector *steps, double *l, Trrt *rrt)
A rewire that is propagates as much as necessary over the graph.
Definition: rrt.c:2144
unsigned int * tp
Definition: rrt.h:340
void AddSample2Samples(unsigned int nv, double *sample, unsigned int nvs, boolean *systemVars, unsigned int *ms, unsigned int *ns, double ***path)
Adds a sample to a set of samples.
Definition: samples.c:672
double costp
Definition: rrt.h:287
boolean LessThanDoublePair(void *a, void *b, void *userData)
Comparison operator for paris of doubles.
Definition: heap.c:224
unsigned int ReconstructRRTPath(Tparameters *pr, unsigned int sID, double *pl, double *pc, unsigned int *ns, double ***path, Trrt *rrt)
Collects samples from the tree root to a given sample.
Definition: rrt.c:1076
double LowerLimit(Tinterval *i)
Gets the lower limit.
Definition: interval.c:79
Tbox * ambient
Definition: rrt.h:345
void GetRRTNNInBranch(unsigned int tree, unsigned int n1, unsigned int n2, unsigned int *n, unsigned int *nn, Trrt *rrt)
Locates the nearest sample in the tree to a branch.
Definition: rrt.c:1774
void SetRRTCostAndParent(unsigned int i, unsigned int p, double costp, double cost, Trrt *rrt)
Changes the cost and the parent associated with a node.
Definition: rrt.c:3620
unsigned int * GetRRTTopology(Trrt *rrt)
Returns a pointer to an array with the topology for each variable.
Definition: rrt.c:3638
void ResetVector(Tvector *vector)
Resets a vector.
Definition: vector.c:120
void UpdateCostToRoot(unsigned int sID, Trrt *rrt)
Updates the cost from a node to the root.
Definition: rrt.c:3658
void * GetHeapElement(unsigned int i, Theap *heap)
Returns a pointer to a heap element.
Definition: heap.c:331
double FirstInPair(TDoublePair *p)
The first element of a pair.
Definition: vector.c:55
unsigned int ns
Definition: rrt.h:342
#define TWO_TREES
One of the modes for the RRT.
Definition: rrt.h:141
#define CT_CUT_Z
Limit of domain of the Z dimension of 3d plots.
Definition: parameters.h:444
#define CS_WD_SIMP_INEQUALITIES_HOLD(pr, p, wcs)
Cheks if all inequalities hold.
Definition: wcs.h:207
boolean InDynamicDomain(unsigned int i, double *q, Trrt *rrt)
Checks if a sample is in the dynamic domaiin of a given node.
Definition: rrt.c:3473
#define KDTREE_SAMPLING
One of the possible sampling modes.
Definition: parameters.h:162
boolean AddBranchToRRT(Tparameters *pr, boolean ccRRT, unsigned int tree, unsigned int i_near, double *q_rand, double *goal, unsigned int *lastSample, double(*costF)(Tparameters *, boolean, double *, void *), void *costData, TRRTStatistics *rst, Trrt *rrt)
Extends a RRT as much as possible towards a given sample.
Definition: rrt.c:847
Definitions of constants and macros used in several parts of the cuik library.
unsigned int nNoEmptyBranch
Definition: rrt.h:206
void InitVector(unsigned int ele_size, void(*Copy)(void *, void *), void(*Delete)(void *), unsigned int max_ele, Tvector *vector)
Constructor.
Definition: vector.c:100
#define HEURISTIC_RRT_STAR
Whether to use an heuristic in AtlarRRT*.
Definition: rrt.h:54
unsigned int k
Definition: rrt.h:327
#define CS_WD_NEWTON_IN_SIMP(pr, p, wcs)
Applies a Newton procedure to move a point towads the manifold.
Definition: wcs.h:580
boolean parallel
Definition: rrt.h:337
Statistics associated with a solving process.
Definition: statistics.h:28
unsigned int nQrandReached
Definition: rrt.h:215
#define MOV_AVG_UP
Weight of new data when computing moving averages.
Definition: defines.h:451
boolean HeapEmpty(Theap *heap)
Checks if a heap is empty.
Definition: heap.c:289
boolean DynamicDomainRRT(Trrt *rrt)
TRUE if the dynamic domain is active.
Definition: rrt.c:3521
double dd
Definition: rrt.h:355
double RRTPathSteps(unsigned int sID, Tvector *path, Trrt *rrt)
Produces a vector with the nodes in a given branch.
Definition: rrt.c:3276
void DeleteHeap(Theap *heap)
Destructor.
Definition: heap.c:388
unsigned int nNoEmptyTreeConnection
Definition: rrt.h:209
void Warning(const char *s)
General warning function.
Definition: error.c:116
A table of parameters.
#define BOTHTREES
Used for samples in both trees.
Definition: rrt.h:183
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
double GetRRTNodeCostFromParent(unsigned int i, Trrt *rrt)
Returns the cost from the parent node, if defined.
Definition: rrt.c:3601
double UpperLimit(Tinterval *i)
Gets the uppser limit.
Definition: interval.c:87
double cost
Definition: rrt.h:289
void PlotRRT(char *fname, int argc, char **arg, Tparameters *pr, unsigned int xID, unsigned int yID, unsigned int zID, Trrt *rrt)
Pots a projection of a RRT.
Definition: rrt.c:3734
void InitRRT(Tparameters *pr, boolean parallel, boolean simp, double *ps, unsigned int mode, boolean graph, double *pg, unsigned int m, TAtlasBase *w, Trrt *rrt)
Defines a RRT from a given point.
Definition: rrt.c:1203
void CopyRRTStep(void *a, void *b)
Copy constructor for RRTSteps.
Definition: rrt.c:750
void UpdateTree(unsigned int sID, Trrt *rrt)
Updates the tree assignment a node to the root.
Definition: rrt.c:3663
boolean PathStart2GoalInRRT(Tparameters *pr, double *pgs, unsigned int l1, unsigned int l2, double *pl, double *pc, unsigned int *ns, double ***path, Trrt *rrt)
Determines the path from start to goal using an RRT.
Definition: rrt.c:3401
double * GetRRTNode(unsigned int i, Trrt *rrt)
Returns one of the nodes of the RRT.
Definition: rrt.c:3531
Type defining the equations on which the atlas is defined.
Definition: wcs.h:30
unsigned int RRTMemSize(Trrt *rrt)
Memory used by a given RRT.
Definition: rrt.c:3973
A generic vector.
Definition: vector.h:227
#define CS_WD_GET_SYSTEM_VARS(sv, wcs)
Gets the system variables.
Definition: wcs.h:238
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
#define M_2PI
2*Pi.
Definition: defines.h:100
#define SOL_EXT
File extension for solution files.
Definition: filename.h:138
#define EXPLORATION_RRT
Select between exploration and goal driven RRT.
Definition: rrt.h:98
unsigned int nOutOfDomain
Definition: rrt.h:218
#define CS_WD_REGENERATE_ORIGINAL_POINT(pr, p, o, wcs)
Completes an original point from a simplified one.
Definition: wcs.h:293
unsigned int m
Definition: rrt.h:325
unsigned int nCollision
Definition: rrt.h:220
double cost
Definition: rrt.h:250
void InitHeap(unsigned int ele_size, void(*Copy)(void *, void *), void(*Delete)(void *), boolean(*LessThan)(void *, void *, void *), void *userData, boolean hasIDs, unsigned int max_ele, Theap *heap)
Constructor.
Definition: heap.c:237
double CostToRoot(unsigned int sID, Trrt *rrt)
Computes the cost from a node to the root.
Definition: rrt.c:3643
unsigned int nDistanceIncreases
Definition: rrt.h:219
A box.
Definition: box.h:83
double ConnectSamples(Tparameters *pr, unsigned int *tp, boolean *sv, Tbox *domain, unsigned int m, unsigned int n, double *s1, double *s2, double md, boolean checkCollisions, TJacobian *sJ, boolean *reached, boolean *collision, double *lastSample, unsigned int *ns, double ***path, TAtlasBase *w)
Determines the connection between two points on the manifold.
Definition: samples.c:966
double ChangeBiRRTSteps(unsigned int l1, unsigned int l2, double c12, Tvector *steps, Trrt *rrt)
Changes the optimal path in a bidirectional RRT.
Definition: rrt.c:3297
void ReverseSamples(unsigned int ns, double **path)
Reverses a set of samples.
Definition: samples.c:2752
void BiRRTstarCloseIteration(unsigned int it, double l, double time, double gamma, double *times, double *costs, Trrt *rrt)
Prints information about the BiRRT* iteration.
Definition: rrt.c:2323
unsigned int GetRRTNumNodes(Trrt *rrt)
Number of nodes in the RRT.
Definition: rrt.c:3526
void * GetRRTNodeInfo(unsigned int i, Trrt *rrt)
Returns the user info associated with a node.
Definition: rrt.c:3577
#define MEM_DUP(_var, _n, _type)
Duplicates a previously allocated memory space.
Definition: defines.h:414
#define NO_UINT
Used to denote an identifier that has not been initialized.
Definition: defines.h:435
#define RRT_NN_TOPOLOGY
Set to 1 to use the topology in the search for nearest-neighbours.
Definition: rrt.h:117
CBLAS_INLINE void SumVectorScale(unsigned int s, double *v1, double w, double *v2, double *v)
Adds two vectors with a scale.
Definition: basic_algebra.c:86
unsigned int nTooFar
Definition: rrt.h:221
boolean IsRRTGraph(Trrt *rrt)
Identifies RRT with a graph structure.
Definition: rrt.c:1465
void NewRRTSampleRejection(TRRTStatistics *rst)
New sample rejection.
Definition: rrt.c:308
void NewRRTConvergenceError(TRRTStatistics *rst)
Convergence error.
Definition: rrt.c:263
void InitSamples(unsigned int *ms, unsigned int *ns, double ***path)
Initializes a set of samples.
Definition: samples.c:665
void SetRRTParent(unsigned int i, unsigned int p, Trrt *rrt)
Changes the parent for a given node.
Definition: rrt.c:3560
Step in a solution path.
Definition: rrt.h:248
double SquaredDistanceTopology(unsigned int s, unsigned int *tp, double *v1, double *v2)
Computes the squared distance of two points.
unsigned int AddStepToRRTstar(Tparameters *pr, unsigned int i_near, double *q_rand, double *goal, unsigned int *i_goal, TRRTStatistics *rst, Trrt *rrt)
Extend strategy for the RRT.
Definition: rrt.c:1970
void DeleteBox(void *b)
Destructor.
Definition: box.c:1283
#define CT_DYNAMIC_DOMAIN
Dynamic domain.
Definition: parameters.h:533
void DeleteRRTStatistics(TRRTStatistics *rst)
Destructor.
Definition: rrt.c:499
#define SOL_WITH_DUMMIES_EXT
File extension for solution files with dummies.
Definition: filename.h:144
void NewDoublePair(double f, double s, TDoublePair *p)
Constructor.
Definition: vector.c:49
unsigned int GetRRTMode(Trrt *rrt)
Identifies mode of the RRTs.
Definition: rrt.c:3468
void SetRRTTopology(Tparameters *pr, Trrt *rrt)
Initializes the topology array in the RRT.
Definition: rrt.c:757
void NewRRTCollisionCheck(TRRTStatistics *rst)
New collision check.
Definition: rrt.c:313
unsigned int ExtractMinElement(void *e, Theap *heap)
Extracts and removes the minimal element of a heap.
Definition: heap.c:356
double * samples
Definition: rrt.h:284
double DistanceTopologyMin(double t, unsigned int s, unsigned int *tp, double *v1, double *v2)
Computes the distance of two points, if it is below a given threshold.
#define MEM_EXPAND(_var, _n, _type)
Expands a previously allocated memory space.
Definition: defines.h:404
#define TWO_TREES_WITH_SWAP
One of the modes for the RRT.
Definition: rrt.h:154
double GetParameter(unsigned int n, Tparameters *p)
Gets the value for a particular parameter.
Definition: parameters.c:93
A generic binary heap.
Definition: heap.h:105
#define CS_WD_REGENERATE_SOLUTION_POINT(pr, p, r, wcs)
Compleates a solution point with the dummy variables.
Definition: wcs.h:480
#define CT_CUT_Y
Limit of domain of the Y dimension of 3d plots.
Definition: parameters.h:432
unsigned int nCores
Definition: rrt.h:336
void SaveRRTCosts(Tparameters *pr, char *fname, Trrt *rrt)
Stores the cost associated with the nodes of the RRT.
Definition: rrt.c:3934
void DeleteColor(Tcolor *c)
Destructor.
Definition: color.c:143
unsigned int parent
Definition: rrt.h:285
#define CS_WD_IN_COLLISION(f, pr, s, sPrev, wcs)
Checks if a configuration is in collision.
Definition: wcs.h:355
#define INF
Infinite.
Definition: defines.h:70
void NewRRTDistanceQrand(double dqr, TRRTStatistics *rst)
New distance to q_rand.
Definition: rrt.c:248
void RRTstarCloseIteration(unsigned int it, unsigned int id_goal, double time, double gamma, double *times, double *costs, Trrt *rrt)
Prints information about the RRT* iteration.
Definition: rrt.c:2294
#define CT_DELTA
Size of the steps in the path connecting two configurations.
Definition: parameters.h:282
double GetTRRTTemperature(Trrt *rrt)
Temperature of the T-RRT.
Definition: rrt.c:1460
#define CT_COEF_TEMP
Scale factor of the temperature parameter for Transition-based RRT.
Definition: parameters.h:451
#define CT_N_DOF
Dimensionality of the solution space for the mechanism at hand.
Definition: parameters.h:318
Auxiliary functions to deal with sets of samples.
#define GOAL2START
One of the possible trees.
Definition: rrt.h:176
void NewRRTCollision(TRRTStatistics *rst)
New collision.
Definition: rrt.c:283
Definition of basic randomization functions.
#define CS_WD_INIT_CD(pr, mt, wcs)
Initializes the collision detector.
Definition: wcs.h:308
double GetElapsedTime(Tstatistics *t)
Elapsed time.
Definition: statistics.c:92
void NewColor(double r, double g, double b, Tcolor *c)
Constructor.
Definition: color.c:14
void CopyDoublePair(void *a, void *b)
Copy constructor for pairs of doubles.
Definition: vector.c:71
boolean Bidirectional(Trrt *rrt)
Identifies bidirectional RRTs.
Definition: rrt.c:3462
void AccumulateRRTStatistics(TRRTStatistics *rst1, TRRTStatistics *rst2)
Accumulates two sets of RRT statistics.
Definition: rrt.c:318
void DeleteSamples(unsigned int ns, double **path)
Deletes the space used by a set of samples.
Definition: samples.c:3159
unsigned int nn
Definition: rrt.h:305
void AdjustDynamicDomain(unsigned int i, boolean collision, Trrt *rrt)
Sets the dynamic domain.
Definition: rrt.c:3481
void NewRRTNoEmptyBranch(TRRTStatistics *rst)
New no empty branch.
Definition: rrt.c:233
unsigned int nTreeConnection
Definition: rrt.h:208
unsigned int nRejections
Definition: rrt.h:229
#define CS_WD_GENERATE_SIMP_INITIAL_BOX(pr, b, wcs)
Computes the global box for the simplified system.
Definition: wcs.h:539
unsigned int nSample
Definition: rrt.h:224
Defines a interval.
Definition: interval.h:33
void * userInfo
Definition: rrt.h:310
boolean RRTstar(Tparameters *pr, double *pg, unsigned int *it, double *times, double *costs, double *planningTime, double *pl, unsigned int *ns, double ***path, TRRTStatistics *grst, Trrt *rrt)
Optimal RRT on manifolds.
Definition: rrt.c:2351
void InitRRTStatistics(TRRTStatistics *rst)
Init the RRT statistics.
Definition: rrt.c:195
unsigned int nHighCost
Definition: rrt.h:217
void NewRRTSample(TRRTStatistics *rst)
New sample.
Definition: rrt.c:298
unsigned int nStep
Definition: rrt.h:211
void NewRRTNoEmptyTreeConnection(TRRTStatistics *rst)
New non-void attempt to connect the two trees.
Definition: rrt.c:243
unsigned int StartNew3dObject(Tcolor *c, Tplot3d *p)
Start a composed object.
Definition: plot3d.c:157
void DeleteStatistics(Tstatistics *t)
Destructor.
Definition: statistics.c:274
Information for each sample in a RRT.
Definition: rrt.h:283
#define DIVERGED
One of the possible outputs of the Newton iteration.
Definition: cuiksystem.h:111
void NewRRTDistanceIncreases(TRRTStatistics *rst)
The distance to q_rand increase.
Definition: rrt.c:278
unsigned int n
Definition: rrt.h:202
double dQrand
Definition: rrt.h:212
#define CS_WD_GET_SIMP_TOPOLOGY(pr, tp, wcs)
Gets the simplified variable topology.
Definition: wcs.h:450
double GetDynamicDomainRadius(unsigned int i, Trrt *rrt)
Returns the current dynamic domain radius for a given sample.
Definition: rrt.c:3513
void Close3dObject(Tplot3d *p)
Closes a composed object.
Definition: plot3d.c:171
void UpdateCostAndTree(unsigned int sID, Trrt *rrt)
A combination of UpdateCostToRoot and UpdateTree.
Definition: rrt.c:3692
unsigned int nBranch
Definition: rrt.h:205
double ddr
Definition: rrt.h:299
void UpdateHeapElement(unsigned int id, void *e, Theap *heap)
Updates the position of an element in the heap.
Definition: heap.c:308
void ClosePlot3d(boolean quit, double average_x, double average_y, double average_z, Tplot3d *p)
Destructor.
Definition: plot3d.c:473
#define CT_MAX_NODES_RRT
Maximum number of nodes in an RRT.
Definition: parameters.h:497
unsigned int NewVectorElement(void *e, Tvector *vector)
Adds an element to the vector.
Definition: vector.c:216
#define TOPOLOGY_S
One of the possible topologies.
Definition: defines.h:139
double delta
Definition: rrt.h:330
boolean PointInBoxTopology(boolean *used, boolean update, unsigned int n, double *v, double tol, unsigned int *tp, Tbox *b)
Checks if a point is included in a(sub-) box.
Definition: box.c:374
void NewRRTStalled(TRRTStatistics *rst)
New stalled branch.
Definition: rrt.c:293
void SaveRRT(Tfilename *fname, Trrt *rrt)
Stores the RRT information on a file.
Definition: rrt.c:3990
unsigned int * n
Definition: rrt.h:306
#define CS_WD_ORIGINAL_IN_COLLISION(pr, o, oPrev, wcs)
Checks if a configuration is in collision.
Definition: wcs.h:397
#define MOV_AVG_DOWN
Weight of new data when computing moving averages.
Definition: defines.h:467