2024-06-23 14:13:50 -04:00
|
|
|
/*
|
|
|
|
* <Short Description>
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <blt/gp/program.h>
|
2024-06-26 20:24:58 -04:00
|
|
|
#include <blt/gp/generators.h>
|
|
|
|
#include <blt/gp/tree.h>
|
|
|
|
#include <blt/std/logging.h>
|
|
|
|
|
2024-06-23 14:13:50 -04:00
|
|
|
|
|
|
|
static constexpr long SEED = 41912;
|
|
|
|
|
2024-06-29 10:47:27 -04:00
|
|
|
blt::gp::type_provider type_system;
|
2024-07-11 21:14:23 -04:00
|
|
|
blt::gp::gp_program program(type_system, SEED); // NOLINT
|
2024-06-23 14:13:50 -04:00
|
|
|
|
2024-06-27 01:35:29 -04:00
|
|
|
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);
|
2024-08-21 01:40:21 -04:00
|
|
|
return a - b;
|
|
|
|
});
|
2024-06-27 01:35:29 -04:00
|
|
|
blt::gp::operation_t mul([](float a, float b) {
|
|
|
|
BLT_TRACE("a: %f * b: %f = %f", a, b, a * b);
|
2024-08-21 01:40:21 -04:00
|
|
|
return a * b;
|
|
|
|
});
|
2024-06-27 01:35:29 -04:00
|
|
|
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));
|
2024-08-21 01:40:21 -04:00
|
|
|
return b == 0 ? 0.0f : a / b;
|
|
|
|
});
|
|
|
|
auto lit = blt::gp::operation_t([]() {
|
2024-06-26 20:24:58 -04:00
|
|
|
//static std::uniform_real_distribution<float> dist(-32000, 32000);
|
2024-07-09 21:57:18 -04:00
|
|
|
// static std::uniform_real_distribution<float> dist(0.0f, 10.0f);
|
|
|
|
return program.get_random().get_float(0.0f, 10.0f);
|
2024-08-21 01:40:21 -04:00
|
|
|
}).set_ephemeral();
|
2024-06-23 14:13:50 -04:00
|
|
|
|
2024-06-26 20:55:37 -04:00
|
|
|
/**
|
|
|
|
* This is a test using a type with blt::gp
|
|
|
|
*/
|
2024-06-24 21:56:51 -04:00
|
|
|
int main()
|
2024-06-23 14:13:50 -04:00
|
|
|
{
|
|
|
|
type_system.register_type<float>();
|
|
|
|
|
2024-06-29 10:47:27 -04:00
|
|
|
blt::gp::operator_builder silly{type_system};
|
2024-06-24 04:01:29 -04:00
|
|
|
|
2024-08-21 01:40:21 -04:00
|
|
|
program.set_operations(silly.build(add, sub, mul, pro_div, lit));
|
2024-06-23 22:01:48 -04:00
|
|
|
|
2024-06-26 20:24:58 -04:00
|
|
|
blt::gp::grow_generator_t grow;
|
|
|
|
auto tree = grow.generate(blt::gp::generator_arguments{program, type_system.get_type<float>().id(), 3, 7});
|
|
|
|
|
2024-08-21 20:40:42 -04:00
|
|
|
auto value = tree.get_evaluation_value<float>(nullptr);
|
2024-06-26 20:24:58 -04:00
|
|
|
|
|
|
|
BLT_TRACE(value);
|
|
|
|
|
2024-06-23 22:01:48 -04:00
|
|
|
return 0;
|
2024-06-23 14:13:50 -04:00
|
|
|
}
|