diff --git a/CMakeLists.txt b/CMakeLists.txt index 23de5e5..e685b9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.0.95) +project(blt-gp VERSION 0.0.96) include(CTest) @@ -87,7 +87,7 @@ endmacro() if (${BUILD_EXAMPLES}) - blt_add_project(blt-SR-playground examples/symbolic_regression.cpp example) + blt_add_project(blt-symbolic-regression examples/symbolic_regression.cpp example) endif () diff --git a/src/selection.cpp b/src/selection.cpp index 779cb5e..34343ed 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -80,12 +80,17 @@ namespace blt::gp tree_t& select_fitness_proportionate_t::select(gp_program& program, population_t& pop, population_stats& stats) { auto choice = program.get_random().get_double(); - for (const auto& ind : blt::enumerate(pop)) + for (const auto& [index, ref] : blt::enumerate(pop)) { - if (ind.first == 0 && choice <= stats.normalized_fitness[ind.first]) - return ind.second.tree; - if (choice > stats.normalized_fitness[ind.first - 1] && choice <= stats.normalized_fitness[ind.first]) - return ind.second.tree; + if (index == 0) + { + if (choice <= stats.normalized_fitness[index]) + return ref.tree; + } else + { + if (choice > stats.normalized_fitness[index - 1] && choice <= stats.normalized_fitness[index]) + return ref.tree; + } } BLT_WARN("Unable to find individual with fitness proportionate. This should not be a possible code path! (%lf)", choice); return pop.get_individuals()[0].tree;