cuikatlasrrtstar.c
Go to the documentation of this file.
1 
2 #include "world.h"
3 #include "parameters.h"
4 
5 #include "defines.h"
6 #include "error.h"
7 #include "filename.h"
8 #include "atlasrrt.h"
9 #include "random.h"
10 #include "geom.h"
11 #include "samples.h"
12 #include "averages.h"
13 
14 #include <stdlib.h>
15 #include <string.h>
16 #include <time.h>
17 #include <math.h>
18 
84 int main(int argc, char **arg)
85 {
86  TAtlasBase world; /* The set of mechanism and obstacles. */
87  Tparameters parameters; /* Parameters used in the Cuik process. */
88 
89  Tfilename fparam;
90 
91  double *s1,*s2; /* Origin/goal of the AtlasRRT. */
92 
93  unsigned int nvs;
94 
95  Tatlasrrt atlasrrt;
96 
97  boolean connected;
98  double planningTime;
99  double pl;
100  unsigned int ns;
101  double **path;
102  boolean birrt;
103  boolean rrtgraph;
104 
105  unsigned int it,nRepetitions;
106  Taverages averages;
107 
108  unsigned int ri;
109  time_t t;
110 
111  /* Statistics about the time take up to each iteration and
112  the path lengh at that point */
113  unsigned int maxIt,execIt;
114  double *times,*costs;
115 
116  TAtlasRRTStatistics *arst;
117 
118  if (argc>1)
119  {
120  if (argc>2)
121  {
122  nRepetitions=atoi(arg[2]);
123  if (nRepetitions==0)
124  Error("Second parameter for cuikatlasrrtstar is wrong");
125  }
126  else
127  nRepetitions=1;
128 
129  if ((nRepetitions>1)&&(RRT_VERBOSE))
130  Warning("To get accurate execution time statistics, set GET_ATLASRRT_STATISTICS to 0");
131 
132  if ((GET_ATLASRRT_STATISTICS)&&(nRepetitions>1))
133  {
134  NEW(arst,1,TAtlasRRTStatistics);
136  }
137  else
138  arst=NULL;
139 
140  /*Init parameters*/
141  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
142  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
143  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
144 
145  birrt=(GetParameter(CT_BI_RRT,&parameters)>0.5);
146  rrtgraph=(GetParameter(CT_RRT_GRAPH,&parameters)>0.5);
147 
148  /*Read the world/cuik from file*/
149  CS_WD_INIT(&parameters,arg[1],&world);
150 
151  /* Read samples */
152  nvs=ReadTwoSamples(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&world),&s1,&s2);
153 
154  /* Random seed initialization */
155  t=time(NULL); /* Get the time at which input files have been read */
156  ri=(unsigned int)t;
157  //ri=1341338413; // with gamma=0 the c8 give a long path
158  //ri=1341346253; // seed used to generate the growing RRTs for c8
159  randomSet(ri);
160  fprintf(stderr,"Random seed : %u\n",ri);
161 
162  /* Maximum of iteraitons (set to NO_UINT to limit execution only in time) */
163  maxIt=(unsigned int)GetParameter(CT_MAX_PLANNING_ITERATIONS,&parameters);
164 
165  /* Start the process to connect the two samples */
166  InitAverages(nRepetitions,TRUE,TRUE,maxIt,&averages);
167 
168  /* Buffer to store statistics about the path length */
169  if (maxIt!=NO_UINT)
170  {
171  NEW(times,maxIt,double);
172  NEW(costs,maxIt,double);
173  }
174 
175  for(it=0;it<nRepetitions;it++)
176  {
177  fprintf(stderr,"************************************************\n");
178  /* Init an AtlasRRT (bi-directional or with graph structure depending on parameters) */
179  InitAtlasRRT(&parameters,TRUE/*parallel*/,s1,(birrt?TWO_TREES_WITH_SWAP:ONE_TREE),rrtgraph,s2,&world,&atlasrrt);
180 
181  /* Try to connect the goal with a tree from the start with
182  an optimal path */
183  connected=AtlasRRTstar(&parameters,s2,
184  &execIt,
185  times,costs,
186  &planningTime,&pl,&ns,&path,arst,&atlasrrt);
187 
188  /* Save the results (only if one shot execution) */
189  if (nRepetitions==1)
190  {
191  if (connected)
192  SaveSamples(arg[1],FALSE,nvs,ns,path);
193 
194  SaveAtlasRRT(&parameters,arg[1],&atlasrrt);
195  }
196 
197  /* Summarize and release allocated objects for this repetition*/
198  if (connected)
199  {
200  NewSuccesfulExperiment(planningTime,AtlasRRTMemSize(&atlasrrt),pl,0,
201  (double)GetAtlasRRTNumCharts(&atlasrrt),
202  (double)GetAtlasRRTNumNodes(&atlasrrt),
203  (execIt==maxIt?times:NULL),
204  (execIt==maxIt?costs:NULL),
205  &averages);
206 
207  DeleteSamples(ns,path);
208  }
209  else
210  fprintf(stderr," Execution failed\n");
211 
212  DeleteAtlasRRT(&atlasrrt);
213 
214  fprintf(stderr,"Execution compleated %u/%u\n",it+1,nRepetitions);
215  }
216 
217  /* Print data about the path length at each iteration. 0 means no path
218  to goal found yet */
219 
220  /* Print statistics about the execution (only if many iterations) */
221 
222  if (nRepetitions>1)
223  {
224  PrintAveragesHeader(stderr,argc,arg,&averages);
225 
226  fprintf(stderr,"%% **************************************************\n");
227  fprintf(stderr,"Random seed : %u\n",ri);
228  fprintf(stderr,"Update_Costs: %u Symmetric_Cost: %u Heuristic: %u Exploration: %u Adjust_SA: %u Adjust_SR: %u (%.2f--%.2f) GlobalNN: %u GlobalCurv: %u Tree_ATLAS: %u\n",
230  PrintParameters(stderr,&parameters);
231 
232  #if (GET_ATLASRRT_STATISTICS)
233  PrintAtlasRRTStatistics(NULL,arst);
235  free(arst);
236  #endif
237 
238  PrintAverages(stderr,&averages);
239 
240  fprintf(stderr,"%% **************************************************\n");
241  }
242 
243  /* Release memory */
244  if (maxIt!=NO_UINT)
245  {
246  free(times);
247  free(costs);
248  }
249 
250  DeleteAverages(&averages);
251 
252  free(s1);
253  free(s2);
254 
255  DeleteParameters(&parameters);
256 
257  CS_WD_DELETE(&world);
258 
259  DeleteFileName(&fparam);
260  }
261  else
262  {
263  fprintf(stderr," Wrong number of parameters.\n");
264  fprintf(stderr," Use:\n");
265  fprintf(stderr," cuikatlasrrtstar <problem filename>.%s [num Repetitions]\n",CS_WD_EXT);
266  fprintf(stderr," where <problem filename> the equations/world description\n");
267  fprintf(stderr," <num Repetitions> experiment repetitions to gather statistics\n");
268  fprintf(stderr," This is optional.\n");
269  fprintf(stderr," (the '.%s' extension is not required)\n",CS_WD_EXT);
270  }
271  return(EXIT_SUCCESS);
272 }
273 
Definition of the combination of an atlas with a RRT.
Definition of basic functions.
#define FALSE
FALSE.
Definition: boolean.h:30
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
void PrintParameters(FILE *f, Tparameters *p)
Prints a parameter set.
Definition: parameters.c:181
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
Data structure to hold the information about the name of a file.
Definition: filename.h:248
void NewSuccesfulExperiment(double t, unsigned int mem, double pl, double pc, unsigned int nc, unsigned int ns, double *time, double *cost, Taverages *av)
Adds data of a new experiment.
Definition: averages.c:75
#define RRT_VERBOSE
Vebosity of the RRT operations.
Definition: rrt.h:32
#define USE_ATLAS_TREE
Whether to use a binary tree to search for neighbouring charts.
Definition: atlas.h:78
#define CT_RRT_GRAPH
Graph RRT.
Definition: parameters.h:518
Definition of the Tfilename type and the associated functions.
#define ONE_TREE
One of the modes for the RRT.
Definition: rrt.h:130
void DeleteAtlasRRT(Tatlasrrt *ar)
Destructor.
Definition: atlasrrt.c:4817
#define TRUE
TRUE.
Definition: boolean.h:21
void InitAtlasRRTStatistics(TAtlasRRTStatistics *arst)
Init the Atlas RRT statistics.
Definition: atlasrrt.c:325
void Error(const char *s)
General error function.
Definition: error.c:80
#define ADJUST_SR
Set this to one if the sampling radius for each polytope has to be self-adjusted. ...
Definition: scpolytope.h:31
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:131
#define CS_WD_DELETE(wcs)
Destructor of the equation structure.
Definition: wcs.h:500
Definition of the Tworld type and the associated functions.
#define CT_MAX_PLANNING_ITERATIONS
Maximum iterations for path planning.
Definition: parameters.h:483
#define CT_BI_RRT
Bi-directional RRT.
Definition: parameters.h:508
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
#define RRTSTAR_UPDATE_COSTS
On the fly update of the cost in the RRTstar.
Definition: rrt.h:66
void PrintAverages(FILE *f, Taverages *av)
Prints the averages of a set of experiments.
Definition: averages.c:170
void PrintAveragesHeader(FILE *f, int argc, char **arg, Taverages *av)
Prints a header to the averages results.
Definition: averages.c:149
unsigned int AtlasRRTMemSize(Tatlasrrt *ar)
Memory used by a given atlasRRT.
Definition: atlasrrt.c:4677
unsigned int ReadTwoSamples(Tparameters *p, char *fname, unsigned int nvs, double **s1, double **s2)
Reads two samples from a file.
Definition: samples.c:1247
Definitions of constants and macros used in several parts of the cuik library.
#define ATLASRRT_GLOBAL_NN
Set to 1 if nearest neighbours are searched without using the chart relations.
Definition: atlasrrt.h:70
#define HEURISTIC_RRT_STAR
Whether to use an heuristic in AtlarRRT*.
Definition: rrt.h:54
int main(int argc, char **arg)
Main body of the cuikatlasrrtstar application.
Auxiliary functions to deal averages of path planner executions.
#define MOV_AVG_UP
Weight of new data when computing moving averages.
Definition: defines.h:451
void Warning(const char *s)
General warning function.
Definition: error.c:116
A table of parameters.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
void DeleteAtlasRRTStatistics(TAtlasRRTStatistics *arst)
Destructor.
Definition: atlasrrt.c:745
void InitParametersFromFile(char *file, Tparameters *p)
Constructor from a file.
Definition: parameters.c:51
Type defining the equations on which the atlas is defined.
Definition: wcs.h:30
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
#define EXPLORATION_RRT
Select between exploration and goal driven RRT.
Definition: rrt.h:96
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
#define CS_WD_EXT
Possible extensions for the equation files.
Definition: wcs.h:48
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:295
void SaveSamples(char *fname, boolean smooth, unsigned int nvs, unsigned int ns, double **path)
Saves a set of samples to a file.
Definition: samples.c:1318
Statistics on the AtlasRRT constrution.
Definition: atlasrrt.h:96
#define CS_WD_INIT(pr, name, wcs)
Initializes the equations from a file.
Definition: wcs.h:89
Structure to store expeeriment results.
Definition: averages.h:32
RRT with an atlas for sampling.
Definition: atlasrrt.h:190
#define RRTSTAR_SYMMETRIC_COST
TRUE (or 1) if cost(a,b)=cost(b,a)
Definition: rrt.h:74
#define TWO_TREES_WITH_SWAP
One of the modes for the RRT.
Definition: rrt.h:152
double GetParameter(unsigned int n, Tparameters *p)
Gets the value for a particular parameter.
Definition: parameters.c:93
#define ADJUST_SA
Set this to one to adjust the sampling area.
Definition: atlasrrt.h:57
#define CS_WD_GET_NUM_SYSTEM_VARS(wcs)
Gets the number of system variables.
Definition: wcs.h:250
Auxiliary functions to deal with sets of samples.
#define GET_ATLASRRT_STATISTICS
Set this to one to gather statistics of AtlasRRT construction.
Definition: atlasrrt.h:38
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.
#define GET_ATLASRRT_GLOBAL_CURV_CHECK
Set this to one to check the global curvature tolerences between charts.
Definition: atlasrrt.h:78
void DeleteAverages(Taverages *av)
Deletes the space used by a set of averages.
Definition: averages.c:263
void DeleteSamples(unsigned int ns, double **path)
Deletes the space used by a set of samples.
Definition: samples.c:1495
Definition of the Tparameters type and the associated functions.
unsigned int GetAtlasRRTNumNodes(Tatlasrrt *ar)
Number of nodes in the AtlasRRT.
Definition: atlasrrt.c:4400
void InitAverages(unsigned int m, boolean useCharts, boolean useSamples, unsigned int maxIt, Taverages *av)
Initializes a set of averages.
Definition: averages.c:21
void PrintAtlasRRTStatistics(Tatlasrrt *ar, TAtlasRRTStatistics *arst)
Prints the summary of atlasRRT statistics.
Definition: atlasrrt.c:538
void SaveAtlasRRT(Tparameters *pr, char *prefix, Tatlasrrt *ar)
Stores the Atlas-RRT information on a file.
Definition: atlasrrt.c:4687
void randomSet(unsigned int seed)
Sets the random seed.
Definition: random.c:25
#define MOV_AVG_DOWN
Weight of new data when computing moving averages.
Definition: defines.h:467