rrt.h
Go to the documentation of this file.
1 #ifndef RRTH
2 #define RRTH
3 
4 #include "parameters.h"
5 #include "vector.h"
6 #include "heap.h"
7 #include "wcs.h"
8 
9 #if (_KDTREE==1)
10  #include <cuik-kdtree/cuik-kdtree.h>
11 #endif
12 #if (_KDTREE==2)
13  #include <DNN/ANN_C.h>
14 #endif
15 
32 #define RRT_VERBOSE 0
33 
34 
41 #define GET_RRT_STATISTICS 1
42 
54 #define HEURISTIC_RRT_STAR (0) //(1+2)
55 
66 #define RRTSTAR_UPDATE_COSTS 0
67 
74 #define RRTSTAR_SYMMETRIC_COST 1
75 
79 #define TEMPERATURE_INIT 0.001
80 
96 #define EXPLORATION_RRT 0
97 
105 #define RRT_PLOT_NODES 1
106 
115 #define RRT_NN_TOPOLOGY 1
116 
123 #define INIT_NUM_SAMPLES_RRT 100
124 
130 #define ONE_TREE 0
131 
139 #define TWO_TREES 1
140 
152 #define TWO_TREES_WITH_SWAP 2
153 
159 #define NOTREE 0
160 
166 #define START2GOAL 1
167 
174 #define GOAL2START 2
175 
181 #define BOTHTREES (START2GOAL|GOAL2START)
182 
199 typedef struct {
200  unsigned int n;
203  unsigned int nBranch;
204  unsigned int nNoEmptyBranch;
206  unsigned int nTreeConnection;
207  unsigned int nNoEmptyTreeConnection;
209  unsigned int nStep;
210  double dQrand;
212  /* Reasons to stop a branch extension */
213  unsigned int nQrandReached;
214  unsigned int nConvergenceError;
215  unsigned int nHighCost;
216  unsigned int nOutOfDomain;
217  unsigned int nDistanceIncreases;
218  unsigned int nCollision;
219  unsigned int nTooFar;
220  unsigned int nStalled;
222  unsigned int nSample;
224  /* Information about sampling */
225  unsigned int nRandom;
227  unsigned int nRejections;
229  /* Information aobut collison checking */
230  unsigned int nCollisionChecks;
232 
233 /*******************************************************************************/
234 
246 typedef struct {
247  unsigned int id;
248  double cost;
249 } TRRTStep;
250 
259 void CopyRRTStep(void *a,void *b);
260 
268 void DeleteRRTStep(void *a);
269 
270 /*******************************************************************************/
271 
290 typedef struct {
291  double *samples;
292  unsigned int parent;
294  double costp;
296  double cost;
306  double ddr;
308  double g;
311  unsigned int m;
312  unsigned int nn;
313  unsigned int *n;
314  double *cn;
316  unsigned int tree;
317  void *userInfo;
319 
329 typedef struct {
332  unsigned int m;
334  unsigned int k;
335  unsigned int n;
337  double delta;
339  double temperature;
340  unsigned int nFail;
343  unsigned int nCores;
344  boolean parallel;
347  unsigned int *tp;
349  unsigned int ns;
350  unsigned int ms;
356  unsigned int mode;
358  boolean graph;
362  double dd;
364  #if (_KDTREE==1)
365  TKDtree *treeS2G;
366  TKDtree *treeG2S;
368  #endif
369  #if (_KDTREE==2)
370  TKDTree *treeS2G;
372  TKDTree *treeG2S;
374  unsigned int nodesT1;
376  unsigned int nodesT2;
378  unsigned int maxNodesT1;
380  unsigned int maxNodesT2;
382  unsigned int *t1ToId;
384  unsigned int *t2ToId;
387  #endif
388 
389 } Trrt;
390 
391 /*******************************************************************************/
392 
401 
413 
422 void PrintRRTStatistics(Trrt *rrt,TRRTStatistics *rst);
423 
432 
433 /*******************************************************************************/
434 
458 void InitRRT(Tparameters *pr,boolean parallel,boolean simp,double *ps,
459  unsigned int mode,boolean graph,double *pg,
460  unsigned int m,TAtlasBase *w,Trrt *rrt);
461 
471 double GetTRRTTemperature(Trrt *rrt);
472 
484 boolean IsRRTGraph(Trrt *rrt);
485 
513 boolean RRTSample(unsigned int samplingMode,unsigned int tree,
514  double *goal,double *q_rand,
515  TRRTStatistics *rst,Trrt *rrt);
516 
517 
539 boolean RRTValidateSample(Tparameters *pr,double *q_rand,unsigned int tree,boolean expand2goal,
540  double *goal,double l,double *h,unsigned int *i_near,
541  TRRTStatistics *rst,Trrt *rrt);
542 
557 unsigned int GetRRTNN(unsigned int tree,double *q_rand,Trrt *rrt);
558 
573 void GetRRTNNInBall(unsigned int tree,double *q_rand,double r,
574  unsigned int *nn,unsigned int **n,Trrt *rrt);
575 
594 void GetRRTNNInBranch(unsigned int tree,
595  unsigned int n1,unsigned int n2,
596  unsigned int *n,unsigned int *nn,
597  Trrt *rrt);
598 
629 boolean AddNodeToRRT(Tparameters *pr,unsigned int tree,
630  unsigned int i_near,double *sample,double *goal,
631  unsigned int *lastSample,void *info,double costp,double cost,
632  TRRTStatistics *rst,Trrt *rrt);
633 
646 void AddEdgeToRRT(unsigned int i,unsigned int j,double c,Trrt *rrt);
647 
648 
663 boolean TransitionTestRRT(Tparameters *pr,unsigned int parent,
664  double* q_next,double deltaStep,double* cost,
665  double (*costF)(Tparameters*,boolean,double*,void*),
666  void *costData,Trrt *rrt);
667 
684 void RecursiveReWireRRTstar(Tparameters *pr,Theap *q,double *g,Tvector *steps,double *l,
685  Trrt *rrt);
724 boolean RRTstar(Tparameters *pr,double *pg,
725  unsigned int *it,double *times,double *costs,
726  double *planningTime,double *pl,
727  unsigned int *ns,double ***path,
728  TRRTStatistics *grst,Trrt *rrt);
753 boolean BiRRTstar(Tparameters *pr,double *pg,
754  unsigned int *it,double *times,double *costs,
755  double *planningTime,double *pl,
756  unsigned int *ns,double ***path,
757  TRRTStatistics *grst,Trrt *rrt);
758 
785 boolean ccRRT(Tparameters *pr,double *pg,double *time,
786  double *pl,unsigned int *ns,double ***path,
787  TRRTStatistics *grst,Trrt *rrt);
788 
789 
823 boolean ccTRRT(Tparameters *pr,double *pg,
824  double *time,
825  double *pl, double* pc, unsigned int *ns,double ***path,
826  double (*costF)(Tparameters*,boolean,double*,void*),
827  void *costData,
828  TRRTStatistics *grst,Trrt *rrt);
829 
830 
831 
857 boolean cBiRRT(Tparameters *pr,double *pg,
858  double *time,
859  double *pl,unsigned int *ns,double ***path,
860  TRRTStatistics *grst,Trrt *rrt);
861 
862 
878 double RRTPathSteps(unsigned int sID,Tvector *path,Trrt *rrt);
879 
880 
900 double ChangeBiRRTSteps(unsigned int l1,unsigned int l2,double c12,
901  Tvector *steps,Trrt *rrt);
902 
921 double UpdateBiRRTSteps(Tvector *steps,Trrt *rrt);
922 
945 boolean PathStart2GoalInRRT(Tparameters *pr,double *pgs,
946  unsigned int l1,unsigned int l2,
947  double *pl,double *pc,unsigned int *ns,double ***path,
948  Trrt *rrt);
949 
959 boolean Bidirectional(Trrt *rrt);
960 
970 unsigned int GetRRTMode(Trrt *rrt);
971 
984 boolean InDynamicDomain(unsigned int i,double *q,Trrt *rrt);
985 
998 void AdjustDynamicDomain(unsigned int i,boolean collision,Trrt *rrt);
999 
1012 double GetDynamicDomainRadius(unsigned int i,Trrt *rrt);
1013 
1025 boolean DynamicDomainRRT(Trrt *rrt);
1026 
1036 unsigned int GetRRTNumNodes(Trrt *rrt);
1037 
1048 double *GetRRTNode(unsigned int i,Trrt *rrt);
1049 
1060 unsigned int GetRRTNodeTree(unsigned int i,Trrt *rrt);
1061 
1073 unsigned int GetRRTParent(unsigned int i,Trrt *rrt);
1074 
1086 void SetRRTParent(unsigned int i,unsigned int p,Trrt *rrt);
1087 
1098 void *GetRRTNodeInfo(unsigned int i,Trrt *rrt);
1099 
1109 void SetRRTNodeInfo(unsigned int i,void *info,Trrt *rrt);
1110 
1121 double GetRRTNodeCost(unsigned int i,Trrt *rrt);
1122 
1133 double GetRRTNodeCostFromParent(unsigned int i,Trrt *rrt);
1134 
1145 void SetRRTNodeCost(unsigned int i,double costp,double cost,Trrt *rrt);
1146 
1147 
1159 void SetRRTCostAndParent(unsigned int i,unsigned int p,double costp,double cost,Trrt *rrt);
1160 
1161 
1171 unsigned int *GetRRTTopology(Trrt *rrt);
1172 
1188 double CostToRoot(unsigned int sID,Trrt* rrt);
1189 
1199 void UpdateCostToRoot(unsigned int sID,Trrt* rrt);
1200 
1213 void UpdateTree(unsigned int sID,Trrt* rrt);
1214 
1224 void UpdateCostAndTree(unsigned int sID,Trrt* rrt);
1225 
1226 
1235 unsigned int StepsToRoot(unsigned int sID,Trrt* rrt);
1236 
1265 void PlotRRT(char *fname,int argc, char **arg,Tparameters *pr,
1266  unsigned int xID,unsigned int yID,unsigned int zID,Trrt *rrt);
1267 
1280 void SaveRRTNodes(Tparameters *pr,char *fname,boolean saveWithDummies,Trrt *rrt);
1281 
1292 void SaveRRTCosts(Tparameters *pr,char *fname,Trrt *rrt);
1293 
1303 unsigned int RRTMemSize(Trrt *rrt);
1304 
1315 void SaveRRT(Tfilename *fname,Trrt *rrt);
1316 
1335 void LoadRRT(Tparameters *pr,Tfilename *fname,TAtlasBase *w,Trrt *rrt);
1336 
1345 void DeleteRRT(Trrt *rrt);
1346 
1347 #endif
boolean IsRRTGraph(Trrt *rrt)
Identifies RRT with a graph structure.
Definition: rrt.c:1466
TRRTSampleInfo ** si
Definition: rrt.h:354
unsigned int nFail
Definition: rrt.h:340
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
double * cn
Definition: rrt.h:314
void AdjustDynamicDomain(unsigned int i, boolean collision, Trrt *rrt)
Sets the dynamic domain.
Definition: rrt.c:3482
Statistics on the RRT construction.
Definition: rrt.h:199
unsigned int nCollisionChecks
Definition: rrt.h:230
unsigned int id
Definition: rrt.h:247
unsigned int nRandom
Definition: rrt.h:225
double temperature
Definition: rrt.h:339
double GetRRTNodeCostFromParent(unsigned int i, Trrt *rrt)
Returns the cost from the parent node, if defined.
Definition: rrt.c:3596
void DeleteRRT(Trrt *rrt)
Destructor.
Definition: rrt.c:4196
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
boolean ccTRRT(Tparameters *pr, double *pg, double *time, double *pl, double *pc, unsigned int *ns, double ***path, double(*costF)(Tparameters *, boolean, double *, void *), void *costData, TRRTStatistics *grst, Trrt *rrt)
Extends a T-RRT until we reach a targed point.
Definition: rrt.c:2823
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
unsigned int nConvergenceError
Definition: rrt.h:214
void AddEdgeToRRT(unsigned int i, unsigned int j, double c, Trrt *rrt)
Adds a neighbouring relation to an RRT.
Definition: rrt.c:784
double g
Definition: rrt.h:308
unsigned int mode
Definition: rrt.h:356
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 SaveRRTNodes(Tparameters *pr, char *fname, boolean saveWithDummies, Trrt *rrt)
Stores the nodes of the RRT.
Definition: rrt.c:3878
void DeleteRRTStatistics(TRRTStatistics *rst)
Destructor.
Definition: rrt.c:499
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 GetRRTNN(unsigned int tree, double *q_rand, Trrt *rrt)
Locates the nearest sample in the tree of samples.
Definition: rrt.c:1547
unsigned int tree
Definition: rrt.h:316
TAtlasBase * w
Definition: rrt.h:330
unsigned int m
Definition: rrt.h:311
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
double RRTPathSteps(unsigned int sID, Tvector *path, Trrt *rrt)
Produces a vector with the nodes in a given branch.
Definition: rrt.c:3277
void DeleteRRTStep(void *a)
RRTStep destructor.
Definition: rrt.c:756
void SaveRRTCosts(Tparameters *pr, char *fname, Trrt *rrt)
Stores the cost associated with the nodes of the RRT.
Definition: rrt.c:3929
double GetTRRTTemperature(Trrt *rrt)
Temperature of the T-RRT.
Definition: rrt.c:1461
A RRT on a manifold.
Definition: rrt.h:329
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 n
Definition: rrt.h:335
unsigned int RRTMemSize(Trrt *rrt)
Memory used by a given RRT.
Definition: rrt.c:3968
unsigned int nStalled
Definition: rrt.h:220
boolean graph
Definition: rrt.h:358
void SetRRTParent(unsigned int i, unsigned int p, Trrt *rrt)
Changes the parent for a given node.
Definition: rrt.c:3555
boolean RRTstar(Tparameters *pr, double *pg, unsigned int *it, double *times, double *costs, double *planningTime, double *pl, unsigned int *ns, double ***path, TRRTStatistics *grst, Trrt *rrt)
Optimal RRT on manifolds.
Definition: rrt.c:2352
void LoadRRT(Tparameters *pr, Tfilename *fname, TAtlasBase *w, Trrt *rrt)
Defines a RRT from the information on a file.
Definition: rrt.c:4036
boolean RRTValidateSample(Tparameters *pr, double *q_rand, unsigned int tree, boolean expand2goal, double *goal, double l, double *h, unsigned int *i_near, TRRTStatistics *rst, Trrt *rrt)
Validates a sample generate with RRTSample.
Definition: rrt.c:1510
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
double * GetRRTNode(unsigned int i, Trrt *rrt)
Returns one of the nodes of the RRT.
Definition: rrt.c:3526
unsigned int StepsToRoot(unsigned int sID, Trrt *rrt)
Computes the number of steps from a node to the root.
Definition: rrt.c:3714
unsigned int ms
Definition: rrt.h:350
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 * tp
Definition: rrt.h:347
double costp
Definition: rrt.h:294
boolean ccRRT(Tparameters *pr, double *pg, double *time, double *pl, unsigned int *ns, double ***path, TRRTStatistics *grst, Trrt *rrt)
Extends a RRT until we reach a targed point.
Definition: rrt.c:2966
Tbox * ambient
Definition: rrt.h:352
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
double UpdateBiRRTSteps(Tvector *steps, Trrt *rrt)
Updates the current optimal path.
Definition: rrt.c:3357
unsigned int ns
Definition: rrt.h:349
void InitRRTStatistics(TRRTStatistics *rst)
Init the RRT statistics.
Definition: rrt.c:195
unsigned int nNoEmptyBranch
Definition: rrt.h:204
void SetRRTNodeInfo(unsigned int i, void *info, Trrt *rrt)
Changes the user info associated with a node.
Definition: rrt.c:3580
unsigned int GetRRTMode(Trrt *rrt)
Identifies mode of the RRTs.
Definition: rrt.c:3469
unsigned int k
Definition: rrt.h:334
boolean parallel
Definition: rrt.h:344
unsigned int nQrandReached
Definition: rrt.h:213
double dd
Definition: rrt.h:362
unsigned int nNoEmptyTreeConnection
Definition: rrt.h:207
A table of parameters.
double cost
Definition: rrt.h:296
Type defining the equations on which the atlas is defined.
Definition: wcs.h:30
A generic vector.
Definition: vector.h:227
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
unsigned int nOutOfDomain
Definition: rrt.h:216
unsigned int m
Definition: rrt.h:332
unsigned int nCollision
Definition: rrt.h:218
double cost
Definition: rrt.h:248
unsigned int nDistanceIncreases
Definition: rrt.h:217
A box.
Definition: box.h:83
unsigned int GetRRTNodeTree(unsigned int i, Trrt *rrt)
Returns the tree for a given node.
Definition: rrt.c:3534
double GetRRTNodeCost(unsigned int i, Trrt *rrt)
Returns the cost associated with a node.
Definition: rrt.c:3588
unsigned int nTooFar
Definition: rrt.h:219
void SaveRRT(Tfilename *fname, Trrt *rrt)
Stores the RRT information on a file.
Definition: rrt.c:3985
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
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 * samples
Definition: rrt.h:291
A generic binary heap.
Definition: heap.h:105
unsigned int nCores
Definition: rrt.h:343
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
double CostToRoot(unsigned int sID, Trrt *rrt)
Computes the cost from a node to the root.
Definition: rrt.c:3638
unsigned int parent
Definition: rrt.h:292
void UpdateCostAndTree(unsigned int sID, Trrt *rrt)
A combination of UpdateCostToRoot and UpdateTree.
Definition: rrt.c:3687
void SetRRTNodeCost(unsigned int i, double costp, double cost, Trrt *rrt)
Changes the cost associated with a node.
Definition: rrt.c:3604
void UpdateCostToRoot(unsigned int sID, Trrt *rrt)
Updates the cost from a node to the root.
Definition: rrt.c:3653
Macros and functions to operate on worlds/cuiksystems.
unsigned int nn
Definition: rrt.h:312
void PrintRRTStatistics(Trrt *rrt, TRRTStatistics *rst)
Prints the summary of RRT statistics.
Definition: rrt.c:352
boolean BiRRTstar(Tparameters *pr, double *pg, unsigned int *it, double *times, double *costs, double *planningTime, double *pl, unsigned int *ns, double ***path, TRRTStatistics *grst, Trrt *rrt)
Optimal RRT on manifolds.
Definition: rrt.c:2584
unsigned int nTreeConnection
Definition: rrt.h:206
unsigned int nRejections
Definition: rrt.h:227
unsigned int nSample
Definition: rrt.h:222
void AccumulateRRTStatistics(TRRTStatistics *rst1, TRRTStatistics *rst2)
Accumulates two sets of RRT statistics.
Definition: rrt.c:318
void * userInfo
Definition: rrt.h:317
unsigned int nHighCost
Definition: rrt.h:215
Definition of the Tparameters type and the associated functions.
void UpdateTree(unsigned int sID, Trrt *rrt)
Updates the tree assignment a node to the root.
Definition: rrt.c:3658
unsigned int nStep
Definition: rrt.h:209
Information for each sample in a RRT.
Definition: rrt.h:290
unsigned int n
Definition: rrt.h:200
void CopyRRTStep(void *a, void *b)
Copy constructor for RRTSteps.
Definition: rrt.c:750
double dQrand
Definition: rrt.h:210
boolean cBiRRT(Tparameters *pr, double *pg, double *time, double *pl, unsigned int *ns, double ***path, TRRTStatistics *grst, Trrt *rrt)
Extends a RRT until we reach a targed point.
Definition: rrt.c:3099
unsigned int nBranch
Definition: rrt.h:203
double ddr
Definition: rrt.h:306
unsigned int * GetRRTTopology(Trrt *rrt)
Returns a pointer to an array with the topology for each variable.
Definition: rrt.c:3633
double delta
Definition: rrt.h:337
void * GetRRTNodeInfo(unsigned int i, Trrt *rrt)
Returns the user info associated with a node.
Definition: rrt.c:3572
double GetDynamicDomainRadius(unsigned int i, Trrt *rrt)
Returns the current dynamic domain radius for a given sample.
Definition: rrt.c:3508
unsigned int * n
Definition: rrt.h:313
boolean Bidirectional(Trrt *rrt)
Identifies bidirectional RRTs.
Definition: rrt.c:3463