GALib-Parallel
Header-only C++ library for parallel evolutionary algorithms
Loading...
Searching...
No Matches
FitnessFactory.h
Go to the documentation of this file.
1#pragma once
2
3#include "utils/Config.h"
10
11#include <memory>
12#include <stdexcept>
13#include <string>
14
15namespace galib::utils {
23 public:
30 static std::unique_ptr<FitnessFunction<double>> create(const ProblemConfig& problem) {
31 const std::string& name = problem.name;
32 const std::size_t dim = problem.dimensions;
33 const double lb = problem.lower_bound;
34 const double ub = problem.upper_bound;
35
36 if (name == "Sphere") return std::make_unique<benchmark::SphereFunction<double>>(dim, lb, ub);
37 if (name == "Rastrigin") return std::make_unique<benchmark::RastriginFunction<double>>(dim, lb, ub);
38 if (name == "Himmelblau") return std::make_unique<benchmark::HimmelblauFitness<double>>();
39 if (name == "DeJongF5") return std::make_unique<benchmark::DeJongF5Function<double>>();
40 if (name == "HeavyTrig") return std::make_unique<benchmark::HeavyTrigFunction<double>>(dim, lb, ub);
41
42 throw std::invalid_argument("Unknown fitness function: '" + name + "'");
43 }
44 };
45} // namespace galib::utils
A factory for instantiating standard benchmark functions.
static std::unique_ptr< FitnessFunction< double > > create(const ProblemConfig &problem)
Creates a fitness function based on the provided configuration.