multi type test, it's possible for infinite recursion.
parent
ea80e28f84
commit
78b37584a9
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.25)
|
||||
project(blt-gp VERSION 0.0.36)
|
||||
project(blt-gp VERSION 0.0.37)
|
||||
|
||||
include(CTest)
|
||||
|
||||
|
|
|
@ -26,10 +26,19 @@ 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 add([](float a, float b) {
|
||||
BLT_TRACE("a: %f + b: %f = %f", a, b, a + b);
|
||||
return a + b;
|
||||
});
|
||||
blt::gp::operation_t sub([](float a, float b) {
|
||||
BLT_TRACE("a: %f - b: %f = %f", a, b, a - b);
|
||||
return a - b; });
|
||||
blt::gp::operation_t mul([](float a, float b) {
|
||||
BLT_TRACE("a: %f * b: %f = %f", a, b, a * b);
|
||||
return a * b; });
|
||||
blt::gp::operation_t pro_div([](float a, float b) {
|
||||
BLT_TRACE("a: %f / b: %f = %f", a, b, (b == 0 ? 0.0f : a / b));
|
||||
return b == 0 ? 0.0f : a / b; });
|
||||
blt::gp::operation_t lit([]() {
|
||||
//static std::uniform_real_distribution<float> dist(-32000, 32000);
|
||||
static std::uniform_real_distribution<float> dist(0.0f, 10.0f);
|
||||
|
|
|
@ -59,6 +59,17 @@ int main()
|
|||
silly.add_operator(sub);
|
||||
silly.add_operator(mul);
|
||||
silly.add_operator(pro_div);
|
||||
|
||||
silly.add_operator(op_if);
|
||||
silly.add_operator(eq_f);
|
||||
silly.add_operator(eq_b);
|
||||
silly.add_operator(lt);
|
||||
silly.add_operator(gt);
|
||||
silly.add_operator(op_and);
|
||||
silly.add_operator(op_or);
|
||||
silly.add_operator(op_xor);
|
||||
silly.add_operator(op_not);
|
||||
|
||||
silly.add_operator(lit, true);
|
||||
|
||||
program.set_operations(std::move(silly));
|
||||
|
|
|
@ -61,10 +61,10 @@ namespace blt::gp
|
|||
tree_generator.pop();
|
||||
|
||||
tree.get_operations().emplace_back(
|
||||
args.program.get_operation(top.id),
|
||||
args.program.get_transfer_func(top.id),
|
||||
args.program.is_static(top.id)
|
||||
);
|
||||
args.program.get_operation(top.id),
|
||||
args.program.get_transfer_func(top.id),
|
||||
args.program.is_static(top.id)
|
||||
);
|
||||
max_depth = std::max(max_depth, top.depth);
|
||||
|
||||
if (args.program.is_static(top.id))
|
||||
|
@ -89,7 +89,10 @@ namespace blt::gp
|
|||
return create_tree([args](gp_program& program, std::stack<stack>& tree_generator, const type& type, blt::size_t new_depth) {
|
||||
if (new_depth >= args.max_depth)
|
||||
{
|
||||
tree_generator.push({program.select_terminal(type.id()), new_depth});
|
||||
if (program.get_type_terminals(type.id()).empty())
|
||||
tree_generator.push({program.select_non_terminal(type.id()), new_depth});
|
||||
else
|
||||
tree_generator.push({program.select_terminal(type.id()), new_depth});
|
||||
return;
|
||||
}
|
||||
if (program.choice() || new_depth < args.min_depth)
|
||||
|
@ -104,7 +107,10 @@ namespace blt::gp
|
|||
return create_tree([args](gp_program& program, std::stack<stack>& tree_generator, const type& type, blt::size_t new_depth) {
|
||||
if (new_depth >= args.max_depth)
|
||||
{
|
||||
tree_generator.push({program.select_terminal(type.id()), new_depth});
|
||||
if (program.get_type_terminals(type.id()).empty())
|
||||
tree_generator.push({program.select_non_terminal(type.id()), new_depth});
|
||||
else
|
||||
tree_generator.push({program.select_terminal(type.id()), new_depth});
|
||||
return;
|
||||
}
|
||||
tree_generator.push({program.select_non_terminal(type.id()), new_depth});
|
||||
|
|
Loading…
Reference in New Issue