From e9954f5065d703295f5a627ed25fda1540007a45 Mon Sep 17 00:00:00 2001 From: Brett Date: Sun, 11 Aug 2024 13:57:55 -0400 Subject: [PATCH] debug --- CMakeLists.txt | 2 +- lib/blt | 2 +- tests/destructor_test.cpp | 34 ++++++++++++++++++++++------------ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f66556..8e05dc2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.0.134) +project(blt-gp VERSION 0.0.135) include(CTest) diff --git a/lib/blt b/lib/blt index 99e735b..4327b34 160000 --- a/lib/blt +++ b/lib/blt @@ -1 +1 @@ -Subproject commit 99e735b7601716caf9e5b6dbac0ae22b2ab99b3d +Subproject commit 4327b34c841fd6d8fb6509757d5cab2717d35457 diff --git a/tests/destructor_test.cpp b/tests/destructor_test.cpp index c8e27b9..29fbe70 100644 --- a/tests/destructor_test.cpp +++ b/tests/destructor_test.cpp @@ -52,13 +52,23 @@ class move_float move_float(): f(new float()) { constructions++; } - move_float(float f): f(new float(f)) // NOLINT + explicit move_float(float f): f(new float(f)) { constructions++; // BLT_TRACE("Value Constructed"); } - operator float() // NOLINT + explicit operator float() const + { + return *f; + } + + float get() const + { + return *f; + } + + float operator*() const { return *f; } @@ -99,27 +109,27 @@ blt::gp::prog_config_t config = blt::gp::prog_config_t() blt::gp::type_provider type_system; blt::gp::gp_program program{type_system, SEED, config}; -blt::gp::operation_t add([](move_float a, move_float b) { return move_float(a + b); }, "add"); -blt::gp::operation_t sub([](move_float a, move_float b) { return move_float(a - b); }, "sub"); -blt::gp::operation_t mul([](move_float a, move_float b) { return move_float(a * b); }, "mul"); -blt::gp::operation_t pro_div([](move_float a, move_float b) { return move_float(b == 0.0f ? 1.0f : a / b); }, "div"); -blt::gp::operation_t op_sin([](move_float a) { return move_float(std::sin(a)); }, "sin"); -blt::gp::operation_t op_cos([](move_float a) { return move_float(std::cos(a)); }, "cos"); -blt::gp::operation_t op_exp([](move_float a) { return move_float(std::exp(a)); }, "exp"); -blt::gp::operation_t op_log([](move_float a) { return move_float(a == 0.0f ? 0.0f : std::log(a)); }, "log"); +blt::gp::operation_t add([](const move_float& a, const move_float& b) { return move_float(*a + *b); }, "add"); +blt::gp::operation_t sub([](const move_float& a, const move_float& b) { return move_float(*a - *b); }, "sub"); +blt::gp::operation_t mul([](const move_float& a, const move_float& b) { return move_float(*a * *b); }, "mul"); +blt::gp::operation_t pro_div([](const move_float& a, const move_float& b) { return move_float(*b == 0.0f ? 1.0f : *a / *b); }, "div"); +blt::gp::operation_t op_sin([](const move_float& a) { return move_float(std::sin(*a)); }, "sin"); +blt::gp::operation_t op_cos([](const move_float& a) { return move_float(std::cos(*a)); }, "cos"); +blt::gp::operation_t op_exp([](const move_float& a) { return move_float(std::exp(*a)); }, "exp"); +blt::gp::operation_t op_log([](const move_float& a) { return move_float(*a == 0.0f ? 0.0f : std::log(*a)); }, "log"); blt::gp::operation_t lit([]() { return move_float(program.get_random().get_float(-320.0f, 320.0f)); }, "lit"); blt::gp::operation_t op_x([](const context& context) { - return move_float(context.x); + return context.x; }, "x"); constexpr auto fitness_function = [](blt::gp::tree_t& current_tree, blt::gp::fitness_t& fitness, blt::size_t) { constexpr double value_cutoff = 1.e15; for (auto& fitness_case : fitness_cases) { - auto diff = std::abs(fitness_case.y - current_tree.get_evaluation_value(&fitness_case)); + auto diff = std::abs(*fitness_case.y - *current_tree.get_evaluation_value(&fitness_case)); if (diff < value_cutoff) { fitness.raw_fitness += diff;