Commit b99dcf89 authored by wcancino's avatar wcancino Committed by Waldo Cancino

Add BBOB 2013 benchmarks, first version, it should be polished to work

in a EASEA way.
parent 3991236c
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <limits.h>
void MY_OPTIMIZER(double(*fitnessfunction)(double*), unsigned int dim, double ftarget, double maxfunevals)
{
double * x = (double *)malloc(sizeof(double) * dim);
double f;
double iter;
unsigned int j;
if (maxfunevals > 1000000000. * dim)
maxfunevals = 1000000000. * dim;
for (iter = 0.; iter < maxfunevals; iter++)
{
/* Generate individual */
for (j = 0; j < dim; j++)
x[j] = 10. * ((double)rand() / RAND_MAX) - 5.;
/* evaluate x on the objective function */
f = fitnessfunction(x);
if (f < ftarget)
break;
}
free(x);
}
bbob2013.mak
\ No newline at end of file
#This is an example Makefile that will create the executables exampletiming and
#exampleexperiment. This Makefile can either be completed with rules to create
#the executables for your own experiment or the rules here can be added to your
#own Makefile.
#Define your compiler/linker if needed.
#CC=
#Strict options
LDFLAGS=
CFLAGS=-Wextra -Wall -ansi -pedantic
#Lenient: add/remove any compilation or linking flags that you feel are necessary or not.
# LDFLAGS=
# CFLAGS=
DIROK=dirOK.o
#Linux/Unix users can try to comment the above and uncomment the following line instead.
# DIROK=dirOK-linux.o
#Lists all executable, used by the "all" and "clean" rules.
EXECS=exampletiming exampleexperiment
all: $(EXECS)
#Add here any rules needed for your own experiments
#Example experiments:
exampletiming: MY_OPTIMIZER.o benchmarksdeclare.o $(DIROK) benchmarkshelper.o benchmarks.o benchmarksnoisy.o fgeneric.o exampletiming.o
$(CC) $(LDFLAGS) -o $@ $^ -lm
exampleexperiment: MY_OPTIMIZER.o benchmarksdeclare.o $(DIROK) benchmarkshelper.o benchmarks.o benchmarksnoisy.o fgeneric.o exampleexperiment.o
$(CC) $(LDFLAGS) -o $@ $^ -lm
#Your own experiment should have bbobStructures.h as a dependency and so should be added here.
exampletiming.o exampleexperiment.o benchmarkshelper.o fgeneric.o benchmarks.o benchmarksnoisy.o benchmarksdeclare.o : bbobStructures.h
#Benchmarks object files are optimized so they are exceptions to the implicit *.o generation rule.
benchmarks.o : benchmarks.c
$(CC) -c $(CFLAGS) -O2 $<
benchmarksnoisy.o : benchmarksnoisy.c
$(CC) -c $(CFLAGS) -O2 $<
#Clean
.PHONY: clean
#Comment the command starting with rm and uncomment the comment starting with del to make the makefile work under Windows.
clean:
rm -f *.o $(EXECS)
# del *.o exampleexperiment.exe exampletiming.exe
/**
This is program entry for STD template for bbob2013
*/
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include "COptionParser.h"
#include "CRandomGenerator.h"
#include "CEvolutionaryAlgorithm.h"
#include "global.h"
#include "bbob2013Individual.hpp"
using namespace std;
/** Global variables for the whole algorithm */
CIndividual** pPopulation = NULL;
CIndividual* bBest = NULL;
float* pEZ_MUT_PROB = NULL;
float* pEZ_XOVER_PROB = NULL;
unsigned *EZ_NB_GEN;
unsigned *EZ_current_generation;
CEvolutionaryAlgorithm* EA;
int main(int argc, char** argv){
parseArguments("bbob2013.prm",argc,argv);
ParametersImpl p;
p.setDefaultParameters(argc,argv);
CEvolutionaryAlgorithm* ea = p.newEvolutionaryAlgorithm();
EA = ea;
bbob2013Init(argc,argv);
CPopulation* pop = ea->getPopulation();
ea->runEvolutionaryLoop();
bbob2013Final(pop);
delete pop;
return 0;
}
/*_________________________________________________________
Test functions
log normal adaptive mutation
Selection operator: Tournament
__________________________________________________________*/
\User declarations :
#define SIZE 100
#define X_MIN -5.
#define X_MAX 5.
#define ITER 120
#define Abs(x) ((x) < 0 ? -(x) : (x))
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define SIGMA 1. /* mutation parameter */
#define PI 3.141592654
float pMutPerGene=0.1;
int DIM = 2;
int trialid = 1;
int funcId = 2; //passed by parameter
int instanceId = 1;
double * peaks;
double * Xopt; /*Initialized in benchmarkhelper.c*/
double Fopt;
unsigned int isInitDone=0;
\end
\User functions:
#include <math.h>
extern "C" {
#include "bbobStructures.h"
}
__device__ __host__ inline double bbob_eval( double *x)
{
return fgeneric_evaluate(x);
}
float gauss()
/* Generates a normally distributed random value with variance 1 and 0 mean.
Algorithm based on "gasdev" from Numerical recipes' pg. 203. */
{
static int iset = 0;
float gset = 0.0;
float v1 = 0.0, v2 = 0.0, r = 0.0;
float factor = 0.0;
if (iset) {
iset = 0;
return gset;
}
else {
do {
v1 = (float)random(0.,1.) * 2.0 - 1.0;
v2 = (float)random(0.,1.) * 2.0 - 1.0;
r = v1 * v1 + v2 * v2;
}
while (r > 1.0);
factor = sqrt (-2.0 * log (r) / r);
gset = v1 * factor;
iset = 1;
return (v2 * factor);
}
}
\end
\User CUDA:
\end
\Before everything else function:
fgeneric_initialize();
\end
\After everything else function:
//cout << "After everything else function called" << endl;
fgeneric_finalize();
\end
\At the beginning of each generation function:
\end
\At the end of each generation function:
//cout << "At the end of each generation function called" << endl;
\end
\At each generation before reduce function:
//cout << "At each generation before replacement function called" << endl;
\end
\User classes :
GenomeClass {
double *x;
double *sigma; // auto-adaptative mutation parameter
}
\end
\GenomeClass::display:
/* for( size_t i=0 ; i<SIZE ; i++){ */
/* // cout << Genome.x[i] << ":" << Genome.sigma[i] << "|"; */
/* printf("%.02f:%.02f|",Genome.x[i],Genome.sigma[i]); */
/* } */
\end
\GenomeClass::initialiser : // "initializer" is also accepted
Genome.x = (double *) malloc( DIM * sizeof(double) );
Genome.sigma = (double *) malloc( DIM * sizeof(double) );
for(int i=0; i<DIM; i++ ) {
Genome.x[i] = (double)random(X_MIN,X_MAX);
Genome.sigma[i]=(double)random(0.,0.5);
}
\end
\GenomeClass::crossover :
for (int i=0; i<DIM; i++)
{
float alpha = (float)random(0.,1.); // barycentric crossover
child.x[i] = alpha*parent1.x[i] + (1.-alpha)*parent2.x[i];
}
\end
\GenomeClass::mutator : // Must return the number of mutations
int NbMut=0;
float pond = 1./sqrt((float)DIM);
for (int i=0; i<DIM; i++)
if (tossCoin(pMutPerGene)){
NbMut++;
Genome.sigma[i] = Genome.sigma[i] * exp(SIGMA*pond*(float)gauss());
Genome.sigma[i] = MIN(0.5,Genome.sigma[i]);
Genome.sigma[i] = MAX(0.,Genome.sigma[i]);
Genome.x[i] += Genome.sigma[i]*(float)gauss();
Genome.x[i] = MIN(X_MAX,Genome.x[i]); // pour eviter les depassements
Genome.x[i] = MAX(X_MIN,Genome.x[i]);
}
return NbMut;
\end
\GenomeClass::evaluator : // Returns the score
double Score= 0.0;
Score= bbob_eval(Genome.x);
//Score= rosenbrock(Genome.x);
return Score;
\end
\User Makefile options:
CXXFLAGS+=-I/usr/local/cuda/common/inc/ -I/usr/local/cuda/include/ -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
LDFLAGS+=-lgfal_pthr -llcg_util
\end
\Default run parameters : // Please let the parameters appear in this order
Number of generations : 100 // NB_GEN
Time limit: 0 // In seconds, 0 to deactivate
Population size : 2048 //POP_SIZE
Offspring size : 2048 // 40%
Mutation probability : 1 // MUT_PROB
Crossover probability : 1 // XOVER_PROB
Evaluator goal : minimise // Maximise
Selection operator: Tournament 2.0
Surviving parents: 100%//perceor absolute
Surviving offspring: 100%
Reduce parents operator: Tournament 2
Reduce offspring operator: Tournament 2
Final reduce operator: Tournament 2
Elitism: Strong //Weak or Strong
Elite: 1
Print stats: true //Default: 1
Generate csv stats file:false
Generate gnuplot script:false
Generate R script:false
Plot stats:true //Default: 0
Remote island model: false
IP file: ip.txt //File containing all the remote island's IP
Experiment ID: weierstrass
Grid Working Path: lfn:/grid/vo.complex-systems.eu/easea/experiments/
Server port : 2929
Migration probability: 0.33
Save population: false
Start from file:false
\end
This diff is collapsed.
#ifndef PROBLEM_DEP_H
#define PROBLEM_DEP_H
//#include "CRandomGenerator.h"
#include <stdlib.h>
#include <iostream>
#include <CIndividual.h>
#include <Parameters.h>
#include <string>
using namespace std;
class CRandomGenerator;
class CSelectionOperator;
class CGenerationalCriterion;
class CEvolutionaryAlgorithm;
class CPopulation;
class Parameters;
class IndividualImpl : public CIndividual {
public: // in bbob2013 the genome is public (for user functions,...)
// Class members
// Class members
double *sigma;
double *x;
public:
IndividualImpl();
IndividualImpl(const IndividualImpl& indiv);
virtual ~IndividualImpl();
float evaluate();
static unsigned getCrossoverArrity(){ return 2; }
float getFitness(){ return this->fitness; }
CIndividual* crossover(CIndividual** p2);
void printOn(std::ostream& O) const;
CIndividual* clone();
unsigned mutate(float pMutationPerGene);
void boundChecking();
string serialize();
void deserialize(string EASEA_Line);
friend std::ostream& operator << (std::ostream& O, const IndividualImpl& B) ;
void initRandomGenerator(CRandomGenerator* rg){ IndividualImpl::rg = rg;}
};
class ParametersImpl : public Parameters {
public:
void setDefaultParameters(int argc, char** argv);
CEvolutionaryAlgorithm* newEvolutionaryAlgorithm();
};
/**
* @TODO ces functions devraient s'appeler weierstrassInit, weierstrassFinal etc... (en gros bbob2013Final dans le tpl).
*
*/
void bbob2013Init(int argc, char** argv);
void bbob2013Final(CPopulation* pop);
void bbob2013BeginningGenerationFunction(CEvolutionaryAlgorithm* evolutionaryAlgorithm);
void bbob2013EndGenerationFunction(CEvolutionaryAlgorithm* evolutionaryAlgorithm);
void bbob2013GenerationFunctionBeforeReplacement(CEvolutionaryAlgorithm* evolutionaryAlgorithm);
class EvolutionaryAlgorithmImpl: public CEvolutionaryAlgorithm {
public:
EvolutionaryAlgorithmImpl(Parameters* params);
virtual ~EvolutionaryAlgorithmImpl();
void initializeParentPopulation();
};
#endif /* PROBLEM_DEP_H */
#ifndef _bbobStructures_H
#define _bbobStructures_H
/* some structures, to try to imitate that gorgious Matlab Code !!!
*/
/* sometimes, M_PI is not defined ????? */
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
/* the return type of all benchmark functions: 2 doubles, the true value and the noisy value - are equal in case of non-noisy functions */
struct twoDoubles {
double Ftrue;
double Fval;
};
typedef struct twoDoubles TwoDoubles;
/* and now the type of the benchmark functions themselves */
typedef struct twoDoubles (*bbobFunction)(double *);
/* need to put all parameters into a single structure that
can be passed around
*/
/* all static char* (increase if your system uses huge file names) */
#define DefaultStringLength 1024
/* for not having to allocate the x in struct lastEvalStruct */
#define DIM_MAX 200
/* These ones might be defined somewhere in the C headers, but in case it's system-dependent ... */
/*#define MAX_FLOAT 1.0E308
#define MIN_FLOAT 1.0E-308
#define MAX_INT 32767*/
void fgeneric_initialize();
double fgeneric_finalize(void);
double fgeneric_evaluate(double * X);
double fgeneric_ftarget(void);
#endif
This diff is collapsed.
/*Global definitions*/
int DIM;
int trialid;
double * peaks;
double * Xopt; /*Initialized in benchmarkhelper.c*/
double Fopt;
unsigned int isInitDone;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
/*Global declarations */
extern int DIM; // passed by parameter
extern int trialid;
extern int funcId; //passed by parameter
extern int instanceId;
extern double * peaks;
extern double * Xopt;
extern double Fopt;
extern unsigned int isInitDone;
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include "benchmarksdeclare.h"
#include "bbobStructures.h"
#define TOL 1e-8
static int seed = -1;
static int seedn = -1;
static double * gval;
static double * gval2;
static double * gvect;
static double * uniftmp;
static double * tmpvect;
#ifdef __cplusplus /* Might be a problem when compiling with g++ on Mac OS X */
double round(double a) throw() {
return floor(a + 0.5);
}
double fmin(double a, double b) throw() {
return b < a ? b : a;
}
double fmax(double a, double b) throw() {
return b > a ? b : a;
}
#else
double round(double a){
return floor(a + 0.5);
}
double fmin(double a, double b){
return b < a ? b : a;
}
double fmax(double a, double b){
return b > a ? b : a;
}
#endif
/* set the seed for the noise.
* If the seeds are larger than 1e9 they are set back to 1 in randn and myrand.
*/
void setNoiseSeed(unsigned int _seed, unsigned int _seedn)
{
seed = _seed;
seedn = _seedn;
}
void unif(double* r, int N, int inseed)
{
/* generates N uniform numbers with starting seed*/
int aktseed;
int tmp;
int rgrand[32];
int aktrand;
int i;
if (inseed < 0)
inseed = -inseed;
if (inseed < 1)
inseed = 1;
aktseed = inseed;
for (i = 39; i >= 0; i--)
{
tmp = (int)floor((double)aktseed/(double)127773);
aktseed = 16807 * (aktseed - tmp * 127773) - 2836 * tmp;
if (aktseed < 0)
aktseed = aktseed + 2147483647;
if (i < 32)
rgrand[i] = aktseed;
}
aktrand = rgrand[0];
for (i = 0; i < N; i++)
{
tmp = (int)floor((double)aktseed/(double)127773);
aktseed = 16807 * (aktseed - tmp * 127773) - 2836 * tmp;
if (aktseed < 0)
aktseed = aktseed + 2147483647;
tmp = (int)floor((double)aktrand / (double)67108865);
aktrand = rgrand[tmp];
rgrand[tmp] = aktseed;
r[i] = (double)aktrand/2.147483647e9;
if (r[i] == 0.)
{
printf("Warning: zero sampled(?), set to 1e-99.\n");
r[i] = 1e-99;
}
}
return;
}
void gauss(double * g, int N, int seed)
{
/* samples N standard normally distributed numbers
being the same for a given seed.*/
int i;
unif(uniftmp, 2*N, seed);
for (i = 0; i < N; i++)
{
g[i] = sqrt(-2*log(uniftmp[i])) * cos(2*M_PI*uniftmp[N+i]);
if (g[i] == 0.)
g[i] = 1e-99;
}
return;
}
void computeXopt(int seed, int _DIM) {
int i;
unif(tmpvect, _DIM, seed);
printf("Computing Xopt ... ->\n");
for (i = 0; i < _DIM; i++)
{
Xopt[i] = 8 * floor(1e4 * tmpvect[i])/1e4 - 4;
if (Xopt[i] == 0.0)
Xopt[i] = -1e-5;
printf("%10.4f ,",Xopt[i]);
}
printf(" \n");
}
void monotoneTFosc(double* f) {
double a = 0.1;
int i;
for (i = 0; i < DIM; i++)
{
if (f[i] > 0)
{
f[i] = log(f[i])/a;
f[i] = pow(exp(f[i] + 0.49*(sin(f[i]) + sin(0.79*f[i]))), a);
}
else if (f[i] < 0)
{
f[i] = log(-f[i])/a;
f[i] = -pow(exp(f[i] + 0.49*(sin(0.55 * f[i]) + sin(0.31*f[i]))), a);
}
}
}
void freeStarStar(double** M, int m)
{
int i;
for (i = 0; i < m; i++)
{
free(M[i]);
}
free(M);
return;
}
double** reshape(double** B, double* vector, int m, int n)
{
int i, j;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
B[i][j] = vector[j * m + i];
}
}
return B;
}
void computeRotation(double ** B, int seed, int _DIM)
{
double prod;
int i, j, k; /*Loop over pairs of column vectors*/
gauss(gvect, _DIM * _DIM, seed);
reshape(B, gvect, _DIM, _DIM);
/*1st coordinate is row, 2nd is column.*/
for (i = 0; i < _DIM; i++)
{
for (j = 0; j < i; j++)
{
prod = 0;
for (k = 0; k < _DIM; k++)
{
prod += B[k][i] * B[k][j];
}
for (k = 0; k < _DIM; k++)
{
B[k][i] -= prod * B[k][j];
}
}
prod = 0;
for (k = 0; k < _DIM; k++)
{
prod += B[k][i] * B[k][i];
}
for (k = 0; k < _DIM; k++)
{
B[k][i] /= sqrt(prod);
}
}
}