cuikrrtstar.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 "rrt.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 
96 int main(int argc, char **arg)
97 {
98  TAtlasBase world; /* The set of mechanism and obstacles. */
99  Tparameters parameters; /* Parameters used in the Cuik process. */
100 
101  Tfilename fparam;
102 
103  double *s1,*s2; /* Origin/goal of the RRT. */
104 
105  unsigned int nvs;
106 
107  Trrt rrt;
108 
109  boolean connected;
110  double planningTime;
111  double pl;
112  unsigned int ns;
113  double **path;
114  boolean birrt;
115  boolean rrtgraph;
116 
117  unsigned int it,nRepetitions;
118  Taverages averages;
119 
120  unsigned int ri;
121  time_t t;
122 
123  /* Statistics about the time take up to each iteration and
124  the path lengh at that point */
125  unsigned int maxIt,execIt;
126  double *times,*costs;
127 
128  TRRTStatistics *rst;
129 
130  if (argc>1)
131  {
132  if (argc>2)
133  {
134  nRepetitions=atoi(arg[2]);
135  if (nRepetitions==0)
136  Error("Second parameter for cuikrrtstar is wrong");
137  }
138  else
139  nRepetitions=1;
140 
141  if ((nRepetitions>1)&&((RRT_VERBOSE)||(GET_RRT_STATISTICS)))
142  Warning("To get accurate execution time statistics, set RRT_VERBOSE and GET_RRT_STATISTICS to 0");
143 
144  if ((GET_RRT_STATISTICS)&&(nRepetitions>1))
145  {
146  NEW(rst,1,TRRTStatistics);
147  InitRRTStatistics(rst);
148  }
149  else
150  rst=NULL;
151 
152  /*Init parameters*/
153  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
154  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
155  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
156 
157  birrt=(GetParameter(CT_BI_RRT,&parameters)>0.5);
158  rrtgraph=(GetParameter(CT_RRT_GRAPH,&parameters)>0.5);
159 
160  /*Read the world from file*/
161  CS_WD_INIT(&parameters,arg[1],&world);
162 
163  /* Read samples */
164  nvs=ReadTwoSamples(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&world),&s1,&s2);
165 
166  /* Random seed initialization */
167  t=time(NULL); /* Get the time at which input files have been read */
168  ri=(unsigned int)t;
169  //ri=1406813613;
170  randomSet(ri);
171  fprintf(stderr,"Random seed : %u\n",ri);
172 
173  /* Maximum number of iterations (set to NO_UINT to limit execution only in time) */
174  maxIt=(unsigned int)GetParameter(CT_MAX_PLANNING_ITERATIONS,&parameters);
175 
176  /* Start the process to connect the two samples */
177  InitAverages(nRepetitions,FALSE,TRUE,maxIt,&averages);
178 
179  /* Buffer to store statistics about the path length */
180  if (maxIt!=NO_UINT)
181  {
182  NEW(times,maxIt,double);
183  NEW(costs,maxIt,double);
184  }
185 
186  for(it=0;it<nRepetitions;it++)
187  {
188  fprintf(stderr,"************************************************\n");
189 
190  /* Init a RRT (bi-directional and with graph structure depending on parameters) */
191  InitRRT(&parameters,TRUE,FALSE,s1,(birrt?TWO_TREES_WITH_SWAP:ONE_TREE),rrtgraph,s2,nvs,&world,&rrt);
192 
193  /* Try to connect the goal with a tree from the start with
194  an optimal path */
195  connected=RRTstar(&parameters,s2,
196  &execIt,times,costs,
197  &planningTime,&pl,&ns,&path,
198  rst,&rrt);
199 
200  /* Save the results (only if one shot execution) */
201  if (nRepetitions==1)
202  {
203  Tfilename frrt;
204 
205  if (connected)
206  SaveSamples(arg[1],FALSE,nvs,ns,path);
207 
208  CreateFileName(NULL,arg[1],NULL,RRT_EXT,&frrt);
209  fprintf(stderr,"Writing RRT to : %s\n",GetFileFullName(&frrt));
210  SaveRRT(&frrt,&rrt);
211  DeleteFileName(&frrt);
212  }
213 
214  /* Summarize and release allocated objects for this repetition*/
215  if (connected)
216  {
217  NewSuccesfulExperiment(planningTime,RRTMemSize(&rrt),pl,0,
218  NO_UINT,
219  (double)GetRRTNumNodes(&rrt),
220  (execIt==maxIt?times:NULL),
221  (execIt==maxIt?costs:NULL),
222  &averages);
223  DeleteSamples(ns,path);
224  }
225  else
226  fprintf(stderr," Execution failed\n");
227 
228  DeleteRRT(&rrt);
229 
230  fprintf(stderr,"Execution compleated %u/%u\n",it+1,nRepetitions);
231  }
232 
233  /* Print statistics about the execution (only if many iterations) */
234  if (nRepetitions>1)
235  {
236  PrintAveragesHeader(stderr,argc,arg,&averages);
237 
238  fprintf(stderr,"%% **************************************************\n");
239  fprintf(stderr,"Random seed : %u\n",ri);
240  fprintf(stderr,"Update_Costs: %u Symmetric_Cost: %u Heuristic: %u \n",
242  PrintParameters(stderr,&parameters);
243 
244  #if (GET_ATLASRRT_STATISTICS)
245  PrintAtlasRRTStatistics(NULL,arst);
247  free(arst);
248  #endif
249 
250  PrintAverages(stderr,&averages);
251 
252  fprintf(stderr,"%% **************************************************\n");
253  }
254 
255  /* Release memory */
256  if (maxIt!=NO_UINT)
257  {
258  free(times);
259  free(costs);
260  }
261 
262  DeleteAverages(&averages);
263 
264  free(s1);
265  free(s2);
266 
267  DeleteParameters(&parameters);
268 
269  CS_WD_DELETE(&world);
270 
271  DeleteFileName(&fparam);
272  }
273  else
274  {
275  fprintf(stderr," Wrong number of parameters.\n");
276  fprintf(stderr," Use:\n");
277  fprintf(stderr," cuikrrtstar <problem filename>.%s [num Repetitions]\n",CS_WD_EXT);
278  fprintf(stderr," where <problem filename> the equations/world description\n");
279  fprintf(stderr," <num Repetitions> experiment repetitions to gather statistics\n");
280  fprintf(stderr," This is optional.\n");
281  fprintf(stderr," (the '.%s' extension is not required)\n",CS_WD_EXT);
282  }
283  return(EXIT_SUCCESS);
284 }
285 
Statistics on the RRT construction.
Definition: rrt.h:199
Definition of basic functions.
#define FALSE
FALSE.
Definition: boolean.h:30
void PrintParameters(FILE *f, Tparameters *p)
Prints a parameter set.
Definition: parameters.c:181
void DeleteRRT(Trrt *rrt)
Destructor.
Definition: rrt.c:4196
#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
#define RRT_EXT
File extension for files storing rrt's.
Definition: filename.h:205
int main(int argc, char **arg)
Main body of the cuikrrtstar application.
Definition: cuikrrtstar.c:96
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 CT_RRT_GRAPH
Graph RRT.
Definition: parameters.h:518
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
Definition of the Tfilename type and the associated functions.
#define ONE_TREE
One of the modes for the RRT.
Definition: rrt.h:130
#define TRUE
TRUE.
Definition: boolean.h:21
void Error(const char *s)
General error function.
Definition: error.c:80
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:131
A RRT on a manifold.
Definition: rrt.h:329
#define CS_WD_DELETE(wcs)
Destructor of the equation structure.
Definition: wcs.h:500
unsigned int RRTMemSize(Trrt *rrt)
Memory used by a given RRT.
Definition: rrt.c:3968
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
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
Definition of a rrt on a manifold.
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
void InitRRTStatistics(TRRTStatistics *rst)
Init the RRT statistics.
Definition: rrt.c:195
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 HEURISTIC_RRT_STAR
Whether to use an heuristic in AtlarRRT*.
Definition: rrt.h:54
Auxiliary functions to deal averages of path planner executions.
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 NO_UINT
Used to denote an identifier that has not been initialized.
Definition: defines.h:435
void SaveRRT(Tfilename *fname, Trrt *rrt)
Stores the RRT information on a file.
Definition: rrt.c:3985
#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
#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
#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
unsigned int GetRRTNumNodes(Trrt *rrt)
Number of nodes in the RRT.
Definition: rrt.c:3521
#define GET_RRT_STATISTICS
Set this to one to gather statistics of RRT construction.
Definition: rrt.h:41
#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.
Definition of basic randomization functions.
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.
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 randomSet(unsigned int seed)
Sets the random seed.
Definition: random.c:25