• Main Page
  • Modules
  • Classes
  • Files
  • File List

D:/Projekt/ECF_trunk/examples/CEC/cec14-c-code/cec14_test_func.cpp

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

Generated on Tue Nov 4 2014 13:04:31 for ECF by  doxygen 1.7.1