/home/coin/SVN-release/OS-2.4.0/Couenne/src/cut/sdpcuts/report2.cpp

Go to the documentation of this file.
00001 /* $Id: report2.cpp 508 2011-02-15 21:52:44Z pbelotti $
00002  *
00003  * Name:    report2.cpp
00004  * Author:  Andrea Qualizza
00005  * Purpose: 
00006  *
00007  * This file is licensed under the Eclipse Public License (EPL)
00008  */
00009 
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <string.h>
00013 #include <misc_util.hpp>
00014 #include <OsiSolverInterface.hpp> //defines DBL_MAX
00015 
00016 
00017 //discard time differences below this value
00018 #define MIN_TIME_DIFFERENCE 1.0
00019 #define CMP_TOLERANCE 0.1
00020 
00021 
00023 
00024 #define MAX_INSTANCES 1000
00025 #define SOLUTIONS_DOUBLE_FIELDS 8
00026 #define BOUNDOPTVALUES_DOUBLE_FIELDS 2
00027 #define F_RES_DOUBLE_FIELDS 4
00028 #define F_RES_INT_FIELDS 3
00029 #define F_RES_MAX_ITER 2000
00030 #define F_RES_HEADER_LINES 7
00031 #define TEST_NOT_RUN_STRING "#"
00032 #define F_RES_MULTIPLIER -1.0
00033 
00034 #define INVALID_ENTRY -999999999
00035 
00036 enum BoundOptValuesEntries
00037 {
00038         BOUNDOPT_BOUND = 0,
00039         BOUNDOPT_OPT = 1
00040 };
00041 
00042 enum f_resDoubleEntries
00043 {
00044         F_RES_UBOUND=0,
00045         F_RES_TIME=1,
00046         F_RES_CURRHEUR=2,
00047         F_RES_BESTHEUR=3
00048 };
00049 enum f_resIntEntries
00050 {
00051         F_RES_ITER=0,
00052         F_RES_TOTCONS=1,
00053         F_RES_ITERGENCONS=2
00054 };
00055 
00056 
00057 
00058 
00059 
00060 /***************************************************************************/
00061 
00062 bool doubleEqual(double val1,double val2) {
00063         double a,b;
00064         if (val1 > val2) {
00065                 a = val2;
00066                 b = val1;
00067         } else {
00068                 a = val1;
00069                 b = val2;                       
00070         }
00071         //a<=b
00072         if ((b-CMP_TOLERANCE) <= a)
00073                 return true;
00074         else
00075                 return false;
00076 }
00077 
00078 int doubleCmp(double val1,double val2) {
00079         if (doubleEqual(val1,val2))
00080                 return 0;
00081         if (val1<val2)
00082                 return 1;
00083         else
00084                 return 2;
00085 }
00086 
00087 
00088 
00089 class bounds_opt_values {
00090 private:
00091         int _bound_opt_values_num_instances;
00092         char **_instance_name_lookup;
00093         double **_instance_data;
00094 
00095 public:
00096         bounds_opt_values(const char* filename) {
00097                 _instance_name_lookup = (char**) malloc(sizeof(char*)*MAX_INSTANCES);
00098                 for(int i=0;i<MAX_INSTANCES;i++)
00099                         _instance_name_lookup[i] = (char*) malloc(sizeof(char)*1024);
00100                 _instance_data = (double**) malloc(sizeof(double*)*MAX_INSTANCES);
00101                 for(int i=0;i<MAX_INSTANCES;i++) {
00102                         _instance_data[i] = (double*) malloc(sizeof(double)*BOUNDOPTVALUES_DOUBLE_FIELDS);
00103                 }
00104                 int status;
00105                 status = readBoundsOptValuesFile(filename);
00106                 if (status)
00107                         exit(1);
00108         }
00109 
00110         ~bounds_opt_values() {
00111                 for(int i=0;i<MAX_INSTANCES;i++) {
00112                         free(_instance_name_lookup[i]);
00113                         free(_instance_data[i]);
00114                 }
00115                 free(_instance_name_lookup);
00116                 free(_instance_data);
00117         }
00118 /***********************************************************************/
00119         int getNumInstances() {return _bound_opt_values_num_instances;}
00120 /***********************************************************************/
00121         double getDoubleField(int inst,int field) {return _instance_data[inst][field];}
00122 /***********************************************************************/
00123 /***********************************************************************/
00124 /***********************************************************************/
00125         int instancename2index(char *name) {
00126                 for(int i=0;i<getNumInstances();i++) {
00127                         if(strcmp(name,_instance_name_lookup[i]) == 0)
00128                                 return i;
00129                 }
00130                 return -1;
00131         }
00132 /***********************************************************************/
00133         char *getInstanceName(int inst) {
00134                 if ((inst >= 0)&& (inst <= getNumInstances()))
00135                         return _instance_name_lookup[inst];
00136                 else
00137                         return NULL;
00138         }
00139 /*********************************************************************/
00140         void fprint(FILE *out) {
00141                 for (int i=0;i<getNumInstances();i++) {
00142                         fprintf(out,"%13s\t%10.2f\t%10.2f\n"
00143                                 ,getInstanceName(i)
00144                                 ,getDoubleField(i,BOUNDOPT_BOUND)
00145                                 ,getDoubleField(i,BOUNDOPT_OPT));
00146                 }
00147         }
00148 /***********************************************************************/
00149 private:
00150         int readBoundsOptValuesFile(const char *filename) {
00151                 FILE *_bound_opt_file = fopen(filename,"r");
00152                 if (_bound_opt_file == NULL) {
00153                         printf("Error opening %s. Exiting.\n",filename);
00154                         return 1;
00155                 }
00156                 char line [ 1024 ];
00157                 int linecnt = 0;
00158                 while ( fgets ( line, sizeof line, _bound_opt_file) != NULL ) {
00159                         if (linecnt > 0) {  //skips the first line in the file (header)
00160                                 char *curr;
00161                                 curr = strtok ( line, " \t" );
00162                                 strcpy(_instance_name_lookup[linecnt-1],curr);
00163                                 for (int j=0;j<BOUNDOPTVALUES_DOUBLE_FIELDS;j++) {
00164                                         curr = strtok ( NULL, " \t" );
00165                                         if (curr == NULL) {
00166                                                 printf("readBoundsOptValuesFile::missing field %d line [%d]: %s\n"
00167                                                         ,j,linecnt+1,line);
00168                                                 return 1;
00169                                         }
00170 
00171                                         _instance_data[linecnt-1][j] = atof(curr);
00172                                 }
00173                         }
00174                         linecnt++;
00175                         if (linecnt == MAX_INSTANCES) {
00176                                 printf("readBoundsOptValuesFile::instances limit exceeded [%d]\n",MAX_INSTANCES);
00177                                 return 1;
00178                         }
00179                 }
00180                 _bound_opt_values_num_instances = linecnt-1;
00181                 fclose(_bound_opt_file);
00182                 return 0;
00183         }
00184 
00185 
00186 };
00187 
00188 
00189 /*********************************************************************/
00190 
00191 
00192 
00193 
00194 class dataset {
00195 private:
00196         int *_f_res_iter;
00197         double ***_f_res_double_data;
00198         int ***_f_res_int_data;
00199         char *_f_res_name;
00200         char **_f_res_info; //experiment parameters defined in the f_res file header
00201 
00202         bounds_opt_values *_bov;
00203 
00204         int _num_instances;
00205 
00206 public:
00207         dataset(const char *filename, bounds_opt_values *bovptr) {
00208                 _f_res_name = (char*)malloc(sizeof(char)*256);
00209                 char *name_pos,*last_dot_pos;
00210                 name_pos = strrchr(const_cast <char *> (filename), '/');
00211                 if(name_pos != NULL)
00212                         strcpy(_f_res_name, &(name_pos[1]));
00213                 else
00214                         strcpy(_f_res_name, filename);
00215                 last_dot_pos = strrchr(_f_res_name, '.');
00216                 if(last_dot_pos !=NULL)
00217                         last_dot_pos[0] = '\0';
00218 
00219                 _bov = bovptr;
00220                 _f_res_double_data = (double***) malloc(sizeof(double*)*MAX_INSTANCES);
00221                 _f_res_int_data = (int***) malloc(sizeof(int*)*MAX_INSTANCES);
00222                 _f_res_iter = (int*) malloc(sizeof(double*)*MAX_INSTANCES);
00223                 for (int i=0;i<MAX_INSTANCES;i++) {
00224                         _f_res_double_data[i] = (double**) malloc(sizeof(double)*F_RES_MAX_ITER);
00225                         _f_res_int_data[i] = (int**) malloc(sizeof(int)*F_RES_MAX_ITER);
00226                         for(int k=0;k<F_RES_MAX_ITER;k++) {
00227                                 _f_res_double_data[i][k] = 
00228                                         (double*) malloc(sizeof(double)*F_RES_DOUBLE_FIELDS);
00229                                 _f_res_int_data[i][k] = 
00230                                         (int*) malloc(sizeof(int)*F_RES_INT_FIELDS);
00231                                 for (int j=0;j<F_RES_DOUBLE_FIELDS;j++) {
00232                                         _f_res_double_data[i][k][j] = -DBL_MAX;
00233                                 }
00234                         }
00235                         _f_res_iter[i] = -1;
00236                 }
00237 
00238                 int info_lines = F_RES_HEADER_LINES + 1;
00239                 _f_res_info = (char**) malloc(sizeof(char*)*info_lines);
00240                 for (int i=0;i<info_lines;i++) {
00241                         _f_res_info[i] = (char*) malloc(sizeof(char)*1024);
00242                         _f_res_info[i][0] = '\0';
00243                 }
00244 
00245                 int status;
00246                 status = readF_resFile(filename);
00247                 if (status)
00248                         exit(1);
00249         }
00250 /***********************************************************************/
00251         ~dataset() {
00252                 for (int i=0;i<MAX_INSTANCES;i++) {
00253                         for (int j=0;j<F_RES_MAX_ITER;j++) {
00254                                 free(_f_res_double_data[i][j]);
00255                                 free(_f_res_int_data[i][j]);
00256                         }
00257                         free(_f_res_double_data[i]);
00258                         free(_f_res_int_data[i]);
00259                 }
00260                 free(_f_res_double_data);
00261                 free(_f_res_int_data);
00262                 free(_f_res_name);
00263                 int info_lines = F_RES_HEADER_LINES + 1;
00264                 for (int i=0;i<info_lines;i++)
00265                         free(_f_res_info[i]);
00266                 free(_f_res_info);
00267         }
00268 
00269 /***********************************************************************/
00270         char *getName() {return _f_res_name;}
00271 /***********************************************************************/
00272         int getIter(int inst) {return _f_res_iter[inst];}
00273 /***********************************************************************/
00274         double getDoubleField(int inst,int iter, int field) {return _f_res_double_data[inst][iter][field];}
00275 /***********************************************************************/
00276         int getIntField(int inst,int iter, int field) {return _f_res_int_data[inst][iter][field];}
00277 /***********************************************************************/
00278         void fprintInfo(FILE *out) {
00279                 for(int i=0;i<F_RES_HEADER_LINES;i++)
00280                         fprintf(out,"%s",_f_res_info[i]);
00281         }
00282 /***********************************************************************/
00283         void fprint(FILE* out) {
00284                 for (int i=0;i<_bov->getNumInstances();i++) {
00285                         for (int k=0;k<getIter(i);k++) {
00286                                 fprintf(out,"%13s\t%10.2f\t%3d\t%7.2f\t%5d\t%5d"
00287                                         ,_bov->getInstanceName(i)
00288                                         ,getDoubleField(i,k,F_RES_UBOUND)
00289                                         ,getIntField(i,k,F_RES_ITER)
00290                                         ,getDoubleField(i,k,F_RES_TIME)
00291                                         ,getIntField(i,k,F_RES_TOTCONS)
00292                                         ,getIntField(i,k,F_RES_ITERGENCONS));
00293                                 if (getDoubleField(i,k,F_RES_CURRHEUR) <= -DBL_MAX)
00294                                         fprintf(out,"\t%10s","N/A");
00295                                 else
00296                                         fprintf(out,"\t%10.2f",getDoubleField(i,k,F_RES_CURRHEUR));
00297 
00298                                 if (getDoubleField(i,k,F_RES_BESTHEUR) <= -DBL_MAX)
00299                                         fprintf(out,"\t%10s","N/A");
00300                                 else
00301                                         fprintf(out,"\t%10.2f",getDoubleField(i,k,F_RES_BESTHEUR));
00302                                 fprintf(out,"\n");
00303                         }
00304                 }
00305         }
00306 
00307 /***********************************************************************/
00308         double timeAtBound(int inst,double value) {
00309                 for (int i=0;i<getIter(inst);i++) {
00310                         if (    (doubleCmp(getDoubleField(inst,i,F_RES_UBOUND),value) == 1) ||
00311                                 (doubleCmp(getDoubleField(inst,i,F_RES_UBOUND),value) == 0)) {
00312 //printf("\n f_res%s i=%d bound=%.2f  time=%.2f value=%.2f\n",_f_res_name,i,getDoubleField(inst,i,F_RES_UBOUND),getDoubleField(inst,i,F_RES_TIME),value);
00313                                 return getDoubleField(inst,i,F_RES_TIME);
00314                         }
00315                 }
00316                 return -1.0;
00317         }
00318 /***********************************************************************/
00319         double timeAtLinearizedBound(int inst,double value) {
00320                 double time1=-DBL_MAX;
00321                 double time2=-DBL_MAX;
00322                 double bound1 = -DBL_MAX;
00323                 double bound2 = -DBL_MAX;
00324                 int iter;
00325                 for (int i=0;i<getIter(inst);i++) {
00326                         if (getDoubleField(inst,i,F_RES_UBOUND) <= value) {
00327                                 time2 = getDoubleField(inst,i,F_RES_TIME);
00328                                 bound2 = getDoubleField(inst,i,F_RES_UBOUND);
00329                                 iter = i;
00330                                 break;
00331                         }
00332                 }
00333                 if ((time2 != -DBL_MAX) && (iter >= 1)) {
00334                         time1 = getDoubleField(inst,iter-1,F_RES_TIME);
00335                         bound1 = getDoubleField(inst,iter-1,F_RES_UBOUND);
00336                         double linearized_time;
00337                         linearized_time = ((value - bound1)*(time2 - time1)/(bound2 - bound1)) + time1;
00338 
00339 
00340 //printf("\ni=%d bound1=%.4f  time1=%.4f  bound2=%.4f time2=%.4f  boundinput=%.4f timelinearized=%.4f\n",
00341 //iter,bound1,time1,bound2,time2,value,linearized_time);
00342                         return linearized_time;
00343                 }
00344                 return -1.0;
00345         }
00346 /***********************************************************************/
00347 private:
00348         bool isNumber(char *string) {
00349                 if (string == NULL)
00350                         return false;
00351                 for (int i=0;i< (int)strlen(string);i++) {
00352                         char c=string[i];
00353                         if (!( (c == '.') || (c == '-') || (c == '+') ||(isdigit(c)) ))
00354                                 return false;
00355                 }
00356                 return true;
00357         }
00358 /***********************************************************************/
00359         int readF_resFile(const char *filename) {
00360                 FILE *f_res_file = fopen(filename,"r");
00361                 if (f_res_file == NULL) {
00362                         printf("Error opening %s. Exiting.\n",filename);
00363                         return 1;
00364                 }
00365                 char line [ 1024 ];
00366                 int linecnt = 0;
00367                 int curr_instance = -1;
00368                 int curr_iter = 0;
00369                 while ( fgets ( line, sizeof line, f_res_file) != NULL ) {
00370                         if (linecnt > F_RES_HEADER_LINES) {
00371                                 char *curr;
00372                                 char curr_instance_name[256];
00373                                 curr = strtok ( line, " \t" );
00374                                 if (!(isNumber(curr))) {
00375                                         strcpy(curr_instance_name,curr);
00376                                         curr_instance = _bov->instancename2index(curr_instance_name);
00377                                         if (curr_instance < 0) {
00378                                                 printf("readF_res_File:: instance %s not in bounds+opt values file\n",curr_instance_name);
00379                                                 return 1;
00380                                         }
00381                                         curr_iter = 0;
00382                                         if (_f_res_iter[curr_instance] > 0) {
00383                                                 printf("readF_res_File:: WARNING multiple runs of instance %s (replacing)\n",curr_instance_name);
00384 
00385                                         }
00386                                         _f_res_iter[curr_instance] = 0;
00387                                         curr = strtok ( NULL, " \t" );
00388                                 }
00389                                 if (curr_iter > F_RES_MAX_ITER - 1) {
00390                                         printf("readF_res_File::iterations for %s greater than %d\n",curr_instance_name,F_RES_MAX_ITER);
00391                                 }
00392                                 
00393                                 if (curr_instance == -1) {
00394                                                 printf("readF_res_File::missing instance name on line [%d]: %s\n"
00395                                                         ,linecnt+1,line);
00396                                                 return 1;
00397                                 }
00398 
00399                                 if (curr == NULL) {
00400                                         printf("readF_res_File::missing field 0 line [%d]: %s\n"
00401                                                 ,linecnt+1,line);
00402                                         return 1;
00403                                 }
00404                                 _f_res_double_data[curr_instance][curr_iter][F_RES_UBOUND] = atof(curr);
00405 
00406                                 curr = strtok ( NULL, " \t" );
00407                                 if (curr == NULL) {
00408                                         printf("readF_res_File::missing field 1 line [%d]: %s\n"
00409                                                 ,linecnt+1,line);
00410                                         return 1;
00411                                 }
00412                                 _f_res_int_data[curr_instance][curr_iter][F_RES_ITER] = atoi(curr);
00413                                 if (curr_iter != _f_res_int_data[curr_instance][curr_iter][F_RES_ITER]) {
00414                                         printf("readF_res_File::iteration jump line [%d]:%s\n",linecnt+1,line);
00415                                         return 1;
00416                                 }
00417 
00418                                 curr = strtok ( NULL, " \t" );
00419                                 if (curr == NULL) {
00420                                         printf("readF_res_File::missing field 2 line [%d]: %s\n"
00421                                                 ,linecnt+1,line);
00422                                         return 1;
00423                                 }
00424                                 _f_res_double_data[curr_instance][curr_iter][F_RES_TIME] = atof(curr);
00425 
00426                                 curr = strtok ( NULL, " \t" );
00427                                 if (curr == NULL) {
00428                                         printf("readF_res_File::missing field 4 line [%d]: %s\n"
00429                                                 ,linecnt+1,line);
00430                                         return 1;
00431                                 }
00432                                 _f_res_int_data[curr_instance][curr_iter][F_RES_TOTCONS] = atoi(curr);
00433 
00434                                 curr = strtok ( NULL, " \t" );
00435                                 if (curr == NULL) {
00436                                         printf("readF_res_File::missing field 5 line [%d]: %s\n"
00437                                                 ,linecnt+1,line);
00438                                         return 1;
00439                                 }
00440                                 _f_res_int_data[curr_instance][curr_iter][F_RES_ITERGENCONS] = atoi(curr);
00441 
00442                                 curr = strtok ( NULL, " \t" );
00443                                 if (curr == NULL) {
00444                                         printf("readF_res_File::missing field 6 line [%d]: %s\n"
00445                                                 ,linecnt+1,line);
00446                                         return 1;
00447                                 }
00448                                 if (isNumber(curr))
00449                                         _f_res_double_data[curr_instance][curr_iter][F_RES_CURRHEUR] =
00450                                                                                         atof(curr);
00451                                 else
00452                                         _f_res_double_data[curr_instance][curr_iter][F_RES_CURRHEUR] =
00453                                                                                         -DBL_MAX;
00454 
00455                                 curr = strtok ( NULL, " \t" );
00456                                 if (curr == NULL) {
00457                                         printf("readF_res_File::missing field 7 line [%d]: %s\n"
00458                                                 ,linecnt+1,line);
00459                                         return 1;
00460                                 }
00461                                 if (isNumber(curr))
00462                                         _f_res_double_data[curr_instance][curr_iter][F_RES_BESTHEUR] =
00463                                                                                         atof(curr);
00464                                 else
00465                                         _f_res_double_data[curr_instance][curr_iter][F_RES_CURRHEUR] =
00466                                                                                         -DBL_MAX;
00467 
00468                                 curr_iter++;
00469                                 _f_res_iter[curr_instance]++;
00470                         } else {
00471                                 strcpy(_f_res_info[linecnt],line);
00472                         }
00473                         linecnt++;
00474                 }
00475                 fclose(f_res_file);
00476                 return 0;
00477         }
00478 /***********************************************************************/
00479         double computeBoundClosedGap(double bound, double rlt, double opt) {
00480                 return ((-bound - rlt) / (opt-rlt))*100;
00481         }
00482 /***********************************************************************/
00483 };
00484 
00485 
00486 
00487 /***********************************************************************/
00488 /***********************************************************************/
00489 /***********************************************************************/
00490 
00491 
00492 
00493 class Report {
00494 
00495 private:
00496         bounds_opt_values *_bov;
00497         dataset *_f_res1,*_f_res2;
00498 
00499 private:
00500 
00501 /*
00502         void fprintfReportHeader(FILE *out) {
00503                 fprintf(out,". . . | %s . . . . . | %s . . . . | .\n",getF_res(1)->getName(),getF_res(2)->getName());
00504                 fprintf(out,"%-13s %10s %10s | %10s %5s %10s %7s %5s %5s | %10s %5s %10s %7s %5s %5s | %3s\n",
00505                         "instance"
00506                         ,"bound"
00507                         ,"opt"
00508                         ,"bound"
00509                         ,"cl.gap"
00510                         ,"heursol"
00511                         ,"time"
00512                         ,"iter"
00513                         ,"gencuts"
00514                         ,"bound"
00515                         ,"cl.gap"
00516                         ,"heursol"
00517                         ,"time"
00518                         ,"iter"
00519                         ,"gencuts"
00520                         ,"cmp");
00521         }
00522 */
00523 /***********************************************************************/
00524 /*      void fprintfRHeader(FILE *out) {
00525                 fprintf(out,"%-15s %3s %4s %4s %8s\n",
00526                         "",
00527                         "alg",
00528                         "prob",
00529                         "fail",
00530                         "test_val");
00531         }
00532         void fprintfRLine(FILE *out,int instance, int f_res1_iter, int f_res2_iter) {
00533                 if ((f_res1_iter >=0) && (f_res1_iter < getF_res(1)->getIter(instance))) {
00534                         char tempstring[256];
00535                         sprintf(tempstring,"%s-1",getBoundOptValues()->getInstanceName(instance));
00536                         printf("%-15s %3s %4d %4s %8.2f\n",
00537                                 tempstring,
00538                                 "A1",
00539                                 instance,
00540                                 "0",
00541                                 getF_res(1)->getDoubleField(instance,f_res1_iter,F_RES_TIME));
00542                 }
00543                 if ((f_res2_iter >=0) && (f_res2_iter < getF_res(2)->getIter(instance))) {
00544                         char tempstring[256];
00545                         sprintf(tempstring,"%s-2",getBoundOptValues()->getInstanceName(instance));
00546                         printf("%-15s %3s %4d %4s %8.2f\n",
00547                                 tempstring,
00548                                 "A2",
00549                                 instance,
00550                                 "0",
00551                                 getF_res(2)->getDoubleField(instance,f_res2_iter,F_RES_TIME));
00552                 }
00553         }
00554 */
00555 /***********************************************************************/
00556 /*
00557         void fprintfReportLine(FILE *out,int instance, int f_res1_iter, int f_res2_iter, char *additional_col) {
00558                 //print instance name, rlt,opt,anureet results
00559 
00560                 //prints an error line if rlt bounds do no match
00561                 bool rlt_bound_error = false;
00562                 if(getF_res(1)->getIter(instance) >= 0) {
00563                         if (!(doubleEqual(-getF_res(1)->getDoubleField(instance,0,F_RES_UBOUND), 
00564                                           getBoundOptValues()->getDoubleField(instance,BOUNDOPT_BOUND)))) {
00565 //                              fprintf(out,". . . . . rlt != bound @iter0 = %.2f ",-getF_res(1)->getDoubleField(instance,0,F_RES_UBOUND));
00566                                 rlt_bound_error = true;
00567                         }
00568                 }
00569                 if(getF_res(2)->getIter(instance) >= 0) {
00570                         if (!(doubleEqual(-getF_res(2)->getDoubleField(instance,0,F_RES_UBOUND), 
00571                                           getBoundOptValues()->getDoubleField(instance,BOUNDOPT_BOUND)))) {
00572 //                              fprintf(out,"rlt != bound @iter0 = %.2f",-getF_res(1)->getDoubleField(instance,0,F_RES_UBOUND));
00573                                 rlt_bound_error = true;
00574                         }
00575                 }
00576 //              if (rlt_bound_error) fprintf(out,"\n");
00577 
00578 
00579                 fprintf(out,"%-13s %10.2f %10.2f | "
00580                                 ,getBoundOptValues()->getInstanceName(instance)
00581                                 ,getBoundOptValues()->getDoubleField(instance,BOUNDOPT_BOUND)
00582                                 ,getBoundOptValues()->getDoubleField(instance,BOUNDOPT_OPT));
00583 
00584                 //print line from f_res1
00585                 if ((f_res1_iter >= 0) && (f_res1_iter < getF_res(1)->getIter(instance))) {
00586                         fprintf(out,"%10.2f %5.2f"
00587                                 ,getF_res(1)->getDoubleField(instance,f_res1_iter,F_RES_UBOUND)*F_RES_MULTIPLIER
00588                                 ,getF_res(1)->boundClosedGap(instance,f_res1_iter));
00589 
00590                         if (getF_res(1)->getDoubleField(instance,f_res1_iter,F_RES_BESTHEUR) <= -DBL_MAX)
00591                                 fprintf(out,"\t%10s","N/A ");
00592                         else
00593                                 fprintf(out,"\t%10.2f "
00594                                         ,getF_res(1)->getDoubleField(instance,f_res1_iter,F_RES_BESTHEUR)*F_RES_MULTIPLIER);
00595 
00596                         fprintf(out,"%7.2f %5d %5d"
00597                                 ,getF_res(1)->getDoubleField(instance,f_res1_iter,F_RES_TIME)
00598                                 ,getF_res(1)->getIntField(instance,f_res1_iter,F_RES_ITER)
00599                                 ,getF_res(1)->getIntField(instance,f_res1_iter,F_RES_TOTCONS));
00600                 } else {
00601                         fprintf(out,"%10s %5s %10s %7s %5s %5s"
00602                                 ,TEST_NOT_RUN_STRING
00603                                 ,TEST_NOT_RUN_STRING
00604                                 ,TEST_NOT_RUN_STRING
00605                                 ,TEST_NOT_RUN_STRING
00606                                 ,TEST_NOT_RUN_STRING
00607                                 ,TEST_NOT_RUN_STRING);
00608                 }
00609 
00610                 fprintf(out," | ");
00611 
00612                 //print line from f_res2
00613                 if ((f_res2_iter >= 0) && (f_res2_iter < getF_res(2)->getIter(instance))) {
00614                         fprintf(out,"%10.2f %5.2f"
00615                                 ,getF_res(2)->getDoubleField(instance,f_res2_iter,F_RES_UBOUND)*F_RES_MULTIPLIER
00616                                 ,getF_res(2)->boundClosedGap(instance,f_res2_iter));
00617 
00618                         if (getF_res(2)->getDoubleField(instance,f_res2_iter,F_RES_BESTHEUR) <= -DBL_MAX)
00619                                 fprintf(out,"\t%10s","N/A ");
00620                         else
00621                                 fprintf(out,"\t%10.2f "
00622                                         ,getF_res(2)->getDoubleField(instance,f_res2_iter,F_RES_BESTHEUR)*F_RES_MULTIPLIER);
00623 
00624                         fprintf(out,"%7.2f %5d %5d"
00625                                 ,getF_res(2)->getDoubleField(instance,f_res2_iter,F_RES_TIME)
00626                                 ,getF_res(2)->getIntField(instance,f_res2_iter,F_RES_ITER)
00627                                 ,getF_res(2)->getIntField(instance,f_res2_iter,F_RES_TOTCONS));
00628                 } else {
00629                         fprintf(out,"%10s %5s %10s %7s %5s"
00630                                 ,TEST_NOT_RUN_STRING
00631                                 ,TEST_NOT_RUN_STRING
00632                                 ,TEST_NOT_RUN_STRING
00633                                 ,TEST_NOT_RUN_STRING
00634                                 ,TEST_NOT_RUN_STRING);
00635                 }
00636 
00637                 //print comparison column
00638                 fprintf(out," | %3s\n",additional_col);
00639         }
00640 */
00641 /***********************************************************************/
00642 public: 
00643         Report(const char *bound_opt_values_filename, const char *f_res1_filename, const char *f_res2_filename) {
00644                 _bov = new bounds_opt_values(bound_opt_values_filename);
00645                 _f_res1 = new dataset(f_res1_filename,_bov);
00646                 _f_res2 = new dataset(f_res2_filename,_bov);
00647         }
00648 /***********************************************************************/
00649 
00650 /***********************************************************************/
00651         dataset* getF_res(int i) {
00652                 if (i == 1)
00653                         return _f_res1;
00654                 if (i == 2)
00655                         return _f_res2;
00656                 return NULL;
00657         }
00658 /***********************************************************************/
00659         bounds_opt_values *getBoundOptValues() {return _bov;}
00660 /***********************************************************************/
00661         void fprint(FILE *out) {
00662                 getBoundOptValues()->fprint(out);
00663                 getF_res(1)->fprint(out);
00664                 getF_res(2)->fprint(out);
00665         }
00666 
00667 
00668         void report(double perc) {
00669                 Stat improvement_stat;
00670                 printf("time improvement when bound get below %.2f x SDP+RLT_BOUND\n",perc);
00671                 printf("%14s %13s %13s %13s %12s %12s %10s\n",
00672                         "instance","rlt_bound","sdp_bound","bound_threshold","time1","time2","improvement");
00673                 for(int i=0;i<getBoundOptValues()->getNumInstances();i++) {
00674                         char* instancename = getBoundOptValues()->getInstanceName(i);
00675                         double rlt_bound = getF_res(1)->getDoubleField(i,0,F_RES_UBOUND);
00676                         // just to check :)
00677                         if (rlt_bound != getF_res(2)->getDoubleField(i,0,F_RES_UBOUND)) {
00678                                 printf("RLT bounds mismatch for %s!!!\n",instancename);
00679                                 exit(0);
00680                         }
00681                         double sdp_bound = getBoundOptValues()->getDoubleField(i,BOUNDOPT_BOUND);
00682                         printf("%14s ",instancename);
00683                         if (rlt_bound == -DBL_MAX) {
00684                                 printf("%13s ","N/A");
00685                         }
00686                         else {
00687                                 double bound_threshold = sdp_bound + ((perc)*(rlt_bound - sdp_bound));
00688 //                              double time1 = getF_res(1)->timeAtBound(i,bound_threshold);
00689 //                              double time2 = getF_res(2)->timeAtBound(i,bound_threshold);     
00690                                 double time1 = getF_res(1)->timeAtLinearizedBound(i,bound_threshold);
00691                                 double time2 = getF_res(2)->timeAtLinearizedBound(i,bound_threshold);
00692 
00693                                 printf("%13.4f ",rlt_bound);
00694                                 printf("%13.4f ",sdp_bound);
00695                                 printf("%13.4f ",bound_threshold);
00696                                 if (time1 >= 0) printf("%12.2f ",time1);
00697                                 else            printf("%12s ","N/A");
00698                                 if (time2 >= 0) printf("%12.2f ",time2);
00699                                 else            printf("%12s ","N/A");
00700                                 if ((time1 >= 0) && (time2 >= 0)) {
00701                                         double maxtime = time1;
00702                                         if (time1 < time2)
00703                                                 maxtime = time2;
00704                                         if (maxtime == 0)
00705                                                 maxtime = 0.000000001;
00706                                         double improvement = ((time1-time2)*100.0/maxtime);
00707                                         if (fabs(time1-time2) < MIN_TIME_DIFFERENCE)
00708                                                 improvement = 0.0;
00709                                         printf("%10.2f %% ",improvement);
00710                                         improvement_stat.addEntry(improvement);
00711                                 }
00712                         }
00713                         printf("\n");
00714                 }
00715                 
00716                 printf("\n Mean=%.2f %%  Stddev= %2f  Min= %.2f %% Max= %.2f %%\n",improvement_stat.mean(),improvement_stat.stdDev(),improvement_stat.min(),improvement_stat.max());
00717         }
00718 
00719 
00720         void reportMaxDiff() {
00721                 Stat improvement_stat;
00722                 printf("%14s %13s %13s %13s %12s %12s %10s %10s\n",
00723                         "instance","rlt_bound","sdp_bound","bound","time1","time2","maximprtimetime","maximprtimebnd");
00724                 for(int i=0;i<getBoundOptValues()->getNumInstances();i++) {
00725                         char* instancename = getBoundOptValues()->getInstanceName(i);
00726                         double rlt_bound = getF_res(1)->getDoubleField(i,0,F_RES_UBOUND);
00727                         // just to check :)
00728                         if (rlt_bound != getF_res(2)->getDoubleField(i,0,F_RES_UBOUND)) {
00729                                 printf("RLT bounds mismatch for %s!!!\n",instancename);
00730                                 exit(0);
00731                         }
00732                         double sdp_bound = getBoundOptValues()->getDoubleField(i,BOUNDOPT_BOUND);
00733                         printf("%14s ",instancename);
00734                         if (rlt_bound == -DBL_MAX) {
00735                                 printf("%12s ","N/A");
00736                         }
00737                         else {
00738                                 double maximprtime = INVALID_ENTRY;
00739                                 double maximprbound = INVALID_ENTRY;
00740                                 double besttime1 = -INVALID_ENTRY;
00741                                 double besttime2 = -INVALID_ENTRY;
00742                                 double bestbound = -INVALID_ENTRY;
00743                                 for (int j=0;j<getF_res(1)->getIter(i);j++) {
00744                                         double time1 = getF_res(1)->getDoubleField(i,j,F_RES_TIME);
00745                                         double bound1 = getF_res(1)->getDoubleField(i,j,F_RES_UBOUND);
00746                                         double time2 = getF_res(2)->timeAtLinearizedBound(i,bound1);
00747                                         if ((time1 >= 0) && (time2 >= 0)) {
00748                                                 double maxtime = time1;
00749                                                 if (time1 < time2)
00750                                                         maxtime = time2;
00751                                                 if (maxtime == 0)
00752                                                         maxtime = 0.000000001;
00753                                                 double improvement = ((time1-time2)*100.0/maxtime);
00754                                                 if (fabs(time1-time2) < MIN_TIME_DIFFERENCE)
00755                                                         improvement = 0.0;
00756                                                 if (improvement > maximprtime) {
00757                                                         maximprtime = improvement;
00758                                                         besttime1 = time1;
00759                                                         besttime2 = time2;
00760                                                         bestbound = bound1;
00761                                                         double currbound = (bestbound - sdp_bound)*100.0/(rlt_bound - sdp_bound);
00762 //                                                      if (fabs(currbound) < 0.01)
00763 //                                                              currbound = fabs(currbound);
00764                                                         maximprbound = currbound;
00765                                                         
00766                                                 }
00767                                         }
00768                                 }
00769                                 printf("%13.4f ",rlt_bound);
00770                                 printf("%13.4f ",sdp_bound);
00771                                 if ((besttime1 >= 0) && (besttime2 >= 0) && (maximprtime != INVALID_ENTRY)){
00772                                         printf("%13.4f ",bestbound);
00773                                         printf("%12.2f ",besttime1);
00774                                         printf("%12.2f ",besttime2);
00775                                         printf("%10.2f %% ",maximprtime);
00776                                         printf("%10.2f %% ",maximprbound);
00777                                         improvement_stat.addEntry(maximprtime);
00778 
00779                                 } else {
00780                                         printf("%13s ","N/A");
00781                                         printf("%12s ","N/A");
00782                                         printf("%12s ","N/A");
00783                                         printf("%10s ","N/A");
00784                                         printf("%10s ","N/A");
00785                                 }
00786                         }
00787                         printf("\n");
00788                 }
00789         }
00790 
00791 };
00792 
00793 
00794 
00795 
00796 /***********************************************************************/
00797 /***********************************************************************/
00798 /***********************************************************************/
00799 #if 0
00800 int main (int argc, const char **argv) {
00801         if (argc < 5) {
00802                 printf("Usage: %s [boundoptfile] [f_res1.xxx] [f_res2.xxx] [perc]\n",argv[0]);
00803                 return 1;
00804         }
00805         Report *report = new Report(argv[1],argv[2],argv[3]);
00806 
00807 //      report->fprint(stdout);
00808 
00809         report->report(atof(argv[4])/100.0);
00810 //      report->reportMaxDiff();
00811 
00812 
00813 }
00814 
00815 #endif

Generated on Thu Sep 22 03:05:57 2011 by  doxygen 1.4.7