Compare commits

..

No commits in common. "407273d0dcd86cb3f2030ca9b470cfa78958f23d" and "d5dea3b31ecc02207af6bc8ecfbd715c149febe5" have entirely different histories.

7 changed files with 27 additions and 34 deletions

View File

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

View File

@ -177,11 +177,6 @@ namespace blt::gp
return name;
}
inline constexpr const auto& get_function() const
{
return func;
}
operator_id id = -1;
private:
function_t func;

View File

@ -254,7 +254,7 @@ namespace blt::gp
if (bytes_available < 0)
{
remaining_bytes -= blk->used_bytes_in_block();
blk = blk->metadata.prev;
blk = head->metadata.prev;
} else
break;
}

View File

@ -32,6 +32,8 @@ namespace blt::gp
using op_iter = std::vector<blt::gp::op_container_t>::iterator;
}
blt::ptrdiff_t find_endpoint(blt::gp::gp_program& program, const std::vector<blt::gp::op_container_t>& container, blt::ptrdiff_t start);
class crossover_t
{
public:
@ -106,8 +108,7 @@ namespace blt::gp
virtual tree_t apply(gp_program& program, const tree_t& p); // NOLINT
// returns the point after the mutation
blt::size_t mutate_point(gp_program& program, tree_t& c, blt::size_t node);
void mutate_point(gp_program& program, tree_t& c, blt::size_t node);
virtual ~mutation_t() = default;

View File

@ -113,8 +113,6 @@ namespace blt::gp
void print(gp_program& program, std::ostream& output, bool print_literals = true, bool pretty_indent = false, bool include_types = false) const;
blt::ptrdiff_t find_endpoint(blt::gp::gp_program& program, blt::ptrdiff_t start);
private:
std::vector<op_container_t> operations;
blt::gp::stack_allocator values;

View File

@ -71,10 +71,10 @@ namespace blt::gp
return blt::unexpected(point.error());
auto crossover_point_begin_itr = c1_ops.begin() + point->p1_crossover_point;
auto crossover_point_end_itr = c1_ops.begin() + c1.find_endpoint(program, point->p1_crossover_point);
auto crossover_point_end_itr = c1_ops.begin() + find_endpoint(program, c1_ops, point->p1_crossover_point);
auto found_point_begin_itr = c2_ops.begin() + point->p2_crossover_point;
auto found_point_end_itr = c2_ops.begin() + c2.find_endpoint(program, point->p2_crossover_point);
auto found_point_end_itr = c2_ops.begin() + find_endpoint(program, c2_ops, point->p2_crossover_point);
stack_allocator& c1_stack = c1.get_values();
stack_allocator& c2_stack = c2.get_values();
@ -215,13 +215,13 @@ namespace blt::gp
return c;
}
blt::size_t mutation_t::mutate_point(gp_program& program, tree_t& c, blt::size_t node)
void mutation_t::mutate_point(gp_program& program, tree_t& c, blt::size_t node)
{
auto& ops_r = c.get_operations();
auto& vals_r = c.get_values();
auto begin_point = static_cast<blt::ptrdiff_t>(node);
auto end_point = c.find_endpoint(program, begin_point);
auto end_point = find_endpoint(program, ops_r, begin_point);
auto begin_operator_id = ops_r[begin_point].id;
const auto& type_info = program.get_operator_info(begin_operator_id);
@ -293,6 +293,23 @@ namespace blt::gp
throw std::exception();
}
#endif
return begin_point + new_ops_r.size();
}
blt::ptrdiff_t find_endpoint(blt::gp::gp_program& program, const std::vector<blt::gp::op_container_t>& container, blt::ptrdiff_t index)
{
blt::i64 children_left = 0;
do
{
const auto& type = program.get_operator_info(container[index].id);
// this is a child to someone
if (children_left != 0)
children_left--;
if (type.argc.argc > 0)
children_left += type.argc.argc;
index++;
} while (children_left > 0);
return index;
}
}

View File

@ -201,22 +201,4 @@ namespace blt::gp
return depth;
}
blt::ptrdiff_t tree_t::find_endpoint(gp_program& program, blt::ptrdiff_t index)
{
blt::i64 children_left = 0;
do
{
const auto& type = program.get_operator_info(operations[index].id);
// this is a child to someone
if (children_left != 0)
children_left--;
if (type.argc.argc > 0)
children_left += type.argc.argc;
index++;
} while (children_left > 0);
return index;
}
}