00001
00002
00003
00004
00005
00006
00007 #ifdef _WIN32
00008 #include <WINDOWS.H>
00009 #endif
00010
00011 #include <stdio.h>
00012 #include <math.h>
00013 #include <malloc.h>
00014
00015 #define INF 1.0e99
00016 #define EPS 1.0e-14
00017 #define E 2.7182818284590452353602874713526625
00018 #define PI 3.1415926535897932384626433832795029
00019
00020 void sphere_func (double *, double *, int , double *,double *, int, int);
00021 void ellips_func(double *, double *, int , double *,double *, int, int);
00022 void bent_cigar_func(double *, double *, int , double *,double *, int, int);
00023 void discus_func(double *, double *, int , double *,double *, int, int);
00024 void dif_powers_func(double *, double *, int , double *,double *, int, int);
00025 void rosenbrock_func (double *, double *, int , double *,double *, int, int);
00026 void schaffer_F7_func (double *, double *, int , double *,double *, int, int);
00027 void ackley_func (double *, double *, int , double *,double *, int, int);
00028 void rastrigin_func (double *, double *, int , double *,double *, int, int);
00029 void weierstrass_func (double *, double *, int , double *,double *, int, int);
00030 void griewank_func (double *, double *, int , double *,double *, int, int);
00031 void schwefel_func (double *, double *, int , double *,double *, int, int);
00032 void katsuura_func (double *, double *, int , double *,double *, int, int);
00033 void bi_rastrigin_func (double *, double *, int , double *,double *, int, int);
00034 void grie_rosen_func (double *, double *, int , double *,double *, int, int);
00035 void escaffer6_func (double *, double *, int , double *,double *, int, int);
00036 void step_rastrigin_func (double *, double *, int , double *,double *, int, int);
00037 void happycat_func (double *, double *, int , double *,double *, int, int);
00038 void hgbat_func (double *, double *, int , double *,double *, int, int);
00039
00040 void hf01 (double *, double *, int, double *,double *, int *,int, int);
00041 void hf02 (double *, double *, int, double *,double *, int *,int, int);
00042 void hf03 (double *, double *, int, double *,double *, int *,int, int);
00043 void hf04 (double *, double *, int, double *,double *, int *,int, int);
00044 void hf05 (double *, double *, int, double *,double *, int *,int, int);
00045 void hf06 (double *, double *, int, double *,double *, int *,int, int);
00046
00047 void cf01 (double *, double *, int , double *,double *, int);
00048 void cf02 (double *, double *, int , double *,double *, int);
00049 void cf03 (double *, double *, int , double *,double *, int);
00050 void cf04 (double *, double *, int , double *,double *, int);
00051 void cf05 (double *, double *, int , double *,double *, int);
00052 void cf06 (double *, double *, int , double *,double *, int);
00053 void cf07 (double *, double *, int , double *,double *, int *, int);
00054 void cf08 (double *, double *, int , double *,double *, int *, int);
00055
00056 void shiftfunc (double*,double*,int,double*);
00057 void rotatefunc (double*,double*,int, double*);
00058 void sr_func (double *, double *, int, double*, double*, double, int, int);
00059 void asyfunc (double *, double *x, int, double);
00060 void oszfunc (double *, double *, int);
00061 void cf_cal(double *, double *, int, double *,double *,double *,double *,int);
00062
00063 extern double *OShift,*M,*y,*z,*x_bound;
00064 extern int ini_flag,n_flag,func_flag,*SS;
00065
00066
00067 void cec14_test_func(double *x, double *f, int nx, int mx,int func_num)
00068 {
00069 int cf_num=10,i,j;
00070 if (ini_flag==1)
00071 {
00072 if ((n_flag!=nx)||(func_flag!=func_num))
00073 {
00074 ini_flag=0;
00075 }
00076 }
00077
00078 if (ini_flag==0)
00079 {
00080 FILE *fpt;
00081 char FileName[256];
00082 free(M);
00083 free(OShift);
00084 free(y);
00085 free(z);
00086 free(x_bound);
00087 y=(double *)malloc(sizeof(double) * nx);
00088 z=(double *)malloc(sizeof(double) * nx);
00089 x_bound=(double *)malloc(sizeof(double) * nx);
00090 for (i=0; i<nx; i++)
00091 x_bound[i]=100.0;
00092
00093 if (!(nx==2||nx==10||nx==20||nx==30||nx==50||nx==100))
00094 {
00095 printf("\nError: Test functions are only defined for D=2,10,20,30,50,100.\n");
00096 }
00097 if (nx==2&&((func_num>=17&&func_num<=22)||(func_num>=29&&func_num<=30)))
00098 {
00099 printf("\nError: hf01,hf02,hf03,hf04,hf05,hf06,cf07&cf08 are NOT defined for D=2.\n");
00100 }
00101
00102
00103 sprintf(FileName, "input_data/M_%d_D%d.txt", func_num,nx);
00104 fpt = fopen(FileName,"r");
00105 if (fpt==NULL)
00106 {
00107 printf("\n Error: Cannot open input file for reading \n");
00108 }
00109 if (func_num<23)
00110 {
00111 M=(double*)malloc(nx*nx*sizeof(double));
00112 if (M==NULL)
00113 printf("\nError: there is insufficient memory available!\n");
00114 for (i=0; i<nx*nx; i++)
00115 {
00116 fscanf(fpt,"%lf",&M[i]);
00117 }
00118 }
00119 else
00120 {
00121 M=(double*)malloc(cf_num*nx*nx*sizeof(double));
00122 if (M==NULL)
00123 printf("\nError: there is insufficient memory available!\n");
00124 for (i=0; i<cf_num*nx*nx; i++)
00125 {
00126 fscanf(fpt,"%lf",&M[i]);
00127 }
00128 }
00129 fclose(fpt);
00130
00131
00132 sprintf(FileName, "input_data/shift_data_%d.txt", func_num);
00133 fpt = fopen(FileName,"r");
00134 if (fpt==NULL)
00135 {
00136 printf("\n Error: Cannot open input file for reading \n");
00137 }
00138
00139 if (func_num<23)
00140 {
00141 OShift=(double *)malloc(nx*sizeof(double));
00142 if (OShift==NULL)
00143 printf("\nError: there is insufficient memory available!\n");
00144 for(i=0;i<nx;i++)
00145 {
00146 fscanf(fpt,"%lf",&OShift[i]);
00147 }
00148 }
00149 else
00150 {
00151 OShift=(double *)malloc(nx*cf_num*sizeof(double));
00152 if (OShift==NULL)
00153 printf("\nError: there is insufficient memory available!\n");
00154 for(i=0;i<cf_num-1;i++)
00155 {
00156 for (j=0;j<nx;j++)
00157 {
00158 fscanf(fpt,"%lf",&OShift[i*nx+j]);
00159 }
00160 fscanf(fpt,"%*[^\n]%*c");
00161 }
00162 for (j=0;j<nx;j++)
00163 {
00164 fscanf(fpt,"%lf",&OShift[(cf_num-1)*nx+j]);
00165 }
00166
00167 }
00168 fclose(fpt);
00169
00170
00171
00172
00173 if (func_num>=17&&func_num<=22)
00174 {
00175 sprintf(FileName, "input_data/shuffle_data_%d_D%d.txt", func_num, nx);
00176 fpt = fopen(FileName,"r");
00177 if (fpt==NULL)
00178 {
00179 printf("\n Error: Cannot open input file for reading \n");
00180 }
00181 SS=(int *)malloc(nx*sizeof(int));
00182 if (SS==NULL)
00183 printf("\nError: there is insufficient memory available!\n");
00184 for(i=0;i<nx;i++)
00185 {
00186 fscanf(fpt,"%d",&SS[i]);
00187 }
00188 fclose(fpt);
00189 }
00190 else if (func_num==29||func_num==30)
00191 {
00192 sprintf(FileName, "input_data/shuffle_data_%d_D%d.txt", func_num, nx);
00193 fpt = fopen(FileName,"r");
00194 if (fpt==NULL)
00195 {
00196 printf("\n Error: Cannot open input file for reading \n");
00197 }
00198 SS=(int *)malloc(nx*cf_num*sizeof(int));
00199 if (SS==NULL)
00200 printf("\nError: there is insufficient memory available!\n");
00201 for(i=0;i<nx*cf_num;i++)
00202 {
00203 fscanf(fpt,"%d",&SS[i]);
00204 }
00205 fclose(fpt);
00206 }
00207
00208
00209 n_flag=nx;
00210 func_flag=func_num;
00211 ini_flag=1;
00212
00213 }
00214
00215
00216 for (i = 0; i < mx; i++)
00217 {
00218 switch(func_num)
00219 {
00220 case 1:
00221 ellips_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
00222 f[i]+=100.0;
00223 break;
00224 case 2:
00225 bent_cigar_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
00226 f[i]+=200.0;
00227 break;
00228 case 3:
00229 discus_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
00230 f[i]+=300.0;
00231 break;
00232 case 4:
00233 rosenbrock_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
00234 f[i]+=400.0;
00235 break;
00236 case 5:
00237 ackley_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
00238 f[i]+=500.0;
00239 break;
00240 case 6:
00241 weierstrass_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
00242 f[i]+=600.0;
00243 break;
00244 case 7:
00245 griewank_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
00246 f[i]+=700.0;
00247 break;
00248 case 8:
00249 rastrigin_func(&x[i*nx],&f[i],nx,OShift,M,1,0);
00250 f[i]+=800.0;
00251 break;
00252 case 9:
00253 rastrigin_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
00254 f[i]+=900.0;
00255 break;
00256 case 10:
00257 schwefel_func(&x[i*nx],&f[i],nx,OShift,M,1,0);
00258 f[i]+=1000.0;
00259 break;
00260 case 11:
00261 schwefel_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
00262 f[i]+=1100.0;
00263 break;
00264 case 12:
00265 katsuura_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
00266 f[i]+=1200.0;
00267 break;
00268 case 13:
00269 happycat_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
00270 f[i]+=1300.0;
00271 break;
00272 case 14:
00273 hgbat_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
00274 f[i]+=1400.0;
00275 break;
00276 case 15:
00277 grie_rosen_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
00278 f[i]+=1500.0;
00279 break;
00280 case 16:
00281 escaffer6_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
00282 f[i]+=1600.0;
00283 break;
00284 case 17:
00285 hf01(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
00286 f[i]+=1700.0;
00287 break;
00288 case 18:
00289 hf02(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
00290 f[i]+=1800.0;
00291 break;
00292 case 19:
00293 hf03(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
00294 f[i]+=1900.0;
00295 break;
00296 case 20:
00297 hf04(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
00298 f[i]+=2000.0;
00299 break;
00300 case 21:
00301 hf05(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
00302 f[i]+=2100.0;
00303 break;
00304 case 22:
00305 hf06(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
00306 f[i]+=2200.0;
00307 break;
00308 case 23:
00309 cf01(&x[i*nx],&f[i],nx,OShift,M,1);
00310 f[i]+=2300.0;
00311 break;
00312 case 24:
00313 cf02(&x[i*nx],&f[i],nx,OShift,M,1);
00314 f[i]+=2400.0;
00315 break;
00316 case 25:
00317 cf03(&x[i*nx],&f[i],nx,OShift,M,1);
00318 f[i]+=2500.0;
00319 break;
00320 case 26:
00321 cf04(&x[i*nx],&f[i],nx,OShift,M,1);
00322 f[i]+=2600.0;
00323 break;
00324 case 27:
00325 cf05(&x[i*nx],&f[i],nx,OShift,M,1);
00326 f[i]+=2700.0;
00327 break;
00328 case 28:
00329 cf06(&x[i*nx],&f[i],nx,OShift,M,1);
00330 f[i]+=2800.0;
00331 break;
00332 case 29:
00333 cf07(&x[i*nx],&f[i],nx,OShift,M,SS,1);
00334 f[i]+=2900.0;
00335 break;
00336 case 30:
00337 cf08(&x[i*nx],&f[i],nx,OShift,M,SS,1);
00338 f[i]+=3000.0;
00339 break;
00340 default:
00341 printf("\nError: There are only 30 test functions in this test suite!\n");
00342 f[i] = 0.0;
00343 break;
00344 }
00345
00346 }
00347
00348 }
00349
00350 void sphere_func (double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
00351 {
00352 int i;
00353 f[0] = 0.0;
00354 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
00355 for (i=0; i<nx; i++)
00356 {
00357 f[0] += z[i]*z[i];
00358 }
00359
00360 }
00361
00362
00363
00364 void ellips_func (double *x, double *f, int nx, double *Os,double *Mr, int s_flag, int r_flag)
00365 {
00366 int i;
00367 f[0] = 0.0;
00368 sr_func (x, z, nx, Os, Mr,1.0, s_flag, r_flag);
00369 for (i=0; i<nx; i++)
00370 {
00371 f[0] += pow(10.0,6.0*i/(nx-1))*z[i]*z[i];
00372 }
00373 }
00374
00375 void bent_cigar_func (double *x, double *f, int nx, double *Os,double *Mr, int s_flag, int r_flag)
00376 {
00377 int i;
00378 sr_func (x, z, nx, Os, Mr,1.0, s_flag, r_flag);
00379
00380 f[0] = z[0]*z[0];
00381 for (i=1; i<nx; i++)
00382 {
00383 f[0] += pow(10.0,6.0)*z[i]*z[i];
00384 }
00385
00386
00387 }
00388
00389 void discus_func (double *x, double *f, int nx, double *Os,double *Mr, int s_flag, int r_flag)
00390 {
00391 int i;
00392 sr_func (x, z, nx, Os, Mr,1.0, s_flag, r_flag);
00393 f[0] = pow(10.0,6.0)*z[0]*z[0];
00394 for (i=1; i<nx; i++)
00395 {
00396 f[0] += z[i]*z[i];
00397 }
00398 }
00399
00400 void dif_powers_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag)
00401 {
00402 int i;
00403 f[0] = 0.0;
00404 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
00405
00406 for (i=0; i<nx; i++)
00407 {
00408 f[0] += pow(fabs(z[i]),2+4*i/(nx-1));
00409 }
00410 f[0]=pow(f[0],0.5);
00411 }
00412
00413
00414 void rosenbrock_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag)
00415 {
00416 int i;
00417 double tmp1,tmp2;
00418 f[0] = 0.0;
00419 sr_func (x, z, nx, Os, Mr, 2.048/100.0, s_flag, r_flag);
00420 z[0] += 1.0;
00421 for (i=0; i<nx-1; i++)
00422 {
00423 z[i+1] += 1.0;
00424 tmp1=z[i]*z[i]-z[i+1];
00425 tmp2=z[i]-1.0;
00426 f[0] += 100.0*tmp1*tmp1 +tmp2*tmp2;
00427 }
00428 }
00429
00430 void schaffer_F7_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag)
00431 {
00432 int i;
00433 double tmp;
00434 f[0] = 0.0;
00435 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
00436 for (i=0; i<nx-1; i++)
00437 {
00438 z[i]=pow(y[i]*y[i]+y[i+1]*y[i+1],0.5);
00439 tmp=sin(50.0*pow(z[i],0.2));
00440 f[0] += pow(z[i],0.5)+pow(z[i],0.5)*tmp*tmp ;
00441 }
00442 f[0] = f[0]*f[0]/(nx-1)/(nx-1);
00443 }
00444
00445 void ackley_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag)
00446 {
00447 int i;
00448 double sum1, sum2;
00449 sum1 = 0.0;
00450 sum2 = 0.0;
00451
00452 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
00453
00454 for (i=0; i<nx; i++)
00455 {
00456 sum1 += z[i]*z[i];
00457 sum2 += cos(2.0*PI*z[i]);
00458 }
00459 sum1 = -0.2*sqrt(sum1/nx);
00460 sum2 /= nx;
00461 f[0] = E - 20.0*exp(sum1) - exp(sum2) +20.0;
00462 }
00463
00464
00465 void weierstrass_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag)
00466 {
00467 int i,j,k_max;
00468 double sum,sum2, a, b;
00469 a = 0.5;
00470 b = 3.0;
00471 k_max = 20;
00472 f[0] = 0.0;
00473
00474 sr_func (x, z, nx, Os, Mr, 0.5/100.0, s_flag, r_flag);
00475
00476 for (i=0; i<nx; i++)
00477 {
00478 sum = 0.0;
00479 sum2 = 0.0;
00480 for (j=0; j<=k_max; j++)
00481 {
00482 sum += pow(a,j)*cos(2.0*PI*pow(b,j)*(z[i]+0.5));
00483 sum2 += pow(a,j)*cos(2.0*PI*pow(b,j)*0.5);
00484 }
00485 f[0] += sum;
00486 }
00487 f[0] -= nx*sum2;
00488 }
00489
00490
00491 void griewank_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag)
00492 {
00493 int i;
00494 double s, p;
00495 s = 0.0;
00496 p = 1.0;
00497
00498 sr_func (x, z, nx, Os, Mr, 600.0/100.0, s_flag, r_flag);
00499
00500 for (i=0; i<nx; i++)
00501 {
00502 s += z[i]*z[i];
00503 p *= cos(z[i]/sqrt(1.0+i));
00504 }
00505 f[0] = 1.0 + s/4000.0 - p;
00506 }
00507
00508 void rastrigin_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag)
00509 {
00510 int i;
00511 f[0] = 0.0;
00512
00513 sr_func (x, z, nx, Os, Mr, 5.12/100.0, s_flag, r_flag);
00514
00515 for (i=0; i<nx; i++)
00516 {
00517 f[0] += (z[i]*z[i] - 10.0*cos(2.0*PI*z[i]) + 10.0);
00518 }
00519 }
00520
00521 void step_rastrigin_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag)
00522 {
00523 int i;
00524 f[0]=0.0;
00525 for (i=0; i<nx; i++)
00526 {
00527 if (fabs(y[i]-Os[i])>0.5)
00528 y[i]=Os[i]+floor(2*(y[i]-Os[i])+0.5)/2;
00529 }
00530
00531 sr_func (x, z, nx, Os, Mr, 5.12/100.0, s_flag, r_flag);
00532
00533 for (i=0; i<nx; i++)
00534 {
00535 f[0] += (z[i]*z[i] - 10.0*cos(2.0*PI*z[i]) + 10.0);
00536 }
00537 }
00538
00539 void schwefel_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag)
00540 {
00541 int i;
00542 double tmp;
00543 f[0]=0.0;
00544
00545 sr_func (x, z, nx, Os, Mr, 1000.0/100.0, s_flag, r_flag);
00546
00547 for (i=0; i<nx; i++)
00548 {
00549 z[i] += 4.209687462275036e+002;
00550 if (z[i]>500)
00551 {
00552 f[0]-=(500.0-fmod(z[i],500))*sin(pow(500.0-fmod(z[i],500),0.5));
00553 tmp=(z[i]-500.0)/100;
00554 f[0]+= tmp*tmp/nx;
00555 }
00556 else if (z[i]<-500)
00557 {
00558 f[0]-=(-500.0+fmod(fabs(z[i]),500))*sin(pow(500.0-fmod(fabs(z[i]),500),0.5));
00559 tmp=(z[i]+500.0)/100;
00560 f[0]+= tmp*tmp/nx;
00561 }
00562 else
00563 f[0]-=z[i]*sin(pow(fabs(z[i]),0.5));
00564 }
00565 f[0] +=4.189828872724338e+002*nx;
00566
00567 }
00568
00569 void katsuura_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag)
00570 {
00571 int i,j;
00572 double temp,tmp1,tmp2,tmp3;
00573 f[0]=1.0;
00574 tmp3=pow(1.0*nx,1.2);
00575
00576 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag);
00577
00578 for (i=0; i<nx; i++)
00579 {
00580 temp=0.0;
00581 for (j=1; j<=32; j++)
00582 {
00583 tmp1=pow(2.0,j);
00584 tmp2=tmp1*z[i];
00585 temp += fabs(tmp2-floor(tmp2+0.5))/tmp1;
00586 }
00587 f[0] *= pow(1.0+(i+1)*temp,10.0/tmp3);
00588 }
00589 tmp1=10.0/nx/nx;
00590 f[0]=f[0]*tmp1-tmp1;
00591
00592 }
00593
00594 void bi_rastrigin_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag)
00595 {
00596 int i;
00597 double mu0=2.5,d=1.0,s,mu1,tmp,tmp1,tmp2;
00598 double *tmpx;
00599 tmpx=(double *)malloc(sizeof(double) * nx);
00600 s=1.0-1.0/(2.0*pow(nx+20.0,0.5)-8.2);
00601 mu1=-pow((mu0*mu0-d)/s,0.5);
00602
00603 if (s_flag==1)
00604 shiftfunc(x, y, nx, Os);
00605 else
00606 {
00607 for (i=0; i<nx; i++)
00608 {
00609 y[i] = x[i];
00610 }
00611 }
00612 for (i=0; i<nx; i++)
00613 {
00614 y[i] *= 10.0/100.0;
00615 }
00616
00617 for (i = 0; i < nx; i++)
00618 {
00619 tmpx[i]=2*y[i];
00620 if (Os[i] < 0.0)
00621 tmpx[i] *= -1.;
00622 }
00623 for (i=0; i<nx; i++)
00624 {
00625 z[i]=tmpx[i];
00626 tmpx[i] += mu0;
00627 }
00628 tmp1=0.0;tmp2=0.0;
00629 for (i=0; i<nx; i++)
00630 {
00631 tmp = tmpx[i]-mu0;
00632 tmp1 += tmp*tmp;
00633 tmp = tmpx[i]-mu1;
00634 tmp2 += tmp*tmp;
00635 }
00636 tmp2 *= s;
00637 tmp2 += d*nx;
00638 tmp=0.0;
00639
00640 if (r_flag==1)
00641 {
00642 rotatefunc(z, y, nx, Mr);
00643 for (i=0; i<nx; i++)
00644 {
00645 tmp+=cos(2.0*PI*y[i]);
00646 }
00647 if(tmp1<tmp2)
00648 f[0] = tmp1;
00649 else
00650 f[0] = tmp2;
00651 f[0] += 10.0*(nx-tmp);
00652 }
00653 else
00654 {
00655 for (i=0; i<nx; i++)
00656 {
00657 tmp+=cos(2.0*PI*z[i]);
00658 }
00659 if(tmp1<tmp2)
00660 f[0] = tmp1;
00661 else
00662 f[0] = tmp2;
00663 f[0] += 10.0*(nx-tmp);
00664 }
00665
00666 free(tmpx);
00667 }
00668
00669 void grie_rosen_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag)
00670 {
00671 int i;
00672 double temp,tmp1,tmp2;
00673 f[0]=0.0;
00674
00675 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag);
00676
00677 z[0] += 1.0;
00678 for (i=0; i<nx-1; i++)
00679 {
00680 z[i+1] += 1.0;
00681 tmp1 = z[i]*z[i]-z[i+1];
00682 tmp2 = z[i]-1.0;
00683 temp = 100.0*tmp1*tmp1 + tmp2*tmp2;
00684 f[0] += (temp*temp)/4000.0 - cos(temp) + 1.0;
00685 }
00686 tmp1 = z[nx-1]*z[nx-1]-z[0];
00687 tmp2 = z[nx-1]-1.0;
00688 temp = 100.0*tmp1*tmp1 + tmp2*tmp2;
00689 f[0] += (temp*temp)/4000.0 - cos(temp) + 1.0 ;
00690 }
00691
00692
00693 void escaffer6_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag)
00694 {
00695 int i;
00696 double temp1, temp2;
00697
00698 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
00699
00700 f[0] = 0.0;
00701 for (i=0; i<nx-1; i++)
00702 {
00703 temp1 = sin(sqrt(z[i]*z[i]+z[i+1]*z[i+1]));
00704 temp1 =temp1*temp1;
00705 temp2 = 1.0 + 0.001*(z[i]*z[i]+z[i+1]*z[i+1]);
00706 f[0] += 0.5 + (temp1-0.5)/(temp2*temp2);
00707 }
00708 temp1 = sin(sqrt(z[nx-1]*z[nx-1]+z[0]*z[0]));
00709 temp1 =temp1*temp1;
00710 temp2 = 1.0 + 0.001*(z[nx-1]*z[nx-1]+z[0]*z[0]);
00711 f[0] += 0.5 + (temp1-0.5)/(temp2*temp2);
00712 }
00713
00714 void happycat_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag)
00715
00716 {
00717 int i;
00718 double alpha,r2,sum_z;
00719 alpha=1.0/8.0;
00720
00721 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag);
00722
00723 r2 = 0.0;
00724 sum_z=0.0;
00725 for (i=0; i<nx; i++)
00726 {
00727 z[i]=z[i]-1.0;
00728 r2 += z[i]*z[i];
00729 sum_z += z[i];
00730 }
00731 f[0]=pow(fabs(r2-nx),2*alpha) + (0.5*r2 + sum_z)/nx + 0.5;
00732 }
00733
00734 void hgbat_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag)
00735
00736 {
00737 int i;
00738 double alpha,r2,sum_z;
00739 alpha=1.0/4.0;
00740
00741 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag);
00742
00743 r2 = 0.0;
00744 sum_z=0.0;
00745 for (i=0; i<nx; i++)
00746 {
00747 z[i]=z[i]-1.0;
00748 r2 += z[i]*z[i];
00749 sum_z += z[i];
00750 }
00751 f[0]=pow(fabs(pow(r2,2.0)-pow(sum_z,2.0)),2*alpha) + (0.5*r2 + sum_z)/nx + 0.5;
00752 }
00753
00754 void hf01 (double *x, double *f, int nx, double *Os,double *Mr,int *S,int s_flag,int r_flag)
00755 {
00756 int i,tmp,cf_num=3;
00757 double fit[3];
00758 int G[3],G_nx[3];
00759 double Gp[3]={0.3,0.3,0.4};
00760
00761 tmp=0;
00762 for (i=0; i<cf_num-1; i++)
00763 {
00764 G_nx[i] = ceil(Gp[i]*nx);
00765 tmp += G_nx[i];
00766 }
00767 G_nx[cf_num-1]=nx-tmp;
00768 G[0]=0;
00769 for (i=1; i<cf_num; i++)
00770 {
00771 G[i] = G[i-1]+G_nx[i-1];
00772 }
00773
00774 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
00775
00776 for (i=0; i<nx; i++)
00777 {
00778 y[i]=z[S[i]-1];
00779 }
00780 i=0;
00781 schwefel_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00782 i=1;
00783 rastrigin_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00784 i=2;
00785 ellips_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00786 f[0]=0.0;
00787 for(i=0;i<cf_num;i++)
00788 {
00789 f[0] += fit[i];
00790 }
00791 }
00792
00793 void hf02 (double *x, double *f, int nx, double *Os,double *Mr,int *S,int s_flag,int r_flag)
00794 {
00795 int i,tmp,cf_num=3;
00796 double fit[3];
00797 int G[3],G_nx[3];
00798 double Gp[3]={0.3,0.3,0.4};
00799
00800 tmp=0;
00801 for (i=0; i<cf_num-1; i++)
00802 {
00803 G_nx[i] = ceil(Gp[i]*nx);
00804 tmp += G_nx[i];
00805 }
00806 G_nx[cf_num-1]=nx-tmp;
00807
00808 G[0]=0;
00809 for (i=1; i<cf_num; i++)
00810 {
00811 G[i] = G[i-1]+G_nx[i-1];
00812 }
00813
00814 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
00815
00816 for (i=0; i<nx; i++)
00817 {
00818 y[i]=z[S[i]-1];
00819 }
00820 i=0;
00821 bent_cigar_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00822 i=1;
00823 hgbat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00824 i=2;
00825 rastrigin_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00826
00827 f[0]=0.0;
00828 for(i=0;i<cf_num;i++)
00829 {
00830 f[0] += fit[i];
00831 }
00832 }
00833
00834 void hf03 (double *x, double *f, int nx, double *Os,double *Mr,int *S,int s_flag,int r_flag)
00835 {
00836 int i,tmp,cf_num=4;
00837 double fit[4];
00838 int G[4],G_nx[4];
00839 double Gp[4]={0.2,0.2,0.3,0.3};
00840
00841 tmp=0;
00842 for (i=0; i<cf_num-1; i++)
00843 {
00844 G_nx[i] = ceil(Gp[i]*nx);
00845 tmp += G_nx[i];
00846 }
00847 G_nx[cf_num-1]=nx-tmp;
00848
00849 G[0]=0;
00850 for (i=1; i<cf_num; i++)
00851 {
00852 G[i] = G[i-1]+G_nx[i-1];
00853 }
00854
00855 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
00856
00857 for (i=0; i<nx; i++)
00858 {
00859 y[i]=z[S[i]-1];
00860 }
00861 i=0;
00862 griewank_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00863 i=1;
00864 weierstrass_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00865 i=2;
00866 rosenbrock_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00867 i=3;
00868 escaffer6_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00869
00870 f[0]=0.0;
00871 for(i=0;i<cf_num;i++)
00872 {
00873 f[0] += fit[i];
00874 }
00875 }
00876
00877 void hf04 (double *x, double *f, int nx, double *Os,double *Mr,int *S,int s_flag,int r_flag)
00878 {
00879 int i,tmp,cf_num=4;
00880 double fit[4];
00881 int G[4],G_nx[4];
00882 double Gp[4]={0.2,0.2,0.3,0.3};
00883
00884 tmp=0;
00885 for (i=0; i<cf_num-1; i++)
00886 {
00887 G_nx[i] = ceil(Gp[i]*nx);
00888 tmp += G_nx[i];
00889 }
00890 G_nx[cf_num-1]=nx-tmp;
00891
00892 G[0]=0;
00893 for (i=1; i<cf_num; i++)
00894 {
00895 G[i] = G[i-1]+G_nx[i-1];
00896 }
00897
00898 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
00899
00900 for (i=0; i<nx; i++)
00901 {
00902 y[i]=z[S[i]-1];
00903 }
00904 i=0;
00905 hgbat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00906 i=1;
00907 discus_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00908 i=2;
00909 grie_rosen_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00910 i=3;
00911 rastrigin_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00912
00913 f[0]=0.0;
00914 for(i=0;i<cf_num;i++)
00915 {
00916 f[0] += fit[i];
00917 }
00918 }
00919 void hf05 (double *x, double *f, int nx, double *Os,double *Mr,int *S,int s_flag,int r_flag)
00920 {
00921 int i,tmp,cf_num=5;
00922 double fit[5];
00923 int G[5],G_nx[5];
00924 double Gp[5]={0.1,0.2,0.2,0.2,0.3};
00925
00926 tmp=0;
00927 for (i=0; i<cf_num-1; i++)
00928 {
00929 G_nx[i] = ceil(Gp[i]*nx);
00930 tmp += G_nx[i];
00931 }
00932 G_nx[cf_num-1]=nx-tmp;
00933
00934 G[0]=0;
00935 for (i=1; i<cf_num; i++)
00936 {
00937 G[i] = G[i-1]+G_nx[i-1];
00938 }
00939
00940 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
00941
00942 for (i=0; i<nx; i++)
00943 {
00944 y[i]=z[S[i]-1];
00945 }
00946 i=0;
00947 escaffer6_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00948 i=1;
00949 hgbat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00950 i=2;
00951 rosenbrock_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00952 i=3;
00953 schwefel_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00954 i=4;
00955 ellips_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00956
00957 f[0]=0.0;
00958 for(i=0;i<cf_num;i++)
00959 {
00960 f[0] += fit[i];
00961 }
00962 }
00963
00964 void hf06 (double *x, double *f, int nx, double *Os,double *Mr,int *S,int s_flag,int r_flag)
00965 {
00966 int i,tmp,cf_num=5;
00967 double fit[5];
00968 int G[5],G_nx[5];
00969 double Gp[5]={0.1,0.2,0.2,0.2,0.3};
00970
00971 tmp=0;
00972 for (i=0; i<cf_num-1; i++)
00973 {
00974 G_nx[i] = ceil(Gp[i]*nx);
00975 tmp += G_nx[i];
00976 }
00977 G_nx[cf_num-1]=nx-tmp;
00978
00979 G[0]=0;
00980 for (i=1; i<cf_num; i++)
00981 {
00982 G[i] = G[i-1]+G_nx[i-1];
00983 }
00984
00985 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag);
00986
00987 for (i=0; i<nx; i++)
00988 {
00989 y[i]=z[S[i]-1];
00990 }
00991 i=0;
00992 katsuura_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00993 i=1;
00994 happycat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00995 i=2;
00996 grie_rosen_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00997 i=3;
00998 schwefel_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
00999 i=4;
01000 ackley_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
01001 f[0]=0.0;
01002 for(i=0;i<cf_num;i++)
01003 {
01004 f[0] += fit[i];
01005 }
01006 }
01007
01008 void cf01 (double *x, double *f, int nx, double *Os,double *Mr,int r_flag)
01009 {
01010 int i,cf_num=5;
01011 double fit[5];
01012 double delta[5] = {10, 20, 30, 40, 50};
01013 double bias[5] = {0, 100, 200, 300, 400};
01014
01015 i=0;
01016 rosenbrock_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01017 fit[i]=10000*fit[i]/1e+4;
01018 i=1;
01019 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01020 fit[i]=10000*fit[i]/1e+10;
01021 i=2;
01022 bent_cigar_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01023 fit[i]=10000*fit[i]/1e+30;
01024 i=3;
01025 discus_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01026 fit[i]=10000*fit[i]/1e+10;
01027 i=4;
01028 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,0);
01029 fit[i]=10000*fit[i]/1e+10;
01030 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
01031 }
01032
01033 void cf02 (double *x, double *f, int nx, double *Os,double *Mr,int r_flag)
01034 {
01035 int i,cf_num=3;
01036 double fit[3];
01037 double delta[3] = {20,20,20};
01038 double bias[3] = {0, 100, 200};
01039
01040 i=0;
01041 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,0);
01042 i=1;
01043 rastrigin_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01044 i=2;
01045 hgbat_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01046 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
01047 }
01048
01049 void cf03 (double *x, double *f, int nx, double *Os,double *Mr,int r_flag)
01050 {
01051 int i,cf_num=3;
01052 double fit[3];
01053 double delta[3] = {10,30,50};
01054 double bias[3] = {0, 100, 200};
01055 i=0;
01056 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01057 fit[i]=1000*fit[i]/4e+3;
01058 i=1;
01059 rastrigin_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01060 fit[i]=1000*fit[i]/1e+3;
01061 i=2;
01062 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01063 fit[i]=1000*fit[i]/1e+10;
01064 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
01065 }
01066
01067 void cf04 (double *x, double *f, int nx, double *Os,double *Mr,int r_flag)
01068 {
01069 int i,cf_num=5;
01070 double fit[5];
01071 double delta[5] = {10,10,10,10,10};
01072 double bias[5] = {0, 100, 200, 300, 400};
01073 i=0;
01074 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01075 fit[i]=1000*fit[i]/4e+3;
01076 i=1;
01077 happycat_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01078 fit[i]=1000*fit[i]/1e+3;
01079 i=2;
01080 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01081 fit[i]=1000*fit[i]/1e+10;
01082 i=3;
01083 weierstrass_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01084 fit[i]=1000*fit[i]/400;
01085 i=4;
01086 griewank_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01087 fit[i]=1000*fit[i]/100;
01088 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
01089 }
01090
01091 void cf05 (double *x, double *f, int nx, double *Os,double *Mr,int r_flag)
01092 {
01093 int i,cf_num=5;
01094 double fit[5];
01095 double delta[5] = {10,10,10,20,20};
01096 double bias[5] = {0, 100, 200, 300, 400};
01097 i=0;
01098 hgbat_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01099 fit[i]=10000*fit[i]/1000;
01100 i=1;
01101 rastrigin_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01102 fit[i]=10000*fit[i]/1e+3;
01103 i=2;
01104 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01105 fit[i]=10000*fit[i]/4e+3;
01106 i=3;
01107 weierstrass_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01108 fit[i]=10000*fit[i]/400;
01109 i=4;
01110 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01111 fit[i]=10000*fit[i]/1e+10;
01112 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
01113 }
01114
01115 void cf06 (double *x, double *f, int nx, double *Os,double *Mr,int r_flag)
01116 {
01117 int i,cf_num=5;
01118 double fit[5];
01119 double delta[5] = {10,20,30,40,50};
01120 double bias[5] = {0, 100, 200, 300, 400};
01121 i=0;
01122 grie_rosen_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01123 fit[i]=10000*fit[i]/4e+3;
01124 i=1;
01125 happycat_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01126 fit[i]=10000*fit[i]/1e+3;
01127 i=2;
01128 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01129 fit[i]=10000*fit[i]/4e+3;
01130 i=3;
01131 escaffer6_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01132 fit[i]=10000*fit[i]/2e+7;
01133 i=4;
01134 ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
01135 fit[i]=10000*fit[i]/1e+10;
01136 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
01137 }
01138
01139 void cf07 (double *x, double *f, int nx, double *Os,double *Mr,int *SS,int r_flag)
01140 {
01141 int i,cf_num=3;
01142 double fit[3];
01143 double delta[3] = {10,30,50};
01144 double bias[3] = {0, 100, 200};
01145 i=0;
01146 hf01(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
01147 i=1;
01148 hf02(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
01149 i=2;
01150 hf03(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
01151 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
01152 }
01153
01154 void cf08 (double *x, double *f, int nx, double *Os,double *Mr,int *SS,int r_flag)
01155 {
01156 int i,cf_num=3;
01157 double fit[3];
01158 double delta[3] = {10,30,50};
01159 double bias[3] = {0, 100, 200};
01160 i=0;
01161 hf04(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
01162 i=1;
01163 hf05(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
01164 i=2;
01165 hf06(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
01166 cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
01167 }
01168
01169
01170
01171 void shiftfunc (double *x, double *xshift, int nx,double *Os)
01172 {
01173 int i;
01174 for (i=0; i<nx; i++)
01175 {
01176 xshift[i]=x[i]-Os[i];
01177 }
01178 }
01179
01180 void rotatefunc (double *x, double *xrot, int nx,double *Mr)
01181 {
01182 int i,j;
01183 for (i=0; i<nx; i++)
01184 {
01185 xrot[i]=0;
01186 for (j=0; j<nx; j++)
01187 {
01188 xrot[i]=xrot[i]+x[j]*Mr[i*nx+j];
01189 }
01190 }
01191 }
01192
01193 void sr_func (double *x, double *sr_x, int nx, double *Os,double *Mr, double sh_rate, int s_flag,int r_flag)
01194 {
01195 int i;
01196 if (s_flag==1)
01197 {
01198 if (r_flag==1)
01199 {
01200 shiftfunc(x, y, nx, Os);
01201 for (i=0; i<nx; i++)
01202 {
01203 y[i]=y[i]*sh_rate;
01204 }
01205 rotatefunc(y, sr_x, nx, Mr);
01206 }
01207 else
01208 {
01209 shiftfunc(x, sr_x, nx, Os);
01210 for (i=0; i<nx; i++)
01211 {
01212 sr_x[i]=sr_x[i]*sh_rate;
01213 }
01214 }
01215 }
01216 else
01217 {
01218
01219 if (r_flag==1)
01220 {
01221 for (i=0; i<nx; i++)
01222 {
01223 y[i]=x[i]*sh_rate;
01224 }
01225 rotatefunc(y, sr_x, nx, Mr);
01226 }
01227 else
01228 for (i=0; i<nx; i++)
01229 {
01230 sr_x[i]=x[i]*sh_rate;
01231 }
01232 }
01233 }
01234
01235 void asyfunc (double *x, double *xasy, int nx, double beta)
01236 {
01237 int i;
01238 for (i=0; i<nx; i++)
01239 {
01240 if (x[i]>0)
01241 xasy[i]=pow(x[i],1.0+beta*i/(nx-1)*pow(x[i],0.5));
01242 }
01243 }
01244
01245 void oszfunc (double *x, double *xosz, int nx)
01246 {
01247 int i,sx;
01248 double c1,c2,xx;
01249 for (i=0; i<nx; i++)
01250 {
01251 if (i==0||i==nx-1)
01252 {
01253 if (x[i]!=0)
01254 xx=log(fabs(x[i]));
01255 if (x[i]>0)
01256 {
01257 c1=10;
01258 c2=7.9;
01259 }
01260 else
01261 {
01262 c1=5.5;
01263 c2=3.1;
01264 }
01265 if (x[i]>0)
01266 sx=1;
01267 else if (x[i]==0)
01268 sx=0;
01269 else
01270 sx=-1;
01271 xosz[i]=sx*exp(xx+0.049*(sin(c1*xx)+sin(c2*xx)));
01272 }
01273 else
01274 xosz[i]=x[i];
01275 }
01276 }
01277
01278
01279 void cf_cal(double *x, double *f, int nx, double *Os,double * delta,double * bias,double * fit, int cf_num)
01280 {
01281 int i,j;
01282 double *w;
01283 double w_max=0,w_sum=0;
01284 w=(double *)malloc(cf_num * sizeof(double));
01285 for (i=0; i<cf_num; i++)
01286 {
01287 fit[i]+=bias[i];
01288 w[i]=0;
01289 for (j=0; j<nx; j++)
01290 {
01291 w[i]+=pow(x[j]-Os[i*nx+j],2.0);
01292 }
01293 if (w[i]!=0)
01294 w[i]=pow(1.0/w[i],0.5)*exp(-w[i]/2.0/nx/pow(delta[i],2.0));
01295 else
01296 w[i]=INF;
01297 if (w[i]>w_max)
01298 w_max=w[i];
01299 }
01300
01301 for (i=0; i<cf_num; i++)
01302 {
01303 w_sum=w_sum+w[i];
01304 }
01305 if(w_max==0)
01306 {
01307 for (i=0; i<cf_num; i++)
01308 w[i]=1;
01309 w_sum=cf_num;
01310 }
01311 f[0] = 0.0;
01312 for (i=0; i<cf_num; i++)
01313 {
01314 f[0]=f[0]+w[i]/w_sum*fit[i];
01315 }
01316 free(w);
01317 }