Merge branch 'dev'

main
Brett 2024-08-31 22:44:44 -04:00
commit 0da04237c7
6 changed files with 28 additions and 28 deletions

View File

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

View File

@ -137,7 +137,7 @@ namespace blt::gp
template<class U, class... Args>
void construct(U* p, Args&& ... args)
{
new(p) T(args...);
new(p) T(std::forward<Args>(args)...);
}
template<class U>

View File

@ -70,7 +70,7 @@ namespace blt::gp
struct operator_info
{
// types of the arguments
std::vector<type_id> argument_types;
tracked_vector<type_id> argument_types;
// return type of this operator
type_id return_type;
// number of arguments for this operator
@ -82,15 +82,15 @@ namespace blt::gp
struct program_operator_storage_t
{
// indexed from return TYPE ID, returns index of operator
blt::expanding_buffer<std::vector<operator_id>> terminals;
blt::expanding_buffer<std::vector<operator_id>> non_terminals;
blt::expanding_buffer<std::vector<std::pair<operator_id, blt::size_t>>> operators_ordered_terminals;
blt::expanding_buffer<tracked_vector<operator_id>> terminals;
blt::expanding_buffer<tracked_vector<operator_id>> non_terminals;
blt::expanding_buffer<tracked_vector<std::pair<operator_id, blt::size_t>>> operators_ordered_terminals;
// indexed from OPERATOR ID (operator number)
blt::hashset_t<operator_id> ephemeral_leaf_operators;
std::vector<operator_info> operators;
std::vector<detail::print_func_t> print_funcs;
std::vector<detail::destroy_func_t> destroy_funcs;
std::vector<std::optional<std::string_view>> names;
tracked_vector<operator_info> operators;
tracked_vector<detail::print_func_t> print_funcs;
tracked_vector<detail::destroy_func_t> destroy_funcs;
tracked_vector<std::optional<std::string_view>> names;
detail::eval_func_t eval_func;
@ -110,7 +110,7 @@ namespace blt::gp
template<typename... Operators>
program_operator_storage_t& build(Operators& ... operators)
{
std::vector<blt::size_t> sizes;
tracked_vector<blt::size_t> sizes;
(sizes.push_back(add_operator(operators)), ...);
blt::size_t largest = 0;
for (auto v : sizes)
@ -153,7 +153,7 @@ namespace blt::gp
if (op_r.second.empty())
continue;
auto return_type = op_r.first;
std::vector<std::pair<operator_id, blt::size_t>> ordered_terminals;
tracked_vector<std::pair<operator_id, blt::size_t>> ordered_terminals;
for (const auto& op : op_r.second)
{
// count number of terminals
@ -675,12 +675,12 @@ namespace blt::gp
return storage.names[id];
}
[[nodiscard]] inline std::vector<operator_id>& get_type_terminals(type_id id)
[[nodiscard]] inline tracked_vector<operator_id>& get_type_terminals(type_id id)
{
return storage.terminals[id];
}
[[nodiscard]] inline std::vector<operator_id>& get_type_non_terminals(type_id id)
[[nodiscard]] inline tracked_vector<operator_id>& get_type_non_terminals(type_id id)
{
return storage.non_terminals[id];
}
@ -715,7 +715,7 @@ namespace blt::gp
{
std::array<blt::size_t, size> arr;
std::vector<std::pair<blt::size_t, double>> values;
tracked_vector<std::pair<blt::size_t, double>> values;
values.reserve(current_pop.get_individuals().size());
for (const auto& ind : blt::enumerate(current_pop.get_individuals()))
@ -789,11 +789,11 @@ namespace blt::gp
std::atomic_bool fitness_should_exit = false;
population_stats current_stats{};
std::vector<population_stats> statistic_history;
tracked_vector<population_stats> statistic_history;
struct concurrency_storage
{
std::vector<std::unique_ptr<std::thread>> threads;
tracked_vector<std::unique_ptr<std::thread>> threads;
std::mutex thread_function_control{};
std::condition_variable thread_function_condition{};

View File

@ -156,7 +156,7 @@ namespace blt::gp
bool check(gp_program& program, void* context) const;
void find_child_extends(gp_program& program, std::vector<child_t>& vec, blt::size_t parent_node, blt::size_t argc) const;
void find_child_extends(gp_program& program, tracked_vector<child_t>& vec, blt::size_t parent_node, blt::size_t argc) const;
blt::ptrdiff_t find_endpoint(blt::gp::gp_program& program, blt::ptrdiff_t start) const;
@ -251,7 +251,7 @@ namespace blt::gp
std::atomic<double> average_fitness = 0;
std::atomic<double> best_fitness = 0;
std::atomic<double> worst_fitness = 1;
std::vector<double> normalized_fitness{};
tracked_vector<double> normalized_fitness{};
void clear()
{

View File

@ -85,8 +85,8 @@ namespace blt::gp
stack_allocator& c2_stack = c2.get_values();
// we have to make a copy because we will modify the underlying storage.
static thread_local std::vector<op_container_t> c1_operators;
static thread_local std::vector<op_container_t> c2_operators;
static thread_local tracked_vector<op_container_t> c1_operators;
static thread_local tracked_vector<op_container_t> c2_operators;
c1_operators.clear();
c2_operators.clear();
@ -359,7 +359,7 @@ namespace blt::gp
auto& replacement_func_info = program.get_operator_info(random_replacement);
// cache memory used for offset data.
thread_local static std::vector<tree_t::child_t> children_data;
thread_local static tracked_vector<tree_t::child_t> children_data;
children_data.clear();
c.find_child_extends(program, children_data, c_node, current_func_info.argument_types.size());
@ -586,7 +586,7 @@ namespace blt::gp
if (argument_index == -1ul)
continue;
static thread_local std::vector<tree_t::child_t> child_data;
static thread_local tracked_vector<tree_t::child_t> child_data;
child_data.clear();
c.find_child_extends(program, child_data, c_node, info.argument_types.size());
@ -670,7 +670,7 @@ namespace blt::gp
to = pt;
}
static thread_local std::vector<tree_t::child_t> child_data;
static thread_local tracked_vector<tree_t::child_t> child_data;
child_data.clear();
c.find_child_extends(program, child_data, c_node, info.argument_types.size());
@ -700,7 +700,7 @@ namespace blt::gp
vals.copy_from(from_ptr, from_bytes);
vals.copy_from(after_ptr, after_to_bytes);
static thread_local std::vector<op_container_t> op_copy;
static thread_local tracked_vector<op_container_t> op_copy;
op_copy.clear();
op_copy.insert(op_copy.begin(), ops.begin() + from_child.start, ops.begin() + from_child.end);

View File

@ -145,8 +145,8 @@ namespace blt::gp
blt::size_t depth = 0;
auto operations_stack = operations;
std::vector<blt::size_t> values_process;
std::vector<blt::size_t> value_stack;
tracked_vector<blt::size_t> values_process;
tracked_vector<blt::size_t> value_stack;
for (const auto& op : operations_stack)
{
@ -275,7 +275,7 @@ namespace blt::gp
return true;
}
void tree_t::find_child_extends(gp_program& program, std::vector<child_t>& vec, blt::size_t parent_node, blt::size_t argc) const
void tree_t::find_child_extends(gp_program& program, tracked_vector<child_t>& vec, blt::size_t parent_node, blt::size_t argc) const
{
while (vec.size() < argc)
{