2024-06-21 22:04:57 -04:00
|
|
|
#pragma once
|
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BLT_GP_GENERATORS_H
|
|
|
|
#define BLT_GP_GENERATORS_H
|
|
|
|
|
|
|
|
#include <blt/gp/fwdecl.h>
|
|
|
|
#include <blt/gp/tree.h>
|
|
|
|
|
|
|
|
namespace blt::gp
|
|
|
|
{
|
|
|
|
|
2024-06-25 22:21:41 -04:00
|
|
|
struct generator_arguments
|
|
|
|
{
|
|
|
|
gp_program& program;
|
|
|
|
type_id root_type;
|
|
|
|
blt::size_t min_depth;
|
|
|
|
blt::size_t max_depth;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct initializer_arguments
|
|
|
|
{
|
|
|
|
gp_program& program;
|
|
|
|
type_id root_type;
|
|
|
|
blt::size_t size;
|
|
|
|
blt::size_t min_depth;
|
|
|
|
blt::size_t max_depth;
|
|
|
|
|
|
|
|
[[nodiscard]] generator_arguments to_gen_args() const
|
|
|
|
{
|
|
|
|
return {program, root_type, min_depth, max_depth};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-06-21 22:04:57 -04:00
|
|
|
// base class for any kind of tree generator
|
|
|
|
class tree_generator_t
|
|
|
|
{
|
|
|
|
public:
|
2024-06-25 22:21:41 -04:00
|
|
|
virtual tree_t generate(const generator_arguments& args) = 0;
|
2024-06-21 22:04:57 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class grow_generator_t : public tree_generator_t
|
|
|
|
{
|
|
|
|
public:
|
2024-06-25 22:21:41 -04:00
|
|
|
tree_t generate(const generator_arguments& args) final;
|
2024-06-21 22:04:57 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class full_generator_t : public tree_generator_t
|
|
|
|
{
|
|
|
|
public:
|
2024-06-25 22:21:41 -04:00
|
|
|
tree_t generate(const generator_arguments& args) final;
|
2024-06-21 22:04:57 -04:00
|
|
|
};
|
|
|
|
|
2024-06-24 21:56:51 -04:00
|
|
|
class population_initializer_t
|
|
|
|
{
|
|
|
|
public:
|
2024-06-25 22:21:41 -04:00
|
|
|
virtual population_t generate(const initializer_arguments& args) = 0;
|
2024-06-24 21:56:51 -04:00
|
|
|
};
|
|
|
|
|
2024-06-25 22:21:41 -04:00
|
|
|
class grow_initializer_t : public population_initializer_t
|
2024-06-24 21:56:51 -04:00
|
|
|
{
|
|
|
|
public:
|
2024-06-25 22:21:41 -04:00
|
|
|
population_t generate(const initializer_arguments& args) final;
|
|
|
|
|
|
|
|
private:
|
|
|
|
grow_generator_t grow;
|
2024-06-24 21:56:51 -04:00
|
|
|
};
|
|
|
|
|
2024-06-25 22:21:41 -04:00
|
|
|
class full_initializer_t : public population_initializer_t
|
2024-06-24 21:56:51 -04:00
|
|
|
{
|
|
|
|
public:
|
2024-06-25 22:21:41 -04:00
|
|
|
population_t generate(const initializer_arguments& args) final;
|
|
|
|
|
|
|
|
private:
|
|
|
|
full_generator_t full;
|
2024-06-24 21:56:51 -04:00
|
|
|
};
|
|
|
|
|
2024-06-25 22:21:41 -04:00
|
|
|
class half_half_initializer_t : public population_initializer_t
|
2024-06-24 21:56:51 -04:00
|
|
|
{
|
|
|
|
public:
|
2024-06-25 22:21:41 -04:00
|
|
|
population_t generate(const initializer_arguments& args) final;
|
|
|
|
|
|
|
|
private:
|
|
|
|
grow_generator_t grow;
|
|
|
|
full_generator_t full;
|
2024-06-24 21:56:51 -04:00
|
|
|
};
|
|
|
|
|
2024-06-25 22:21:41 -04:00
|
|
|
class ramped_half_initializer_t : public population_initializer_t
|
2024-06-24 21:56:51 -04:00
|
|
|
{
|
|
|
|
public:
|
2024-06-25 22:21:41 -04:00
|
|
|
population_t generate(const initializer_arguments& args) final;
|
|
|
|
|
|
|
|
private:
|
|
|
|
grow_generator_t grow;
|
|
|
|
full_generator_t full;
|
2024-06-24 21:56:51 -04:00
|
|
|
};
|
|
|
|
|
2024-06-21 22:04:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif //BLT_GP_GENERATORS_H
|