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=1405333052;
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 compleated.\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 
Definition of basic functions.
#define FALSE
FALSE.
Definition: boolean.h:30
Data structure to hold the information about the name of a file.
Definition: filename.h:248
void InitStatistics(unsigned int np, double v, Tstatistics *t)
Constructor.
Definition: statistics.c:21
Definition of the Tfilename type and the associated functions.
void DeleteAtlas(Tatlas *a)
Destructor.
Definition: atlas.c:4561
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:131
#define CS_WD_DELETE(wcs)
Destructor of the equation structure.
Definition: wcs.h:500
Definition of the Tworld type and the associated functions.
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
#define ATLAS_EXT
File extension for files storing atlas.
Definition: filename.h:199
Definitions of constants and macros used in several parts of the cuik library.
Statistics associated with a solving process.
Definition: statistics.h:28
A table of parameters.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
void InitParametersFromFile(char *file, Tparameters *p)
Constructor from a file.
Definition: parameters.c:51
Type defining the equations on which the atlas is defined.
Definition: wcs.h:30
Definition of an atlas on a manifold.
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
int main(int argc, char **arg)
Main body of the cuikatlas application.
Definition: cuikatlas.c:80
A atlas on a manifold.
Definition: atlas.h:289
#define CS_WD_EXT
Possible extensions for the equation files.
Definition: wcs.h:48
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:295
void SaveAtlas(Tparameters *pr, Tfilename *fname, Tatlas *a)
Stores the atlas information on a file.
Definition: atlas.c:3842
#define CS_WD_INIT(pr, name, wcs)
Initializes the equations from a file.
Definition: wcs.h:89
#define CS_WD_GET_NUM_SYSTEM_VARS(wcs)
Gets the number of system variables.
Definition: wcs.h:250
Auxiliary functions to deal with sets of samples.
Definition of basic randomization functions.
double GetElapsedTime(Tstatistics *t)
Elapsed time.
Definition: statistics.c:92
Definition of the Tparameters type and the associated functions.
void DeleteStatistics(Tstatistics *t)
Destructor.
Definition: statistics.c:274
unsigned int ReadOneSample(Tparameters *p, char *fname, unsigned int nvs, double **s)
Reads one sample from a file.
Definition: samples.c:1216
void BuildAtlasFromPoint(Tparameters *pr, double *p, boolean simpleChart, TAtlasBase *w, Tatlas *a)
Defines an atlas from a given point.
Definition: atlas.c:2919
void randomSet(unsigned int seed)
Sets the random seed.
Definition: random.c:25