statistics.c
Go to the documentation of this file.
1 #include "statistics.h"
2 
3 #include <unistd.h>
4 #include <time.h>
5 
6 
18 /*
19  * Resets the statistics
20  */
21 void InitStatistics(unsigned int np,double v,Tstatistics *t)
22 {
23  t->np=np;
24  t->volume=v;
25  t->s_volume=0.0;
26  t->s_diagonal=0.0;
27 
28  t->n_max_level=0;
29 
30  t->n_processed_boxes=0;
31  t->n_solution_boxes=0;
33  t->n_empty_boxes=0;
34  t->n_splitted_boxes=0;
35 
36  t->n_lost_boxes=0;
37 
38  t->n_box_reductions=0;
39 
40  t->n_errors=0;
41 
42  t->t_init=GetTime(t);
43 }
44 
46 {
47  t_dst->volume=t_src->volume;
48  t_dst->s_volume=t_src->s_volume;
49  t_dst->s_diagonal=t_src->s_diagonal;
50 
51  t_dst->n_max_level=t_src->n_max_level;
52 
54  t_dst->n_solution_boxes=t_src->n_solution_boxes;
56  t_dst->n_empty_boxes=t_src->n_empty_boxes;
57  t_dst->n_splitted_boxes=t_src->n_splitted_boxes;
58 
59  t_dst->n_lost_boxes=t_src->n_lost_boxes;
60 
61  t_dst->n_box_reductions=t_src->n_box_reductions;
62 
63  t_dst->n_errors=t_src->n_errors;
64 
65  t_dst->t_init=t_src->t_init;
66 }
67 
68 /*
69  Auxiliary function to get the time since the current process was
70  started. In a multi-processor environment
71  the result is the number of seconds since
72  the Epoch (this is still useful for counting elapsed times)
73 */
74 double GetTime(Tstatistics *t)
75 {
76  if (t->np>1)
77  return((double)time(NULL));
78  else
79  {
80  double ts;
81  struct tms tm;
82 
83  times(&tm);
84  ts=(double)sysconf(_SC_CLK_TCK); /*tics per second*/
85  return((double)((tm.tms_utime)+(tm.tms_stime)+(tm.tms_cutime)+(tm.tms_cstime))/ts);
86  }
87 }
88 
89 /*
90  Returns the time (in seconds) since the InitStatistics was called
91 */
93 {
94  return(GetTime(t)-t->t_init);
95 }
96 
97 /*
98  Auxiliariy function to get the time at which InitStatistics was called
99 */
101 {
102  return(t->t_init);
103 }
104 
105 /*
106  Auxiliariy function to set the time at which InitStatistics was called
107  This is used when re-starting a process after a crash
108 */
109 void SetInitialTime(double tm,Tstatistics *t)
110 {
111  t->t_init=tm;
112 }
113 
114 /*
115  * To assess the maximum number of boxes in the list of boxes still to be processed
116  */
117 void NewMaxLevel(unsigned int m,Tstatistics *t)
118 {
119  if (m>t->n_max_level)
120  t->n_max_level=m;
121 }
122 
123 /*
124  * To assess the number of processes boxes
125  */
127 {
128  t->n_processed_boxes++;
129 }
130 
131 /*
132  * To assess the number of solution boxes
133  */
134 void NewSolutionBox(boolean validated,double vs,double d,Tstatistics *t)
135 {
136  if (d>t->s_diagonal) t->s_diagonal=d;
137  t->s_volume+=vs;
138  t->n_solution_boxes++;
139  if (validated)
141 }
142 
143 /*
144  * To assess the number of boxes that, after the process of the box,
145  * become emtpy
146  */
148 {
149  t->n_empty_boxes++;
150 }
151 
152 /*
153  * To assess the number of boxes that, after the process of the box,
154  * are splitted
155  */
157 {
158  t->n_splitted_boxes++;
159 }
160 
161 /*
162  * Number of errors in the Reduce Box process
163  *
164  */
166 {
167  t->n_errors++;
168 }
169 
170 /*
171  * Number of boxes send to process that returned too late and that were re-submitted
172 */
174 {
175  t->n_lost_boxes++;
176 }
177 
178 /*
179  * Number of times the function ReduceBox (Trapezoid Clipping) is used
180  */
182 {
183  t->n_box_reductions++;
184 }
185 
187 {
188  return(t->n_box_reductions);
189 }
190 
192 {
193  return(t->n_solution_boxes);
194 }
195 
197 {
198  t->n_box_reductions=0;
199 }
200 
201 void AddNBoxReductions(unsigned int nr,Tstatistics *t)
202 {
203  t->n_box_reductions+=nr;
204 }
205 
206 /*
207  * Prints all the collected statistics
208  */
209 void PrintStatistics(FILE *f,Tstatistics *t)
210 {
211  double tm;
212 
213  tm=GetElapsedTime(t);
214 
215  fprintf(f,"STATITISTICS FOR Cuik:\n\n");
216 
217  fprintf(f,"Volume of the search space: %g\n",t->volume);
218  fprintf(f,"Volume of the solution space: %g\n",t->s_volume);
219  if (t->volume>0.0)
220  fprintf(f," Volume ratio: %5.2f %%\n",t->s_volume/t->volume);
221  fprintf(f,"Max solution diagonal: %g\n",t->s_diagonal);
222 
223  fprintf(f,"Number of processors: %u\n",t->np);
224  fprintf(f,"User time in process: %f seg (%f min)\n",tm,tm/60.0);
225 
226  fprintf(f,"Box level information:\n");
227  fprintf(f," N processed boxes : %6u\n",t->n_processed_boxes);
228  fprintf(f," Max depth : %6u\n",t->n_max_level);
229  fprintf(f," Types of boxes:\n");
230 
231  fprintf(f," N solution boxes: %6u (%u)",t->n_solution_boxes,t->n_validated_solution_boxes);
232  if (t->n_processed_boxes>0)
233  fprintf(f," (%5.2f%%)",(double)t->n_solution_boxes/(double)t->n_processed_boxes*100.0);
234  fprintf(f,"\n");
235 
236  fprintf(f," N empty boxes : %6u ",t->n_empty_boxes);
237  if (t->n_processed_boxes>0)
238  fprintf(f," (%5.2f%%)",(double)t->n_empty_boxes/(double)t->n_processed_boxes*100.0);
239  fprintf(f,"\n");
240 
241  fprintf(f," N bisected boxes: %6u ",t->n_splitted_boxes);
242  if (t->n_processed_boxes>0)
243  fprintf(f," (%5.2f%%)",(double)t->n_splitted_boxes/(double)t->n_processed_boxes*100.0);
244  fprintf(f,"\n");
245 
246  #if (_USE_MPI)
247  fprintf(f," N lost boxes : %6u ",t->n_lost_boxes);
248  if (t->n_processed_boxes>0)
249  fprintf(f," (%5.2f%%)",(double)t->n_lost_boxes/(double)t->n_processed_boxes*100.0);
250  fprintf(f,"\n");
251  #endif
252 
253  fprintf(f," Box Reductions : %6u\n",t->n_box_reductions);
254  fprintf(f," N Errors : %6u \n\n",t->n_errors);
255 
256  fprintf(f,"\n==========================================================================\n\n");
257 }
258 
259 /* saves in binary format */
260 void SaveStatistics(FILE *f,Tstatistics *t)
261 {
262  fwrite(t,sizeof(Tstatistics),1,f);
263 }
264 
265 /* loads from binary file */
266 void LoadStatistics(FILE *f,Tstatistics *t)
267 {
268  fread(t,sizeof(Tstatistics),1,f);
269 }
270 
271 /*
272  * Deletes the statistics structure
273  */
275 {
276 }
void NewMaxLevel(unsigned int m, Tstatistics *t)
Sets a new maximum level.
Definition: statistics.c:117
unsigned int n_lost_boxes
Definition: statistics.h:47
unsigned int GetNBoxReductions(Tstatistics *t)
Gets the number of reduced boxes.
Definition: statistics.c:186
void SaveStatistics(FILE *f, Tstatistics *t)
Saves the statistics to a file in binary format.
Definition: statistics.c:260
void DeleteStatistics(Tstatistics *t)
Destructor.
Definition: statistics.c:274
void NewRBError(Tstatistics *t)
Increases the number of errors when reducing a boxe.
Definition: statistics.c:165
double GetInitialTime(Tstatistics *t)
Initial time.
Definition: statistics.c:100
void InitStatistics(unsigned int np, double v, Tstatistics *t)
Constructor.
Definition: statistics.c:21
double t_init
Definition: statistics.h:30
void AddNBoxReductions(unsigned int nr, Tstatistics *t)
Increases the number of reduced boxes.
Definition: statistics.c:201
void NewEmptyBox(Tstatistics *t)
Increases the number of empty boxes.
Definition: statistics.c:147
double s_volume
Definition: statistics.h:36
unsigned int n_solution_boxes
Definition: statistics.h:42
unsigned int n_processed_boxes
Definition: statistics.h:41
Definition of the Tstatistics type and the associated functions.
void NewBoxReduction(Tstatistics *t)
Increases the number of reduced boxes.
Definition: statistics.c:181
double volume
Definition: statistics.h:35
void NewSplittedBox(Tstatistics *t)
Increases the number of splitted boxes.
Definition: statistics.c:156
double GetElapsedTime(Tstatistics *t)
Elapsed time.
Definition: statistics.c:92
unsigned int n_max_level
Definition: statistics.h:39
void SetInitialTime(double tm, Tstatistics *t)
Sets a new initial time.
Definition: statistics.c:109
unsigned int n_errors
Definition: statistics.h:51
Statistics associated with a solving process.
Definition: statistics.h:28
unsigned int GetNSolutionBoxes(Tstatistics *t)
Gets the number of solution boxes.
Definition: statistics.c:191
void CopyStatistics(Tstatistics *t_dst, Tstatistics *t_src)
Copy constructor.
Definition: statistics.c:45
unsigned int n_empty_boxes
Definition: statistics.h:44
double GetTime(Tstatistics *t)
Curent time.
Definition: statistics.c:74
unsigned int n_validated_solution_boxes
Definition: statistics.h:43
void NewLostBox(Tstatistics *t)
Increases the number of lost boxes.
Definition: statistics.c:173
unsigned int np
Definition: statistics.h:33
double s_diagonal
Definition: statistics.h:37
void ResetNBoxReductions(Tstatistics *t)
Resets the number of reduced boxes.
Definition: statistics.c:196
unsigned int n_splitted_boxes
Definition: statistics.h:45
unsigned int n_box_reductions
Definition: statistics.h:49
void LoadStatistics(FILE *f, Tstatistics *t)
Loads the statistics from a file in binary format.
Definition: statistics.c:266
void PrintStatistics(FILE *f, Tstatistics *t)
Prints the statistics to a file.
Definition: statistics.c:209
void NewSolutionBox(boolean validated, double vs, double d, Tstatistics *t)
Increases the number of solution boxes.
Definition: statistics.c:134
void NewBoxProcessed(Tstatistics *t)
Increases the number of processed boxes.
Definition: statistics.c:126