00001
00037
00038
00039
00040 #include <EALib/ObjectiveFunctions.h>
00041 #include <LinAlg/LinAlg.h>
00042
00043
00044 Sphere::Sphere(unsigned d) : ObjectiveFunctionVS<double>(d, NULL)
00045 {
00046 m_name = "Sphere";
00047 }
00048
00049 Sphere::~Sphere()
00050 {}
00051
00052
00053 unsigned int Sphere::objectives() const
00054 {
00055 return 1;
00056 }
00057
00058 void Sphere::result(double* const& point, std::vector<double>& value)
00059 {
00060 unsigned i;
00061 double sum = 0.;
00062 for (i = 0; i < m_dimension; i++) sum += point[i] * point[i];
00063 value.resize(1);
00064 value[0] = sum;
00065 m_timesCalled++;
00066 }
00067
00068 bool Sphere::ProposeStartingPoint(double*& point) const
00069 {
00070 double r2 = 0.0;
00071 unsigned int i;
00072 for (i = 0; i < m_dimension; i++)
00073 {
00074 double a = Rng::gauss();
00075 point[i] = a;
00076 r2 += a * a;
00077 }
00078 double r = sqrt(r2);
00079 for (i = 0; i < m_dimension; i++) point[i] /= r;
00080 return true;
00081 }
00082
00083 bool Sphere::utopianFitness(std::vector<double>& fitness) const
00084 {
00085 fitness.resize(1, false);
00086 fitness[0] = 0.0;
00087 return true;
00088 }
00089
00090
00092
00093
00094 NoisySphere::NoisySphere(unsigned d) : ObjectiveFunctionVS<double>(d, NULL)
00095 {
00096 m_name = "NoisySphere";
00097 }
00098
00099 NoisySphere::~NoisySphere()
00100 {}
00101
00102
00103 unsigned int NoisySphere::objectives() const
00104 {
00105 return 1;
00106 }
00107
00108 void NoisySphere::result(double* const& point, std::vector<double>& value)
00109 {
00110 unsigned i;
00111 double sum = 0.;
00112 for (i = 0; i < m_dimension; i++) sum += point[i] * point[i];
00113 value.resize(1);
00114 value[0] = sum + sum / (2. * m_dimension) * Rng::cauchy();
00115 m_timesCalled++;
00116 }
00117
00118 bool NoisySphere::ProposeStartingPoint(double*& point) const
00119 {
00120 double r2 = 0.0;
00121 unsigned int i;
00122 for (i = 0; i < m_dimension; i++)
00123 {
00124 double a = Rng::gauss();
00125 point[i] = a;
00126 r2 += a * a;
00127 }
00128 double r = sqrt(r2);
00129 for (i = 0; i < m_dimension; i++) point[i] /= r;
00130 return true;
00131 }
00132
00133
00135
00136
00137 Paraboloid::Paraboloid(unsigned d, double c)
00138 : TransformedObjectiveFunction(base, d)
00139 , base(d)
00140 {
00141 m_name = "Paraboloid";
00142
00143 Array<double> tmp(m_dimension, m_dimension);
00144 Array<double> diag(m_dimension, m_dimension);
00145 diag = 0.0;
00146 unsigned i;
00147 for (i = 0; i < m_dimension; i++) diag(i, i) = pow(c, (double(i) / double(m_dimension - 1)));
00148 matMat(tmp, m_Transformation, diag);
00149 m_Transformation = tmp;
00150 }
00151
00152 Paraboloid::~Paraboloid()
00153 {}
00154
00155
00157
00158
00159 Tablet::Tablet(unsigned d, double c) : TransformedObjectiveFunction(base, d)
00160 , base(d)
00161 {
00162 m_name = "Tablet";
00163
00164 Array<double> tmp(m_dimension, m_dimension);
00165 Array<double> diag(m_dimension, m_dimension);
00166 diag = 0.0;
00167 diag(0, 0) = c;
00168
00169 for (unsigned i = 1; i < m_dimension; i++)
00170 diag(i, i) = 1.0;
00171
00172 matMat(tmp, m_Transformation, diag);
00173 m_Transformation = tmp;
00174 }
00175
00176 Tablet::~Tablet()
00177 {}
00178
00179
00181
00182
00183 Cigar::Cigar(unsigned d, double c) : TransformedObjectiveFunction(base, d)
00184 , base(d)
00185 {
00186 m_name = "Cigar";
00187
00188 Array<double> tmp(m_dimension, m_dimension);
00189 Array<double> diag(m_dimension, m_dimension);
00190 diag = 0.0;
00191 diag(0, 0) = 1;
00192
00193 for (unsigned i = 1; i < m_dimension; i++)
00194 diag(i, i) = c;
00195
00196 matMat(tmp, m_Transformation, diag);
00197 m_Transformation = tmp;
00198 }
00199
00200 Cigar::~Cigar()
00201 {}
00202
00203
00205
00206
00207 Twoaxis::Twoaxis(unsigned d, double c) : TransformedObjectiveFunction(base, d)
00208 , base(d)
00209 {
00210 m_name = "Twoaxis";
00211
00212 Array<double> tmp(m_dimension, m_dimension);
00213 Array<double> diag(m_dimension, m_dimension);
00214 diag = 0.0;
00215
00216 unsigned i;
00217 for (i = 0; i < m_dimension / 2; i++)
00218 diag(i, i) = c;
00219 for (i++; i < m_dimension; i++)
00220 diag(i, i) = 1;
00221
00222 matMat(tmp, m_Transformation, diag);
00223 m_Transformation = tmp;
00224 }
00225
00226 Twoaxis::~Twoaxis()
00227 {}
00228
00229
00231
00232
00233 Ackley::Ackley(unsigned d) : ObjectiveFunctionVS<double>(d, new BoxConstraintHandler(d, -32.0, 32.0))
00234 {
00235 m_name = "Ackley's function";
00236 }
00237
00238 Ackley::~Ackley()
00239 {
00240 delete constrainthandler;
00241 }
00242
00243
00244 unsigned int Ackley::objectives() const
00245 {
00246 return 1;
00247 }
00248
00249 void Ackley::result(double* const& point, std::vector<double>& value)
00250 {
00251
00252 const double A = 20.;
00253 const double B = 0.2;
00254 const double C = M_2PI;
00255
00256 unsigned i;
00257 double a, b;
00258
00259 for (a = b = 0.0, i = 0; i < m_dimension; ++i)
00260 {
00261 a += point[i] * point[i];
00262 b += cos(C * point[i]);
00263 }
00264
00265 value.resize(1);
00266 value[0] = -A * exp(-B * sqrt(a / m_dimension)) - exp(b / m_dimension) + A + M_E;
00267
00268 m_timesCalled++;
00269 }
00270
00271 bool Ackley::ProposeStartingPoint(double*& point) const
00272 {
00273
00274 const double bound = 32.0;
00275
00276 for (unsigned int i = 0; i < m_dimension; i++)
00277 point[i] = 2 * bound * Rng::uni() - bound;
00278
00279 return true;
00280 }
00281
00282 bool Ackley::utopianFitness(std::vector<double>& fitness) const
00283 {
00284 fitness.resize(1, false);
00285 fitness[0] = 0.0;
00286 return true;
00287 }
00288
00289
00291
00292
00293 Rastrigin::Rastrigin(unsigned d) : ObjectiveFunctionVS<double>(d, new BoxConstraintHandler(d, -5.12, 5.12))
00294 {
00295 m_name = "Rastrigin's function";
00296 }
00297
00298 Rastrigin::~Rastrigin()
00299 {
00300 delete constrainthandler;
00301 }
00302
00303
00304 unsigned int Rastrigin::objectives() const
00305 {
00306 return 1;
00307 }
00308
00309 void Rastrigin::result(double* const& point, std::vector<double>& value)
00310 {
00311
00312 double result = 10.0 * m_dimension;
00313
00314 for (unsigned int i = 0; i < m_dimension; i++)
00315 result += point[i] * point[i] - 10.0 * cos(M_2PI * point[i]);
00316
00317 value.resize(1);
00318 value[0] = result;
00319
00320 m_timesCalled++;
00321 }
00322
00323 bool Rastrigin::ProposeStartingPoint(double*& point) const
00324 {
00325
00326 const double bound = 5.12;
00327
00328 for (unsigned int i = 0; i < m_dimension; i++)
00329 point[i] = 2 * bound * Rng::uni() - bound;
00330
00331 return true;
00332 }
00333
00334 bool Rastrigin::utopianFitness(std::vector<double>& fitness) const
00335 {
00336 fitness.resize(1, false);
00337 fitness[0] = 0.0;
00338 return true;
00339 }
00340
00341
00343
00344
00345 Griewangk::Griewangk(unsigned d) : ObjectiveFunctionVS<double>(d, new BoxConstraintHandler(d, -600.0, 600.0))
00346 {
00347 m_name = "Griewangk's function";
00348 }
00349
00350 Griewangk::~Griewangk()
00351 {
00352 delete constrainthandler;
00353 }
00354
00355
00356 unsigned int Griewangk::objectives() const
00357 {
00358 return 1;
00359 }
00360
00361 void Griewangk::result(double* const& point, std::vector<double>& value)
00362 {
00363
00364 double sum = 0.0;
00365 double prod = 1.0;
00366
00367 for (unsigned int i = 0; i < m_dimension; i++)
00368 {
00369 sum += point[i] * point[i];
00370 prod *= cos(point[i] / sqrt((double)(i + 1)));
00371 }
00372
00373 value.resize(1);
00374 value[0] = 1.0 + sum / 4000.0 - prod;
00375
00376 m_timesCalled++;
00377 }
00378
00379 bool Griewangk::ProposeStartingPoint(double*& point) const
00380 {
00381
00382 const double bound = 600.0;
00383
00384 for (unsigned int i = 0; i < m_dimension; i++)
00385 point[i] = 2 * bound * Rng::uni() - bound;
00386
00387 return true;
00388 }
00389
00390 bool Griewangk::utopianFitness(std::vector<double>& fitness) const
00391 {
00392 fitness.resize(1, false);
00393 fitness[0] = 0.0;
00394 return true;
00395 }
00396
00397
00399
00400
00401 Rosenbrock::Rosenbrock(unsigned d) : ObjectiveFunctionVS<double>(d, NULL)
00402 {
00403 m_name = "Rosenbrock's function";
00404 }
00405
00406 Rosenbrock::~Rosenbrock()
00407 {}
00408
00409
00410 unsigned int Rosenbrock::objectives() const
00411 {
00412 return 1;
00413 }
00414
00415 void Rosenbrock::result(double* const& point, std::vector<double>& value)
00416 {
00417
00418 double result = 0.0;
00419
00420 for (unsigned i = 0; i < m_dimension - 1; i++)
00421 result += 100.0 * (point[i+1] - point[i] * point[i]) *
00422 (point[i+1] - point[i] * point[i]) +
00423 (point[i] - 1.0) * (point[i] - 1.0);
00424
00425 value.resize(1);
00426 value[0] = result;
00427
00428 m_timesCalled++;
00429 }
00430
00431 bool Rosenbrock::ProposeStartingPoint(double*& point) const
00432 {
00433
00434 for (unsigned int i = 0; i < m_dimension; i++)
00435 point[i] = Rng::gauss();
00436
00437 return true;
00438 }
00439
00440 bool Rosenbrock::utopianFitness(std::vector<double>& fitness) const
00441 {
00442 fitness.resize(1, false);
00443 fitness[0] = 0.0;
00444 return true;
00445 }
00446
00447
00449
00450
00451 RosenbrockRotated:: RosenbrockRotated(unsigned d): TransformedObjectiveFunction(base, d)
00452 , base(d)
00453 {
00454 m_name = "DifferentPowersRotated";
00455 }
00456
00457 RosenbrockRotated::~RosenbrockRotated()
00458 {}
00459
00460
00462
00463
00464 DiffPow::DiffPow(unsigned d) : ObjectiveFunctionVS<double>(d, NULL)
00465 {
00466 m_name = "DifferentPowers";
00467 }
00468
00469 DiffPow::~DiffPow()
00470 {}
00471
00472
00473 unsigned int DiffPow::objectives() const
00474 {
00475 return 1;
00476 }
00477
00478 void DiffPow::result(double* const& point, std::vector<double>& value)
00479 {
00480
00481 double result = 0.0;
00482
00483 for (unsigned i = 0; i < m_dimension; i++)
00484 result += pow(fabs(point[i]), 2.0 + 10.0 * i / (m_dimension - 1.0));
00485
00486 value.resize(1);
00487 value[0] = result;
00488
00489 m_timesCalled++;
00490 }
00491
00492 bool DiffPow::ProposeStartingPoint(double*& point) const
00493 {
00494
00495 for (unsigned int i = 0; i < m_dimension; i++)
00496 point[i] = Rng::gauss();
00497
00498 return true;
00499 }
00500
00501 bool DiffPow::utopianFitness(std::vector<double>& fitness) const
00502 {
00503 fitness.resize(1, false);
00504 fitness[0] = 0.0;
00505 return true;
00506 }
00507
00508
00510
00511
00512 DiffPowRotated::DiffPowRotated(unsigned d): TransformedObjectiveFunction(base, d)
00513 , base(d)
00514 {
00515 m_name = "DifferentPowersRotated";
00516 }
00517
00518 DiffPowRotated::~DiffPowRotated()
00519 {}
00520
00521
00523
00524
00525 Schwefel::Schwefel(unsigned d) : ObjectiveFunctionVS<double>(d, NULL)
00526 {
00527 m_name = "Rosenbrock's function";
00528 }
00529
00530 Schwefel::~Schwefel()
00531 {}
00532
00533
00534 unsigned int Schwefel::objectives() const
00535 {
00536 return 1;
00537 }
00538
00539 void Schwefel::result(double* const& point, std::vector<double>& value)
00540 {
00541
00542 double result = 0.0;
00543
00544 for (unsigned i = 0; i < m_dimension; i++)
00545 result += point[i] * sin(sqrt(fabs(point[i])));
00546
00547 value.resize(1);
00548 value[0] = -result;
00549
00550 m_timesCalled++;
00551 }
00552
00553 bool Schwefel::ProposeStartingPoint(double*& point) const
00554 {
00555
00556 const double bound = 500.0;
00557
00558 for (unsigned int i = 0; i < m_dimension; i++)
00559 point[i] = 2 * bound * Rng::uni() - bound;
00560
00561 return true;
00562 }
00563
00564
00566
00567
00568 SchwefelEllipsoid::SchwefelEllipsoid(unsigned d) : ObjectiveFunctionVS<double>(d, NULL)
00569 {
00570 m_name = "SchwefelEllipsoid";
00571 }
00572
00573 SchwefelEllipsoid::~SchwefelEllipsoid()
00574 {}
00575
00576
00577 unsigned int SchwefelEllipsoid::objectives() const
00578 {
00579 return 1;
00580 }
00581
00582 void SchwefelEllipsoid::result(double* const& point, std::vector<double>& value)
00583 {
00584 unsigned i, j;
00585 double sum = 0.;
00586 double sumHelp;
00587 for (i = 0; i < m_dimension; i++)
00588 {
00589 sumHelp = 0.;
00590 for (j = 0; j <= i; j++)
00591 {
00592 sumHelp += point[j];
00593 }
00594 sum += sumHelp * sumHelp;
00595 }
00596 value.resize(1);
00597 value[0] = sum;
00598 m_timesCalled++;
00599 }
00600
00601 bool SchwefelEllipsoid::ProposeStartingPoint(double*& point) const
00602 {
00603 unsigned int i;
00604 for (i = 0; i < m_dimension; i++) point[i] = 1.;
00605 return true;
00606 }
00607
00608
00609 bool SchwefelEllipsoid::utopianFitness(std::vector<double>& fitness) const
00610 {
00611 fitness.resize(1, false);
00612 fitness[0] = 0.0;
00613 return true;
00614 }
00615
00616
00618
00619
00620 SchwefelEllipsoidRotated::SchwefelEllipsoidRotated(unsigned d)
00621 : TransformedObjectiveFunction(base, d)
00622 , base(d)
00623 {
00624 m_name = "SchwefelEllipsoidRotated";
00625 }
00626
00627 SchwefelEllipsoidRotated::~SchwefelEllipsoidRotated()
00628 {}
00629
00630
00632
00633
00634 RandomFitness::RandomFitness(unsigned d) : ObjectiveFunctionVS<double>(d, NULL)
00635 {
00636 m_name = "Random Fitness";
00637 }
00638
00639 RandomFitness::~RandomFitness()
00640 {}
00641
00642
00643 unsigned int RandomFitness::objectives() const
00644 {
00645 return 1;
00646 }
00647
00648 void RandomFitness::result(double* const& point, std::vector<double>& value)
00649 {
00650 value.resize(1);
00651 value[0] = Rng::gauss();
00652 m_timesCalled++;
00653 }
00654
00655 bool RandomFitness::ProposeStartingPoint(double*& point) const
00656 {
00657 for (unsigned int i = 0; i < m_dimension; i++)
00658 point[i] = Rng::gauss();
00659 return true;
00660 }