diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f5877a..0270901 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(lilfbtf5 VERSION 0.1.35) +project(lilfbtf5 VERSION 0.1.36) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) diff --git a/include/lilfbtf/fwddecl.h b/include/lilfbtf/fwddecl.h index 3aa17c8..a23600d 100644 --- a/include/lilfbtf/fwddecl.h +++ b/include/lilfbtf/fwddecl.h @@ -29,13 +29,22 @@ namespace fb namespace detail { class node_t; + + struct fitness_results + { + double fitness; + blt::size_t hits; + }; } class func_t; + class tree_t; class type_engine_t; + class gp_system_t; + class gp_population_t; // no way we are going to have more than 4billion types or functions. @@ -44,7 +53,7 @@ namespace fb using arg_c_t = blt::size_t; using func_t_call_t = std::function)>; using func_t_init_t = std::function; - using fitness_eval_func_t = std::function; + using fitness_eval_func_t = std::function; using function_name = const std::string&; using type_name = const std::string&; } diff --git a/include/lilfbtf/system.h b/include/lilfbtf/system.h index f0f7aea..90061e4 100644 --- a/include/lilfbtf/system.h +++ b/include/lilfbtf/system.h @@ -21,6 +21,7 @@ #include #include +#include #include namespace fb @@ -28,7 +29,22 @@ namespace fb class gp_population_t { - + private: + blt::thread_pool& pool; + std::vector population; + + void crossover(); + + void mutate(); + public: + explicit gp_population_t(blt::thread_pool& pool): pool(pool) + {} + + void init_pop(); + + void execute(const fitness_eval_func_t& fitnessEvalFunc); + + void breed_new_pop(); }; class gp_system_t @@ -36,7 +52,7 @@ namespace fb private: public: - gp_system_t(type_engine_t& types): types(types) + explicit gp_system_t(type_engine_t& types): types(types) {} private: diff --git a/include/lilfbtf/tree.h b/include/lilfbtf/tree.h index 1c4facc..3fcc798 100644 --- a/include/lilfbtf/tree.h +++ b/include/lilfbtf/tree.h @@ -173,7 +173,7 @@ namespace fb static tree_t make_tree(detail::tree_construction_info_t tree_info, blt::size_t min_depth, blt::size_t max_depth, std::optional starting_type = {}); - detail::tree_eval_t evaluate(); + detail::tree_eval_t evaluate(const fitness_eval_func_t& fitnessEvalFunc); blt::size_t depth(); @@ -191,6 +191,7 @@ namespace fb { blt::size_t depth = 0; blt::size_t node_count = 0; + detail::fitness_results fitness; bool dirty = true; } cache; }; diff --git a/libs/BLT b/libs/BLT index 9bba525..16641a2 160000 --- a/libs/BLT +++ b/libs/BLT @@ -1 +1 @@ -Subproject commit 9bba525b1f33495a68c43fa1f66c0a239220e68c +Subproject commit 16641a27cbe6fccb8f6a6518d903432311cbeb81 diff --git a/src/system.cpp b/src/system.cpp index 1341cd7..87a96a5 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -19,5 +19,28 @@ namespace fb { - + void fb::gp_population_t::crossover() + { + + } + + void fb::gp_population_t::mutate() + { + + } + + void fb::gp_population_t::init_pop() + { + + } + + void fb::gp_population_t::execute(const fitness_eval_func_t& fitnessEvalFunc) + { + + } + + void fb::gp_population_t::breed_new_pop() + { + + } } \ No newline at end of file diff --git a/src/tree.cpp b/src/tree.cpp index 06d7158..b683811 100644 --- a/src/tree.cpp +++ b/src/tree.cpp @@ -63,7 +63,7 @@ namespace fb return tree; } - detail::tree_eval_t tree_t::evaluate() + detail::tree_eval_t tree_t::evaluate(const fitness_eval_func_t& fitnessEvalFunc) { using detail::node_t; std::stack nodes; @@ -87,6 +87,8 @@ namespace fb node_stack.pop(); } + cache.fitness = fitnessEvalFunc(root); + return {root->type.getValue(), root->type.getType()}; }