cuikminimize.c
Go to the documentation of this file.
1 #include "world.h"
2 #include "atlas.h"
3 #include "filename.h"
4 #include "samples.h"
5 #include "error.h"
6 #include "parameters.h"
7 
8 #include <stdlib.h>
9 #include <string.h>
10 #include <time.h>
11 
63 int main(int argc, char **arg)
64 {
65  if (argc>1)
66  {
67  Tworld world; /* The tenegrity description. */
68  Tatlas atlas; /* The atlas defined during minimization. */
69  Tparameters parameters; /* Parameters used in the Cuik process. */
70 
71  Tfilename fparam;
72  Tfilename fatlas;
73 
74  double *s1; /* Starting point for the minimization. */
75 
76  unsigned int maxIterations;
77 
78  TAtlasBase ab;
79 
80  /*Init parameters*/
81  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
82  fprintf(stderr,"Reading parameters from : %s\n",GetFileFullName(&fparam));
83  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
84 
85  /*Init the world (tensegrity only)*/
86  if (!InitTensegrityFromFile(&parameters,arg[1],&world))
87  Error("Can not open the tensegrity file");
88  CS_WD_FROM_WORLD(&world,&ab);
89 
90  /* Read the start sample */
91  ReadOneSample(&parameters,arg[1],CS_WD_GET_NUM_SYSTEM_VARS(&ab),&s1);
92 
93  if (argc>2)
94  {
95  maxIterations=atoi(arg[2]);
96  if (maxIterations==0)
97  Error("Wrong maximum number of iterations");
98  }
99  else
100  maxIterations=1000;
101  fprintf(stderr,"Number of iterations : %u\n",maxIterations);
102 
103  /* Minimize */
104  MinimizeOnAtlas(&parameters,arg[1],s1,&ab,maxIterations,
107  (void *)(&world),&atlas);
108 
109 
110  /* Save the results (the tracked paths are already saved in MinimizeOnAtlas) */
111  CreateFileName(NULL,arg[1],NULL,ATLAS_EXT,&fatlas);
112  fprintf(stderr,"Writing atlas to : %s\n",GetFileFullName(&fatlas));
113  SaveAtlas(&parameters,&fatlas,&atlas);
114 
115  /* Release memory */
116  free(s1);
117  DeleteAtlas(&atlas);
118  DeleteParameters(&parameters);
119  DeleteWorld(&world);
120 
121  DeleteFileName(&fparam);
122  DeleteFileName(&fatlas);
123  }
124  else
125  {
126  fprintf(stderr," Wrong number of parameters.\n");
127  fprintf(stderr," Use:\n");
128  fprintf(stderr," cuikminimize <problem filename>.tens [max iterations]\n");
129  fprintf(stderr," where <problem filename>.tens contains the tensegrity description\n");
130  fprintf(stderr," [max iterations] is the optional maximum number of iterations\n");
131  fprintf(stderr," The default is 1000\n");
132  fprintf(stderr," The extension for the problem file (ex. tens) is not required.\n");
133  }
134  return(EXIT_SUCCESS);
135 }
136 
Data structure to hold the information about the name of a file.
Definition: filename.h:271
Definition of the Tfilename type and the associated functions.
void DeleteAtlas(Tatlas *a)
Destructor.
Definition: atlas.c:4634
void Error(const char *s)
General error function.
Definition: error.c:80
boolean MinimizeOnAtlas(Tparameters *pr, char *fname, double *p, TAtlasBase *w, unsigned int maxSteps, double(*costF)(Tparameters *, boolean, double *, void *), void(*costG)(Tparameters *, boolean, double *, double **, void *), void *costData, Tatlas *a)
Gradient minimization on an manifold.
Definition: atlas.c:3153
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:132
All the necessary information to generate equations for mechanisms.
Definition: world.h:229
Definition of the Tworld type and the associated functions.
void DeleteWorld(Tworld *w)
Destructor.
Definition: world.c:3952
int main(int argc, char **arg)
Main body of the cuikminimize application.
Definition: cuikminimize.c:63
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:200
A table of parameters.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
void WorldForceField(Tparameters *p, boolean simp, double *sol, double **g, void *w)
Evaluates the gradient of the potential energy of a configuration.
Definition: world.c:2722
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.
boolean InitTensegrityFromFile(Tparameters *p, char *fn, Tworld *w)
Constructor.
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
A atlas on a manifold.
Definition: atlas.h:289
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:294
void SaveAtlas(Tparameters *pr, Tfilename *fname, Tatlas *a)
Stores the atlas information on a file.
Definition: atlas.c:3946
#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
Definition of the Tparameters type and the associated functions.
double WorldPotentialEnergy(Tparameters *p, boolean simp, double *sol, void *w)
Evaluates the potential energy of a configuration.
Definition: world.c:2680
unsigned int ReadOneSample(Tparameters *p, char *fname, unsigned int nvs, double **s)
Reads one sample from a file.
Definition: samples.c:2772