Commit 9de1a87d authored by Waldo Cancino's avatar Waldo Cancino

Delete unnecessary files, correct template

parent 600acd59
#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;
}
......@@ -152,7 +152,7 @@ return NbMut;
\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
LDFLAGS+=
OBJS+= benchmarks.o benchmarksnoisy.o fgeneric.o benchmarkshelper.o
\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 */
/*Global definitions*/
int DIM;
int trialid;
double * peaks;
double * Xopt; /*Initialized in benchmarkhelper.c*/
double Fopt;
unsigned int isInitDone;
/* runs an entire experiment for benchmarking MY_OPTIMIZER
* on the noise-free testbed
* or the noisy testbed (change the ifun loop in this case as given below).
*/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include "bbobStructures.h" /* Include all declarations for BBOB calls */
/* include all declarations for your own optimizer here */
void MY_OPTIMIZER(double(*fitnessfunction)(double*), unsigned int dim, double ftarget,
double maxfunevals);
int main(void)
{
unsigned int dim[6] = {2, 3, 5, 10, 20, 40};
unsigned int instances[15] = {1, 2, 3, 4, 5, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40};
unsigned int idx_dim, ifun, idx_instances, seed;
int independent_restarts;
double maxfunevals, minfunevals;
clock_t t0 = clock();
time_t Tval;
/**************************************************
* BBOB Mandatory initialization *
*************************************************/
/* retrieve all default parameters of BBOB calls */
ParamStruct params = fgeneric_getDefaultPARAMS();
/* modify the following parameters, choosing a different setting
* for each new experiment */
strcpy(params.dataPath, "PUT_MY_BBOB_DATA_PATH"); /* different folder for each experiment! */
/* please beforehand run from the command-line 'python createfolders.py PUT_MY_BBOB_DATA_PATH'
* to create the necessary folder structure to run an experiment. */
strcpy(params.algName, "PUT ALGORITHM NAME");
strcpy(params.comments, "PUT MORE DETAILED INFORMATION, PARAMETER SETTINGS ETC");
seed = time(NULL);
srand(seed); /* used by MY_OPTIMIZER */
printf("random seed set to %d\n", seed);
/* To make the noise deterministic. */
/* fgeneric_noiseseed(30); printf("seed for the noise set to: 30\n"); */
/* now the main loop */
for (idx_dim = 0; idx_dim < 6; idx_dim++)
{
/* Function indices are from 1 to 24 (noiseless) or from 101 to 130 (noisy) */
/* for the noisy functions exchange the for loop with */
/* for (ifun = 101; ifun <= 130; ifun++) */
for (ifun = 1; ifun <= 24; ifun++)
{
for (idx_instances = 0; idx_instances < 15; idx_instances++)
{
/* set DIM, funcId, instanceId to initialize BBOB fgeneric */
params.DIM = dim[idx_dim];
params.funcId = ifun;
params.instanceId = instances[idx_instances];
/* call the BBOB initialization */
fgeneric_initialize(params);
/* now call your optimizer so that it optimizes the function
* fgeneric_evaluate or
* fgeneric_evaluate_vector(double * XX, unsigned int howMany,
* double * result)
*/
/* The fgeneric interface can give some information:
* e.g. fgeneric_ftarget() the target value only for termination
* fgeneric_evaluations() the number of calls to fgeneric_evaluate
* after fgeneric_initialization
* fgeneric_best() the best value reached
*/
maxfunevals = 5. * dim[idx_dim]; /* PUT APPROPRIATE MAX. NUMBER OF FEVALS */
/* 5. * dim should be fine to just check everything */
minfunevals = dim[idx_dim] + 2; /* PUT MINIMAL USEFUL NUMBER OF FEVALS */
independent_restarts = -1;
while (fgeneric_evaluations() + minfunevals <= maxfunevals)
{
if (++independent_restarts > 0)
fgeneric_restart("independent restart"); /* additional info */
MY_OPTIMIZER(&fgeneric_evaluate, dim[idx_dim], fgeneric_ftarget(),
maxfunevals - fgeneric_evaluations());
if (fgeneric_best() < fgeneric_ftarget())
break;
}
printf(" f%d in %d-D, instance %d: FEs=%.0f with %d restarts,", ifun, dim[idx_dim],
instances[idx_instances], fgeneric_evaluations(), independent_restarts);
printf(" fbest-ftarget=%.4e, elapsed time [h]: %.2f\n",
fgeneric_best() - fgeneric_ftarget(), (double)(clock()-t0)/CLOCKS_PER_SEC/60./60.);
/* call the BBOB closing function to wrap things up neatly */
fgeneric_finalize();
}
Tval = time(NULL);
printf(" date and time: %s", ctime(&Tval));
}
printf("---- dimension %d-D done ----\n", dim[idx_dim]);
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment