1#ifndef SPHERE_FUNCTION_H
2#define SPHERE_FUNCTION_H
27 template <
typename GeneType =
double>
30 std::size_t dimensions;
41 : dimensions(dim), lower_bound(lb), upper_bound(ub) {}
48 double evaluate(
const std::vector<GeneType>& phenotype)
const override {
50 for (GeneType gene : phenotype) {
51 sum +=
static_cast<double>(gene * gene);
56 std::size_t
size()
const override {
return dimensions; }
57 std::string
name()
const override {
return "Sphere"; }
59 GeneType
getLowerBound(std::size_t)
const override {
return lower_bound; }
60 GeneType
getUpperBound(std::size_t)
const override {
return upper_bound; }
Abstract base class for objective functions to be minimized.
Implementation of the Sphere function.
std::size_t size() const override
Returns the dimensionality of the optimization problem.
double evaluate(const std::vector< GeneType > &phenotype) const override
Evaluates the N-dimensional Sphere function.
GeneType getLowerBound(std::size_t) const override
Gets the lower bound for a specific dimension.
std::string name() const override
Short identifier used to select a GPU evaluation kernel.
GeneType getUpperBound(std::size_t) const override
Gets the upper bound for a specific dimension.
SphereFunction(const std::size_t dim, GeneType lb, GeneType ub)
Constructs the Sphere function with given dimensions and bounds.