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 
98 #define EXPLORATION_RRT 0
99 
107 #define RRT_PLOT_NODES 1
108 
117 #define RRT_NN_TOPOLOGY 1
118 
125 #define INIT_NUM_SAMPLES_RRT 100
126 
132 #define ONE_TREE 0
133 
141 #define TWO_TREES 1
142 
154 #define TWO_TREES_WITH_SWAP 2
155 
161 #define NOTREE 0
162 
168 #define START2GOAL 1
169 
176 #define GOAL2START 2
177 
183 #define BOTHTREES (START2GOAL|GOAL2START)
184 
201 typedef struct {
202  unsigned int n;
205  unsigned int nBranch;
206  unsigned int nNoEmptyBranch;
208  unsigned int nTreeConnection;
209  unsigned int nNoEmptyTreeConnection;
211  unsigned int nStep;
212  double dQrand;
214  /* Reasons to stop a branch extension */
215  unsigned int nQrandReached;
216  unsigned int nConvergenceError;
217  unsigned int nHighCost;
218  unsigned int nOutOfDomain;
219  unsigned int nDistanceIncreases;
220  unsigned int nCollision;
221  unsigned int nTooFar;
222  unsigned int nStalled;
224  unsigned int nSample;
226  /* Information about sampling */
227  unsigned int nRandom;
229  unsigned int nRejections;
231  /* Information aobut collison checking */
232  unsigned int nCollisionChecks;
234 
235 /*******************************************************************************/
236 
248 typedef struct {
249  unsigned int id;
250  double cost;
251 } TRRTStep;
252 
261 void CopyRRTStep(void *a,void *b);
262 
263 /*******************************************************************************/
264 
283 typedef struct {
284  double *samples;
285  unsigned int parent;
287  double costp;
289  double cost;
299  double ddr;
301  double g;
304  unsigned int m;
305  unsigned int nn;
306  unsigned int *n;
307  double *cn;
309  unsigned int tree;
310  void *userInfo;
312 
322 typedef struct {
325  unsigned int m;
327  unsigned int k;
328  unsigned int n;
330  double delta;
332  double temperature;
333  unsigned int nFail;
336  unsigned int nCores;
337  boolean parallel;
340  unsigned int *tp;
342  unsigned int ns;
343  unsigned int ms;
349  unsigned int mode;
351  boolean graph;
355  double dd;
357  #if (_KDTREE==1)
358  TKDtree *treeS2G;
359  TKDtree *treeG2S;
361  #endif
362  #if (_KDTREE==2)
363  TKDTree *treeS2G;
365  TKDTree *treeG2S;
367  unsigned int nodesT1;
369  unsigned int nodesT2;
371  unsigned int maxNodesT1;
373  unsigned int maxNodesT2;
375  unsigned int *t1ToId;
377  unsigned int *t2ToId;
380  #endif
381 
382 } Trrt;
383 
384 /*******************************************************************************/
385 
394 
406 
415 void PrintRRTStatistics(Trrt *rrt,TRRTStatistics *rst);
416 
425 
426 /*******************************************************************************/
427 
451 void InitRRT(Tparameters *pr,boolean parallel,boolean simp,double *ps,
452  unsigned int mode,boolean graph,double *pg,
453  unsigned int m,TAtlasBase *w,Trrt *rrt);
454 
464 double GetTRRTTemperature(Trrt *rrt);
465 
477 boolean IsRRTGraph(Trrt *rrt);
478 
506 boolean RRTSample(unsigned int samplingMode,unsigned int tree,
507  double *goal,double *q_rand,
508  TRRTStatistics *rst,Trrt *rrt);
509 
510 
532 boolean RRTValidateSample(Tparameters *pr,double *q_rand,unsigned int tree,boolean expand2goal,
533  double *goal,double l,double *h,unsigned int *i_near,
534  TRRTStatistics *rst,Trrt *rrt);
535 
550 unsigned int GetRRTNN(unsigned int tree,double *q_rand,Trrt *rrt);
551 
566 void GetRRTNNInBall(unsigned int tree,double *q_rand,double r,
567  unsigned int *nn,unsigned int **n,Trrt *rrt);
568 
587 void GetRRTNNInBranch(unsigned int tree,
588  unsigned int n1,unsigned int n2,
589  unsigned int *n,unsigned int *nn,
590  Trrt *rrt);
591 
622 boolean AddNodeToRRT(Tparameters *pr,unsigned int tree,
623  unsigned int i_near,double *sample,double *goal,
624  unsigned int *lastSample,void *info,double costp,double cost,
625  TRRTStatistics *rst,Trrt *rrt);
626 
639 void AddEdgeToRRT(unsigned int i,unsigned int j,double c,Trrt *rrt);
640 
641 
656 boolean TransitionTestRRT(Tparameters *pr,unsigned int parent,
657  double* q_next,double deltaStep,double* cost,
658  double (*costF)(Tparameters*,boolean,double*,void*),
659  void *costData,Trrt *rrt);
660 
677 void RecursiveReWireRRTstar(Tparameters *pr,Theap *q,double *g,Tvector *steps,double *l,
678  Trrt *rrt);
717 boolean RRTstar(Tparameters *pr,double *pg,
718  unsigned int *it,double *times,double *costs,
719  double *planningTime,double *pl,
720  unsigned int *ns,double ***path,
721  TRRTStatistics *grst,Trrt *rrt);
746 boolean BiRRTstar(Tparameters *pr,double *pg,
747  unsigned int *it,double *times,double *costs,
748  double *planningTime,double *pl,
749  unsigned int *ns,double ***path,
750  TRRTStatistics *grst,Trrt *rrt);
751 
778 boolean ccRRT(Tparameters *pr,double *pg,double *time,
779  double *pl,unsigned int *ns,double ***path,
780  TRRTStatistics *grst,Trrt *rrt);
781 
782 
816 boolean ccTRRT(Tparameters *pr,double *pg,
817  double *time,
818  double *pl, double* pc, unsigned int *ns,double ***path,
819  double (*costF)(Tparameters*,boolean,double*,void*),
820  void *costData,
821  TRRTStatistics *grst,Trrt *rrt);
822 
823 
824 
850 boolean cBiRRT(Tparameters *pr,double *pg,
851  double *time,
852  double *pl,unsigned int *ns,double ***path,
853  TRRTStatistics *grst,Trrt *rrt);
854 
855 
871 double RRTPathSteps(unsigned int sID,Tvector *path,Trrt *rrt);
872 
873 
893 double ChangeBiRRTSteps(unsigned int l1,unsigned int l2,double c12,
894  Tvector *steps,Trrt *rrt);
895 
914 double UpdateBiRRTSteps(Tvector *steps,Trrt *rrt);
915 
938 boolean PathStart2GoalInRRT(Tparameters *pr,double *pgs,
939  unsigned int l1,unsigned int l2,
940  double *pl,double *pc,unsigned int *ns,double ***path,
941  Trrt *rrt);
942 
952 boolean Bidirectional(Trrt *rrt);
953 
963 unsigned int GetRRTMode(Trrt *rrt);
964 
977 boolean InDynamicDomain(unsigned int i,double *q,Trrt *rrt);
978 
991 void AdjustDynamicDomain(unsigned int i,boolean collision,Trrt *rrt);
992 
1005 double GetDynamicDomainRadius(unsigned int i,Trrt *rrt);
1006 
1018 boolean DynamicDomainRRT(Trrt *rrt);
1019 
1029 unsigned int GetRRTNumNodes(Trrt *rrt);
1030 
1041 double *GetRRTNode(unsigned int i,Trrt *rrt);
1042 
1053 unsigned int GetRRTNodeTree(unsigned int i,Trrt *rrt);
1054 
1066 unsigned int GetRRTParent(unsigned int i,Trrt *rrt);
1067 
1079 void SetRRTParent(unsigned int i,unsigned int p,Trrt *rrt);
1080 
1091 void *GetRRTNodeInfo(unsigned int i,Trrt *rrt);
1092 
1102 void SetRRTNodeInfo(unsigned int i,void *info,Trrt *rrt);
1103 
1114 double GetRRTNodeCost(unsigned int i,Trrt *rrt);
1115 
1126 double GetRRTNodeCostFromParent(unsigned int i,Trrt *rrt);
1127 
1138 void SetRRTNodeCost(unsigned int i,double costp,double cost,Trrt *rrt);
1139 
1140 
1152 void SetRRTCostAndParent(unsigned int i,unsigned int p,double costp,double cost,Trrt *rrt);
1153 
1154 
1164 unsigned int *GetRRTTopology(Trrt *rrt);
1165 
1181 double CostToRoot(unsigned int sID,Trrt* rrt);
1182 
1192 void UpdateCostToRoot(unsigned int sID,Trrt* rrt);
1193 
1206 void UpdateTree(unsigned int sID,Trrt* rrt);
1207 
1217 void UpdateCostAndTree(unsigned int sID,Trrt* rrt);
1218 
1219 
1228 unsigned int StepsToRoot(unsigned int sID,Trrt* rrt);
1229 
1258 void PlotRRT(char *fname,int argc, char **arg,Tparameters *pr,
1259  unsigned int xID,unsigned int yID,unsigned int zID,Trrt *rrt);
1260 
1273 void SaveRRTNodes(Tparameters *pr,char *fname,boolean saveWithDummies,Trrt *rrt);
1274 
1285 void SaveRRTCosts(Tparameters *pr,char *fname,Trrt *rrt);
1286 
1296 unsigned int RRTMemSize(Trrt *rrt);
1297 
1308 void SaveRRT(Tfilename *fname,Trrt *rrt);
1309 
1328 void LoadRRT(Tparameters *pr,Tfilename *fname,TAtlasBase *w,Trrt *rrt);
1329 
1338 void DeleteRRT(Trrt *rrt);
1339 
1340 #endif
boolean IsRRTGraph(Trrt *rrt)
Identifies RRT with a graph structure.
Definition: rrt.c:1465
TRRTSampleInfo ** si
Definition: rrt.h:347
unsigned int nFail
Definition: rrt.h:333
unsigned int GetRRTParent(unsigned int i, Trrt *rrt)
Returns identifier of the parent of one of the nodes of the RRT.
Definition: rrt.c:3552
double * cn
Definition: rrt.h:307
void AdjustDynamicDomain(unsigned int i, boolean collision, Trrt *rrt)
Sets the dynamic domain.
Definition: rrt.c:3481
Statistics on the RRT construction.
Definition: rrt.h:201
unsigned int nCollisionChecks
Definition: rrt.h:232
unsigned int id
Definition: rrt.h:249
unsigned int nRandom
Definition: rrt.h:227
double temperature
Definition: rrt.h:332
double GetRRTNodeCostFromParent(unsigned int i, Trrt *rrt)
Returns the cost from the parent node, if defined.
Definition: rrt.c:3601
void DeleteRRT(Trrt *rrt)
Destructor.
Definition: rrt.c:4201
boolean RRTSample(unsigned int samplingMode, unsigned int tree, double *goal, double *q_rand, TRRTStatistics *rst, Trrt *rrt)
Generates a random sample to expand the RRT.
Definition: rrt.c:1470
Data structure to hold the information about the name of a file.
Definition: filename.h:271
boolean ccTRRT(Tparameters *pr, double *pg, double *time, double *pl, double *pc, unsigned int *ns, double ***path, double(*costF)(Tparameters *, boolean, double *, void *), void *costData, TRRTStatistics *grst, Trrt *rrt)
Extends a T-RRT until we reach a targed point.
Definition: rrt.c:2822
void PlotRRT(char *fname, int argc, char **arg, Tparameters *pr, unsigned int xID, unsigned int yID, unsigned int zID, Trrt *rrt)
Pots a projection of a RRT.
Definition: rrt.c:3734
unsigned int nConvergenceError
Definition: rrt.h:216
void AddEdgeToRRT(unsigned int i, unsigned int j, double c, Trrt *rrt)
Adds a neighbouring relation to an RRT.
Definition: rrt.c:781
double g
Definition: rrt.h:301
unsigned int mode
Definition: rrt.h:349
boolean AddNodeToRRT(Tparameters *pr, unsigned int tree, unsigned int i_near, double *sample, double *goal, unsigned int *lastSample, void *info, double costp, double cost, TRRTStatistics *rst, Trrt *rrt)
Adds a point to a RRT.
Definition: rrt.c:1868
void SaveRRTNodes(Tparameters *pr, char *fname, boolean saveWithDummies, Trrt *rrt)
Stores the nodes of the RRT.
Definition: rrt.c:3883
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:1203
unsigned int GetRRTNN(unsigned int tree, double *q_rand, Trrt *rrt)
Locates the nearest sample in the tree of samples.
Definition: rrt.c:1546
unsigned int tree
Definition: rrt.h:309
TAtlasBase * w
Definition: rrt.h:323
unsigned int m
Definition: rrt.h:304
boolean TransitionTestRRT(Tparameters *pr, unsigned int parent, double *q_next, double deltaStep, double *cost, double(*costF)(Tparameters *, boolean, double *, void *), void *costData, Trrt *rrt)
transition Test for Transition RRT
Definition: rrt.c:806
double RRTPathSteps(unsigned int sID, Tvector *path, Trrt *rrt)
Produces a vector with the nodes in a given branch.
Definition: rrt.c:3276
void SaveRRTCosts(Tparameters *pr, char *fname, Trrt *rrt)
Stores the cost associated with the nodes of the RRT.
Definition: rrt.c:3934
double GetTRRTTemperature(Trrt *rrt)
Temperature of the T-RRT.
Definition: rrt.c:1460
A RRT on a manifold.
Definition: rrt.h:322
double ChangeBiRRTSteps(unsigned int l1, unsigned int l2, double c12, Tvector *steps, Trrt *rrt)
Changes the optimal path in a bidirectional RRT.
Definition: rrt.c:3297
unsigned int n
Definition: rrt.h:328
unsigned int RRTMemSize(Trrt *rrt)
Memory used by a given RRT.
Definition: rrt.c:3973
unsigned int nStalled
Definition: rrt.h:222
boolean graph
Definition: rrt.h:351
void SetRRTParent(unsigned int i, unsigned int p, Trrt *rrt)
Changes the parent for a given node.
Definition: rrt.c:3560
boolean RRTstar(Tparameters *pr, double *pg, unsigned int *it, double *times, double *costs, double *planningTime, double *pl, unsigned int *ns, double ***path, TRRTStatistics *grst, Trrt *rrt)
Optimal RRT on manifolds.
Definition: rrt.c:2351
void LoadRRT(Tparameters *pr, Tfilename *fname, TAtlasBase *w, Trrt *rrt)
Defines a RRT from the information on a file.
Definition: rrt.c:4041
boolean RRTValidateSample(Tparameters *pr, double *q_rand, unsigned int tree, boolean expand2goal, double *goal, double l, double *h, unsigned int *i_near, TRRTStatistics *rst, Trrt *rrt)
Validates a sample generate with RRTSample.
Definition: rrt.c:1509
boolean PathStart2GoalInRRT(Tparameters *pr, double *pgs, unsigned int l1, unsigned int l2, double *pl, double *pc, unsigned int *ns, double ***path, Trrt *rrt)
Determines the path from start to goal using an RRT.
Definition: rrt.c:3401
double * GetRRTNode(unsigned int i, Trrt *rrt)
Returns one of the nodes of the RRT.
Definition: rrt.c:3531
unsigned int StepsToRoot(unsigned int sID, Trrt *rrt)
Computes the number of steps from a node to the root.
Definition: rrt.c:3719
unsigned int ms
Definition: rrt.h:343
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:3473
unsigned int * tp
Definition: rrt.h:340
double costp
Definition: rrt.h:287
boolean ccRRT(Tparameters *pr, double *pg, double *time, double *pl, unsigned int *ns, double ***path, TRRTStatistics *grst, Trrt *rrt)
Extends a RRT until we reach a targed point.
Definition: rrt.c:2965
Tbox * ambient
Definition: rrt.h:345
void RecursiveReWireRRTstar(Tparameters *pr, Theap *q, double *g, Tvector *steps, double *l, Trrt *rrt)
A rewire that is propagates as much as necessary over the graph.
Definition: rrt.c:2144
double UpdateBiRRTSteps(Tvector *steps, Trrt *rrt)
Updates the current optimal path.
Definition: rrt.c:3356
unsigned int ns
Definition: rrt.h:342
void InitRRTStatistics(TRRTStatistics *rst)
Init the RRT statistics.
Definition: rrt.c:195
unsigned int nNoEmptyBranch
Definition: rrt.h:206
void SetRRTNodeInfo(unsigned int i, void *info, Trrt *rrt)
Changes the user info associated with a node.
Definition: rrt.c:3585
unsigned int GetRRTMode(Trrt *rrt)
Identifies mode of the RRTs.
Definition: rrt.c:3468
unsigned int k
Definition: rrt.h:327
boolean parallel
Definition: rrt.h:337
unsigned int nQrandReached
Definition: rrt.h:215
double dd
Definition: rrt.h:355
unsigned int nNoEmptyTreeConnection
Definition: rrt.h:209
A table of parameters.
double cost
Definition: rrt.h:289
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:1774
unsigned int nOutOfDomain
Definition: rrt.h:218
unsigned int m
Definition: rrt.h:325
unsigned int nCollision
Definition: rrt.h:220
double cost
Definition: rrt.h:250
unsigned int nDistanceIncreases
Definition: rrt.h:219
A box.
Definition: box.h:83
unsigned int GetRRTNodeTree(unsigned int i, Trrt *rrt)
Returns the tree for a given node.
Definition: rrt.c:3539
double GetRRTNodeCost(unsigned int i, Trrt *rrt)
Returns the cost associated with a node.
Definition: rrt.c:3593
unsigned int nTooFar
Definition: rrt.h:221
void SaveRRT(Tfilename *fname, Trrt *rrt)
Stores the RRT information on a file.
Definition: rrt.c:3990
void GetRRTNNInBall(unsigned int tree, double *q_rand, double r, unsigned int *nn, unsigned int **n, Trrt *rrt)
Locates the all the sample closer than a given distance.
Definition: rrt.c:1653
Definition of the Tvector type and the associated functions.
Step in a solution path.
Definition: rrt.h:248
void SetRRTCostAndParent(unsigned int i, unsigned int p, double costp, double cost, Trrt *rrt)
Changes the cost and the parent associated with a node.
Definition: rrt.c:3620
double * samples
Definition: rrt.h:284
A generic binary heap.
Definition: heap.h:105
unsigned int nCores
Definition: rrt.h:336
boolean DynamicDomainRRT(Trrt *rrt)
TRUE if the dynamic domain is active.
Definition: rrt.c:3521
unsigned int GetRRTNumNodes(Trrt *rrt)
Number of nodes in the RRT.
Definition: rrt.c:3526
double CostToRoot(unsigned int sID, Trrt *rrt)
Computes the cost from a node to the root.
Definition: rrt.c:3643
unsigned int parent
Definition: rrt.h:285
void UpdateCostAndTree(unsigned int sID, Trrt *rrt)
A combination of UpdateCostToRoot and UpdateTree.
Definition: rrt.c:3692
void SetRRTNodeCost(unsigned int i, double costp, double cost, Trrt *rrt)
Changes the cost associated with a node.
Definition: rrt.c:3609
void UpdateCostToRoot(unsigned int sID, Trrt *rrt)
Updates the cost from a node to the root.
Definition: rrt.c:3658
Macros and functions to operate on worlds/cuiksystems.
unsigned int nn
Definition: rrt.h:305
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:2583
unsigned int nTreeConnection
Definition: rrt.h:208
unsigned int nRejections
Definition: rrt.h:229
unsigned int nSample
Definition: rrt.h:224
void AccumulateRRTStatistics(TRRTStatistics *rst1, TRRTStatistics *rst2)
Accumulates two sets of RRT statistics.
Definition: rrt.c:318
void * userInfo
Definition: rrt.h:310
unsigned int nHighCost
Definition: rrt.h:217
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:3663
unsigned int nStep
Definition: rrt.h:211
Information for each sample in a RRT.
Definition: rrt.h:283
unsigned int n
Definition: rrt.h:202
void CopyRRTStep(void *a, void *b)
Copy constructor for RRTSteps.
Definition: rrt.c:750
double dQrand
Definition: rrt.h:212
boolean cBiRRT(Tparameters *pr, double *pg, double *time, double *pl, unsigned int *ns, double ***path, TRRTStatistics *grst, Trrt *rrt)
Extends a RRT until we reach a targed point.
Definition: rrt.c:3098
unsigned int nBranch
Definition: rrt.h:205
double ddr
Definition: rrt.h:299
unsigned int * GetRRTTopology(Trrt *rrt)
Returns a pointer to an array with the topology for each variable.
Definition: rrt.c:3638
double delta
Definition: rrt.h:330
void * GetRRTNodeInfo(unsigned int i, Trrt *rrt)
Returns the user info associated with a node.
Definition: rrt.c:3577
double GetDynamicDomainRadius(unsigned int i, Trrt *rrt)
Returns the current dynamic domain radius for a given sample.
Definition: rrt.c:3513
unsigned int * n
Definition: rrt.h:306
boolean Bidirectional(Trrt *rrt)
Identifies bidirectional RRTs.
Definition: rrt.c:3462