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

41
lab4/random_walk.hpp Normal file
View File

@@ -0,0 +1,41 @@
#pragma once
#include "search_function.h"
#include <algorithm>
class random_walk : public search_function {
public:
random_walk(function f) : search_function(f) {
}
double search(int permutations, int dimensionality) {
timer t;
t.start();
std::vector<double> r;
for (int i = 0; i < permutations; i++){
std::vector<double> dimension_vals;
for (int i = 0; i < dimensionality; i++) {
auto val = fmod(randomMT(), (func.upper_bound * 2)) + func.lower_bound;
dimension_vals.push_back(fmod(randomMT(), (func.upper_bound * 2)) + func.lower_bound);
}
r.push_back(func.compute(dimension_vals));
}
t.end();
std::sort(r.begin(), r.end(), std::less<double>());
return r[0];
}
};