ECF 1.5
cec14_test_func.cpp
1/*
2 CEC14 Test Function Suite for Single Objective Optimization
3 Jane Jing Liang (email: liangjing@zzu.edu.cn; liangjing@pmail.ntu.edu.cn)
4 Dec. 20th 2013
5*/
6
7
8#include <WINDOWS.H>
9#include <stdio.h>
10#include <math.h>
11#include <malloc.h>
12
13#define INF 1.0e99
14#define EPS 1.0e-14
15#define E 2.7182818284590452353602874713526625
16#define PI 3.1415926535897932384626433832795029
17
18void sphere_func (double *, double *, int , double *,double *, int, int); /* Sphere */
19void ellips_func(double *, double *, int , double *,double *, int, int); /* Ellipsoidal */
20void bent_cigar_func(double *, double *, int , double *,double *, int, int); /* Discus */
21void discus_func(double *, double *, int , double *,double *, int, int); /* Bent_Cigar */
22void dif_powers_func(double *, double *, int , double *,double *, int, int); /* Different Powers */
23void rosenbrock_func (double *, double *, int , double *,double *, int, int); /* Rosenbrock's */
24void schaffer_F7_func (double *, double *, int , double *,double *, int, int); /* Schwefel's F7 */
25void ackley_func (double *, double *, int , double *,double *, int, int); /* Ackley's */
26void rastrigin_func (double *, double *, int , double *,double *, int, int); /* Rastrigin's */
27void weierstrass_func (double *, double *, int , double *,double *, int, int); /* Weierstrass's */
28void griewank_func (double *, double *, int , double *,double *, int, int); /* Griewank's */
29void schwefel_func (double *, double *, int , double *,double *, int, int); /* Schwefel's */
30void katsuura_func (double *, double *, int , double *,double *, int, int); /* Katsuura */
31void bi_rastrigin_func (double *, double *, int , double *,double *, int, int); /* Lunacek Bi_rastrigin */
32void grie_rosen_func (double *, double *, int , double *,double *, int, int); /* Griewank-Rosenbrock */
33void escaffer6_func (double *, double *, int , double *,double *, int, int); /* Expanded Scaffer??s F6 */
34void step_rastrigin_func (double *, double *, int , double *,double *, int, int); /* Noncontinuous Rastrigin's */
35void happycat_func (double *, double *, int , double *,double *, int, int); /* HappyCat */
36void hgbat_func (double *, double *, int , double *,double *, int, int); /* HGBat */
37
38void hf01 (double *, double *, int, double *,double *, int *,int, int); /* Hybrid Function 1 */
39void hf02 (double *, double *, int, double *,double *, int *,int, int); /* Hybrid Function 2 */
40void hf03 (double *, double *, int, double *,double *, int *,int, int); /* Hybrid Function 3 */
41void hf04 (double *, double *, int, double *,double *, int *,int, int); /* Hybrid Function 4 */
42void hf05 (double *, double *, int, double *,double *, int *,int, int); /* Hybrid Function 5 */
43void hf06 (double *, double *, int, double *,double *, int *,int, int); /* Hybrid Function 6 */
44
45void cf01 (double *, double *, int , double *,double *, int); /* Composition Function 1 */
46void cf02 (double *, double *, int , double *,double *, int); /* Composition Function 2 */
47void cf03 (double *, double *, int , double *,double *, int); /* Composition Function 3 */
48void cf04 (double *, double *, int , double *,double *, int); /* Composition Function 4 */
49void cf05 (double *, double *, int , double *,double *, int); /* Composition Function 5 */
50void cf06 (double *, double *, int , double *,double *, int); /* Composition Function 6 */
51void cf07 (double *, double *, int , double *,double *, int *, int); /* Composition Function 7 */
52void cf08 (double *, double *, int , double *,double *, int *, int); /* Composition Function 8 */
53
54void shiftfunc (double*,double*,int,double*);
55void rotatefunc (double*,double*,int, double*);
56void sr_func (double *, double *, int, double*, double*, double, int, int); /* shift and rotate */
57void asyfunc (double *, double *x, int, double);
58void oszfunc (double *, double *, int);
59void cf_cal(double *, double *, int, double *,double *,double *,double *,int);
60
61extern double *OShift,*M,*y,*z,*x_bound;
62extern int ini_flag,n_flag,func_flag,*SS;
63
64
65void cec14_test_func(double *x, double *f, int nx, int mx,int func_num)
66{
67 int cf_num=10,i,j;
68 if (ini_flag==1)
69 {
70 if ((n_flag!=nx)||(func_flag!=func_num))
71 {
72 ini_flag=0;
73 }
74 }
75
76 if (ini_flag==0)
77 {
78 FILE *fpt;
79 char FileName[256];
80 free(M);
81 free(OShift);
82 free(y);
83 free(z);
84 free(x_bound);
85 y=(double *)malloc(sizeof(double) * nx);
86 z=(double *)malloc(sizeof(double) * nx);
87 x_bound=(double *)malloc(sizeof(double) * nx);
88 for (i=0; i<nx; i++)
89 x_bound[i]=100.0;
90
91 if (!(nx==2||nx==10||nx==20||nx==30||nx==50||nx==100))
92 {
93 printf("\nError: Test functions are only defined for D=2,10,20,30,50,100.\n");
94 }
95 if (nx==2&&((func_num>=17&&func_num<=22)||(func_num>=29&&func_num<=30)))
96 {
97 printf("\nError: hf01,hf02,hf03,hf04,hf05,hf06,cf07&cf08 are NOT defined for D=2.\n");
98 }
99
100 /* Load Matrix M*/
101 sprintf(FileName, "input_data/M_%d_D%d.txt", func_num,nx);
102 fpt = fopen(FileName,"r");
103 if (fpt==NULL)
104 {
105 printf("\n Error: Cannot open input file for reading \n");
106 }
107 if (func_num<23)
108 {
109 M=(double*)malloc(nx*nx*sizeof(double));
110 if (M==NULL)
111 printf("\nError: there is insufficient memory available!\n");
112 for (i=0; i<nx*nx; i++)
113 {
114 fscanf(fpt,"%Lf",&M[i]);
115 }
116 }
117 else
118 {
119 M=(double*)malloc(cf_num*nx*nx*sizeof(double));
120 if (M==NULL)
121 printf("\nError: there is insufficient memory available!\n");
122 for (i=0; i<cf_num*nx*nx; i++)
123 {
124 fscanf(fpt,"%Lf",&M[i]);
125 }
126 }
127 fclose(fpt);
128
129 /* Load shift_data */
130 sprintf(FileName, "input_data/shift_data_%d.txt", func_num);
131 fpt = fopen(FileName,"r");
132 if (fpt==NULL)
133 {
134 printf("\n Error: Cannot open input file for reading \n");
135 }
136
137 if (func_num<23)
138 {
139 OShift=(double *)malloc(nx*sizeof(double));
140 if (OShift==NULL)
141 printf("\nError: there is insufficient memory available!\n");
142 for(i=0;i<nx;i++)
143 {
144 fscanf(fpt,"%Lf",&OShift[i]);
145 }
146 }
147 else
148 {
149 OShift=(double *)malloc(nx*cf_num*sizeof(double));
150 if (OShift==NULL)
151 printf("\nError: there is insufficient memory available!\n");
152 for(i=0;i<cf_num-1;i++)
153 {
154 for (j=0;j<nx;j++)
155 {
156 fscanf(fpt,"%Lf",&OShift[i*nx+j]);
157 }
158 fscanf(fpt,"%*[^\n]%*c");
159 }
160 for (j=0;j<nx;j++)
161 {
162 fscanf(fpt,"%Lf",&OShift[(cf_num-1)*nx+j]);
163 }
164
165 }
166 fclose(fpt);
167
168
169 /* Load Shuffle_data */
170
171 if (func_num>=17&&func_num<=22)
172 {
173 sprintf(FileName, "input_data/shuffle_data_%d_D%d.txt", func_num, nx);
174 fpt = fopen(FileName,"r");
175 if (fpt==NULL)
176 {
177 printf("\n Error: Cannot open input file for reading \n");
178 }
179 SS=(int *)malloc(nx*sizeof(int));
180 if (SS==NULL)
181 printf("\nError: there is insufficient memory available!\n");
182 for(i=0;i<nx;i++)
183 {
184 fscanf(fpt,"%d",&SS[i]);
185 }
186 fclose(fpt);
187 }
188 else if (func_num==29||func_num==30)
189 {
190 sprintf(FileName, "input_data/shuffle_data_%d_D%d.txt", func_num, nx);
191 fpt = fopen(FileName,"r");
192 if (fpt==NULL)
193 {
194 printf("\n Error: Cannot open input file for reading \n");
195 }
196 SS=(int *)malloc(nx*cf_num*sizeof(int));
197 if (SS==NULL)
198 printf("\nError: there is insufficient memory available!\n");
199 for(i=0;i<nx*cf_num;i++)
200 {
201 fscanf(fpt,"%d",&SS[i]);
202 }
203 fclose(fpt);
204 }
205
206
207 n_flag=nx;
208 func_flag=func_num;
209 ini_flag=1;
210 //printf("Function has been initialized!\n");
211 }
212
213
214 for (i = 0; i < mx; i++)
215 {
216 switch(func_num)
217 {
218 case 1:
219 ellips_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
220 f[i]+=100.0;
221 break;
222 case 2:
223 bent_cigar_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
224 f[i]+=200.0;
225 break;
226 case 3:
227 discus_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
228 f[i]+=300.0;
229 break;
230 case 4:
231 rosenbrock_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
232 f[i]+=400.0;
233 break;
234 case 5:
235 ackley_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
236 f[i]+=500.0;
237 break;
238 case 6:
239 weierstrass_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
240 f[i]+=600.0;
241 break;
242 case 7:
243 griewank_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
244 f[i]+=700.0;
245 break;
246 case 8:
247 rastrigin_func(&x[i*nx],&f[i],nx,OShift,M,1,0);
248 f[i]+=800.0;
249 break;
250 case 9:
251 rastrigin_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
252 f[i]+=900.0;
253 break;
254 case 10:
255 schwefel_func(&x[i*nx],&f[i],nx,OShift,M,1,0);
256 f[i]+=1000.0;
257 break;
258 case 11:
259 schwefel_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
260 f[i]+=1100.0;
261 break;
262 case 12:
263 katsuura_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
264 f[i]+=1200.0;
265 break;
266 case 13:
267 happycat_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
268 f[i]+=1300.0;
269 break;
270 case 14:
271 hgbat_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
272 f[i]+=1400.0;
273 break;
274 case 15:
275 grie_rosen_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
276 f[i]+=1500.0;
277 break;
278 case 16:
279 escaffer6_func(&x[i*nx],&f[i],nx,OShift,M,1,1);
280 f[i]+=1600.0;
281 break;
282 case 17:
283 hf01(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
284 f[i]+=1700.0;
285 break;
286 case 18:
287 hf02(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
288 f[i]+=1800.0;
289 break;
290 case 19:
291 hf03(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
292 f[i]+=1900.0;
293 break;
294 case 20:
295 hf04(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
296 f[i]+=2000.0;
297 break;
298 case 21:
299 hf05(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
300 f[i]+=2100.0;
301 break;
302 case 22:
303 hf06(&x[i*nx],&f[i],nx,OShift,M,SS,1,1);
304 f[i]+=2200.0;
305 break;
306 case 23:
307 cf01(&x[i*nx],&f[i],nx,OShift,M,1);
308 f[i]+=2300.0;
309 break;
310 case 24:
311 cf02(&x[i*nx],&f[i],nx,OShift,M,1);
312 f[i]+=2400.0;
313 break;
314 case 25:
315 cf03(&x[i*nx],&f[i],nx,OShift,M,1);
316 f[i]+=2500.0;
317 break;
318 case 26:
319 cf04(&x[i*nx],&f[i],nx,OShift,M,1);
320 f[i]+=2600.0;
321 break;
322 case 27:
323 cf05(&x[i*nx],&f[i],nx,OShift,M,1);
324 f[i]+=2700.0;
325 break;
326 case 28:
327 cf06(&x[i*nx],&f[i],nx,OShift,M,1);
328 f[i]+=2800.0;
329 break;
330 case 29:
331 cf07(&x[i*nx],&f[i],nx,OShift,M,SS,1);
332 f[i]+=2900.0;
333 break;
334 case 30:
335 cf08(&x[i*nx],&f[i],nx,OShift,M,SS,1);
336 f[i]+=3000.0;
337 break;
338 default:
339 printf("\nError: There are only 30 test functions in this test suite!\n");
340 f[i] = 0.0;
341 break;
342 }
343
344 }
345
346}
347
348void sphere_func (double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag) /* Sphere */
349{
350 int i;
351 f[0] = 0.0;
352 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag); /* shift and rotate */
353 for (i=0; i<nx; i++)
354 {
355 f[0] += z[i]*z[i];
356 }
357
358}
359
360
361
362void ellips_func (double *x, double *f, int nx, double *Os,double *Mr, int s_flag, int r_flag) /* Ellipsoidal */
363{
364 int i;
365 f[0] = 0.0;
366 sr_func (x, z, nx, Os, Mr,1.0, s_flag, r_flag); /* shift and rotate */
367 for (i=0; i<nx; i++)
368 {
369 f[0] += pow(10.0,6.0*i/(nx-1))*z[i]*z[i];
370 }
371}
372
373void bent_cigar_func (double *x, double *f, int nx, double *Os,double *Mr, int s_flag, int r_flag) /* Bent_Cigar */
374{
375 int i;
376 sr_func (x, z, nx, Os, Mr,1.0, s_flag, r_flag); /* shift and rotate */
377
378 f[0] = z[0]*z[0];
379 for (i=1; i<nx; i++)
380 {
381 f[0] += pow(10.0,6.0)*z[i]*z[i];
382 }
383
384
385}
386
387void discus_func (double *x, double *f, int nx, double *Os,double *Mr, int s_flag, int r_flag) /* Discus */
388{
389 int i;
390 sr_func (x, z, nx, Os, Mr,1.0, s_flag, r_flag); /* shift and rotate */
391 f[0] = pow(10.0,6.0)*z[0]*z[0];
392 for (i=1; i<nx; i++)
393 {
394 f[0] += z[i]*z[i];
395 }
396}
397
398void dif_powers_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Different Powers */
399{
400 int i;
401 f[0] = 0.0;
402 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag); /* shift and rotate */
403
404 for (i=0; i<nx; i++)
405 {
406 f[0] += pow(fabs(z[i]),2+4*i/(nx-1));
407 }
408 f[0]=pow(f[0],0.5);
409}
410
411
412void rosenbrock_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Rosenbrock's */
413{
414 int i;
415 double tmp1,tmp2;
416 f[0] = 0.0;
417 sr_func (x, z, nx, Os, Mr, 2.048/100.0, s_flag, r_flag); /* shift and rotate */
418 z[0] += 1.0;//shift to orgin
419 for (i=0; i<nx-1; i++)
420 {
421 z[i+1] += 1.0;//shift to orgin
422 tmp1=z[i]*z[i]-z[i+1];
423 tmp2=z[i]-1.0;
424 f[0] += 100.0*tmp1*tmp1 +tmp2*tmp2;
425 }
426}
427
428void schaffer_F7_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Schwefel's 1.2 */
429{
430 int i;
431 double tmp;
432 f[0] = 0.0;
433 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag); /* shift and rotate */
434 for (i=0; i<nx-1; i++)
435 {
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 ;
439 }
440 f[0] = f[0]*f[0]/(nx-1)/(nx-1);
441}
442
443void ackley_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Ackley's */
444{
445 int i;
446 double sum1, sum2;
447 sum1 = 0.0;
448 sum2 = 0.0;
449
450 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag); /* shift and rotate */
451
452 for (i=0; i<nx; i++)
453 {
454 sum1 += z[i]*z[i];
455 sum2 += cos(2.0*PI*z[i]);
456 }
457 sum1 = -0.2*sqrt(sum1/nx);
458 sum2 /= nx;
459 f[0] = E - 20.0*exp(sum1) - exp(sum2) +20.0;
460}
461
462
463void weierstrass_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Weierstrass's */
464{
465 int i,j,k_max;
466 double sum,sum2, a, b;
467 a = 0.5;
468 b = 3.0;
469 k_max = 20;
470 f[0] = 0.0;
471
472 sr_func (x, z, nx, Os, Mr, 0.5/100.0, s_flag, r_flag); /* shift and rotate */
473
474 for (i=0; i<nx; i++)
475 {
476 sum = 0.0;
477 sum2 = 0.0;
478 for (j=0; j<=k_max; j++)
479 {
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);
482 }
483 f[0] += sum;
484 }
485 f[0] -= nx*sum2;
486}
487
488
489void griewank_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Griewank's */
490{
491 int i;
492 double s, p;
493 s = 0.0;
494 p = 1.0;
495
496 sr_func (x, z, nx, Os, Mr, 600.0/100.0, s_flag, r_flag); /* shift and rotate */
497
498 for (i=0; i<nx; i++)
499 {
500 s += z[i]*z[i];
501 p *= cos(z[i]/sqrt(1.0+i));
502 }
503 f[0] = 1.0 + s/4000.0 - p;
504}
505
506void rastrigin_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Rastrigin's */
507{
508 int i;
509 f[0] = 0.0;
510
511 sr_func (x, z, nx, Os, Mr, 5.12/100.0, s_flag, r_flag); /* shift and rotate */
512
513 for (i=0; i<nx; i++)
514 {
515 f[0] += (z[i]*z[i] - 10.0*cos(2.0*PI*z[i]) + 10.0);
516 }
517}
518
519void step_rastrigin_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Noncontinuous Rastrigin's */
520{
521 int i;
522 f[0]=0.0;
523 for (i=0; i<nx; i++)
524 {
525 if (fabs(y[i]-Os[i])>0.5)
526 y[i]=Os[i]+floor(2*(y[i]-Os[i])+0.5)/2;
527 }
528
529 sr_func (x, z, nx, Os, Mr, 5.12/100.0, s_flag, r_flag); /* shift and rotate */
530
531 for (i=0; i<nx; i++)
532 {
533 f[0] += (z[i]*z[i] - 10.0*cos(2.0*PI*z[i]) + 10.0);
534 }
535}
536
537void schwefel_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Schwefel's */
538{
539 int i;
540 double tmp;
541 f[0]=0.0;
542
543 sr_func (x, z, nx, Os, Mr, 1000.0/100.0, s_flag, r_flag); /* shift and rotate */
544
545 for (i=0; i<nx; i++)
546 {
547 z[i] += 4.209687462275036e+002;
548 if (z[i]>500)
549 {
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;
552 f[0]+= tmp*tmp/nx;
553 }
554 else if (z[i]<-500)
555 {
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;
558 f[0]+= tmp*tmp/nx;
559 }
560 else
561 f[0]-=z[i]*sin(pow(fabs(z[i]),0.5));
562 }
563 f[0] +=4.189828872724338e+002*nx;
564
565}
566
567void katsuura_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Katsuura */
568{
569 int i,j;
570 double temp,tmp1,tmp2,tmp3;
571 f[0]=1.0;
572 tmp3=pow(1.0*nx,1.2);
573
574 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag); /* shift and rotate */
575
576 for (i=0; i<nx; i++)
577 {
578 temp=0.0;
579 for (j=1; j<=32; j++)
580 {
581 tmp1=pow(2.0,j);
582 tmp2=tmp1*z[i];
583 temp += fabs(tmp2-floor(tmp2+0.5))/tmp1;
584 }
585 f[0] *= pow(1.0+(i+1)*temp,10.0/tmp3);
586 }
587 tmp1=10.0/nx/nx;
588 f[0]=f[0]*tmp1-tmp1;
589
590}
591
592void bi_rastrigin_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Lunacek Bi_rastrigin Function */
593{
594 int i;
595 double mu0=2.5,d=1.0,s,mu1,tmp,tmp1,tmp2;
596 double *tmpx;
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);
600
601 if (s_flag==1)
602 shiftfunc(x, y, nx, Os);
603 else
604 {
605 for (i=0; i<nx; i++)//shrink to the orginal search range
606 {
607 y[i] = x[i];
608 }
609 }
610 for (i=0; i<nx; i++)//shrink to the orginal search range
611 {
612 y[i] *= 10.0/100.0;
613 }
614
615 for (i = 0; i < nx; i++)
616 {
617 tmpx[i]=2*y[i];
618 if (Os[i] < 0.0)
619 tmpx[i] *= -1.;
620 }
621 for (i=0; i<nx; i++)
622 {
623 z[i]=tmpx[i];
624 tmpx[i] += mu0;
625 }
626 tmp1=0.0;tmp2=0.0;
627 for (i=0; i<nx; i++)
628 {
629 tmp = tmpx[i]-mu0;
630 tmp1 += tmp*tmp;
631 tmp = tmpx[i]-mu1;
632 tmp2 += tmp*tmp;
633 }
634 tmp2 *= s;
635 tmp2 += d*nx;
636 tmp=0.0;
637
638 if (r_flag==1)
639 {
640 rotatefunc(z, y, nx, Mr);
641 for (i=0; i<nx; i++)
642 {
643 tmp+=cos(2.0*PI*y[i]);
644 }
645 if(tmp1<tmp2)
646 f[0] = tmp1;
647 else
648 f[0] = tmp2;
649 f[0] += 10.0*(nx-tmp);
650 }
651 else
652 {
653 for (i=0; i<nx; i++)
654 {
655 tmp+=cos(2.0*PI*z[i]);
656 }
657 if(tmp1<tmp2)
658 f[0] = tmp1;
659 else
660 f[0] = tmp2;
661 f[0] += 10.0*(nx-tmp);
662 }
663
664 free(tmpx);
665}
666
667void grie_rosen_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Griewank-Rosenbrock */
668{
669 int i;
670 double temp,tmp1,tmp2;
671 f[0]=0.0;
672
673 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag); /* shift and rotate */
674
675 z[0] += 1.0;//shift to orgin
676 for (i=0; i<nx-1; i++)
677 {
678 z[i+1] += 1.0;//shift to orgin
679 tmp1 = z[i]*z[i]-z[i+1];
680 tmp2 = z[i]-1.0;
681 temp = 100.0*tmp1*tmp1 + tmp2*tmp2;
682 f[0] += (temp*temp)/4000.0 - cos(temp) + 1.0;
683 }
684 tmp1 = z[nx-1]*z[nx-1]-z[0];
685 tmp2 = z[nx-1]-1.0;
686 temp = 100.0*tmp1*tmp1 + tmp2*tmp2;
687 f[0] += (temp*temp)/4000.0 - cos(temp) + 1.0 ;
688}
689
690
691void escaffer6_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Expanded Scaffer??s F6 */
692{
693 int i;
694 double temp1, temp2;
695
696 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag); /* shift and rotate */
697
698 f[0] = 0.0;
699 for (i=0; i<nx-1; i++)
700 {
701 temp1 = sin(sqrt(z[i]*z[i]+z[i+1]*z[i+1]));
702 temp1 =temp1*temp1;
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);
705 }
706 temp1 = sin(sqrt(z[nx-1]*z[nx-1]+z[0]*z[0]));
707 temp1 =temp1*temp1;
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);
710}
711
712void 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) */
713/* original global optimum: [-1,-1,...,-1] */
714{
715 int i;
716 double alpha,r2,sum_z;
717 alpha=1.0/8.0;
718
719 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag); /* shift and rotate */
720
721 r2 = 0.0;
722 sum_z=0.0;
723 for (i=0; i<nx; i++)
724 {
725 z[i]=z[i]-1.0;//shift to orgin
726 r2 += z[i]*z[i];
727 sum_z += z[i];
728 }
729 f[0]=pow(fabs(r2-nx),2*alpha) + (0.5*r2 + sum_z)/nx + 0.5;
730}
731
732void 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)*/
733/* original global optimum: [-1,-1,...,-1] */
734{
735 int i;
736 double alpha,r2,sum_z;
737 alpha=1.0/4.0;
738
739 sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag); /* shift and rotate */
740
741 r2 = 0.0;
742 sum_z=0.0;
743 for (i=0; i<nx; i++)
744 {
745 z[i]=z[i]-1.0;//shift to orgin
746 r2 += z[i]*z[i];
747 sum_z += z[i];
748 }
749 f[0]=pow(fabs(pow(r2,2.0)-pow(sum_z,2.0)),2*alpha) + (0.5*r2 + sum_z)/nx + 0.5;
750}
751
752void hf01 (double *x, double *f, int nx, double *Os,double *Mr,int *S,int s_flag,int r_flag) /* Hybrid Function 1 */
753{
754 int i,tmp,cf_num=3;
755 double fit[3];
756 int G[3],G_nx[3];
757 double Gp[3]={0.3,0.3,0.4};
758
759 tmp=0;
760 for (i=0; i<cf_num-1; i++)
761 {
762 G_nx[i] = ceil(Gp[i]*nx);
763 tmp += G_nx[i];
764 }
765 G_nx[cf_num-1]=nx-tmp;
766 G[0]=0;
767 for (i=1; i<cf_num; i++)
768 {
769 G[i] = G[i-1]+G_nx[i-1];
770 }
771
772 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag); /* shift and rotate */
773
774 for (i=0; i<nx; i++)
775 {
776 y[i]=z[S[i]-1];
777 }
778 i=0;
779 schwefel_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
780 i=1;
781 rastrigin_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
782 i=2;
783 ellips_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
784 f[0]=0.0;
785 for(i=0;i<cf_num;i++)
786 {
787 f[0] += fit[i];
788 }
789}
790
791void hf02 (double *x, double *f, int nx, double *Os,double *Mr,int *S,int s_flag,int r_flag) /* Hybrid Function 2 */
792{
793 int i,tmp,cf_num=3;
794 double fit[3];
795 int G[3],G_nx[3];
796 double Gp[3]={0.3,0.3,0.4};
797
798 tmp=0;
799 for (i=0; i<cf_num-1; i++)
800 {
801 G_nx[i] = ceil(Gp[i]*nx);
802 tmp += G_nx[i];
803 }
804 G_nx[cf_num-1]=nx-tmp;
805
806 G[0]=0;
807 for (i=1; i<cf_num; i++)
808 {
809 G[i] = G[i-1]+G_nx[i-1];
810 }
811
812 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag); /* shift and rotate */
813
814 for (i=0; i<nx; i++)
815 {
816 y[i]=z[S[i]-1];
817 }
818 i=0;
819 bent_cigar_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
820 i=1;
821 hgbat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
822 i=2;
823 rastrigin_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
824
825 f[0]=0.0;
826 for(i=0;i<cf_num;i++)
827 {
828 f[0] += fit[i];
829 }
830}
831
832void hf03 (double *x, double *f, int nx, double *Os,double *Mr,int *S,int s_flag,int r_flag) /* Hybrid Function 3 */
833{
834 int i,tmp,cf_num=4;
835 double fit[4];
836 int G[4],G_nx[4];
837 double Gp[4]={0.2,0.2,0.3,0.3};
838
839 tmp=0;
840 for (i=0; i<cf_num-1; i++)
841 {
842 G_nx[i] = ceil(Gp[i]*nx);
843 tmp += G_nx[i];
844 }
845 G_nx[cf_num-1]=nx-tmp;
846
847 G[0]=0;
848 for (i=1; i<cf_num; i++)
849 {
850 G[i] = G[i-1]+G_nx[i-1];
851 }
852
853 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag); /* shift and rotate */
854
855 for (i=0; i<nx; i++)
856 {
857 y[i]=z[S[i]-1];
858 }
859 i=0;
860 griewank_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
861 i=1;
862 weierstrass_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
863 i=2;
864 rosenbrock_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
865 i=3;
866 escaffer6_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
867
868 f[0]=0.0;
869 for(i=0;i<cf_num;i++)
870 {
871 f[0] += fit[i];
872 }
873}
874
875void hf04 (double *x, double *f, int nx, double *Os,double *Mr,int *S,int s_flag,int r_flag) /* Hybrid Function 4 */
876{
877 int i,tmp,cf_num=4;
878 double fit[4];
879 int G[4],G_nx[4];
880 double Gp[4]={0.2,0.2,0.3,0.3};
881
882 tmp=0;
883 for (i=0; i<cf_num-1; i++)
884 {
885 G_nx[i] = ceil(Gp[i]*nx);
886 tmp += G_nx[i];
887 }
888 G_nx[cf_num-1]=nx-tmp;
889
890 G[0]=0;
891 for (i=1; i<cf_num; i++)
892 {
893 G[i] = G[i-1]+G_nx[i-1];
894 }
895
896 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag); /* shift and rotate */
897
898 for (i=0; i<nx; i++)
899 {
900 y[i]=z[S[i]-1];
901 }
902 i=0;
903 hgbat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
904 i=1;
905 discus_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
906 i=2;
907 grie_rosen_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
908 i=3;
909 rastrigin_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
910
911 f[0]=0.0;
912 for(i=0;i<cf_num;i++)
913 {
914 f[0] += fit[i];
915 }
916}
917void hf05 (double *x, double *f, int nx, double *Os,double *Mr,int *S,int s_flag,int r_flag) /* Hybrid Function 5 */
918{
919 int i,tmp,cf_num=5;
920 double fit[5];
921 int G[5],G_nx[5];
922 double Gp[5]={0.1,0.2,0.2,0.2,0.3};
923
924 tmp=0;
925 for (i=0; i<cf_num-1; i++)
926 {
927 G_nx[i] = ceil(Gp[i]*nx);
928 tmp += G_nx[i];
929 }
930 G_nx[cf_num-1]=nx-tmp;
931
932 G[0]=0;
933 for (i=1; i<cf_num; i++)
934 {
935 G[i] = G[i-1]+G_nx[i-1];
936 }
937
938 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag); /* shift and rotate */
939
940 for (i=0; i<nx; i++)
941 {
942 y[i]=z[S[i]-1];
943 }
944 i=0;
945 escaffer6_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
946 i=1;
947 hgbat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
948 i=2;
949 rosenbrock_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
950 i=3;
951 schwefel_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
952 i=4;
953 ellips_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
954
955 f[0]=0.0;
956 for(i=0;i<cf_num;i++)
957 {
958 f[0] += fit[i];
959 }
960}
961
962void hf06 (double *x, double *f, int nx, double *Os,double *Mr,int *S,int s_flag,int r_flag) /* Hybrid Function 6 */
963{
964 int i,tmp,cf_num=5;
965 double fit[5];
966 int G[5],G_nx[5];
967 double Gp[5]={0.1,0.2,0.2,0.2,0.3};
968
969 tmp=0;
970 for (i=0; i<cf_num-1; i++)
971 {
972 G_nx[i] = ceil(Gp[i]*nx);
973 tmp += G_nx[i];
974 }
975 G_nx[cf_num-1]=nx-tmp;
976
977 G[0]=0;
978 for (i=1; i<cf_num; i++)
979 {
980 G[i] = G[i-1]+G_nx[i-1];
981 }
982
983 sr_func (x, z, nx, Os, Mr, 1.0, s_flag, r_flag); /* shift and rotate */
984
985 for (i=0; i<nx; i++)
986 {
987 y[i]=z[S[i]-1];
988 }
989 i=0;
990 katsuura_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
991 i=1;
992 happycat_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
993 i=2;
994 grie_rosen_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
995 i=3;
996 schwefel_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
997 i=4;
998 ackley_func(&y[G[i]],&fit[i],G_nx[i],Os,Mr,0,0);
999 f[0]=0.0;
1000 for(i=0;i<cf_num;i++)
1001 {
1002 f[0] += fit[i];
1003 }
1004}
1005
1006void cf01 (double *x, double *f, int nx, double *Os,double *Mr,int r_flag) /* Composition Function 1 */
1007{
1008 int i,cf_num=5;
1009 double fit[5];
1010 double delta[5] = {10, 20, 30, 40, 50};
1011 double bias[5] = {0, 100, 200, 300, 400};
1012
1013 i=0;
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;
1016 i=1;
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;
1019 i=2;
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;
1022 i=3;
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;
1025 i=4;
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);
1029}
1030
1031void cf02 (double *x, double *f, int nx, double *Os,double *Mr,int r_flag) /* Composition Function 2 */
1032{
1033 int i,cf_num=3;
1034 double fit[3];
1035 double delta[3] = {20,20,20};
1036 double bias[3] = {0, 100, 200};
1037
1038 i=0;
1039 schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,0);
1040 i=1;
1041 rastrigin_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1042 i=2;
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);
1045}
1046
1047void cf03 (double *x, double *f, int nx, double *Os,double *Mr,int r_flag) /* Composition Function 3 */
1048{
1049 int i,cf_num=3;
1050 double fit[3];
1051 double delta[3] = {10,30,50};
1052 double bias[3] = {0, 100, 200};
1053 i=0;
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;
1056 i=1;
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;
1059 i=2;
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);
1063}
1064
1065void cf04 (double *x, double *f, int nx, double *Os,double *Mr,int r_flag) /* Composition Function 4 */
1066{
1067 int i,cf_num=5;
1068 double fit[5];
1069 double delta[5] = {10,10,10,10,10};
1070 double bias[5] = {0, 100, 200, 300, 400};
1071 i=0;
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;
1074 i=1;
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;
1077 i=2;
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;
1080 i=3;
1081 weierstrass_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1082 fit[i]=1000*fit[i]/400;
1083 i=4;
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);
1087}
1088
1089void cf05 (double *x, double *f, int nx, double *Os,double *Mr,int r_flag) /* Composition Function 4 */
1090{
1091 int i,cf_num=5;
1092 double fit[5];
1093 double delta[5] = {10,10,10,20,20};
1094 double bias[5] = {0, 100, 200, 300, 400};
1095 i=0;
1096 hgbat_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],1,r_flag);
1097 fit[i]=10000*fit[i]/1000;
1098 i=1;
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;
1101 i=2;
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;
1104 i=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;
1107 i=4;
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);
1111}
1112
1113void cf06 (double *x, double *f, int nx, double *Os,double *Mr,int r_flag) /* Composition Function 6 */
1114{
1115 int i,cf_num=5;
1116 double fit[5];
1117 double delta[5] = {10,20,30,40,50};
1118 double bias[5] = {0, 100, 200, 300, 400};
1119 i=0;
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;
1122 i=1;
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;
1125 i=2;
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;
1128 i=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;
1131 i=4;
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);
1135}
1136
1137void cf07 (double *x, double *f, int nx, double *Os,double *Mr,int *SS,int r_flag) /* Composition Function 7 */
1138{
1139 int i,cf_num=3;
1140 double fit[3];
1141 double delta[3] = {10,30,50};
1142 double bias[3] = {0, 100, 200};
1143 i=0;
1144 hf01(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1145 i=1;
1146 hf02(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1147 i=2;
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);
1150}
1151
1152void cf08 (double *x, double *f, int nx, double *Os,double *Mr,int *SS,int r_flag) /* Composition Function 8 */
1153{
1154 int i,cf_num=3;
1155 double fit[3];
1156 double delta[3] = {10,30,50};
1157 double bias[3] = {0, 100, 200};
1158 i=0;
1159 hf04(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1160 i=1;
1161 hf05(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],&SS[i*nx],1,r_flag);
1162 i=2;
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);
1165}
1166
1167
1168
1169void shiftfunc (double *x, double *xshift, int nx,double *Os)
1170{
1171 int i;
1172 for (i=0; i<nx; i++)
1173 {
1174 xshift[i]=x[i]-Os[i];
1175 }
1176}
1177
1178void rotatefunc (double *x, double *xrot, int nx,double *Mr)
1179{
1180 int i,j;
1181 for (i=0; i<nx; i++)
1182 {
1183 xrot[i]=0;
1184 for (j=0; j<nx; j++)
1185 {
1186 xrot[i]=xrot[i]+x[j]*Mr[i*nx+j];
1187 }
1188 }
1189}
1190
1191void 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 */
1192{
1193 int i;
1194 if (s_flag==1)
1195 {
1196 if (r_flag==1)
1197 {
1198 shiftfunc(x, y, nx, Os);
1199 for (i=0; i<nx; i++)//shrink to the original search range
1200 {
1201 y[i]=y[i]*sh_rate;
1202 }
1203 rotatefunc(y, sr_x, nx, Mr);
1204 }
1205 else
1206 {
1207 shiftfunc(x, sr_x, nx, Os);
1208 for (i=0; i<nx; i++)//shrink to the original search range
1209 {
1210 sr_x[i]=sr_x[i]*sh_rate;
1211 }
1212 }
1213 }
1214 else
1215 {
1216
1217 if (r_flag==1)
1218 {
1219 for (i=0; i<nx; i++)//shrink to the original search range
1220 {
1221 y[i]=x[i]*sh_rate;
1222 }
1223 rotatefunc(y, sr_x, nx, Mr);
1224 }
1225 else
1226 for (i=0; i<nx; i++)//shrink to the original search range
1227 {
1228 sr_x[i]=x[i]*sh_rate;
1229 }
1230 }
1231}
1232
1233void asyfunc (double *x, double *xasy, int nx, double beta)
1234{
1235 int i;
1236 for (i=0; i<nx; i++)
1237 {
1238 if (x[i]>0)
1239 xasy[i]=pow(x[i],1.0+beta*i/(nx-1)*pow(x[i],0.5));
1240 }
1241}
1242
1243void oszfunc (double *x, double *xosz, int nx)
1244{
1245 int i,sx;
1246 double c1,c2,xx;
1247 for (i=0; i<nx; i++)
1248 {
1249 if (i==0||i==nx-1)
1250 {
1251 if (x[i]!=0)
1252 xx=log(fabs(x[i]));
1253 if (x[i]>0)
1254 {
1255 c1=10;
1256 c2=7.9;
1257 }
1258 else
1259 {
1260 c1=5.5;
1261 c2=3.1;
1262 }
1263 if (x[i]>0)
1264 sx=1;
1265 else if (x[i]==0)
1266 sx=0;
1267 else
1268 sx=-1;
1269 xosz[i]=sx*exp(xx+0.049*(sin(c1*xx)+sin(c2*xx)));
1270 }
1271 else
1272 xosz[i]=x[i];
1273 }
1274}
1275
1276
1277void cf_cal(double *x, double *f, int nx, double *Os,double * delta,double * bias,double * fit, int cf_num)
1278{
1279 int i,j;
1280 double *w;
1281 double w_max=0,w_sum=0;
1282 w=(double *)malloc(cf_num * sizeof(double));
1283 for (i=0; i<cf_num; i++)
1284 {
1285 fit[i]+=bias[i];
1286 w[i]=0;
1287 for (j=0; j<nx; j++)
1288 {
1289 w[i]+=pow(x[j]-Os[i*nx+j],2.0);
1290 }
1291 if (w[i]!=0)
1292 w[i]=pow(1.0/w[i],0.5)*exp(-w[i]/2.0/nx/pow(delta[i],2.0));
1293 else
1294 w[i]=INF;
1295 if (w[i]>w_max)
1296 w_max=w[i];
1297 }
1298
1299 for (i=0; i<cf_num; i++)
1300 {
1301 w_sum=w_sum+w[i];
1302 }
1303 if(w_max==0)
1304 {
1305 for (i=0; i<cf_num; i++)
1306 w[i]=1;
1307 w_sum=cf_num;
1308 }
1309 f[0] = 0.0;
1310 for (i=0; i<cf_num; i++)
1311 {
1312 f[0]=f[0]+w[i]/w_sum*fit[i];
1313 }
1314 free(w);
1315}