diff --git a/include/blt/gp/program.h b/include/blt/gp/program.h index f044f4a..6d3c091 100644 --- a/include/blt/gp/program.h +++ b/include/blt/gp/program.h @@ -399,6 +399,7 @@ namespace blt::gp void next_generation() { + current_pop.drop(*this); current_pop = std::move(next_pop); current_generation++; } @@ -543,12 +544,7 @@ namespace blt::gp ~gp_program() { - std::cout << ("Destroying Program!") << std::endl; - for (auto& pop : current_pop.get_individuals()) - { - pop.tree.drop(*this); - pop = {}; - } + current_pop.drop(*this); thread_helper.lifetime_over = true; thread_helper.barrier.notify_all(); thread_helper.thread_function_condition.notify_all(); diff --git a/include/blt/gp/tree.h b/include/blt/gp/tree.h index adbe430..841aed1 100644 --- a/include/blt/gp/tree.h +++ b/include/blt/gp/tree.h @@ -337,6 +337,7 @@ namespace blt::gp population_t& operator=(population_t&&) = default; + void drop(gp_program& program); private: std::vector individuals; }; diff --git a/src/tree.cpp b/src/tree.cpp index a9de1f2..5514847 100644 --- a/src/tree.cpp +++ b/src/tree.cpp @@ -291,7 +291,7 @@ namespace blt::gp return; if (values.empty()) return; - std::cout << "---- NEW TREE ---- References " << *reference_counter << " ----" << std::endl; + //std::cout << "---- NEW TREE ---- References " << *reference_counter << " ----" << std::endl; if (reference_counter->load() > 1) return; static blt::hashset_t sets; @@ -305,18 +305,24 @@ namespace blt::gp float* f; blt::size_t i; }; - auto h = values.from(0); - if (sets.find(h.i) != sets.end()) + //auto h = values.from(0); + /*if (sets.find(h.i) != sets.end()) std::cout << "HEY ASSHOLE Duplicate Value " << h.i << std::endl; else { std::cout << "Destroying Value " << h.i << std::endl; sets.insert(h.i); - } + }*/ program.get_destroy_func(operation.id)(detail::destroy_t::RETURN, nullptr, values); values.pop_bytes(static_cast(stack_allocator::aligned_size(operation.type_size))); } operations.pop_back(); } } + + void population_t::drop(gp_program& program) + { + for (auto& pop : get_individuals()) + pop.tree.drop(program); + } } \ No newline at end of file diff --git a/tests/destructor_test.cpp b/tests/destructor_test.cpp index 5bf05b8..a340449 100644 --- a/tests/destructor_test.cpp +++ b/tests/destructor_test.cpp @@ -113,9 +113,9 @@ blt::gp::prog_config_t config = blt::gp::prog_config_t() .set_initial_min_tree_size(2) .set_initial_max_tree_size(6) .set_elite_count(0) - .set_crossover_chance(0.9) - .set_mutation_chance(0.1) - .set_reproduction_chance(0) + .set_crossover_chance(0) + .set_mutation_chance(0) + .set_reproduction_chance(1.0) .set_max_generations(5) .set_pop_size(500) .set_thread_count(0);