00001
00020 #define _FUNCTIONS
00021
00022 #include <math.h>
00023 #include "functions.h"
00024 #include "newutil.h"
00025 #include "../common/define.h"
00026 #include "../common/random.h"
00027 #include <assert.h>
00028 #include <cmath>
00029
00030 using namespace std;
00031
00032 double pow(const tGen x, double n) {
00033 return (pow(x, (const tGen) n));
00034 }
00035
00036
00037
00038 double sphere(const tGen *x, int n)
00039 {
00040 int i;
00041 double sum;
00042
00043 sum = 0.0;
00044 for (i = 0; i < n; i++)
00045 sum += x[i] * x[i];
00046
00047 return (sum);
00048 }
00049
00050 double step(const tGen *x, int dim) {
00051 double result=0;
00052 int i=0;
00053
00054 for (i = 0; i < dim; i++) {
00055 result += fabs(x[i]);
00056 }
00057
00058 result += 6*dim;
00059 return result;
00060 }
00061
00062 double step2(const tGen *x, int dim) {
00063 double result=0;
00064 int i=0;
00065
00066 for (i = 0; i < dim; i++) {
00067 result += ceil(x[i]);
00068 }
00069
00070 result += 6*dim;
00071 return result;
00072 }
00073
00074
00075
00076
00077
00078 double branin(const tGen *x, int n)
00079 {
00080 double A,B,C;
00081 double x1, x2, s1, s2;
00082 x1 = x[0];
00083 x2 = x[1];
00084 A = 5.0/(4*M_PI*M_PI);
00085 B = 5.0/M_PI;
00086 C = 1-(1.0/(8*M_PI));
00087
00088 s1 = x2-A*x1*x1+B*x1-6;
00089 s2 = 10*C*cos(x1)+10;
00090
00091 return (s1*s1+s2);
00092 }
00093
00094
00095
00096 double b2(const tGen *x, int n) {
00097 double x1, x2;
00098 x1 = x[0];
00099 x2 = x[1];
00100 return (x1*x1+2*x2*x2-0.3*cos(3*M_PI*x1)-0.4*cos(4*M_PI*x2)+0.7);
00101 }
00102
00103 double easom(const tGen *x, int n) {
00104 double x1, x2;
00105 double sum;
00106 x1 = x[0];
00107 x2 = x[1];
00108 sum = (x1-M_PI)*(x1-M_PI)+(x2-M_PI)*(x2-M_PI);
00109
00110 return -cos(x1)*cos(x2)*exp(-sum);
00111 }
00112
00113
00114 double shubert(const tGen *x, int n) {
00115 int j;
00116 double s1,s2;
00117 s1 = s2 = 0;
00118
00119 for (j = 1; j <= 5; j++) {
00120 s1 += j*cos((j+1)*x[0]+j);
00121 s2 += j*cos((j+1)*x[1]+j);
00122 }
00123
00124 return (s1*s2);
00125 }
00126
00127
00128 double beale(const tGen *x, int n) {
00129 double s1,s2,s3;
00130 double x1=x[0], x2=x[1];
00131
00132 s1 = 1.5-x1+x1*x2;
00133 s2 = 2.25-x1+x1*x2*x2;
00134 s3 = 2.625-x1+x1*x2*x2*x2;
00135
00136 return (s1*s1+s2*s2+s3*s3);
00137 }
00138
00139
00140 double booth(const tGen *x, int n) {
00141 double s1,s2;
00142 double x1=x[0],x2=x[1];
00143
00144 s1 = x1+2*x2-7;
00145 s2 = 2*x1+x2-5;
00146 return (s1*s1+s2*s2);
00147 }
00148
00149
00150 double matyas(const tGen *x, int n) {
00151 double x1=x[0];
00152 double x2=x[1];
00153
00154 return (0.26*(x1*x1+x2*x2))-(0.48*x1*x2);
00155 }
00156
00157
00158 double bump(const tGen *x, int n) {
00159 double cos_x;
00160 double num,denom;
00161 int i;
00162 double sum1 = 0;
00163 double sum2 = 1;
00164 double sum3 = 0;
00165
00166 for (i = 0; i < n; i++) {
00167 cos_x = cos(x[i]);
00168 sum1 += (cos_x*cos_x*cos_x*cos_x);
00169 }
00170
00171 for (i = 0; i < n; i++) {
00172 cos_x = cos(x[i]);
00173 sum2 *= cos_x*cos_x;
00174 }
00175
00176 num = fabs(sum1-2*sum2);
00177
00178 for (i = 0; i < n; i++) {
00179 sum3 += (i+1)*x[i]*x[i];
00180 }
00181
00182 assert(sum3 > 0);
00183 denom = sqrt(sum3);
00184 return num/denom;
00185 }
00186
00187
00188 double sixhumpcamelback(const tGen *x, int n) {
00189 double x1=x[0];
00190 double x2=x[1];
00191 double x12=x1*x1;
00192 double x22=x2*x2;
00193
00194 return (4*x12-2.1*x12*x12+(x12*x12*x12)/3.0+x1*x2-4*x22+4*x22*x22);
00195 }
00196
00197
00198
00199
00200 double
00201 rosenbrock(const tGen *x, int n)
00202 {
00203
00204 int i;
00205
00206 double Sum,
00207 sum1, sum2;
00208
00209 for (Sum = 0, i = 0; i < n-1; i++) {
00210 sum1 = x[i+1]-x[i]*x[i];
00211 sum2 = x[i]-1;
00212 Sum += 100*sum1*sum1+sum2*sum2;
00213 }
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 return (Sum);
00224 }
00225
00227
00228
00229 double
00230 goldstein_price(const tGen *x, int n)
00231 {
00232 double suma;
00233 suma=(1.0 + (x[0]+x[1]+1.0)*(x[0]+x[1]+1.0)*
00234 (19.0-14.0*x[0]+3.0*x[0]*x[0]-14.0*x[1]+6.0*x[0]*x[1]+3.0*x[1]*x[1]))*
00235 (30.0 + (2.0*x[0]-3.0*x[1])*(2.0*x[0]-3.0*x[1])*
00236 (18.0-32.0*x[0]+12.0*x[0]*x[0]+48.0*x[1]-36.0*x[0]*x[1]+27.0*x[1]*x[1]));
00237
00238 return (suma);
00239 }
00240
00241
00242 double zakharov(const tGen *x, int D) {
00243 int j;
00244 double s1,s2,s3,inc;
00245
00246 s1=s2=s3= 0;
00247
00248 for (j = 1; j <= D; j++) {
00249 s1 += x[j-1]*x[j-1];
00250 inc = 0.5*j*x[j-1];
00251 s2 += inc*inc;
00252 s3 += inc*inc*inc*inc;
00253 }
00254
00255 return (s1+s2+s3);
00256 }
00257
00258
00259 double dejoung(const tGen *x, int n) {
00260 return (x[0]*x[0]+x[1]*x[1]+x[2]*x[2]);
00261 }
00262
00263
00264 double bohachevsky(const tGen *x, int n) {
00265 double x1,x2;
00266
00267 x1 = x[0];
00268 x2 = x[1];
00269
00270 return (x1*x1+2*x2*x2-0.3*cos(3*M_PI*x1)*cos(4*M_PI*x2)+0.3);
00271 }
00272
00273
00274 double watson(const tGen *x, int n) {
00275 int i,j;
00276 double ai;
00277 double total,sum1,sum2;
00278
00279 total = 0;
00280
00281 for (i = 1; i <= 30; i++) {
00282
00283 sum1 = 0;
00284
00285 ai = (i-1)/29.0;
00286
00287 for (j = 1; j < n; j++) {
00288 sum1 += j * pow(ai, j-1) * x[ j ];
00289 }
00290
00291
00292 sum2 = 0;
00293
00294 for (j = 1; j <= n; j++) {
00295 sum2 += pow(ai, j-1) * x[ j-1 ];
00296 }
00297
00298 total += (sum1-sum2-1)*(sum1-sum2-1);
00299 }
00300
00301 return total + x[0]*x[0];
00302 }
00303
00304
00305 double Hartman34(const tGen *x, int n) {
00306 int i, j;
00307 double s1, s2;
00308 double c[] = {1.0,1.2,3.0,3.2};
00309 double a[4][3] = {
00310 {3.0,10.0,30.0},
00311 {0.1,10.0,35.0},
00312 {3.0,10.0,30.0},
00313 {0.1,10.0,35.0}
00314 };
00315
00316 double p[4][3] = {
00317 {0.3689,0.1170,0.2673},
00318 {0.4699,0.4387,0.7470},
00319 {0.1091,0.8732,0.5547},
00320 {0.0381,0.5743,0.8828}
00321 };
00322
00323 for (i = 0, s1 = 0; i < 4; i++) {
00324 for (s2 = 0, j = 0; j < 3; j++) {
00325 s2 += a[i][j]*(x[j]-p[i][j])*(x[j]-p[i][j]);
00326 }
00327
00328 s1 += c[i]*exp(-s2);
00329 }
00330
00331 return s1;
00332 }
00333
00334
00335 double colville(const tGen *x, int n) {
00336 double x1=x[0],x2=x[1],x3=x[2],x4=x[3];
00337 double Sum=0;
00338
00339 Sum += 100*(x2-x1*x1)*(x2-x1*x1)+(1-x1)*(1-x1);
00340 Sum += 90*(x4-x3*x3)*(x4-x3*x3)+(1-x3)*(1-x3);
00341 Sum += 10.1*((x2-1)*(x2-1)+(x4-1)*(x4-1));
00342 Sum += 19.8*(x2-1)*(x4-1);
00343 return Sum;
00344 }
00345
00346
00347
00348
00349 double shekel(const tGen *x, int n) {
00350 double value,value2;
00351 int i, j;
00352 double c[] = {0.1,0.2,0.2,0.4,0.4,0.6,0.3,0.7,0.5,0.5};
00353 double a[][4] = {
00354 {4.0,4.0,4.0,4.0},
00355 {1.0,1.0,1.0,1.0},
00356 {8.0,8.0,8.0,8.0},
00357 {6.0,6.0,6.0,6.0},
00358 {3.0,7.0,3.0,7.0},
00359 {2.0,9.0,2.0,9.0},
00360 {5.0,5.0,3.0,3.0},
00361 {8.0,1.0,8.0,1.0},
00362 {6.0,2.0,6.0,2.0},
00363 {7.0,3.6,7.0,3.6}
00364 };
00365
00366 value = 0;
00367
00368 for (i = 0; i < n; i++) {
00369 value2 = 0;
00370
00371 for (j = 0; j < 4; j++) {
00372 value2 += (x[j]-a[i][j])*(x[j]-a[i][j]);
00373 }
00374
00375 value += 1.0/(value2+c[i]);
00376 }
00377
00378 return (-value);
00379 }
00380
00381
00382 double shekel5(const tGen *x, int n) {
00383 return shekel(x,5);
00384 }
00385
00386 double shekel7(const tGen *x, int n) {
00387 return shekel(x,7);
00388 }
00389
00390 double shekel10(const tGen *x, int n) {
00391 return shekel(x,10);
00392 }
00393
00394
00395
00396 double Perm2(const tGen *x, int n, double beta) {
00397 int i, k;
00398 double sum,result,coc;
00399
00400 result = 0;
00401
00402 for (k=1; k <= n; k++) {
00403 sum = 0;
00404
00405 for (i = 1; i <= n; i++) {
00406 coc = (x[i-1]/i);
00407 sum += (pow( (const tGen)i,k)+beta)*(pow(coc,k)-1);
00408 }
00409
00410 result +=sum*sum;
00411 }
00412
00413 return result;
00414 }
00415
00416 double Perm(const tGen *x, int n) {
00417 return Perm2(x, n, 0.5);
00418 }
00419
00420
00421 double Perm02(const tGen *x, int n, double beta) {
00422 int i, k;
00423 double sum,result,coc;
00424
00425 result = 0;
00426
00427 for (k=1; k <= n; k++) {
00428 sum = 0;
00429
00430 for (i = 1; i <= n; i++) {
00431 coc = (1.0/i);
00432 sum += (i+beta)*(pow(x[i-1],k)-pow(coc,k));
00433 }
00434
00435 result +=sum*sum;
00436 }
00437
00438 return result;
00439 }
00440
00441 double Perm_0(const tGen *x, int n) {
00442 return Perm02(x, n, 10.0);
00443 }
00444
00445
00446
00447 double PowerSum(const tGen *x, int n) {
00448 int i, k;
00449 double b[] ={8.0,18.0,44.0,114.0};
00450 double sum,result;
00451
00452 result = 0;
00453
00454 for (k = 1; k <= n; k++) {
00455 sum = 0;
00456
00457 for (i = 0; i < n; i++) {
00458 sum += pow(x[i],k);
00459 }
00460
00461 sum -= b[k-1];
00462 result += sum*sum;
00463 }
00464
00465 return result;
00466 }
00467
00468
00469 double Hartman64(const tGen *x, int n) {
00470 int i, j;
00471 double s1, s2;
00472 double c[] = {1.0,1.2,3.0,3.2};
00473 double a[4][6] = {
00474 {10.0, 3.0,17.0, 3.5, 1.7, 8.0},
00475 {0.05,10.0,17.0, 0.1, 8.0,14.0},
00476 {3.0, 3.5,1.7, 10.0,17.0, 8.0},
00477 {17.0, 8.0,0.05, 10.0, 0.1, 14.0}
00478 };
00479
00480 double p[4][6] = {
00481 {0.1312, 0.1696, 0.5569, 0.0124, 0.8283, 0.5886},
00482 {0.2329, 0.4135, 0.8307, 0.3736, 0.1004, 0.9991},
00483 {0.2348, 0.1451, 0.3522, 0.2883, 0.3047, 0.6650},
00484 {0.4047, 0.8828, 0.8732, 0.5743, 0.1091, 0.0381}
00485 };
00486
00487 for (i = 0, s1 = 0; i < 4; i++) {
00488 for (s2 = 0, j = 0; j < 6; j++) {
00489 s2 += a[i][j]*(x[j]-p[i][j])*(x[j]-p[i][j]);
00490 }
00491
00492 s1 += c[i]*exp(-s2);
00493 }
00494
00495 return s1;
00496 }
00497
00498
00499 double Trid(const tGen *x, int n) {
00500 int i;
00501 double sum,rest;
00502
00503 sum = rest = 0;
00504
00505 for (i = 0; i < n; i++) {
00506 sum += (x[i]-1)*(x[i]-1);
00507 }
00508
00509 for (i = 1; i < n; i++) {
00510 rest += x[i]*x[i-1];
00511 }
00512
00513 return (sum-rest);
00514 }
00515
00516
00517
00518
00519
00520 double Chebychev(const tGen *tmp, int D)
00521 {
00522 int i,j;
00523 double px,x=-1,result=0,dx=0;
00524
00525 if ( D == 9 )
00526 dx=72.66066;
00527 if ( D == 17 )
00528 dx=10558.145;
00529
00530 for (i=0;i<=100;i++)
00531 {
00532 px=tmp[0];
00533 for (j=1;j<D;j++) px=x*px+tmp[j];
00534 if (px<-1 || px>1) result+=(1.-px)*(1.-px);
00535 x+=.02;
00536 }
00537
00538 px=tmp[0];
00539 for (j=1;j<D;j++) px=1.2*px+tmp[j];
00540 px=px-dx;
00541 if (px<0) result+=px*px;
00542
00543 px=tmp[0];
00544 for (j=1;j<D;j++) px=-1.2*px+tmp[j];
00545 px=px-dx;
00546 if (px<0) result+=px*px;
00547
00548 return(result);
00549 }
00550
00551
00552 double cheb9(const tGen *x, int n)
00553 {
00554 double result;
00555
00556 result=Chebychev(x, 9);
00557 return(result);
00558
00559 }
00560
00561
00562
00563 double f_5(const tGen *x, int n) {
00564 int a[2][25] ={
00565 {
00566 -32, -16, 0, 16, 32, -32, -16, 0, 16, 32, -32, -16, 0, 16, 32,
00567 -32, -16, 0, 16, 32, -32, -16, 0, 16, 32 },
00568 {
00569 -32, -32, -32, -32, -32, -16, -16, -16, -16, -16,0,0,0,0,0,
00570 16, 16, 16, 16, 16, 32, 32, 32, 32, 32 }
00571 };
00572
00573 double K = 500.0;
00574
00575
00576 int i,j;
00577
00578 double Sum = 0.0,
00579 Val,
00580 Dif;
00581
00582 for (Sum = 1.0 / K, j = 0; j < 25; j++)
00583 {
00584 for (Val = (const tGen)j + 1.0, i = 0; i < n; i++)
00585 {
00586 Dif = x[i] - (const tGen)a[i][j];
00587 Val += pow(Dif, 6.0);
00588 }
00589 Sum += 1.0 / Val;
00590 }
00591
00592 return (1.0 / Sum);
00593 }
00594
00595
00596
00597 double
00598 schwefel_12(const tGen *x, int n)
00599 {
00600
00601 register int i;
00602
00603 double Sum,
00604 Val;
00605
00606 for (Sum = Val = 0.0, i = 0; i < n; i++)
00607 {
00608 Val += x[i];
00609 Sum += Val * Val;
00610 }
00611
00612 return (Sum);
00613
00614 }
00615
00616
00617 double
00618 rastrigin(const tGen *x, int n)
00619 {
00620 #define OMEGA 6.28318530717958647688
00621 #define AMP 10.0
00622
00623
00624 register int i;
00625 double Sum;
00626
00627 for (Sum = 0.0, i = 0; i < n; i++)
00628 Sum += x[i] * x[i] - AMP * cos(OMEGA * x[i]);
00629
00630 Sum += (const tGen)n * AMP;
00631
00632 return(Sum);
00633 }
00634
00635 double rastrigin_funcR(const tGen *x, int n) {
00636 MyMatrix A(n,n);
00637 double result=0;
00638 Real data[n];
00639 int i;
00640
00641 for (i = 0; i < n; i++) {
00642 data[i] = x[i];
00643 }
00644
00645 A = 0.0;
00646
00647 for (i = 1; i <= n; ++i) {
00648 ColumnVector colA = A.Column(i);
00649 colA[i-1]=4.0/5.0;
00650
00651 if (i % 2 == 0) {
00652 colA[i-2]=-3.0/5.0;
00653 }
00654 else if (i != n) {
00655 colA[i] = 3.0/5.0;
00656 }
00657
00658 A.Column(i) = colA;
00659 }
00660
00661 ColumnVector t(n);
00662 t <<data;
00663
00664 ColumnVector y(n);
00665 y = A*t;
00666
00667 for (i = 0, result = 0.0; i < n; i++) {
00668 result += pow2(y[i])-10*cos(2*M_PI*y[i])+10;
00669 }
00670 return result;
00671 }
00672
00673 double rastrigin_funcS(const tGen *x, int n) {
00674 double value, sum;
00675 int i;
00676 double D=n-1.0;
00677
00678 for (i = 0, sum = 0; i < n; i++) {
00679 value = pow(10.0, i/D)*x[i];
00680 sum += pow2(value)-10*cos(2*M_PI*value)+10;
00681 }
00682
00683 return sum;
00684 }
00685
00686
00687
00688
00689 double schwefel_226(const tGen *x, int n)
00690 {
00691 int i;
00692 double h, raiz;
00693
00694 h = 0;
00695
00696 for (i=0; i<n; i++)
00697 {
00698 raiz=sqrt(fabs(x[i]));
00699 h -= x[i] * sin(raiz);
00700 }
00701
00702 return (h);
00703 }
00704
00705 double
00706 schwefel(const tGen *x, int n)
00707 {
00708 int i;
00709 double h, ab, raiz;
00710
00711 h=(const tGen)n;
00712 h*=418.9829;
00713
00714 for (i=0; i<n; i++)
00715 {
00716 if (x[i] > 0)
00717 ab = x[i];
00718 else
00719 ab = (-1.0) * x[i];
00720
00721 raiz=sqrt(ab);
00722
00723 h += x[i] * sin(raiz);
00724 }
00725
00726 return (h);
00727 }
00728
00729
00730
00731 double
00732 griewank(const tGen *x, int n)
00733 {
00734 register int i;
00735 double D =4000.0;
00736
00737 double Val1,
00738 Val2,
00739 Val3,
00740 Sum;
00741
00742 for (Val1 = 0.0, Val2 = 1.0, i = 0; i < n; i++)
00743 {
00744 Val1 += x[i] * x[i];
00745 Val3=sqrt((const tGen) (i + 1));
00746 Val2 *= cos(x[i] / Val3);
00747 }
00748
00749 Sum = Val1 / D - Val2 + 1.0;
00750 return (Sum);
00751 }
00752
00753
00754 double sum_squares(const tGen *x, int n) {
00755 int i;
00756 double result = 0;
00757
00758 for (i = 1; i <= n; i++) {
00759 result += i*x[i-1]*x[i-1];
00760 }
00761
00762 return result;
00763 }
00764
00765
00766 double powell(const tGen *x, int n) {
00767 int i, j, maxn;
00768 double result, sum1, sum2, sum3, sum4;
00769
00770 maxn = n/4;
00771 result = 0;
00772
00773 for (j = 1; j <= maxn; j++) {
00774 i = 4*j-1;
00775 sum1 = x[i-3]+10*x[i-2];
00776 sum2 = x[i-1]-x[i];
00777 sum3 = x[i-2]-2*x[i-1];
00778 sum4 = x[i-3]-x[i];
00779 result += sum1*sum1+5*sum2*sum2+pow(sum3, 4)+10*pow(sum4,4);
00780 }
00781
00782 return result;
00783 }
00784
00785
00786 double dixon_price(const tGen *x, int n) {
00787 double result;
00788 double sum;
00789 int i;
00790
00791 sum = result = 0;
00792 result += (x[0]-1.0)*(x[0]-1.0);
00793
00794 for (i = 1; i < n; i++) {
00795 sum = 2*x[i]-x[i-1];
00796 result += (i+1)*sum*sum;
00797 }
00798
00799 return result;
00800 }
00801
00802
00803
00804 double levy(const tGen *x, int n) {
00805 int i;
00806 double result=0;
00807 double A,op1,op2, sum;
00808
00809 result = sum = 0;
00810
00811 A = sin(3*M_PI*x[0]);
00812 result += A*A;
00813
00814 for (i = 0; i < n-2; i++) {
00815 op1=(x[i]-1)*(x[i]-1);
00816 op2 = sin(3*M_PI*x[i+1]);
00817 result += op1*op1*(1+op2*op2);
00818 }
00819
00820 op1 = (x[n-1]-1);
00821 op2 = sin(2*M_PI*x[n-1]);
00822 result += op1*(1+op2*op2);
00823
00824 return result;
00825 }
00826
00827
00828
00829
00830 double ackley(const tGen *x, int n)
00831 {
00832 int i;
00833 double A=20.0;
00834 double B=0.2;
00835 double Da=0.0;
00836 double E, Val1,
00837 Val2,
00838 Sum;
00839
00840 Da = 2.0*3.141592654;
00841 E = exp(1.0);
00842
00843 for (Val1 = Val2 = 0.0, i = 0; i < n; i++)
00844 {
00845 Val1 += x[i] * x[i];
00846 Val2 += cos(Da * x[i]);
00847 }
00848
00849
00850 Val1=sqrt(Val1 /(const tGen) n);
00851
00852 Val2=exp(Val2 / (const tGen) n);
00853
00854 Val1=exp(-B *Val1);
00855
00856 Sum = - A * Val1 + A - Val2 + E;
00857
00858 return (Sum);
00859 }
00860
00861
00862
00863 double F10(const tGen x, tGen y)
00864 {
00865 tGen z, t, salida;
00866
00867 z=(x*x+y*y);
00868 z=pow(z, 0.25);
00869 t=(x*x+y*y);
00870 t=50.0*pow(t, 0.1);
00871 t=sin(t);
00872 t=t*t+1.0;
00873 salida=z*t;
00874
00875 return(salida);
00876 }
00877
00878 double ef10(const tGen *x, int n)
00879 {
00880 int i;
00881 double suma;
00882
00883 for(i=0, suma=0.0; i<n-1; i++)
00884 suma+=F10(x[i], x[i+1]);
00885
00886 suma+=F10(x[n-1], x[0]);
00887
00888 return(suma);
00889 }
00890
00891
00892
00893
00894 double
00895 f_12(const tGen *x, int n)
00896 {
00897 int i, j, beta;
00898
00899 double Val1,
00900 Val2,
00901 suma,
00902 producto;
00903
00904 static int firstflag=1;
00905
00906 static double Exp2[100];
00907
00908 beta=30;
00909
00910
00911 if (firstflag)
00912 {
00913 firstflag=0;
00914 for (producto=1.0, i=0; i <= beta; i++)
00915 {
00916 Exp2[i]=producto;
00917 producto*=2.0;
00918 }
00919 }
00920
00921 for (producto=1.0, i = 0; i < n; i++)
00922 {
00923 for (suma=0.0, j=0; j <= beta; j++)
00924 {
00925 Val1=(const tGen)(Exp2[i+1]*x[i]);
00926
00927 Val2=fabs(Exp2[j]*x[i]-Val1);
00928
00929 suma+=Val2/Exp2[j];
00930 }
00931 producto*=1.0+(const tGen)(i+1)*suma;
00932 }
00933
00934 return(producto);
00935 }
00936
00940 double fcigtab(const tGen *x, int ndim) {
00941 double sum, result;
00942 int i;
00943 int begin =0;
00944 int end = ndim-1;
00945
00946 result = x[begin]*x[begin]+1e8*x[end]*x[end];
00947
00948 for (i = begin+1, sum=0; i < end; i++) {
00949 sum += x[i]*x[i];
00950 }
00951
00952 result += 1e4*sum;
00953 return result;
00954 }
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970 double suma_producto(const tGen *x, int n) {
00971 double s, p;
00972 int i;
00973
00974 s = 0.0;
00975 p = 1.0;
00976
00977 for (i = 0; i < n; ++i) {
00978 s += fabs(x[i]);
00979 p *= fabs(x[i]);
00980 }
00981
00982 return (s+p);
00983 }
00984
00985 double maximo_x(const tGen *x, int n) {
00986 double max_x, f_x;
00987 int i;
00988
00989 max_x = 0;
00990
00991 for (i = 0; i < n; ++i) {
00992 f_x = fabs(x[i]);
00993
00994 if (i == 0 || f_x > max_x) {
00995 max_x = f_x;
00996 }
00997 }
00998
00999 return max_x;
01000 }
01001
01002
01003 static double MatA[10][10]={{5.0, 4.0, 5.0, 2.0, 9.0, 5.0, 4.0, 2.0, 3.0, 1.0},
01004 {9.0, 7.0, 1.0, 1.0, 7.0, 2.0, 2.0, 6.0, 6.0, 9.0},
01005 {3.0, 1.0, 8.0, 6.0, 9.0, 7.0, 4.0, 2.0, 1.0, 6.0},
01006 {8.0, 3.0, 7.0, 3.0, 7.0, 5.0, 3.0, 9.0, 9.0, 5.0},
01007 {9.0, 5.0, 1.0, 6.0, 3.0, 4.0, 2.0, 3.0, 3.0, 9.0},
01008 {1.0, 2.0, 3.0, 1.0, 7.0, 6.0, 6.0, 3.0, 3.0, 3.0},
01009 {1.0, 5.0, 7.0, 8.0, 1.0, 4.0, 7.0, 8.0, 4.0, 8.0},
01010 {9.0, 3.0, 8.0, 6.0, 3.0, 4.0, 7.0, 1.0, 8.0, 1.0},
01011 {8.0, 2.0, 8.0, 5.0, 3.0, 8.0, 7.0, 2.0, 7.0, 5.0},
01012 {2.0, 1.0, 2.0, 2.0, 9.0, 8.0, 7.0, 4.0, 4.0, 1.0}};
01013
01014 static double MatB[10]={40.0, 50.0, 47.0, 59.0, 45.0, 35.0, 53.0, 50.0, 55.0, 40.0};
01015
01016 double sle(const tGen *x, int n)
01017 {
01018 int i, j;
01019 double ER, er;
01020
01021 ER=0.0;
01022 for (i=0; i<n; i++)
01023 {
01024 er=0.0;
01025 for (j=0; j<n; j++) er+=(MatA[i][j] * x[j]);
01026 if (er>MatB[i]) ER+=er-MatB[i];
01027 else ER+=MatB[i]-er;
01028 }
01029
01030 return(ER);
01031 }
01032
01033
01034 double f_14(const tGen *x, int n)
01035 {
01036 int i;
01037 double y[110], sum;
01038
01039 sum = 0.0;
01040 y[0]=100.0;
01041
01042 for (i = 0; i < n; i++)
01043 {
01044 sum+=(y[i]*y[i]+x[i]*x[i]);
01045 y[i+1]=y[i]+x[i];
01046 }
01047
01048 return (y[n]+sum);
01049 }
01050
01051
01052
01053 double y_0(const tGen a1, double w1, double a2, double w2, double a3,
01054 double w3, int t)
01055 {
01056 double x, y, eta;
01057
01058 eta=2.0*3.141592654/100.0;
01059
01060 y=w3*(const tGen)t*eta;
01061 x=a3*sin(y);
01062 y=x+w2*(const tGen)t*eta;
01063 x=a2*sin(y);
01064 y=x+w1*(const tGen)t*eta;
01065 x=a1*sin(y);
01066 return(x);
01067 }
01068
01069 double fms(const tGen *x, int n)
01070 {
01071 int i;
01072 double yt, yt_0, sum;
01073
01074 sum=0.0;
01075 for (i=0; i <=100; i++)
01076 {
01077 yt_0= y_0(1.0, 5.0, -1.5, 4.8, 2.0, 4.9, i);
01078 yt = y_0(x[0], x[1], x[2], x[3], x[4], x[5], i);
01079 sum=sum+(yt_0-yt)*(yt_0-yt);
01080 }
01081
01082 return (sum);
01083 }
01084
01085 double fschaffer(const tGen *x, int n) {
01086 double s, result;
01087 double sin_s;
01088 int i;
01089
01090 for (i = 0, result=0; i < n-1; i++) {
01091 s=pow2(x[i])+pow2(x[i+1]);
01092 sin_s = sin(50*pow(s, 0.1));
01093 result += pow(s, 0.25)*(pow2(sin_s)+1);
01094 }
01095
01096 return result;
01097 }
01098
01099 double f8f2(const tGen *x, int n) {
01100 double sum;
01101 tGen aux[2];
01102 int i;
01103
01104 for (i = 0, sum=0; i < n-1; ++i) {
01105 sum += griewank(&x[i], 2);
01106 }
01107
01108 aux[0] = x[n-1];
01109 aux[1] = x[0];
01110 sum += griewank(aux, 2);
01111 return sum;
01112 }
01113
01114 double fschwefelmult(const tGen *x, int n) {
01115 double sum;
01116 int i;
01117
01118 for (i = 0, sum = 0; i < n; i++) {
01119 sum += x[i]*sin(sqrt(fabs(x[i])));
01120 }
01121
01122 return -sum;
01123 }
01124
01125
01126
01127
01128 double objfn(const tGen *x, int nvar) {
01129 int j,k,nhard=1;
01130 int NVAR=nvar;
01131
01132 double cw=0.5, cmin=0.0, A=0.05, B=0.01;
01133
01134 tGen fnval=0.0, fdum=0.0, fhdum=0.0, sdum=0.0;
01135
01136 tGen af[5][NVAR], cf[5], dist[5], wf[5];
01137
01138 tGen dum[5], dif[NVAR], dist2=0.0;
01139
01140
01141
01142 for (j=0; j<NVAR; j++) af[0][j]=2.0;
01143
01144 for (j=0; j<NVAR; j++) af[1][j]=5.0;
01145
01146 for (j=0; j<NVAR; j++) af[2][j]=7.0;
01147
01148 for (j=0; j<NVAR; j++) af[3][j]=9.0;
01149
01150 for (j=0; j<NVAR; j++) af[4][j]=3.5;
01151
01152
01153
01154
01155
01156 wf[0]=cw;
01157
01158 wf[1]=cw;
01159
01160 wf[2]=cw;
01161
01162
01163
01164 wf[3]=cw;
01165
01166 wf[4]=cw;
01167
01168
01169
01170 cf[0]=A;
01171
01172 cf[1]=A;
01173
01174 cf[2]=A;
01175
01176 cf[3]=A;
01177
01178 cf[4]=A;
01179
01180
01181
01182
01183
01184
01185
01186 for (k=0; k<4; k++)
01187
01188 {
01189
01190 sdum=0.0;
01191
01192 for(j=0; j<nhard; j++)
01193
01194 {
01195
01196 dif[j] = x[j] - af[k][j];
01197
01198 sdum += (dif[j]*dif[j]);
01199
01200 }
01201
01202 dist[k] = sqrt(sdum);
01203
01204 }
01205
01206 dist[4] = 0.0;
01207
01208
01209
01210 for (k=0; k<4; k++)
01211
01212 dum[k] = cf[k] * exp(-(dist[k]*dist[k])/(wf[k]*wf[k]*(nhard)));
01213
01214
01215
01216 if (x[0]<4) cmin=af[0][0];
01217
01218 else if (x[0]<6) cmin=af[1][0];
01219
01220 else if (x[0]<8.5) cmin=af[2][0];
01221
01222 else if (x[0]<10) cmin=af[3][0];
01223
01224
01225
01226 sdum=0.0;
01227
01228 for(j=0; j<NVAR; j++)
01229
01230 {
01231
01232 dif[j] = x[j] - cmin;
01233
01234 sdum += (dif[j]*dif[j]);
01235
01236 }
01237
01238 dist2 = sqrt(sdum);
01239
01240
01241
01242 fhdum = B *dist2 / sqrt( (double) NVAR);
01243
01244
01245
01246 for (k=0; k<4; k++) fdum += dum[k];
01247
01248 fnval= A - fdum + fhdum;
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258 return(fnval);
01259 }
01260
01261
01262 double salomon(const tGen *x, int nvar) {
01263 double valtam = sqrt(sphere(x, nvar));
01264
01265 return (-cos(2*M_PI*valtam)+0.1*valtam+1);
01266 }
01267
01268 double whitely(const tGen *x, int nvar) {
01269 tGen y[nvar][nvar];
01270 int i, j;
01271 double sum;
01272
01273 for (i = 0; i < nvar; ++i) {
01274 for (j = 0; j < nvar; ++j) {
01275 y[i][j] = 100*pow((x[j]-x[i]*x[i]), 2)+pow(1-x[i], 2);
01276 }
01277 }
01278
01279 sum = 0;
01280
01281 for (i = 0; i < nvar; ++i) {
01282 for (j = 0; j < nvar; ++j) {
01283 sum += (y[i][j]*y[i][j])/4000-cos(y[i][j])+1;
01284 }
01285
01286 }
01287
01288 return sum;
01289 }
01290
01291 double pn_u(const tGen x, double a, double k, double m) {
01292 double result;
01293
01294 if (x > a) {
01295 result = k*pow((x-a), m);
01296 }
01297 else if (x >= -a && x <= a) {
01298 result = 0;
01299 }
01300 else {
01301 result = k*pow((-x-a),m);
01302 }
01303
01304 return result;
01305 }
01306
01307 double pn1(const tGen *x, int nvar) {
01308 tGen y[nvar];
01309 double sumu, sumy,result;
01310 int i;
01311
01312 for (i = 0; i < nvar; ++i) {
01313 y[i] = 1+0.25*(x[i]+1);
01314 }
01315
01316 sumy = 0;
01317 sumu = 0;
01318
01319 for (i = 0; i < nvar-1; ++i) {
01320 sumy += (y[i]-1)*(y[i]-1)*(1+10*pow(sin(M_PI*y[i+1]),2));
01321 }
01322
01323 for (i = 0; i < nvar; ++i) {
01324 sumu += pn_u(x[i],10.0,100.0,4.0);
01325 }
01326
01327 result = M_PI/nvar*(10*pow(sin(M_PI*y[1]),2)+sumy+pow(y[nvar-1]-1, 2)) + sumu;
01328 return result;
01329 }
01330
01331 double pn2(const tGen *x, int nvar) {
01332 double sumu, sumx;
01333 double result;
01334 int i;
01335
01336 sumx = 0;
01337 sumu = 0;
01338
01339 for (i = 0; i < nvar-1; ++i) {
01340 sumx += (x[i]-1)*(x[i]-1)*(1+pow(sin(3*M_PI*x[i+1]),2));
01341 }
01342
01343 for (i = 0; i < nvar; ++i) {
01344 sumu += pn_u(x[i],5.0,100.0,4.0);
01345 }
01346
01347 result = 0.1*(pow(sin(3*M_PI*x[1]),2)+sumx+pow(x[nvar-1]-1, 2)*(1+pow(sin(2*M_PI*x[nvar-1]),2))) + sumu;
01348
01349 return result;
01350 }
01351
01352 double foxhole(const tGen *xs, int nvar) {
01353 assert(nvar == 2);
01354 tGen x, y;
01355 double a[25],b[25];
01356 int i;
01357
01358 x = xs[0]; y = xs[1];
01359
01360 double sum = 0;
01361 for (i = 0; i < 25; ++i) {
01362 a[i] = 16*((i % 5)-2);
01363 b[i] = 16*((i/5)-2);
01364 }
01365
01366 for (i = 0; i <= 24; ++i) {
01367 sum += 1/(pow(1 +i +a[i], 6) + pow(y- b[i],6));
01368 }
01369
01370 return (500-1.0/(0.002+sum));
01371 }
01372