init
This commit is contained in:
56
lab4/search_function.h
Normal file
56
lab4/search_function.h
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user