cuikbioatlastrrt.c
Go to the documentation of this file.
1 
2 #include "bioworld.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 
75 int main(int argc, char **arg)
76 {
77  if (argc>1)
78  {
79  #if (ATLAS_ON_CUIKSYSTEM)
80  Error("cuikbioatlastrrt can ony operate on worlds");
81  #else
82  TBioWorld bioWorld; /* The molecular information. */
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  TAtlasBase ba;
106 
107  unsigned int db;
108 
109  TAtlasRRTStatistics *arst;
110 
111  #if (EXPLORATION_RRT)
112  nRepetitions=1;
113  #else
114  if (argc>2)
115  {
116  nRepetitions=atoi(arg[2]);
117  if (nRepetitions==0)
118  Error("The repetition parameter for cuikbioatlastrrt is wrong");
119  }
120  else
121  nRepetitions=1;
122  #endif
123 
124  if ((nRepetitions>1)&&(GET_ATLASRRT_STATISTICS))
125  Error("To get meaninful statistics results, please set GET_ATLASRRT_STATISTICS to 0");
126 
127  if ((nRepetitions>1)&&(ATLASRRT_VERBOSE))
128  Error("To get meaninful statistics results, please set ATLASRRT_VERBOSE to 0");
129 
130  if ((GET_ATLASRRT_STATISTICS)&&(nRepetitions>1))
131  {
132  NEW(arst,1,TAtlasRRTStatistics);
134  }
135  else
136  arst=NULL;
137 
138  /*Init parameters*/
139  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
140  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
141  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
142 
143  db=(unsigned int)GetParameter(CT_DETECT_BIFURCATIONS,&parameters);
144  if (db>0)
145  Error("cuikatlastrrt does not deal with bifurcations (yet)");
146 
147  /*Read the bio-information from file*/
148  InitBioWorld(&parameters,arg[1],NO_UINT,&s1,&bioWorld);
149  free(s1);
150  CS_WD_FROM_WORLD(BioWorldWorld(&bioWorld),&ba);
151 
152  /* Read the goal sample */
153  #if (EXPLORATION_RRT)
154  nvs=ReadOneSample(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&ba),&s1);
155  NEW(s2,nvs,double);
156  memcpy(s2,s1,sizeof(double)*nvs);
157  #else
158  nvs=ReadTwoSamples(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&ba),&s1,&s2);
159  #endif
160 
161  /* Random seed initialization */
162  t=time(NULL); /* Get the time at which input files have been read */
163  ri=(unsigned int)t;
164  randomSet(ri);
165  fprintf(stderr,"Random seed : %u\n",ri);
166 
167  /* Start the process to connect the two samples */
168  InitAverages(nRepetitions,TRUE,TRUE,NO_UINT,&averages);
169 
170  for(it=0;it<nRepetitions;it++)
171  {
172  /* Initialize the atlas */
173  fprintf(stderr,"************************************************\n");
174  InitAtlasRRT(&parameters,FALSE/*parallel*/,s1,ONE_TREE,FALSE,s2,&ba,&atlasrrt);
175 
176  /* Define the path using the atlas */
177  connected=AtlasTRRT(&parameters,s2,
178  &planningTime,
179  &pl,&pc,&ns,&path,BioWorldEnergy,
180  (void *)&bioWorld,arst,&atlasrrt);
181 
182  /* Save the results (only if one shot execution) */
183  if (nRepetitions==1)
184  {
185  if (connected)
186  SaveSamples(arg[1],FALSE,nvs,ns,path);
187 
188  SaveAtlasRRT(&parameters,arg[1],&atlasrrt);
189  }
190 
191  /* Summarize and release allocated objects for this repetition*/
192 
193  if ((EXPLORATION_RRT)||(connected))
194  {
195  NewSuccesfulExperiment(planningTime,AtlasRRTMemSize(&atlasrrt),pl,pc,
196  (double)GetAtlasRRTNumCharts(&atlasrrt),
197  (double)GetAtlasRRTNumNodes(&atlasrrt),
198  NULL,NULL,
199  &averages);
200  DeleteSamples(ns,path);
201  }
202  else
203  fprintf(stderr," Execution failed (%f sec)\n",planningTime);
204 
205  DeleteAtlasRRT(&atlasrrt);
206 
207  fprintf(stderr,"Execution compleated %u/%u\n",it+1,nRepetitions);
208  }
209 
210  /* Print statistics about the execution (only if many iterations) */
211  if (nRepetitions>1)
212  {
213  PrintAveragesHeader(stderr,argc,arg,&averages);
214 
215  fprintf(stderr,"%% **************************************************\n");
216  fprintf(stderr,"Random seed : %u\n",ri);
217  fprintf(stderr,"GlobalCurv: %u Tree_ATLAS: %u\n",
219  PrintParameters(stderr,&parameters);
220 
221  #if (GET_ATLASRRT_STATISTICS)
222  PrintAtlasRRTStatistics(NULL,arst);
224  free(arst);
225  #endif
226 
227  PrintAverages(stderr,&averages);
228 
229  fprintf(stderr,"%% **************************************************\n");
230  }
231 
232  /* Release memory */
233  DeleteAverages(&averages);
234 
235  /* Release memory */
236  free(s1);
237  free(s2);
238 
239  DeleteParameters(&parameters);
240  DeleteBioWorld(&bioWorld);
241 
242  DeleteFileName(&fparam);
243  #endif
244  }
245  else
246  {
247  fprintf(stderr," Wrong number of parameters.\n");
248  fprintf(stderr," Use:\n");
249  fprintf(stderr," cuikbioatlastrrt <problem filename>.world [num Repetitions]\n");
250  fprintf(stderr," where <problem filename>.pdb the equations/world description\n");
251  fprintf(stderr," <num Repetitions> experiment repetitions to gather statistics\n");
252  fprintf(stderr," This is optional.\n");
253  fprintf(stderr," The '.pab' extension is required\n");
254  fprintf(stderr," All the extensions managed by OpenBabel can be used\n");
255  }
256  return(EXIT_SUCCESS);
257 }
258