shared
Brett 2024-08-21 01:40:21 -04:00
parent 3d82f69370
commit 46ceaf49dd
5 changed files with 35 additions and 44 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25)
project(blt-gp VERSION 0.1.17)
project(blt-gp VERSION 0.1.18)
include(CTest)

View File

@ -319,9 +319,9 @@ namespace blt::gp::detail
explicit operator_storage_test(blt::gp::operator_builder<context>& ops): ops(ops)
{}
inline blt::gp::detail::callable_t& operator[](blt::size_t index)
inline blt::gp::detail::operator_func_t& operator[](blt::size_t index)
{
return ops.storage.operators[index].function;
return ops.storage.operators[index].func;
}
private:
@ -447,24 +447,21 @@ int main()
//BLT_TRACE(blt::type_string<blt::gp::detail::remove_cv_ref<decltype(silly_op_3)::first::type>>());
//BLT_TRACE("Same types? %s", (std::is_same_v<context, blt::gp::detail::remove_cv_ref<decltype(silly_op_3)::first::type>>) ? "true" : "false");
ops.add_operator(silly_op_3);
ops.add_operator(silly_op_4);
ops.add_operator(silly_op_2);
ops.build(silly_op_3, silly_op_4, silly_op_2);
blt::gp::detail::operator_storage_test de(ops);
context hello{5, 10};
alloc.push(1.153f);
de[0](static_cast<void*>(&hello), alloc, alloc, nullptr);
de[0](static_cast<void*>(&hello), alloc, alloc);
BLT_TRACE("first value: %f", alloc.pop<float>());
de[1](static_cast<void*>(&hello), alloc, alloc, nullptr);
de[1](static_cast<void*>(&hello), alloc, alloc);
BLT_TRACE("second value: %f", alloc.pop<float>());
alloc.push(1.0f);
alloc.push(52.213f);
de[2](static_cast<void*>(&hello), alloc, alloc, nullptr);
de[2](static_cast<void*>(&hello), alloc, alloc);
BLT_TRACE("third value: %f", alloc.pop<float>());
//auto* pointer = static_cast<void*>(head->metadata.offset);

View File

@ -32,18 +32,21 @@ blt::gp::operation_t add([](float a, float b) {
});
blt::gp::operation_t sub([](float a, float b) {
BLT_TRACE("a: %f - b: %f = %f", a, b, a - b);
return 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; });
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([]() {
return b == 0 ? 0.0f : a / b;
});
auto lit = blt::gp::operation_t([]() {
//static std::uniform_real_distribution<float> dist(-32000, 32000);
// static std::uniform_real_distribution<float> dist(0.0f, 10.0f);
return program.get_random().get_float(0.0f, 10.0f);
});
}).set_ephemeral();
/**
* This is a test using a type with blt::gp
@ -53,18 +56,13 @@ int main()
type_system.register_type<float>();
blt::gp::operator_builder 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(silly.build());
program.set_operations(silly.build(add, sub, mul, pro_div, lit));
blt::gp::grow_generator_t grow;
auto tree = grow.generate(blt::gp::generator_arguments{program, type_system.get_type<float>().id(), 3, 7});
auto value = tree.get_evaluation_value<float>(nullptr);
auto value = tree.get_evaluation_value<float>(nullptr, program.get_eval_func());
BLT_TRACE(value);

View File

@ -72,13 +72,13 @@ blt::gp::operation_t basic_sub([](float a, float b, bool choice) {
}
}, "sub");
blt::gp::operation_t basic_lit_f([]() {
auto basic_lit_f= blt::gp::operation_t([]() {
return b_rand.choice() ? 5.0f : 10.0f;
});
}).set_ephemeral();
blt::gp::operation_t basic_lit_b([]() {
auto basic_lit_b = blt::gp::operation_t([]() {
return false;
});
}).set_ephemeral();
void basic_test()
{
@ -86,18 +86,14 @@ void basic_test()
blt::gp::operator_builder<context> builder{type_system};
builder.add_operator(basic_sub);
builder.add_operator(basic_lit_f, true);
builder.add_operator(basic_lit_b, true);
program.set_operations(builder.build());
program.set_operations(builder.build(basic_sub, basic_lit_f, basic_lit_b));
blt::gp::grow_generator_t gen;
blt::gp::generator_arguments args{program, type_system.get_type<float>().id(), 1, 1};
auto tree = gen.generate(args);
context ctx{&program};
auto result = tree.get_evaluation_value<float>(&ctx);
auto result = tree.get_evaluation_value<float>(&ctx, program.get_eval_func());
BLT_TRACE(result);
BLT_ASSERT(result == -5.0f || result == 5.0f || result == 0.0f);
tree.print(program, std::cout, true, true);

View File

@ -302,7 +302,7 @@ void test_basic()
stack.push(50.0f);
stack.push(10.0f);
BLT_TRACE_STREAM << stack.size() << "\n";
basic_2.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
basic_2.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
BLT_TRACE_STREAM << stack.size() << "\n";
auto val = stack.pop<float>();
RUN_TEST(val != 60.000000f, stack, "Basic 2 Test Passed", "Basic 2 Test Failed. Unexpected value produced '%lf'", val);
@ -318,7 +318,7 @@ void test_basic()
auto size = stack.size();
BLT_TRACE_STREAM << size << "\n";
//BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
basic_2.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
basic_2.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
BLT_TRACE_STREAM << stack.size() << "\n";
auto val = stack.pop<float>();
stack.pop<std::array<blt::u8, 4096 - sizeof(float)>>();
@ -339,7 +339,7 @@ void test_mixed()
stack.push(false);
BLT_TRACE_STREAM << stack.size() << "\n";
basic_mixed_4.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
basic_mixed_4.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
BLT_TRACE_STREAM << stack.size() << "\n";
auto val = stack.pop<float>();
RUN_TEST(val != 50.000000f, stack, "Mixed 4 Test Passed", "Mixed 4 Test Failed. Unexpected value produced '%lf'", val);
@ -357,7 +357,7 @@ void test_mixed()
auto size = stack.size();
BLT_TRACE_STREAM << size << "\n";
// BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
basic_mixed_4.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
basic_mixed_4.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
BLT_TRACE_STREAM << stack.size() << "\n";
auto val = stack.pop<float>();
stack.pop<std::array<blt::u8, 4096 - sizeof(float)>>();
@ -377,7 +377,7 @@ void test_large_256()
stack.push(69.420f);
BLT_TRACE_STREAM << stack.size() << "\n";
large_256_basic_3.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
large_256_basic_3.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
BLT_TRACE_STREAM << stack.size() << "\n";
auto val = stack.pop<large_256>();
RUN_TEST(!compare(val, base_256), stack, "Large 256 3 Test Passed", "Large 256 3 Test Failed. Unexpected value produced '%lf'", val);
@ -394,7 +394,7 @@ void test_large_256()
auto size = stack.size();
BLT_TRACE_STREAM << size << "\n";
// BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
large_256_basic_3.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
large_256_basic_3.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
BLT_TRACE_STREAM << stack.size() << "\n";
auto val = stack.pop<large_256>();
stack.pop<std::array<blt::u8, 4096 - sizeof(large_256)>>();
@ -413,7 +413,7 @@ void test_large_4096()
stack.push(33.0f);
stack.push(true);
BLT_TRACE_STREAM << stack.size() << "\n";
large_4096_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
large_4096_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
BLT_TRACE_STREAM << stack.size() << "\n";
auto val = stack.pop<large_4096>();
RUN_TEST(!compare(val, base_4096), stack, "Large 4096 3 Test Passed", "Large 4096 3 Test Failed. Unexpected value produced '%lf'", val);
@ -429,7 +429,7 @@ void test_large_4096()
auto size = stack.size();
BLT_TRACE_STREAM << size << "\n";
// BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
large_4096_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
large_4096_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
BLT_TRACE_STREAM << stack.size() << "\n";
auto val = stack.pop<large_4096>();
RUN_TEST(!compare(val, base_4096), stack, "Large 4096 3 Boundary Test Passed", "Large 4096 3 Test Failed. Unexpected value produced '%lf'", val);
@ -447,7 +447,7 @@ void test_large_18290()
stack.push(-2543.0f);
stack.push(true);
BLT_TRACE_STREAM << stack.size() << "\n";
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
BLT_TRACE_STREAM << stack.size() << "\n";
auto val = stack.pop<large_18290>();
RUN_TEST(!compare(val, base_18290), stack, "Large 18290 3 Test Passed", "Large 4096 3 Test Failed. Unexpected value produced '%lf'", val);
@ -464,7 +464,7 @@ void test_large_18290()
auto size = stack.size();
BLT_TRACE_STREAM << size << "\n";
// BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
BLT_TRACE_STREAM << stack.size() << "\n";
auto val = stack.pop<large_18290>();
stack.pop<std::array<blt::u8, 20480 - 18290 - 32>>();
@ -480,12 +480,12 @@ void test_large_18290()
stack.push(true);
auto size = stack.size();
BLT_TRACE_STREAM << size << "\n";
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
BLT_TRACE_STREAM << stack.size() << "\n";
stack.push(-2543.0f);
stack.push(true);
BLT_TRACE_STREAM << stack.size() << "\n";
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
BLT_TRACE_STREAM << stack.size() << "\n";
auto val = stack.pop<large_18290>();
RUN_TEST(!compare(val, base_18290), stack, "Large 18290 3 Boundary Test Passed", "Large 4096 3 Test Failed. Unexpected value produced '%lf'", val);