1#ifndef HEAVY_TRIG_FUNCTION_H
2#define HEAVY_TRIG_FUNCTION_H
24template <
typename GeneType =
double>
27 std::size_t dimensions_m;
28 GeneType lower_bound_m;
29 GeneType upper_bound_m;
30 std::size_t repeat_count_m;
43 std::size_t repeat_count = 64)
44 : dimensions_m(dimensions),
45 lower_bound_m(lower_bound),
46 upper_bound_m(upper_bound),
47 repeat_count_m(repeat_count) {}
54 double evaluate(
const std::vector<GeneType>& phenotype)
const override {
55 if (phenotype.size() != dimensions_m) {
56 throw std::invalid_argument(
57 "HeavyTrig requires exactly " + std::to_string(dimensions_m) +
58 " dimensions, but received " + std::to_string(phenotype.size())
63 for (std::size_t i = 0; i < phenotype.size(); ++i) {
64 const double x =
static_cast<double>(phenotype[i]);
66 for (std::size_t r = 1; r <= repeat_count_m; ++r) {
67 const double factor =
static_cast<double>(r);
68 const double angle = factor * 0.017 + x * 0.031;
69 state = std::sin(state + angle)
70 + std::cos(state - angle * 0.5)
71 + std::exp(-0.001 * state * state)
72 + 0.0005 * state * state;
74 sum += state * state + 0.1 * x * x;
79 [[nodiscard]] std::size_t
size()
const override {
return dimensions_m; }
80 [[nodiscard]] std::string
name()
const override {
return "HeavyTrig"; }
Abstract base class for objective functions to be minimized.
A computationally intensive trigonometric benchmark function.
GeneType getUpperBound(std::size_t) const override
Gets the upper bound for a specific dimension.
HeavyTrigFunction(std::size_t dimensions, GeneType lower_bound, GeneType upper_bound, std::size_t repeat_count=64)
Constructs the benchmark.
std::string name() const override
Short identifier used to select a GPU evaluation kernel.
GeneType getLowerBound(std::size_t) const override
Gets the lower bound for a specific dimension.
std::size_t size() const override
Returns the dimensionality of the optimization problem.
double evaluate(const std::vector< GeneType > &phenotype) const override
Evaluates the heavy trigonometric sum.