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

D:/Projekt/ECF_trunk/examples/FunctionMin/exampleexperiment.c

00001 /* runs an entire experiment for benchmarking MY_OPTIMIZER
00002 * on the noise-free testbed
00003 * or the noisy testbed (change the ifun loop in this case as given below).
00004 */
00005 
00006 #include <stdio.h>
00007 #include <string.h>
00008 #include <time.h>
00009 #include <stdlib.h>
00010 #include "bbobStructures.h" /* Include all declarations for BBOB calls */
00011 
00012 /* include all declarations for your own optimizer here */
00013 void MY_OPTIMIZER(double(*fitnessfunction)(double*), unsigned int dim, double ftarget,
00014                   double maxfunevals);
00015 
00016 int main(void)
00017 {
00018     unsigned int dim[6] = {2, 3, 5, 10, 20, 40};
00019     unsigned int instances[15] = {1, 2, 3, 4, 5, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};
00020     unsigned int idx_dim, ifun, idx_instances, seed;
00021     int independent_restarts;
00022     double maxfunevals, minfunevals;
00023 
00024     clock_t t0 = clock();
00025     time_t Tval;
00026     /**************************************************
00027      *          BBOB Mandatory initialization         *
00028      *************************************************/
00029     /* retrieve all default parameters of BBOB calls  */
00030     ParamStruct params = fgeneric_getDefaultPARAMS();
00031 
00032     /* modify the following parameters, choosing a different setting
00033      * for each new experiment */
00034     strcpy(params.dataPath, "PUT_MY_BBOB_DATA_PATH");  /* different folder for each experiment! */
00035     /* please beforehand run from the command-line 'python createfolders.py PUT_MY_BBOB_DATA_PATH'
00036      * to create the necessary folder structure to run an experiment. */
00037     strcpy(params.algName, "PUT ALGORITHM NAME");
00038     strcpy(params.comments, "PUT MORE DETAILED INFORMATION, PARAMETER SETTINGS ETC");
00039 
00040     seed = time(NULL);
00041     srand(seed); /* used by MY_OPTIMIZER */
00042     printf("random seed set to %d\n", seed);
00043 
00044     /* To make the noise deterministic. */
00045     /* fgeneric_noiseseed(30); printf("seed for the noise set to: 30\n"); */
00046 
00047     /* now the main loop */
00048     for (idx_dim = 0; idx_dim < 6; idx_dim++)
00049     {
00050         /* Function indices are from 1 to 24 (noiseless) or from 101 to 130 (noisy) */
00051         /* for the noisy functions exchange the for loop with */
00052         /* for (ifun = 101; ifun <= 130; ifun++) */
00053         for (ifun = 1; ifun <= 24; ifun++)
00054         {
00055             for (idx_instances = 0; idx_instances < 15; idx_instances++)
00056             {
00057                 /* set DIM, funcId, instanceId to initialize BBOB fgeneric */
00058                 params.DIM = dim[idx_dim];
00059                 params.funcId = ifun;
00060                 params.instanceId = instances[idx_instances];
00061                 /* call the BBOB initialization */
00062                 fgeneric_initialize(params);
00063 
00064                 /* now call your optimizer so that it optimizes the function
00065                  * fgeneric_evaluate or
00066                  * fgeneric_evaluate_vector(double * XX, unsigned int howMany,
00067                  *                          double * result)
00068                  */
00069 
00070                 /* The fgeneric interface can give some information:
00071                  *    e.g. fgeneric_ftarget() the target value only for termination
00072                  *         fgeneric_evaluations() the number of calls to fgeneric_evaluate 
00073                  *                 after fgeneric_initialization
00074                  *         fgeneric_best() the best value reached  
00075                  */
00076                 maxfunevals = 5. * dim[idx_dim]; /* PUT APPROPRIATE MAX. NUMBER OF FEVALS */
00077                                                  /* 5. * dim should be fine to just check everything */
00078                 minfunevals = dim[idx_dim] + 2;  /* PUT MINIMAL USEFUL NUMBER OF FEVALS */
00079                 independent_restarts = -1;
00080                 while (fgeneric_evaluations() + minfunevals <= maxfunevals)
00081                 {
00082                     if (++independent_restarts > 0) 
00083                         fgeneric_restart("independent restart");  /* additional info */
00084                     MY_OPTIMIZER(&fgeneric_evaluate, dim[idx_dim], fgeneric_ftarget(),
00085                                  maxfunevals - fgeneric_evaluations());
00086                     if (fgeneric_best() < fgeneric_ftarget())
00087                         break;
00088                 }
00089 
00090                 printf("  f%d in %d-D, instance %d: FEs=%.0f with %d restarts,", ifun, dim[idx_dim],
00091                        instances[idx_instances], fgeneric_evaluations(), independent_restarts);
00092                 printf(" fbest-ftarget=%.4e, elapsed time [h]: %.2f\n", 
00093                        fgeneric_best() - fgeneric_ftarget(), (double)(clock()-t0)/CLOCKS_PER_SEC/60./60.);
00094                 /* call the BBOB closing function to wrap things up neatly */
00095                 fgeneric_finalize();
00096             }
00097             Tval = time(NULL);
00098             printf("    date and time: %s", ctime(&Tval));
00099         }
00100         printf("---- dimension %d-D done ----\n", dim[idx_dim]);
00101     }
00102     return 0;
00103 }

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