cuikatlasGBF.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 "atlas.h"
9 #include "random.h"
10 #include "geom.h"
11 #include "samples.h"
12 #include "rrt.h"
13 #include "averages.h"
14 
15 #include <stdlib.h>
16 #include <time.h>
17 
80 int main(int argc, char **arg)
81 {
82  TAtlasBase world; /* The set of mechanism and obstacles. */
83  Tparameters parameters; /* Parameters used in the Cuik process. */
84 
85  Tfilename fparam;
86 
87  double *s1,*s2; /* Two points on the manifold to connect. */
88 
89  unsigned int nvs;
90 
91  boolean connected;
92  double pl;
93  unsigned int ns;
94  double **path;
95 
96  double planningTime;
97 
98  Tatlas atlas;
99 
100  unsigned int it,nRepetitions;
101  Taverages averages;
102 
103  unsigned int ri;
104  time_t t;
105 
106  if (argc>1)
107  {
108  if (argc>2)
109  nRepetitions=atoi(arg[2]);
110  else
111  nRepetitions=1;
112 
113  if ((nRepetitions>1)&&(ATLAS_VERBOSE))
114  Warning("To get accurate execution time statistics, set GET_ATLASRRT_STATISTICS to 0");
115 
116  /*Init parameters*/
117  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
118  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
119  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
120 
121  /*Read the world/cuik from file*/
122  CS_WD_INIT(&parameters,arg[1],&world);
123 
124  /* Read samples */
125  nvs=ReadTwoSamples(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&world),&s1,&s2);
126 
127  /* Random seed initialization */
128  t=time(NULL); /* Get the time at which input files have been read */
129  ri=(unsigned int)t;
130  randomSet(ri);
131  fprintf(stderr,"Random seed : %u\n",ri);
132 
133  /* Start the process to connect the two samples */
134  InitAverages(nRepetitions,TRUE,FALSE,NO_UINT,&averages);
135 
136  for(it=0;it<nRepetitions;it++)
137  {
138  if (!InitAtlasFromPoint(&parameters,FALSE,FALSE,s1,&world,&atlas))
139  Error("Can not start an atlas from the given point");
140 
141  fprintf(stderr,"************************************************\n");
142 
143  connected=AtlasGBF(&parameters,s2,
144  &planningTime,
145  &pl,&ns,&path,&atlas);
146 
147  /* Save the results (only if one shot execution) */
148  if (nRepetitions==1)
149  {
150  Tfilename fatlas;
151 
152  fprintf(stderr,"Ambient space dim: %u\n",GetAtlasAmbientDim(&atlas));
153  fprintf(stderr,"Manifold dim : %u\n",GetAtlasManifoldDim(&atlas));
154 
155  if (connected)
156  SaveSamples(arg[1],FALSE,nvs,ns,path);
157 
158  CreateFileName(NULL,arg[1],NULL,ATLAS_EXT,&fatlas);
159  fprintf(stderr,"Writing atlas to : %s\n",GetFileFullName(&fatlas));
160  SaveAtlas(&parameters,&fatlas,&atlas);
161  DeleteFileName(&fatlas);
162  }
163 
164  /* Summarize and elete the information for this repetition */
165  if (connected)
166  {
167  NewSuccesfulExperiment(planningTime,AtlasMemSize(&atlas),pl,0,
168  (double)GetAtlasNumCharts(&atlas),
169  NO_UINT,NULL,NULL,
170  &averages);
171  DeleteSamples(ns,path);
172  }
173  else
174  fprintf(stderr," Execution failed (%f sec)\n",planningTime);
175 
176  DeleteAtlas(&atlas);
177 
178  fprintf(stderr,"Execution compleated %u/%u\n",it+1,nRepetitions);
179  }
180 
181  /* Print statistics about the execution (only if many iterations) */
182  if (nRepetitions>1)
183  {
184  PrintAveragesHeader(stderr,argc,arg,&averages);
185 
186  fprintf(stderr,"%% **************************************************\n");
187  fprintf(stderr,"Random seed : %u\n",ri);
188  fprintf(stderr,"Tree_Atlas: %u\n",USE_ATLAS_TREE);
189  PrintParameters(stderr,&parameters);
190 
191  PrintAverages(stderr,&averages);
192 
193  fprintf(stderr,"%% **************************************************\n");
194  }
195 
196  /* Release memory */
197  DeleteAverages(&averages);
198 
199  free(s1);
200  free(s2);
201 
202  DeleteParameters(&parameters);
203 
204  CS_WD_DELETE(&world);
205 
206  DeleteFileName(&fparam);
207  }
208  else
209  {
210  fprintf(stderr," Wrong number of parameters.\n");
211  fprintf(stderr," Use:\n");
212  fprintf(stderr," cuikatlasGBF <problem filename>.%s [num Repetitions]\n",CS_WD_EXT);
213  fprintf(stderr," where <problem filename> the equations/world description\n");
214  fprintf(stderr," <num Repetitions> experiment repetitions to gather statistics\n");
215  fprintf(stderr," This is optional.\n");
216  fprintf(stderr," (the '.%s' extension is not required)\n",CS_WD_EXT);
217  }
218  return(EXIT_SUCCESS);
219 }
220 
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
unsigned int GetAtlasManifoldDim(Tatlas *a)
Manifold dimensionality.
Definition: atlas.c:3440
Data structure to hold the information about the name of a file.
Definition: filename.h:271
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 USE_ATLAS_TREE
Whether to use a binary tree to search for neighbouring charts.
Definition: atlas.h:78
Definition of the Tfilename type and the associated functions.
#define TRUE
TRUE.
Definition: boolean.h:21
void DeleteAtlas(Tatlas *a)
Destructor.
Definition: atlas.c:4634
void Error(const char *s)
General error function.
Definition: error.c:80
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:132
#define CS_WD_DELETE(wcs)
Destructor of the equation structure.
Definition: wcs.h:592
void SaveSamples(char *fname, char *suffix, unsigned int nvs, unsigned int ns, double **path)
Saves a set of samples to a file.
Definition: samples.c:2879
unsigned int GetAtlasAmbientDim(Tatlas *a)
Ambient dimensionality.
Definition: atlas.c:3435
Definition of the Tworld type and the associated functions.
Definition of a rrt on a manifold.
unsigned int GetAtlasNumCharts(Tatlas *a)
Number of charts in the atlas.
Definition: atlas.c:4035
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
#define ATLAS_EXT
File extension for files storing atlas.
Definition: filename.h:200
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 ReadTwoSamples(Tparameters *p, char *fname, unsigned int nvs, double **s1, double **s2)
Reads two samples from a file.
Definition: samples.c:2803
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
Definition of an atlas on a manifold.
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
boolean AtlasGBF(Tparameters *pr, double *p, double *time, double *pl, unsigned int *ns, double ***path, Tatlas *a)
Expands the atlas to reach a given point.
Definition: atlas.c:3781
A atlas on a manifold.
Definition: atlas.h:289
unsigned int AtlasMemSize(Tatlas *a)
Memory used by a given atlas.
Definition: atlas.c:3935
#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:294
int main(int argc, char **arg)
Main body of the cuikatlasGBF application.
Definition: cuikatlasGBF.c:80
void SaveAtlas(Tparameters *pr, Tfilename *fname, Tatlas *a)
Stores the atlas information on a file.
Definition: atlas.c:3946
#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 ATLAS_VERBOSE
Vebosity of the atlas operations.
Definition: atlas.h:29
#define CS_WD_GET_NUM_SYSTEM_VARS(wcs)
Gets the number of system variables.
Definition: wcs.h:264
Auxiliary functions to deal with sets of samples.
boolean InitAtlasFromPoint(Tparameters *pr, boolean parallel, boolean simpleChart, double *p, TAtlasBase *w, Tatlas *a)
Initializes an atlas from a given point.
Definition: atlas.c:2782
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:3159
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 randomSet(unsigned int seed)
Sets the random seed.
Definition: random.c:25