prepare for gc

thread
Brett 2024-08-12 20:36:21 -04:00
parent 552b150402
commit 2d4ae109df
5 changed files with 17 additions and 14 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.139) project(blt-gp VERSION 0.0.140)
include(CTest) include(CTest)

View File

@ -399,6 +399,7 @@ namespace blt::gp
void next_generation() void next_generation()
{ {
current_pop.drop(*this);
current_pop = std::move(next_pop); current_pop = std::move(next_pop);
current_generation++; current_generation++;
} }
@ -543,12 +544,7 @@ namespace blt::gp
~gp_program() ~gp_program()
{ {
std::cout << ("Destroying Program!") << std::endl; current_pop.drop(*this);
for (auto& pop : current_pop.get_individuals())
{
pop.tree.drop(*this);
pop = {};
}
thread_helper.lifetime_over = true; thread_helper.lifetime_over = true;
thread_helper.barrier.notify_all(); thread_helper.barrier.notify_all();
thread_helper.thread_function_condition.notify_all(); thread_helper.thread_function_condition.notify_all();

View File

@ -337,6 +337,7 @@ namespace blt::gp
population_t& operator=(population_t&&) = default; population_t& operator=(population_t&&) = default;
void drop(gp_program& program);
private: private:
std::vector<individual> individuals; std::vector<individual> individuals;
}; };

View File

@ -291,7 +291,7 @@ namespace blt::gp
return; return;
if (values.empty()) if (values.empty())
return; return;
std::cout << "---- NEW TREE ---- References " << *reference_counter << " ----" << std::endl; //std::cout << "---- NEW TREE ---- References " << *reference_counter << " ----" << std::endl;
if (reference_counter->load() > 1) if (reference_counter->load() > 1)
return; return;
static blt::hashset_t<blt::size_t> sets; static blt::hashset_t<blt::size_t> sets;
@ -305,18 +305,24 @@ namespace blt::gp
float* f; float* f;
blt::size_t i; blt::size_t i;
}; };
auto h = values.from<hello>(0); //auto h = values.from<hello>(0);
if (sets.find(h.i) != sets.end()) /*if (sets.find(h.i) != sets.end())
std::cout << "HEY ASSHOLE Duplicate Value " << h.i << std::endl; std::cout << "HEY ASSHOLE Duplicate Value " << h.i << std::endl;
else else
{ {
std::cout << "Destroying Value " << h.i << std::endl; std::cout << "Destroying Value " << h.i << std::endl;
sets.insert(h.i); sets.insert(h.i);
} }*/
program.get_destroy_func(operation.id)(detail::destroy_t::RETURN, nullptr, values); program.get_destroy_func(operation.id)(detail::destroy_t::RETURN, nullptr, values);
values.pop_bytes(static_cast<blt::ptrdiff_t>(stack_allocator::aligned_size(operation.type_size))); values.pop_bytes(static_cast<blt::ptrdiff_t>(stack_allocator::aligned_size(operation.type_size)));
} }
operations.pop_back(); operations.pop_back();
} }
} }
void population_t::drop(gp_program& program)
{
for (auto& pop : get_individuals())
pop.tree.drop(program);
}
} }

View File

@ -113,9 +113,9 @@ blt::gp::prog_config_t config = blt::gp::prog_config_t()
.set_initial_min_tree_size(2) .set_initial_min_tree_size(2)
.set_initial_max_tree_size(6) .set_initial_max_tree_size(6)
.set_elite_count(0) .set_elite_count(0)
.set_crossover_chance(0.9) .set_crossover_chance(0)
.set_mutation_chance(0.1) .set_mutation_chance(0)
.set_reproduction_chance(0) .set_reproduction_chance(1.0)
.set_max_generations(5) .set_max_generations(5)
.set_pop_size(500) .set_pop_size(500)
.set_thread_count(0); .set_thread_count(0);