This commit is contained in:
2016-11-25 19:31:00 -08:00
commit 001a46260a
73 changed files with 8363 additions and 0 deletions

56
lab4/search_function.h Normal file
View File

@@ -0,0 +1,56 @@
#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;
}
}
};