has a silly flaw

main
Brett 2025-04-29 21:48:05 -04:00
parent f6d8073be9
commit 6700161699
4 changed files with 14 additions and 6 deletions

View File

@ -27,7 +27,7 @@ macro(compile_options target_name)
sanitizers(${target_name}) sanitizers(${target_name})
endmacro() endmacro()
project(blt-gp VERSION 0.5.22) project(blt-gp VERSION 0.5.23)
include(CTest) include(CTest)

View File

@ -157,6 +157,7 @@ namespace blt::gp
class one_point_crossover_t : public crossover_t class one_point_crossover_t : public crossover_t
{ {
public:
one_point_crossover_t(): crossover_t(config_t{}) one_point_crossover_t(): crossover_t(config_t{})
{ {
} }

View File

@ -31,7 +31,8 @@ namespace blt::gp
// this is largely to not break the tests :3 // this is largely to not break the tests :3
// it's also to allow for quick setup of a gp program if you don't care how crossover or mutation is handled // it's also to allow for quick setup of a gp program if you don't care how crossover or mutation is handled
static advanced_mutation_t s_mutator; static advanced_mutation_t s_mutator;
static subtree_crossover_t s_crossover; // static subtree_crossover_t s_crossover;
static one_point_crossover_t s_crossover;
static ramped_half_initializer_t s_init; static ramped_half_initializer_t s_init;
prog_config_t::prog_config_t(): mutator(s_mutator), crossover(s_crossover), pop_initializer(s_init) prog_config_t::prog_config_t(): mutator(s_mutator), crossover(s_crossover), pop_initializer(s_init)

View File

@ -123,8 +123,8 @@ namespace blt::gp
bool one_point_crossover_t::apply(gp_program& program, const tree_t& p1, const tree_t& p2, tree_t& c1, tree_t& c2) bool one_point_crossover_t::apply(gp_program& program, const tree_t& p1, const tree_t& p2, tree_t& c1, tree_t& c2)
{ {
if (p1.size() < config.min_tree_size || p2.size() < config.min_tree_size) // if (p1.size() < config.min_tree_size || p2.size() < config.min_tree_size)
return false; // return false;
tree_t::subtree_point_t point1, point2; // NOLINT tree_t::subtree_point_t point1, point2; // NOLINT
if (config.traverse) if (config.traverse)
@ -173,6 +173,8 @@ namespace blt::gp
std::vector<reorder_index_t> p1_reorder_types; std::vector<reorder_index_t> p1_reorder_types;
std::vector<reorder_index_t> p2_reorder_types; std::vector<reorder_index_t> p2_reorder_types;
std::vector<swap_index_t> swap_types; std::vector<swap_index_t> swap_types;
std::vector<swap_index_t> p1_to_p2_transfer_types;
std::vector<swap_index_t> p2_to_p1_transfer_types;
std::optional<size_t> get_p1_index(const type_id& id) std::optional<size_t> get_p1_index(const type_id& id)
{ {
@ -216,6 +218,8 @@ namespace blt::gp
p1_reorder_types.clear(); p1_reorder_types.clear();
p2_reorder_types.clear(); p2_reorder_types.clear();
swap_types.clear(); swap_types.clear();
p1_to_p2_transfer_types.clear();
p2_to_p1_transfer_types.clear();
for (auto& [id, v] : missing_p1_types) for (auto& [id, v] : missing_p1_types)
v.clear(); v.clear();
for (auto& [id, v] : missing_p2_types) for (auto& [id, v] : missing_p2_types)
@ -296,14 +300,16 @@ namespace blt::gp
c2.swap_subtrees(resolver.children_data_p2[index1], c2, resolver.children_data_p2[index2]); c2.swap_subtrees(resolver.children_data_p2[index1], c2, resolver.children_data_p2[index2]);
for (const auto& [p1_index, p2_index] : resolver.swap_types) for (const auto& [p1_index, p2_index] : resolver.swap_types)
{ c1.swap_subtrees(resolver.children_data_p1[p1_index], c2, resolver.children_data_p2[p2_index]);
} c1.modify_operator(point1.pos, p2_operator.id(), p2_info.return_type);
c2.modify_operator(point2.pos, p1_operator.id(), p1_info.return_type);
#if BLT_DEBUG_LEVEL >= 2 #if BLT_DEBUG_LEVEL >= 2
if (!c1.check(detail::debug::context_ptr) || !c2.check(detail::debug::context_ptr)) if (!c1.check(detail::debug::context_ptr) || !c2.check(detail::debug::context_ptr))
throw std::runtime_error("Tree check failed"); throw std::runtime_error("Tree check failed");
#endif #endif
return true;
} }
bool advanced_crossover_t::apply(gp_program& program, const tree_t& p1, const tree_t& p2, tree_t& c1, tree_t& c2) bool advanced_crossover_t::apply(gp_program& program, const tree_t& p1, const tree_t& p2, tree_t& c1, tree_t& c2)