|
GALib-Parallel
Header-only C++ library for parallel evolutionary algorithms
|
A wrapper for FitnessFunction that allows using a lambda or std::function. More...
#include <FunctionalFitness.h>
Public Types | |
| using | EvalFunc = std::function< double(const std::vector< GeneType > &)> |
Public Member Functions | |
| FunctionalFitness (std::size_t dims, GeneType lower, GeneType upper, EvalFunc func) | |
| Constructor for uniform bounds. | |
| FunctionalFitness (std::size_t dims, std::vector< GeneType > lowers, std::vector< GeneType > uppers, EvalFunc func) | |
| Constructor for non-uniform bounds. | |
| double | evaluate (const std::vector< GeneType > &phenotype) const override |
| Evaluates the fitness of a candidate solution using the wrapped function. | |
| std::size_t | size () const override |
| Returns the problem dimensionality. | |
| GeneType | getLowerBound (std::size_t dimension) const override |
| Gets the lower bound for a specific dimension. | |
| GeneType | getUpperBound (std::size_t dimension) const override |
| Gets the upper bound for a specific dimension. | |
Public Member Functions inherited from galib::FitnessFunction< GeneType > | |
| virtual | ~FitnessFunction ()=default |
| virtual std::string | name () const |
| Short identifier used to select a GPU evaluation kernel. | |
| GeneType | getLowerBound () const |
| Convenience method to get the lower bound of the first dimension. | |
| GeneType | getUpperBound () const |
| Convenience method to get the upper bound of the first dimension. | |
A wrapper for FitnessFunction that allows using a lambda or std::function.
This class eliminates the need for users to create a new class for every custom optimization problem. It supports both uniform bounds (same for all dimensions) and non-uniform bounds.
| GeneType | The type of the genes (default is double). |
Definition at line 24 of file FunctionalFitness.h.
| using galib::FunctionalFitness< GeneType >::EvalFunc = std::function<double(const std::vector<GeneType>&)> |
Definition at line 26 of file FunctionalFitness.h.
|
inline |
Constructor for uniform bounds.
| dims | Number of dimensions. |
| lower | Lower bound applied to all dimensions. |
| upper | Upper bound applied to all dimensions. |
| func | Evaluation callable (lambda, function pointer, std::function). |
Definition at line 38 of file FunctionalFitness.h.
|
inline |
Constructor for non-uniform bounds.
| dims | Number of dimensions. |
| lowers | Vector of lower bounds per dimension. |
| uppers | Vector of upper bounds per dimension. |
| func | Evaluation callable. |
| std::invalid_argument | if bounds vector sizes do not match dims. |
Definition at line 56 of file FunctionalFitness.h.
|
inlineoverridevirtual |
Evaluates the fitness of a candidate solution using the wrapped function.
| phenotype | Gene values of the individual. |
Implements galib::FitnessFunction< GeneType >.
Definition at line 75 of file FunctionalFitness.h.
|
inlineoverridevirtual |
Gets the lower bound for a specific dimension.
| dimension | Index of the dimension. |
Implements galib::FitnessFunction< GeneType >.
Definition at line 92 of file FunctionalFitness.h.
|
inlineoverridevirtual |
Gets the upper bound for a specific dimension.
| dimension | Index of the dimension. |
Implements galib::FitnessFunction< GeneType >.
Definition at line 101 of file FunctionalFitness.h.
|
inlineoverridevirtual |
Returns the problem dimensionality.
Implements galib::FitnessFunction< GeneType >.
Definition at line 83 of file FunctionalFitness.h.