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

Go to the documentation of this file.
00001 /* $Id: tracerreport.cpp 508 2011-02-15 21:52:44Z pbelotti $
00002  *
00003  * Name:    tracerreport.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 <math.h>
00014 
00015 #include <tracer.hpp>
00016 
00017 #define TIE_PERC 5.0
00018 
00019 
00020 #define MAX_ENTRIES 50
00021 #define MAX_INSTANCES 1000
00022 #define SEPARATORS "| \t"
00023 
00024 #define BOUNDOPTRLTVALUES_DOUBLE_FIELDS 3
00025 
00026 #define INVALID_ENTRY -999999999
00027 
00028 enum BoundOptRltValuesEntries
00029 {
00030         BOUNDOPT_BOUND = 0, // SDP+RLT approximate bound (used instead of BOUNDOPT_OPT when the latter is not available)
00031         BOUNDOPT_OPT = 1,
00032         BOUNDOPT_RLT = 2
00033 };
00034 
00035 class bounds_opt_rlt_values {
00036 private:
00037         int _bound_opt_rlt_values_num_instances;
00038         char **_instance_name_lookup;
00039         double **_instance_data;
00040 
00041 public:
00042         bounds_opt_rlt_values(const char* filename) {
00043                 _instance_name_lookup = (char**) malloc(sizeof(char*)*MAX_INSTANCES);
00044                 for(int i=0;i<MAX_INSTANCES;i++)
00045                         _instance_name_lookup[i] = (char*) malloc(sizeof(char)*1024);
00046                 _instance_data = (double**) malloc(sizeof(double*)*MAX_INSTANCES);
00047                 for(int i=0;i<MAX_INSTANCES;i++) {
00048                         _instance_data[i] = (double*) malloc(sizeof(double)*BOUNDOPTRLTVALUES_DOUBLE_FIELDS);
00049                 }
00050                 int status;
00051                 status = readBoundsOptValuesFile(filename);
00052                 if (status)
00053                         exit(1);
00054         }
00055 
00056         ~bounds_opt_rlt_values() {
00057                 for(int i=0;i<MAX_INSTANCES;i++) {
00058                         free(_instance_name_lookup[i]);
00059                         free(_instance_data[i]);
00060                 }
00061                 free(_instance_name_lookup);
00062                 free(_instance_data);
00063         }
00064 /***********************************************************************/
00065         int getNumInstances() {return _bound_opt_rlt_values_num_instances;}
00066 /***********************************************************************/
00067         double getDoubleField(int inst,int field) {return _instance_data[inst][field];}
00068 /***********************************************************************/
00069 /***********************************************************************/
00070 /***********************************************************************/
00071         int findInstanceIdx(const char *name) {
00072                 for(int i=0;i<getNumInstances();i++) {
00073                         if(strcmp(name,_instance_name_lookup[i]) == 0)
00074                                 return i;
00075                 }
00076                 return -1;
00077         }
00078 /***********************************************************************/
00079         char *getInstanceName(int inst) {
00080                 if ((inst >= 0)&& (inst <= getNumInstances()))
00081                         return _instance_name_lookup[inst];
00082                 else
00083                         return NULL;
00084         }
00085 /*********************************************************************/
00086         void fprint(FILE *out) {
00087                 for (int i=0;i<getNumInstances();i++) {
00088                         fprintf(out,"%13s\t%10.2f\t%10.2f\t%10.2f\n"
00089                                 ,getInstanceName(i)
00090                                 ,getDoubleField(i,BOUNDOPT_BOUND)
00091                                 ,getDoubleField(i,BOUNDOPT_OPT)
00092                                 ,getDoubleField(i,BOUNDOPT_RLT));
00093                 }
00094         }
00095 /***********************************************************************/
00096 private:
00097         int readBoundsOptValuesFile(const char *filename) {
00098                 FILE *_bound_opt_file = fopen(filename,"r");
00099                 if (_bound_opt_file == NULL) {
00100                         printf("Error opening %s. Exiting.\n",filename);
00101                         return 1;
00102                 }
00103                 char line [ 1024 ];
00104                 int linecnt = 0;
00105                 while ( fgets ( line, sizeof line, _bound_opt_file) != NULL ) {
00106                         if (linecnt > 0) {  //skips the first line in the file (header)
00107                                 char *curr;
00108                                 curr = strtok ( line, " \t" );
00109                                 strcpy(_instance_name_lookup[linecnt-1],curr);
00110                                 for (int j=0;j<BOUNDOPTRLTVALUES_DOUBLE_FIELDS;j++) {
00111                                         curr = strtok ( NULL, " \t" );
00112                                         if (curr == NULL) {
00113                                                 printf("readBoundsOptValuesFile::missing field %d line [%d]: %s\n"
00114                                                         ,j,linecnt+1,line);
00115                                                 return 1;
00116                                         }
00117 
00118                                         _instance_data[linecnt-1][j] = atof(curr);
00119                                 }
00120                         }
00121                         linecnt++;
00122                         if (linecnt == MAX_INSTANCES) {
00123                                 printf("readBoundsOptRltValuesFile::instances limit exceeded [%d]\n",MAX_INSTANCES);
00124                                 return 1;
00125                         }
00126                 }
00127                 _bound_opt_rlt_values_num_instances = linecnt-1;
00128                 fclose(_bound_opt_file);
00129                 return 0;
00130         }
00131 
00132 
00133 };
00134 
00135 
00136 /*********************************************************************/
00137 
00138 
00139 
00140 class GlobalReportInstanceData {
00141 public:
00142         char    *instanceName;
00143         const   char* getInstanceName() {return instanceName;}
00144         void    setInstanceName(const char *instanceNameParam){ strcpy(instanceName,instanceNameParam);}
00145 
00146 
00147         int     boundAtIter_entries;
00148         double  *boundAtIter_bound;
00149         double  *boundAtIter_time;
00150         int     getBoundAtIter_entries() {return boundAtIter_entries;}
00151         double  getBoundAtIter_bound(int i) {return boundAtIter_bound[i];}
00152         double  getBoundAtIter_time(int i) {return boundAtIter_time[i];}
00153         void    setBoundAtIter_bound(int i,double bound) {boundAtIter_bound[i] = bound;}
00154         void    setBoundAtIter_time(int i,double time) {boundAtIter_time[i] = time;}
00155         void    setBoundAtIter_entries(int n) {boundAtIter_entries = n;}
00156 
00157         int     boundAtTime_entries;
00158         double  *boundAtTime_time;
00159         double  *boundAtTime_bound;
00160         int     getBoundAtTime_entries() {return boundAtTime_entries;}
00161         double  getBoundAtTime_time(int i) {return boundAtTime_time[i];}
00162         double  getBoundAtTime_bound(int i) {return boundAtTime_bound[i];}
00163         void    setBoundAtTime_time(int i,double time) {boundAtTime_time[i] = time;}
00164         void    setBoundAtTime_bound(int i,double bound) {boundAtTime_bound[i] = bound;}
00165         void    setBoundAtTime_entries(int n) {boundAtTime_entries = n;}
00166 
00167         int     boundInterpAtTime_entries;
00168         double  *boundInterpAtTime_bound;
00169         int     getBoundInterpAtTime_entries() {return boundInterpAtTime_entries;}
00170         double  getBoundInterpAtTime_bound(int i) {return boundInterpAtTime_bound[i];}
00171         void    setBoundInterpAtTime_bound(int i,double bound) {boundInterpAtTime_bound[i] = bound;}
00172         void    setBoundInterpAtTime_entries(int n) {boundInterpAtTime_entries = n;}
00173 
00174 
00175         GlobalReportInstanceData() {
00176                 instanceName = new char[1024];
00177                 boundAtTime_entries = 0;
00178                 boundAtTime_time = new double[MAX_ENTRIES];
00179                 boundAtTime_bound = new double[MAX_ENTRIES];
00180                 boundAtIter_entries = 0;
00181                 boundAtIter_time = new double[MAX_ENTRIES];
00182                 boundAtIter_bound = new double[MAX_ENTRIES];
00183                 boundInterpAtTime_entries = 0;
00184                 boundInterpAtTime_bound = new double[MAX_ENTRIES];
00185         }
00186 
00187         ~GlobalReportInstanceData() {
00188                 delete [] instanceName;
00189                 delete [] boundAtTime_time;
00190                 delete [] boundAtTime_bound;
00191                 delete [] boundAtIter_time;
00192                 delete [] boundAtIter_bound;
00193                 delete [] boundInterpAtTime_bound;
00194         }
00195 };
00196 
00197 
00198 
00199 class GlobalReport {
00200 public:
00201         GlobalReportInstanceData *instances;
00202         GlobalReportInstanceData *getInstances() {return instances;}
00203 
00204         int     version;
00205         int     getVersion() {return version;}
00206         int     instances_card;
00207         int     getNumInstances() {return instances_card;}
00208         char    *valid_instances;
00209 
00210         int     boundAtIter_iterheader[MAX_ENTRIES];
00211         int     boundAtIter_entries;
00212         int     *getBoundAtIter_iterheader() {return boundAtIter_iterheader;}
00213         int     getBoundAtIter_entries() {return boundAtIter_entries;}
00214 
00215         double  boundAtTime_timeheader[MAX_ENTRIES];
00216         int     boundAtTime_entries;
00217         double  *getBoundAtTime_timeheader() {return boundAtTime_timeheader;}
00218         int     getBoundAtTime_entries() {return boundAtTime_entries;}
00219 
00220         double  boundInterpAtTime_timeheader[MAX_ENTRIES];
00221         int     boundInterpAtTime_entries;
00222         double  *getBoundInterpAtTime_timeheader() {return boundInterpAtTime_timeheader;}
00223         int     getBoundInterpAtTime_entries() {return boundInterpAtTime_entries;}
00224 
00225 
00226         int     boundAtIter_firstEntryIndex;
00227         int     boundAtTime_firstEntryIndex;
00228         int     boundInterpAtTime_firstEntryIndex;
00229 
00230         double getDoubleParam(const char *str) const{
00231                 if (strncmp(str,REPORT_NO_ENTRY,1) == 0) {
00232                         return TRACER_INVALID_ENTRY;
00233                 } else {
00234                         return atof(str);
00235                 }
00236         }
00237 
00238         int findInstanceIdx(const char* instanceName) {
00239                 for (int i=0;i<getNumInstances();i++) {
00240                         if (strcmp(instanceName,instances[i].getInstanceName()) == 0)
00241                                 return i;
00242                 }
00243                 return -1;
00244         }
00245 
00246         GlobalReport(const char* filename, const char* valid_instances) {
00247                 boundAtIter_entries = 0;
00248                 boundAtTime_entries = 0;
00249                 boundInterpAtTime_entries = 0;
00250 
00251                 boundAtIter_firstEntryIndex = -1;
00252                 boundAtTime_firstEntryIndex = -1;
00253                 boundInterpAtTime_firstEntryIndex = -1;
00254 
00255                 int version = 0;
00256                 char line[64000];
00257 
00258                 instances = new GlobalReportInstanceData[MAX_INSTANCES];
00259 
00260                 FILE *globalreportfile = fopen(filename,"r");
00261                 int linecnt = 0;
00262                 int instanceidx = 0;
00263                 while ( fgets ( line, sizeof line, globalreportfile) != NULL ) {
00264                         linecnt++;
00265                         if (linecnt == 1) {
00266                                 sscanf(line,"TRACER_VERSION %d",&version);
00267                                 continue;
00268                         }
00269                         if (linecnt < 10) continue; // skip initial header
00270                         int tokidx = 0;
00271                         char *tok;
00272                         if (linecnt == 10) {
00273                                 //column names (we need to parse the bound@iter%d ...)
00274                                 tok = strtok(line,SEPARATORS);
00275                                 while (tok != NULL) {
00276                                         if (strncmp(tok,"bound@iter",10) == 0) {
00277                                                 int curriter;
00278                                                 sscanf(tok,"bound@iter%d",&curriter);
00279                                                 boundAtIter_iterheader[boundAtIter_entries] = curriter;
00280                                                 if (boundAtIter_firstEntryIndex < 0)
00281                                                         boundAtIter_firstEntryIndex = tokidx;
00282                                         }
00283                                         if (strncmp(tok,"time@iter",9) == 0) {
00284                                                 int curriter;
00285                                                 sscanf(tok,"time@iter%d",&curriter);
00286                                                 if (boundAtIter_iterheader[boundAtIter_entries] 
00287                                                         != curriter) {
00288                                                         printf("Error parsing global report header\n");
00289                                                         exit(1);
00290                                                 }
00291                                                 boundAtIter_entries++;
00292                                         }
00293                                         if (strncmp(tok,"bound@time",10) == 0) {
00294                                                 double currtime;
00295                                                 tok += 10;
00296                                                 currtime = atof(tok);
00297                                                 boundAtTime_timeheader[boundAtTime_entries] = currtime;
00298                                                 if (boundAtTime_firstEntryIndex < 0)
00299                                                         boundAtTime_firstEntryIndex = tokidx;
00300                                         }
00301                                         if (strncmp(tok,"time@time",9) == 0) {
00302                                                 double currtime;
00303                                                 tok += 9;
00304                                                 currtime = atof(tok);
00305                                                 if (boundAtTime_timeheader[boundAtTime_entries]
00306                                                         != currtime){
00307                                                         printf("Error parsing global report header\n");
00308                                                         exit(1);
00309                                                 }
00310                                                 boundAtTime_entries++;
00311                                         }
00312                                         if (strncmp(tok,"bound_interp@time",17) == 0) {
00313                                                 double currtime;
00314                                                 tok += 17;
00315                                                 currtime = atof(tok);
00316                                                 boundInterpAtTime_timeheader[boundInterpAtTime_entries] = currtime;
00317                                                 boundInterpAtTime_entries++;
00318                                                 if (boundInterpAtTime_firstEntryIndex < 0)
00319                                                         boundInterpAtTime_firstEntryIndex = tokidx;
00320                                         }
00321                                         tok = strtok(NULL,SEPARATORS);
00322                                         tokidx ++;
00323                                 }
00324                         } else {
00325                                 if (    (boundAtIter_firstEntryIndex<2) || 
00326                                         (boundAtTime_firstEntryIndex<2) ||
00327                                         (boundInterpAtTime_firstEntryIndex <2) ) {
00328                                         printf("Error parsing global report header - missing fields\n");
00329                                         exit(1);
00330                                 }
00331                                 tokidx = 0;
00332                                 int paramidx = 0;
00333                                 tok = strtok(line,SEPARATORS);
00334                                 if (    (valid_instances != NULL) &&
00335                                         (strstr(valid_instances,tok) ==NULL) )
00336                                         continue; // skip current instance, not in valid_instances
00337                                 double *tempparam = new double[1000];
00338                                 while (tok != NULL) {
00339                                         if (tokidx == 0) {
00340                                                 instances[instanceidx].setInstanceName(tok);
00341                                         }
00342                                         if (    (tokidx >= boundAtIter_firstEntryIndex) 
00343                                                 && (tokidx < boundInterpAtTime_firstEntryIndex +
00344                                                                 boundInterpAtTime_entries) 
00345                                            ){
00346                                                 tempparam[paramidx] = getDoubleParam(tok);
00347                                                 paramidx++;
00348                                         }
00349                                         tok = strtok(NULL,SEPARATORS);
00350                                         tokidx ++;
00351                                 }
00352                                 paramidx = 0;
00353                                 for (int i=0;i<boundAtIter_entries;i++) {
00354                                         instances[instanceidx]
00355                                                 .setBoundAtIter_bound(i,tempparam[paramidx++]);
00356                                         instances[instanceidx]
00357                                                 .setBoundAtIter_time(i,tempparam[paramidx++]);
00358                                 }
00359                                 for (int i=0;i<boundAtTime_entries;i++) {
00360                                         instances[instanceidx]
00361                                                 .setBoundAtTime_bound(i,tempparam[paramidx++]);
00362                                         instances[instanceidx]
00363                                                 .setBoundAtTime_time(i,tempparam[paramidx++]);
00364                                 }
00365                                 for (int i=0;i<boundInterpAtTime_entries;i++) {
00366                                         instances[instanceidx]
00367                                                 .setBoundInterpAtTime_bound(i,tempparam[paramidx++]);
00368                                 }
00369                                 instances[instanceidx].setBoundAtIter_entries
00370                                         (boundAtIter_entries);
00371                                 instances[instanceidx].setBoundAtTime_entries
00372                                         (boundAtTime_entries);
00373                                 instances[instanceidx].setBoundInterpAtTime_entries
00374                                         (boundInterpAtTime_entries);
00375                                 instanceidx++;
00376 //for (int i=0;i<2*boundAtIter_entries+2*boundAtTime_entries+boundInterpAtTime_entries;i++)
00377 //printf("%.0f ",tempparam[i]);
00378 //printf("\n");
00379                                 delete [] tempparam; 
00380                         }
00381                 }
00382                 instances_card = instanceidx;
00383                 fclose(globalreportfile);
00384 
00385 //              for (int i=0;i<boundAtIter_entries;i++)
00386 //                      printf("%d ",boundAtIter_iterheader[i]);
00387 //              printf("\n");
00388 //              for (int i=0;i<boundAtTime_entries;i++)
00389 //                      printf("%.1f ",boundAtTime_timeheader[i]);
00390 //              printf("\n");
00391 //              for (int i=0;i<boundInterpAtTime_entries;i++)
00392 //                      printf("%.1f ",boundInterpAtTime_timeheader[i]);
00393 //              printf("\n");
00394 //              printf("%d %d %d\n",boundAtIter_firstEntryIndex,boundAtTime_firstEntryIndex,boundInterpAtTime_firstEntryIndex);
00395 
00396 /*
00397         for (int i=0;i<instances_card;i++) {
00398                 printf("instance %s\n",instances[i].getInstanceName());
00399                 for (int j=0;j<boundAtIter_entries;j++) {
00400                         printf("bound@iter%-4d= %12.4f  time@iter%-4d= %12.4f\n",
00401                                 boundAtIter_iterheader[j],
00402                                 instances[i].getBoundAtIter_bound(j),
00403                                 boundAtIter_iterheader[j],
00404                                 instances[i].getBoundAtIter_time(j));
00405                 }
00406                 for (int j=0;j<boundAtTime_entries;j++) {
00407                         printf("bound@time%-8.2f= %12.4f  time@time%-8.2f= %12.4f\n",
00408                                 boundAtTime_timeheader[j],
00409                                 instances[i].getBoundAtTime_bound(j),
00410                                 boundAtTime_timeheader[j],
00411                                 instances[i].getBoundAtTime_time(j));
00412                 }
00413                 for (int j=0;j<boundAtTime_entries;j++) {
00414                         printf("bound_interp@time%-8.2f= %12.4f\n",
00415                                 boundInterpAtTime_timeheader[j],
00416                                 instances[i].getBoundInterpAtTime_bound(j));
00417                 }
00418         }
00419 */
00420         }
00421 private:
00422         
00423 };
00424 
00425 
00426 #define A_BETTER 1
00427 #define B_BETTER 2
00428 #define AB_TIE   3
00429 #define A_UNC    4
00430 #define B_UNC    5
00431 #define AB_UNC   6
00432 int compare(double a, double b) {
00433         if ((a == TRACER_INVALID_ENTRY) && (b == TRACER_INVALID_ENTRY))
00434                 return AB_UNC;
00435         if (a == TRACER_INVALID_ENTRY)
00436                 return A_UNC;
00437         if (b == TRACER_INVALID_ENTRY)
00438                 return B_UNC;
00439         if (fabs(a-b)/fabs(a) * 100.0 < TIE_PERC)
00440                 return AB_TIE;
00441         if (a < b)
00442                 return A_BETTER;
00443         else
00444                 return B_BETTER;
00445 }
00446 
00447 int compareImpr(double a, double b) {
00448         if ((a == TRACER_INVALID_ENTRY) && (b == TRACER_INVALID_ENTRY))
00449                 return AB_UNC;
00450         if (a == TRACER_INVALID_ENTRY)
00451                 return A_UNC;
00452         if (b == TRACER_INVALID_ENTRY)
00453                 return B_UNC;
00454         if (fabs(a-b) < TIE_PERC)
00455                 return AB_TIE;
00456         if (a < b)
00457                 return A_BETTER;
00458         else
00459                 return B_BETTER;
00460 }
00461 
00462 int compare_strict(double a ,double b) {
00463         if ((a == TRACER_INVALID_ENTRY) && (b == TRACER_INVALID_ENTRY))
00464                 return AB_UNC;
00465         if (a == TRACER_INVALID_ENTRY)
00466                 return A_UNC;
00467         if (b == TRACER_INVALID_ENTRY)
00468                 return B_UNC;
00469         if (a == b)
00470                 return AB_TIE;
00471         if (a < b)
00472                 return A_BETTER;
00473         else
00474                 return B_BETTER;
00475 }
00476 
00477 
00478 double computeImprovement(double rlt, double opt, double sdp, double bound) {
00479         double improvement;
00480         double optapprox = opt;
00481         if (optapprox == INVALID_ENTRY){
00482                 optapprox = sdp;
00483         }
00484         if ((optapprox != INVALID_ENTRY) && (rlt != INVALID_ENTRY) && (bound != INVALID_ENTRY)) {
00485                 improvement = 100.0*((bound - rlt)/(optapprox - rlt));
00486         } else
00487                 improvement = INVALID_ENTRY;
00488         return improvement;
00489 }
00490 
00491 
00492 int main (int argc, const char **argv) {
00493         printf("Comparison tolerance %.2f%%\n",(double)TIE_PERC);
00494 
00495         if (argc < 3) {
00496                 printf("Usage: %s globalreport1.txt globalreport2.txt [instances.txt can be nullfile] [bounds+opt+rlt.txt]\n",argv[0]);
00497                 return 1;
00498         }
00499         
00500         char *valid_instances = NULL;
00501         if (argc > 3) {
00502                 FILE *valid_instances_file;
00503                 valid_instances_file = fopen(argv[3],"r");
00504                 if (valid_instances_file != NULL) {
00505                         char valid_instances_tmp[64000];
00506                         valid_instances = valid_instances_tmp;
00507                         fgets ( valid_instances_tmp, sizeof valid_instances_tmp, valid_instances_file);
00508                         fclose(valid_instances_file);
00509                 }
00510         }
00511 
00512         bounds_opt_rlt_values *borv = NULL;
00513         if (argc > 4) {
00514                 borv = new bounds_opt_rlt_values(argv[4]);
00515         }
00516 
00517         GlobalReport *gr1 = new GlobalReport(argv[1],valid_instances);
00518         GlobalReport *gr2 = new GlobalReport(argv[2],valid_instances);
00519 
00520         if (gr1->getVersion() != gr2->getVersion()) {
00521                 printf("version mismatch\n");
00522                 exit(1);
00523         }
00524 
00525         // determine how many instances are not in common
00526         int notincommon1 = 0;
00527         int notincommon2 = 0;
00528         for (int i=0;i<gr1->getNumInstances();i++) {
00529                 int inst_idx1,inst_idx2;
00530                 inst_idx1 = i;
00531                 const char *instance_name = gr1->getInstances()[inst_idx1].getInstanceName();
00532                 inst_idx2 = gr2->findInstanceIdx(instance_name);
00533                 if (inst_idx2 < 0)
00534                         notincommon1++;
00535         }
00536         for (int i=0;i<gr2->getNumInstances();i++) {
00537                 int inst_idx1,inst_idx2;
00538                 inst_idx2 = i;
00539                 const char *instance_name = gr2->getInstances()[inst_idx2].getInstanceName();
00540                 inst_idx1 = gr1->findInstanceIdx(instance_name);
00541                 if (inst_idx1 < 0)
00542                         notincommon2++;
00543         }
00544 
00545 
00546         // determine aggregate results for boundAtIter
00547         int     *boundAtIter_best1 = new int[gr1->getBoundAtIter_entries()];
00548         int     *boundAtIter_best2 = new int[gr1->getBoundAtIter_entries()];
00549         int     *boundAtIter_tie   = new int[gr1->getBoundAtIter_entries()];
00550         int     *boundAtIter_total = new int[gr1->getBoundAtIter_entries()];
00551         Stat    *improvement1vs2_stat = new Stat[gr1->getBoundAtIter_entries()];        
00552         for (int j=0;j<gr1->getBoundAtIter_entries();j++) {
00553                 boundAtIter_best1[j] = TRACER_INVALID_ENTRY;
00554                 boundAtIter_best2[j] = TRACER_INVALID_ENTRY;
00555                 boundAtIter_tie[j]   = TRACER_INVALID_ENTRY;
00556                 boundAtIter_total[j] = TRACER_INVALID_ENTRY;
00557         }
00558 
00559         for (int j=0;j<gr1->boundAtIter_entries;j++) {
00560                 int total_instances = 0;
00561                 int best1 = 0;
00562                 int best2 = 0;
00563                 int ties = 0;
00564                 for (int i=0;i<gr1->getNumInstances();i++) {
00565                         int inst_idx1,inst_idx2;
00566                         inst_idx1 = i;
00567                         const char *instance_name = gr1->getInstances()[inst_idx1].getInstanceName();
00568                         inst_idx2 = gr2->findInstanceIdx(instance_name);
00569                         if (inst_idx2 < 0) 
00570                                 continue;
00571                         total_instances++;
00572                         double bound1 = gr1->getInstances()[inst_idx1].getBoundAtIter_bound(j);
00573                         double bound2 = gr2->getInstances()[inst_idx2].getBoundAtIter_bound(j);
00574 double impr1 = INVALID_ENTRY;
00575 double impr2 = INVALID_ENTRY;
00576 if (borv) {
00577 int borv_idx = borv->findInstanceIdx(instance_name);
00578 if (borv_idx < 0) {
00579         printf("CANNOT FIND INSTANCE\n");
00580         exit(-1);
00581 }
00582 impr1 = computeImprovement(
00583         borv->getDoubleField(borv_idx,BOUNDOPT_RLT),
00584         borv->getDoubleField(borv_idx,BOUNDOPT_OPT),
00585         borv->getDoubleField(borv_idx,BOUNDOPT_BOUND),
00586         bound1);
00587 impr2 = computeImprovement(
00588         borv->getDoubleField(borv_idx,BOUNDOPT_RLT),
00589         borv->getDoubleField(borv_idx,BOUNDOPT_OPT),
00590         borv->getDoubleField(borv_idx,BOUNDOPT_BOUND),
00591         bound2);
00592 if ((impr1 != INVALID_ENTRY) && (impr2 != INVALID_ENTRY)) {
00593         improvement1vs2_stat[j].addEntry(impr2-impr1);
00594 
00595 //if ((gr1->getBoundAtIter_iterheader()[j]>= 300) && (impr2-impr1 < 0)) {
00596 //printf("iter=%d impr2VSimpr1=%.2f  %s\n",gr1->getBoundAtIter_iterheader()[j],impr2-impr1,instance_name);
00597 //}
00598 }
00599 }
00600 //                      switch(compare(bound1,bound2)) {
00601                         switch(compareImpr(impr2,impr1)) {
00602                                 case A_BETTER:
00603                                                 best1++;
00604                                                 break;
00605                                 case B_BETTER:
00606                                                 best2++;
00607                                                 break;
00608                                 case AB_TIE:
00609                                                 ties++;
00610                                                 break;
00611                                 case A_UNC:
00612                                                 break;
00613                                 case B_UNC:
00614                                                 break;
00615                                 case AB_UNC:
00616                                                 break;
00617                         }
00618                 }
00619                 boundAtIter_best1[j] = best1;
00620                 boundAtIter_best2[j] = best2;
00621                 boundAtIter_tie[j]   = ties;
00622                 boundAtIter_total[j] = total_instances;
00623         }
00624 
00625 
00626 //      printf("%13s %6s %6s %6s %6s %6s %6s %4s %4s %4s %4s %4s %6s %8s %8s %8s %8s\n",
00627 //              "b@iter","best1","%best1","best2","%best2","ties","%ties","unc1","tot1","unc2","tot2","best","%gain","2VS1mean","2VS1sdev","2VS1min","2VS1max");
00628         printf("%13s %6s %6s %6s %6s %6s %6s %6s %6s %4s %8s %8s %8s %8s\n",
00629                 "b@iter","best1","%best1","best2","%best2","ties","%ties","unc","%unc","tot","2VS1mean","2VS1sdev","2VS1min","2VS1max");
00630         for (int j=0;j<gr1->boundAtIter_entries;j++) {
00631 //              int total_instances_cmp = boundAtIter_best1[j] + boundAtIter_best2[j] + boundAtIter_tie[j];
00632                 int total_instances_cmp = boundAtIter_total[j];
00633                 double best1_perc = 0.0;
00634                 double best2_perc = 0.0;
00635                 double tie_perc = 0.0;
00636                 double unc_perc = 0.0;
00637                 int unc = 0;
00638                 if (total_instances_cmp != 0) {
00639                         best1_perc = boundAtIter_best1[j]*100.0/total_instances_cmp;
00640                         best2_perc = boundAtIter_best2[j]*100.0/total_instances_cmp;
00641                         tie_perc = boundAtIter_tie[j]*100.0/total_instances_cmp;
00642                         unc = boundAtIter_total[j] - boundAtIter_tie[j] -boundAtIter_best2[j] - boundAtIter_best1[j];
00643                         unc_perc = unc*100/total_instances_cmp;
00644                 }
00645                 printf("%13d %6d %6.2f %6d %6.2f %6d %6.2f %6d %6.2f %4d %8.2f %8.2f %8.2f %8.2f\n",
00646                         gr1->getBoundAtIter_iterheader()[j],
00647                         boundAtIter_best1[j],
00648                         best1_perc,
00649                         boundAtIter_best2[j],
00650                         best2_perc,
00651                         boundAtIter_tie[j],
00652                         tie_perc,
00653                         unc,
00654                         unc_perc,
00655                         total_instances_cmp,
00656                         improvement1vs2_stat[j].mean(),
00657                         improvement1vs2_stat[j].stdDev(),
00658                         improvement1vs2_stat[j].min(),
00659                         improvement1vs2_stat[j].max()
00660                         );
00661         }
00662 
00663 //#########################
00664 printf("\n");
00665         // determine aggregate results for boundAtTime
00666         int     *boundAtTime_best1 = new int[gr1->getBoundAtTime_entries()];
00667         int     *boundAtTime_best2 = new int[gr1->getBoundAtTime_entries()];
00668         int     *boundAtTime_tie   = new int[gr1->getBoundAtTime_entries()];
00669         int     *boundAtTime_unc1  = new int[gr1->getBoundAtTime_entries()];
00670         int     *boundAtTime_unc2  = new int[gr1->getBoundAtTime_entries()];
00671         int     *boundAtTime_total = new int[gr1->getBoundAtTime_entries()];
00672         double  *boundAtTime_sumbounds1 = new double[gr1->getBoundAtTime_entries()];
00673         double  *boundAtTime_sumbounds2 = new double[gr1->getBoundAtTime_entries()];
00674 
00675         for (int j=0;j<gr1->getBoundAtTime_entries();j++) {
00676                 improvement1vs2_stat[j].reset();
00677                 boundAtTime_best1[j] = TRACER_INVALID_ENTRY;
00678                 boundAtTime_best2[j] = TRACER_INVALID_ENTRY;
00679                 boundAtTime_tie[j]   = TRACER_INVALID_ENTRY;
00680                 boundAtTime_unc1[j]  = TRACER_INVALID_ENTRY;
00681                 boundAtTime_unc2[j]  = TRACER_INVALID_ENTRY;
00682                 boundAtTime_total[j] = TRACER_INVALID_ENTRY;
00683                 boundAtTime_sumbounds1[j] = TRACER_INVALID_ENTRY;
00684                 boundAtTime_sumbounds2[j] = TRACER_INVALID_ENTRY;
00685         }
00686 
00687         for (int j=0;j<gr1->boundAtTime_entries;j++) {
00688                 int total_instances = 0;
00689                 int best1 = 0;
00690                 int best2 = 0;
00691                 int ties = 0;
00692                 for (int i=0;i<gr1->getNumInstances();i++) {
00693                         int inst_idx1,inst_idx2;
00694                         inst_idx1 = i;
00695                         const char *instance_name = gr1->getInstances()[inst_idx1].getInstanceName();
00696                         inst_idx2 = gr2->findInstanceIdx(instance_name);
00697                         if (inst_idx2 < 0) 
00698                                 continue;
00699                         total_instances++;
00700                         double bound1 = gr1->getInstances()[inst_idx1].getBoundAtTime_bound(j);
00701                         double bound2 = gr2->getInstances()[inst_idx2].getBoundAtTime_bound(j);
00702 double impr1 = INVALID_ENTRY;
00703 double impr2 = INVALID_ENTRY;
00704 if (borv) {
00705 int borv_idx = borv->findInstanceIdx(instance_name);
00706 if (borv_idx < 0) {
00707         printf("CANNOT FIND INSTANCE\n");
00708         exit(-1);
00709 }
00710 impr1 = computeImprovement(
00711         borv->getDoubleField(borv_idx,BOUNDOPT_RLT),
00712         borv->getDoubleField(borv_idx,BOUNDOPT_OPT),
00713         borv->getDoubleField(borv_idx,BOUNDOPT_BOUND),
00714         bound1);
00715 impr2 = computeImprovement(
00716         borv->getDoubleField(borv_idx,BOUNDOPT_RLT),
00717         borv->getDoubleField(borv_idx,BOUNDOPT_OPT),
00718         borv->getDoubleField(borv_idx,BOUNDOPT_BOUND),
00719         bound2);
00720 if ((impr1 != INVALID_ENTRY) && (impr2 != INVALID_ENTRY)) {
00721         improvement1vs2_stat[j].addEntry(impr2-impr1);
00722 }
00723 }
00724 //                      switch(compare(bound1,bound2)) {
00725                         switch(compare(impr2,impr1)) {
00726                                 case A_BETTER:
00727                                                 best1++;
00728                                                 break;
00729                                 case B_BETTER:
00730                                                 best2++;                
00731                                                 break;
00732                                 case AB_TIE:
00733                                                 ties++;
00734                                                 break;
00735                                 case A_UNC:
00736                                                 break;
00737                                 case B_UNC:
00738                                                 break;
00739                                 case AB_UNC:
00740                                                 break;
00741                         }
00742                 }
00743                 boundAtTime_best1[j] = best1;
00744                 boundAtTime_best2[j] = best2;
00745                 boundAtTime_tie[j]   = ties;
00746                 boundAtTime_total[j] = total_instances;
00747         }
00748 
00749 
00750 //      printf("%13s %6s %6s %6s %6s %6s %6s %4s %4s %4s %4s %4s %6s %8s %8s %8s %8s\n",
00751 //              "b@time","best1","%best1","best2","%best2","ties","%ties","unc1","tot1","unc2","tot2","best","%gain","2VS1mean","2VS1sdev","2VS1min","2VS1max");
00752         printf("%13s %6s %6s %6s %6s %6s %6s %6s %6s %4s %8s %8s %8s %8s\n",
00753                 "b@time","best1","%best1","best2","%best2","ties","%ties","unc","%unc","tot","2VS1mean","2VS1sdev","2VS1min","2VS1max");
00754         for (int j=0;j<gr1->boundAtTime_entries;j++) {
00755 //              int total_instances_cmp = boundAtTime_best1[j] + boundAtTime_best2[j] + boundAtTime_tie[j];
00756                 int total_instances_cmp = boundAtTime_total[j];
00757                 double best1_perc = 0.0;
00758                 double best2_perc = 0.0;
00759                 double tie_perc = 0.0;
00760                 double unc_perc = 0.0;
00761                 int unc = 0;
00762                 if (total_instances_cmp != 0) {
00763                         best1_perc = boundAtTime_best1[j]*100.0/total_instances_cmp;
00764                         best2_perc = boundAtTime_best2[j]*100.0/total_instances_cmp;
00765                         tie_perc = boundAtTime_tie[j]*100.0/total_instances_cmp;
00766                         unc = boundAtTime_total[j] - boundAtTime_tie[j] - boundAtTime_best2[j] - boundAtTime_best1[j];
00767                         unc_perc = unc*100.0/total_instances_cmp;
00768                 }
00769                 printf("%13.2f %6d %6.2f %6d %6.2f %6d %6.2f %6d %6.2f %6d %8.2f %8.2f %8.2f %8.2f\n",
00770                         gr1->getBoundAtTime_timeheader()[j],
00771                         boundAtTime_best1[j],
00772                         best1_perc,
00773                         boundAtTime_best2[j],
00774                         best2_perc,
00775                         boundAtTime_tie[j],
00776                         tie_perc,
00777                         unc,
00778                         unc_perc,
00779                         total_instances_cmp,
00780                         improvement1vs2_stat[j].mean(),
00781                         improvement1vs2_stat[j].stdDev(),
00782                         improvement1vs2_stat[j].min(),
00783                         improvement1vs2_stat[j].max());
00784         }
00785 
00786 
00787 //#########################
00788 printf("\n");
00789         // determine aggregate results for boundInterpAtTime
00790         int     *boundInterpAtTime_best1 = new int[gr1->getBoundInterpAtTime_entries()];
00791         int     *boundInterpAtTime_best2 = new int[gr1->getBoundInterpAtTime_entries()];
00792         int     *boundInterpAtTime_tie   = new int[gr1->getBoundInterpAtTime_entries()];
00793         int     *boundInterpAtTime_unc1  = new int[gr1->getBoundInterpAtTime_entries()];
00794         int     *boundInterpAtTime_unc2  = new int[gr1->getBoundInterpAtTime_entries()];
00795         int     *boundInterpAtTime_total = new int[gr1->getBoundInterpAtTime_entries()];
00796         double  *boundInterpAtTime_sumbounds1 = new double[gr1->getBoundInterpAtTime_entries()];
00797         double  *boundInterpAtTime_sumbounds2 = new double[gr1->getBoundInterpAtTime_entries()];
00798         for (int j=0;j<gr1->getBoundInterpAtTime_entries();j++) {
00799                 improvement1vs2_stat[j].reset();
00800                 boundInterpAtTime_best1[j] = TRACER_INVALID_ENTRY;
00801                 boundInterpAtTime_best2[j] = TRACER_INVALID_ENTRY;
00802                 boundInterpAtTime_tie[j]   = TRACER_INVALID_ENTRY;
00803                 boundInterpAtTime_unc1[j]  = TRACER_INVALID_ENTRY;
00804                 boundInterpAtTime_unc2[j]  = TRACER_INVALID_ENTRY;
00805                 boundInterpAtTime_total[j] = TRACER_INVALID_ENTRY;
00806                 boundInterpAtTime_sumbounds1[j] = TRACER_INVALID_ENTRY;
00807                 boundInterpAtTime_sumbounds2[j] = TRACER_INVALID_ENTRY;
00808         }
00809 
00810         for (int j=0;j<gr1->boundInterpAtTime_entries;j++) {
00811                 int total_instances = 0;
00812                 int best1 = 0;
00813                 int best2 = 0;
00814                 int ties = 0;
00815                 for (int i=0;i<gr1->getNumInstances();i++) {
00816                         int inst_idx1,inst_idx2;
00817                         inst_idx1 = i;
00818                         const char *instance_name = gr1->getInstances()[inst_idx1].getInstanceName();
00819                         inst_idx2 = gr2->findInstanceIdx(instance_name);
00820                         if (inst_idx2 < 0) 
00821                                 continue;
00822                         total_instances++;
00823                         double bound1 = gr1->getInstances()[inst_idx1].getBoundInterpAtTime_bound(j);
00824                         double bound2 = gr2->getInstances()[inst_idx2].getBoundInterpAtTime_bound(j);
00825 double impr1 = INVALID_ENTRY;
00826 double impr2 = INVALID_ENTRY;
00827 if (borv) {
00828 int borv_idx = borv->findInstanceIdx(instance_name);
00829 if (borv_idx < 0) {
00830         printf("CANNOT FIND INSTANCE\n");
00831         exit(-1);
00832 }
00833 impr1 = computeImprovement(
00834         borv->getDoubleField(borv_idx,BOUNDOPT_RLT),
00835         borv->getDoubleField(borv_idx,BOUNDOPT_OPT),
00836         borv->getDoubleField(borv_idx,BOUNDOPT_BOUND),
00837         bound1);
00838 impr2 = computeImprovement(
00839         borv->getDoubleField(borv_idx,BOUNDOPT_RLT),
00840         borv->getDoubleField(borv_idx,BOUNDOPT_OPT),
00841         borv->getDoubleField(borv_idx,BOUNDOPT_BOUND),
00842         bound2);
00843 if ((impr1 != INVALID_ENTRY) && (impr2 != INVALID_ENTRY)) {
00844         improvement1vs2_stat[j].addEntry(impr2-impr1);
00845 }
00846 }
00847 //                      switch(compare(bound1,bound2)) {
00848                         switch(compare(impr2,impr1)) {
00849                                 case A_BETTER:
00850                                                 best1++;
00851                                                 break;
00852                                 case B_BETTER:
00853                                                 best2++;                
00854                                                 break;
00855                                 case AB_TIE:
00856                                                 ties++;
00857                                                 break;
00858                                 case A_UNC:
00859                                                 break;
00860                                 case B_UNC:
00861                                                 break;
00862                                 case AB_UNC:
00863                                                 break;
00864                         }
00865                 }
00866                 boundInterpAtTime_best1[j] = best1;
00867                 boundInterpAtTime_best2[j] = best2;
00868                 boundInterpAtTime_tie[j]   = ties;
00869                 boundInterpAtTime_total[j] = total_instances;
00870         }
00871 
00872 
00873 //      printf("%13s %6s %6s %6s %6s %6s %6s %4s %4s %4s %4s %4s %6s %8s %8s %8s %8s\n",
00874 //              "biterp@time","best1","%best1","best2","%best2","ties","%ties","unc1","tot1","unc2","tot2","best","%gain","2VS1mean","2VS1sdev","2VS1min","2VS1max");
00875         printf("%13s %6s %6s %6s %6s %6s %6s %6s %6s %4s %8s %8s %8s %8s\n",
00876                 "binterp@time","best1","%best1","best2","%best2","ties","%ties","unc","%unc","tot","2VS1mean","2VS1sdev","2VS1min","2VS1max");
00877         int totbest1 = 0;
00878         int totbest2 = 0;
00879         int totties = 0;
00880         int totunc1 = 0;
00881         int totunc2 = 0;
00882         int totcmp = 0;
00883         for (int j=0;j<gr1->boundInterpAtTime_entries;j++) {
00884 //              int total_instances_cmp = boundInterpAtTime_best1[j] + boundInterpAtTime_best2[j] + boundInterpAtTime_tie[j];
00885                 int total_instances_cmp = boundInterpAtTime_total[j];
00886                 double best1_perc = 0.0;
00887                 double best2_perc = 0.0;
00888                 double tie_perc = 0.0;
00889                 int unc = 0;
00890                 double unc_perc = 0.0;
00891                 if (total_instances_cmp != 0) {
00892                         best1_perc = boundInterpAtTime_best1[j]*100.0/total_instances_cmp;
00893                         best2_perc = boundInterpAtTime_best2[j]*100.0/total_instances_cmp;
00894                         tie_perc = boundInterpAtTime_tie[j]*100.0/total_instances_cmp;
00895                         unc = boundInterpAtTime_total[j] - boundInterpAtTime_tie[j] - boundInterpAtTime_best2[j] - boundInterpAtTime_best1[j];
00896                         unc_perc = unc*100.0/total_instances_cmp;
00897                 }
00898 //              printf("%13.2f %6d %6.2f %6d %6.2f %6d %6.2f %4d %4d %4d %4d %4c %6.2f %8.2f %8.2f %8.2f %8.2f\n",
00899                 printf("%13.2f %6d %6.2f %6d %6.2f %6d %6.2f %6d %6.2f %6d %8.2f %8.2f %8.2f %8.2f\n",
00900                         gr1->getBoundInterpAtTime_timeheader()[j],
00901                         boundInterpAtTime_best1[j],
00902                         best1_perc,
00903                         boundInterpAtTime_best2[j],
00904                         best2_perc,
00905                         boundInterpAtTime_tie[j],
00906                         tie_perc,
00907                         unc,
00908                         unc_perc,
00909                         total_instances_cmp,
00910                         improvement1vs2_stat[j].mean(),
00911                         improvement1vs2_stat[j].stdDev(),
00912                         improvement1vs2_stat[j].min(),
00913                         improvement1vs2_stat[j].max());
00914 
00915                 totbest1 += boundInterpAtTime_best1[j];
00916                 totbest2 += boundInterpAtTime_best2[j];
00917                 totties  += boundInterpAtTime_tie[j];
00918                 totunc1  += boundInterpAtTime_unc1[j];
00919                 totunc2  += boundInterpAtTime_unc2[j];
00920                 totcmp   += total_instances_cmp;
00921         }
00922         double totbest1_perc = totbest1 *100.0/totcmp;
00923         double totbest2_perc = totbest2 *100.0/totcmp;
00924         double totties_perc = totties *100.0/totcmp;
00925         printf("%13s %6d %6.2f %6d %6.2f %6d %6.2f\n",
00926                 "Aggregate",
00927                 totbest1,
00928                 totbest1_perc,
00929                 totbest2,
00930                 totbest2_perc,
00931                 totties,
00932                 totties_perc
00933                 );
00934 
00935 
00936 
00937 
00938 }
00939 
00940 
00941 

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