crossover

thread
Brett 2024-06-30 03:20:56 -04:00
parent 1fa12da477
commit d3124f8516
8 changed files with 42 additions and 30 deletions

View File

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

View File

@ -53,6 +53,11 @@ namespace blt::gp
blt::size_t argc_context = 0;
};
struct operator_info
{
};
struct operator_storage
{
// indexed from return TYPE ID, returns index of operator

View File

@ -21,11 +21,13 @@
#include <blt/std/types.h>
#include <blt/std/logging.h>
#include <blt/gp/fwdecl.h>
#include <utility>
#include <stdexcept>
#include <cstdlib>
#include <memory>
#include <type_traits>
#include <cstring>
namespace blt::gp
{
@ -52,7 +54,8 @@ namespace blt::gp
template<typename T>
T pop()
{
static_assert(std::is_trivially_copyable_v<std::remove_reference_t<T>> && "Type must be bitwise copyable!");
using NO_REF_T = std::remove_reference_t<T>;
static_assert(std::is_trivially_copyable_v<NO_REF_T> && "Type must be bitwise copyable!");
constexpr static auto TYPE_SIZE = aligned_size<T>();
if (head == nullptr)
throw std::runtime_error("Silly boi the stack is empty!");
@ -116,7 +119,8 @@ namespace blt::gp
free(old);
if (diff == 0)
break;
} else {
} else
{
// otherwise update the offset pointer
head->metadata.offset -= bytes;
break;
@ -185,8 +189,7 @@ namespace blt::gp
stack_allocator& operator=(stack_allocator&& move) noexcept
{
head = move.head;
move.head = nullptr;
move.head = std::exchange(head, move.head);
return *this;
}

View File

@ -22,6 +22,7 @@
#include <blt/std/utility.h>
#include <blt/gp/fwdecl.h>
#include <blt/gp/tree.h>
#include <blt/std/expected.h>
namespace blt::gp
{
@ -29,8 +30,25 @@ namespace blt::gp
class crossover_t
{
public:
BLT_ATTRIB_CONST virtual std::pair<tree_t, tree_t> apply(gp_program& program, const tree_t& p1, const tree_t& p2);
virtual void apply_in_place(gp_program& program, tree_t& p1, tree_t& p2);
enum class error_t
{
NO_VALID_TYPE
};
struct result_t
{
tree_t child1;
tree_t child2;
};
/**
* child1 and child2 are copies of the parents, the result of selecting a crossover point and performing standard subtree crossover.
* the parents are not modified during this process
* @param program reference to the global program container responsible for managing these trees
* @param p1 reference to the first parent
* @param p2 reference to the second parent
* @return expected pair of child otherwise returns error enum
*/
virtual blt::expected<result_t, error_t> apply(gp_program& program, const tree_t& p1, const tree_t& p2); // NOLINT
};
}

View File

@ -57,7 +57,6 @@ namespace blt::gp
public:
[[nodiscard]] inline std::vector<op_container_t>& get_operations()
{
valid = false;
return operations;
}
@ -71,20 +70,6 @@ namespace blt::gp
return values;
}
void setDepth(blt::size_t d)
{
depth = d;
valid = true;
}
blt::size_t getDepth()
{
if (valid)
return depth;
valid = true;
return 0;
}
evaluation_context evaluate(void* context);
/**
@ -116,7 +101,6 @@ namespace blt::gp
}
private:
bool valid = false;
std::vector<op_container_t> operations;
blt::gp::stack_allocator values;
blt::size_t depth;

@ -1 +1 @@
Subproject commit cdb91d800781d2c2a8ad3b9a829ca6d52abaa6ea
Subproject commit f3451b57ab249fdcf5ccedd64cbd56b2a64e2de2

View File

@ -59,7 +59,6 @@ namespace blt::gp
{
auto top = tree_generator.top();
tree_generator.pop();
//BLT_INFO("%ld D: %ld (%ld left)", top.id, top.depth, tree_generator.size());
tree.get_operations().emplace_back(
args.program.get_operation(top.id),
@ -74,13 +73,9 @@ namespace blt::gp
}
for (const auto& child : args.program.get_argument_types(top.id))
{
std::forward<Func>(perChild)(args.program, tree_generator, child, top.depth + 1);
}
}
tree.setDepth(max_depth);
return tree;
}

View File

@ -19,5 +19,12 @@
namespace blt::gp
{
blt::expected<crossover_t::result_t, crossover_t::error_t> crossover_t::apply(gp_program& program, const tree_t& p1, const tree_t& p2) // NOLINT
{
result_t result{p1, p2};
return result;
}
}