15#define E 2.7182818284590452353602874713526625
16#define PI 3.1415926535897932384626433832795029
18void sphere_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
19void ellips_func(
double *,
double *,
int ,
double *,
double *,
int,
int);
20void bent_cigar_func(
double *,
double *,
int ,
double *,
double *,
int,
int);
21void discus_func(
double *,
double *,
int ,
double *,
double *,
int,
int);
22void dif_powers_func(
double *,
double *,
int ,
double *,
double *,
int,
int);
23void rosenbrock_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
24void schaffer_F7_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
25void ackley_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
26void rastrigin_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
27void weierstrass_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
28void griewank_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
29void schwefel_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
30void katsuura_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
31void bi_rastrigin_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
32void grie_rosen_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
33void escaffer6_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
34void step_rastrigin_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
35void happycat_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
36void hgbat_func (
double *,
double *,
int ,
double *,
double *,
int,
int);
38void hf01 (
double *,
double *,
int,
double *,
double *,
int *,
int,
int);
39void hf02 (
double *,
double *,
int,
double *,
double *,
int *,
int,
int);
40void hf03 (
double *,
double *,
int,
double *,
double *,
int *,
int,
int);
41void hf04 (
double *,
double *,
int,
double *,
double *,
int *,
int,
int);
42void hf05 (
double *,
double *,
int,
double *,
double *,
int *,
int,
int);
43void hf06 (
double *,
double *,
int,
double *,
double *,
int *,
int,
int);
45void cf01 (
double *,
double *,
int ,
double *,
double *,
int);
46void cf02 (
double *,
double *,
int ,
double *,
double *,
int);
47void cf03 (
double *,
double *,
int ,
double *,
double *,
int);
48void cf04 (
double *,
double *,
int ,
double *,
double *,
int);
49void cf05 (
double *,
double *,
int ,
double *,
double *,
int);
50void cf06 (
double *,
double *,
int ,
double *,
double *,
int);
51void cf07 (
double *,
double *,
int ,
double *,
double *,
int *,
int);
52void cf08 (
double *,
double *,
int ,
double *,
double *,
int *,
int);
54void shiftfunc (
double*,
double*,
int,
double*);
55void rotatefunc (
double*,
double*,
int,
double*);
56void sr_func (
double *,
double *,
int,
double*,
double*,
double,
int,
int);
57void asyfunc (
double *,
double *x,
int,
double);
58void oszfunc (
double *,
double *,
int);
59void cf_cal(
double *,
double *,
int,
double *,
double *,
double *,
double *,
int);
61extern double *OShift,*M,*y,*z,*x_bound;
62extern int ini_flag,n_flag,func_flag,*SS;
65void cec14_test_func(
double *x,
double *f,
int nx,
int mx,
int func_num)
70 if ((n_flag!=nx)||(func_flag!=func_num))
85 y=(
double *)malloc(
sizeof(
double) * nx);
86 z=(
double *)malloc(
sizeof(
double) * nx);
87 x_bound=(
double *)malloc(
sizeof(
double) * nx);
91 if (!(nx==2||nx==10||nx==20||nx==30||nx==50||nx==100))
93 printf(
"\nError: Test functions are only defined for D=2,10,20,30,50,100.\n");
95 if (nx==2&&((func_num>=17&&func_num<=22)||(func_num>=29&&func_num<=30)))
97 printf(
"\nError: hf01,hf02,hf03,hf04,hf05,hf06,cf07&cf08 are NOT defined for D=2.\n");
101 sprintf(FileName,
"input_data/M_%d_D%d.txt", func_num,nx);
102 fpt = fopen(FileName,
"r");
105 printf(
"\n Error: Cannot open input file for reading \n");
109 M=(
double*)malloc(nx*nx*
sizeof(
double));
111 printf(
"\nError: there is insufficient memory available!\n");
112 for (i=0; i<nx*nx; i++)
114 fscanf(fpt,
"%Lf",&M[i]);
119 M=(
double*)malloc(cf_num*nx*nx*
sizeof(
double));
121 printf(
"\nError: there is insufficient memory available!\n");
122 for (i=0; i<cf_num*nx*nx; i++)
124 fscanf(fpt,
"%Lf",&M[i]);
130 sprintf(FileName,
"input_data/shift_data_%d.txt", func_num);
131 fpt = fopen(FileName,
"r");
134 printf(
"\n Error: Cannot open input file for reading \n");
139 OShift=(
double *)malloc(nx*
sizeof(
double));
141 printf(
"\nError: there is insufficient memory available!\n");
144 fscanf(fpt,
"%Lf",&OShift[i]);
149 OShift=(
double *)malloc(nx*cf_num*
sizeof(
double));
151 printf(
"\nError: there is insufficient memory available!\n");
152 for(i=0;i<cf_num-1;i++)
156 fscanf(fpt,
"%Lf",&OShift[i*nx+j]);
158 fscanf(fpt,
"%*[^\n]%*c");
162 fscanf(fpt,
"%Lf",&OShift[(cf_num-1)*nx+j]);
171 if (func_num>=17&&func_num<=22)
173 sprintf(FileName,
"input_data/shuffle_data_%d_D%d.txt", func_num, nx);
174 fpt = fopen(FileName,
"r");
177 printf(
"\n Error: Cannot open input file for reading \n");
179 SS=(
int *)malloc(nx*
sizeof(
int));
181 printf(
"\nError: there is insufficient memory available!\n");
184 fscanf(fpt,
"%d",&SS[i]);
188 else if (func_num==29||func_num==30)
190 sprintf(FileName,
"input_data/shuffle_data_%d_D%d.txt", func_num, nx);
191 fpt = fopen(FileName,
"r");
194 printf(
"\n Error: Cannot open input file for reading \n");
196 SS=(
int *)malloc(nx*cf_num*
sizeof(
int));
198 printf(
"\nError: there is insufficient memory available!\n");
199 for(i=0;i<nx*cf_num;i++)
201 fscanf(fpt,
"%d",&SS[i]);
214 for (i = 0; i < mx; i++)
219 ellips_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
223 bent_cigar_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
227 discus_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
231 rosenbrock_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
235 ackley_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
239 weierstrass_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
243 griewank_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
247 rastrigin_func(&x[i*nx],&f[i],nx,OShift,M,1,0);
251 rastrigin_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
255 schwefel_func(&x[i*nx],&f[i],nx,OShift,M,1,0);
259 schwefel_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
263 katsuura_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
267 happycat_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
271 hgbat_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
275 grie_rosen_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
279 escaffer6_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
283 hf01(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
287 hf02(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
291 hf03(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
295 hf04(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
299 hf05(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
303 hf06(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
307 cf01(&x[i*nx],&f[i],nx,OShift,M,1);
311 cf02(&x[i*nx],&f[i],nx,OShift,M,1);
315 cf03(&x[i*nx],&f[i],nx,OShift,M,1);
319 cf04(&x[i*nx],&f[i],nx,OShift,M,1);
323 cf05(&x[i*nx],&f[i],nx,OShift,M,1);
327 cf06(&x[i*nx],&f[i],nx,OShift,M,1);
331 cf07(&x[i*nx],&f[i],nx,OShift,M,SS,1);
335 cf08(&x[i*nx],&f[i],nx,OShift,M,SS,1);
339 printf(
"\nError: There are only 30 test functions in this test suite!\n");
348void sphere_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
352 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
362void ellips_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
366 sr_func (x, z, nx, Os, Mr,1.0, s_flag, r_flag);
369 f[0] += pow(10.0,6.0*i/(nx-1))*z[i]*z[i];
373void bent_cigar_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
376 sr_func (x, z, nx, Os, Mr,1.0, s_flag, r_flag);
381 f[0] += pow(10.0,6.0)*z[i]*z[i];
387void discus_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
390 sr_func (x, z, nx, Os, Mr,1.0, s_flag, r_flag);
391 f[0] = pow(10.0,6.0)*z[0]*z[0];
398void dif_powers_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
402 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
406 f[0] += pow(fabs(z[i]),2+4*i/(nx-1));
412void rosenbrock_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
417 sr_func (x, z, nx, Os, Mr, 2.048/100.0, s_flag, r_flag);
419 for (i=0; i<nx-1; i++)
422 tmp1=z[i]*z[i]-z[i+1];
424 f[0] += 100.0*tmp1*tmp1 +tmp2*tmp2;
428void schaffer_F7_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
433 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
434 for (i=0; i<nx-1; i++)
436 z[i]=pow(y[i]*y[i]+y[i+1]*y[i+1],0.5);
437 tmp=sin(50.0*pow(z[i],0.2));
438 f[0] += pow(z[i],0.5)+pow(z[i],0.5)*tmp*tmp ;
440 f[0] = f[0]*f[0]/(nx-1)/(nx-1);
443void ackley_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
450 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
455 sum2 += cos(2.0*PI*z[i]);
457 sum1 = -0.2*sqrt(sum1/nx);
459 f[0] = E - 20.0*exp(sum1) - exp(sum2) +20.0;
463void weierstrass_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
466 double sum,sum2, a, b;
472 sr_func (x, z, nx, Os, Mr, 0.5/100.0, s_flag, r_flag);
478 for (j=0; j<=k_max; j++)
480 sum += pow(a,j)*cos(2.0*PI*pow(b,j)*(z[i]+0.5));
481 sum2 += pow(a,j)*cos(2.0*PI*pow(b,j)*0.5);
489void griewank_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
496 sr_func (x, z, nx, Os, Mr, 600.0/100.0, s_flag, r_flag);
501 p *= cos(z[i]/sqrt(1.0+i));
503 f[0] = 1.0 + s/4000.0 - p;
506void rastrigin_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
511 sr_func (x, z, nx, Os, Mr, 5.12/100.0, s_flag, r_flag);
515 f[0] += (z[i]*z[i] - 10.0*cos(2.0*PI*z[i]) + 10.0);
519void step_rastrigin_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
525 if (fabs(y[i]-Os[i])>0.5)
526 y[i]=Os[i]+floor(2*(y[i]-Os[i])+0.5)/2;
529 sr_func (x, z, nx, Os, Mr, 5.12/100.0, s_flag, r_flag);
533 f[0] += (z[i]*z[i] - 10.0*cos(2.0*PI*z[i]) + 10.0);
537void schwefel_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
543 sr_func (x, z, nx, Os, Mr, 1000.0/100.0, s_flag, r_flag);
547 z[i] += 4.209687462275036e+002;
550 f[0]-=(500.0-fmod(z[i],500))*sin(pow(500.0-fmod(z[i],500),0.5));
551 tmp=(z[i]-500.0)/100;
556 f[0]-=(-500.0+fmod(fabs(z[i]),500))*sin(pow(500.0-fmod(fabs(z[i]),500),0.5));
557 tmp=(z[i]+500.0)/100;
561 f[0]-=z[i]*sin(pow(fabs(z[i]),0.5));
563 f[0] +=4.189828872724338e+002*nx;
567void katsuura_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
570 double temp,tmp1,tmp2,tmp3;
572 tmp3=pow(1.0*nx,1.2);
574 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag);
579 for (j=1; j<=32; j++)
583 temp += fabs(tmp2-floor(tmp2+0.5))/tmp1;
585 f[0] *= pow(1.0+(i+1)*temp,10.0/tmp3);
592void bi_rastrigin_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
595 double mu0=2.5,d=1.0,s,mu1,tmp,tmp1,tmp2;
597 tmpx=(
double *)malloc(
sizeof(
double) * nx);
598 s=1.0-1.0/(2.0*pow(nx+20.0,0.5)-8.2);
599 mu1=-pow((mu0*mu0-d)/s,0.5);
602 shiftfunc(x, y, nx, Os);
615 for (i = 0; i < nx; i++)
640 rotatefunc(z, y, nx, Mr);
643 tmp+=cos(2.0*PI*y[i]);
649 f[0] += 10.0*(nx-tmp);
655 tmp+=cos(2.0*PI*z[i]);
661 f[0] += 10.0*(nx-tmp);
667void grie_rosen_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
670 double temp,tmp1,tmp2;
673 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag);
676 for (i=0; i<nx-1; i++)
679 tmp1 = z[i]*z[i]-z[i+1];
681 temp = 100.0*tmp1*tmp1 + tmp2*tmp2;
682 f[0] += (temp*temp)/4000.0 - cos(temp) + 1.0;
684 tmp1 = z[nx-1]*z[nx-1]-z[0];
686 temp = 100.0*tmp1*tmp1 + tmp2*tmp2;
687 f[0] += (temp*temp)/4000.0 - cos(temp) + 1.0 ;
691void escaffer6_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
696 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
699 for (i=0; i<nx-1; i++)
701 temp1 = sin(sqrt(z[i]*z[i]+z[i+1]*z[i+1]));
703 temp2 = 1.0 + 0.001*(z[i]*z[i]+z[i+1]*z[i+1]);
704 f[0] += 0.5 + (temp1-0.5)/(temp2*temp2);
706 temp1 = sin(sqrt(z[nx-1]*z[nx-1]+z[0]*z[0]));
708 temp2 = 1.0 + 0.001*(z[nx-1]*z[nx-1]+z[0]*z[0]);
709 f[0] += 0.5 + (temp1-0.5)/(temp2*temp2);
712void happycat_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
716 double alpha,r2,sum_z;
719 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag);
729 f[0]=pow(fabs(r2-nx),2*alpha) + (0.5*r2 + sum_z)/nx + 0.5;
732void hgbat_func (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int s_flag,
int r_flag)
736 double alpha,r2,sum_z;
739 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag);
749 f[0]=pow(fabs(pow(r2,2.0)-pow(sum_z,2.0)),2*alpha) + (0.5*r2 + sum_z)/nx + 0.5;
752void hf01 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *S,
int s_flag,
int r_flag)
757 double Gp[3]={0.3,0.3,0.4};
760 for (i=0; i<cf_num-1; i++)
762 G_nx[i] = ceil(Gp[i]*nx);
765 G_nx[cf_num-1]=nx-tmp;
767 for (i=1; i<cf_num; i++)
769 G[i] = G[i-1]+G_nx[i-1];
772 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
779 schwefel_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
781 rastrigin_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
783 ellips_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
785 for(i=0;i<cf_num;i++)
791void hf02 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *S,
int s_flag,
int r_flag)
796 double Gp[3]={0.3,0.3,0.4};
799 for (i=0; i<cf_num-1; i++)
801 G_nx[i] = ceil(Gp[i]*nx);
804 G_nx[cf_num-1]=nx-tmp;
807 for (i=1; i<cf_num; i++)
809 G[i] = G[i-1]+G_nx[i-1];
812 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
819 bent_cigar_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
821 hgbat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
823 rastrigin_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
826 for(i=0;i<cf_num;i++)
832void hf03 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *S,
int s_flag,
int r_flag)
837 double Gp[4]={0.2,0.2,0.3,0.3};
840 for (i=0; i<cf_num-1; i++)
842 G_nx[i] = ceil(Gp[i]*nx);
845 G_nx[cf_num-1]=nx-tmp;
848 for (i=1; i<cf_num; i++)
850 G[i] = G[i-1]+G_nx[i-1];
853 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
860 griewank_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
862 weierstrass_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
864 rosenbrock_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
866 escaffer6_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
869 for(i=0;i<cf_num;i++)
875void hf04 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *S,
int s_flag,
int r_flag)
880 double Gp[4]={0.2,0.2,0.3,0.3};
883 for (i=0; i<cf_num-1; i++)
885 G_nx[i] = ceil(Gp[i]*nx);
888 G_nx[cf_num-1]=nx-tmp;
891 for (i=1; i<cf_num; i++)
893 G[i] = G[i-1]+G_nx[i-1];
896 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
903 hgbat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
905 discus_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
907 grie_rosen_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
909 rastrigin_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
912 for(i=0;i<cf_num;i++)
917void hf05 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *S,
int s_flag,
int r_flag)
922 double Gp[5]={0.1,0.2,0.2,0.2,0.3};
925 for (i=0; i<cf_num-1; i++)
927 G_nx[i] = ceil(Gp[i]*nx);
930 G_nx[cf_num-1]=nx-tmp;
933 for (i=1; i<cf_num; i++)
935 G[i] = G[i-1]+G_nx[i-1];
938 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
945 escaffer6_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
947 hgbat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
949 rosenbrock_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
951 schwefel_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
953 ellips_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
956 for(i=0;i<cf_num;i++)
962void hf06 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *S,
int s_flag,
int r_flag)
967 double Gp[5]={0.1,0.2,0.2,0.2,0.3};
970 for (i=0; i<cf_num-1; i++)
972 G_nx[i] = ceil(Gp[i]*nx);
975 G_nx[cf_num-1]=nx-tmp;
978 for (i=1; i<cf_num; i++)
980 G[i] = G[i-1]+G_nx[i-1];
983 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
990 katsuura_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
992 happycat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
994 grie_rosen_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
996 schwefel_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
998 ackley_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
1000 for(i=0;i<cf_num;i++)
1006void cf01 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int r_flag)
1010 double delta[5] = {10, 20, 30, 40, 50};
1011 double bias[5] = {0, 100, 200, 300, 400};
1014 rosenbrock_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1015 fit[i]=10000*fit[i]/1e+4;
1017 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1018 fit[i]=10000*fit[i]/1e+10;
1020 bent_cigar_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1021 fit[i]=10000*fit[i]/1e+30;
1023 discus_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1024 fit[i]=10000*fit[i]/1e+10;
1026 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,0);
1027 fit[i]=10000*fit[i]/1e+10;
1028 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1031void cf02 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int r_flag)
1035 double delta[3] = {20,20,20};
1036 double bias[3] = {0, 100, 200};
1039 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,0);
1041 rastrigin_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1043 hgbat_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1044 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1047void cf03 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int r_flag)
1051 double delta[3] = {10,30,50};
1052 double bias[3] = {0, 100, 200};
1054 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1055 fit[i]=1000*fit[i]/4e+3;
1057 rastrigin_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1058 fit[i]=1000*fit[i]/1e+3;
1060 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1061 fit[i]=1000*fit[i]/1e+10;
1062 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1065void cf04 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int r_flag)
1069 double delta[5] = {10,10,10,10,10};
1070 double bias[5] = {0, 100, 200, 300, 400};
1072 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1073 fit[i]=1000*fit[i]/4e+3;
1075 happycat_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1076 fit[i]=1000*fit[i]/1e+3;
1078 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1079 fit[i]=1000*fit[i]/1e+10;
1081 weierstrass_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1082 fit[i]=1000*fit[i]/400;
1084 griewank_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1085 fit[i]=1000*fit[i]/100;
1086 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1089void cf05 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int r_flag)
1093 double delta[5] = {10,10,10,20,20};
1094 double bias[5] = {0, 100, 200, 300, 400};
1096 hgbat_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1097 fit[i]=10000*fit[i]/1000;
1099 rastrigin_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1100 fit[i]=10000*fit[i]/1e+3;
1102 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1103 fit[i]=10000*fit[i]/4e+3;
1105 weierstrass_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1106 fit[i]=10000*fit[i]/400;
1108 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1109 fit[i]=10000*fit[i]/1e+10;
1110 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1113void cf06 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int r_flag)
1117 double delta[5] = {10,20,30,40,50};
1118 double bias[5] = {0, 100, 200, 300, 400};
1120 grie_rosen_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1121 fit[i]=10000*fit[i]/4e+3;
1123 happycat_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1124 fit[i]=10000*fit[i]/1e+3;
1126 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1127 fit[i]=10000*fit[i]/4e+3;
1129 escaffer6_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1130 fit[i]=10000*fit[i]/2e+7;
1132 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1133 fit[i]=10000*fit[i]/1e+10;
1134 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1137void cf07 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *SS,
int r_flag)
1141 double delta[3] = {10,30,50};
1142 double bias[3] = {0, 100, 200};
1144 hf01(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1146 hf02(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1148 hf03(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1149 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1152void cf08 (
double *x,
double *f,
int nx,
double *Os,
double *Mr,
int *SS,
int r_flag)
1156 double delta[3] = {10,30,50};
1157 double bias[3] = {0, 100, 200};
1159 hf04(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1161 hf05(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1163 hf06(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1164 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1169void shiftfunc (
double *x,
double *xshift,
int nx,
double *Os)
1172 for (i=0; i<nx; i++)
1174 xshift[i]=x[i]-Os[i];
1178void rotatefunc (
double *x,
double *xrot,
int nx,
double *Mr)
1181 for (i=0; i<nx; i++)
1184 for (j=0; j<nx; j++)
1186 xrot[i]=xrot[i]+x[j]*Mr[i*nx+j];
1191void sr_func (
double *x,
double *sr_x,
int nx,
double *Os,
double *Mr,
double sh_rate,
int s_flag,
int r_flag)
1198 shiftfunc(x, y, nx, Os);
1199 for (i=0; i<nx; i++)
1203 rotatefunc(y, sr_x, nx, Mr);
1207 shiftfunc(x, sr_x, nx, Os);
1208 for (i=0; i<nx; i++)
1210 sr_x[i]=sr_x[i]*sh_rate;
1219 for (i=0; i<nx; i++)
1223 rotatefunc(y, sr_x, nx, Mr);
1226 for (i=0; i<nx; i++)
1228 sr_x[i]=x[i]*sh_rate;
1233void asyfunc (
double *x,
double *xasy,
int nx,
double beta)
1236 for (i=0; i<nx; i++)
1239 xasy[i]=pow(x[i],1.0+beta*i/(nx-1)*pow(x[i],0.5));
1243void oszfunc (
double *x,
double *xosz,
int nx)
1247 for (i=0; i<nx; i++)
1269 xosz[i]=sx*exp(xx+0.049*(sin(c1*xx)+sin(c2*xx)));
1277void cf_cal(
double *x,
double *f,
int nx,
double *Os,
double * delta,
double * bias,
double * fit,
int cf_num)
1281 double w_max=0,w_sum=0;
1282 w=(
double *)malloc(cf_num *
sizeof(
double));
1283 for (i=0; i<cf_num; i++)
1287 for (j=0; j<nx; j++)
1289 w[i]+=pow(x[j]-Os[i*nx+j],2.0);
1292 w[i]=pow(1.0/w[i],0.5)*exp(-w[i]/2.0/nx/pow(delta[i],2.0));
1299 for (i=0; i<cf_num; i++)
1305 for (i=0; i<cf_num; i++)
1310 for (i=0; i<cf_num; i++)
1312 f[0]=f[0]+w[i]/w_sum*fit[i];