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