diff --git a/CMakeLists.txt b/CMakeLists.txt index d8de23b..4014091 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.1.50) +project(blt-gp VERSION 0.1.51) include(CTest) diff --git a/examples/symbolic_regression.cpp b/examples/symbolic_regression.cpp index e7999be..b722744 100644 --- a/examples/symbolic_regression.cpp +++ b/examples/symbolic_regression.cpp @@ -90,8 +90,6 @@ float example_function(float x) return x * x * x * x + x * x * x + x * x + x; } -BLT_MAKE_CONFIG_TYPE(test, BLT_MAKE_GETTER_AND_SETTER(int, silly) BLT_MAKE_GETTER(int, billy)); - int main() { test t; diff --git a/include/blt/gp/transformers.h b/include/blt/gp/transformers.h index 65aa279..0879c11 100644 --- a/include/blt/gp/transformers.h +++ b/include/blt/gp/transformers.h @@ -57,6 +57,10 @@ namespace blt::gp class crossover_t { public: + struct point_info_t + { + type_id return_type; + }; struct crossover_point_t { blt::ptrdiff_t p1_crossover_point; @@ -78,7 +82,8 @@ namespace blt::gp {} std::optional get_crossover_point(gp_program& program, const tree_t& c1, const tree_t& c2) const; - std::optional find_place_of_type(gp_program& program, const tree_t& t, type_id type) const; + + static std::optional find_place_of_type(gp_program& program, const tree_t& t, type_id type); /** * child1 and child2 are copies of the parents, the result of selecting a crossover point and performing standard subtree crossover. @@ -167,7 +172,7 @@ namespace blt::gp 0.01, // JUMP_FUNC 0.05 // COPY ); -}; + }; } diff --git a/lib/blt b/lib/blt index 7410dfe..56a3c2f 160000 --- a/lib/blt +++ b/lib/blt @@ -1 +1 @@ -Subproject commit 7410dfe0ff6196e77856a79b4c92b05a90e35880 +Subproject commit 56a3c2f836a37258290c2cc43b52df18249b1c0c diff --git a/src/transformers.cpp b/src/transformers.cpp index cfa1f04..fca6946 100644 --- a/src/transformers.cpp +++ b/src/transformers.cpp @@ -211,9 +211,13 @@ namespace blt::gp return crossover_point_t{static_cast(crossover_point), static_cast(attempted_point)}; } - std::optional crossover_t::find_place_of_type(gp_program& program, const tree_t& t, type_id type) const + std::optional crossover_t::find_place_of_type(gp_program& program, const tree_t& t, type_id type) { - return std::optional(); + auto attempted_point = program.get_random().get_size_t(1ul, t.get_operations().size()); + auto& attempted_point_type = program.get_operator_info(t.get_operations()[attempted_point].id); + if (type == attempted_point_type.return_type) + return {attempted_point}; + return {}; } bool mutation_t::apply(gp_program& program, const tree_t&, tree_t& c)