cuiksmoothpath.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 "atlas.h"
9 #include "samples.h"
10 #include "random.h"
11 
12 #include <stdlib.h>
13 
75 int main(int argc, char **arg)
76 {
77  TAtlasBase world; /* The set of mechanism and obstacles. */
78  Tparameters parameters; /* Parameters used in the Cuik process. */
79 
80  Tfilename fparam;
81  Tfilename fpath;
82 
83  /* input path */
84  unsigned int nvs,ns;
85  double **path;
86 
87  /* smoothed path */
88  unsigned int sns;
89  double **spath;
90  unsigned int mode;
91  boolean parallel;
92  unsigned int numIterations;
93 
94  unsigned int ri;
95  time_t t;
96 
97  if (argc>=2)
98  {
99  /*Init parameters*/
100  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
101  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
102  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
103 
104  /*Read the world from file*/
105  CS_WD_INIT(&parameters,arg[1],&world);
106 
107  t=time(NULL); /* Get the time at which input files have been read */
108  ri=(unsigned int)t;
109  ri=1405498615;
110  randomSet(ri);
111  fprintf(stderr,"Random seed : %u\n",ri);
112 
113  mode=SMOOTH_SHORTCUT;
114  if (argc>=3)
115  {
116  /* Select the smoothing mode */
117  switch(arg[2][0])
118  {
119  case 'G':
120  case 'g':
121  mode=SMOOTH_GRADIENT;
122  break;
123  case 'R':
124  case 'r':
125  mode=SMOOTH_RANDOM;
126  break;
127  case 'S':
128  case 's':
129  mode=SMOOTH_SHORTCUT;
130  break;
131  default:
132  Error("Undefined smooth method");
133  }
134  }
135  numIterations=2;
136  if (argc>=4)
137  numIterations=atoi(arg[3]);
138  if (numIterations==0)
139  numIterations=2;
140 
141  parallel=FALSE;
142  if (argc>=5)
143  parallel=atoi(arg[4]);
144 
145  CreateFileName(NULL,arg[1],"_path",SOL_EXT,&fpath);
146 
147  if (LoadSamples(fpath,&nvs,&ns,&path))
148  {
149  SmoothSamples(&parameters,parallel,mode,numIterations,ns,path,&sns,&spath,&world);
150 
151  SaveSamples(arg[1],TRUE,nvs,sns,spath);
152 
153  DeleteSamples(ns,path);
154  DeleteSamples(sns,spath);
155  }
156  else
157  Error("Could not read the input path file");
158 
159  DeleteParameters(&parameters);
160  CS_WD_DELETE(&world);
161 
162  DeleteFileName(&fparam);
163  DeleteFileName(&fpath);
164  }
165  else
166  {
167  fprintf(stderr," Wrong number of parameters.\n");
168  fprintf(stderr," Use:\n");
169  fprintf(stderr," cuiksmoothpath <problem filename> <mode> <iterations> <parallel>\n");
170  fprintf(stderr," where <problem filename> is the base name for the problem files.\n");
171  fprintf(stderr," <mode> [optional] is the algorithm to use: RANDOM, GRADIENT, or SHORTCUT, The defatul is SHORTCUT.\n");
172  fprintf(stderr," <itetarions> [optional] is the maximum number of iterations (scaled by the number of steps in the intput path). The default is 2.\n");
173  fprintf(stderr," <parallel> [optional] 1 if the smooth has to be exectued in parallel. The default is 0.\n");
174 
175  }
176  return(EXIT_SUCCESS);
177 }
178 
#define FALSE
FALSE.
Definition: boolean.h:30
Data structure to hold the information about the name of a file.
Definition: filename.h:248
#define SMOOTH_GRADIENT
One of the possible smoothing methods.
Definition: samples.h:57
Definition of the Tfilename type and the associated functions.
#define TRUE
TRUE.
Definition: boolean.h:21
void Error(const char *s)
General error function.
Definition: error.c:80
#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
int main(int argc, char **arg)
Main body of the cuiksmoothpath application.
Definition of the Tworld type and the associated functions.
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
void SmoothSamples(Tparameters *pr, boolean parallel, int mode, unsigned int maxIterations, unsigned int ns, double **path, unsigned int *sns, double ***spath, TAtlasBase *w)
Path smoothing.
Definition: samples.c:1033
Definitions of constants and macros used in several parts of the cuik library.
#define SMOOTH_SHORTCUT
One of the possible smoothing methods.
Definition: samples.h:67
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
#define SOL_EXT
File extension for solution files.
Definition: filename.h:137
#define SMOOTH_RANDOM
One of the possible smoothing methods.
Definition: samples.h:47
boolean LoadSamples(Tfilename fname, unsigned int *nvs, unsigned int *ns, double ***path)
Reads a set of samples from file.
Definition: samples.c:1352
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:295
void SaveSamples(char *fname, boolean smooth, unsigned int nvs, unsigned int ns, double **path)
Saves a set of samples to a file.
Definition: samples.c:1318
#define CS_WD_INIT(pr, name, wcs)
Initializes the equations from a file.
Definition: wcs.h:89
Auxiliary functions to deal with sets of samples.
Definition of basic randomization functions.
void DeleteSamples(unsigned int ns, double **path)
Deletes the space used by a set of samples.
Definition: samples.c:1495
Definition of the Tparameters type and the associated functions.
void randomSet(unsigned int seed)
Sets the random seed.
Definition: random.c:25