cuikatlastrrt.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 "atlasrrt.h"
9 #include "random.h"
10 #include "geom.h"
11 #include "chart.h"
12 #include "samples.h"
13 #include "averages.h"
14 
15 #include <stdlib.h>
16 #include <string.h>
17 #include <time.h>
18 
79 int main(int argc, char **arg)
80 {
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; /* Origin/goal of the RRT. */
88 
89  unsigned int nvs;
90 
91  Tatlasrrt atlasrrt;
92 
93  boolean connected;
94  double pl, pc;
95  unsigned int ns;
96  double **path;
97 
98  double planningTime;
99 
100  unsigned int it,nRepetitions;
101  Taverages averages;
102 
103  unsigned int ri; /* random seed*/
104  time_t t; /* Used to timestamp the results */
105 
106  unsigned int db;
107 
108  TAtlasRRTStatistics *arst;
109 
110  if (argc>1)
111  {
112  if (argc>2)
113  {
114  nRepetitions=atoi(arg[2]);
115  if (nRepetitions==0)
116  Error("Second parameter for cuikatlastrrt is wrong");
117  }
118  else
119  nRepetitions=1;
120 
121  if ((nRepetitions>1)&&(GET_ATLASRRT_STATISTICS))
122  Warning("To get accurate execution time statistics, set GET_ATLASRRT_STATISTICS to 0");
123 
124  if ((nRepetitions>1)&&(ATLASRRT_VERBOSE))
125  Warning("To get accurate execution time statistics, set GET_ATLASRRT_STATISTICS to 0");
126 
127  if ((GET_ATLASRRT_STATISTICS)&&(nRepetitions>1))
128  {
129  NEW(arst,1,TAtlasRRTStatistics);
131  }
132  else
133  arst=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  db=(unsigned int)GetParameter(CT_DETECT_BIFURCATIONS,&parameters);
141  if (db>0)
142  Error("cuikatlastrrt does not deal with bifurcations (yet)");
143 
144  /*Read the world/cuik from file*/
145  CS_WD_INIT(&parameters,arg[1],&world);
146 
147  /* Read samples */
148  #if (EXPLORATION_RRT)
149  nvs=ReadOneSample(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&world),&s1);
150  NEW(s2,nvs,double);
151  memcpy(s2,s1,sizeof(double)*nvs);
152  #else
153  nvs=ReadTwoSamples(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&world),&s1,&s2);
154  #endif
155 
156  /* Random seed initialization */
157  t=time(NULL); /* Get the time at which input files have been read */
158  ri=(unsigned int)t;
159  //ri=1532025502;
160  randomSet(ri);
161  fprintf(stderr,"Random seed : %u\n",ri);
162 
163  /* Start the process to connect the two samples */
164  InitAverages(nRepetitions,TRUE,TRUE,NO_UINT,&averages);
165 
166  for(it=0;it<nRepetitions;it++)
167  {
168  /* Initialize the atlas */
169  InitAtlasRRT(&parameters,FALSE/*parallel*/,s1,ONE_TREE,FALSE,s2,&world,&atlasrrt);
170  fprintf(stderr,"************************************************\n");
171 
172  /* Define the path using the atlas */
173  connected=AtlasTRRT(&parameters,s2,
174  &planningTime,
175  &pl,&pc,&ns,&path,CS_WD_COST_FN(&world),
176  CS_WD_COST_PTR(&world),arst,&atlasrrt);
177 
178  /* Save the results (only if one shot execution) */
179  if (nRepetitions==1)
180  {
181  if (connected)
182  SaveSamples(arg[1],FALSE,nvs,ns,path);
183 
184  SaveAtlasRRT(&parameters,arg[1],&atlasrrt);
185  }
186 
187  /* Summarize and release allocated objects for this repetition*/
188 
189  if ((EXPLORATION_RRT)||(connected))
190  {
191  NewSuccesfulExperiment(planningTime,AtlasRRTMemSize(&atlasrrt),pl,pc,
192  (double)GetAtlasRRTNumCharts(&atlasrrt),
193  (double)GetAtlasRRTNumNodes(&atlasrrt),
194  NULL,NULL,
195  &averages);
196  DeleteSamples(ns,path);
197  }
198  else
199  fprintf(stderr," Execution failed (%f sec)\n",planningTime);
200 
201  DeleteAtlasRRT(&atlasrrt);
202 
203  fprintf(stderr,"Execution compleated %u/%u\n",it+1,nRepetitions);
204  }
205 
206  /* Print statistics about the execution (only if many iterations) */
207  if (nRepetitions>1)
208  {
209  PrintAveragesHeader(stderr,argc,arg,&averages);
210 
211  fprintf(stderr,"%% **************************************************\n");
212  fprintf(stderr,"Random seed : %u\n",ri);
213  fprintf(stderr," Random seed : %u\n",ri);
214  PrintAtlasRRTDefines(stderr);
215  PrintParameters(stderr,&parameters);
216 
217  #if (GET_ATLASRRT_STATISTICS)
218  PrintAtlasRRTStatistics(NULL,arst);
220  free(arst);
221  #endif
222 
223  PrintAverages(stderr,&averages);
224 
225  fprintf(stderr,"%% **************************************************\n");
226  }
227 
228  /* Release memory */
229  DeleteAverages(&averages);
230 
231  /* Release memory */
232  free(s1);
233  free(s2);
234 
235  DeleteParameters(&parameters);
236 
237  CS_WD_DELETE(&world);
238 
239  DeleteFileName(&fparam);
240  }
241  else
242  {
243  fprintf(stderr," Wrong number of parameters.\n");
244  fprintf(stderr," Use:\n");
245  fprintf(stderr," cuikatlastrrt <problem filename>.%s [num Repetitions]\n",CS_WD_EXT);
246  fprintf(stderr," where <problem filename> the equations/world description\n");
247  fprintf(stderr," <num Repetitions> experiment repetitions to gather statistics\n");
248  fprintf(stderr," This is optional.\n");
249  fprintf(stderr," (the '.%s' extension is not required)\n",CS_WD_EXT);
250  }
251  return(EXIT_SUCCESS);
252 }
253