From 766befd9495bb3b8ef399947801d6ea96b915779 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Tue, 13 Aug 2024 20:07:46 -0400 Subject: [PATCH] silly little child finder --- CMakeLists.txt | 2 +- include/blt/gp/tree.h | 8 ++++++++ src/tree.cpp | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) 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())