I am trying to build an optimization library in C++ for parameters optimization.
The problem and the parameters type may vary, e.g. if the problem is to minimize the Ackley Function, then we have a vector<double>
of size 2
(index 0 for the x, and index 1 for the y). However, we may have problems where the parameters are integers, or even strings.
Many algorithm exist for this type of optimization, like Genetic Algorithm, Differential Evolution, etc. In most of them, once we modify the parameters based on their optimization strategy, we have to call an evaluation function that receives the parameters, and given a objective function, will return a value (fitness).
My question is how could I implement an abstract class Problem
in C++ such that it contains an virtual double evaluate
function in which receives as reference a vector of the generic type of the related problem? For example, user's problem should inherit Problem
and he needs to specify a type T
, in this case, the evaluation function should be like virtual double evaluate(const vector<T> ¶meters){}
.
If the strategy which I mentioned above is not feasible for C++. Please, suggest alternatives strategies.