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  if (GetParameter(CT_DYNAMICS,&parameters)>0)
122  Error("cuikatlasGBF do not work for problems with dynamics");
123 
124  /*Read the world/cuik from file*/
125  CS_WD_INIT(&parameters,arg[1],&world);
126 
127  /* Read samples */
128  nvs=ReadTwoSamples(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&world),&s1,&s2);
129 
130  /* Random seed initialization */
131  t=time(NULL); /* Get the time at which input files have been read */
132  ri=(unsigned int)t;
133  randomSet(ri);
134  fprintf(stderr,"Random seed : %u\n",ri);
135 
136  /* Start the process to connect the two samples */
137  InitAverages(nRepetitions,TRUE,FALSE,NO_UINT,&averages);
138 
139  for(it=0;it<nRepetitions;it++)
140  {
141  if (!InitAtlasFromPoint(&parameters,FALSE,FALSE,s1,&world,&atlas))
142  Error("Can not start an atlas from the given point");
143 
144  fprintf(stderr,"************************************************\n");
145 
146  connected=AtlasGBF(&parameters,s2,
147  &planningTime,
148  &pl,&ns,&path,&atlas);
149 
150  /* Save the results (only if one shot execution) */
151  if (nRepetitions==1)
152  {
153  Tfilename fatlas;
154 
155  fprintf(stderr,"Ambient space dim: %u\n",GetAtlasAmbientDim(&atlas));
156  fprintf(stderr,"Manifold dim : %u\n",GetAtlasManifoldDim(&atlas));
157 
158  if (connected)
159  SaveSamples(arg[1],FALSE,nvs,ns,path);
160 
161  CreateFileName(NULL,arg[1],NULL,ATLAS_EXT,&fatlas);
162  fprintf(stderr,"Writing atlas to : %s\n",GetFileFullName(&fatlas));
163  SaveAtlas(&parameters,&fatlas,&atlas);
164  DeleteFileName(&fatlas);
165  }
166 
167  /* Summarize and elete the information for this repetition */
168  if (connected)
169  {
170  NewSuccesfulExperiment(planningTime,AtlasMemSize(&atlas),pl,0,
171  (double)GetAtlasNumCharts(&atlas),
172  NO_UINT,NULL,NULL,
173  &averages);
174  DeleteSamples(ns,path);
175  }
176  else
177  fprintf(stderr," Execution failed (%f sec)\n",planningTime);
178 
179  DeleteAtlas(&atlas);
180 
181  fprintf(stderr,"Execution compleated %u/%u\n",it+1,nRepetitions);
182  }
183 
184  /* Print statistics about the execution (only if many iterations) */
185  if (nRepetitions>1)
186  {
187  PrintAveragesHeader(stderr,argc,arg,&averages);
188 
189  fprintf(stderr,"%% **************************************************\n");
190  fprintf(stderr," Random seed : %u\n",ri);
191  PrintAtlasDefines(stderr);
192  PrintParameters(stderr,&parameters);
193 
194  PrintAverages(stderr,&averages);
195 
196  fprintf(stderr,"%% **************************************************\n");
197  }
198 
199  /* Release memory */
200  DeleteAverages(&averages);
201 
202  free(s1);
203  free(s2);
204 
205  DeleteParameters(&parameters);
206 
207  CS_WD_DELETE(&world);
208 
209  DeleteFileName(&fparam);
210  }
211  else
212  {
213  fprintf(stderr," Wrong number of parameters.\n");
214  fprintf(stderr," Use:\n");
215  fprintf(stderr," cuikatlasGBF <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 is optional.\n");
219  fprintf(stderr," (the '.%s' extension is not required)\n",CS_WD_EXT);
220  }
221  return(EXIT_SUCCESS);
222 }
223