• Main Page
  • Modules
  • Classes
  • Files
  • File List

D:/Projekt/ECF_trunk/examples/COCO/exampleexperiment.cpp

00001 /* runs an entire experiment for benchmarking an arbitrary ECF algorithm,
00002 * on the noise-free testbed
00003 * or the noisy testbed (change the ifun loop in this case as given below).
00004 */
00005 
00006 /**************************************************
00007  *          BBOB Mandatory initialization         *
00008  *************************************************/
00009 /* 
00010 BBOB parameters defined in this file are:
00011     - function id
00012     - function instance
00013 (given in for loops, see below)
00014 
00015 All the other BBOB parameters are given in the ECF configuration file:
00016     - algorithm name
00017     - algorithm description
00018     - dimensionality
00019     - termination criteria (number of evaluations)
00020 as well as the actual ECF optimization algorithm.
00021 */
00022 
00023 
00024 #include <stdio.h>
00025 #include <string.h>
00026 #include <time.h>
00027 #include <stdlib.h>
00028 #include "./bbob/bbobStructures.h" /* Include all declarations for BBOB calls */
00029 #include <ecf/ECF.h>
00030 #include "FunctionMinEvalOp.h"
00031 
00032 extern int enableOutput;
00033 
00034 
00035 int main(int argc, char **argv)
00036 {
00037     unsigned int instances[15] = {1, 2, 3, 4, 5, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};
00038     unsigned int ifun, idx_instances;
00039     int independent_restarts;
00040     double maxfunevals, minfunevals;
00041 
00042     clock_t t0 = clock();
00043     time_t Tval;
00044 
00045     /* To make the noise deterministic. */
00046     /* fgeneric_noiseseed(30); printf("seed for the noise set to: 30\n"); */
00047 
00048     /* Function indices are from 1 to 24 (noiseless) or from 101 to 130 (noisy) */
00049     /* for the noisy functions exchange the for loop with */
00050     /* for (ifun = 101; ifun <= 130; ifun++) */
00051     for (ifun = 1; ifun <= 24; ifun++)
00052     {
00053 
00054         for (idx_instances = 0; idx_instances < 15; idx_instances++)
00055         {
00056             // set up ECF
00057             StateP state (new State);
00058             // set the evaluation operator
00059             FunctionMinEvalOp* evalOp = new FunctionMinEvalOp;
00060             state->setEvalOp(evalOp);
00061 
00062             // initialize with current parameters, but skip evaluateOp
00063             evalOp->experimentMode_ = true;
00064             state->initialize(argc, argv);
00065             evalOp->experimentMode_ = false;
00066 
00067             // force BBOB output (overrides ECF configuration)
00068             enableOutput = 1;
00069             // set function ID (overrides ECF configuration)
00070             state->getRegistry()->modifyEntry("coco.function", (voidP) (new uint(ifun)));
00071             state->getRegistry()->modifyEntry("coco.enableoutput", (voidP) (new uint(1)));
00072 
00073             // set function instance
00074             state->getRegistry()->modifyEntry("coco.instance", (voidP) (new uint(instances[idx_instances])));
00075 
00076             // initialize evaluator with current instance
00077             state->getEvalOp()->initialize(state);
00078 
00079 
00080             maxfunevals = 10; /* PUT APPROPRIATE MAX. NUMBER OF FEVALS */
00081                                              /* 5. * dim should be fine to just check everything */
00082             minfunevals = 10;  /* PUT MINIMAL USEFUL NUMBER OF FEVALS */
00083             independent_restarts = -1;
00084             while (fgeneric_evaluations() + minfunevals <= maxfunevals)
00085             {
00086                 if (++independent_restarts > 0) 
00087                     fgeneric_restart("independent restart");  /* additional info */
00088 
00089                 // ECF optimization
00090                 state->run();
00091 
00092                 if (fgeneric_best() < fgeneric_ftarget())
00093                     break;
00094             }
00095 
00096             printf("  f%d in %d-D, instance %d: FEs=%.0f with %d restarts,", ifun, 10,
00097                    instances[idx_instances], fgeneric_evaluations(), independent_restarts);
00098             printf(" fbest-ftarget=%.4e, elapsed time [h]: %.2f\n", 
00099                    fgeneric_best() - fgeneric_ftarget(), (double)(clock()-t0)/CLOCKS_PER_SEC/60./60.);
00100 
00101             fgeneric_finalize();
00102         }
00103         Tval = time(NULL);
00104         printf("    date and time: %s", ctime(&Tval));
00105     }
00106 
00107     return 0;
00108 }

Generated on Tue Nov 4 2014 13:04:31 for ECF by  doxygen 1.7.1