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,"GlobalNN: %u 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 
Definition of the combination of an atlas with a RRT.
Definition of basic functions.
#define FALSE
FALSE.
Definition: boolean.h:30
void DeleteBioWorld(TBioWorld *bw)
Destructor.
Definition: bioworld.c:1924
double BioWorldEnergy(Tparameters *p, boolean simp, double *conformation, void *bw)
Computes the energy of a given configuration.
Definition: bioworld.c:1902
void PrintParameters(FILE *f, Tparameters *p)
Prints a parameter set.
Definition: parameters.c:181
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
Data structure to hold the information about the name of a file.
Definition: filename.h:271
void NewSuccesfulExperiment(double t, unsigned int mem, double pl, double pc, unsigned int nc, unsigned int ns, double *time, double *cost, Taverages *av)
Adds data of a new experiment.
Definition: averages.c:75
#define USE_ATLAS_TREE
Whether to use a binary tree to search for neighbouring charts.
Definition: atlas.h:78
boolean AtlasTRRT(Tparameters *pr, double *pg, double *time, double *pl, double *pc, unsigned int *ns, double ***path, double(*costF)(Tparameters *, boolean, double *, void *), void *costData, TAtlasRRTStatistics *str, Tatlasrrt *ar)
Extends a Atlas-TRRT until we reach a targed point.
Definition: atlasrrt.c:4688
Definition of the Tfilename type and the associated functions.
#define ONE_TREE
One of the modes for the RRT.
Definition: rrt.h:132
void DeleteAtlasRRT(Tatlasrrt *ar)
Destructor.
Definition: atlasrrt.c:6206
#define TRUE
TRUE.
Definition: boolean.h:21
void InitAtlasRRTStatistics(TAtlasRRTStatistics *arst)
Init the Atlas RRT statistics.
Definition: atlasrrt.c:553
void Error(const char *s)
General error function.
Definition: error.c:80
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:132
void SaveSamples(char *fname, char *suffix, unsigned int nvs, unsigned int ns, double **path)
Saves a set of samples to a file.
Definition: samples.c:2879
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
void PrintAverages(FILE *f, Taverages *av)
Prints the averages of a set of experiments.
Definition: averages.c:170
void PrintAveragesHeader(FILE *f, int argc, char **arg, Taverages *av)
Prints a header to the averages results.
Definition: averages.c:149
unsigned int AtlasRRTMemSize(Tatlasrrt *ar)
Memory used by a given atlasRRT.
Definition: atlasrrt.c:6066
unsigned int ReadTwoSamples(Tparameters *p, char *fname, unsigned int nvs, double **s1, double **s2)
Reads two samples from a file.
Definition: samples.c:2803
Definitions of constants and macros used in several parts of the cuik library.
#define ATLASRRT_GLOBAL_NN
Set to 1 if nearest neighbours are searched without using the chart relations.
Definition: atlasrrt.h:83
Auxiliary functions to deal averages of path planner executions.
boolean InitBioWorld(Tparameters *p, char *filename, unsigned int maxAtomsLink, double **conformation, TBioWorld *bw)
Initializes a world form a biomolecule.
Definition: bioworld.c:1394
A table of parameters.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
void DeleteAtlasRRTStatistics(TAtlasRRTStatistics *arst)
Destructor.
Definition: atlasrrt.c:973
A bridge between world structures and biological information.
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 a local chart on a manifold.
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
#define EXPLORATION_RRT
Select between exploration and goal driven RRT.
Definition: rrt.h:98
unsigned int GetAtlasRRTNumCharts(Tatlasrrt *ar)
Number of charts in the AtlasRRT.
Definition: atlasrrt.c:5794
#define NO_UINT
Used to denote an identifier that has not been initialized.
Definition: defines.h:435
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:294
Statistics on the AtlasRRT constrution.
Definition: atlasrrt.h:109
Structure to store expeeriment results.
Definition: averages.h:32
#define ATLASRRT_VERBOSE
Vebosity of the AtlasRRT operations.
Definition: atlasrrt.h:41
Structure with the molecular and the mechanical information.
Definition: bioworld.h:28
RRT with an atlas for sampling.
Definition: atlasrrt.h:203
double GetParameter(unsigned int n, Tparameters *p)
Gets the value for a particular parameter.
Definition: parameters.c:93
int main(int argc, char **arg)
Main body of the cuikbioatlastrrt application.
#define CS_WD_GET_NUM_SYSTEM_VARS(wcs)
Gets the number of system variables.
Definition: wcs.h:264
Auxiliary functions to deal with sets of samples.
#define CS_WD_FROM_WORLD(ptr, wcs)
Initializes the equations from a world structure.
Definition: wcs.h:108
#define CT_DETECT_BIFURCATIONS
TRUE (or 1) if bifurcation must be detected.
Definition: parameters.h:468
#define GET_ATLASRRT_STATISTICS
Set this to one to gather statistics of AtlasRRT construction.
Definition: atlasrrt.h:49
void InitAtlasRRT(Tparameters *pr, boolean parallel, double *ps, unsigned int mode, boolean graph, double *pg, TAtlasBase *w, Tatlasrrt *ar)
Defines a Atlas-RRT from a given point.
Definition: atlasrrt.c:4114
Definition of basic randomization functions.
#define GET_ATLASRRT_GLOBAL_CURV_CHECK
Set this to one to check the global curvature tolerences between charts.
Definition: atlasrrt.h:91
void DeleteAverages(Taverages *av)
Deletes the space used by a set of averages.
Definition: averages.c:263
void DeleteSamples(unsigned int ns, double **path)
Deletes the space used by a set of samples.
Definition: samples.c:3159
Definition of the Tparameters type and the associated functions.
unsigned int GetAtlasRRTNumNodes(Tatlasrrt *ar)
Number of nodes in the AtlasRRT.
Definition: atlasrrt.c:5789
Tworld * BioWorldWorld(TBioWorld *bw)
Returns a pointer to the world generated from the bio-information.
Definition: bioworld.c:1807
void InitAverages(unsigned int m, boolean useCharts, boolean useSamples, unsigned int maxIt, Taverages *av)
Initializes a set of averages.
Definition: averages.c:21
unsigned int ReadOneSample(Tparameters *p, char *fname, unsigned int nvs, double **s)
Reads one sample from a file.
Definition: samples.c:2772
void PrintAtlasRRTStatistics(Tatlasrrt *ar, TAtlasRRTStatistics *arst)
Prints the summary of atlasRRT statistics.
Definition: atlasrrt.c:766
void SaveAtlasRRT(Tparameters *pr, char *prefix, Tatlasrrt *ar)
Stores the Atlas-RRT information on a file.
Definition: atlasrrt.c:6076
void randomSet(unsigned int seed)
Sets the random seed.
Definition: random.c:25