atlasrrt.c
Go to the documentation of this file.
1 #include "atlasrrt.h"
2 
3 #include "chart.h"
4 #include "filename.h"
5 #include "random.h"
6 #include "algebra.h"
7 #include "samples.h"
8 #include "vector.h"
9 #include "heap.h"
10 
11 #include "boolean.h"
12 
13 #include <string.h>
14 #include <math.h>
15 
31 #define ADD_ALL 0
32 
38 #define ADD_LAST 1
39 
46 #define ADD_LAST_NO_REP 2
47 
53 #define ADD_NONE 3
54 
67 
81 
91 
102 
113 void NewAtlasRRTDistanceQrand(double dqr,TAtlasRRTStatistics *arst);
114 
123 
133 
142 
152 
162 
172 
183 
193 
204 
215 
227 
237 
250 
260 
270 
279 
298 
305 
312 
319 
320 
321 /******************************************************************************/
322 /******************************************************************************/
323 /******************************************************************************/
324 
326 {
327  if (arst!=NULL)
328  {
329  arst->n=0;
330 
331  arst->nBranch=0;
332  arst->nNoEmptyBranch=0;
333 
334  arst->nTreeConnection=0;
335  arst->nNoEmptyTreeConnection=0;
336 
337  arst->nStep=0;
338  arst->dQrand=0.0;
339 
340  arst->nQrandReached=0;
341  arst->nNotInDomain=0;
342  arst->nCollision=0;
343  arst->nTooFar=0;
344  arst->nTooLong=0;
345  arst->nOverlap=0;
346 
347  arst->nErrorNewChart=0;
348  arst->nNoConvergent=0;
349  arst->nOutOfChart=0;
350  arst->nLargeCurvature=0;
351  arst->nDirLargeCurvature=0;
352 
353  arst->nStepReduction=0;
354 
355  arst->nSample=0;
356  arst->nChart=0;
357  arst->nNoConnect=0;
358  arst->nSingular=0;
359 
360  arst->nRandom=0;
361  arst->nRejections=0;
362 
363  arst->nCollisionChecks=0;
364  }
365 }
366 
368 {
369  if (arst!=NULL) arst->nBranch++;
370 }
371 
373 {
374  if (arst!=NULL) arst->nNoEmptyBranch++;
375 }
376 
378 {
379  if (arst!=NULL) arst->nTreeConnection++;
380 }
381 
383 {
384  if (arst!=NULL) arst->nNoEmptyTreeConnection++;
385 }
386 
388 {
389  if (arst!=NULL) arst->dQrand+=dqr;
390 }
391 
393 {
394  if (arst!=NULL) arst->nStep++;
395 }
396 
398 {
399  if (arst!=NULL) arst->nNoConvergent++;
400 }
401 
403 {
404  if (arst!=NULL) arst->nQrandReached++;
405 }
406 
408 {
409  if (arst!=NULL) arst->nNotInDomain++;
410 }
411 
413 {
414  if (arst!=NULL) arst->nCollision++;
415 }
416 
418 {
419  if (arst!=NULL) arst->nTooLong++;
420 }
421 
423 {
424  if (arst!=NULL) arst->nTooFar++;
425 }
426 
428 {
429  if (arst!=NULL) arst->nOverlap++;
430 }
431 
433 {
434  if (arst!=NULL) arst->nOutOfChart++;
435 }
436 
438 {
439  if (arst!=NULL) arst->nErrorNewChart++;
440 }
441 
443 {
444  if (arst!=NULL) arst->nLargeCurvature++;
445 }
446 
448 {
449  if (arst!=NULL) arst->nDirLargeCurvature++;
450 }
451 
453 {
454  if (arst!=NULL) arst->nStepReduction++;
455 }
456 
458 {
459  if (arst!=NULL) arst->nSample++;
460 }
461 
463 {
464  if (arst!=NULL) arst->nChart++;
465 }
466 
468 {
469  if (arst!=NULL) arst->nNoConnect++;
470 }
471 
473 {
474  if (arst!=NULL) arst->nSingular++;
475 }
476 
478 {
479  if (arst!=NULL) arst->nRandom++;
480 }
481 
483 {
484  if (arst!=NULL) arst->nRejections++;
485 }
486 
488 {
489  if (arst!=NULL) arst->nCollisionChecks++;
490 }
491 
493 {
494  if ((arst1!=NULL)&&(arst2!=NULL))
495  {
496  if (arst1->n==0)
497  arst2->n++;
498  else
499  arst2->n+=arst1->n;
500 
501  arst2->nBranch+=arst1->nBranch;
502  arst2->nNoEmptyBranch+=arst1->nNoEmptyBranch;
503 
504  arst2->nTreeConnection+=arst1->nTreeConnection;
506 
507  arst2->nStep+=arst1->nStep;
508  arst2->dQrand+=arst1->dQrand;
509 
510  arst2->nQrandReached+=arst1->nQrandReached;
511  arst2->nNotInDomain+=arst1->nNotInDomain;
512  arst2->nCollision+=arst1->nCollision;
513  arst2->nTooLong+=arst1->nTooLong;
514  arst2->nTooFar+=arst1->nTooFar;
515  arst2->nOverlap+=arst1->nOverlap;
516 
517  arst2->nErrorNewChart+=arst1->nErrorNewChart;
518  arst2->nNoConvergent+=arst1->nNoConvergent;
519  arst2->nOutOfChart+=arst1->nOutOfChart;
520  arst2->nLargeCurvature+=arst1->nLargeCurvature;
521  arst2->nDirLargeCurvature+=arst1->nDirLargeCurvature;
522 
523  arst2->nStepReduction+=arst1->nStepReduction;
524 
525  arst2->nSample+=arst1->nSample;
526  arst2->nChart+=arst1->nChart;
527 
528  arst2->nNoConnect+=arst1->nNoConnect;
529  arst2->nSingular+=arst1->nSingular;
530 
531  arst2->nRandom+=arst1->nRandom;
532  arst2->nRejections+=arst1->nRejections;
533 
534  arst2->nCollisionChecks+=arst1->nCollisionChecks;
535  }
536 }
537 
539 {
540  if (arst!=NULL)
541  {
542  unsigned int m,nExt;
543 
544  if (arst->n==0)
545  arst->n=1;
546 
547  nExt=arst->nBranch+arst->nTreeConnection;
548 
549  fprintf(stderr,"%% **************************************************\n");
550  if (arst->n>1)
551  fprintf(stderr,"AtlasRRT Statistics (averaged over %u repetitions)\n",arst->n);
552  else
553  fprintf(stderr,"AtlasRRT Statistics\n\n");
554  fprintf(stderr," Num. random samples : %.2f\n",
555  (double)arst->nRandom/(double)arst->n);
556  fprintf(stderr," Num. rejected random samples : %.2f (%.2f)\n",
557  (double)arst->nRejections/(double)arst->n,
558  (double)arst->nRejections/(double)arst->nRandom);
559  fprintf(stderr," Num. accepted random samples : %.2f (%.2f)\n",
560  (double)(arst->nRandom-arst->nRejections)/(double)arst->n,
561  (double)(arst->nRandom-arst->nRejections)/(double)arst->nRandom);
562 
563  /* if the chart sampling radius is potentially different for each chart
564  we print information about the extreme/average chart sampling radius. */
565  #if ((ADJUST_SR)||(ADJUST_SA==1))
566  if ((arst->n==1)&&(ar!=NULL))
567  {
568  unsigned int i;
569  double miSr,maSr,avSr,sr;
570 
571  miSr=+INF;
572  maSr=-INF;
573  avSr=0.0;
574  for(i=0;i<ar->nc;i++)
575  {
577  if (sr<miSr)
578  miSr=sr;
579  if (sr>maSr)
580  maSr=sr;
581  avSr+=sr;
582  }
583  fprintf(stderr," Sampling radius info : %.2f <-- %.2f --> %.2f\n",
584  miSr,avSr/(double)ar->nc,maSr);
585  }
586  #endif
587 
588  if ((arst->n==1)&&(ar!=NULL)&&(DynamicDomainRRT(&(ar->rrt))))
589  {
590  unsigned int i,n;
591  double miDD,maDD,avDD,r;
592 
593  miDD=+INF;
594  maDD=-INF;
595  avDD=0.0;
596  n=0;
597  for(i=0;i<ar->ns;i++)
598  {
599  r=GetDynamicDomainRadius(i,&(ar->rrt));
600  if (r>0)
601  {
602  if (r<miDD)
603  miDD=r;
604  if (r>maDD)
605  maDD=r;
606  avDD+=r;
607  n++;
608  }
609  }
610  if (n==0)
611  fprintf(stderr," No dynamic domain effect.");
612  else
613  fprintf(stderr," Dynamic domain radius : %.2f <-- %.2f --> %.2f (%u/%u)\n",
614  miDD,avDD/(double)n,maDD,n,ar->ns);
615  }
616  fprintf(stderr," Average distance to Qrand : %.2f\n",
617  arst->dQrand/(double)arst->nBranch);
618 
619  if (arst->nTreeConnection>0)
620  {
621  fprintf(stderr," Num. direct RRT extensions : %.2f\n",
622  (double)arst->nBranch/(double)arst->n);
623  m=arst->nNoEmptyBranch;
624  fprintf(stderr," Num. no-empty direct extensions : %.2f (%.2f)\n",
625  (double)m/(double)arst->n,
626  (double)m/(double)arst->nBranch);
627 
628  fprintf(stderr," Num. RRT connections : %.2f\n",
629  (double)arst->nTreeConnection/(double)arst->n);
630  m=arst->nNoEmptyTreeConnection;
631  fprintf(stderr," Num. no-empty RRT connections : %.2f (%.2f)\n",
632  (double)m/(double)arst->n,
633  (double)m/(double)arst->nTreeConnection);
634 
635  fprintf(stderr," Total branches : %.2f\n",
636  (double)nExt/(double)arst->n);
637  m=(arst->nNoEmptyBranch+arst->nNoEmptyTreeConnection);
638  fprintf(stderr," Total no-empty branches : %.2f (%.2f)\n",
639  (double)m/(double)arst->n,
640  (double)m/(double)nExt);
641  }
642  else
643  {
644  fprintf(stderr," Total branches : %.2f\n",
645  (double)arst->nBranch/(double)arst->n);
646  m=arst->nNoEmptyBranch;
647  fprintf(stderr," Total no-empty branches : %.2f (%.2f)\n",
648  (double)m/(double)arst->n,
649  (double)m/(double)arst->nBranch);
650  }
651  fprintf(stderr," Reasons to stop the branch/connection\n");
652  m=arst->nQrandReached;
653  fprintf(stderr," q_rand reached : %.2f (%.2f)\n",
654  (double)m/(double)arst->n,
655  (double)m/(double)nExt);
656 
657  m=arst->nNotInDomain;
658  fprintf(stderr," Out of domain : %.2f (%.2f)\n",
659  (double)m/(double)arst->n,
660  (double)m/(double)nExt);
661 
662  m=arst->nCollision;
663  fprintf(stderr," Collision : %.2f (%.2f)\n",
664  (double)m/(double)arst->n,
665  (double)m/(double)nExt);
666 
667  m=arst->nTooLong;
668  fprintf(stderr," Long branch : %.2f (%.2f)\n",
669  (double)m/(double)arst->n,
670  (double)m/(double)nExt);
671 
672  m=arst->nTooFar;
673  fprintf(stderr," Too far from q_near : %.2f (%.2f)\n",
674  (double)m/(double)arst->n,
675  (double)m/(double)nExt);
676 
677  m=arst->nOverlap;
678  fprintf(stderr," Avoid overlap : %.2f (%.2f)\n",
679  (double)m/(double)arst->n,
680  (double)m/(double)nExt);
681 
682  m=arst->nSingular;
683  fprintf(stderr," Singularity : %.2f (%.2f)\n",
684  (double)m/(double)arst->n,
685  (double)m/(double)nExt);
686 
687  fprintf(stderr," Num. extension steps : %.2f\n",
688  (double)arst->nStep/(double)arst->n);
689  fprintf(stderr," Num. steps per branch : %.2f\n",
690  (double)arst->nStep/(double)nExt);
691  fprintf(stderr," Num. step reductions : %.2f\n",
692  (double)arst->nStepReduction/(double)arst->n);
693 
694  fprintf(stderr," Num. collision checks : %.2f\n",
695  (double)arst->nCollisionChecks/(double)arst->n);
696 
697 
698  fprintf(stderr," Num. samples in (bi)RRT : %.2f\n",
699  (double)arst->nSample/(double)arst->n);
700  fprintf(stderr," Samples per non-empty extens. : %.2f\n",
701  (double)arst->nSample/(double)(arst->nNoEmptyBranch+arst->nNoEmptyTreeConnection));
702 
703  fprintf(stderr," Num. charts : %.2f\n",
704  (double)arst->nChart/(double)arst->n);
705 
706  fprintf(stderr," Reasons to create charts\n");
707 
708  m=arst->nErrorNewChart;
709  fprintf(stderr," Error defining chart : %.2f (%.2f)\n",
710  (double)m/(double)arst->n,
711  (double)m/(double)arst->nChart);
712 
713  m=arst->nOutOfChart;
714  fprintf(stderr," Out of radius : %.2f (%.2f)\n",
715  (double)m/(double)arst->n,
716  (double)m/(double)arst->nChart);
717 
718  m=arst->nNoConvergent;
719  fprintf(stderr," Large or convergence error : %.2f (%.2f)\n",
720  (double)m/(double)arst->n,
721  (double)m/(double)arst->nChart);
722 
723  #if (GET_ATLASRRT_GLOBAL_CURV_CHECK)
724  m=arst->nLargeCurvature;
725  fprintf(stderr," Curvature error : %.2f (%.2f)\n",
726  (double)m/(double)arst->n,
727  (double)m/(double)arst->nChart);
728  #endif
729 
730  m=arst->nDirLargeCurvature;
731  fprintf(stderr," Directional curvature error : %.2f (%.2f)\n",
732  (double)m/(double)arst->n,
733  (double)m/(double)arst->nChart);
734 
735  m=arst->nNoConnect;
736  fprintf(stderr," Num. no-intersect with parent : %.2f (%.2f)\n",
737  (double)m/(double)arst->n,
738  (double)m/(double)arst->nChart);
739 
740  fprintf(stderr," Samples per chart : %.2f\n",
741  (double)arst->nSample/(double)arst->nChart);
742  }
743 }
744 
746 {
747 }
748 
749 
750 /******************************************************************************/
751 /******************************************************************************/
752 /******************************************************************************/
753 
754 
828 double AddBranchToAtlasRRT(Tparameters *pr,unsigned int it,
829  unsigned int addMode,boolean revisitCharts,
830  boolean checkCollisions,boolean onManifold,
831  boolean explorationSample,
832  double maxLength,unsigned int i_near,
833  double *origRandSample,
834  double *goalSample,void *st,
835  unsigned int *lastSampleID,
836  boolean *reachedQRand,boolean *reachedGoal,
837  unsigned int *ns,double ***path,
838  double (*costF)(Tparameters*,boolean,double*,void*),
839  void *costData,
840  Tatlasrrt *ar);
841 
902 void NewTemptativeSample(Tparameters *pr,unsigned int it,unsigned int *nChanges,
903  boolean revisitCharts,boolean chartCreated,
904  boolean checkCollisions,boolean onManifold,
905  TSampleInfo *currentSampleInfo,double *currentParam,
906  double *origRandSample,
907  unsigned int *randChart,double *randParam,double *randSample,
908  double currentDelta,double d,double *deltaParam,
909  unsigned int *nextChart,double *nextParam,double *nextSample,
910  void *st,double (*costF)(Tparameters*,boolean,double*,void*),
911  void *costData,double *cost,boolean *blocked,
912  boolean *inCollision,boolean *valid,
913  Tatlasrrt *ar);
914 
938 double AddSample2AtlasRRT(Tparameters *pr,unsigned int tree,
939  unsigned int *currentID,
940  unsigned int nextChart,double *nextParam,double *nextSample,
941  double dp,double cost,Tatlasrrt *ar);
961 boolean AddChart2AtlasRRT(Tparameters *pr,unsigned int tree,unsigned int it,
962  TSampleInfo *currentSampleInfo,
963  boolean* intersectParent,Tatlasrrt *ar);
964 
976 void PopulateWithSamples(Tparameters *pr,unsigned int id,Tatlasrrt *ar);
977 
987 void AddChart2Tree(unsigned int tree,unsigned int chartId,Tatlasrrt* ar);
988 
1019 boolean PointTowardRandSample(unsigned int cId,double d,double *t,
1020  unsigned int samplingMode,
1021  boolean onManifold,double *origRandSample,
1022  unsigned int *randChart,
1023  double *randParam,double *randSample,
1024  double *deltaParam,Tatlasrrt* ar);
1025 
1043 unsigned int ReconstructAtlasRRTPath(Tparameters *pr,unsigned int sID,
1044  double *pl,unsigned int *ns,
1045  double ***path,Tatlasrrt *ar);
1046 
1065 unsigned int Steps2PathinAtlasRRT(Tparameters *pr,Tvector *steps,double *pl,double* pc,
1066  unsigned int *ns,double ***path,Tatlasrrt *ar);
1067 
1079 void SmoothPathInAtlasRRT(Tparameters *pr,unsigned int sID,Tatlasrrt* ar);
1080 
1100 unsigned int AddStepToAtlasRRTstar(Tparameters* pr,
1101  unsigned int it,boolean expand2Goal,
1102  unsigned int i_near,double *q_rand,
1103  unsigned int *id_goal,double *goal,
1104  TAtlasRRTStatistics *arst,
1105  Tatlasrrt *ar);
1106 
1131 void WireAtlasRRTstar(Tparameters *pr,
1132  unsigned int id_new,unsigned int i_near,double gamma,
1133  unsigned int nn,unsigned int *n,double **c,
1134  double h,Theap *q,unsigned int *t,
1135  TAtlasRRTStatistics *arst,Tatlasrrt *ar);
1136 
1159  unsigned int id_new,double gamma,
1160  unsigned int nn,unsigned int *n,double *c,
1161  Tvector *steps,double *l,
1162  TAtlasRRTStatistics *arst,Tatlasrrt *ar);
1163 
1179 void AtlasRRTstarCloseIteration(unsigned int it,unsigned int id_goal,
1180  double time,double gamma,
1181  double *times,double *costs,
1182  Tatlasrrt *ar);
1183 
1199 void AtlasBiRRTstarCloseIteration(unsigned int it,double l,
1200  double time,double gamma,
1201  double *times,double *costs,
1202  Tatlasrrt *ar);
1203 
1213 void SaveAtlasRRTSampleInfo(FILE *f,TSampleInfo *si,Tatlasrrt *ar);
1214 
1224 void SaveAtlasRRTChartInfo(FILE *f,TChartInfo *ci,Tatlasrrt *ar);
1225 
1226 
1236 void LoadAtlasRRTSampleInfo(FILE *f,TSampleInfo *si,Tatlasrrt *ar);
1237 
1247 void LoadAtlasRRTChartInfo(FILE *f,TChartInfo *ci,Tatlasrrt *ar);
1248 
1268 void PlotQrand(Tparameters *pr,char *prefix,unsigned int inear,
1269  unsigned int c_rand,double *t_rand,double *q_rand,
1270  unsigned int xID,unsigned int yID,unsigned int zID,
1271  Tatlasrrt *ar);
1272 
1291 void PlotConnection(Tparameters *pr,char *prefix,
1292  unsigned int target,unsigned int near,unsigned int end,
1293  unsigned int xID,unsigned int yID,unsigned int zID,
1294  Tatlasrrt *ar);
1295 
1296 /******************************************************************************/
1297 /******************************************************************************/
1298 /******************************************************************************/
1299 
1300 double AddBranchToAtlasRRT(Tparameters *pr,unsigned int it,
1301  unsigned int addMode,boolean revisitCharts,
1302  boolean checkCollisions,boolean onManifold,
1303  boolean explorationSample,
1304  double maxLength,unsigned int i_near,
1305  double *origRandSample,
1306  double *goalSample,void *st,
1307  unsigned int *lastSampleID,
1308  boolean *reachedQRand,boolean *reachedGoal,
1309  unsigned int *ns,double ***path,
1310  double (*costF)(Tparameters*,boolean,double*,void*),
1311  void *costData,Tatlasrrt *ar)
1312 {
1313  /*
1314  In this function
1315  current -> refers to the sample already in the altlasRRT that
1316  will be extended with a new child
1317  rand -> is the sample to reach in this particular expansion
1318  goal -> is the final point to reach in the whole tree.
1319  next -> is the sample to add just after current.
1320 
1321  for each one of the previous we have
1322  param -> are the parametes on the corresponding chart
1323  sample -> is the corresponding point on the manifold.
1324  */
1325 
1326  boolean blocked,collision,valid,tooFar,init,intersectParent,canInitChart,noRep;
1327  double epsilon,d,dg,dqr,dnn; /* current branch lenght. */
1328 
1329  /* Next sample */
1330  unsigned int nextChart; /* Chart to which this sample belongs to. */
1331  double *currentParam; /* The parameters for the current sample. Can be different
1332  from those stored in the AtlasRRT */
1333  double *nextParam; /* Parameters in the chart. */
1334  double *nextSample; /* Point on manifolf for next sample. */
1335 
1336  double *deltaParam; /* Normal vector indicating the direction toward
1337  q_rand in the current chart. */
1338 
1339  /* Interpolation step */
1340  double delta; /* Max step size. */
1341  double currentDelta; /* Current size. */
1342  double distQrand; /* Initial distance to q_rand = max length for the
1343  new branch. */
1344  double *nnSample; /* Sample from where to extend the tree. */
1345  TSampleInfo *currentSampleInfo;
1346  unsigned int randChart;
1347  double *randParam;
1348  double dist,maxDist;
1349  TSampleInfo tmpSI; /* Temporary sample info used when addMode!=ADD_ALL */
1350  double *randSample;
1351  boolean tmpQrandReached;
1352  unsigned int ms,nn;
1353  double cost;
1354  unsigned int maxNodes;
1355  unsigned int samplingMode;
1356  unsigned int nChanges; /* only one transition between charts is allowed */
1357  unsigned int tree;
1358 
1359  tree=GetRRTNodeTree(i_near,&(ar->rrt));
1360 
1361  if (i_near==NO_UINT)
1362  Error("Extending a branch from nowhere");
1363 
1364  epsilon=GetParameter(CT_EPSILON,pr);
1365  delta=GetParameter(CT_DELTA,pr);
1366  maxNodes=(unsigned int)GetParameter(CT_MAX_NODES_RRT,pr);
1367  samplingMode=(unsigned int)GetParameter(CT_SAMPLING,pr);
1368 
1369  nnSample=ar->si[i_near]->s;
1370  distQrand=DistanceTopology(ar->m,ar->tp,nnSample,origRandSample);
1371  #if (ATLASRRT_VERBOSE)
1372  if (distQrand<epsilon)
1373  Warning("Repeated points in the AtlasRRT?");
1374  #endif
1375 
1376  nChanges=0;
1377 
1378  /* Interpolation parameters */
1379  currentDelta=delta;
1380 
1381  /* Identifier for current point, used to retive current Chart/Param/Sample
1382  from the AtlasRRT structure */
1383  *lastSampleID=i_near;
1384 
1385  blocked=FALSE;
1386  tooFar=FALSE;
1387  collision=FALSE;
1388  cost=0;
1389  #if (EXPLORATION_RRT)
1390  *reachedGoal=FALSE;
1391  #else
1392  /* The projection on the manifold can be larger than that
1393  on the tangent space */
1394  if (goalSample!=NULL)
1395  {
1396  dg=DistanceTopology(ar->m,ar->tp,nnSample,goalSample);
1397  *reachedGoal=(dg<delta);
1398  }
1399  else
1400  *reachedGoal=FALSE;
1401  #endif
1402  if (onManifold)
1403  *reachedQRand=(distQrand<epsilon);
1404  else
1405  *reachedQRand=FALSE;
1406  tmpQrandReached=*reachedQRand;
1407 
1408  if ((ns!=NULL)&&(path!=NULL))
1409  InitSamples(&ms,ns,path);
1410 
1411  if ((*reachedQRand)||(*reachedGoal))
1412  {
1413  init=FALSE; /* not data structre was initialized */
1414  maxDist=0.0;
1415  d=0.0;
1416  }
1417  else
1418  {
1419  /* If the goal sample is not already reached, we prepare for the
1420  branch extension */
1421  init=TRUE;
1422 
1423  /* Each sample can have many different representations due to the
1424  ambient space topology. Select the one that is closer to
1425  the nearest neighbour. In this wqy we ensure to move towards
1426  the randSample along the shortest path. */
1427  if (ar->tp!=NULL)
1428  {
1429  DifferenceVectorTopology(ar->m,ar->tp,origRandSample,nnSample,origRandSample);
1430  AccumulateVector(ar->m,nnSample,origRandSample);
1431  }
1432  /* the nn can have different parameters in the same tangent space. We store
1433  the ones closer to its chart center (obtained using the topology), but
1434  the direct parameters are better to extend the branch. */
1435  NEW(currentParam,ar->k,double);
1436  Manifold2Chart(nnSample,NULL,currentParam,
1437  GetAtlasChart(ar->si[i_near]->c,&(ar->atlas)));
1438 
1439  d=0.0;
1440  /* get a copy of the random sample since we will modify it while the branch
1441  is extended */
1442  NEW(randSample,ar->m,double);
1443  memcpy(randSample,origRandSample,ar->m*sizeof(double));
1444 
1445  if (maxLength<=0.0)
1446  {
1447  dist=distQrand;
1448  maxDist=2*distQrand;
1449  }
1450  else
1451  {
1452  dist=maxLength;
1453  maxDist=maxLength;
1454  }
1455 
1456  /* if the targed is on the manifold we allow for some tolerance in
1457  the maximum distance from nn to end of path. */
1458  if (onManifold)
1459  distQrand*=1.1;
1460 
1461  /* Detemine the direction of motion toward q_rand from the current sample */
1462  NEW(deltaParam,ar->k,double);
1463 
1464  /* Space for next samples */
1465  NEW(nextParam,ar->k,double);
1466  NEW(nextSample,ar->m,double);
1467 
1468  /* Space for the parameters of q_rand */
1469  NEW(randParam,ar->k,double);
1470 
1471  if (addMode==ADD_ALL)
1472  currentSampleInfo=ar->si[i_near];
1473  else
1474  {
1475  /* Get a copy of the info for sample i_near (many fields are not used
1476  but copied for completeness) */
1477  tmpSI.id=NO_UINT;
1478  NEW(tmpSI.s,ar->m,double);
1479  memcpy(tmpSI.s,ar->si[i_near]->s,ar->m*sizeof(double));
1480  NEW(tmpSI.t,ar->k,double);
1481  memcpy(tmpSI.t,ar->si[i_near]->t,ar->k*sizeof(double));
1482  tmpSI.pc=ar->si[i_near]->pc;
1483  tmpSI.c=ar->si[i_near]->c;
1484  tmpSI.generateChart=ar->si[i_near]->generateChart;
1485  tmpSI.lsc=ar->si[i_near]->lsc;
1486 
1487  /* And the sample from where to extend is the temporal one that will
1488  be modified as we grow the branch */
1489  currentSampleInfo=&tmpSI;
1490  }
1491 
1492  blocked=PointTowardRandSample(currentSampleInfo->c,dist,currentParam,
1493  samplingMode,onManifold,origRandSample,
1494  &randChart,randParam,randSample,deltaParam,ar);
1495  }
1496 
1497  #if (_DEBUG>1)
1498  printf(" Adding branch to RRT from sample %u (chart %u)\n",i_near,ar->si[i_near]->c);
1499  #endif
1500 
1501  /* We stop if blocked, after a maximum dist extansion or
1502  if it gets farther than the ambient dist to the randSample. This
1503  is measured in two ways: the distance traveled over the monifold (d)
1504  and the Euclidian distance from the current sample to q_near (tooFar).
1505  The new branch should not scape the ball of radious maxDist centered
1506  at q_near. We allow for a larger displacement over the manifold to
1507  account for curvature effects.
1508  */
1509  while ((!blocked)&&(!collision)&&(d<maxDist)&&(!tmpQrandReached)&&(!(*reachedGoal))&&
1510  (!(*reachedQRand))&&(!tooFar)&&(ar->ns<maxNodes))
1511  {
1512  NewTemptativeSample(pr,it,&nChanges,
1513  revisitCharts,explorationSample,checkCollisions,onManifold,
1514  currentSampleInfo,currentParam,origRandSample,
1515  &randChart,randParam,randSample,
1516  currentDelta,dist-d,deltaParam,
1517  &nextChart,nextParam,nextSample,
1518  st,costF,costData,&cost,&blocked,&collision,&valid,ar);
1519 
1520  if (!blocked)
1521  {
1522  if (!valid)
1523  {
1524  if (currentSampleInfo->generateChart)
1525  {
1526  currentDelta*=0.5;
1527  #if (GET_ATLASRRT_STATISTICS)
1529  #endif
1530  }
1531  else
1532  {
1533  canInitChart=AddChart2AtlasRRT(pr,tree,it,currentSampleInfo,
1534  &intersectParent,ar);
1535  if (canInitChart)
1536  {
1537  #if (GET_ATLASRRT_STATISTICS)
1539  if(!intersectParent)
1541  #endif
1542 
1543  Manifold2Chart(currentSampleInfo->s,NULL,currentParam,
1544  GetAtlasChart(currentSampleInfo->c,&(ar->atlas)));
1545  blocked=PointTowardRandSample(currentSampleInfo->c,dist-d,
1546  currentParam,samplingMode,
1547  onManifold,origRandSample,
1548  &randChart,randParam,randSample,
1549  deltaParam,ar);
1550  #if (GET_ATLASRRT_STATISTICS)
1551  if (blocked)
1553  #endif
1554  /* Samples that trigger the creation of a chart are considered
1555  exploration samples */
1556  explorationSample=TRUE;
1557  }
1558  else
1559  {
1560  /* Stop the branch extension.
1561  TODO: Implement a more sophisticated stratetgy to deal
1562  with singular regions.
1563  */
1564  blocked=TRUE;
1565  fprintf(stderr," Point in singularity (decrease epsilon?)\n");
1566  #if (GET_ATLASRRT_STATISTICS)
1569  #endif
1570  }
1571  }
1572  }
1573  else
1574  {
1575  tmpQrandReached=((randChart==nextChart)&&
1576  (Distance(ar->k,randParam,nextParam)<epsilon));
1577 
1578  if (onManifold)
1579  {
1580  dqr=DistanceTopology(ar->m,ar->tp,nextSample,origRandSample);
1581  *reachedQRand=(dqr<epsilon);
1582  }
1583 
1584  #if (!EXPLORATION_RRT)
1585  if (goalSample!=NULL)
1586  {
1587  dg=DistanceTopology(ar->m,ar->tp,nextSample,goalSample);
1588  *reachedGoal=(dg<epsilon);
1589  }
1590  #endif
1591 
1592  #if (GET_ATLASRRT_STATISTICS)
1593  if ((*reachedQRand)||(tmpQrandReached)||(*reachedGoal))
1595  #endif
1596 
1597  dnn=DistanceTopology(ar->m,ar->tp,nextSample,nnSample);
1598  tooFar=(dnn>distQrand);
1599 
1600  if (!tooFar)
1601  {
1602  /* Add the sample to the tree, if required */
1603  dnn=DistanceTopology(ar->m,ar->tp,currentSampleInfo->s,nextSample);
1604  if (addMode==ADD_ALL)
1605  {
1606  d+=AddSample2AtlasRRT(pr,tree,lastSampleID,
1607  nextChart,nextParam,nextSample,dnn,cost,ar);
1608 
1609  currentSampleInfo=ar->si[*lastSampleID];
1610  }
1611  else
1612  {
1613  /* If the sample is not added to the tree, we update the
1614  current sample info. */
1615  d+=dnn;
1616 
1617  /* Update the info for the temporary sample */
1618  memcpy(currentSampleInfo->s,nextSample,ar->m*sizeof(double));
1619  memcpy(currentSampleInfo->t,nextParam,ar->k*sizeof(double));
1620  currentSampleInfo->c=nextChart;
1621  currentSampleInfo->pc=nextChart;
1622  currentSampleInfo->generateChart=0;
1623  currentSampleInfo->lsc=NO_UINT;
1624  }
1625  memcpy(currentParam,nextParam,ar->k*sizeof(double));
1626 
1627  currentDelta=delta;
1628 
1629  #if (GET_ATLASRRT_STATISTICS)
1630  if (d>=maxDist)
1632 
1634  #endif
1635 
1636  /* Add the sample the path, if required */
1637  if ((ns!=NULL)&&(path!=NULL)&&
1638  (!tmpQrandReached)&&(!(*reachedGoal))&&(!(*reachedQRand)))
1639  AddSample2Samples(ar->m,nextSample,ar->m,NULL,&ms,ns,path);
1640  }
1641  #if (GET_ATLASRRT_STATISTICS)
1642  else
1644  #endif
1645  }
1646  }
1647  }
1648 
1649  /* Add the distance from the last sample in the branch to the
1650  goal/q_rand (this is epsilon size) */
1651  if (*reachedQRand)
1652  d+=dqr;
1653  else
1654  {
1655  if (*reachedGoal)
1656  d+=dg;
1657  }
1658 
1659  if ((init)&&(d>0)&&((addMode==ADD_LAST)||((addMode==ADD_LAST_NO_REP))))
1660  {
1661  if (addMode==ADD_LAST_NO_REP)
1662  {
1663  nn=GetRRTNN(tree,tmpSI.s,&(ar->rrt));
1664  noRep=(DistanceTopology(ar->m,ar->tp,ar->si[nn]->s,tmpSI.s)>epsilon);
1665  }
1666  else
1667  noRep=TRUE;
1668 
1669  if (noRep)
1670  {
1671  /* If it was required to advance toward q_rand and we actually
1672  moved in that direction and we have to add the last computed
1673  sample -> add it */
1674  AddSample2AtlasRRT(pr,tree,lastSampleID,
1675  tmpSI.c,tmpSI.t,tmpSI.s,d,cost,ar);
1676  }
1677  }
1678 
1679  if (init)
1680  {
1681  /* Update the statistic of how far we can get from i_near */
1682  /* This only has effect if paramter DYNAMIC_DOMAIN is >0 */
1683  AdjustDynamicDomain(i_near,collision,&(ar->rrt));
1684 
1685  /* Release allocated space */
1686  if (addMode!=ADD_ALL)
1687  {
1688  free(tmpSI.s);
1689  free(tmpSI.t);
1690  }
1691  free(currentParam);
1692  free(deltaParam);
1693  free(nextParam);
1694  free(nextSample);
1695  free(randParam);
1696  free(randSample);
1697  }
1698 
1699  return(d);
1700 }
1701 
1702 void NewTemptativeSample(Tparameters *pr,unsigned int it,unsigned int *nChanges,
1703  boolean revisitCharts,boolean explorationSample,
1704  boolean checkCollisions,boolean onManifold,
1705  TSampleInfo *currentSampleInfo,double *currentParam,
1706  double *origRandSample,
1707  unsigned int *randChart,double *randParam,double *randSample,
1708  double currentDelta,double d,double *deltaParam,
1709  unsigned int *nextChart,double *nextParam,double *nextSample,
1710  void *st,double (*costF)(Tparameters*,boolean,double*,void*),
1711  void *costData,double *cost,boolean *blocked,
1712  boolean *inCollision,boolean *valid,
1713  Tatlasrrt *ar)
1714 {
1715  double epsilon;
1716  unsigned int samplingMode;
1717  double dif;
1718 
1719  #if (GET_ATLASRRT_STATISTICS)
1721  #endif
1722 
1723  epsilon=GetParameter(CT_EPSILON,pr);
1724  samplingMode=(unsigned int)GetParameter(CT_SAMPLING,pr);
1725 
1726  if (currentDelta<epsilon)
1727  {
1728  Warning("The impossible happened (III)");
1729  *blocked=TRUE;
1730  }
1731  else
1732  {
1733  dif=Distance(ar->k,currentParam,randParam);
1734  if (dif<currentDelta)
1735  memcpy(nextParam,randParam,ar->k*sizeof(double));
1736  else
1737  SumVectorScale(ar->k,currentParam,currentDelta,deltaParam,nextParam);
1738 
1739  *valid=TRUE;
1740  *blocked=FALSE;
1741  *inCollision=FALSE; /* default no collision */
1742 
1743  if (Norm(ar->k,nextParam)>ar->r)
1744  {
1745  *valid=FALSE;
1746  #if (GET_ATLASRRT_STATISTICS)
1748  #endif
1749  }
1750  else
1751  {
1752  Tchart *nChart;
1753  double *currentSample;
1754  double dp;
1755  boolean inDomain,tooCurved;
1756  boolean trans;
1757 
1758  trans=TRUE; /* default no cost function is considered */
1759 
1760  /* currentSample = sample from where to move forward */
1761  currentSample=currentSampleInfo->s;
1762 
1763  /* In principle, nextChart is currentChart */
1764  *nextChart=currentSampleInfo->c;
1765  nChart=GetAtlasChart(*nextChart,&(ar->atlas));
1766 
1767  if (!InsideChartPolytope(nextParam,nChart))
1768  {
1769  if ((!onManifold)&&((explorationSample)||(*nChanges>0)))
1770  {
1771  /* A branch aiming a random point (in tangent space) that potentially generated
1772  new charts along its way, is stopped to enter a pre-existing chart.
1773  This tries to avoid branch crossing. */
1774  *blocked=TRUE;
1775  #if (GET_ATLASRRT_STATISTICS)
1777  #endif
1778  #if (ATLASRRT_VERBOSE)
1779  if (*nChanges>0)
1780  fprintf(stderr," Branch stopped (visited charts>1)\n");
1781  else
1782  fprintf(stderr," Branch stopped (exploration)\n");
1783  #endif
1784  }
1785  else
1786  {
1787  double *tc;
1788 
1789  *nextChart=DetermineChartNeighbour(epsilon,nextParam,nChart);
1790 
1791  if ((!revisitCharts)&&((!ar->birrt)||((ar->ci[currentSampleInfo->c]->tree)&(ar->ci[*nextChart]->tree))))
1792  {
1793  /* When trying to connect two trees, the branch should not enter other charts in the
1794  same tree. When this happens it means that the sample from where we extend the tree was
1795  not the nearest node to the other tree. Extending this branch results in branch crossing.
1796  Even the part of the branch already created shoud be removed to improve the quality of the
1797  RRT, but this is not implemented yet.
1798  One option would be not to add any node along this "connection" branches. Or implement
1799  a sort of delayed add to the RRT,.... */
1800  *blocked=TRUE;
1801  #if (GET_ATLASRRT_STATISTICS)
1803  #endif
1804  #if (ATLASRRT_VERBOSE)
1805  fprintf(stderr," Branch stopped (non-revisited)\n");
1806  #endif
1807  }
1808  else
1809  {
1810  (*nChanges)++;
1811  #if (ATLASRRT_VERBOSE>1)
1812  fprintf(stderr," Branch moved to chart: %u [num Changes: %u]\n",*nextChart,*nChanges);
1813  #endif
1814  /* Transition between pre-existing charts -> continue */
1815  nChart=GetAtlasChart(*nextChart,&(ar->atlas));
1816 
1817  NEW(tc,ar->k,double);
1818  Manifold2Chart(currentSample,ar->tp,tc,nChart);
1819  *blocked=PointTowardRandSample(*nextChart,d,tc,samplingMode,
1820  onManifold,origRandSample,
1821  randChart,randParam,randSample,
1822  deltaParam,ar);
1823  if (!(*blocked))
1824  {
1825  dif=Distance(ar->k,tc,randParam);
1826  if (dif<currentDelta)
1827  memcpy(nextParam,randParam,ar->k*sizeof(double));
1828  else
1829  SumVectorScale(ar->k,tc,currentDelta,deltaParam,nextParam);
1830  free(tc);
1831 
1832  if (Norm(ar->k,nextParam)>ar->r)
1833  {
1834  #if (GET_ATLASRRT_STATISTICS)
1836  #endif
1837  *valid=FALSE;
1838  }
1839  else
1840  EnlargeChart(nextParam,nChart);
1841  }
1842  #if (GET_ATLASRRT_STATISTICS)
1843  else
1845  #endif
1846  }
1847  }
1848  }
1849 
1850  /* Check error projection (distance) */
1851  if ((*valid)&&(!*blocked)&&
1852  (Chart2Manifold(pr,&(ar->J),nextParam,
1853  ar->tp,currentSample,
1854  nextSample,nChart)<ar->e))
1855  {
1856  /* Check error curvature (only along the expansion direction) */
1857  dp=DistanceTopology(ar->m,ar->tp,currentSample,nextSample);
1858 
1859  tooCurved=((currentDelta/dp)<(1-ar->ce));
1860  if (!tooCurved)
1861  {
1862  /* Check the bounds respect to the ambient space */
1863  inDomain=((PointInBoxTopology(NULL,FALSE,ar->m,nextSample,epsilon,
1864  ar->tp,&(ar->ambient)))&&
1865  (CS_WD_SIMP_INEQUALITIES_HOLD(pr,nextSample,ar->w)));
1866  if (inDomain)
1867  {
1868  *cost=0;
1869 
1870  if (costF!=NULL)
1871  trans=TransitionTestRRT(pr,currentSampleInfo->id,nextSample,dp,cost,
1872  costF,costData,&(ar->rrt));
1873 
1874  if (trans)
1875  {
1876  /* Check the collisions (only if necessary) */
1877  if (checkCollisions)
1878  {
1879  CS_WD_IN_COLLISION(*inCollision,pr,nextSample,currentSample,ar->w);
1880  #if (GET_ATLASRRT_STATISTICS)
1882  #endif
1883  }
1884 
1885  if (*inCollision)
1886  {
1887  *blocked=TRUE;
1888  #if (GET_ATLASRRT_STATISTICS)
1890  #endif
1891  }
1892  #if (GET_ATLASRRT_GLOBAL_CURV_CHECK)
1893  else
1894  {
1895  Tchart cTmp;
1896  boolean closeEnough,canInitChart;
1897 
1898  /* We further check if we are able to create a chart
1899  at the current sample and if this chart is not
1900  too different from its parent chart. */
1901 
1902  /* Check the possibility of a chart creation */
1903  canInitChart=(InitChart(pr,TRUE,&(ar->ambient),
1904  ar->tp,ar->m,ar->k,nextSample,
1905  ar->e,ar->ce,ar->r,&(ar->J),
1906  ar->w,&cTmp)==0);
1907  if (canInitChart)
1908  {
1909  /* Check if new chart respects distance
1910  and angular tolerances */
1911  closeEnough=CloseCharts(pr,ar->tp,nChart,&cTmp);
1912  if (!closeEnough)
1913  {
1914  *valid=FALSE;
1915  #if (GET_ATLASRRT_STATISTICS)
1917  #endif
1918  }
1919  DeleteChart(&cTmp); /* Delete only if init was OK */
1920  }
1921  else
1922  {
1923  /* Point not on manifold, error in QR, singular point
1924  (typically the last one) */
1925  *blocked=TRUE; /* valid=FALSE ?? */
1926  #if (GET_ATLASRRT_STATISTICS)
1928  #endif
1929  }
1930  }
1931  #endif
1932  }
1933  else
1934  {
1935  /*Transition test failed -> rejected step */
1936  *blocked = TRUE;
1937  }
1938  }
1939  else
1940  {
1941  #if (GET_ATLASRRT_STATISTICS)
1943  #endif
1944  *blocked=TRUE;
1945  }
1946  }
1947  else
1948  {
1949  #if (GET_ATLASRRT_STATISTICS)
1951  #endif
1952  *valid=FALSE;
1953  }
1954  }
1955  else
1956  {
1957  #if (GET_ATLASRRT_STATISTICS)
1958  if ((*valid)&&(!*blocked))
1960  #endif
1961  *valid=FALSE;
1962  }
1963  }
1964  }
1965 }
1966 
1967 double AddSample2AtlasRRT(Tparameters *pr,unsigned int tree,
1968  unsigned int *currentID,
1969  unsigned int nextChart,double *nextParam,double *nextSample,
1970  double dp,double cost,
1971  Tatlasrrt *ar)
1972 {
1973  double d;
1974  double *currentSample;
1975  unsigned int k;
1976  TSampleInfo *currentSampleInfo;
1977  TChartInfo *currentChartInfo;
1978 
1979  /* Distance to parent sample */
1980  currentSample=ar->si[*currentID]->s;
1981  d=DistanceTopology(ar->m,ar->tp,nextSample,currentSample);
1982 
1983  #if (_DEBUG>1)
1984  printf(" New sample %u (dp:%f)\n",ar->ns,d);
1985  #endif
1986 
1987  /* Add the sample to the RRT */
1988  if (ar->ns==ar->ms)
1989  MEM_DUP(ar->si,ar->ms,TSampleInfo *);
1990 
1991  /* Store the new sample in the RRT */
1992  AddNodeToRRT(pr,tree,*currentID,nextSample,nextSample,&k,NULL,dp,cost,NULL,&(ar->rrt));
1993  if (k!=ar->ns)
1994  Error("Incongruent node identifier in AtlasRRT (vs RRT inside)");
1995 
1996  /* Set up the information for the new sample */
1997  NEW(ar->si[ar->ns],1,TSampleInfo);
1998  currentSampleInfo=ar->si[ar->ns];
1999  currentChartInfo=ar->ci[nextChart];
2000 
2001  /* Pointer to the just added sample. The sample is stored in the RRT. */
2002  currentSampleInfo->s=GetRRTNode(ar->ns,&(ar->rrt));
2003  currentSampleInfo->id=ar->ns;
2004 
2005  /* Parent chart: Chart at which the sample is created.
2006  At initialization this is the same as currentSampleInfo->c
2007  but currentSampleInfo->c can change as new charts are
2008  created and currentSampleInfo->pc will remain the same */
2009  currentSampleInfo->pc=nextChart;
2010 
2011  /* There is no chart at the new sample (yet) */
2012  currentSampleInfo->generateChart=0;
2013 
2014  /* The chart including the current sample must be associated with
2015  the tree including this sample. */
2016  AddChart2Tree(tree,nextChart,ar);
2017 
2018  /* Store the projection into the current chart */
2019  NEW(currentSampleInfo->t,ar->k,double);
2020  Manifold2Chart(currentSampleInfo->s,ar->tp,currentSampleInfo->t,
2021  GetAtlasChart(nextChart,&(ar->atlas)));
2022 
2023  /* Assign the sample to the corresponding chart */
2024  currentSampleInfo->c=nextChart;
2025 
2026  /* Add the sample to the list of samples of the corresponding chart */
2027  currentSampleInfo->lsc=currentChartInfo->lc;
2028  currentChartInfo->lc=ar->ns;
2029 
2030  /*Move the pointer to current to the new sample */
2031  *currentID=ar->ns;
2032 
2033  ar->ns++;
2034 
2035  return(d);
2036 }
2037 
2038 void AddChart2Tree(unsigned int tree,unsigned int chartId,Tatlasrrt* ar)
2039 {
2040  if ((ar->birrt)&&(!(ar->ci[chartId]->tree&tree)))
2041  {
2042  ar->ci[chartId]->tree|=tree;
2043  if (tree==START2GOAL)
2044  {
2045  if(ar->nct1==ar->mct1)
2046  MEM_DUP(ar->chartsAtTree1,ar->mct1,unsigned int);
2047  ar->chartsAtTree1[ar->nct1]=chartId;
2048  ar->nct1++;
2049  }
2050  else
2051  {
2052  if(ar->nct2==ar->mct2)
2053  MEM_DUP(ar->chartsAtTree2,ar->mct2,unsigned int);
2054  ar->chartsAtTree2[ar->nct2]=chartId;
2055  ar->nct2++;
2056  }
2057  }
2058 }
2059 
2060 boolean PointTowardRandSample(unsigned int cId,double d,double *t,
2061  unsigned int samplingMode,
2062  boolean onManifold,double *origRandSample,
2063  unsigned int *randChart,
2064  double *randParam,double *randSample,
2065  double *deltaParam,
2066  Tatlasrrt* ar)
2067 {
2068  Tchart *c;
2069  double n;
2070 
2071  *randChart=cId;
2072 
2073  /* Get current chart */
2074  c=GetAtlasChart(cId,&(ar->atlas));
2075 
2076  /* w: Project randSample on the chart. Do not use topoogy here
2077  We already used it to fix origRandSample and randSample. If we
2078  take into account the topology we might end up not moving along
2079  the shortest path connecting two samples */
2080  if ((samplingMode!=TANGENT_SAMPLING)||(onManifold))
2081  Manifold2Chart(origRandSample,NULL,randParam,c);
2082  else
2083  Manifold2Chart(randSample,NULL,randParam,c);
2084  /* deltaParam: Vector from current parameters 't' to 'w' */
2085  DifferenceVector(ar->k,randParam,t,deltaParam);
2086  /* Ensure that the new randSample is at least at
2087  distance 'd' from 't' */
2088  n=Norm(ar->k,deltaParam);
2089  if (n>1e-3)
2090  {
2091  Normalize(ar->k,deltaParam);
2092  if ((samplingMode==TANGENT_SAMPLING)&&(!onManifold))
2093  SumVectorScale(ar->k,t,d,deltaParam,randParam);
2094  /* Transform randSample to ambient space. Again, skip
2095  the topology to keep the advance direction.*/
2096  Local2Global(randParam,NULL,randSample,c);
2097 
2098  return(FALSE);
2099  }
2100  else
2101  return(TRUE);
2102 }
2103 
2104 boolean AddChart2AtlasRRT(Tparameters *pr,unsigned int tree,unsigned int it,
2105  TSampleInfo *currentSampleInfo,boolean* intersectParent,
2106  Tatlasrrt *ar)
2107 {
2108  unsigned int j,ncp,newChart;
2109  unsigned nn,i,id;
2110  Tchart* ce;
2111  TChartInfo *currentChartInfo;
2112  unsigned int currentID;
2113  boolean sing;
2114 
2115  currentID=currentSampleInfo->id;
2116 
2117  /* need to generate a new chart at the current sample */
2118  /* change cID */
2119  ncp=ar->nc;
2120 
2121  /* This does not enforce the neighbouring relation with parent chart !!
2122  but tries to detect singularities, if any (and enabled) */
2123  newChart=AddTrustedChart2Atlas(pr,currentSampleInfo->s,
2124  currentSampleInfo->pc,&sing,&(ar->atlas));
2125 
2126  if (newChart!=NO_UINT)
2127  {
2128  ar->nc=GetAtlasNumCharts(&(ar->atlas));
2129 
2130  /* Check if the newChart is neighbour with its parent chart */
2131  if (ncp<(ar->birrt?2:1))
2132  *intersectParent=TRUE; /* for the chart at the given samples -> do not check */
2133  else
2134  {
2135  (*intersectParent)=FALSE;
2136  ce=GetAtlasChart(newChart,&(ar->atlas));
2137  nn=ChartNumNeighbours(ce);
2138 
2139  for(i=0;((!(*intersectParent))&&(i<nn));i++)
2140  {
2141  id=ChartNeighbourID(i,ce);
2142  if ((id!=NO_UINT)&&(id==currentSampleInfo->pc))
2143  (*intersectParent)=TRUE;
2144  }
2145 
2146  if ((!(*intersectParent))&&(currentSampleInfo->pc!=NO_UINT))
2147  {
2148  Tchart *parentChart;
2149 
2150  parentChart=GetAtlasChart(currentSampleInfo->pc,&(ar->atlas));
2151  ForceChartCut(pr,ar->tp,&(ar->ambient),newChart,ce,currentSampleInfo->pc,parentChart);
2152  }
2153  }
2154 
2155  #if (ATLASRRT_VERBOSE>1)
2156  fprintf(stderr," Sample at chart %u generated a new chart (%u)\n",
2157  currentSampleInfo->c,newChart);
2158  #endif
2159 
2160  /* 1+newChart -> we can find out which chart was created at each
2161  sample just by substracting one (used for debug). */
2162  currentSampleInfo->generateChart=1+newChart;
2163 
2164  /* expand chart info if necessary */
2165  if (ar->nc>ar->mc)
2166  {
2167  ar->mc=ar->nc+INIT_NUM_CHARTS;
2168  MEM_EXPAND(ar->ci,ar->mc,TChartInfo *);
2169  }
2170 
2171  /* and initialize an empty list of samples for the new charts */
2172  for(j=ncp;j<ar->nc;j++)
2173  {
2174  NEW(ar->ci[j],1,TChartInfo);
2175  ar->ci[j]->lc=NO_UINT;
2176  ar->ci[j]->it=it;
2177  ar->ci[j]->tree=0; /* chart in no tree initially */
2178  AddChart2Tree(tree,j,ar);
2179  }
2180 
2181  /* Now that the list of samples for the new charts is already initialized,
2182  we assign samples to the newly created charts */
2183  for(j=ncp;j<ar->nc;j++)
2184  PopulateWithSamples(pr,j,ar);
2185 
2186  /* The sample used to create the new chart should be assigned to it.
2187  Otherwise we have to correct the situation.
2188  We do not worry in the case of temporary samples (samples not actually
2189  included in the tree, ID=NO_UINT)
2190  */
2191  if (currentID==NO_UINT)
2192  {
2193  /* Sample not in the tree */
2194  currentSampleInfo->c=newChart;
2195  currentSampleInfo->pc=newChart;
2196  for(j=0;j<ar->k;j++)
2197  currentSampleInfo->t[j]=0;
2198  }
2199  else
2200  {
2201  if (currentSampleInfo->c!=newChart)
2202  {
2203  unsigned int n;
2204  boolean found;
2205  Tchart *ce;
2206  TChartInfo *newChartInfo;
2207  TSampleInfo *previousSampleInfo;
2208 
2209  /* This happens for samples that are not on the chart where
2210  they were originally created and are at a chart that is
2211  not neighbour to the just created chart (mainly due to
2212  curvature errors).
2213  In this case, populateWithSamples is not able to steal
2214  the sample used to create the chart from its current chart.
2215  Here we force the assignment.
2216  */
2217  n=currentSampleInfo->c; /*Chart from where to steal the center*/
2218  currentChartInfo=ar->ci[n];
2219  newChartInfo=ar->ci[newChart];
2220 
2221  previousSampleInfo=NULL; /* previous sample in the list */
2222  j=currentChartInfo->lc; /* first sample in the list */
2223  found=FALSE;
2224  while((j!=NO_UINT)&&(!found))
2225  {
2226  currentSampleInfo=ar->si[j];
2227  if (j==currentID)
2228  {
2229  /* remove the sample from the list of chart c*/
2230  if (previousSampleInfo==NULL)
2231  currentChartInfo->lc=currentSampleInfo->lsc;
2232  else
2233  previousSampleInfo->lsc=currentSampleInfo->lsc;
2234 
2235  /* add to the list of the new chart */
2236  currentSampleInfo->lsc=newChartInfo->lc;
2237  newChartInfo->lc=j;
2238  currentSampleInfo->c=newChart;
2239 
2240  /* Project the sample to the chart. This must result
2241  in zero but....*/
2242  ce=GetAtlasChart(newChart,&(ar->atlas));
2243  Manifold2Chart(currentSampleInfo->s,ar->tp,currentSampleInfo->t,ce);
2244  EnlargeChart(currentSampleInfo->t,ce);
2245 
2246  found=TRUE;
2247  }
2248  else
2249  {
2250  /* Move to next */
2251  previousSampleInfo=currentSampleInfo;
2252  j=currentSampleInfo->lsc;
2253  }
2254  }
2255  if (!found)
2256  Error("A sample is not where it should be");
2257  }
2258  }
2259  return(TRUE); /* The chart could be actually created */
2260  }
2261  else
2262  return(FALSE); /* The chart could not be created (the given point
2263  is in a singular region?) */
2264 }
2265 
2266 
2267 void PopulateWithSamples(Tparameters *pr,unsigned int id,Tatlasrrt *ar)
2268 {
2269  Tchart *c,*c1,*ce;
2270  unsigned int i,j,jt,n,nn,ne;
2271  double *t;
2272  double epsilon;
2273  TSampleInfo *currentSampleInfo;
2274  TSampleInfo *previousSampleInfo;
2275  TChartInfo *currentChartInfo;
2276  TChartInfo *newChartInfo;
2277 
2278  epsilon=GetParameter(CT_EPSILON,pr);
2279 
2280  NEW(t,ar->k,double);
2281 
2282  c=GetAtlasChart(id,&(ar->atlas));
2283  nn=ChartNumNeighbours(c);
2284 
2285  for(i=0;i<nn;i++)
2286  {
2287  /* The neighbouring chart from where to steal some samples */
2288  n=ChartNeighbourID(i,c);
2289  if (n!=NO_UINT)
2290  {
2291  currentChartInfo=ar->ci[n];
2292  c1=GetAtlasChart(n,&(ar->atlas));
2293 
2294  previousSampleInfo=NULL; /* previous sample in the list */
2295  j=currentChartInfo->lc; /* first sample in the list */
2296  while(j!=NO_UINT)
2297  {
2298  currentSampleInfo=ar->si[j];
2299  ne=DetermineChartNeighbour(epsilon,currentSampleInfo->t,c1);
2300  if (ne!=NO_UINT)
2301  {
2302  /* Sample 'j' is not any more in chart 'c1' (chart 'n') but in a
2303  neighbouring one, typically the one just created (ne==id),
2304  but can be any other neighbour */
2305 
2306  newChartInfo=ar->ci[ne]; /* This should be the new chart */
2307 
2308  #if (_DEBUG>2)
2309  fprintf(stderr," Sample %u moves from chart %u to %u\n",j,n,ne);
2310  #endif
2311 
2312  /* Typically 'ce' will be 'c', but not for sure */
2313  ce=GetAtlasChart(ne,&(ar->atlas));
2314  Manifold2Chart(currentSampleInfo->s,ar->tp,currentSampleInfo->t,ce);
2315  EnlargeChart(currentSampleInfo->t,ce);
2316 
2317  currentSampleInfo->c=ne;
2318 
2319  /* we will change lsc[j] in the following -> backup it */
2320  jt=currentSampleInfo->lsc;
2321 
2322  /* remove the sample from the list of chart c*/
2323  if (previousSampleInfo==NULL)
2324  currentChartInfo->lc=currentSampleInfo->lsc;
2325  else
2326  previousSampleInfo->lsc=currentSampleInfo->lsc;
2327 
2328  /* add to the list of chart 'ne' (typically ne==id) */
2329  currentSampleInfo->lsc=newChartInfo->lc;
2330  newChartInfo->lc=j;
2331 
2332  /* The chart importing the sample must be associated with
2333  the tree including this sample. */
2334  AddChart2Tree(GetRRTNodeTree(j,&(ar->rrt)),ne,ar);
2335 
2336  /* Set 'j' to the next in the list of samples for the current
2337  chart (previously backed up) */
2338  j=jt;
2339 
2340  /* Since we removed one element from the list the
2341  previous pointed by 'previousSampleInfo' remains the same. */
2342  }
2343  else
2344  {
2345  /* move to next sample in the list of samples assigned to
2346  chart 'n' */
2347  previousSampleInfo=currentSampleInfo;
2348  j=currentSampleInfo->lsc;
2349  }
2350  }
2351  }
2352  }
2353 
2354  free(t);
2355 }
2356 
2357 unsigned int ReconstructAtlasRRTPath(Tparameters *pr,unsigned int sID,
2358  double *pl,unsigned int *ns,double ***path,Tatlasrrt *ar)
2359 {
2360  unsigned int nv,nvs,i,ms;
2361  signed int j;
2362  double *o,c;
2363  boolean *systemVars;
2364  unsigned int lns;
2365  double **lpath;
2366  boolean reachedParent,reachedG;
2367  unsigned int p,ls;
2368 
2369  *pl=0;
2370 
2371  /* Get the sample in the tree close to the goal */
2372  nv=CS_WD_GET_SYSTEM_VARS(&systemVars,ar->w);
2373  nvs=0;
2374  for(i=0;i<nv;i++)
2375  {
2376  if (systemVars[i])
2377  nvs++;
2378  }
2379 
2380  InitSamples(&ms,ns,path);
2381 
2382  i=sID;
2383  while (i!=NO_UINT)
2384  {
2385  CS_WD_REGENERATE_ORIGINAL_POINT(pr,ar->si[i]->s,&o,ar->w);
2386  AddSample2Samples(nv,o,nvs,systemVars,&ms,ns,path);
2387  free(o);
2388  p=GetRRTParent(i,&(ar->rrt));
2389  if (p!=NO_UINT)
2390  {
2391  /* Check that the two samples can be actually connected and
2392  measure the distance between them. */
2394  0.0,p,ar->si[i]->s,NULL,NULL,&ls,&reachedParent,&reachedG,
2395  &lns,&lpath,NULL,NULL,ar);
2396 
2397  #if (ATLASRRT_VERBOSE)
2398  fprintf(stderr,"{%u->%u}[%g]",i,p,c);
2399  #endif
2400 
2401  (*pl)+=c;
2402  if (!reachedParent)
2403  Warning("Path segment could not be reconstructed in ReconstructAtlasRRTPath");
2404 
2405  for(j=lns-1;j>=0;j--)
2406  {
2407  CS_WD_REGENERATE_ORIGINAL_POINT(pr,lpath[j],&o,ar->w);
2408  AddSample2Samples(nv,o,nvs,systemVars,&ms,ns,path);
2409  free(o);
2410  }
2411 
2412  DeleteSamples(lns,lpath);
2413  }
2414  i=p;
2415  }
2416  ReverseSamples(*ns,*path);
2417 
2418  free(systemVars);
2419 
2420  return(nvs);
2421 }
2422 
2423 
2424 unsigned int Steps2PathinAtlasRRT(Tparameters *pr,Tvector *steps,double *pl,double *pc,
2425  unsigned int *ns,double ***path,Tatlasrrt *ar)
2426 {
2427  unsigned int nv,nvs,ms,n,i,k,current,next;
2428  signed int j;
2429  double *o,c;
2430  boolean *systemVars;
2431  unsigned int lns;
2432  double **lpath;
2433  double epsilon,dc;
2434  boolean reachedG,reachedNext;
2435  unsigned int ls; /* last added sample, if any */
2436 
2437  *pl=0; /* path length */
2438  if (pc!=NULL) /* path cost (mechanical work) */
2439  {
2440  *pc=0;
2441  epsilon=GetParameter(CT_EPSILON,pr);
2442  }
2443 
2444  /* Identify system variables */
2445  nv=CS_WD_GET_SYSTEM_VARS(&systemVars,ar->w);
2446  nvs=0;
2447  for(i=0;i<nv;i++)
2448  {
2449  if (systemVars[i])
2450  nvs++;
2451  }
2452 
2453  InitSamples(&ms,ns,path);
2454 
2455  current=*(unsigned int *)GetVectorElement(0,steps);
2456  n=VectorSize(steps);
2457  k=1;
2458  while (k<n)
2459  {
2460  next=*(unsigned int *)GetVectorElement(k,steps);
2461 
2462  CS_WD_REGENERATE_ORIGINAL_POINT(pr,ar->si[current]->s,&o,ar->w);
2463  AddSample2Samples(nv,o,nvs,systemVars,&ms,ns,path);
2464  free(o);
2465 
2467  0.0,current,ar->si[next]->s,NULL,NULL,&ls,&reachedNext,&reachedG,
2468  &lns,&lpath,NULL,NULL,ar);
2469 
2470  #if (RRT_VERBOSE)
2471  fprintf(stderr,"{%u->%u}[%g]",current,next,c);
2472  #endif
2473 
2474  (*pl)+=c; /* Update the path length */
2475  if(pc!=NULL) /* Update the path cost (mechanical work) */
2476  {
2477  dc=GetRRTNodeCost(current,&(ar->rrt))-GetRRTNodeCost(next,&(ar->rrt));
2478  (*pc)+=(dc>0?dc:0)+epsilon*c;
2479  }
2480 
2481  if (!reachedNext)
2482  Warning("Path segment could not be reconstructed in Steps2PathinRRT");
2483  else
2484  {
2485  for(j=0;j<lns;j++)
2486  {
2487  CS_WD_REGENERATE_ORIGINAL_POINT(pr,lpath[j],&o,ar->w);
2488  AddSample2Samples(nv,o,nvs,systemVars,&ms,ns,path);
2489  free(o);
2490  }
2491  DeleteSamples(lns,lpath);
2492  }
2493 
2494  current=next;
2495  k++;
2496  }
2497 
2498  free(systemVars);
2499 
2500  return(nvs);
2501 }
2502 
2503 void SmoothPathInAtlasRRT(Tparameters *pr,unsigned int sID,Tatlasrrt* ar)
2504 {
2505  signed int l;
2506  unsigned int i,j,k,s,n,n1,n2,o;
2507  unsigned int *path;
2508  double c12,c2_new,c1,c2;
2509  boolean reachedQRand,reachedGoal;
2510  unsigned int lastID;
2511 
2512  n=StepsToRoot(sID,&(ar->rrt));
2513  NEW(path,n,unsigned int);
2514  l=n-1;
2515  s=sID;
2516  while (s!=NO_UINT)
2517  {
2518  path[l]=s;
2519  s=GetRRTParent(s,&(ar->rrt));
2520  l--;
2521  }
2522  s=n; /* initial size of the path */
2523  for(l=0;l<s;l++)
2524  {
2525  /* Select a node at random in the path */
2526  i=randomMax(n-2);
2527  j=i+1+randomMax(n-2-i);
2528 
2529  n1=path[i];
2530  n2=path[j];
2531 
2532  c1=GetRRTNodeCost(n1,&(ar->rrt));
2533  c2=GetRRTNodeCost(n2,&(ar->rrt));
2534 
2535  /* Try to connect the two samples with a shorcut and measure its length */
2537  c2-c1,n1,ar->si[n2]->s,NULL,
2538  NULL,&lastID,&reachedQRand,&reachedGoal,NULL,NULL,
2539  NULL,NULL,ar);
2540 
2541  /* If node n2 can be reached from node n1 */
2542  if (reachedQRand)
2543  {
2544  /* and the cost is smaller */
2545  c2_new=c1+c12;
2546  if (c2_new<c2)
2547  {
2548  /* Set n1 as a parent of n2*/
2549  SetRRTNodeCost(n2,c12,c2_new,&(ar->rrt));
2550  SetRRTParent(n2,n1,&(ar->rrt));
2551 
2552  /* Shrink the path */
2553  for(k=j,o=i+1;k<n;k++,o++)
2554  path[o]=path[k];
2555  n=o;
2556  }
2557  }
2558  }
2559  free(path);
2560 }
2561 
2563  double scale,unsigned int tree,
2564  unsigned int *nm,double *t,double *p,
2565  Tatlasrrt* ar)
2566 {
2567  boolean havePoint;
2568 
2569  /* This is the place where to implement different sampling strategies,
2570  if desired. We can, for instance, we can select the charts taking
2571  into account the number of samples (more samples, less probability
2572  of selecting them). This will approximate the AtlasRRT to an EST. */
2573 
2574  if ((ar->birrt)&&(tree!=BOTHTREES))
2575  {
2576  /* If the sampling radius is potentially different for each chart,
2577  we have to take into account the size of sampling area for each chart to
2578  uniformly sample on the part of the C-space explored so far. */
2579  #if ((ADJUST_SR)||(ADJUST_SA==1))
2580  {
2581  double *w,s;
2582  unsigned int i,nc;
2583  unsigned int *c;
2584 
2585  if (tree==START2GOAL)
2586  {
2587  nc=ar->nct1;
2588  c=ar->chartsAtTree1;
2589  }
2590  else
2591  {
2592  nc=ar->nct2;
2593  c=ar->chartsAtTree2;
2594  }
2595  NEW(w,nc,double);
2596  s=0.0;
2597  for(i=0;i<nc;i++)
2598  {
2599  /* The 'scale' factor, if any affects all charts and, thus it can be
2600  ruled out. */
2601  w[i]=GetChartSamplingRadius(GetAtlasChart(c[i],&(ar->atlas)));
2602  w[i]=pow(w[i],(double)ar->k);
2603  s+=w[i];
2604  }
2605  *nm=c[randomWithDistribution(nc,s,w)];
2606  free(w);
2607  }
2608  #else
2609  /* Uniform distribution on charts of the tree */
2610  if (tree==START2GOAL)
2611  *nm=ar->chartsAtTree1[randomMax(ar->nct1-1)];
2612  else
2613  *nm=ar->chartsAtTree2[randomMax(ar->nct2-1)];
2614  #endif
2615 
2616  /* Get a point from the selected chart */
2617  havePoint=RandomPointInChart(pr,scale,ar->tp,t,p,GetAtlasChart(*nm,&(ar->atlas)));
2618  }
2619  else
2620  {
2621  double *w=NULL;
2622 
2623  #if ((ADJUST_SR)||(ADJUST_SA==1))
2624  {
2625  double s;
2626  unsigned int i,nc;
2627 
2628  nc=GetAtlasNumCharts(&(ar->atlas));
2629  NEW(w,nc,double);
2630  s=0.0;
2631  for(i=0;i<nc;i++)
2632  {
2633  w[i]=GetChartSamplingRadius(GetAtlasChart(i,&(ar->atlas)));
2634  w[i]=pow(w[i],(double)ar->k);
2635  s+=w[i];
2636  }
2637  *nm=randomWithDistribution(nc,s,w);
2638  }
2639  #endif
2640 
2641  havePoint=RandomPointInAtlas(pr,scale,w,nm,t,p,&(ar->atlas));
2642 
2643  #if ((ADJUST_SR)||(ADJUST_SA==1))
2644  free(w);
2645  #endif
2646  }
2647 
2648  return(havePoint);
2649 }
2650 
2651 
2652 void PlotQrand(Tparameters *pr,char *prefix,unsigned int inear,
2653  unsigned int c_rand,double *t_rand,double *q_rand,
2654  unsigned int xID,unsigned int yID,unsigned int zID,
2655  Tatlasrrt *ar)
2656 {
2657  Tfilename fplot;
2658  double *point,*center,*near;
2659  double *o1,*o2,*o3;
2660  Tchart *chart;
2661  Tcolor color;
2662  Tplot3d p3d;
2663  double x[2],y[2],z[2];
2664 
2665  CreateFileName(NULL,prefix,"_qrand",PLOT3D_EXT,&fplot);
2666  fprintf(stderr,"Plotting Qrand to : %s\n",GetFileFullName(&fplot));
2667 
2668  NewColor(1,0,1,&color); /*magenta*/
2669  InitPlot3d(GetFileFullName(&fplot),FALSE,0,NULL,&p3d);
2670  DeleteFileName(&fplot);
2671 
2672  NEW(point,ar->m,double);
2673  chart=GetAtlasChart(c_rand,&(ar->atlas));
2674 
2675  Local2Global(t_rand,ar->tp,point,chart); /* point must be the same as q_rand */
2676  CS_WD_REGENERATE_ORIGINAL_POINT(pr,point,&o1,ar->w);
2677 
2678  center=GetChartCenter(chart);
2679  CS_WD_REGENERATE_ORIGINAL_POINT(pr,center,&o2,ar->w);
2680 
2681  StartNew3dObject(&color,&p3d);
2682 
2683  /* A large cross at q_rand */
2684  x[0]=o1[xID]-0.15;
2685  y[0]=o1[yID];
2686  z[0]=o1[zID];
2687 
2688  x[1]=o1[xID]+0.15;
2689  y[1]=o1[yID];
2690  z[1]=o1[zID];
2691 
2692  PlotVect3d(2,x,y,z,&p3d);
2693 
2694  x[0]=o1[xID];
2695  y[0]=o1[yID]-0.15;
2696  z[0]=o1[zID];
2697 
2698  x[1]=o1[xID];
2699  y[1]=o1[yID]+0.15;
2700  z[1]=o1[zID];
2701 
2702  PlotVect3d(2,x,y,z,&p3d);
2703 
2704  x[0]=o1[xID];
2705  y[0]=o1[yID];
2706  z[0]=o1[zID]-0.15;
2707 
2708  x[1]=o1[xID];
2709  y[1]=o1[yID];
2710  z[1]=o1[zID]+0.15;
2711 
2712  PlotVect3d(2,x,y,z,&p3d);
2713 
2714  /* A line from q_rand to its chart center */
2715  x[0]=o1[xID];
2716  y[0]=o1[yID];
2717  z[0]=o1[zID];
2718 
2719  x[1]=o2[xID];
2720  y[1]=o2[yID];
2721  z[1]=o2[zID];
2722 
2723  PlotVect3d(2,x,y,z,&p3d);
2724 
2725  /* A line to q_near */
2726  near=ar->si[inear]->s;
2727  CS_WD_REGENERATE_ORIGINAL_POINT(pr,near,&o3,ar->w);
2728 
2729  x[0]=o1[xID];
2730  y[0]=o1[yID];
2731  z[0]=o1[zID];
2732 
2733  x[1]=o3[xID];
2734  y[1]=o3[yID];
2735  z[1]=o3[zID];
2736 
2737  PlotVect3d(2,x,y,z,&p3d);
2738 
2739  DeleteColor(&color);
2740  Close3dObject(&p3d);
2741  ClosePlot3d(FALSE,0,0,0,&p3d);
2742 
2743  free(o1);
2744  free(o2);
2745  free(o3);
2746  free(point);
2747 }
2748 
2749 void PlotConnection(Tparameters *pr,char *prefix,
2750  unsigned int target,unsigned int near,unsigned int end,
2751  unsigned int xID,unsigned int yID,unsigned int zID,
2752  Tatlasrrt *ar)
2753 {
2754  Tfilename fplot;
2755  double *point;
2756  double *o1,*o2,*o3;
2757  Tcolor color;
2758  Tplot3d p3d;
2759  double x[2],y[2],z[2];
2760 
2761  CreateFileName(NULL,prefix,"_connect",PLOT3D_EXT,&fplot);
2762  fprintf(stderr,"Plotting connection to : %s\n",GetFileFullName(&fplot));
2763 
2764  NewColor(1,0,1,&color); /*magenta*/
2765  InitPlot3d(GetFileFullName(&fplot),FALSE,0,NULL,&p3d);
2766  DeleteFileName(&fplot);
2767 
2768  point=ar->si[target]->s;
2769  CS_WD_REGENERATE_ORIGINAL_POINT(pr,point,&o1,ar->w);
2770 
2771  point=ar->si[near]->s;
2772  CS_WD_REGENERATE_ORIGINAL_POINT(pr,point,&o2,ar->w);
2773 
2774  point=ar->si[end]->s;
2775  CS_WD_REGENERATE_ORIGINAL_POINT(pr,point,&o3,ar->w);
2776 
2777  StartNew3dObject(&color,&p3d);
2778 
2779  x[0]=o1[xID];
2780  y[0]=o1[yID];
2781  z[0]=o1[zID];
2782 
2783  x[1]=o2[xID];
2784  y[1]=o2[yID];
2785  z[1]=o2[zID];
2786 
2787  PlotVect3d(2,x,y,z,&p3d);
2788 
2789  x[0]=o1[xID];
2790  y[0]=o1[yID];
2791  z[0]=o1[zID];
2792 
2793  x[1]=o3[xID];
2794  y[1]=o3[yID];
2795  z[1]=o3[zID];
2796 
2797  PlotVect3d(2,x,y,z,&p3d);
2798 
2799  DeleteColor(&color);
2800  Close3dObject(&p3d);
2801  ClosePlot3d(FALSE,0,0,0,&p3d);
2802 
2803  free(o1);
2804  free(o2);
2805  free(o3);
2806 }
2807 
2809 {
2810  unsigned int i;
2811 
2812  fprintf(f,"%u\n",si->id);
2813  for(i=0;i<ar->k;i++)
2814  fprintf(f,"%.16f ",si->t[i]);
2815  fprintf(f,"\n");
2816  fprintf(f,"%u\n",si->pc);
2817  fprintf(f,"%u\n",si->c);
2818  fprintf(f,"%u\n",si->generateChart);
2819  fprintf(f,"%u\n",si->lsc);
2820 }
2821 
2823 {
2824  fprintf(f,"%u\n",ci->lc);
2825  fprintf(f,"%u\n",ci->tree);
2826  fprintf(f,"%u\n",ci->it);
2827 }
2828 
2830 {
2831  unsigned int i;
2832 
2833  fscanf(f,"%u",&(si->id));
2834  si->s=GetRRTNode(si->id,&(ar->rrt));
2835  NEW(si->t,ar->k,double);
2836  for(i=0;i<ar->k;i++)
2837  fscanf(f,"%lf",&(si->t[i]));
2838  fscanf(f,"%u",&(si->pc));
2839  fscanf(f,"%u",&(si->c));
2840  fscanf(f,"%u",&(si->generateChart));
2841  fscanf(f,"%u",&(si->lsc));
2842 }
2843 
2845 {
2846  fscanf(f,"%u",&(ci->lc));
2847  fscanf(f,"%u",&(ci->tree));
2848  fscanf(f,"%u",&(ci->it));
2849 }
2850 
2851 /******************************************************************************/
2852 /******************************************************************************/
2853 /******************************************************************************/
2854 
2855 void InitAtlasRRT(Tparameters *pr,boolean parallel,double *ps,unsigned int mode,boolean graph,
2856  double *pg,TAtlasBase *w,Tatlasrrt *ar)
2857 {
2858  unsigned int i;
2859  boolean intersectParent;
2860  TSampleInfo *currentSampleInfo;
2861 
2862 
2863  /*************************************************************/
2864  /* Init the basic AtlasRRT information */
2865  ar->w=w;
2866  CS_WD_GENERATE_SIMP_INITIAL_BOX(pr,&(ar->ambient),ar->w);
2867  ar->m=GetBoxNIntervals(&(ar->ambient));
2868  ar->e=GetParameter(CT_E,pr);;
2869  ar->ce=GetParameter(CT_CE,pr);
2870  ar->r=GetParameter(CT_R,pr);
2871  /* Exploration trees are forced to be one-directional */
2872  ar->birrt=((!EXPLORATION_RRT)&&(mode!=ONE_TREE));
2873  ar->parallel=parallel;
2874 
2875  /*************************************************************/
2876  /* Init the Atlas */
2877  /* The atlas is initilized on the initial point only, latter
2878  on we add a chart for the final point if the AtlasRRT is
2879  bidirectional. */
2880  if (!InitAtlasFromPoint(pr,FALSE,TRUE,ps,w,&(ar->atlas)))
2881  Error("Can not start the atlas at the given point");
2882  ar->mc=INIT_NUM_CHARTS;
2883 
2884  ar->nc=GetAtlasNumCharts(&(ar->atlas));
2885 
2886  /* Note that InitAtlasFromPoint can change this parameter */
2887  ar->k=(unsigned int)GetParameter(CT_N_DOF,pr);
2888 
2889  /*************************************************************/
2890  /* Init the RRT */
2891  /* This verifies that the initial point are valid (on
2892  the manifold, collision free, in domain,...). It also
2893  checks this for the final point on bidirectional RRTs */
2895  InitRRT(pr,ar->parallel,FALSE,ps,mode,graph,pg,ar->m,w,&(ar->rrt));
2896  ar->ns=GetRRTNumNodes(&(ar->rrt));
2897 
2898  /*************************************************************/
2899  /* Init the mapping from samples to charts */
2900  NEW(ar->ci,ar->mc,TChartInfo*);
2901  for(i=0;i<ar->nc;i++)
2902  {
2903  NEW(ar->ci[i],1,TChartInfo);
2904  ar->ci[i]->lc=NO_UINT; /* No samples in any chart */
2905  ar->ci[i]->tree=START2GOAL;
2906  ar->ci[i]->it=0;
2907  }
2908 
2909  NEW(ar->si,ar->ms,TSampleInfo*);
2910 
2911  NEW(ar->si[0],1,TSampleInfo);
2912  /* This sets t[0] to zero (sample[0] is the center of the first chart) */
2913  currentSampleInfo=ar->si[0];
2914 
2915  NEW(currentSampleInfo->t,ar->k,double);
2916  for(i=0;i<ar->k;i++)
2917  currentSampleInfo->t[i]=0.0;
2918 
2919  /* Chart 0 is not generated from any other chart */
2920  currentSampleInfo->pc=NO_UINT;
2921 
2922  /* Pointer to the first sample in the RRT */
2923  currentSampleInfo->s=GetRRTNode(0,&(ar->rrt));
2924  currentSampleInfo->id=0;
2925 
2926  /* assign the first sample to the first chart */
2927  currentSampleInfo->c=0; /* fist sample is in chart 0 */
2928  ar->ci[0]->lc=0; /* list of samples for chart 0 start at sample 0 */
2929  currentSampleInfo->lsc=NO_UINT; /* and there is no other sample next */
2930 
2931  /* we have a chart on sample 0 */
2932  currentSampleInfo->generateChart=1;
2933 
2934  /*************************************************************/
2935  /* Init the mapping betwen charts and trees */
2936  if (ar->birrt)
2937  {
2938  NEW(ar->si[1],1,TSampleInfo);
2939  currentSampleInfo=ar->si[1];
2940 
2941  /* The goal samples has param 0 in its own chart */
2942  NEW(currentSampleInfo->t,ar->k,double);
2943 
2944  for(i=0;i<ar->k;i++)
2945  currentSampleInfo->t[i]=0.0;
2946 
2947  /* Allocate the samples 2 tree mapping */
2948  ar->mct1=ar->mc;
2949  NEW(ar->chartsAtTree1,ar->mct1,unsigned int);
2950 
2951  ar->mct2=ar->mc;
2952  NEW(ar->chartsAtTree2,ar->mct2,unsigned int);
2953 
2954  /* Assign char 0 to the first tree */
2955  ar->chartsAtTree1[0]=0;
2956  ar->nct1=1;
2957 
2958  ar->nct2=0;
2959  /* The chart for the goal sample is added to the tree
2960  using AddChart2AtlasRRT (see below) and this automatically
2961  updates ar->chartsAtTree2, ar->nct2,...*/
2962 
2963  /* Chart 1 is not generated from any other chart */
2964  currentSampleInfo->pc=NO_UINT;
2965 
2966  /* Pointer to the sample in the RRT */
2967  currentSampleInfo->s=GetRRTNode(1,&(ar->rrt));
2968  currentSampleInfo->id=1;
2969 
2970  /* By setting c[1]=1, AddChart2AtlasRRT does not
2971  re-assigns the new sample. We do it manually
2972  after the chart creation. */
2973  currentSampleInfo->c=1;
2974 
2975  if (!AddChart2AtlasRRT(pr,GOAL2START,0,currentSampleInfo,&intersectParent,ar))
2976  Error("Could not init the AtlasRRT on the given point (is it singular? decrease epsilon?)");
2977 
2978  /* Manually assign sample 1 to chart 1 */
2979  ar->ci[1]->lc=1;
2980  currentSampleInfo->lsc=NO_UINT;
2981  }
2982 
2983  /*************************************************************/
2984  /* Get the topology for all variables */
2985  ar->tp=GetRRTTopology(&(ar->rrt));
2986 
2987  /*************************************************************/
2988  /* Since atlas are defined on the simplified system we get the
2989  corresponding Jacobian. */
2990  CS_WD_GET_SIMP_JACOBIAN(pr,&(ar->J),ar->w);
2991 }
2992 
2993 boolean AtlasRRTSample(Tparameters *pr,unsigned int samplingMode,
2994  unsigned int it,unsigned int tree,
2995  double *goal,double scale,boolean *exploration,
2996  unsigned int *c_rand,double *t_rand,double *q_rand,
2997  TAtlasRRTStatistics *arst,Tatlasrrt *ar)
2998 {
2999  boolean expand2Goal,validSample;
3000  #if (ATLASRRT_VERBOSE)
3001  unsigned int s;
3002  #endif
3003 
3004  expand2Goal=((goal!=NULL)&&((it==0)||((!ar->birrt)&&(randomDouble()<0.01))));
3005 
3006  if (expand2Goal)
3007  {
3008  memcpy(q_rand,goal,ar->m*sizeof(double));
3009  #if (GET_ATLASRRT_STATISTICS)
3011  #endif
3012  #if (ATLASRRT_VERBOSE)
3013  fprintf(stderr," Expanding to goal-----------------------------------------------------------------\n");
3014  #endif
3015  *exploration=FALSE;
3016  *c_rand=NO_UINT;
3017  }
3018  else
3019  {
3020  #if (ATLASRRT_VERBOSE)
3021  s=0;
3022  #endif
3023  switch(samplingMode)
3024  {
3025  case AMBIENT_SAMPLING:
3026  case KDTREE_SAMPLING:
3027  do {
3028  RRTSample(samplingMode,tree,NULL,q_rand,NULL,&(ar->rrt));
3029  validSample=CS_WD_SIMP_INEQUALITIES_HOLD(pr,q_rand,ar->w);
3030  #if (ATLASRRT_VERBOSE)
3031  s++;
3032  #endif
3033  #if (GET_ATLASRRT_STATISTICS)
3035  if (!validSample)
3037  #endif
3038  } while (!validSample);
3039  *exploration=FALSE;
3040  *c_rand=NO_UINT;
3041  #if (ATLASRRT_VERBOSE)
3042  fprintf(stderr," Random point in ambient. Rej: %u\n",s);
3043  #endif
3044  break;
3045 
3046  case TANGENT_SAMPLING:
3047  do {
3048  validSample=RandomPointInAtlasTree(pr,scale,tree,c_rand,t_rand,q_rand,ar);
3049  #if (ATLASRRT_VERBOSE)
3050  s++;
3051  #endif
3052  #if (ADJUST_SR)
3053  if (!validSample)
3055  #endif
3056  #if (GET_ATLASRRT_STATISTICS)
3058  if (!validSample)
3060  #endif
3061  } while (!validSample);
3062 
3063  #if (ADJUST_SR)
3065  #endif
3066  *exploration=(Norm(ar->k,t_rand)>ar->r);
3067  #if (ATLASRRT_VERBOSE)
3068  fprintf(stderr," Random point on chart %u (rej: %u) [%g:%s]\n",*c_rand,s,
3069  Norm(ar->k,t_rand),(*exploration?"exp":"non-exp"));
3070  #endif
3071  break;
3072  default:
3073  Error("Unknow sampling mode in AtlasRRTSample");
3074  break;
3075  }
3076  }
3077 
3078  return(expand2Goal);
3079 }
3080 
3081 boolean AtlasRRTValidateSample(Tparameters *pr,double *q_rand,unsigned int tree,boolean expand2goal,
3082  unsigned int lastNN2Goal,double *goal,double l,double *h,unsigned int *i_near,
3083  TAtlasRRTStatistics *arst,Tatlasrrt *ar)
3084 {
3085  boolean validSample=TRUE;
3086 
3087  /* check if the sample in invalid due to a heuristic used in optimal path planning */
3088  if ((expand2goal)||(goal==NULL))
3089  *h=0;
3090  else
3091  {
3092  *h=DistanceTopology(ar->m,ar->tp,q_rand,goal);
3093  if ((l<INF)&&((HEURISTIC_RRT_STAR)&(1)))
3094  validSample=((DistanceTopology(ar->m,ar->tp,ar->si[0]->s,q_rand)+*h)<=l);
3095  }
3096 
3097  /* Now check if the sample is invalid due to its nearest neighbour (dynamic domain et al.) */
3098  if (validSample)
3099  {
3100  #if (ATLASRRT_GLOBAL_NN)
3101  /*search in the entire atlas */
3102  *i_near=GetRRTNN(tree,q_rand,&(ar->rrt));
3103  #else
3104  if (expand2Goal)
3105  *i_near=GetRRTNN(tree,q_rand,&(ar->rrt));
3106  else
3107  {
3108  /* limit the search to q_rand chart and neigbors charts */
3109  *i_near=GetRRTNNInNeighbourChart(tree,c_rand,t_rand,q_rand,ar);
3110  if (*i_near==NO_UINT)
3111  *i_near=GetRRTNN(tree,q_rand,&(ar->rrt));
3112  }
3113  #endif
3114  #if (ATLASRRT_VERBOSE)
3115  fprintf(stderr," Nearest point %u on chart %u \n",*i_near,ar->si[*i_near]->c);
3116  fflush(stdout);
3117  #endif
3118 
3119  /* Check if the random sample is in the domain of the nearest neighbour */
3120  /* This only has effect if paramter DYNAMIC_DOMAIN is >0 */
3121  validSample=(((!expand2goal)||(lastNN2Goal!=*i_near))&&
3122  (InDynamicDomain(*i_near,q_rand,&(ar->rrt))));
3123  }
3124 
3125  #if (GET_ATLASRRT_STATISTICS)
3126  if (!validSample)
3128  #endif
3129 
3130  return(validSample);
3131 }
3132 
3133 boolean AtlasRRT(Tparameters *pr,double *pg,double *time,
3134  double *pl,unsigned int *ns,double ***path,
3135  TAtlasRRTStatistics *str,Tatlasrrt *ar)
3136 {
3137  boolean done;
3138  double dst;
3139  unsigned int it,n;
3140  double er,epsilon,h;
3141  double *pWithDummies,*initialPoint,*finalPoint,*q_rand,*q_goal,*t_rand;
3142  boolean expand2Goal,pathFound;
3143  unsigned int samplingMode;
3144  unsigned int i_near1,i_near2;
3145  unsigned int t1,t2;
3146  unsigned int lastSample;
3147  unsigned int lastSample2;
3148  TAtlasRRTStatistics *arst;
3149  Tstatistics stime; /* used just to measure execution time */
3150  boolean collision=FALSE;
3151  unsigned int target;
3152  boolean reachedQRand,reachedGoal;
3153  unsigned int lastNN2Goal;
3154  unsigned int db;
3155  double maxTime;
3156  unsigned int maxNodes;
3157  boolean exploration;
3158  double scale; /* Global scale factor for the sampling areas */
3159  boolean validSample;
3160  unsigned int c_rand;
3161 
3162  db=(unsigned int)GetParameter(CT_DETECT_BIFURCATIONS,pr);
3163  if (db>0)
3164  Error("AtlasRRT can not deal with bifurcations (yet)");
3165 
3166  samplingMode=(unsigned int)GetParameter(CT_SAMPLING,pr);
3167 
3168  scale=1.0; /* Not used yet... */
3169 
3170  /* Initially the AtlasRRT must only include one sample and one chart or
3171  two sample and two chart for bidirectional trees */
3172  n=(ar->birrt?2:1);
3173  if ((ar->ns!=n)||(ar->nc!=n))
3174  Error("AtlasRRT must be used on a just initialized AtlasRRT");
3175 
3176  #if (GET_ATLASRRT_STATISTICS)
3177  {
3178  unsigned int i;
3179 
3180  NEW(arst,1,TAtlasRRTStatistics);
3181  InitAtlasRRTStatistics(arst);
3182  for(i=0;i<ar->nc;i++)
3183  NewAtlasRRTChart(arst);
3184  for(i=0;i<ar->ns;i++)
3185  NewAtlasRRTSample(arst);
3186  }
3187  #else
3188  arst=NULL;
3189  #endif
3190 
3191  /* Init the RRT structure */
3192  epsilon=GetParameter(CT_EPSILON,pr);
3193  maxTime=GetParameter(CT_MAX_PLANNING_TIME,pr);
3194  maxNodes=(unsigned int)GetParameter(CT_MAX_NODES_RRT,pr);
3195 
3196  /* For bi-directional AtlasRRTs the goal is already in the RRT
3197  and it is already verified */
3198  initialPoint=ar->si[0]->s;
3199  if (ar->birrt)
3200  finalPoint=ar->si[1]->s;
3201  else
3202  {
3203  if (EXPLORATION_RRT)
3204  finalPoint=NULL;
3205  else
3206  {
3207  /* For one-directional RRTS, the goal is given as a parameter when
3208  calling this function and we must ensure that it is valid */
3209  CS_WD_REGENERATE_SOLUTION_POINT(pr,pg,&pWithDummies,ar->w);
3210  CS_WD_GENERATE_SIMPLIFIED_POINT(pr,pWithDummies,&finalPoint,ar->w);
3211 
3212  if ((!PointInBoxTopology(NULL,TRUE,ar->m,finalPoint,0,ar->tp,&(ar->ambient)))||
3213  (!CS_WD_SIMP_INEQUALITIES_HOLD(pr,finalPoint,ar->w)))
3214  Error("The goal point for the RRT is not in domain");
3215 
3216  if (ar->m==ar->k) /* empty system of equations */
3217  er=0;
3218  else
3219  er=CS_WD_ERROR_IN_SIMP_EQUATIONS(pr,finalPoint,ar->w);
3220  if (er>epsilon)
3221  Error("The target point is not on the manifold");
3222 
3223  collision=CS_WD_ORIGINAL_IN_COLLISION(pr,pWithDummies,NULL,ar->w);
3224  if (collision)
3225  Error("Target point for the RRT is in collision");
3226  free(pWithDummies);
3227  }
3228  }
3229 
3230  NEW(q_rand,ar->m,double);
3231  if (ar->birrt)
3232  NEW(q_goal,ar->m,double);
3233  NEW(t_rand,ar->k,double);
3234 
3235  done=FALSE;
3236  lastNN2Goal=NO_UINT;
3237  it=0;
3238  InitStatistics(0,0,&stime);
3239  *time=0.0;
3240 
3241  /* The two trees. This is only used for bidirectiononal RRTs. In norma
3242  RRTs only the START2GOAL tree is extended*/
3243  t1=START2GOAL;
3244  t2=GOAL2START;
3245 
3246  while((!done)&&(*time<maxTime)&&(ar->ns<maxNodes))
3247  {
3248  #if (!ATLASRRT_VERBOSE)
3249  if ((it%1000)==0)
3250  #endif
3251  fprintf(stderr,"Iteration: %u (s:%u c:%u t:%u tm:%g sc:%.2f)\n",it,ar->ns,ar->nc,t1,*time,scale);
3252 
3253  /*******************************************************************/
3254  /* Sample */
3255  exploration=FALSE;
3256  do {
3257  /* Generate a random sample */
3258  expand2Goal=AtlasRRTSample(pr,samplingMode,it,t1,finalPoint,scale,
3259  &exploration,&c_rand,t_rand,q_rand,arst,ar);
3260 
3261  /* validate the random sample */
3262  validSample=AtlasRRTValidateSample(pr,q_rand,t1,expand2Goal,lastNN2Goal,NULL,INF,
3263  &h,&i_near1,arst,ar);
3264  } while (!validSample);
3265 
3266  if (expand2Goal)
3267  lastNN2Goal=i_near1;
3268 
3269  /*******************************************************************/
3270  /* Extend the RRT from q_near toward q_rand */
3271  #if (GET_ATLASRRT_STATISTICS)
3272  NewAtlasRRTBranch(arst);
3273  NewAtlasRRTDistanceQrand(DistanceTopology(ar->m,ar->tp,ar->si[i_near1]->s,q_rand),arst);
3274  #endif
3275  dst=AddBranchToAtlasRRT(pr,it,ADD_ALL,TRUE,TRUE,expand2Goal,exploration,
3276  0.0,i_near1,q_rand,
3277  (((!ar->birrt)||(t1==START2GOAL))?finalPoint:initialPoint),
3278  (void*)arst,&lastSample,&reachedQRand,&reachedGoal,NULL,NULL,
3279  NULL,NULL,ar);
3280  #if (GET_ATLASRRT_STATISTICS)
3281  if (dst>0)
3283  #endif
3284  done=((!EXPLORATION_RRT)&&(!ar->birrt)&&(reachedGoal));
3285 
3286  if ((!done)&&(ar->birrt))
3287  {
3288  if (dst>0)
3289  {
3290  #if (ADJUST_SA)
3291  if (samplingMode==TANGENT_SAMPLING)
3292  {
3293  #if (ADJUST_SA==2)
3294  /* No trouble extending branches: increase sampling area to focus on exploration */
3295  //scale=1.0;
3296  scale=scale*(1+MOV_AVG_UP);
3297  if (scale>1.0) scale=1.0;
3298  #else
3299  /* an alternative is to adjust the sampling radius locally */
3300  if (!expand2Goal)
3302  #endif
3303  }
3304  #endif
3305 
3306  /* Try to connect to the other tree */
3307 
3308  /* Get the node of the just added branch closer to the other tree (and the node of
3309  the other tree closer to this just added node). */
3310  GetRRTNNInBranch(t2,i_near1,lastSample,&target,&i_near2,&(ar->rrt));
3311 
3312  lastSample=target;
3313  memcpy(q_rand,ar->si[target]->s,ar->m*sizeof(double));
3314 
3315  memcpy(q_goal,q_rand,ar->m*sizeof(double));
3316 
3317  /* Try to connect the '2nd' tree to the last node added to the '1st' tree */
3318  #if (GET_ATLASRRT_STATISTICS)
3320  #endif
3322  0.0,i_near2,q_rand,q_goal,
3323  (void*)arst,&lastSample2,&reachedQRand,&reachedGoal,NULL,NULL,
3324  NULL,NULL,ar);
3325  #if (GET_ATLASRRT_STATISTICS)
3326  if (dst>0)
3328  #endif
3329 
3330  done=((!EXPLORATION_RRT)&&(reachedGoal));
3331  }
3332  #if (ADJUST_SA)
3333  else
3334  {
3335  if (samplingMode==TANGENT_SAMPLING)
3336  {
3337  #if (ADJUST_SA==2)
3338  /* Troubles extending branches: reduce the sampling areas to focus on refinement */
3339  scale=scale*(1-MOV_AVG_DOWN);
3340  if (scale<0.05) scale=0.05;
3341  #else
3342  /* an alternative is to adjust the sampling radius locally */
3343  if (!expand2Goal)
3345  #endif
3346  }
3347  }
3348  #endif
3349 
3350  /* Swap the trees */
3351  if ((it%2)==0)
3352  {
3353  t1=START2GOAL;
3354  t2=GOAL2START;
3355  }
3356  else
3357  {
3358  t1=GOAL2START;
3359  t2=START2GOAL;
3360  }
3361  }
3362 
3363  it++;
3364  *time=GetElapsedTime(&stime);
3365  }
3366  DeleteStatistics(&stime);
3367 
3368  #if (GET_ATLASRRT_STATISTICS)
3369  if (str==NULL)
3370  PrintAtlasRRTStatistics(ar,arst);
3371  else
3372  AccumulateAtlasRRTStatistics(arst,str);
3374  free(arst);
3375  #endif
3376 
3377  fprintf(stderr,"Final number of samples: %u\n",ar->ns);
3378 
3379  /* Reconstruct the path (if any) */
3380  if (EXPLORATION_RRT)
3381  pathFound=FALSE;
3382  else
3383  pathFound=PathStart2GoalInRRT(pr,finalPoint,lastSample,lastSample2,
3384  pl,NULL,ns,path,&(ar->rrt));
3385 
3386  free(t_rand);
3387  free(q_rand);
3388  if (ar->birrt)
3389  free(q_goal);
3390  else
3391  {
3392  if (finalPoint!=NULL)
3393  free(finalPoint);
3394  }
3395 
3396  return(pathFound);
3397 }
3398 
3399 boolean AtlasTRRT(Tparameters *pr,double *pg,double *time,
3400  double *pl,double *pc,unsigned int *ns,double ***path,
3401  double (*costF)(Tparameters*,boolean,double*,void*),
3402  void *costData,TAtlasRRTStatistics *str,Tatlasrrt *ar)
3403 {
3404  boolean done;
3405  unsigned int it;
3406  double er,epsilon,h;
3407  unsigned int samplingMode;
3408  double *pWithDummies,*finalPoint,*q_rand,*t_rand;
3409  unsigned int c_rand;
3410  boolean expand2Goal,pathFound,exploration;
3411  unsigned int i_near1;
3412  unsigned int lastSample;
3413  TAtlasRRTStatistics *arst;
3414  Tstatistics stime; /* used just to measure execution time */
3415  boolean collision=FALSE;
3416  boolean reachedQRand,reachedGoal;
3417  unsigned int lastNN2Goal;
3418  unsigned int db;
3419  double maxTime;
3420  unsigned int maxNodes;
3421  double scale; /* Global scale factor for sampling areas */
3422  boolean validSample;
3423 
3424  if (ar->birrt)
3425  Error("AtlasTRRT operates on one-directional RRTs");
3426 
3427  db=(unsigned int)GetParameter(CT_DETECT_BIFURCATIONS,pr);
3428  if (db>0)
3429  Error("AtlasRRT can not deal with bifurcations (yet)");
3430 
3431  samplingMode=(unsigned int)GetParameter(CT_SAMPLING,pr);
3432 
3433  scale=1.0; /* not used yet */
3434 
3435  /* Initially the AtlasRRT must only include one sample and one chart or
3436  two sample and two chart for bidirectional trees */
3437  if (ar->ns>1)
3438  Error("AtlasRRTstar must be used to a just initilized RRT");
3439 
3440  #if (GET_ATLASRRT_STATISTICS)
3441  {
3442  unsigned int i;
3443 
3444  NEW(arst,1,TAtlasRRTStatistics);
3445  InitAtlasRRTStatistics(arst);
3446  for(i=0;i<ar->nc;i++)
3447  NewAtlasRRTChart(arst);
3448  for(i=0;i<ar->ns;i++)
3449  NewAtlasRRTSample(arst);
3450  }
3451  #else
3452  arst=NULL;
3453  #endif
3454 
3455  /* Init the RRT structure */
3456  epsilon=GetParameter(CT_EPSILON,pr);
3457  maxTime=GetParameter(CT_MAX_PLANNING_TIME,pr);
3458  maxNodes=(unsigned int)GetParameter(CT_MAX_NODES_RRT,pr);
3459 
3460  if (EXPLORATION_RRT)
3461  finalPoint=NULL;
3462  else
3463  {
3464  /* One-directional RRTs, the goal is given as a parameter
3465  and we must ensure that it is valid */
3466  CS_WD_REGENERATE_SOLUTION_POINT(pr,pg,&pWithDummies,ar->w);
3467  CS_WD_GENERATE_SIMPLIFIED_POINT(pr,pWithDummies,&finalPoint,ar->w);
3468 
3469  if ((!PointInBoxTopology(NULL,TRUE,ar->m,finalPoint,0,ar->tp,&(ar->ambient)))||
3470  (!CS_WD_SIMP_INEQUALITIES_HOLD(pr,finalPoint,ar->w)))
3471  Error("The goal point for the RRT is not in domain");
3472 
3473  if (ar->m==ar->k)
3474  er=0;
3475  else
3476  er=CS_WD_ERROR_IN_SIMP_EQUATIONS(pr,finalPoint,ar->w);
3477  if (er>epsilon)
3478  Error("The target point is not on the manifold");
3479 
3480  collision=CS_WD_ORIGINAL_IN_COLLISION(pr,pWithDummies,NULL,ar->w);;
3481  if (collision)
3482  Error("Target point for the RRT is in collision");
3483  free(pWithDummies);
3484  }
3485 
3486  /*init the cost of the first node*/
3487  SetRRTNodeCost(0,0,costF(pr,TRUE,GetRRTNode(0,&(ar->rrt)),costData),&(ar->rrt));
3488 
3489  NEW(q_rand,ar->m,double);
3490  NEW(t_rand,ar->k,double);
3491 
3492  done=FALSE;
3493  lastNN2Goal=NO_UINT;
3494  it=1;
3495  InitStatistics(0,0,&stime);
3496  *time=0.0;
3497 
3498  while((!done)&&(*time<maxTime)&&(ar->ns<maxNodes))
3499  {
3500  #if (!ATLASRRT_VERBOSE)
3501  if ((it%1000)==0)
3502  #endif
3503  fprintf(stderr,"Iteration: %u (s:%u c:%u t:%u tm:%g tmp:%g)\n",it,ar->ns,ar->nc,
3504  START2GOAL,*time,GetTRRTTemperature(&(ar->rrt)));
3505 
3506 
3507  /*******************************************************************/
3508  /* Sample */
3509  exploration=FALSE;
3510  do {
3511  /* generate the random sample */
3512  expand2Goal=AtlasRRTSample(pr,samplingMode,it,START2GOAL,finalPoint,scale,
3513  &exploration,&c_rand,t_rand,q_rand,arst,ar);
3514 
3515  /* validate the random sample */
3516  validSample=AtlasRRTValidateSample(pr,q_rand,START2GOAL,expand2Goal,lastNN2Goal,NULL,INF,
3517  &h,&i_near1,arst,ar);
3518 
3519  /* There is no point in expanding the same node towards the goal twice */
3520  } while (!validSample);
3521 
3522  if (expand2Goal)
3523  lastNN2Goal=i_near1;
3524 
3525  /*******************************************************************/
3526  /* Extend the RRT from q_near toward q_rand */
3527  AddBranchToAtlasRRT(pr,it,ADD_ALL,TRUE,TRUE,expand2Goal,exploration,
3528  0.0,i_near1,q_rand,finalPoint,
3529  (void*)arst,&lastSample,&reachedQRand,&reachedGoal,
3530  NULL,NULL,costF,costData,ar);
3531 
3532  done=((!EXPLORATION_RRT)&&(reachedGoal));
3533 
3534  it++;
3535  *time=GetElapsedTime(&stime);
3536  }
3537  DeleteStatistics(&stime);
3538 
3539  #if (GET_ATLASRRT_STATISTICS)
3540  if (str==NULL)
3541  PrintAtlasRRTStatistics(ar,arst);
3542  else
3543  AccumulateAtlasRRTStatistics(arst,str);
3545  free(arst);
3546  #endif
3547 
3548  fprintf(stderr,"Final number of samples: %u\n",ar->ns);
3549 
3550  /* Reconstruct the path (if any) */
3551  pathFound=PathStart2GoalInRRT(pr,finalPoint,lastSample,NO_UINT,
3552  pl,pc,ns,path,&(ar->rrt));
3553 
3554  free(t_rand);
3555  free(q_rand);
3556  free(finalPoint);
3557 
3558  return(pathFound);
3559 }
3560 
3562  unsigned int it,boolean expand2Goal,
3563  unsigned int i_near,double *q_rand,
3564  unsigned int *id_goal,double *goal,
3565  TAtlasRRTStatistics *arst,
3566  Tatlasrrt *ar)
3567 {
3568  unsigned int id_new;
3569  double d,dg,epsilon;
3570  boolean reachedQRand,reachedGoal;
3571 
3572  epsilon=GetParameter(CT_EPSILON,pr);
3573 
3574  /* Try to advance as much as possible in the direction of q_rand. Only
3575  the last node is added to the tree. */
3576  d=AddBranchToAtlasRRT(pr,it,(expand2Goal?ADD_LAST_NO_REP:ADD_LAST),TRUE,TRUE,expand2Goal,FALSE,
3577  0.0,i_near,q_rand,goal,
3578  (void*)arst,&id_new,&reachedQRand,&reachedGoal,NULL,NULL,NULL,NULL,ar);
3579 
3580  /* if we actually added a node */
3581  if (id_new!=i_near)
3582  {
3583  /* Store the cost of the new node. The cost to the parent is already correct (we
3584  need it if 'graph's is set to TRUE) but the total cost is not set */
3585  SetRRTNodeCost(id_new,d,GetRRTNodeCost(i_near,&(ar->rrt))+d,&(ar->rrt));
3586 
3587  #if (ATLASRRT_VERBOSE)
3588  fprintf(stderr," {%u->%u}[%g]\n",id_new,GetRRTParent(id_new,&(ar->rrt)),d);
3589  #endif
3590 
3591  /* if the new point is actually the goal record it */
3592  if ((goal!=NULL)&&(*id_goal==NO_UINT)&&
3593  ((reachedGoal)||((expand2Goal)&&(reachedQRand))))
3594  {
3595  dg=DistanceTopology(ar->m,ar->tp,ar->si[id_new]->s,goal);
3596 
3597  if (dg<epsilon)
3598  /* The new node is actually the goal */
3599  *id_goal=id_new;
3600  else
3601  {
3602  /* If the branch stopped very close to the goal, we add a small
3603  branch from the end of the branch to the goal and the goal itself. */
3604  d=AddBranchToAtlasRRT(pr,it,ADD_LAST,TRUE,TRUE,TRUE,FALSE,
3605  0.0,id_new,goal,NULL,
3606  (void*)arst,id_goal,&reachedQRand,&reachedGoal,NULL,NULL,
3607  NULL,NULL,ar);
3608 
3609  if (!reachedQRand)
3610  Error("Could not reach goal from near-gaol");
3611 
3612  SetRRTNodeCost(*id_goal,d,GetRRTNodeCost(id_new,&(ar->rrt))+d,&(ar->rrt));
3613 
3614  #if (RRT_VERBOSE)
3615  fprintf(stderr," {%u->%u}[%g] **\n",*id_goal,GetRRTParent(*id_goal,&(ar->rrt)),d);
3616  #endif
3617  }
3618  }
3619  }
3620  return(id_new);
3621 }
3622 
3624  unsigned int id_new,unsigned int i_near,double gamma,
3625  unsigned int nn,unsigned int *n,double **c,
3626  double h,Theap *q,unsigned int *t,
3627  TAtlasRRTStatistics *arst,Tatlasrrt *ar)
3628 {
3629  unsigned int i,lastID;
3630  double ic,cn,epsilon,c_new;
3631  double *cost;
3632  boolean *reachedQRand;
3633  double *q_new;
3634  TDoublePair pair;
3635  unsigned int rrtMode;
3636  boolean graph;
3637 
3638  epsilon=GetParameter(CT_EPSILON,pr);
3639 
3640  /*******************************************************************/
3641  /* Wire: Search for the lowest cost path to the new node */
3642  #if (ATLASRRT_VERBOSE)
3643  fprintf(stderr," Wire %u [nn:%u g:%g]\n",id_new,nn,gamma);
3644  #endif
3645  rrtMode=GetRRTMode(&(ar->rrt));
3646  graph=IsRRTGraph(&(ar->rrt));
3647  #if (RRTSTAR_SYMMETRIC_COST)
3648  if (!graph)
3649  NEW(*c,nn,double);
3650  #endif
3651  ic=GetRRTNodeCostFromParent(id_new,&(ar->rrt)); /*cost to i_near*/
3652  q_new=ar->si[id_new]->s;
3653  *t=0; /* initially no tree in the set of neighbours */
3654 
3655  NEW(cost,nn,double);
3656  NEW(reachedQRand,nn,boolean);
3657 
3658  #pragma omp parallel for private(i) schedule(dynamic) if (ar->parallel)
3659  for(i=0;i<nn;i++)
3660  {
3661  if (n[i]==id_new)
3662  reachedQRand[i]=FALSE;
3663  else
3664  {
3665  if (n[i]==i_near)
3666  {
3667  cost[i]=ic;
3668  reachedQRand[i]=TRUE;
3669  }
3670  else
3671  {
3672  if (ar->parallel)
3673  {
3674  boolean collision;
3675 
3676  /* When executing in parallel we:
3677  - Do not collect statistics about the connection process.
3678  - Do not add new charts to the atlas. We only generate temporary charts. */
3679  cost[i]=ConnectSamplesChart(pr,ar->tp,&(ar->ambient),
3680  ar->m,ar->m-ar->k,ar->si[n[i]]->s,q_new,gamma,
3681  TRUE,&(reachedQRand[i]),&collision,NULL,NULL,NULL,ar->w);;
3682  }
3683  else
3684  {
3685  boolean reachedGoal;
3686 
3688  gamma,n[i],q_new,NULL,
3689  (void*)arst,&lastID,&(reachedQRand[i]),&reachedGoal,NULL,NULL,
3690  NULL,NULL,ar);
3691  }
3692  }
3693  }
3694  }
3695 
3696  for(i=0;i<nn;i++)
3697  {
3698  if (n[i]!=id_new)
3699  {
3700  #if (GET_ATLASRRT_STATISTICS)
3701  NewAtlasRRTBranch(arst);
3702  #endif
3703  (*t)|=GetRRTNodeTree(n[i],&(ar->rrt)); /* take note of the tree of this neighbour (even if not reached)*/
3704  }
3705 
3706  if (reachedQRand[i])
3707  {
3708  cn=cost[i];
3709 
3710  #if (GET_ATLASRRT_STATISTICS)
3712  #endif
3713 
3714  /* update the cost of the reached neighbour */
3715  #if (!RRTSTAR_UPDATE_COSTS)
3716  if (rrtMode==TWO_TREES_WITH_SWAP)
3717  #endif
3718  UpdateCostAndTree(n[i],&(ar->rrt));
3719 
3720  /* There is an edge connecting id_new and n[i] */
3721  if (graph)
3722  AddEdgeToRRT(id_new,n[i],cn,&(ar->rrt));
3723 
3724  c_new=GetRRTNodeCost(n[i],&(ar->rrt))+cn;
3725  if (c_new<(GetRRTNodeCost(id_new,&(ar->rrt))-epsilon))
3726  {
3727  #if (ATLASRRT_VERBOSE)
3728  fprintf(stderr," {%u->%u}[%g %g] ->",id_new,GetRRTParent(id_new,&(ar->rrt)),
3729  GetRRTNodeCostFromParent(id_new,&(ar->rrt)),
3730  GetRRTNodeCost(id_new,&(ar->rrt)));
3731  #endif
3732 
3733  SetRRTCostAndParent(id_new,n[i],cn,c_new,&(ar->rrt));
3734 
3735  #if (ATLASRRT_VERBOSE)
3736  fprintf(stderr,"{%u->%u}[%g %g]\n",id_new,GetRRTParent(id_new,&(ar->rrt)),
3737  GetRRTNodeCostFromParent(id_new,&(ar->rrt)),
3738  GetRRTNodeCost(id_new,&(ar->rrt)));
3739  #endif
3740  }
3741  }
3742  else
3743  cn=INF;
3744 
3745  #if (RRTSTAR_SYMMETRIC_COST)
3746  if (!graph)
3747  (*c)[i]=cn;
3748  #endif
3749  }
3750 
3751  free(cost);
3752  free(reachedQRand);
3753 
3754  if (graph)
3755  {
3756  if (!q)
3757  Error("RRT must be in graph mode to use a heap");
3758  c_new=GetRRTNodeCost(id_new,&(ar->rrt));
3759  NewDoublePair(c_new+h,c_new,&pair);
3760  AddElement2Heap(id_new,(void *)&pair,q);
3761  }
3762 }
3763 
3765  unsigned int id_new,double gamma,
3766  unsigned int nn,unsigned int *n,double *c,
3767  Tvector *steps,double *l,
3768  TAtlasRRTStatistics *arst,Tatlasrrt *ar)
3769 {
3770 
3771  unsigned int i,parent;
3772  double cn,epsilon,c_new;
3773  boolean reachedQRand;
3774  unsigned int rrtMode;
3775  #if (!RRTSTAR_SYMMETRIC_COST)
3776  boolean reachedGoal;
3777  unsigned int lastID;
3778  #endif
3779 
3780  epsilon=GetParameter(CT_EPSILON,pr);
3781 
3782  #if (ATLASRRT_VERBOSE)
3783  fprintf(stderr," Rewire\n");
3784  #endif
3785  rrtMode=GetRRTMode(&(ar->rrt));
3786  /* best parent for the new node */
3787  parent=GetRRTParent(id_new,&(ar->rrt));
3788  for(i=0;i<nn;i++)
3789  {
3790  if ((n[i]==id_new)||(n[i]==parent))
3791  reachedQRand=FALSE;
3792  else
3793  {
3794  #if (RRTSTAR_SYMMETRIC_COST)
3795  cn=c[i];
3796  reachedQRand=(cn<INF);
3797  #else
3798  /* cost to go from id_new to n[i] */
3799  /* the branch is virtual-> nothing is added to the RRT */
3801  gamma,id_new,ar->si[n[i]]->s,NULL,
3802  (void*)arst,&lastID,&reachedQRand,&reachedGoal,NULL,NULL,NULL,NULL,ar);
3803  #endif
3804  }
3805 
3806  if (reachedQRand)
3807  {
3808  /* Ensure that any previous-rewire is propagated to the currently tested node */
3809  if (rrtMode==TWO_TREES_WITH_SWAP)
3810  UpdateCostAndTree(n[i],&(ar->rrt));
3811 
3812  c_new=GetRRTNodeCost(id_new,&(ar->rrt))+cn;
3813  if (c_new<(GetRRTNodeCost(n[i],&(ar->rrt))-epsilon))
3814  {
3815  #if (ATLASRRT_VERBOSE)
3816  fprintf(stderr," {%u->%u}[%g] ->",n[i],GetRRTParent(n[i],&(ar->rrt)),
3817  GetRRTNodeCostFromParent(n[i],&(ar->rrt)));
3818  #endif
3819 
3820  SetRRTCostAndParent(n[i],id_new,cn,c_new,&(ar->rrt));
3821 
3822  #if (ATLASRRT_VERBOSE)
3823  fprintf(stderr,"{%u->%u}[%g]\n",n[i],GetRRTParent(n[i],&(ar->rrt)),
3824  GetRRTNodeCostFromParent(n[i],&(ar->rrt)));
3825  #endif
3826  }
3827  else
3828  {
3829  /* if the node is connected to a sample in a different tree, update the optimal path */
3830  if ((rrtMode==TWO_TREES_WITH_SWAP)&&(steps!=NULL)&&(l!=NULL)&&
3831  (GetRRTNodeTree(n[i],&(ar->rrt))!=GetRRTNodeTree(id_new,&(ar->rrt))))
3832  {
3833  c_new+=GetRRTNodeCost(n[i],&(ar->rrt)); /* cost of start to goal via this connection
3834  between trees.*/
3835  if (c_new<*l)
3836  *l=ChangeBiRRTSteps(n[i],id_new,cn,steps,&(ar->rrt));
3837  }
3838  }
3839  }
3840  }
3841 }
3842 
3843 void AtlasRRTstarCloseIteration(unsigned int it,unsigned int id_goal,
3844  double time,double gamma,
3845  double *times,double *costs,
3846  Tatlasrrt *ar)
3847 {
3848  /* Print information about the quality of the path so far */
3849 
3850  if ((ATLASRRT_VERBOSE)||((it%1000)==0))
3851  {
3852  if (id_goal!=NO_UINT)
3853  {
3854  fprintf(stderr,"Iteration: %u (s:%u nc:%u t:%g g:%g c:%g [%g] [%u])\n",it,ar->ns,ar->nc,
3855  time,gamma,GetRRTNodeCost(id_goal,&(ar->rrt)),CostToRoot(id_goal,&(ar->rrt)),id_goal);
3856  }
3857  else
3858  fprintf(stderr,"Iteration: %u (s:%u t:%g)\n",it,ar->ns,time);
3859  fflush(stdout);
3860  }
3861 
3862  /*******************************************************************/
3863  /* Store information about the quality of the path so far and
3864  conclude the iteration */
3865 
3866  if (times!=NULL)
3867  times[it]=time;
3868 
3869  if (costs!=NULL)
3870  {
3871  if (id_goal==NO_UINT)
3872  costs[it]=-1.0;
3873  else
3874  costs[it]=GetRRTNodeCost(id_goal,&(ar->rrt)); //CostToRoot(id_goal,&(ar->rrt));
3875  }
3876 }
3877 
3878 void AtlasBiRRTstarCloseIteration(unsigned int it,double l,
3879  double time,double gamma,
3880  double *times,double *costs,
3881  Tatlasrrt *ar)
3882 {
3883  if ((ATLASRRT_VERBOSE)||((it%1000)==0))
3884  {
3885  if (l<INF)
3886  {
3887  fprintf(stderr,"Iteration: %u (s:%u nc: %u t:%g g:%g c:%g)\n",it,ar->ns,ar->nc,
3888  time,gamma,l);
3889  }
3890  else
3891  fprintf(stderr,"Iteration: %u (s:%u t:%g)\n",it,ar->ns,time);
3892  fflush(stdout);
3893  }
3894 
3895  if (times!=NULL)
3896  times[it]=time;
3897 
3898  if (costs!=NULL)
3899  {
3900  if (l<INF)
3901  costs[it]=l;
3902  else
3903  costs[it]=-1.0;
3904  }
3905 }
3906 
3907 
3908 boolean AtlasRRTstar(Tparameters *pr,double *pg,
3909  unsigned int *it,double *times,double *costs,
3910  double *planningTime,double *pl,unsigned int *ns,double ***path,
3911  TAtlasRRTStatistics *str,Tatlasrrt *ar)
3912 {
3913  if (EXPLORATION_RRT)
3914  Error("AtlasRRTstart is not designed for exploration RRTs");
3915 
3916  if (ar->birrt)
3917  return(AtlasBiRRTstar(pr,pg,it,times,costs,planningTime,pl,ns,path,str,ar));
3918  else
3919  {
3920  double *pWithDummies,*pgs,*t_rand,*q_rand,*q_new;
3921  unsigned int i,id_new,id_goal,c_rand,samplingMode;
3922  unsigned int i_near;
3923  double time,epsilon,delta,er,gamma,ct_gamma;
3924  Tstatistics st; /* used just to measure execution time */
3925  boolean collision,expand2Goal,done,optimal,validSample,exploration;
3926  #if (RRTSTAR_SYMMETRIC_COST)
3927  /* cost of paths to neighbouring nodes */
3928  double *c;
3929  #endif
3930  /* neighbours for each new node */
3931  unsigned int nn;
3932  unsigned int *n;
3933  TAtlasRRTStatistics *arst;
3934  double maxTime;
3935  unsigned int maxIterations;
3936  double h,l;
3937  Theap q;
3938  boolean graph;
3939  unsigned int vt; /* trees in set of neighbours, only relevant in bi-RRTs */
3940  double numSamples;
3941  double scale; /* Global adjustment of sampling areas */
3942 
3943  if (ar->ns>1)
3944  Error("AtlasRRTstart must be used to a just initilized RRT");
3945 
3946  #if (GET_ATLASRRT_STATISTICS)
3947  {
3948  unsigned int i;
3949 
3950  NEW(arst,1,TAtlasRRTStatistics);
3951  InitAtlasRRTStatistics(arst);
3952  for(i=0;i<ar->nc;i++)
3953  NewAtlasRRTChart(arst);
3954  for(i=0;i<ar->ns;i++)
3955  NewAtlasRRTSample(arst);
3956  }
3957  #else
3958  arst=NULL;
3959  #endif
3960 
3961  scale=1.0; /* not used yet */
3962 
3963  /* Init the AtlasRRT structure */
3964  epsilon=GetParameter(CT_EPSILON,pr);
3965  delta=GetParameter(CT_DELTA,pr);
3966  ct_gamma=GetParameter(CT_GAMMA,pr);
3967  maxTime=GetParameter(CT_MAX_PLANNING_TIME,pr);
3968  maxIterations=(unsigned int)GetParameter(CT_MAX_PLANNING_ITERATIONS,pr);
3969  samplingMode=(unsigned int)GetParameter(CT_SAMPLING,pr);
3970 
3971  graph=IsRRTGraph(&(ar->rrt));
3972 
3973  CS_WD_REGENERATE_SOLUTION_POINT(pr,pg,&pWithDummies,ar->w);
3974  CS_WD_GENERATE_SIMPLIFIED_POINT(pr,pWithDummies,&pgs,ar->w);
3975 
3976  if ((!PointInBoxTopology(NULL,TRUE,ar->m,pgs,0,ar->tp,&(ar->ambient)))||
3977  (!CS_WD_SIMP_INEQUALITIES_HOLD(pr,pgs,ar->w)))
3978  Error("The targed point for the AtlasRRTstar is not in domain");
3979 
3980  if (ar->m==ar->k)
3981  er=0;
3982  else
3983  er=CS_WD_ERROR_IN_SIMP_EQUATIONS(pr,pgs,ar->w);
3984  if (er>epsilon)
3985  Error("The target point for the AtlasRRTstar is not on the manifold");
3986 
3987  collision=CS_WD_ORIGINAL_IN_COLLISION(pr,pWithDummies,NULL,ar->w);
3988  if (collision)
3989  Error("The target point for the AtlasRRTstar is in collision");
3990  free(pWithDummies);
3991 
3992  /* Room for the randomly generated samples (and its correspoinding point
3993  on the manifold) */
3994  NEW(q_rand,ar->m,double);
3995  NEW(t_rand,ar->k,double);
3996 
3997  /* Reset the output statistics (just in case maxIterations
3998  is not reached) */
3999  for(i=0;i<maxIterations;i++)
4000  {
4001  times[i]=0;
4002  costs[i]=-1;
4003  }
4004 
4005  if (graph)
4007  LessThanDoublePair,NULL,TRUE,ar->ms,&q);
4008 
4009  gamma=ct_gamma;
4010  optimal=(ct_gamma>0);
4011 
4012  id_goal=NO_UINT;
4013  *it=0;
4014 
4015  InitStatistics((ar->parallel?2:1),0,&st); /* 2 just to indicated multi-core process */
4016  time=0.0;
4017  done=FALSE;
4018  l=INF; /* cost to goal (INF while goal not found) */
4019  c=NULL; /* default -> no cache of costs to neighbours */
4020 
4021  while ((!done)&&(time<maxTime)&&(*it<maxIterations))
4022  {
4023  #if (HEURISTIC_RRT_STAR&(1))
4024  /* keep the cost to goal up to date so that the heuristic
4025  is more effective*/
4026  if (id_goal!=NO_UINT)
4027  UpdateCostAndTree(id_goal,&(ar->rrt));
4028  #endif
4029 
4030  /*******************************************************************/
4031  /* best estimation of the cost to goal (up to now) */
4032  if (id_goal==NO_UINT)
4033  l=INF;
4034  else
4035  l=GetRRTNodeCost(id_goal,&(ar->rrt));
4036 
4037  /*******************************************************************/
4038  /* Generate a random sample */
4039  do {
4040  /* Generate the sample */
4041  expand2Goal=AtlasRRTSample(pr,samplingMode,*it,START2GOAL,(id_goal==NO_UINT?pgs:NULL),
4042  scale,&exploration,&c_rand,t_rand,q_rand,arst,ar);
4043 
4044 
4045  /* validate the random sample */
4046  validSample=AtlasRRTValidateSample(pr,q_rand,START2GOAL,expand2Goal,NO_UINT,
4047  pgs,l,&h,&i_near,arst,ar);
4048  } while (!validSample);
4049 
4050  /*******************************************************************/
4051  /* Extend the AtlasRRT from q_near to q_rand */
4052  /* Note that here we use a connect strategy but we only add the last sample */
4053  id_new=AddStepToAtlasRRTstar(pr,*it,expand2Goal,i_near,q_rand,
4054  &id_goal,pgs,(void*)arst,ar);
4055 
4056  /*******************************************************************/
4057  if (!optimal)
4058  {
4059  if (id_goal!=NO_UINT)
4060  done=TRUE;
4061  }
4062  else
4063  {
4064  /* If we actually added something */
4065  if ((id_new!=i_near)&&((((HEURISTIC_RRT_STAR)&(2))==0)||(id_goal!=NO_UINT)))
4066  {
4067  /* q_new is the last samples added to the tree */
4068  q_new=ar->si[id_new]->s;
4069  h=DistanceTopology(ar->m,ar->tp,q_new,pgs);
4070 
4071  /* Wire and re-wire the tree, only we we are interested in an optimal path
4072  If heristic #4 is active optimization is delayed until the goal is found */
4073 
4074  /*******************************************************************/
4075  /* Search for the set of potential neighbours */
4076  numSamples=(double)(ar->ns<3?3:ar->ns);
4077  gamma=ct_gamma*pow(log(numSamples)/numSamples,1.0/(double)ar->k);
4078  gamma=(gamma<delta?delta:gamma);
4079 
4080  GetRRTNNInBall(START2GOAL,q_new,gamma,&nn,&n,&(ar->rrt));
4081 
4082  /*******************************************************************/
4083  /* Wire: Search for the lowest cost path to the new node */
4084  WireAtlasRRTstar(pr,id_new,i_near,gamma,nn,n,&c,h,(graph?&q:NULL),&vt,arst,ar);
4085 
4086  /*******************************************************************/
4087  /* Rewire the tree around the new point */
4088  if (graph)
4089  RecursiveReWireRRTstar(pr,&q,pgs,NULL,&l,&(ar->rrt));
4090  else
4091  ReWireAtlasRRTstar(pr,id_new,gamma,nn,n,c,NULL,&l,arst,ar);
4092 
4093  /*******************************************************************/
4094  /* release the data for this iteration */
4095  if (c!=NULL)
4096  free(c);
4097  free(n);
4098  }
4099  #if (ATLASRRT_VERBOSE)
4100  else
4101  {
4102  if (id_new==i_near)
4103  fprintf(stderr," Blocked [%u]\n",i_near);
4104  }
4105  #endif
4106  }
4107 
4108  /*******************************************************************/
4109  /* Print a summary about this iteration */
4110  time=GetElapsedTime(&st);
4111 
4112  AtlasRRTstarCloseIteration(*it,id_goal,time,gamma,times,costs,ar);
4113 
4114  (*it)++;
4115  }
4116 
4117  if (graph)
4118  DeleteHeap(&q);
4119 
4120  *planningTime=time;
4121 
4122  DeleteStatistics(&st);
4123 
4124  fprintf(stderr,"Final number of samples: %u\n",ar->ns);
4125 
4126  /* Reconstruct the path (if any) */
4127  if (id_goal!=NO_UINT)
4128  ReconstructAtlasRRTPath(pr,id_goal,pl,ns,path,ar);
4129 
4130  /* Release memory */
4131  free(t_rand);
4132  free(q_rand);
4133  free(pgs);
4134 
4135  #if (GET_ATLASRRT_STATISTICS)
4136  if (str==NULL)
4137  PrintAtlasRRTStatistics(ar,arst);
4138  else
4139  AccumulateAtlasRRTStatistics(arst,str);
4141  free(arst);
4142  #endif
4143 
4144  return(id_goal!=NO_UINT);
4145  }
4146 }
4147 
4148 boolean AtlasBiRRTstar(Tparameters *pr,double *pg,
4149  unsigned int *it,double *times,double *costs,
4150  double *planningTime,double *pl,unsigned int *ns,double ***path,
4151  TAtlasRRTStatistics *str,Tatlasrrt *ar)
4152 {
4153 
4154  if (EXPLORATION_RRT)
4155  Error("AtlasBiRRTstart is not designed for exploration RRTs");
4156 
4157  if (!ar->birrt)
4158  return(AtlasRRTstar(pr,pg,it,times,costs,planningTime,pl,ns,path,str,ar));
4159  else
4160  {
4161  double *q_rand,*t_rand,*g;
4162  unsigned int c_rand;
4163  unsigned int i_near;
4164  double delta;
4165  Tstatistics st; /* used just to measure execution time */
4166  double time;
4167  #if (RRTSTAR_SYMMETRIC_COST)
4168  /* if the cost function is symmetrical, we cache
4169  the evaluation of the cost to neighbour. */
4170  double *c;
4171  #endif
4172  /* neighbours for each new node */
4173  unsigned int nn;
4174  unsigned int *n;
4175  /* distance q_rand,tree */
4176  double gamma,ct_gamma;
4177  unsigned int i,id_new,samplingMode;
4178  double *q_new;
4179  boolean done,optimal,validSample,exploration;
4180  double l; /* length of the shortest path so far */
4181  double h;
4182  Theap q;
4183  Tvector steps;
4184  TAtlasRRTStatistics *arst;
4185  double maxTime;
4186  unsigned int maxIterations;
4187  boolean graph;
4188  unsigned int vt;
4189  double l1,c12;
4190  boolean reachedQRand,reachedGoal;
4191  unsigned int lastID;
4192  double numSamples;
4193  double scale; /* Global adjust of sampling areas */
4194 
4195  if (ar->ns>2)
4196  Error("AtlasBiRRTstart must be used to a just initilized RRT");
4197 
4198  #if (GET_ATLASRRT_STATISTICS)
4199  {
4200  unsigned int i;
4201 
4202  NEW(arst,1,TAtlasRRTStatistics);
4203  InitAtlasRRTStatistics(arst);
4204  for(i=0;i<ar->nc;i++)
4205  NewAtlasRRTChart(arst);
4206  for(i=0;i<ar->ns;i++)
4207  NewAtlasRRTSample(arst);
4208  }
4209  #else
4210  arst=NULL;
4211  #endif
4212 
4213  scale=1.0; /* not used yet */
4214 
4215  /* Init the RRT structure */
4216  delta=GetParameter(CT_DELTA,pr);
4217  ct_gamma=GetParameter(CT_GAMMA,pr);
4218  maxTime=GetParameter(CT_MAX_PLANNING_TIME,pr);
4219  maxIterations=(unsigned int)GetParameter(CT_MAX_PLANNING_ITERATIONS,pr);
4220  samplingMode=(unsigned int)GetParameter(CT_SAMPLING,pr);
4221 
4222  graph=IsRRTGraph(&(ar->rrt));
4223 
4224  /* Room for the randomly generated samples (and its correspoinding point
4225  on the manifold) */
4226  NEW(q_rand,ar->m,double);
4227  NEW(t_rand,ar->k,double);
4228 
4229  /* Reset the output statistics (just in case maxIterations
4230  is not reached) */
4231  for(i=0;i<maxIterations;i++)
4232  {
4233  times[i]=0;
4234  costs[i]=-1;
4235  }
4236 
4237  if (graph)
4239  LessThanDoublePair,NULL,TRUE,ar->ms,&q);
4240 
4241  gamma=ct_gamma;
4242  optimal=(ct_gamma>0);
4243 
4244  *it=0;
4245 
4246  InitStatistics((ar->parallel?2:1),0,&st); /* if parallel 2 indicates multi-core */
4247  time=0.0;
4248  done=FALSE;
4249 
4250  InitVector(sizeof(TRRTStep),CopyRRTStep,DeleteRRTStep,100,&steps);
4251  l=INF;
4252  c=NULL;
4253 
4254  while ((!done)&&(time<maxTime)&&(*it<maxIterations))
4255  {
4256  /* keep the optimal path up to date (if any) */
4257  if (l<INF)
4258  l=UpdateBiRRTSteps(&steps,&(ar->rrt));
4259 
4260  /*******************************************************************/
4261  do {
4262  /* Geerate a random sample */
4263  AtlasRRTSample(pr,samplingMode,*it,BOTHTREES,NULL,scale,
4264  &exploration,&c_rand,t_rand,q_rand,arst,ar);
4265 
4266  /* validate the random sample */
4267  validSample=AtlasRRTValidateSample(pr,q_rand,BOTHTREES,FALSE,NO_UINT,
4268  ar->si[1]->s,l,&h,&i_near,arst,ar);
4269  } while (!validSample);
4270 
4271  /*******************************************************************/
4272  /* decide who is the goal (for the heuristic) */
4273  if (GetRRTNodeTree(i_near,&(ar->rrt))==START2GOAL)
4274  g=ar->si[1]->s;
4275  else
4276  g=ar->si[0]->s;
4277  h=DistanceTopology(ar->m,ar->tp,q_rand,g);
4278 
4279 
4280  /*******************************************************************/
4281  /* Extend the AtlasRRT from q_near to q_rand using the cbiRRT extend method */
4282  /* Note that here we use a extend strategy (we only add one sample) */
4283 
4284  id_new=AddStepToAtlasRRTstar(pr,*it,FALSE,i_near,q_rand,
4285  NULL,NULL,(void*)arst,ar);
4286 
4287  /* If we actually added something */
4288  if ((id_new!=i_near)&&((((HEURISTIC_RRT_STAR)&(2))==0)||(l<INF)))
4289  {
4290  /* q_new is the last samples added to the tree */
4291  q_new=ar->si[id_new]->s;
4292  h=DistanceTopology(ar->m,ar->tp,q_new,g);
4293 
4294  /*******************************************************************/
4295  /* Search for the set of potential neighbours */
4296  numSamples=(double)(ar->ns<3?3:ar->ns);
4297  gamma=ct_gamma*pow(log(numSamples)/numSamples,1.0/(double)ar->k);
4298  gamma=(gamma<delta?delta:gamma);
4299 
4300  GetRRTNNInBall(BOTHTREES,q_new,gamma,&nn,&n,&(ar->rrt));
4301 
4302  /*******************************************************************/
4303  /* Wire: Search for the lowest cost path to the new node */
4304  WireAtlasRRTstar(pr,id_new,i_near,gamma,nn,n,&c,h,(graph?&q:NULL),&vt,arst,ar);
4305 
4306  /*******************************************************************/
4307  /* Rewire the tree around the new point */
4308  if (graph)
4309  RecursiveReWireRRTstar(pr,&q,g,&steps,&l,&(ar->rrt));
4310  else
4311  ReWireAtlasRRTstar(pr,id_new,gamma,nn,n,c,&steps,&l,arst,ar);
4312 
4313  /*******************************************************************/
4314  /* release the data for this iteration (cost and neighbours) */
4315  if (c!=NULL)
4316  free(c);
4317  free(n);
4318 
4319  /*******************************************************************/
4320  /* If the set of neighbours does not include nodes in the two trees
4321  and we do not have a path start<->goal we try to connect the two
4322  trees (this is hardly used since when l=INF, gamma is large and
4323  the neighbours always include nodes in the two trees) */
4324  //if ((vt!=BOTHTREES)&&(l==INF))
4325  if (vt!=BOTHTREES)
4326  {
4327  /* In the re-wire the current sample might end up in tree 't2'
4328  and the connection must be always with the other tree */
4329  if (GetRRTNodeTree(id_new,&(ar->rrt))==START2GOAL)
4330  i_near=GetRRTNN(GOAL2START,q_new,&(ar->rrt));
4331  else
4332  i_near=GetRRTNN(START2GOAL,q_new,&(ar->rrt));
4333 
4334  l1=GetRRTNodeCost(id_new,&(ar->rrt))+GetRRTNodeCost(i_near,&(ar->rrt));
4336  (l<INF?l-l1:0.0),id_new,ar->si[i_near]->s,NULL,
4337  (void*)arst,&lastID,&reachedQRand,&reachedGoal,NULL,NULL,NULL,NULL,ar);
4338 
4339  if (reachedQRand)
4340  {
4341  if (graph)
4342  AddEdgeToRRT(id_new,i_near,c12,&(ar->rrt));
4343  l1+=c12;
4344  if (l1<l)
4345  l=ChangeBiRRTSteps(id_new,i_near,c12,&steps,&(ar->rrt));
4346  }
4347  }
4348  }
4349  #if (ATLASRRT_VERBOSE)
4350  else
4351  {
4352  if (id_new==i_near)
4353  fprintf(stderr," Blocked [%u]\n",i_near);
4354  }
4355  #endif
4356 
4357  if (!optimal)
4358  done=(l<INF);
4359 
4360  /*******************************************************************/
4361  /* Conclude the iteration */
4362  time=GetElapsedTime(&st);
4363 
4364  AtlasBiRRTstarCloseIteration(*it,l,time,gamma,times,costs,ar);
4365 
4366  (*it)++;
4367  }
4368 
4369  if (graph)
4370  DeleteHeap(&q);
4371 
4372  *planningTime=GetElapsedTime(&st);
4373 
4374  DeleteStatistics(&st);
4375 
4376  fprintf(stderr,"Final number of samples: %u\n",ar->ns);
4377 
4378  /* Reconstruct the path (if any) */
4379  if (l<INF)
4380  Steps2PathinAtlasRRT(pr,&steps,pl,NULL,ns,path,ar);
4381 
4382  /* Release memory */
4383  free(q_rand);
4384  free(t_rand);
4385  DeleteVector(&steps);
4386 
4387  #if (GET_ATLASRRT_STATISTICS)
4388  if (str==NULL)
4389  PrintAtlasRRTStatistics(ar,arst);
4390  else
4391  AccumulateAtlasRRTStatistics(arst,str);
4393  free(arst);
4394  #endif
4395 
4396  return(l<INF);
4397  }
4398 }
4399 
4401 {
4402  return(ar->ns);
4403 }
4404 
4406 {
4407  return(ar->nc);
4408 }
4409 
4410 
4411 unsigned int GetRRTNNInNeighbourChart(unsigned int tree,
4412  unsigned int c_rand,double *t_rand,double *q_rand,
4413  Tatlasrrt *ar)
4414 {
4415  double d,d1;
4416  unsigned int inear,inear1;
4417  Tchart *chart;
4418  unsigned int i,nn,nID;
4419 
4420  inear=GetRRTNNInChart(tree,c_rand,q_rand,INF,&d,ar);
4421 
4422  chart=GetAtlasChart(c_rand,&(ar->atlas));
4423  nn=ChartNumNeighbours(chart);
4424  for(i=0;i<nn;i++)
4425  {
4426  nID=ChartNeighbourID(i,chart);
4427  if (nID!=NO_UINT)
4428  {
4429  //if ((!ar->birrt)||(ar->ci[nID]->tree&tree))
4430  {
4431  inear1=GetRRTNNInChart(tree,nID,q_rand,d,&d1,ar);
4432  if (d1<d)
4433  {
4434  d=d1;
4435  inear=inear1;
4436  }
4437  }
4438  }
4439  }
4440  return(inear);
4441 }
4442 
4443 unsigned int GetRRTNNInChart(unsigned int tree,
4444  unsigned int chartId,double *q_rand,
4445  double t,double *d,Tatlasrrt *ar)
4446 {
4447  double d1;
4448  unsigned int j,inear;
4449 
4450  *d=t;
4451  inear=NO_UINT;
4452  j=ar->ci[chartId]->lc;
4453  while(j!=NO_UINT)
4454  {
4455  if ((!ar->birrt)||(GetRRTNodeTree(j,&(ar->rrt))==tree))
4456  {
4457  d1=DistanceTopologyMin(*d,ar->m,ar->tp,q_rand,ar->si[j]->s);
4458  if (d1<*d)
4459  {
4460  *d=d1;
4461  inear=j;
4462  }
4463  }
4464  j=ar->si[j]->lsc;
4465  }
4466 
4467  return(inear);
4468 }
4469 
4470 void PlotAtlasRRT(char *prefix,int argc,char **arg,Tparameters *pr,
4471  unsigned int xID,unsigned int yID,unsigned int zID,Tatlasrrt *ar)
4472 {
4473  Tfilename fplot;
4474  unsigned int i;
4475  Tchart *chart1,*chart2;
4476  double *sample1,*sample2;
4477  unsigned int parent;
4478  double x[4],y[4],z[4];
4479  double *point1,*point2;
4480  double *o1,*o2,*o3,*o4;
4481  Tcolor color;
4482  Tplot3d p3d;
4483 
4484  CreateFileName(NULL,prefix,"_rrt",PLOT3D_EXT,&fplot);
4485  fprintf(stderr,"Plotting RRT to : %s\n",GetFileFullName(&fplot));
4486  PlotRRT(GetFileFullName(&fplot),argc,arg,pr,xID,yID,zID,&(ar->rrt));
4487  DeleteFileName(&fplot);
4488 
4489  if ((!PLOT_AS_POLYGONS)||(ar->k<4))
4490  {
4491  CreateFileName(NULL,prefix,"_atlas",PLOT3D_EXT,&fplot);
4492  fprintf(stderr,"Plotting Atlas to : %s\n",GetFileFullName(&fplot));
4493  PlotAtlas(GetFileFullName(&fplot),argc,arg,pr,NULL,xID,yID,zID,&(ar->atlas));
4494  DeleteFileName(&fplot);
4495  }
4496  else
4497  fprintf(stderr,"Skipping the plot of the atlas (too large dimension)\n");
4498 
4499  /* Now we plot the RRT in the tangent space and a line from tangent space to
4500  the RRT. This basically replicates the plot of the RRT but in the tangent
4501  space */
4502 
4503  CreateFileName(NULL,prefix,"_atlasrrt",PLOT3D_EXT,&fplot);
4504  fprintf(stderr,"Plotting AtlasRRT to : %s\n",GetFileFullName(&fplot));
4505 
4506  InitPlot3d(GetFileFullName(&fplot),FALSE,argc,arg,&p3d);
4507  DeleteFileName(&fplot);
4508 
4509  NEW(point1,ar->m,double);
4510  NEW(point2,ar->m,double);
4511 
4512  NewColor(0.5,0,0,&color); /*red*/
4513  StartNew3dObject(&color,&p3d);
4514 
4515  for(i=(ar->birrt?2:1);i<ar->ns;i++)
4516  {
4517  if ((!ar->birrt)||(GetRRTNodeTree(i,&(ar->rrt))==START2GOAL))
4518  {
4519  parent=GetRRTParent(i,&(ar->rrt));
4520 
4521  chart1=GetAtlasChart(ar->si[i]->c,&(ar->atlas));
4522  chart2=GetAtlasChart(ar->si[parent]->c,&(ar->atlas));
4523 
4524  if (chart1==chart2)
4525  {
4526  sample1=ar->si[i]->s;
4527  sample2=ar->si[parent]->s;
4528 
4529  CS_WD_REGENERATE_ORIGINAL_POINT(pr,sample1,&o1,ar->w);
4530  CS_WD_REGENERATE_ORIGINAL_POINT(pr,sample2,&o2,ar->w);
4531 
4532  Local2Global(ar->si[i]->t,NULL,point1,chart1);
4533  Local2Global(ar->si[parent]->t,NULL,point2,chart2);
4534 
4535  CS_WD_REGENERATE_ORIGINAL_POINT(pr,point1,&o3,ar->w);
4536  CS_WD_REGENERATE_ORIGINAL_POINT(pr,point2,&o4,ar->w);
4537 
4538  x[0]=o1[xID];
4539  y[0]=o1[yID];
4540  z[0]=o1[zID];
4541 
4542  x[1]=o3[xID];
4543  y[1]=o3[yID];
4544  z[1]=o3[zID];
4545 
4546  x[2]=o4[xID];
4547  y[2]=o4[yID];
4548  z[2]=o4[zID];
4549 
4550  x[3]=o2[xID];
4551  y[3]=o2[yID];
4552  z[3]=o2[zID];
4553 
4554  PlotVect3d(4,x,y,z,&p3d);
4555 
4556  free(o1);
4557  free(o2);
4558  free(o3);
4559  free(o4);
4560  }
4561  }
4562  }
4563  DeleteColor(&color);
4564  Close3dObject(&p3d);
4565 
4566  if (ar->birrt)
4567  {
4568  NewColor(0,0.5,0,&color); /*green*/
4569  StartNew3dObject(&color,&p3d);
4570 
4571  for(i=2;i<ar->ns;i++)
4572  {
4573  if (GetRRTNodeTree(i,&(ar->rrt))==GOAL2START)
4574  {
4575  parent=GetRRTParent(i,&(ar->rrt));
4576 
4577  chart1=GetAtlasChart(ar->si[i]->c,&(ar->atlas));
4578  chart2=GetAtlasChart(ar->si[parent]->c,&(ar->atlas));
4579 
4580  if (chart1==chart2)
4581  {
4582  sample1=ar->si[i]->s;
4583  sample2=ar->si[parent]->s;
4584 
4585  CS_WD_REGENERATE_ORIGINAL_POINT(pr,sample1,&o1,ar->w);
4586  CS_WD_REGENERATE_ORIGINAL_POINT(pr,sample2,&o2,ar->w);
4587 
4588  Local2Global(ar->si[i]->t,NULL,point1,chart1);
4589  Local2Global(ar->si[parent]->t,NULL,point2,chart2);
4590 
4591  CS_WD_REGENERATE_ORIGINAL_POINT(pr,point1,&o3,ar->w);
4592  CS_WD_REGENERATE_ORIGINAL_POINT(pr,point2,&o4,ar->w);
4593 
4594  x[0]=o1[xID];
4595  y[0]=o1[yID];
4596  z[0]=o1[zID];
4597 
4598  x[1]=o3[xID];
4599  y[1]=o3[yID];
4600  z[1]=o3[zID];
4601 
4602  x[2]=o4[xID];
4603  y[2]=o4[yID];
4604  z[2]=o4[zID];
4605 
4606  x[3]=o2[xID];
4607  y[3]=o2[yID];
4608  z[3]=o2[zID];
4609 
4610  PlotVect3d(4,x,y,z,&p3d);
4611 
4612  free(o1);
4613  free(o2);
4614  free(o3);
4615  free(o4);
4616  }
4617  }
4618  }
4619  DeleteColor(&color);
4620  Close3dObject(&p3d);
4621  }
4622 
4623  #if (RRT_PLOT_NODES)
4624  /* Dots, one per node */
4625  NewColor(0,0,0,&color); /*black*/
4626  StartNew3dObject(&color,&p3d);
4627 
4628  for(i=0;i<ar->ns;i++)
4629  {
4630  chart1=GetAtlasChart(ar->si[i]->c,&(ar->atlas));
4631  Local2Global(ar->si[i]->t,NULL,point1,chart1);
4632  CS_WD_REGENERATE_ORIGINAL_POINT(pr,point1,&o1,ar->w);
4633 
4634  x[0]=o1[xID]-0.005;
4635  y[0]=o1[yID];
4636  z[0]=o1[zID];
4637 
4638  x[1]=o1[xID]+0.005;
4639  y[1]=o1[yID];
4640  z[1]=o1[zID];
4641 
4642  PlotVect3d(2,x,y,z,&p3d);
4643 
4644  x[0]=o1[xID];
4645  y[0]=o1[yID]-0.005;
4646  z[0]=o1[zID];
4647 
4648  x[1]=o1[xID];
4649  y[1]=o1[yID]+0.005;
4650  z[1]=o1[zID];
4651 
4652  PlotVect3d(2,x,y,z,&p3d);
4653 
4654  x[0]=o1[xID];
4655  y[0]=o1[yID];
4656  z[0]=o1[zID]-0.005;
4657 
4658  x[1]=o1[xID];
4659  y[1]=o1[yID];
4660  z[1]=o1[zID]+0.005;
4661 
4662  PlotVect3d(2,x,y,z,&p3d);
4663 
4664  free(o1);
4665  }
4666 
4667  DeleteColor(&color);
4668  Close3dObject(&p3d);
4669  #endif
4670 
4671  ClosePlot3d(FALSE,0,0,0,&p3d);
4672 
4673  free(point1);
4674  free(point2);
4675 }
4676 
4677 unsigned int AtlasRRTMemSize(Tatlasrrt *ar)
4678 {
4679  unsigned int b;
4680 
4681  b=RRTMemSize(&(ar->rrt));
4682  b+=AtlasMemSize(&(ar->atlas));
4683 
4684  return(b);
4685 }
4686 
4687 void SaveAtlasRRT(Tparameters *pr,char *prefix,Tatlasrrt *ar)
4688 {
4689  Tfilename fsave;
4690  FILE *f;
4691  unsigned int i;
4692 
4693  CreateFileName(NULL,prefix,NULL,RRT_EXT,&fsave);
4694  fprintf(stderr,"Writing RRT to : %s\n",GetFileFullName(&fsave));
4695  SaveRRT(&fsave,&(ar->rrt));
4696  DeleteFileName(&fsave);
4697 
4698  CreateFileName(NULL,prefix,NULL,ATLAS_EXT,&fsave);
4699  fprintf(stderr,"Writing atlas to : %s\n",GetFileFullName(&fsave));
4700  SaveAtlas(pr,&fsave,&(ar->atlas));
4701  DeleteFileName(&fsave);
4702 
4703  CreateFileName(NULL,prefix,NULL,ATLAS_RRT_EXT,&fsave);
4704  fprintf(stderr,"Writing AtlasRRT to : %s\n",GetFileFullName(&fsave));
4705  f=fopen(GetFileFullName(&fsave),"w");
4706  if (!f)
4707  Error("Could not open file to write the AtlasRRT information");
4708  DeleteFileName(&fsave);
4709 
4710  fprintf(f,"%u\n",ar->m);
4711  fprintf(f,"%u\n",ar->k);
4712  fprintf(f,"%.12f\n",ar->e);
4713  fprintf(f,"%.12f\n",ar->ce);
4714  fprintf(f,"%.12f\n",ar->r);
4715  fprintf(f,"%u\n",ar->birrt);
4716 
4717  fprintf(f,"%u\n",ar->ms);
4718  fprintf(f,"%u\n",ar->ns);
4719  for(i=0;i<ar->ns;i++)
4720  SaveAtlasRRTSampleInfo(f,ar->si[i],ar);
4721 
4722  fprintf(f,"%u\n",ar->mc);
4723  fprintf(f,"%u\n",ar->nc);
4724  for(i=0;i<ar->nc;i++)
4725  SaveAtlasRRTChartInfo(f,ar->ci[i],ar);
4726 
4727  if (ar->birrt)
4728  {
4729  fprintf(f,"%u\n",ar->mct1);
4730  fprintf(f,"%u\n",ar->nct1);
4731  for(i=0;i<ar->nct1;i++)
4732  fprintf(f,"%u ",ar->chartsAtTree1[i]);
4733  fprintf(f,"\n");
4734 
4735  fprintf(f,"%u\n",ar->mct2);
4736  fprintf(f,"%u\n",ar->nct2);
4737  for(i=0;i<ar->nct2;i++)
4738  fprintf(f,"%u ",ar->chartsAtTree2[i]);
4739  fprintf(f,"\n");
4740  }
4741  fclose(f);
4742 }
4743 
4744 void LoadAtlasRRT(Tparameters *pr,char *prefix,TAtlasBase *w,Tatlasrrt *ar)
4745 {
4746  Tfilename fload;
4747  FILE *f;
4748  unsigned int i;
4749 
4750  CreateFileName(NULL,prefix,NULL,RRT_EXT,&fload);
4751  fprintf(stderr,"Reading RRT from : %s\n",GetFileFullName(&fload));
4752  LoadRRT(pr,&fload,w,&(ar->rrt));
4753  DeleteFileName(&fload);
4754 
4755  CreateFileName(NULL,prefix,NULL,ATLAS_EXT,&fload);
4756  fprintf(stderr,"Reading atlas from : %s\n",GetFileFullName(&fload));
4757  LoadAtlas(pr,&fload,w,&(ar->atlas));
4758  DeleteFileName(&fload);
4759 
4760  CreateFileName(NULL,prefix,NULL,ATLAS_RRT_EXT,&fload);
4761  fprintf(stderr,"Reading AtlasRRT from : %s\n",GetFileFullName(&fload));
4762  f=fopen(GetFileFullName(&fload),"r");
4763  if (!f)
4764  Error("Could not open file to load the AtlasRRT information");
4765  DeleteFileName(&fload);
4766 
4767  ar->w=w;
4768 
4769  fscanf(f,"%u",&(ar->m));
4770  fscanf(f,"%u",&(ar->k));
4771  fscanf(f,"%lf",&(ar->e));
4772  fscanf(f,"%lf",&(ar->ce));
4773  fscanf(f,"%lf",&(ar->r));
4774  fscanf(f,"%u",&(ar->birrt));
4775  ar->parallel=FALSE; /* AtlasRRts loaded from files are not processed in parallel */
4776 
4777  fscanf(f,"%u",&(ar->ms));
4778  fscanf(f,"%u",&(ar->ns));
4779  NEW(ar->si,ar->ms,TSampleInfo *);
4780  for(i=0;i<ar->ns;i++)
4781  {
4782  NEW(ar->si[i],1,TSampleInfo);
4783  LoadAtlasRRTSampleInfo(f,ar->si[i],ar);
4784  }
4785 
4786  fscanf(f,"%u",&(ar->mc));
4787  fscanf(f,"%u",&(ar->nc));
4788  NEW(ar->ci,ar->mc,TChartInfo *);
4789  for(i=0;i<ar->nc;i++)
4790  {
4791  NEW(ar->ci[i],1,TChartInfo);
4792  LoadAtlasRRTChartInfo(f,ar->ci[i],ar);
4793  }
4794 
4795  if (ar->birrt)
4796  {
4797  fscanf(f,"%u",&(ar->mct1));
4798  fscanf(f,"%u",&(ar->nct1));
4799  NEW(ar->chartsAtTree1,ar->mct1,unsigned int);
4800  for(i=0;i<ar->nct1;i++)
4801  fscanf(f,"%u",&(ar->chartsAtTree1[i]));
4802 
4803  fscanf(f,"%u",&(ar->mct2));
4804  fscanf(f,"%u",&(ar->nct2));
4805  NEW(ar->chartsAtTree2,ar->mct2,unsigned int);
4806  for(i=0;i<ar->nct2;i++)
4807  fscanf(f,"%u",&(ar->chartsAtTree2[i]));
4808  }
4809  fclose(f);
4810 
4811 
4812  CS_WD_GENERATE_SIMP_INITIAL_BOX(pr,&(ar->ambient),ar->w);
4813  ar->tp=GetRRTTopology(&(ar->rrt));
4814  CS_WD_GET_SIMP_JACOBIAN(pr,&(ar->J),ar->w);
4815 }
4816 
4818 {
4819  unsigned int i;
4820 
4821  DeleteBox(&(ar->ambient));
4822 
4823  DeleteAtlas(&(ar->atlas));
4824  DeleteRRT(&(ar->rrt));
4825 
4826  /* Release sample info */
4827  for(i=0;i<ar->ns;i++)
4828  {
4829  free(ar->si[i]->t);
4830  free(ar->si[i]);
4831  /* The sample info is a pointer to an array
4832  stored in the RRT -> no need to free here */
4833  }
4834  free(ar->si);
4835 
4836  /* Release chart info */
4837  for(i=0;i<ar->nc;i++)
4838  free(ar->ci[i]);
4839 
4840  free(ar->ci);
4841 
4842  /* Release the assignment of charts to trees */
4843  if (ar->birrt)
4844  {
4845  free(ar->chartsAtTree1);
4846  free(ar->chartsAtTree2);
4847  }
4848 
4849  DeleteJacobian(&(ar->J));
4850 }
4851 
#define CT_R
Ball radius in atlas.
Definition: parameters.h:257
Definition of the boolean type.
void NewAtlasRRTNoConnectToParent(TAtlasRRTStatistics *arst)
A chart that does not intersect with its parent.
Definition: atlasrrt.c:467
unsigned int nStepReduction
Definition: atlasrrt.h:126
boolean IsRRTGraph(Trrt *rrt)
Identifies RRT with a graph structure.
Definition: rrt.c:1466
unsigned int GetRRTParent(unsigned int i, Trrt *rrt)
Returns identifier of the parent of one of the nodes of the RRT.
Definition: rrt.c:3547
void AdjustDynamicDomain(unsigned int i, boolean collision, Trrt *rrt)
Sets the dynamic domain.
Definition: rrt.c:3482
void PlotVect3d(unsigned int n, double *x, double *y, double *z, Tplot3d *p)
Adds a polyline to the current object.
Definition: plot3d.c:447
unsigned int k
Definition: atlasrrt.h:194
void DeleteVector(void *vector)
Destructor.
Definition: vector.c:388
#define TANGENT_SAMPLING
One of the possible sampling modes.
Definition: parameters.h:174
void LoadAtlas(Tparameters *pr, Tfilename *fname, TAtlasBase *w, Tatlas *a)
Defines an atlas from the information on a file.
Definition: atlas.c:3869
Definition of the combination of an atlas with a RRT.
unsigned int nct2
Definition: atlasrrt.h:230
void NewAtlasRRTBranch(TAtlasRRTStatistics *arst)
New branch creation.
Definition: atlasrrt.c:367
unsigned int nc
Definition: atlasrrt.h:222
unsigned int VectorSize(Tvector *vector)
Gets the number of elements in a vector.
Definition: vector.c:169
#define CS_WD_ERROR_IN_SIMP_EQUATIONS(pr, p, wcs)
Computes the error in the simplified system for a given point.
Definition: wcs.h:446
double GetRRTNodeCostFromParent(unsigned int i, Trrt *rrt)
Returns the cost from the parent node, if defined.
Definition: rrt.c:3596
unsigned int * tp
Definition: atlasrrt.h:210
#define CT_EPSILON
Numerical tolerance.
Definition: parameters.h:194
void NewAtlasRRTOverlap(TAtlasRRTStatistics *arst)
New overlap.
Definition: atlasrrt.c:427
#define FALSE
FALSE.
Definition: boolean.h:30
unsigned int nCollisionChecks
Definition: atlasrrt.h:142
boolean AtlasRRTstar(Tparameters *pr, double *pg, unsigned int *it, double *times, double *costs, double *planningTime, double *pl, unsigned int *ns, double ***path, TAtlasRRTStatistics *str, Tatlasrrt *ar)
Optimal AtlasRRT on manifolds.
Definition: atlasrrt.c:3908
#define CS_WD_GENERATE_SIMPLIFIED_POINT(pr, p, r, wcs)
Generates a simplified point from an original one.
Definition: wcs.h:432
void LoadAtlasRRTSampleInfo(FILE *f, TSampleInfo *si, Tatlasrrt *ar)
Reads the information associated with a sample in an AtlasRRT.
Definition: atlasrrt.c:2829
void DeleteRRT(Trrt *rrt)
Destructor.
Definition: rrt.c:4196
unsigned int nSample
Definition: atlasrrt.h:129
double DistanceTopology(unsigned int s, unsigned int *tp, double *v1, double *v2)
Computes the distance of two points.
unsigned int n
Definition: atlasrrt.h:97
unsigned int ms
Definition: atlasrrt.h:217
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
unsigned int nCollision
Definition: atlasrrt.h:112
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:1471
Data structure to hold the information about the name of a file.
Definition: filename.h:248
#define RRT_EXT
File extension for files storing rrt's.
Definition: filename.h:205
unsigned int ns
Definition: atlasrrt.h:218
A pair of dubles.
Definition: vector.h:114
void NewAtlasRRTTooLong(TAtlasRRTStatistics *arst)
New long branch.
Definition: atlasrrt.c:417
boolean RandomPointInAtlas(Tparameters *pr, double scale, double *w, unsigned int *nm, double *t, double *p, Tatlas *a)
Samples a random point on the atlas.
Definition: atlas.c:3944
void NewAtlasRRTDistanceQrand(double dqr, TAtlasRRTStatistics *arst)
New distance to q_rand.
Definition: atlasrrt.c:387
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:3729
void NewAtlasRRTOutOfChart(TAtlasRRTStatistics *arst)
New chart due to radius.
Definition: atlasrrt.c:432
unsigned int nTooLong
Definition: atlasrrt.h:113
TChartInfo ** ci
Definition: atlasrrt.h:223
void * GetVectorElement(unsigned int i, Tvector *vector)
Returns a pointer to a vector element.
Definition: vector.c:269
unsigned int nOutOfChart
Definition: atlasrrt.h:120
unsigned int randomMax(unsigned int m)
Returns a random integer in the range [0,m].
Definition: random.c:77
void NewAtlasRRTSample(TAtlasRRTStatistics *arst)
New sample.
Definition: atlasrrt.c:457
#define ADD_ALL
One of the addition modes for AddBranchToAtlasRRT.
Definition: atlasrrt.c:31
Information for each sample in an AtlasRRT.
Definition: atlasrrt.h:156
void AddEdgeToRRT(unsigned int i, unsigned int j, double c, Trrt *rrt)
Adds a neighbouring relation to an RRT.
Definition: rrt.c:784
unsigned int mct2
Definition: atlasrrt.h:229
void NewAtlasRRTNoEmptyTreeConnection(TAtlasRRTStatistics *arst)
New non-void attempt to connect the two trees.
Definition: atlasrrt.c:382
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.
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:1869
void PlotConnection(Tparameters *pr, char *prefix, unsigned int target, unsigned int near, unsigned int end, unsigned int xID, unsigned int yID, unsigned int zID, Tatlasrrt *ar)
Graphical representation of the attempt to connect two trees.
Definition: atlasrrt.c:2749
unsigned int nStep
Definition: atlasrrt.h:106
unsigned int tree
Definition: atlasrrt.h:177
void DeleteJacobian(TJacobian *j)
Destructor.
Definition: jacobian.c:249
#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.
TJacobian J
Definition: atlasrrt.h:212
void NewAtlasRRTQrandReached(TAtlasRRTStatistics *arst)
Random sample reached.
Definition: atlasrrt.c:402
CBLAS_INLINE void AccumulateVector(unsigned int s, double *v1, double *v2)
Adds a vector to another vectors.
Definition: basic_algebra.c:55
boolean AtlasTRRT(Tparameters *pr, double *pg, double *time, double *pl, double *pc, unsigned int *ns, double ***path, double(*costF)(Tparameters *, boolean, double *, void *), void *costData, TAtlasRRTStatistics *str, Tatlasrrt *ar)
Extends a Atlas-TRRT until we reach a targed point.
Definition: atlasrrt.c:3399
#define CT_SAMPLING
Sampling mode.
Definition: parameters.h:563
void PlotQrand(Tparameters *pr, char *prefix, unsigned int inear, unsigned int c_rand, double *t_rand, double *q_rand, unsigned int xID, unsigned int yID, unsigned int zID, Tatlasrrt *ar)
Plots a point where q_rang is and a line to its chart.
Definition: atlasrrt.c:2652
void LoadAtlasRRTChartInfo(FILE *f, TChartInfo *ci, Tatlasrrt *ar)
Reads the information associated with a chart in an AtlasRRT.
Definition: atlasrrt.c:2844
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:1204
unsigned int randomWithDistribution(unsigned int m, double s, double *d)
Random number with a given discrete distribution.
Definition: random.c:86
unsigned int GetRRTNN(unsigned int tree, double *q_rand, Trrt *rrt)
Locates the nearest sample in the tree of samples.
Definition: rrt.c:1547
Definition of the Tfilename type and the associated functions.
void PlotAtlasRRT(char *prefix, int argc, char **arg, Tparameters *pr, unsigned int xID, unsigned int yID, unsigned int zID, Tatlasrrt *ar)
Pots a projection of an atlasRRT.
Definition: atlasrrt.c:4470
#define START2GOAL
One of the possible trees.
Definition: rrt.h:166
#define ONE_TREE
One of the modes for the RRT.
Definition: rrt.h:130
void InitPlot3d(char *name, boolean axes, int argc, char **arg, Tplot3d *p)
Constructor.
Definition: plot3d.c:41
void DeleteAtlasRRT(Tatlasrrt *ar)
Destructor.
Definition: atlasrrt.c:4817
#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 IncreaseChartSamplingRadius(Tchart *c)
Increase the sampling radious of the chart.
Definition: chart.c:1379
CBLAS_INLINE void Normalize(unsigned int s, double *v)
Normalizes a vector.
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:809
void InitAtlasRRTStatistics(TAtlasRRTStatistics *arst)
Init the Atlas RRT statistics.
Definition: atlasrrt.c:325
double ConnectSamplesChart(Tparameters *pr, unsigned int *tp, Tbox *domain, unsigned int m, unsigned int n, double *s1, double *s2, double md, boolean checkCollisions, 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:172
double AddSample2AtlasRRT(Tparameters *pr, unsigned int tree, unsigned int *currentID, unsigned int nextChart, double *nextParam, double *nextSample, double dp, double cost, Tatlasrrt *ar)
Adds a sample to the AtlasRRT.
Definition: atlasrrt.c:1967
double Chart2Manifold(Tparameters *pr, TJacobian *sJ, double *t, unsigned int *tp, double *pInit, double *p, Tchart *c)
Returns the point in the manifold for a given set of parameteres.
Definition: chart.c:1066
void DeleteAtlas(Tatlas *a)
Destructor.
Definition: atlas.c:4561
void Error(const char *s)
General error function.
Definition: error.c:80
void NewTemptativeSample(Tparameters *pr, unsigned int it, unsigned int *nChanges, boolean revisitCharts, boolean chartCreated, boolean checkCollisions, boolean onManifold, TSampleInfo *currentSampleInfo, double *currentParam, double *origRandSample, unsigned int *randChart, double *randParam, double *randSample, double currentDelta, double d, double *deltaParam, unsigned int *nextChart, double *nextParam, double *nextSample, void *st, double(*costF)(Tparameters *, boolean, double *, void *), void *costData, double *cost, boolean *blocked, boolean *inCollision, boolean *valid, Tatlasrrt *ar)
Generates a new sample in between q_near and q_rand.
Definition: atlasrrt.c:1702
unsigned int GetRRTNNInNeighbourChart(unsigned int tree, unsigned int c_rand, double *t_rand, double *q_rand, Tatlasrrt *ar)
Selects the nearest point in the chart of Id ChartId, or in a neighbour.
Definition: atlasrrt.c:4411
A color.
Definition: color.h:23
void DeleteRRTStep(void *a)
RRTStep destructor.
Definition: rrt.c:756
double GetTRRTTemperature(Trrt *rrt)
Temperature of the T-RRT.
Definition: rrt.c:1461
unsigned int nNoEmptyBranch
Definition: atlasrrt.h:101
void NewAtlasRRTSampleRejection(TAtlasRRTStatistics *arst)
New sample rejection.
Definition: atlasrrt.c:482
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:3298
unsigned int RRTMemSize(Trrt *rrt)
Memory used by a given RRT.
Definition: rrt.c:3968
unsigned int nErrorNewChart
Definition: atlasrrt.h:118
#define INIT_NUM_SAMPLES_RRT
Initial room for samples of an rrt.
Definition: rrt.h:123
unsigned int ReconstructAtlasRRTPath(Tparameters *pr, unsigned int sID, double *pl, unsigned int *ns, double ***path, Tatlasrrt *ar)
Collects samples from the tree root to a given sample.
Definition: atlasrrt.c:2357
boolean AddChart2AtlasRRT(Tparameters *pr, unsigned int tree, unsigned int it, TSampleInfo *currentSampleInfo, boolean *intersectParent, Tatlasrrt *ar)
Adds a chart to the Atlas RRT.
Definition: atlasrrt.c:2104
double * t
Definition: atlasrrt.h:160
void NewAtlasRRTChart(TAtlasRRTStatistics *arst)
New Chart.
Definition: atlasrrt.c:462
A chart on a manifold.
Definition: chart.h:70
double r
Definition: atlasrrt.h:197
unsigned int lc
Definition: atlasrrt.h:176
#define CT_MAX_PLANNING_ITERATIONS
Maximum iterations for path planning.
Definition: parameters.h:483
unsigned int GetBoxNIntervals(Tbox *b)
Box dimensionality.
Definition: box.c:992
void SetRRTParent(unsigned int i, unsigned int p, Trrt *rrt)
Changes the parent for a given node.
Definition: rrt.c:3555
void AtlasRRTstarCloseIteration(unsigned int it, unsigned int id_goal, double time, double gamma, double *times, double *costs, Tatlasrrt *ar)
Prints information about the AtlasRRT* iteration.
Definition: atlasrrt.c:3843
double randomDouble()
Returns a random double in the [0,1] interval.
Definition: random.c:33
void LoadRRT(Tparameters *pr, Tfilename *fname, TAtlasBase *w, Trrt *rrt)
Defines a RRT from the information on a file.
Definition: rrt.c:4036
void AddElement2Heap(unsigned int id, void *e, Theap *heap)
Adds an element to the heap.
Definition: heap.c:294
Tbox ambient
Definition: atlasrrt.h:209
void DeleteDoublePair(void *a)
Destructor for pairs of doubles.
Definition: vector.c:77
unsigned int GetAtlasNumCharts(Tatlas *a)
Number of charts in the atlas.
Definition: atlas.c:3931
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:3402
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
double * GetRRTNode(unsigned int i, Trrt *rrt)
Returns one of the nodes of the RRT.
Definition: rrt.c:3526
#define PLOT_AS_POLYGONS
Set to 1 to get a nicer plot for 2D manifolds.
Definition: chart.h:50
unsigned int StepsToRoot(unsigned int sID, Trrt *rrt)
Computes the number of steps from a node to the root.
Definition: rrt.c:3714
A 3D plot.
Definition: plot3d.h:54
Tatlas atlas
Definition: atlasrrt.h:215
unsigned int id
Definition: atlasrrt.h:157
unsigned int nChart
Definition: atlasrrt.h:130
Definition of a binary heap used to implement priority queues.
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:3474
unsigned int nTooFar
Definition: atlasrrt.h:114
double Distance(unsigned int s, double *v1, double *v2)
Computes the distance of two points.
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:150
boolean LessThanDoublePair(void *a, void *b, void *userData)
Comparison operator for paris of doubles.
Definition: heap.c:224
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:2145
#define ATLAS_EXT
File extension for files storing atlas.
Definition: filename.h:199
unsigned int c
Definition: atlasrrt.h:162
unsigned int InitChart(Tparameters *pr, boolean simple, Tbox *domain, unsigned int *tp, unsigned int m, unsigned int k, double *p, double e, double eCurv, double r, TJacobian *sJ, TAtlasBase *w, Tchart *c)
Constructor.
Definition: chart.c:792
void NewAtlasRRTStepReduction(TAtlasRRTStatistics *arst)
Step reduction.
Definition: atlasrrt.c:452
double UpdateBiRRTSteps(Tvector *steps, Trrt *rrt)
Updates the current optimal path.
Definition: rrt.c:3357
unsigned int AtlasRRTMemSize(Tatlasrrt *ar)
Memory used by a given atlasRRT.
Definition: atlasrrt.c:4677
boolean AtlasBiRRTstar(Tparameters *pr, double *pg, unsigned int *it, double *times, double *costs, double *planningTime, double *pl, unsigned int *ns, double ***path, TAtlasRRTStatistics *str, Tatlasrrt *ar)
Bidirectional version of AtlasRRTstar.
Definition: atlasrrt.c:4148
#define CS_WD_SIMP_INEQUALITIES_HOLD(pr, p, wcs)
Cheks if all inequalities hold.
Definition: wcs.h:207
#define KDTREE_SAMPLING
One of the possible sampling modes.
Definition: parameters.h:162
boolean RandomPointInChart(Tparameters *pr, double scale, unsigned int *tp, double *t, double *p, Tchart *c)
Samples a random point in the area covered by the chart.
Definition: chart.c:1364
void AtlasBiRRTstarCloseIteration(unsigned int it, double l, double time, double gamma, double *times, double *costs, Tatlasrrt *ar)
Prints information about the BiAtlasRRT* iteration.
Definition: atlasrrt.c:3878
void InitVector(unsigned int ele_size, void(*Copy)(void *, void *), void(*Delete)(void *), unsigned int max_ele, Tvector *vector)
Constructor.
Definition: vector.c:100
void NewAtlasRRTNoEmptyBranch(TAtlasRRTStatistics *arst)
New no empty branch.
Definition: atlasrrt.c:372
void ReWireAtlasRRTstar(Tparameters *pr, unsigned int id_new, double gamma, unsigned int nn, unsigned int *n, double *c, Tvector *steps, double *l, TAtlasRRTStatistics *arst, Tatlasrrt *ar)
Rewires an AtlasRRT star.
Definition: atlasrrt.c:3764
unsigned int GetRRTMode(Trrt *rrt)
Identifies mode of the RRTs.
Definition: rrt.c:3469
unsigned int nNotInDomain
Definition: atlasrrt.h:111
double GetChartSamplingRadius(Tchart *c)
Returns de sampling range of the chart.
Definition: chart.c:943
#define HEURISTIC_RRT_STAR
Whether to use an heuristic in AtlarRRT*.
Definition: rrt.h:54
void NewAtlasRRTTooFar(TAtlasRRTStatistics *arst)
New large step.
Definition: atlasrrt.c:422
void DifferenceVector(unsigned int s, double *v1, double *v2, double *v)
Substracts two vectors.
unsigned int pc
Definition: atlasrrt.h:161
Statistics associated with a solving process.
Definition: statistics.h:28
double * s
Definition: atlasrrt.h:158
unsigned int GetRRTNNInChart(unsigned int tree, unsigned int chartId, double *q_rand, double t, double *d, Tatlasrrt *ar)
Selects the nearest neighbour from the random point in the chart of Id ChartId.
Definition: atlasrrt.c:4443
unsigned int nNoEmptyTreeConnection
Definition: atlasrrt.h:104
#define MOV_AVG_UP
Weight of new data when computing moving averages.
Definition: defines.h:451
boolean AtlasRRT(Tparameters *pr, double *pg, double *time, double *pl, unsigned int *ns, double ***path, TAtlasRRTStatistics *str, Tatlasrrt *ar)
Extends a Atlas-RRT until we reach a targed point.
Definition: atlasrrt.c:3133
void DeleteHeap(Theap *heap)
Destructor.
Definition: heap.c:388
void Warning(const char *s)
General warning function.
Definition: error.c:116
A table of parameters.
unsigned int mc
Definition: atlasrrt.h:221
unsigned int m
Definition: atlasrrt.h:193
#define BOTHTREES
Used for samples in both trees.
Definition: rrt.h:181
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
unsigned int nNoConvergent
Definition: atlasrrt.h:119
void DeleteAtlasRRTStatistics(TAtlasRRTStatistics *arst)
Destructor.
Definition: atlasrrt.c:745
void NewAtlasRRTLargeCurvature(TAtlasRRTStatistics *arst)
New chart due large curvature between two charts.
Definition: atlasrrt.c:442
#define CS_WD_GET_SIMP_JACOBIAN(pr, J, wcs)
Computes the Jacobian of the simplified system.
Definition: wcs.h:474
boolean AtlasRRTSample(Tparameters *pr, unsigned int samplingMode, unsigned int it, unsigned int tree, double *goal, double scale, boolean *exploration, unsigned int *c_rand, double *t_rand, double *q_rand, TAtlasRRTStatistics *arst, Tatlasrrt *ar)
Generates a random sample to expand the AtlasRRT.
Definition: atlasrrt.c:2993
TSampleInfo ** si
Definition: atlasrrt.h:219
boolean birrt
Definition: atlasrrt.h:200
void DeleteChart(Tchart *c)
Destructor.
Definition: chart.c:2011
#define ADD_LAST
One of the addition modes for AddBranchToAtlasRRT.
Definition: atlasrrt.c:38
void NewAtlasRRTTreeConnection(TAtlasRRTStatistics *arst)
New attempt to connect the two trees.
Definition: atlasrrt.c:377
Type defining the equations on which the atlas is defined.
Definition: wcs.h:30
void NewAtlasRRTInitChartError(TAtlasRRTStatistics *arst)
New chart due to error when trying to create a chart.
Definition: atlasrrt.c:437
unsigned int nNoConnect
Definition: atlasrrt.h:131
Definition of a local chart on a manifold.
A generic vector.
Definition: vector.h:227
#define CS_WD_GET_SYSTEM_VARS(sv, wcs)
Gets the system variables.
Definition: wcs.h:238
Trrt rrt
Definition: atlasrrt.h:214
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
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:1775
void NewAtlasRRTCollision(TAtlasRRTStatistics *arst)
New collision.
Definition: atlasrrt.c:412
void AccumulateAtlasRRTStatistics(TAtlasRRTStatistics *arst1, TAtlasRRTStatistics *arst2)
Accumulates two sets of Atlas RRT statistics.
Definition: atlasrrt.c:492
#define EXPLORATION_RRT
Select between exploration and goal driven RRT.
Definition: rrt.h:96
#define CS_WD_REGENERATE_ORIGINAL_POINT(pr, p, o, wcs)
Completes an original point from a simplified one.
Definition: wcs.h:279
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
#define ADD_LAST_NO_REP
One of the addition modes for AddBranchToAtlasRRT.
Definition: atlasrrt.c:46
unsigned int AtlasMemSize(Tatlas *a)
Memory used by a given atlas.
Definition: atlas.c:3831
unsigned int GetRRTNodeTree(unsigned int i, Trrt *rrt)
Returns the tree for a given node.
Definition: rrt.c:3534
unsigned int lsc
Definition: atlasrrt.h:164
double ce
Definition: atlasrrt.h:196
double GetRRTNodeCost(unsigned int i, Trrt *rrt)
Returns the cost associated with a node.
Definition: rrt.c:3588
void ReverseSamples(unsigned int ns, double **path)
Reverses a set of samples.
Definition: samples.c:1196
void WireAtlasRRTstar(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, TAtlasRRTStatistics *arst, Tatlasrrt *ar)
Wires a node to the AtlasRRT star.
Definition: atlasrrt.c:3623
#define MEM_DUP(_var, _n, _type)
Duplicates a previously allocated memory space.
Definition: defines.h:414
unsigned int GetAtlasRRTNumCharts(Tatlasrrt *ar)
Number of charts in the AtlasRRT.
Definition: atlasrrt.c:4405
#define NO_UINT
Used to denote an identifier that has not been initialized.
Definition: defines.h:435
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
void SaveRRT(Tfilename *fname, Trrt *rrt)
Stores the RRT information on a file.
Definition: rrt.c:3985
unsigned int generateChart
Definition: atlasrrt.h:163
void InitSamples(unsigned int *ms, unsigned int *ns, double ***path)
Initializes a set of samples.
Definition: samples.c:143
double * GetChartCenter(Tchart *c)
Returns the center of the chart.
Definition: chart.c:933
boolean RandomPointInAtlasTree(Tparameters *pr, double scale, unsigned int tree, unsigned int *nm, double *t, double *p, Tatlasrrt *ar)
Selects a random point in the set of charts of the tree.
Definition: atlasrrt.c:2562
void NewAtlasRRTNotInDomain(TAtlasRRTStatistics *arst)
New node not in the given domain.
Definition: atlasrrt.c:407
void SmoothPathInAtlasRRT(Tparameters *pr, unsigned int sID, Tatlasrrt *ar)
Local optimiziation of the path to a node.
Definition: atlasrrt.c:2503
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:1654
Definition of the Tvector type and the associated functions.
Step in a solution path.
Definition: rrt.h:246
Tchart * GetAtlasChart(unsigned int id, Tatlas *a)
Gets one of the charts of the chart.
Definition: atlas.c:3936
void LoadAtlasRRT(Tparameters *pr, char *prefix, TAtlasBase *w, Tatlasrrt *ar)
Defines an atlasRRT from the information on a file.
Definition: atlasrrt.c:4744
Statistics on the AtlasRRT constrution.
Definition: atlasrrt.h:96
unsigned int nLargeCurvature
Definition: atlasrrt.h:121
void SaveAtlas(Tparameters *pr, Tfilename *fname, Tatlas *a)
Stores the atlas information on a file.
Definition: atlas.c:3842
boolean InsideChartPolytope(double *t, Tchart *c)
Checks if a parameter point is inside the chart polytope.
Definition: chart.c:1313
void DeleteBox(void *b)
Destructor.
Definition: box.c:1259
double e
Definition: atlasrrt.h:195
unsigned int nBranch
Definition: atlasrrt.h:100
#define ATLASRRT_VERBOSE
Vebosity of the AtlasRRT operations.
Definition: atlasrrt.h:30
void NewDoublePair(double f, double s, TDoublePair *p)
Constructor.
Definition: vector.c:49
#define PLOT3D_EXT
File extension for 3D plot files.
Definition: filename.h:167
#define AMBIENT_SAMPLING
One of the possible sampling modes.
Definition: parameters.h:151
void Local2Global(double *t, unsigned int *tp, double *p, Tchart *c)
Transforms a parameter in tangent space to a point in ambient space.
Definition: chart.c:1212
unsigned int AddTrustedChart2Atlas(Tparameters *pr, double *ps, unsigned int parentID, boolean *singular, Tatlas *a)
Defines a new chart and adds it to the atlas.
Definition: atlas.c:2870
unsigned int nRandom
Definition: atlasrrt.h:137
#define CT_E
Chart error in atlas.
Definition: parameters.h:243
RRT with an atlas for sampling.
Definition: atlasrrt.h:190
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:3615
double Manifold2Chart(double *p, unsigned int *tp, double *t, Tchart *c)
Returns the parametrization of a point.
Definition: chart.c:1036
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:152
boolean CloseCharts(Tparameters *pr, unsigned int *tp, Tchart *c1, Tchart *c2)
Identifies close local charts.
Definition: chart.c:1264
double GetParameter(unsigned int n, Tparameters *p)
Gets the value for a particular parameter.
Definition: parameters.c:93
void PopulateWithSamples(Tparameters *pr, unsigned int id, Tatlasrrt *ar)
Assign samples to a newly created chart.
Definition: atlasrrt.c:2267
unsigned int Steps2PathinAtlasRRT(Tparameters *pr, Tvector *steps, double *pl, double *pc, unsigned int *ns, double ***path, Tatlasrrt *ar)
Defines a path from a vector of steps.
Definition: atlasrrt.c:2424
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:417
void NewAtlasRRTStep(TAtlasRRTStatistics *arst)
New step in branch extension.
Definition: atlasrrt.c:392
unsigned int ChartNumNeighbours(Tchart *c)
Number of neighbours of the chart.
Definition: chart.c:1675
boolean DynamicDomainRRT(Trrt *rrt)
TRUE if the dynamic domain is active.
Definition: rrt.c:3516
unsigned int GetRRTNumNodes(Trrt *rrt)
Number of nodes in the RRT.
Definition: rrt.c:3521
void SaveAtlasRRTSampleInfo(FILE *f, TSampleInfo *si, Tatlasrrt *ar)
Saves the information associated with a sample in an AtlasRRT.
Definition: atlasrrt.c:2808
void DeleteColor(Tcolor *c)
Destructor.
Definition: color.c:93
double CostToRoot(unsigned int sID, Trrt *rrt)
Computes the cost from a node to the root.
Definition: rrt.c:3638
void ForceChartCut(Tparameters *pr, unsigned int *tp, Tbox *ambient, unsigned int id1, Tchart *c1, unsigned int id2, Tchart *c2)
Intersect two charts that might be non-neighbours.
Definition: chart.c:265
void UpdateCostAndTree(unsigned int sID, Trrt *rrt)
A combination of UpdateCostToRoot and UpdateTree.
Definition: rrt.c:3687
void NewAtlasRRTCollisionCheck(TAtlasRRTStatistics *arst)
New collision check.
Definition: atlasrrt.c:487
#define CS_WD_IN_COLLISION(f, pr, s, sPrev, wcs)
Checks if a configuration is in collision.
Definition: wcs.h:319
#define INF
Infinite.
Definition: defines.h:70
void SetRRTNodeCost(unsigned int i, double costp, double cost, Trrt *rrt)
Changes the cost associated with a node.
Definition: rrt.c:3604
void EnlargeChart(double *t, Tchart *c)
Ensures that a chart includes a given point.
Definition: chart.c:1332
unsigned int mct1
Definition: atlasrrt.h:225
#define ATLAS_RRT_EXT
File extension for files storing AtlasRTT's.
Definition: filename.h:212
unsigned int * chartsAtTree2
Definition: atlasrrt.h:231
#define CT_DELTA
Size of the steps in the path connecting two configurations.
Definition: parameters.h:282
void NewAtlasRRTDirLargeCurvature(TAtlasRRTStatistics *arst)
New chart due to the curvature in the expansion direction.
Definition: atlasrrt.c:447
void NewAtlasRRTBlockBySingularity(TAtlasRRTStatistics *arst)
Number of times we try to create a char at a singular regions.
Definition: atlasrrt.c:472
#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:174
#define CT_DETECT_BIFURCATIONS
TRUE (or 1) if bifurcation must be detected.
Definition: parameters.h:468
unsigned int ChartNeighbourID(unsigned int n, Tchart *c)
Returns the identifier of one of the neighbours of a chart.
Definition: chart.c:1687
boolean InitAtlasFromPoint(Tparameters *pr, boolean parallel, boolean simpleChart, double *p, TAtlasBase *w, Tatlas *a)
Initializes an atlas from a given point.
Definition: atlas.c:2742
void InitAtlasRRT(Tparameters *pr, boolean parallel, double *ps, unsigned int mode, boolean graph, double *pg, TAtlasBase *w, Tatlasrrt *ar)
Defines a Atlas-RRT from a given point.
Definition: atlasrrt.c:2855
Definition of basic randomization functions.
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
unsigned int nQrandReached
Definition: atlasrrt.h:110
boolean parallel
Definition: atlasrrt.h:204
boolean PointTowardRandSample(unsigned int cId, double d, double *t, unsigned int samplingMode, boolean onManifold, double *origRandSample, unsigned int *randChart, double *randParam, double *randSample, double *deltaParam, Tatlasrrt *ar)
Determines the motion on the current chart to approach q_rand.
Definition: atlasrrt.c:2060
void NewAtlasRRTRandomSample(TAtlasRRTStatistics *arst)
New random sample.
Definition: atlasrrt.c:477
unsigned int it
Definition: atlasrrt.h:178
void CopyDoublePair(void *a, void *b)
Copy constructor for pairs of doubles.
Definition: vector.c:71
unsigned int nOverlap
Definition: atlasrrt.h:115
unsigned int nTreeConnection
Definition: atlasrrt.h:103
void DeleteSamples(unsigned int ns, double **path)
Deletes the space used by a set of samples.
Definition: samples.c:1495
unsigned int nRejections
Definition: atlasrrt.h:139
unsigned int AddStepToAtlasRRTstar(Tparameters *pr, unsigned int it, boolean expand2Goal, unsigned int i_near, double *q_rand, unsigned int *id_goal, double *goal, TAtlasRRTStatistics *arst, Tatlasrrt *ar)
Adds a node to an AtlasRRT*.
Definition: atlasrrt.c:3561
#define ADD_NONE
One of the addition modes for AddBranchToAtlasRRT.
Definition: atlasrrt.c:53
void NewAtlasRRTNoConvergentStep(TAtlasRRTStatistics *arst)
Problems with convergence.
Definition: atlasrrt.c:397
#define CS_WD_GENERATE_SIMP_INITIAL_BOX(pr, b, wcs)
Computes the global box for the simplified system.
Definition: wcs.h:460
TAtlasBase * w
Definition: atlasrrt.h:191
unsigned int nDirLargeCurvature
Definition: atlasrrt.h:122
unsigned int GetAtlasRRTNumNodes(Tatlasrrt *ar)
Number of nodes in the AtlasRRT.
Definition: atlasrrt.c:4400
void SaveAtlasRRTChartInfo(FILE *f, TChartInfo *ci, Tatlasrrt *ar)
Saves the information associated with a chart in an AtlasRRT.
Definition: atlasrrt.c:2822
boolean AtlasRRTValidateSample(Tparameters *pr, double *q_rand, unsigned int tree, boolean expand2goal, unsigned int lastNN2Goal, double *goal, double l, double *h, unsigned int *i_near, TAtlasRRTStatistics *arst, Tatlasrrt *ar)
Validates a sample generate with AtlasRRTSample.
Definition: atlasrrt.c:3081
#define INIT_NUM_CHARTS
Initial number of charts of an atlas.
Definition: atlas.h:60
unsigned int StartNew3dObject(Tcolor *c, Tplot3d *p)
Start a composed object.
Definition: plot3d.c:157
void DeleteStatistics(Tstatistics *t)
Destructor.
Definition: statistics.c:274
void DecreaseChartSamplingRadius(Tchart *c)
Decrease the sampling radious of the chart.
Definition: chart.c:1385
double AddBranchToAtlasRRT(Tparameters *pr, unsigned int it, unsigned int addMode, boolean revisitCharts, boolean checkCollisions, boolean onManifold, boolean explorationSample, double maxLength, unsigned int i_near, double *origRandSample, double *goalSample, void *st, unsigned int *lastSampleID, boolean *reachedQRand, boolean *reachedGoal, unsigned int *ns, double ***path, double(*costF)(Tparameters *, boolean, double *, void *), void *costData, Tatlasrrt *ar)
Adds a new branch to the AtlasRRT.
Definition: atlasrrt.c:1300
#define CT_CE
Chart error in atlas.
Definition: parameters.h:250
void AddChart2Tree(unsigned int tree, unsigned int chartId, Tatlasrrt *ar)
Add a chart to a tree.
Definition: atlasrrt.c:2038
unsigned int nct1
Definition: atlasrrt.h:226
void CopyRRTStep(void *a, void *b)
Copy constructor for RRTSteps.
Definition: rrt.c:750
void PlotAtlas(char *fname, int argc, char **arg, Tparameters *pr, FILE *fcost, unsigned int xID, unsigned int yID, unsigned int zID, Tatlas *a)
Pots a projection of an atlas.
Definition: atlas.c:4151
void Close3dObject(Tplot3d *p)
Closes a composed object.
Definition: plot3d.c:171
Information for each chart in an AtlasRRT.
Definition: atlasrrt.h:175
unsigned int nSingular
Definition: atlasrrt.h:133
unsigned int * GetRRTTopology(Trrt *rrt)
Returns a pointer to an array with the topology for each variable.
Definition: rrt.c:3633
void ClosePlot3d(boolean quit, double average_x, double average_y, double average_z, Tplot3d *p)
Destructor.
Definition: plot3d.c:473
unsigned int * chartsAtTree1
Definition: atlasrrt.h:227
#define CT_MAX_NODES_RRT
Maximum number of nodes in an RRT.
Definition: parameters.h:497
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:350
void PrintAtlasRRTStatistics(Tatlasrrt *ar, TAtlasRRTStatistics *arst)
Prints the summary of atlasRRT statistics.
Definition: atlasrrt.c:538
unsigned int DetermineChartNeighbour(double epsilon, double *t, Tchart *c)
Determines the neighbouring chart containing a given point.
Definition: chart.c:1321
double GetDynamicDomainRadius(unsigned int i, Trrt *rrt)
Returns the current dynamic domain radius for a given sample.
Definition: rrt.c:3508
#define CS_WD_ORIGINAL_IN_COLLISION(pr, o, oPrev, wcs)
Checks if a configuration is in collision.
Definition: wcs.h:348
void SaveAtlasRRT(Tparameters *pr, char *prefix, Tatlasrrt *ar)
Stores the Atlas-RRT information on a file.
Definition: atlasrrt.c:4687
#define MOV_AVG_DOWN
Weight of new data when computing moving averages.
Definition: defines.h:467