ECF 1.5
exampleexperiment.cpp
1/* runs an entire experiment for benchmarking an arbitrary ECF algorithm,
2* on the noise-free testbed
3* or the noisy testbed (change the ifun loop in this case as given below).
4*/
5
6/**************************************************
7 * BBOB Mandatory initialization *
8 *************************************************/
9/*
10BBOB parameters defined in this file are:
11 - function id
12 - function instance
13(given in for loops, see below)
14
15All the other BBOB parameters are given in the ECF configuration file:
16 - algorithm name
17 - algorithm description
18 - dimensionality
19 - termination criteria (number of evaluations)
20as well as the actual ECF optimization algorithm.
21*/
22
23
24#include <stdio.h>
25#include <string.h>
26#include <time.h>
27#include <stdlib.h>
28#include "./bbob/bbobStructures.h" /* Include all declarations for BBOB calls */
29#include <ecf/ECF.h>
30#include "FunctionMinEvalOp.h"
31
32extern int enableOutput;
33
34
35int main(int argc, char **argv)
36{
37 unsigned int instances[15] = {1, 2, 3, 4, 5, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};
38 unsigned int ifun, idx_instances;
39 int independent_restarts;
40 double maxfunevals, minfunevals;
41
42 clock_t t0 = clock();
43 time_t Tval;
44
45 /* To make the noise deterministic. */
46 /* fgeneric_noiseseed(30); printf("seed for the noise set to: 30\n"); */
47
48 /* Function indices are from 1 to 24 (noiseless) or from 101 to 130 (noisy) */
49 /* for the noisy functions exchange the for loop with */
50 /* for (ifun = 101; ifun <= 130; ifun++) */
51 for (ifun = 1; ifun <= 24; ifun++)
52 {
53
54 for (idx_instances = 0; idx_instances < 15; idx_instances++)
55 {
56 // set up ECF
57 StateP state (new State);
58 // set the evaluation operator
60 state->setEvalOp(evalOp);
61
62 // initialize with current parameters, but skip evaluateOp
63 evalOp->experimentMode_ = true;
64 state->initialize(argc, argv);
65 evalOp->experimentMode_ = false;
66
67 // force BBOB output (overrides ECF configuration)
68 enableOutput = 1;
69 // set function ID (overrides ECF configuration)
70 state->getRegistry()->modifyEntry("coco.function", (voidP) (new uint(ifun)));
71 state->getRegistry()->modifyEntry("coco.enableoutput", (voidP) (new uint(1)));
72
73 // set function instance
74 state->getRegistry()->modifyEntry("coco.instance", (voidP) (new uint(instances[idx_instances])));
75
76 // initialize evaluator with current instance
77 state->getEvalOp()->initialize(state);
78
79
80 maxfunevals = 10; /* PUT APPROPRIATE MAX. NUMBER OF FEVALS */
81 /* 5. * dim should be fine to just check everything */
82 minfunevals = 10; /* PUT MINIMAL USEFUL NUMBER OF FEVALS */
83 independent_restarts = -1;
84 while (fgeneric_evaluations() + minfunevals <= maxfunevals)
85 {
86 if (++independent_restarts > 0)
87 fgeneric_restart("independent restart"); /* additional info */
88
89 // ECF optimization
90 state->run();
91
92 if (fgeneric_best() < fgeneric_ftarget())
93 break;
94 }
95
96 printf(" f%d in %d-D, instance %d: FEs=%.0f with %d restarts,", ifun, 10,
97 instances[idx_instances], fgeneric_evaluations(), independent_restarts);
98 printf(" fbest-ftarget=%.4e, elapsed time [h]: %.2f\n",
99 fgeneric_best() - fgeneric_ftarget(), (double)(clock()-t0)/CLOCKS_PER_SEC/60./60.);
100
101 fgeneric_finalize();
102 }
103 Tval = time(NULL);
104 printf(" date and time: %s", ctime(&Tval));
105 }
106
107 return 0;
108}
Function minimization evaluation class.
bool experimentMode_
enable COCO experiment
State class - backbone of the framework.
Definition: State.h:39