17#define E 2.7182818284590452353602874713526625
18#define PI 3.1415926535897932384626433832795029
20void sphere_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
21void ellips_func(
double *,
double *,
int ,
double *,
double *,
int,
int);
22void bent_cigar_func(
double *,
double *,
int ,
double *,
double *,
int,
int);
23void discus_func(
double *,
double *,
int ,
double *,
double *,
int,
int);
24void dif_powers_func(
double *,
double *,
int ,
double *,
double *,
int,
int);
25void rosenbrock_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
26void schaffer_F7_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
27void ackley_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
28void rastrigin_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
29void weierstrass_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
30void griewank_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
31void schwefel_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
32void katsuura_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
33void bi_rastrigin_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
34void grie_rosen_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
35void escaffer6_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
36void step_rastrigin_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
37void happycat_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
38void hgbat_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
40void hf01 (
double *,
double *,
int,
double *,
double *,
int *,
int,
int);
41void hf02 (
double *,
double *,
int,
double *,
double *,
int *,
int,
int);
42void hf03 (
double *,
double *,
int,
double *,
double *,
int *,
int,
int);
43void hf04 (
double *,
double *,
int,
double *,
double *,
int *,
int,
int);
44void hf05 (
double *,
double *,
int,
double *,
double *,
int *,
int,
int);
45void hf06 (
double *,
double *,
int,
double *,
double *,
int *,
int,
int);
47void cf01 (
double *,
double *,
int ,
double *,
double *,
int);
48void cf02 (
double *,
double *,
int ,
double *,
double *,
int);
49void cf03 (
double *,
double *,
int ,
double *,
double *,
int);
50void cf04 (
double *,
double *,
int ,
double *,
double *,
int);
51void cf05 (
double *,
double *,
int ,
double *,
double *,
int);
52void cf06 (
double *,
double *,
int ,
double *,
double *,
int);
53void cf07 (
double *,
double *,
int ,
double *,
double *,
int *,
int);
54void cf08 (
double *,
double *,
int ,
double *,
double *,
int *,
int);
56void shiftfunc (
double*,
double*,
int,
double*);
57void rotatefunc (
double*,
double*,
int,
double*);
58void sr_func (
double *,
double *,
int,
double*,
double*,
double,
int,
int);
59void asyfunc (
double *,
double *x,
int,
double);
60void oszfunc (
double *,
double *,
int);
61void cf_cal(
double *,
double *,
int,
double *,
double *,
double *,
double *,
int);
63extern double *OShift,*M,*y,*z,*x_bound;
64extern int ini_flag,n_flag,func_flag,*SS;
67void cec14_test_func(
double *x,
double *f,
int nx,
int mx,
int func_num)
72 if ((n_flag!=nx)||(func_flag!=func_num))
87 y=(
double *)malloc(
sizeof(
double) * nx);
88 z=(
double *)malloc(
sizeof(
double) * nx);
89 x_bound=(
double *)malloc(
sizeof(
double) * nx);
93 if (!(nx==2||nx==10||nx==20||nx==30||nx==50||nx==100))
95 printf(
"\nError: Test functions are only defined for D=2,10,20,30,50,100.\n");
97 if (nx==2&&((func_num>=17&&func_num<=22)||(func_num>=29&&func_num<=30)))
99 printf(
"\nError: hf01,hf02,hf03,hf04,hf05,hf06,cf07&cf08 are NOT defined for D=2.\n");
103 sprintf(FileName,
"input_data/M_%d_D%d.txt", func_num,nx);
104 fpt = fopen(FileName,
"r");
107 printf(
"\n Error: Cannot open input file for reading \n");
111 M=(
double*)malloc(nx*nx*
sizeof(
double));
113 printf(
"\nError: there is insufficient memory available!\n");
114 for (i=0; i<nx*nx; i++)
116 fscanf(fpt,
"%lf",&M[i]);
121 M=(
double*)malloc(cf_num*nx*nx*
sizeof(
double));
123 printf(
"\nError: there is insufficient memory available!\n");
124 for (i=0; i<cf_num*nx*nx; i++)
126 fscanf(fpt,
"%lf",&M[i]);
132 sprintf(FileName,
"input_data/shift_data_%d.txt", func_num);
133 fpt = fopen(FileName,
"r");
136 printf(
"\n Error: Cannot open input file for reading \n");
141 OShift=(
double *)malloc(nx*
sizeof(
double));
143 printf(
"\nError: there is insufficient memory available!\n");
146 fscanf(fpt,
"%lf",&OShift[i]);
151 OShift=(
double *)malloc(nx*cf_num*
sizeof(
double));
153 printf(
"\nError: there is insufficient memory available!\n");
154 for(i=0;i<cf_num-1;i++)
158 fscanf(fpt,
"%lf",&OShift[i*nx+j]);
160 fscanf(fpt,
"%*[^\n]%*c");
164 fscanf(fpt,
"%lf",&OShift[(cf_num-1)*nx+j]);
173 if (func_num>=17&&func_num<=22)
175 sprintf(FileName,
"input_data/shuffle_data_%d_D%d.txt", func_num, nx);
176 fpt = fopen(FileName,
"r");
179 printf(
"\n Error: Cannot open input file for reading \n");
181 SS=(
int *)malloc(nx*
sizeof(
int));
183 printf(
"\nError: there is insufficient memory available!\n");
186 fscanf(fpt,
"%d",&SS[i]);
190 else if (func_num==29||func_num==30)
192 sprintf(FileName,
"input_data/shuffle_data_%d_D%d.txt", func_num, nx);
193 fpt = fopen(FileName,
"r");
196 printf(
"\n Error: Cannot open input file for reading \n");
198 SS=(
int *)malloc(nx*cf_num*
sizeof(
int));
200 printf(
"\nError: there is insufficient memory available!\n");
201 for(i=0;i<nx*cf_num;i++)
203 fscanf(fpt,
"%d",&SS[i]);
216 for (i = 0; i < mx; i++)
221 ellips_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
225 bent_cigar_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
229 discus_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
233 rosenbrock_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
237 ackley_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
241 weierstrass_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
245 griewank_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
249 rastrigin_func(&x[i*nx],&f[i],nx,OShift,M,1,0);
253 rastrigin_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
257 schwefel_func(&x[i*nx],&f[i],nx,OShift,M,1,0);
261 schwefel_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
265 katsuura_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
269 happycat_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
273 hgbat_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
277 grie_rosen_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
281 escaffer6_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
285 hf01(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
289 hf02(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
293 hf03(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
297 hf04(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
301 hf05(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
305 hf06(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
309 cf01(&x[i*nx],&f[i],nx,OShift,M,1);
313 cf02(&x[i*nx],&f[i],nx,OShift,M,1);
317 cf03(&x[i*nx],&f[i],nx,OShift,M,1);
321 cf04(&x[i*nx],&f[i],nx,OShift,M,1);
325 cf05(&x[i*nx],&f[i],nx,OShift,M,1);
329 cf06(&x[i*nx],&f[i],nx,OShift,M,1);
333 cf07(&x[i*nx],&f[i],nx,OShift,M,SS,1);
337 cf08(&x[i*nx],&f[i],nx,OShift,M,SS,1);
341 printf(
"\nError: There are only 30 test functions in this test suite!\n");
350void sphere_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
354 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
364void ellips_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
368 sr_func (x, z, nx, Os, Mr,1.0, s_flag, r_flag);
371 f[0] += pow(10.0,6.0*i/(nx-1))*z[i]*z[i];
375void bent_cigar_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
378 sr_func (x, z, nx, Os, Mr,1.0, s_flag, r_flag);
383 f[0] += pow(10.0,6.0)*z[i]*z[i];
389void discus_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
392 sr_func (x, z, nx, Os, Mr,1.0, s_flag, r_flag);
393 f[0] = pow(10.0,6.0)*z[0]*z[0];
400void dif_powers_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
404 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
408 f[0] += pow(fabs(z[i]),2+4*i/(nx-1));
414void rosenbrock_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
419 sr_func (x, z, nx, Os, Mr, 2.048/100.0, s_flag, r_flag);
421 for (i=0; i<nx-1; i++)
424 tmp1=z[i]*z[i]-z[i+1];
426 f[0] += 100.0*tmp1*tmp1 +tmp2*tmp2;
430void schaffer_F7_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
435 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
436 for (i=0; i<nx-1; i++)
438 z[i]=pow(y[i]*y[i]+y[i+1]*y[i+1],0.5);
439 tmp=sin(50.0*pow(z[i],0.2));
440 f[0] += pow(z[i],0.5)+pow(z[i],0.5)*tmp*tmp ;
442 f[0] = f[0]*f[0]/(nx-1)/(nx-1);
445void ackley_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
452 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
457 sum2 += cos(2.0*PI*z[i]);
459 sum1 = -0.2*sqrt(sum1/nx);
461 f[0] = E - 20.0*exp(sum1) - exp(sum2) +20.0;
465void weierstrass_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
468 double sum,sum2, a, b;
474 sr_func (x, z, nx, Os, Mr, 0.5/100.0, s_flag, r_flag);
480 for (j=0; j<=k_max; j++)
482 sum += pow(a,j)*cos(2.0*PI*pow(b,j)*(z[i]+0.5));
483 sum2 += pow(a,j)*cos(2.0*PI*pow(b,j)*0.5);
491void griewank_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
498 sr_func (x, z, nx, Os, Mr, 600.0/100.0, s_flag, r_flag);
503 p *= cos(z[i]/sqrt(1.0+i));
505 f[0] = 1.0 + s/4000.0 - p;
508void rastrigin_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
513 sr_func (x, z, nx, Os, Mr, 5.12/100.0, s_flag, r_flag);
517 f[0] += (z[i]*z[i] - 10.0*cos(2.0*PI*z[i]) + 10.0);
521void step_rastrigin_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
527 if (fabs(y[i]-Os[i])>0.5)
528 y[i]=Os[i]+floor(2*(y[i]-Os[i])+0.5)/2;
531 sr_func (x, z, nx, Os, Mr, 5.12/100.0, s_flag, r_flag);
535 f[0] += (z[i]*z[i] - 10.0*cos(2.0*PI*z[i]) + 10.0);
539void schwefel_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
545 sr_func (x, z, nx, Os, Mr, 1000.0/100.0, s_flag, r_flag);
549 z[i] += 4.209687462275036e+002;
552 f[0]-=(500.0-fmod(z[i],500))*sin(pow(500.0-fmod(z[i],500),0.5));
553 tmp=(z[i]-500.0)/100;
558 f[0]-=(-500.0+fmod(fabs(z[i]),500))*sin(pow(500.0-fmod(fabs(z[i]),500),0.5));
559 tmp=(z[i]+500.0)/100;
563 f[0]-=z[i]*sin(pow(fabs(z[i]),0.5));
565 f[0] +=4.189828872724338e+002*nx;
569void katsuura_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
572 double temp,tmp1,tmp2,tmp3;
574 tmp3=pow(1.0*nx,1.2);
576 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag);
581 for (j=1; j<=32; j++)
585 temp += fabs(tmp2-floor(tmp2+0.5))/tmp1;
587 f[0] *= pow(1.0+(i+1)*temp,10.0/tmp3);
594void bi_rastrigin_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
597 double mu0=2.5,d=1.0,s,mu1,tmp,tmp1,tmp2;
599 tmpx=(
double *)malloc(
sizeof(
double) * nx);
600 s=1.0-1.0/(2.0*pow(nx+20.0,0.5)-8.2);
601 mu1=-pow((mu0*mu0-d)/s,0.5);
604 shiftfunc(x, y, nx, Os);
617 for (i = 0; i < nx; i++)
642 rotatefunc(z, y, nx, Mr);
645 tmp+=cos(2.0*PI*y[i]);
651 f[0] += 10.0*(nx-tmp);
657 tmp+=cos(2.0*PI*z[i]);
663 f[0] += 10.0*(nx-tmp);
669void grie_rosen_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
672 double temp,tmp1,tmp2;
675 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag);
678 for (i=0; i<nx-1; i++)
681 tmp1 = z[i]*z[i]-z[i+1];
683 temp = 100.0*tmp1*tmp1 + tmp2*tmp2;
684 f[0] += (temp*temp)/4000.0 - cos(temp) + 1.0;
686 tmp1 = z[nx-1]*z[nx-1]-z[0];
688 temp = 100.0*tmp1*tmp1 + tmp2*tmp2;
689 f[0] += (temp*temp)/4000.0 - cos(temp) + 1.0 ;
693void escaffer6_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
698 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
701 for (i=0; i<nx-1; i++)
703 temp1 = sin(sqrt(z[i]*z[i]+z[i+1]*z[i+1]));
705 temp2 = 1.0 + 0.001*(z[i]*z[i]+z[i+1]*z[i+1]);
706 f[0] += 0.5 + (temp1-0.5)/(temp2*temp2);
708 temp1 = sin(sqrt(z[nx-1]*z[nx-1]+z[0]*z[0]));
710 temp2 = 1.0 + 0.001*(z[nx-1]*z[nx-1]+z[0]*z[0]);
711 f[0] += 0.5 + (temp1-0.5)/(temp2*temp2);
714void happycat_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
718 double alpha,r2,sum_z;
721 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag);
731 f[0]=pow(fabs(r2-nx),2*alpha) + (0.5*r2 + sum_z)/nx + 0.5;
734void hgbat_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
738 double alpha,r2,sum_z;
741 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag);
751 f[0]=pow(fabs(pow(r2,2.0)-pow(sum_z,2.0)),2*alpha) + (0.5*r2 + sum_z)/nx + 0.5;
754void hf01 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *S,
int s_flag,
int r_flag)
759 double Gp[3]={0.3,0.3,0.4};
762 for (i=0; i<cf_num-1; i++)
764 G_nx[i] = ceil(Gp[i]*nx);
767 G_nx[cf_num-1]=nx-tmp;
769 for (i=1; i<cf_num; i++)
771 G[i] = G[i-1]+G_nx[i-1];
774 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
781 schwefel_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
783 rastrigin_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
785 ellips_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
787 for(i=0;i<cf_num;i++)
793void hf02 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *S,
int s_flag,
int r_flag)
798 double Gp[3]={0.3,0.3,0.4};
801 for (i=0; i<cf_num-1; i++)
803 G_nx[i] = ceil(Gp[i]*nx);
806 G_nx[cf_num-1]=nx-tmp;
809 for (i=1; i<cf_num; i++)
811 G[i] = G[i-1]+G_nx[i-1];
814 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
821 bent_cigar_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
823 hgbat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
825 rastrigin_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
828 for(i=0;i<cf_num;i++)
834void hf03 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *S,
int s_flag,
int r_flag)
839 double Gp[4]={0.2,0.2,0.3,0.3};
842 for (i=0; i<cf_num-1; i++)
844 G_nx[i] = ceil(Gp[i]*nx);
847 G_nx[cf_num-1]=nx-tmp;
850 for (i=1; i<cf_num; i++)
852 G[i] = G[i-1]+G_nx[i-1];
855 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
862 griewank_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
864 weierstrass_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
866 rosenbrock_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
868 escaffer6_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
871 for(i=0;i<cf_num;i++)
877void hf04 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *S,
int s_flag,
int r_flag)
882 double Gp[4]={0.2,0.2,0.3,0.3};
885 for (i=0; i<cf_num-1; i++)
887 G_nx[i] = ceil(Gp[i]*nx);
890 G_nx[cf_num-1]=nx-tmp;
893 for (i=1; i<cf_num; i++)
895 G[i] = G[i-1]+G_nx[i-1];
898 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
905 hgbat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
907 discus_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
909 grie_rosen_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
911 rastrigin_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
914 for(i=0;i<cf_num;i++)
919void hf05 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *S,
int s_flag,
int r_flag)
924 double Gp[5]={0.1,0.2,0.2,0.2,0.3};
927 for (i=0; i<cf_num-1; i++)
929 G_nx[i] = ceil(Gp[i]*nx);
932 G_nx[cf_num-1]=nx-tmp;
935 for (i=1; i<cf_num; i++)
937 G[i] = G[i-1]+G_nx[i-1];
940 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
947 escaffer6_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
949 hgbat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
951 rosenbrock_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
953 schwefel_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
955 ellips_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
958 for(i=0;i<cf_num;i++)
964void hf06 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *S,
int s_flag,
int r_flag)
969 double Gp[5]={0.1,0.2,0.2,0.2,0.3};
972 for (i=0; i<cf_num-1; i++)
974 G_nx[i] = ceil(Gp[i]*nx);
977 G_nx[cf_num-1]=nx-tmp;
980 for (i=1; i<cf_num; i++)
982 G[i] = G[i-1]+G_nx[i-1];
985 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
992 katsuura_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
994 happycat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
996 grie_rosen_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
998 schwefel_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
1000 ackley_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
1002 for(i=0;i<cf_num;i++)
1008void cf01 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int r_flag)
1012 double delta[5] = {10, 20, 30, 40, 50};
1013 double bias[5] = {0, 100, 200, 300, 400};
1016 rosenbrock_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1017 fit[i]=10000*fit[i]/1e+4;
1019 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1020 fit[i]=10000*fit[i]/1e+10;
1022 bent_cigar_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1023 fit[i]=10000*fit[i]/1e+30;
1025 discus_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1026 fit[i]=10000*fit[i]/1e+10;
1028 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,0);
1029 fit[i]=10000*fit[i]/1e+10;
1030 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1033void cf02 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int r_flag)
1037 double delta[3] = {20,20,20};
1038 double bias[3] = {0, 100, 200};
1041 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,0);
1043 rastrigin_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1045 hgbat_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1046 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1049void cf03 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int r_flag)
1053 double delta[3] = {10,30,50};
1054 double bias[3] = {0, 100, 200};
1056 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1057 fit[i]=1000*fit[i]/4e+3;
1059 rastrigin_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1060 fit[i]=1000*fit[i]/1e+3;
1062 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1063 fit[i]=1000*fit[i]/1e+10;
1064 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1067void cf04 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int r_flag)
1071 double delta[5] = {10,10,10,10,10};
1072 double bias[5] = {0, 100, 200, 300, 400};
1074 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1075 fit[i]=1000*fit[i]/4e+3;
1077 happycat_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1078 fit[i]=1000*fit[i]/1e+3;
1080 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1081 fit[i]=1000*fit[i]/1e+10;
1083 weierstrass_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1084 fit[i]=1000*fit[i]/400;
1086 griewank_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1087 fit[i]=1000*fit[i]/100;
1088 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1091void cf05 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int r_flag)
1095 double delta[5] = {10,10,10,20,20};
1096 double bias[5] = {0, 100, 200, 300, 400};
1098 hgbat_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1099 fit[i]=10000*fit[i]/1000;
1101 rastrigin_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1102 fit[i]=10000*fit[i]/1e+3;
1104 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1105 fit[i]=10000*fit[i]/4e+3;
1107 weierstrass_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1108 fit[i]=10000*fit[i]/400;
1110 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1111 fit[i]=10000*fit[i]/1e+10;
1112 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1115void cf06 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int r_flag)
1119 double delta[5] = {10,20,30,40,50};
1120 double bias[5] = {0, 100, 200, 300, 400};
1122 grie_rosen_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1123 fit[i]=10000*fit[i]/4e+3;
1125 happycat_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1126 fit[i]=10000*fit[i]/1e+3;
1128 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1129 fit[i]=10000*fit[i]/4e+3;
1131 escaffer6_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1132 fit[i]=10000*fit[i]/2e+7;
1134 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1135 fit[i]=10000*fit[i]/1e+10;
1136 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1139void cf07 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *SS,
int r_flag)
1143 double delta[3] = {10,30,50};
1144 double bias[3] = {0, 100, 200};
1146 hf01(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1148 hf02(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1150 hf03(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1151 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1154void cf08 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *SS,
int r_flag)
1158 double delta[3] = {10,30,50};
1159 double bias[3] = {0, 100, 200};
1161 hf04(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1163 hf05(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1165 hf06(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1166 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1171void shiftfunc (
double *x,
double *xshift,
int nx,
double *Os)
1174 for (i=0; i<nx; i++)
1176 xshift[i]=x[i]-Os[i];
1180void rotatefunc (
double *x,
double *xrot,
int nx,
double *Mr)
1183 for (i=0; i<nx; i++)
1186 for (j=0; j<nx; j++)
1188 xrot[i]=xrot[i]+x[j]*Mr[i*nx+j];
1193void sr_func (
double *x,
double *sr_x,
int nx,
double *Os,
double *Mr,
double sh_rate,
int s_flag,
int r_flag)
1200 shiftfunc(x, y, nx, Os);
1201 for (i=0; i<nx; i++)
1205 rotatefunc(y, sr_x, nx, Mr);
1209 shiftfunc(x, sr_x, nx, Os);
1210 for (i=0; i<nx; i++)
1212 sr_x[i]=sr_x[i]*sh_rate;
1221 for (i=0; i<nx; i++)
1225 rotatefunc(y, sr_x, nx, Mr);
1228 for (i=0; i<nx; i++)
1230 sr_x[i]=x[i]*sh_rate;
1235void asyfunc (
double *x,
double *xasy,
int nx,
double beta)
1238 for (i=0; i<nx; i++)
1241 xasy[i]=pow(x[i],1.0+beta*i/(nx-1)*pow(x[i],0.5));
1245void oszfunc (
double *x,
double *xosz,
int nx)
1249 for (i=0; i<nx; i++)
1271 xosz[i]=sx*exp(xx+0.049*(sin(c1*xx)+sin(c2*xx)));
1279void cf_cal(
double *x,
double *f,
int nx,
double *Os,
double * delta,
double * bias,
double * fit,
int cf_num)
1283 double w_max=0,w_sum=0;
1284 w=(
double *)malloc(cf_num *
sizeof(
double));
1285 for (i=0; i<cf_num; i++)
1289 for (j=0; j<nx; j++)
1291 w[i]+=pow(x[j]-Os[i*nx+j],2.0);
1294 w[i]=pow(1.0/w[i],0.5)*exp(-w[i]/2.0/nx/pow(delta[i],2.0));
1301 for (i=0; i<cf_num; i++)
1307 for (i=0; i<cf_num; i++)
1312 for (i=0; i<cf_num; i++)
1314 f[0]=f[0]+w[i]/w_sum*fit[i];