You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
57 lines
1.3 KiB
#pragma once
|
|
|
|
class search_function {
|
|
|
|
public:
|
|
|
|
function func;
|
|
|
|
search_function(function f) : func(f) {
|
|
};
|
|
|
|
virtual double search(int permutations, int dimensionality) = 0;
|
|
|
|
protected:
|
|
|
|
std::vector<double> generate_solution(int dimensionality){
|
|
|
|
std::vector<double> tmp;
|
|
for (int i = 0; i < dimensionality; i++) {
|
|
tmp.push_back(fmod(randomMT(), (func.upper_bound * 2)) + func.lower_bound);
|
|
}
|
|
return tmp;
|
|
}
|
|
|
|
std::vector<std::vector<double>> generate_population(int dimensionality, int population_count){
|
|
|
|
std::vector<std::vector<double>> tmp;
|
|
for (int i = 0; i < dimensionality; i++) {
|
|
tmp.push_back(generate_solution(dimensionality));
|
|
}
|
|
return tmp;
|
|
}
|
|
|
|
double check_bounds(double input){
|
|
if (input > func.upper_bound)
|
|
return func.upper_bound;
|
|
else if (input < func.lower_bound)
|
|
return func.lower_bound;
|
|
else
|
|
return input;
|
|
}
|
|
|
|
void check_solution_bounds(std::vector<double> *input){
|
|
|
|
for (auto &i: *input){
|
|
if (i > func.upper_bound)
|
|
i = func.upper_bound;
|
|
else if (i < func.lower_bound)
|
|
i = func.lower_bound;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|