cuikccrrt.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 "rrt.h"
9 #include "random.h"
10 #include "geom.h"
11 #include "samples.h"
12 #include "averages.h"
13 
14 #include <stdlib.h>
15 #include <string.h>
16 #include <time.h>
17 
83 int main(int argc, char **arg)
84 {
85  TAtlasBase world; /* The set of mechanism and obstacles. */
86  Tparameters parameters; /* Parameters used in the Cuik process. */
87 
88  Tfilename fparam;
89 
90  double *s1,*s2; /* Origin/goal of the RRT. */
91 
92  unsigned int nvs;
93 
94  Trrt rrt;
95 
96  boolean connected;
97  double pl;
98  unsigned int ns;
99  double **path;
100 
101  double planningTime;
102 
103  unsigned int it,nRepetitions;
104  Taverages averages;
105 
106  unsigned int ri;
107  time_t t;
108 
109  TRRTStatistics *rst;
110 
111  if (argc>1)
112  {
113  if (argc>2)
114  {
115  nRepetitions=atoi(arg[2]);
116  if (nRepetitions==0)
117  Error("Second parameter for cuikccrrt is wrong");
118  }
119  else
120  nRepetitions=1;
121 
122  if ((nRepetitions>1)&&((RRT_VERBOSE)||(GET_RRT_STATISTICS)))
123  Warning("To get accurate execution time statistics, set RRT_VERBOSE and GET_RRT_STATISTICS to 0");
124 
125  if ((GET_RRT_STATISTICS)&&(nRepetitions>1))
126  {
127  NEW(rst,1,TRRTStatistics);
128  InitRRTStatistics(rst);
129  }
130  else
131  rst=NULL;
132 
133  /*Init parameters*/
134  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
135  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
136  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
137 
138  if (GetParameter(CT_DYNAMICS,&parameters)>0)
139  Error("cuikccrrt do not work for problems with dynamics");
140 
141  /*Read the world from file*/
142  CS_WD_INIT(&parameters,arg[1],&world);
143 
144  /* Read samples */
145  nvs=ReadTwoSamples(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&world),&s1,&s2);
146 
147  /* Random seed initialization */
148  t=time(NULL); /* Get the time at which input files have been read */
149  ri=(unsigned int)t;
150  randomSet(ri);
151  fprintf(stderr,"Random seed : %u\n",ri);
152 
153  /* Start the process to connect the two samples */
154  InitAverages(nRepetitions,FALSE,TRUE,NO_UINT,&averages);
155 
156  for(it=0;it<nRepetitions;it++)
157  {
158  /* Init a one-directional RRT (one-directional despite the value of BI_RRT parameter) */
159  InitRRT(&parameters,FALSE,FALSE,s1,ONE_TREE,FALSE,s2,nvs,0,&world,&rrt);
160  fprintf(stderr,"**************************************************\n");
161 
162  /* Try to connect the goal with a tree from the start */
163  connected=ccRRT(&parameters,s2,
164  &planningTime,
165  &pl,&ns,&path,
166  rst,&rrt);
167 
168  /* Save the results (only if one shot execution) */
169  if (nRepetitions==1)
170  {
171  Tfilename frrt;
172 
173  if (connected)
174  SaveSamples(arg[1],FALSE,nvs,ns,path);
175 
176  CreateFileName(NULL,arg[1],NULL,RRT_EXT,&frrt);
177  fprintf(stderr,"Writing RRT to : %s\n",GetFileFullName(&frrt));
178  SaveRRT(&frrt,&rrt);
179  DeleteFileName(&frrt);
180  }
181 
182  /* Summarize and release allocated objects for this repetition*/
183  if (connected)
184  {
185  NewSuccesfulExperiment(planningTime,RRTMemSize(&rrt),pl,0,
186  NO_UINT,
187  (double)GetRRTNumNodes(&rrt),
188  NULL,NULL,
189  &averages);
190  DeleteSamples(ns,path);
191  }
192  else
193  fprintf(stderr," Execution failed (%f sec)\n",planningTime);
194 
195  DeleteRRT(&rrt);
196 
197  fprintf(stderr,"Execution compleated %u/%u\n",it+1,nRepetitions);
198  }
199 
200  /* Print statistics about the execution (only if many iterations) */
201  if (nRepetitions>1)
202  {
203  PrintAveragesHeader(stderr,argc,arg,&averages);
204 
205  fprintf(stderr,"%% **************************************************\n");
206  fprintf(stderr," Random seed : %u\n",ri);
207  PrintRRTDefines(stderr);
208  PrintParameters(stderr,&parameters);
209 
210  #if (GET_RRT_STATISTICS)
211  PrintRRTStatistics(NULL,rst);
212  DeleteRRTStatistics(rst);
213  free(rst);
214  #endif
215 
216  PrintAverages(stderr,&averages);
217 
218  fprintf(stderr,"%% **************************************************\n");
219  }
220 
221  /* Release memory */
222  DeleteAverages(&averages);
223 
224  free(s1);
225  free(s2);
226 
227  DeleteParameters(&parameters);
228 
229  CS_WD_DELETE(&world);
230 
231  DeleteFileName(&fparam);
232  }
233  else
234  {
235  fprintf(stderr," Wrong number of parameters.\n");
236  fprintf(stderr," Use:\n");
237  fprintf(stderr," cuikccrrt <problem filename>.%s [num Repetitions]\n",CS_WD_EXT);
238  fprintf(stderr," where <problem filename> the equations/world description\n");
239  fprintf(stderr," <num Repetitions> experiment repetitions to gather statistics\n");
240  fprintf(stderr," This is optional.\n");
241  fprintf(stderr," (the '.%s' extension is not required)\n",CS_WD_EXT);
242  }
243  return(EXIT_SUCCESS);
244 }
245