functions
parent
14c56b39ae
commit
86c2a8f59a
|
@ -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)
|
||||
|
|
|
@ -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<void(func_t&, blt::span<detail::node_t*>)>;
|
||||
using func_t_init_t = std::function<void(func_t&)>;
|
||||
using fitness_eval_func_t = std::function<void(detail::node_t*)>;
|
||||
using fitness_eval_func_t = std::function<detail::fitness_results(detail::node_t*)>;
|
||||
using function_name = const std::string&;
|
||||
using type_name = const std::string&;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <lilfbtf/fwddecl.h>
|
||||
#include <lilfbtf/tree.h>
|
||||
#include <blt/std/thread.h>
|
||||
#include <vector>
|
||||
|
||||
namespace fb
|
||||
|
@ -28,7 +29,22 @@ namespace fb
|
|||
|
||||
class gp_population_t
|
||||
{
|
||||
|
||||
private:
|
||||
blt::thread_pool<true>& pool;
|
||||
std::vector<tree_t> population;
|
||||
|
||||
void crossover();
|
||||
|
||||
void mutate();
|
||||
public:
|
||||
explicit gp_population_t(blt::thread_pool<true>& 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:
|
||||
|
|
|
@ -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<type_id> 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;
|
||||
};
|
||||
|
|
2
libs/BLT
2
libs/BLT
|
@ -1 +1 @@
|
|||
Subproject commit 9bba525b1f33495a68c43fa1f66c0a239220e68c
|
||||
Subproject commit 16641a27cbe6fccb8f6a6518d903432311cbeb81
|
|
@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -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<node_t*> nodes;
|
||||
|
@ -87,6 +87,8 @@ namespace fb
|
|||
node_stack.pop();
|
||||
}
|
||||
|
||||
cache.fitness = fitnessEvalFunc(root);
|
||||
|
||||
return {root->type.getValue(), root->type.getType()};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue