cuikatlas.c
Go to the documentation of this file.
1 #include "world.h"
2 #include "parameters.h"
3 
4 #include "defines.h"
5 #include "error.h"
6 #include "filename.h"
7 #include "atlas.h"
8 #include "random.h"
9 #include "geom.h"
10 #include "samples.h"
11 
12 #include <stdlib.h>
13 #include <time.h>
14 
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  Tfilename fatlas;
87 
88  double *s1; /* One point on the manifold (values only for the system variables). */
89 
90  Tatlas atlas;
91  Tstatistics st;
92 
93  unsigned int ri;
94 
95  if (argc>1)
96  {
97  /*Init parameters*/
98  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
99  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
100  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
101 
102  /*Read the world/cuik from file*/
103  CS_WD_INIT(&parameters,arg[1],&world);
104 
105  /* Read start sample */
106  ReadOneSample(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&world),&s1);
107 
108  /* Random seed initialization */
109  ri=(unsigned int)time(NULL);
110  //ri=1424688164;
111  randomSet(ri);
112 
113  fprintf(stderr,"Random seed : %u\n",ri);
114 
115  /* The statistics here are just used to compute execution time.
116  In some cases, we use parallel atlas construction. Then
117  CPU time accumulates the time for all the used CPUs, which
118  is significantly larger than the real execution time.
119  Wall clock time has the problem of also accumulating the
120  time of concurrent processes. */
121  #ifdef _OPENMP
122  InitStatistics(2,0,&st); /* just to force wall clock time */
123  #else
124  InitStatistics(0,0,&st); /* use real cpu time */
125  #endif
126 
127  /* Define the atlas */
128  BuildAtlasFromPoint(&parameters,s1,FALSE,&world,&atlas);
129 
130  fprintf(stderr,"Atlas completed.\n");
131  fprintf(stderr,"Elapsed time %f\n", GetElapsedTime(&st));
132 
133  DeleteStatistics(&st);
134 
135  /* Save the results */
136  CreateFileName(NULL,arg[1],NULL,ATLAS_EXT,&fatlas);
137  fprintf(stderr,"Writing atlas to : %s\n",GetFileFullName(&fatlas));
138  SaveAtlas(&parameters,&fatlas,&atlas);
139  DeleteAtlas(&atlas);
140  DeleteFileName(&fatlas);
141 
142  /* Release memory */
143  free(s1);
144 
145  DeleteParameters(&parameters);
146 
147  CS_WD_DELETE(&world);
148 
149  DeleteFileName(&fparam);
150  }
151  else
152  {
153  fprintf(stderr," Wrong number of parameters.\n");
154  fprintf(stderr," Use:\n");
155  fprintf(stderr," cuikatlas <problem filename>.%s \n",CS_WD_EXT);
156  fprintf(stderr," where <problem filename> the equations/world description\n");
157  fprintf(stderr," (the '.%s' extension is not required)\n",CS_WD_EXT);
158  }
159  return(EXIT_SUCCESS);
160 }
161