From e5966789be45685ed73d0a152319c8da1793e53f Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Sun, 25 Aug 2024 18:08:23 -0400 Subject: [PATCH] annoying --- CMakeLists.txt | 2 +- include/blt/gp/program.h | 15 ++------------- include/blt/gp/selection.h | 16 +++++++++++++++- include/blt/gp/stack.h | 4 ++-- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a89ee8b..f41377d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.1.25) +project(blt-gp VERSION 0.1.26) include(CTest) diff --git a/include/blt/gp/program.h b/include/blt/gp/program.h index 5d7bfec..b86080f 100644 --- a/include/blt/gp/program.h +++ b/include/blt/gp/program.h @@ -123,7 +123,6 @@ namespace blt::gp static thread_local evaluation_context results{}; results.values.reset(); results.values.reserve(largest); -// BLT_DEBUG("%ld stored %ld", largest, results.values.internal_storage_size()); blt::size_t total_so_far = 0; @@ -136,11 +135,6 @@ namespace blt::gp continue; } call_jmp_table(operation.id, context, results.values, results.values, operators...); -// if (results.values.internal_storage_size() != l) -// { -// BLT_DEBUG("Size %ld is now %ld", l, results.values.internal_storage_size()); -// l = results.values.internal_storage_size(); -// } } return results; @@ -507,22 +501,16 @@ namespace blt::gp while (thread_helper.next_gen_left > 0) { blt::size_t size = 0; - blt::size_t begin = 0; blt::size_t end = thread_helper.next_gen_left.load(std::memory_order_relaxed); do { size = std::min(end, config.evaluation_size); - begin = end - size; } while (!thread_helper.next_gen_left.compare_exchange_weak(end, end - size, std::memory_order::memory_order_relaxed, std::memory_order::memory_order_relaxed)); - //auto measure = tracker.start_measurement(); - for (blt::size_t i = begin; i < end; i++) + while (new_children.size() < size) func(args, crossover_selection, mutation_selection, reproduction_selection); - //tracker.stop_measurement(measure); - //BLT_TRACE("Allocated %ld times with a total of %s", measure.getAllocationDifference(), - // blt::byte_convert_t(measure.getAllocatedByteDifference()).convert_to_nearest_type().to_pretty_string().c_str()); { std::scoped_lock lock(thread_helper.thread_generation_lock); @@ -553,6 +541,7 @@ namespace blt::gp void next_generation() { + BLT_ASSERT_MSG(next_pop.get_individuals().size() == config.population_size, ("pop size: " + std::to_string(next_pop.get_individuals().size())).c_str()); current_pop = std::move(next_pop); current_generation++; } diff --git a/include/blt/gp/selection.h b/include/blt/gp/selection.h index 5c99354..baf4842 100644 --- a/include/blt/gp/selection.h +++ b/include/blt/gp/selection.h @@ -24,6 +24,7 @@ #include #include #include +#include "blt/std/format.h" namespace blt::gp { @@ -84,6 +85,7 @@ namespace blt::gp // everyone gets a chance once per loop. if (random.choice(config.crossover_chance)) { +// auto state = tracker.start_measurement(); // crossover auto& p1 = crossover_selection.select(program, current_pop, current_stats); auto& p2 = crossover_selection.select(program, current_pop, current_stats); @@ -94,24 +96,36 @@ namespace blt::gp if (results) { next_pop.push_back(std::move(results->child1)); - next_pop.push_back(std::move(results->child2)); + if (next_pop.size() != config.population_size) + next_pop.push_back(std::move(results->child2)); } +// tracker.stop_measurement(state); +// BLT_TRACE("Crossover Allocated %ld times with a total of %s", state.getAllocationDifference(), +// blt::byte_convert_t(state.getAllocatedByteDifference()).convert_to_nearest_type().to_pretty_string().c_str()); } break; case 1: if (random.choice(config.mutation_chance)) { +// auto state = tracker.start_measurement(); // mutation auto& p = mutation_selection.select(program, current_pop, current_stats); next_pop.push_back(std::move(config.mutator.get().apply(program, p))); +// tracker.stop_measurement(state); +// BLT_TRACE("Mutation Allocated %ld times with a total of %s", state.getAllocationDifference(), +// blt::byte_convert_t(state.getAllocatedByteDifference()).convert_to_nearest_type().to_pretty_string().c_str()); } break; case 2: if (config.reproduction_chance > 0 && random.choice(config.reproduction_chance)) { +// auto state = tracker.start_measurement(); // reproduction auto& p = reproduction_selection.select(program, current_pop, current_stats); next_pop.push_back(p); +// tracker.stop_measurement(state); +// BLT_TRACE("Reproduction Allocated %ld times with a total of %s", state.getAllocationDifference(), +// blt::byte_convert_t(state.getAllocatedByteDifference()).convert_to_nearest_type().to_pretty_string().c_str()); } break; default: diff --git a/include/blt/gp/stack.h b/include/blt/gp/stack.h index 4e6b62c..2ecb12c 100644 --- a/include/blt/gp/stack.h +++ b/include/blt/gp/stack.h @@ -121,7 +121,7 @@ namespace blt::gp return getAllocatedBytes() - getDeallocatedBytes(); } - allocation_data_t start_measurement() + [[nodiscard]] allocation_data_t start_measurement() const { allocation_data_t data{}; data.start_allocations = allocations; @@ -131,7 +131,7 @@ namespace blt::gp return data; } - void stop_measurement(allocation_data_t& data) + void stop_measurement(allocation_data_t& data) const { data.end_allocations = allocations; data.end_deallocations = deallocations;