00001 #include <stdio.h> 00002 #include <stdlib.h> 00003 #include <limits.h> 00004 #include <cmath> 00005 00006 #include "funcec08.h" 00007 #include "cec08data.h" 00008 #include <cassert> 00009 00010 using namespace std; 00011 00012 #define abss(a) (a<0 ? (-a) : a) 00013 #define max(a , b) (a>b ? a : b) 00014 #define min(a , b) (a>b ? b : a) 00015 00016 00017 static double pi; 00018 static double e; 00019 int gfunc_number; 00020 static double m_optime; 00021 00022 void init_cec2008(int func_number) { 00023 pi = acos(-1.0); 00024 e = exp(1.0); 00025 gfunc_number = func_number; 00026 } 00027 00028 void finish_cec2008(void) { 00029 00030 } 00031 00032 00033 double Shifted_Sphere( int dim , const double* x ){ 00034 int i; 00035 double z; 00036 double F = 0; 00037 for(i=0;i<dim;i++){ 00038 z = x[i] - sphere[i]; 00039 F += z*z; 00040 } 00041 return F + f_bias[0]; 00042 } 00043 00044 double Schwefel_Problem( int dim , const double* x ){ 00045 int i; 00046 double z; 00047 double F = abss(x[0]); 00048 for(i=1;i<dim;i++){ 00049 z = x[i] - schwefel[i]; 00050 F = max(F , abss(z)); 00051 } 00052 return F + f_bias[1]; 00053 } 00054 00055 double Shifted_Rosenbrock( int dim , const double* x ){ 00056 int i; 00057 double z[dim]; 00058 double F = 0; 00059 00060 for(i=0;i<dim;i++) z[i] = x[i] - rosenbrock[i] + 1; 00061 00062 for(i=0;i<dim-1;i++){ 00063 F = F + 100*( pow((pow(z[i],2)-z[i+1]) , 2) ) + pow((z[i]-1) , 2); 00064 } 00065 return F + f_bias[2]; 00066 } 00067 00068 00069 double Shifted_Rastrigin( int dim , const double* x ) 00070 { 00071 int i; 00072 double z; 00073 double F = 0; 00074 for(i=0;i<dim;i++){ 00075 z = x[i] - rastrigin[i]; 00076 F = F + ( pow(z,2) - 10*cos(2*pi*z) + 10); 00077 } 00078 return F + f_bias[3]; 00079 } 00080 00081 double Shifted_Griewank( int dim , const double* x ){ 00082 int i; 00083 double z; 00084 double F1 = 0; 00085 double F2 = 1; 00086 for(i=0;i<dim;i++){ 00087 z = x[i] - griewank[i]; 00088 F1 = F1 + ( pow(z,2) / 4000 ); 00089 F2 = F2 * ( cos(z/sqrt(i+1))); 00090 00091 } 00092 return (F1 - F2 + 1 + f_bias[4]); 00093 } 00094 00095 double Shifted_Ackley( int dim , const double* x ){ 00096 int i; 00097 double z; 00098 double Sum1 = 0; 00099 double Sum2 = 0; 00100 double F = 0; 00101 for(i=0;i<dim;i++){ 00102 z = x[i] - ackley[i]; 00103 Sum1 = Sum1 + pow(z , 2 ); 00104 Sum2 = Sum2 + cos(2*pi*z); 00105 } 00106 F = -20*exp(-0.2*sqrt(Sum1/dim)) -exp(Sum2/dim) + 20 + e + f_bias[5]; 00107 00108 return F; 00109 } 00110 void getInfo_cec2008(unsigned fun, string &name, double &min, double &max, double &optime) { 00111 if (fun == 1) { 00112 name = "Shifted_Sphere"; 00113 min = -100; 00114 max = 100; 00115 optime = -450.0; 00116 } 00117 else if (fun == 2) { 00118 name = "Schwefel_Problem"; 00119 min = -100; 00120 max = 100; 00121 optime = -450.0; 00122 } 00123 else if (fun == 3) { 00124 name = "Shifted_Rosenbrock"; 00125 min = -100; 00126 max = 100; 00127 optime = 390.0; 00128 } 00129 else if (fun == 4) { 00130 name = "Shifted_Rastrigin"; 00131 min = -5; 00132 max = 5; 00133 optime = -330.0; 00134 } 00135 else if (fun == 5) { 00136 name = "Shifted_Griewank"; 00137 min = -600; 00138 max = 600; 00139 optime = -180.0; 00140 } 00141 else if (fun == 6) { 00142 name = "Shifted_Griewank"; 00143 min = -32; 00144 max = 32; 00145 optime = -140.0; 00146 } 00147 else if (fun == 7) { 00148 name = "Java FastFractal"; 00149 min = -1; 00150 max = 1; 00151 optime = -15000; 00152 } 00153 00154 00155 m_optime = optime; 00156 } 00157 00158 double eval_cec2008(const tGen *x, int dim) { 00159 assert(gfunc_number >= 0 && gfunc_number <= 6); 00160 00161 switch(gfunc_number){ 00162 case 1 : return Shifted_Sphere(dim , x ) - m_optime; 00163 break; 00164 case 2 : return Schwefel_Problem(dim , x )- m_optime; 00165 break; 00166 case 3 : return Shifted_Rosenbrock(dim , x )- m_optime; 00167 break; 00168 case 4 : return Shifted_Rastrigin(dim , x )- m_optime; 00169 break; 00170 case 5 : return Shifted_Griewank(dim , x )- m_optime; 00171 break; 00172 case 6 : return Shifted_Ackley(dim , x ) - m_optime; 00173 break; 00174 00175 default: return -1; 00176 } 00177 00178 }