/*_________________________________________________________ Test functions log normal adaptive mutation Selection operator: Tournament __________________________________________________________*/ \User declarations : #define SIZE 10 #define X_MIN -1. #define X_MAX 1. #define ITER 50 #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; #define N_LIM 10 int n = N_LIM; double (*Fitness)(double *, int); // pointeur sur la fonction de fitness designee dans argv[1] double Sphere(double *, int); double AckleyPath(double *, int); double Easom(double *, int); double Griewangk(double *, int); double Rastrigin(double *, int); float Rosenbrock(float *, int); float Schwefel(float *, int); float Weierstrass(float *, int); struct gpuOptions{ }; \end \User functions: //fitness function #include inline float Sphere(float x[SIZE], int n) // Ex-DeJong function 1 { float ret = 0; for (int i = 0;irandFloat(0.,1.) * 2.0 - 1.0; v2 = (float)globalRandomGenerator->randFloat(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 \GenomeClass::display: for( size_t i=0 ; igetRandomIntMax(1.); // barycentric crossover child1.x[i] = alpha*parent1.x[i] + (1.-alpha)*parent2.x[i]; //if (&child2) child2.x[i] = alpha*parent2.x[i] + (1.-alpha)*parent1.x[i]; } \end \GenomeClass::mutator : // Must return the number of mutations int NbMut=0; float pond = 1./sqrt((float)n); for (int i=0; i