diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e2c523..79cf22e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.0.35) +project(blt-gp VERSION 0.0.36) include(CTest) @@ -64,12 +64,13 @@ if (${BUILD_EXAMPLES}) target_link_options(${name}-example PRIVATE -fsanitize=thread) endif () - add_test(NAME ${name}-test COMMAND ${name}-example) + add_test(NAME ${name} COMMAND ${name}-example) project(blt-gp) endmacro() - blt_add_example(blt-gp1 examples/main.cpp) + blt_add_example(blt-gp1 examples/gp_test_1.cpp) blt_add_example(blt-gp2 examples/gp_test_2.cpp) + blt_add_example(blt-gp3 examples/gp_test_3.cpp) endif () \ No newline at end of file diff --git a/examples/main.cpp b/examples/gp_test_1.cpp similarity index 100% rename from examples/main.cpp rename to examples/gp_test_1.cpp diff --git a/examples/gp_test_2.cpp b/examples/gp_test_2.cpp index 9e8fee1..a2dd137 100644 --- a/examples/gp_test_2.cpp +++ b/examples/gp_test_2.cpp @@ -36,10 +36,12 @@ blt::gp::operation_t lit([]() { return dist(program.get_random()); }); +/** + * This is a test using a type with blt::gp + */ int main() { type_system.register_type(); - type_system.register_type(); blt::gp::gp_operations silly{type_system}; silly.add_operator(add); diff --git a/examples/gp_test_3.cpp b/examples/gp_test_3.cpp new file mode 100644 index 0000000..de0b3ac --- /dev/null +++ b/examples/gp_test_3.cpp @@ -0,0 +1,76 @@ +/* + * + * Copyright (C) 2024 Brett Terpstra + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include +#include +#include + +static constexpr long SEED = 41912; + +blt::gp::type_system type_system; +blt::gp::gp_program program(type_system, std::mt19937_64{SEED}); // NOLINT + +blt::gp::operation_t add([](float a, float b) { return a + b; }); +blt::gp::operation_t sub([](float a, float b) { return a - b; }); +blt::gp::operation_t mul([](float a, float b) { return a * b; }); +blt::gp::operation_t pro_div([](float a, float b) { return b == 0 ? 0.0f : a / b; }); + +blt::gp::operation_t op_if([](bool b, float a, float c) {return b ? a : c; }); +blt::gp::operation_t eq_f([](float a, float b) {return a == b; }); +blt::gp::operation_t eq_b([](bool a, bool b) {return a == b; }); +blt::gp::operation_t lt([](float a, float b) {return a < b; }); +blt::gp::operation_t gt([](float a, float b) {return a > b; }); +blt::gp::operation_t op_and([](bool a, bool b) {return a && b; }); +blt::gp::operation_t op_or([](bool a, bool b) {return a || b; }); +blt::gp::operation_t op_xor([](bool a, bool b) {return static_cast(a ^ b); }); +blt::gp::operation_t op_not([](bool b) {return !b; }); + +blt::gp::operation_t lit([]() { + //static std::uniform_real_distribution dist(-32000, 32000); + static std::uniform_real_distribution dist(0.0f, 10.0f); + return dist(program.get_random()); +}); + +/** + * This is a test using multiple types with blt::gp + */ +int main() +{ + type_system.register_type(); + type_system.register_type(); + + blt::gp::gp_operations silly{type_system}; + silly.add_operator(add); + silly.add_operator(sub); + silly.add_operator(mul); + silly.add_operator(pro_div); + silly.add_operator(lit, true); + + program.set_operations(std::move(silly)); + + blt::gp::grow_generator_t grow; + auto tree = grow.generate(blt::gp::generator_arguments{program, type_system.get_type().id(), 3, 7}); + + auto value = tree.get_evaluation_value(nullptr); + + BLT_TRACE(value); + + return 0; + + return 0; +} diff --git a/src/generators.cpp b/src/generators.cpp index a6ec198..b61a5e9 100644 --- a/src/generators.cpp +++ b/src/generators.cpp @@ -63,10 +63,7 @@ namespace blt::gp tree.get_operations().emplace_back( args.program.get_operation(top.id), args.program.get_transfer_func(top.id), - //static_cast(top.depth), args.program.is_static(top.id) - //static_cast(args.program.get_argc(top.id).argc), - //static_cast(args.program.get_argc(top.id).argc_context) ); max_depth = std::max(max_depth, top.depth); diff --git a/src/tree.cpp b/src/tree.cpp index 477a7c6..04bd793 100644 --- a/src/tree.cpp +++ b/src/tree.cpp @@ -47,8 +47,6 @@ namespace blt::gp operations_stack.emplace_back(empty_callable, operation.transfer, true); } - BLT_TRACE("Bytes Left: %ld | %ld", values_process.bytes_in_head(), value_stack.bytes_in_head()); - return results; } } \ No newline at end of file