diff --git a/Exponential/Exponential.h b/Exponential/Exponential.h index 49cdd02..3be3115 100644 --- a/Exponential/Exponential.h +++ b/Exponential/Exponential.h @@ -528,80 +528,7 @@ namespace JRAMPERSAD throw e; } - // Create initial random solutions - std::random_device device; - std::uniform_real_distribution unif(options.min_range, options.max_range); - std::vector solutions; - - solutions.resize(options.data_size); - for (unsigned int i = 0; i < options.sample_size; i++) - solutions[i] = (GA_Solution{lrgst_expo, 0, unif(device)}); - - float timer{ 0 }; - - for (unsigned int count = 0; count < options.num_of_generations; count++) - { - std::generate(std::execution::par, solutions.begin() + options.sample_size, solutions.end(), [this, &unif, &device]() { - return GA_Solution{lrgst_expo, 0, unif(device)}; - }); - - // Run our fitness function - for (auto& s : solutions) { s.fitness(constants); } - - // Sort our solutions by rank - std::sort(std::execution::par, solutions.begin(), solutions.end(), - [](const auto& lhs, const auto& rhs) { - return lhs.rank > rhs.rank; - }); - - // Take top solutions - std::vector sample; - std::copy( - solutions.begin(), - solutions.begin() + options.sample_size, - std::back_inserter(sample) - ); - solutions.clear(); - - if (count + 1 == options.num_of_generations) - { - std::copy( - sample.begin(), - sample.end(), - std::back_inserter(solutions) - ); - sample.clear(); - break; - } - - // Mutate the top solutions by % - std::uniform_real_distribution m((1 - options.mutation_percentage), (1 + options.mutation_percentage)); - std::for_each(sample.begin(), sample.end(), [&m, &device](auto& s) { - s.x *= m(device); - }); - - // Cross over not needed as it's only one value - - std::copy( - sample.begin(), - sample.end(), - std::back_inserter(solutions) - ); - sample.clear(); - solutions.resize(options.data_size); - } - - std::sort(solutions.begin(), solutions.end(), - [](const auto& lhs, const auto& rhs) { - return lhs.x < rhs.x; - }); - - std::vector ans; - for (auto& s : solutions) - { - ans.push_back(s.x); - } - return ans; + return solve_x(0, options); } double Function::solve_y(const double& x_val) const