cuikcctrrt.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 
85 int main(int argc, char **arg)
86 {
87  TAtlasBase world; /* The set of mechanism and obstacles. */
88  Tparameters parameters; /* Parameters used in the Cuik process. */
89 
90  Tfilename fparam;
91 
92  double *s1,*s2; /* Origin/goal of the RRT. */
93 
94  unsigned int nvs;
95 
96  Trrt rrt;
97 
98  boolean connected;
99  double pl, pc;
100  unsigned int ns;
101  double **path;
102 
103  double planningTime;
104 
105  unsigned int it,nRepetitions;
106  Taverages averages;
107 
108  unsigned int ri;
109  time_t t;
110 
111  TRRTStatistics *rst;
112 
113  if (argc>1)
114  {
115  if (argc>2)
116  {
117  nRepetitions=atoi(arg[2]);
118  if (nRepetitions==0)
119  Error("Second parameter for cuikcctrrt is wrong");
120  }
121  else
122  nRepetitions=1;
123 
124  if ((nRepetitions>1)&&((RRT_VERBOSE)||(GET_RRT_STATISTICS)))
125  Warning("To get accurate execution time statistics, set RRT_VERBOSE and GET_RRT_STATISTICS to 0");
126 
127  if ((GET_RRT_STATISTICS)&&(nRepetitions>1))
128  {
129  NEW(rst,1,TRRTStatistics);
130  InitRRTStatistics(rst);
131  }
132  else
133  rst=NULL;
134 
135  /*Init parameters*/
136  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
137  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
138  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
139 
140  /*Read the world from file*/
141  CS_WD_INIT(&parameters,arg[1],&world);
142 
143  /* Read samples */
144  #if (EXPLORATION_RRT)
145  nvs=ReadOneSample(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&world),&s1);
146  NEW(s2,nvs,double);
147  memcpy(s2,s1,sizeof(double)*nvs);
148  #else
149  nvs=ReadTwoSamples(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&world),&s1,&s2);
150  #endif
151 
152  /* Random seed initialization */
153  t=time(NULL); /* Get the time at which input files have been read */
154  ri=(unsigned int)t;
155  randomSet(ri);
156  fprintf(stderr,"Random seed : %u\n",ri);
157 
158  /* Start the process to connect the two samples */
159  InitAverages(nRepetitions,FALSE,TRUE,NO_UINT,&averages);
160 
161  for(it=0;it<nRepetitions;it++)
162  {
163  fprintf(stderr,"************************************************\n");
164 
165  /* Init a one-directional RRT */
166  InitRRT(&parameters,FALSE,FALSE,s1,ONE_TREE,FALSE,s2,nvs,&world,&rrt);
167 
168  /* Try to connect the goal with a tree from the start */
169  connected=ccTRRT(&parameters,s2,
170  &planningTime,
171  &pl,&pc,&ns,&path,CS_WD_COST_FN(&world),
172  CS_WD_COST_PTR(&world),rst,&rrt);
173 
174  /* Save the results (only if one shot execution) */
175  if (nRepetitions==1)
176  {
177  Tfilename frrt;
178 
179  #if (!EXPLORATION_RRT)
180  if (connected)
181  SaveSamples(arg[1],FALSE,nvs,ns,path);
182  #endif
183 
184  CreateFileName(NULL,arg[1],NULL,RRT_EXT,&frrt);
185  fprintf(stderr,"Writing RRT to : %s\n",GetFileFullName(&frrt));
186  SaveRRT(&frrt,&rrt);
187  DeleteFileName(&frrt);
188  }
189 
190  /* Summarize and release allocated objects for this repetition*/
191  if ((EXPLORATION_RRT)||(connected))
192  {
193  NewSuccesfulExperiment(planningTime,RRTMemSize(&rrt),pl,pc,
194  NO_UINT,
195  (double)GetRRTNumNodes(&rrt),
196  NULL,NULL,
197  &averages);
198  DeleteSamples(ns,path);
199  }
200  else
201  fprintf(stderr," Execution failed (%f sec)\n",planningTime);
202 
203  DeleteRRT(&rrt);
204 
205  fprintf(stderr,"Execution compleated %u/%u\n",it+1,nRepetitions);
206  }
207 
208  /* Print statistics about the execution (only if many iterations) */
209  if (nRepetitions>1)
210  {
211  PrintAveragesHeader(stderr,argc,arg,&averages);
212 
213  fprintf(stderr,"%% **************************************************\n");
214  fprintf(stderr,"Random seed : %u\n",ri);
215  PrintParameters(stderr,&parameters);
216 
217  #if (GET_RRT_STATISTICS)
218  PrintRRTStatistics(NULL,rst);
219  DeleteRRTStatistics(rst);
220  free(rst);
221  #endif
222 
223  PrintAverages(stderr,&averages);
224 
225  fprintf(stderr,"%% **************************************************\n");
226  }
227 
228  /* Release memory */
229  DeleteAverages(&averages);
230 
231  free(s1);
232  free(s2);
233 
234  DeleteParameters(&parameters);
235 
236  CS_WD_DELETE(&world);
237 
238  DeleteFileName(&fparam);
239  }
240  else
241  {
242  fprintf(stderr," Wrong number of parameters.\n");
243  fprintf(stderr," Use:\n");
244  fprintf(stderr," cuikcctrrt <problem filename>.%s [num Repetitions]\n",CS_WD_EXT);
245  fprintf(stderr," where <problem filename> the equations/world description\n");
246  fprintf(stderr," <num Repetitions> experiment repetitions to gather statistics\n");
247  fprintf(stderr," This is optional.\n");
248  fprintf(stderr," (the '.%s' extension is not required)\n",CS_WD_EXT);
249  }
250  return(EXIT_SUCCESS);
251 }
252 
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
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 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 CS_WD_COST_FN(wcs)
Cost function for a given configution.
Definition: wcs.h:369
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
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
#define CS_WD_COST_PTR(wcs)
Pointer to the base type.
Definition: wcs.h:359
Definition of the Tworld type and the associated functions.
Definition of a rrt on a manifold.
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
int main(int argc, char **arg)
Main body of the cuikcctrrt application.
Definition: cuikcctrrt.c:85
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.
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 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
#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
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
void PrintRRTStatistics(Trrt *rrt, TRRTStatistics *rst)
Prints the summary of RRT statistics.
Definition: rrt.c:352
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
unsigned int ReadOneSample(Tparameters *p, char *fname, unsigned int nvs, double **s)
Reads one sample from a file.
Definition: samples.c:1216
void randomSet(unsigned int seed)
Sets the random seed.
Definition: random.c:25