cuikatlasAstar.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 
74 int main(int argc, char **arg)
75 {
76 
77  TAtlasBase world; /* The set of mechanism and obstacles. */
78  Tparameters parameters; /* Parameters used in the Cuik process. */
79 
80  Tfilename fparam;
81 
82  double *s1,*s2; /* Two points on the manifold to connect. */
83 
84  unsigned int nvs;
85 
86  boolean connected;
87  double pl;
88  unsigned int ns;
89  double **path;
90 
91  double planningTime;
92 
93  Tatlas atlas;
94 
95  unsigned int it,nRepetitions;
96  Taverages averages;
97 
98  unsigned int ri;
99  time_t t;
100 
101  if (argc>1)
102  {
103  if (argc>2)
104  {
105  nRepetitions=atoi(arg[2]);
106  if (nRepetitions==0)
107  Error("Second parameter for cuikatlasAstar is wrong");
108  }
109  else
110  nRepetitions=1;
111 
112  if ((nRepetitions>1)&&(ATLAS_VERBOSE))
113  Warning("To get accurate execution time statistics, set GET_ATLASRRT_STATISTICS to 0");
114 
115  /*Init parameters*/
116  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
117  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
118  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
119 
120  /*Read the world/cuik from file*/
121  CS_WD_INIT(&parameters,arg[1],&world);
122 
123  /* Read two samples (start/goal) */
124  nvs=ReadTwoSamples(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&world),&s1,&s2);
125 
126  /* Random seed initialization */
127  t=time(NULL); /* Get the time at which input files have been read */
128  ri=(unsigned int)t;
129  randomSet(ri);
130  fprintf(stderr,"Random seed : %u\n",ri);
131 
132  /* Start the process to connect the two samples */
133  InitAverages(nRepetitions,TRUE,FALSE,NO_UINT,&averages);
134 
135  for(it=0;it<nRepetitions;it++)
136  {
137  /* Initialize the atlas */
138  if (!InitAtlasFromPoint(&parameters,TRUE/*parallel*/,FALSE,s1,&world,&atlas))
139  Error("Can not start an atlas from the given point");
140 
141  /* Completed the path to the goal */
142 
143  connected=AtlasAStar(&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  if (connected)
153  {
154  SaveSamples(arg[1],FALSE,nvs,ns,path);
155  // fprintf(stderr,"Path lenght %f\n",pl);
156  }
157 
158  // fprintf(stderr," Ambient space dim: %u\n",GetAtlasAmbientDim(&atlas));
159 
160  CreateFileName(NULL,arg[1],NULL,ATLAS_EXT,&fatlas);
161  fprintf(stderr,"Writing atlas to : %s\n",GetFileFullName(&fatlas));
162  SaveAtlas(&parameters,&fatlas,&atlas);
163  DeleteFileName(&fatlas);
164  }
165 
166  /* Summarize and delete the information for this repetition */
167  if (connected)
168  {
169  NewSuccesfulExperiment(planningTime,AtlasMemSize(&atlas),pl,0,
170  (double)GetAtlasNumCharts(&atlas),
171  NO_UINT,NULL,NULL,
172  &averages);
173  DeleteSamples(ns,path);
174  }
175  else
176  fprintf(stderr," Execution failed (%f sec)\n",planningTime);
177 
178  DeleteAtlas(&atlas);
179 
180  fprintf(stderr,"Execution compleated %u/%u\n",it+1,nRepetitions);
181  }
182 
183  /* Print statistics about the execution (only if many iterations) */
184  if (nRepetitions>1)
185  {
186  PrintAveragesHeader(stderr,argc,arg,&averages);
187 
188  fprintf(stderr,"%% **************************************************\n");
189  fprintf(stderr,"Random seed : %u\n",ri);
190  fprintf(stderr,"Tree_Atlas: %u\n",USE_ATLAS_TREE);
191  PrintParameters(stderr,&parameters);
192 
193  PrintAverages(stderr,&averages);
194 
195  fprintf(stderr,"%% **************************************************\n");
196  }
197 
198  /* Release memory */
199  DeleteAverages(&averages);
200 
201  free(s1);
202  free(s2);
203 
204  DeleteParameters(&parameters);
205 
206  CS_WD_DELETE(&world);
207 
208  DeleteFileName(&fparam);
209 
210  }
211  else
212  {
213  fprintf(stderr," Wrong number of parameters.\n");
214  fprintf(stderr," Use:\n");
215  fprintf(stderr," cuikatlasAstar <problem filename>.%s [num Repetitions]\n",CS_WD_EXT);
216  fprintf(stderr," where <problem filename> the equations/world description\n");
217  fprintf(stderr," <num Repetitions> experiment repetitions to gather statistics\n");
218  fprintf(stderr," This parameter is optional.\n");
219  fprintf(stderr," (the '.%s' extension is not required)\n",CS_WD_EXT);
220  }
221  return(EXIT_SUCCESS);
222 }
223 
boolean AtlasAStar(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:3341
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
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 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:4561
void Error(const char *s)
General error function.
Definition: error.c:80
#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.
Definition of a rrt on a manifold.
unsigned int GetAtlasNumCharts(Tatlas *a)
Number of charts in the atlas.
Definition: atlas.c:3931
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:199
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: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
Definition of an atlas on a manifold.
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
int main(int argc, char **arg)
Main body of the cuikatlasAstar application.
A atlas on a manifold.
Definition: atlas.h:289
unsigned int AtlasMemSize(Tatlas *a)
Memory used by a given atlas.
Definition: atlas.c:3831
#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
void SaveAtlas(Tparameters *pr, Tfilename *fname, Tatlas *a)
Stores the atlas information on a file.
Definition: atlas.c:3842
#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:250
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:2742
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 randomSet(unsigned int seed)
Sets the random seed.
Definition: random.c:25