diff --git a/CMakeLists.txt b/CMakeLists.txt index 4db598e..0fd941e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.0.142) +project(blt-gp VERSION 0.0.143) include(CTest) diff --git a/include/blt/gp/tree.h b/include/blt/gp/tree.h index d1293ff..176202e 100644 --- a/include/blt/gp/tree.h +++ b/include/blt/gp/tree.h @@ -60,6 +60,13 @@ namespace blt::gp { using iter_type = std::vector::const_iterator; public: + struct child_t + { + blt::ptrdiff_t start; + // one past the end + blt::ptrdiff_t end; + }; + [[nodiscard]] inline std::vector& get_operations() { return operations; @@ -117,6 +124,7 @@ namespace blt::gp bool check(gp_program& program, void* context) const; + void find_child_extends(gp_program& program, std::vector& vec, blt::size_t parent_node, blt::size_t argc) const; blt::ptrdiff_t find_endpoint(blt::gp::gp_program& program, blt::ptrdiff_t start) const; blt::ptrdiff_t find_parent(blt::gp::gp_program& program, blt::ptrdiff_t start) const; diff --git a/src/tree.cpp b/src/tree.cpp index d108456..9ec026f 100644 --- a/src/tree.cpp +++ b/src/tree.cpp @@ -340,6 +340,26 @@ namespace blt::gp } } + void tree_t::find_child_extends(gp_program& program, std::vector& vec, blt::size_t parent_node, blt::size_t argc) const + { + while (vec.size() < argc) + { + auto current_point = vec.size(); + child_t prev{}; + if (current_point == 0) + { + // first child. + prev = {static_cast(parent_node + 1), + find_endpoint(program, static_cast(parent_node + 1))}; + vec.push_back(prev); + continue; + } else + prev = vec[current_point - 1]; + child_t next = {prev.end, find_endpoint(program, prev.end)}; + vec.push_back(next); + } + } + void population_t::drop(gp_program& program) { for (auto& pop : get_individuals())