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

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

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