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