40 double evaluate(
const std::vector<GeneType>& phenotype)
const override {
41 if (phenotype.size() != 2) {
42 throw std::invalid_argument(
43 "De Jong F5 requires exactly 2 dimensions, but received " +
44 std::to_string(phenotype.size())
48 static constexpr double a[2][25] = {
49 {-32, -16, 0, 16, 32, -32, -16, 0, 16, 32, -32, -16, 0, 16, 32, -32, -16, 0, 16, 32, -32, -16, 0, 16, 32},
50 {-32, -32, -32, -32, -32, -16, -16, -16, -16, -16, 0, 0, 0, 0, 0, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32}
53 const auto x =
static_cast<double>(phenotype[0]);
54 const auto y =
static_cast<double>(phenotype[1]);
57 for (
int i = 0; i < 25; ++i) {
58 const double term1 = std::pow(x - a[0][i], 6);
59 const double term2 = std::pow(y - a[1][i], 6);
60 sum += 1.0 / (
static_cast<double>(i + 1) + term1 + term2);
63 return 1.0 / (0.002 + sum);