silly little child finder

thread
Brett 2024-08-13 20:07:46 -04:00
parent a43922589f
commit 766befd949
3 changed files with 29 additions and 1 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
project(blt-gp VERSION 0.0.142) project(blt-gp VERSION 0.0.143)
include(CTest) include(CTest)

View File

@ -60,6 +60,13 @@ namespace blt::gp
{ {
using iter_type = std::vector<op_container_t>::const_iterator; using iter_type = std::vector<op_container_t>::const_iterator;
public: public:
struct child_t
{
blt::ptrdiff_t start;
// one past the end
blt::ptrdiff_t end;
};
[[nodiscard]] inline std::vector<op_container_t>& get_operations() [[nodiscard]] inline std::vector<op_container_t>& get_operations()
{ {
return operations; return operations;
@ -117,6 +124,7 @@ namespace blt::gp
bool check(gp_program& program, void* context) const; bool check(gp_program& program, void* context) const;
void find_child_extends(gp_program& program, std::vector<child_t>& 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_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; blt::ptrdiff_t find_parent(blt::gp::gp_program& program, blt::ptrdiff_t start) const;

View File

@ -340,6 +340,26 @@ namespace blt::gp
} }
} }
void tree_t::find_child_extends(gp_program& program, std::vector<child_t>& 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<blt::ptrdiff_t>(parent_node + 1),
find_endpoint(program, static_cast<blt::ptrdiff_t>(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) void population_t::drop(gp_program& program)
{ {
for (auto& pop : get_individuals()) for (auto& pop : get_individuals())