#include #include #include #include #include typedef double* p_double; //constants and variables of fitness function: #define Dim 2 #define xmin -200.0 #define xmax 200.0 #define r0 1.0 #define y0min 10.0 #define y0max 50.0 #define precision 0.001 double y_0, x_0[Dim]; //constants and variables of SADE: #define PoolSize 20 #define SelectedSize 10 #define radioactivity 0.05 #define mutation_rate 0.5 #define mutagen 1.0 #define cross_rate 0.1 int ActualSize, mutants; double Force[PoolSize], reduced_radioactivity, top; p_double *CH; void initialize_randoms ( void ) { int rseed; struct timeval tv; struct timezone tz; gettimeofday ( &tv, &tz ); rseed = tv.tv_usec + ( tv.tv_sec%4194304 )*1000; srand ( rseed ); } double random_double ( double olow, double ohigh ) { return (( double )rand()/RAND_MAX )*( ohigh-olow )+olow ; } int random_int ( int olow, int ohigh ) { return rand()%( ohigh-olow )+olow; } double fitness ( double *ox ) { double y=0.0; int i; for ( i=0; ibtg ) btg = Force[i]; } if ( start==0 ) start = SelectedSize; return btg; } void SELECT ( void ) { double *h; int i1, i2, dead, last; while ( ActualSize > SelectedSize ) { i1 = random_int ( 0,ActualSize ); i2 = random_int ( 1,ActualSize ); if ( i1==i2 ) i2--; if ( Force[i1] >= Force[i2] ) dead = i2; else dead = i1; last = ActualSize-1; h = CH[last]; CH[last] = CH[dead]; CH[dead] = h; Force[dead] = Force[last]; ActualSize--; } } void MUTATE ( void ) { double p, *x; int i, j, index; for ( i=0; i precision ) return 1; return 0; } void destroy_all ( void ) { int i; for ( i=0; i