fix bug mutation bug. on to the next problem
parent
f227d1fb1c
commit
5bc87be953
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.25)
|
||||
project(image-gp-6 VERSION 0.0.31)
|
||||
project(image-gp-6 VERSION 0.0.32)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 8ee64b5666cf9d1dc308ff629bd4c7ef14b0c96a
|
||||
Subproject commit 877b380a00740a05578298771fd01dfdeb7e9b71
|
|
@ -90,7 +90,7 @@ namespace blt::gp
|
|||
const auto& node = ops[c_node];
|
||||
if (!node.is_value)
|
||||
{
|
||||
BLT_TRACE("Running adjust on function");
|
||||
// BLT_TRACE("Running adjust on function");
|
||||
auto& current_func_info = program.get_operator_info(ops[c_node].id);
|
||||
operator_id random_replacement = program.get_random().select(
|
||||
program.get_type_non_terminals(current_func_info.return_type.id));
|
||||
|
@ -113,7 +113,7 @@ namespace blt::gp
|
|||
child_t prev{};
|
||||
if (current_point == 0)
|
||||
{
|
||||
BLT_TRACE("Child %ld: %s", current_point, std::string(*program.get_name(ops[c_node + 1].id)).c_str());
|
||||
// BLT_TRACE("Child %ld: %s", current_point, std::string(*program.get_name(ops[c_node + 1].id)).c_str());
|
||||
// first child.
|
||||
prev = {static_cast<blt::ptrdiff_t>(c_node + 1),
|
||||
c.find_endpoint(program, static_cast<blt::ptrdiff_t>(c_node + 1))};
|
||||
|
@ -121,23 +121,23 @@ namespace blt::gp
|
|||
continue;
|
||||
} else
|
||||
prev = children_data[current_point - 1];
|
||||
BLT_TRACE("Child %ld: %s", current_point, std::string(*program.get_name(ops[prev.end].id)).c_str());
|
||||
// BLT_TRACE("Child %ld: %s", current_point, std::string(*program.get_name(ops[prev.end].id)).c_str());
|
||||
child_t next = {prev.end, c.find_endpoint(program, prev.end)};
|
||||
children_data.push_back(next);
|
||||
}
|
||||
|
||||
BLT_TRACE("%ld vs %ld, replacement will be size %ld", children_data.size(), current_func_info.argument_types.size(),
|
||||
replacement_func_info.argument_types.size());
|
||||
// BLT_TRACE("%ld vs %ld, replacement will be size %ld", children_data.size(), current_func_info.argument_types.size(),
|
||||
// replacement_func_info.argument_types.size());
|
||||
|
||||
for (const auto& [index, val] : blt::enumerate(replacement_func_info.argument_types))
|
||||
{
|
||||
// need to generate replacement.
|
||||
if (index < current_func_info.argument_types.size() && val.id != current_func_info.argument_types[index].id)
|
||||
{
|
||||
BLT_TRACE_STREAM << "Replacing tree argument (index: " << index << " proper: " << (children_data.size() - 1 - index)
|
||||
<< ") from type "
|
||||
<< program.get_typesystem().get_type(current_func_info.argument_types[index]).name() << " to type "
|
||||
<< program.get_typesystem().get_type(val).name() << "\n";
|
||||
// BLT_TRACE_STREAM << "Replacing tree argument (index: " << index << " proper: " << (children_data.size() - 1 - index)
|
||||
// << ") from type "
|
||||
// << program.get_typesystem().get_type(current_func_info.argument_types[index]).name() << " to type "
|
||||
// << program.get_typesystem().get_type(val).name() << "\n";
|
||||
// TODO: new config?
|
||||
auto tree = config.generator.get().generate(
|
||||
{program, val.id, config.replacement_min_depth, config.replacement_max_depth});
|
||||
|
@ -211,20 +211,23 @@ namespace blt::gp
|
|||
}
|
||||
}
|
||||
|
||||
BLT_DEBUG("Current:");
|
||||
for (const auto& [index, val] : blt::enumerate(current_func_info.argument_types))
|
||||
BLT_DEBUG("%ld: %s", index, std::string(program.get_typesystem().get_type(val).name()).c_str());
|
||||
|
||||
BLT_DEBUG("Replacement:");
|
||||
for (const auto& [index, val] : blt::enumerate(replacement_func_info.argument_types))
|
||||
BLT_DEBUG("%ld: %s", index, std::string(program.get_typesystem().get_type(val).name()).c_str());
|
||||
// BLT_DEBUG("Current:");
|
||||
// for (const auto& [index, val] : blt::enumerate(current_func_info.argument_types))
|
||||
// BLT_DEBUG("%ld: %s", index, std::string(program.get_typesystem().get_type(val).name()).c_str());
|
||||
//
|
||||
// BLT_DEBUG("Replacement:");
|
||||
// for (const auto& [index, val] : blt::enumerate(replacement_func_info.argument_types))
|
||||
// BLT_DEBUG("%ld: %s", index, std::string(program.get_typesystem().get_type(val).name()).c_str());
|
||||
|
||||
if (current_func_info.argc.argc > replacement_func_info.argc.argc)
|
||||
{
|
||||
BLT_TRACE("TOO MANY ARGS");
|
||||
// BLT_TRACE("TOO MANY ARGS");
|
||||
// too many args
|
||||
blt::size_t end_index = children_data[replacement_func_info.argc.argc - 1].end;
|
||||
blt::size_t start_index = children_data.front().start;
|
||||
// BLT_TRACE("Removing %s starting index 0 to %ld",
|
||||
// std::string(*program.get_name(ops[children_data.front().start].id)).c_str(), (current_func_info.argc.argc -
|
||||
// replacement_func_info.argc.argc) - 1);
|
||||
blt::size_t end_index = children_data[(current_func_info.argc.argc - replacement_func_info.argc.argc) - 1].end;
|
||||
blt::size_t start_index = children_data.begin()->start;
|
||||
blt::size_t total_bytes_for = 0;
|
||||
blt::size_t total_bytes_after = 0;
|
||||
for (blt::size_t i = start_index; i < end_index; i++)
|
||||
|
@ -244,12 +247,12 @@ namespace blt::gp
|
|||
ops.erase(ops.begin() + static_cast<blt::ptrdiff_t>(start_index), ops.begin() + static_cast<blt::ptrdiff_t>(end_index));
|
||||
} else if (current_func_info.argc.argc == replacement_func_info.argc.argc)
|
||||
{
|
||||
BLT_TRACE("JUST ENOUGH ARGS");
|
||||
// BLT_TRACE("JUST ENOUGH ARGS");
|
||||
// exactly enough args
|
||||
// return types should have been replaced if needed. this part should do nothing?
|
||||
} else
|
||||
{
|
||||
BLT_TRACE("NOT ENOUGH ARGS");
|
||||
// BLT_TRACE("NOT ENOUGH ARGS");
|
||||
// not enough args
|
||||
blt::size_t total_bytes_after = 0;
|
||||
blt::size_t start_index = c_node + 1;
|
||||
|
@ -260,7 +263,7 @@ namespace blt::gp
|
|||
if (ops[i].is_value)
|
||||
total_bytes_after += stack_allocator::aligned_size(ops[i].type_size);
|
||||
}
|
||||
BLT_TRACE("Total bytes after: %ld", total_bytes_after);
|
||||
// BLT_TRACE("Total bytes after: %ld", total_bytes_after);
|
||||
auto* data = get_thread_pointer_for_size<struct mutation_func>(total_bytes_after);
|
||||
vals.copy_to(data, total_bytes_after);
|
||||
vals.pop_bytes(static_cast<blt::ptrdiff_t>(total_bytes_after));
|
||||
|
@ -268,8 +271,8 @@ namespace blt::gp
|
|||
for (blt::ptrdiff_t i = static_cast<blt::ptrdiff_t>(replacement_func_info.argc.argc) - 1;
|
||||
i >= current_func_info.argc.argc; i--)
|
||||
{
|
||||
BLT_TRACE("Generating argument %ld of type %s", i,
|
||||
std::string(program.get_typesystem().get_type(replacement_func_info.argument_types[i].id).name()).c_str());
|
||||
// BLT_TRACE("Generating argument %ld of type %s", i,
|
||||
// std::string(program.get_typesystem().get_type(replacement_func_info.argument_types[i].id).name()).c_str());
|
||||
auto tree = config.generator.get().generate(
|
||||
{program, replacement_func_info.argument_types[i].id, config.replacement_min_depth,
|
||||
config.replacement_max_depth});
|
||||
|
@ -280,9 +283,9 @@ namespace blt::gp
|
|||
total_bytes_for += stack_allocator::aligned_size(op.type_size);
|
||||
}
|
||||
vals.copy_from(tree.get_values(), total_bytes_for);
|
||||
BLT_TRACE("%ld vs %ld", start_index, ops.size());
|
||||
if (start_index < ops.size())
|
||||
BLT_TRACE("Argument %ld insert before this: %s", i, std::string(*program.get_name(ops[start_index].id)).c_str());
|
||||
// BLT_TRACE("%ld vs %ld", start_index, ops.size());
|
||||
// if (start_index < ops.size())
|
||||
// BLT_TRACE("Argument %ld insert before this: %s", i, std::string(*program.get_name(ops[start_index].id)).c_str());
|
||||
ops.insert(ops.begin() + static_cast<blt::ptrdiff_t>(start_index), tree.get_operations().begin(),
|
||||
tree.get_operations().end());
|
||||
start_index += tree.get_operations().size();
|
||||
|
@ -342,45 +345,14 @@ namespace blt::gp
|
|||
}
|
||||
}
|
||||
#if BLT_DEBUG_LEVEL >= 2
|
||||
blt::size_t bytes_expected = 0;
|
||||
auto bytes_size = vals.size().total_used_bytes;
|
||||
|
||||
for (const auto& op : c.get_operations())
|
||||
{
|
||||
if (op.is_value)
|
||||
bytes_expected += stack_allocator::aligned_size(op.type_size);
|
||||
}
|
||||
|
||||
if (bytes_expected != bytes_size)
|
||||
{
|
||||
BLT_WARN_STREAM << "Stack state: " << vals.size() << "\n";
|
||||
BLT_WARN("Child tree bytes %ld vs expected %ld, difference: %ld", bytes_size, bytes_expected,
|
||||
static_cast<blt::ptrdiff_t>(bytes_expected) - static_cast<blt::ptrdiff_t>(bytes_size));
|
||||
std::cout << "Parent: " << std::endl;
|
||||
c_copy.print(program, std::cout, false, true);
|
||||
std::cout << "Child:" << std::endl;
|
||||
c.print(program, std::cout, false, true);
|
||||
std::cout << std::endl;
|
||||
c.print(program, std::cout, true, true);
|
||||
std::cout << std::endl;
|
||||
BLT_ABORT("Amount of bytes in stack doesn't match the number of bytes expected for the operations");
|
||||
}
|
||||
auto copy = c;
|
||||
try
|
||||
{
|
||||
auto result = copy.evaluate(nullptr);
|
||||
blt::black_box(result);
|
||||
} catch (const std::exception& e)
|
||||
if (!c.check(program, nullptr))
|
||||
{
|
||||
std::cout << "Parent: " << std::endl;
|
||||
c_copy.print(program, std::cout, false, true);
|
||||
std::cout << "Child:" << std::endl;
|
||||
c.print(program, std::cout, false, true);
|
||||
std::cout << std::endl;
|
||||
std::cout << "Child Values:" << std::endl;
|
||||
c.print(program, std::cout, true, true);
|
||||
std::cout << std::endl;
|
||||
BLT_WARN(e.what());
|
||||
throw e;
|
||||
BLT_ABORT("Tree Check Failed.");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -402,45 +374,14 @@ namespace blt::gp
|
|||
}
|
||||
|
||||
#if BLT_DEBUG_LEVEL >= 2
|
||||
blt::size_t bytes_expected = 0;
|
||||
auto bytes_size = vals.size().total_used_bytes;
|
||||
|
||||
for (const auto& op : c.get_operations())
|
||||
{
|
||||
if (op.is_value)
|
||||
bytes_expected += stack_allocator::aligned_size(op.type_size);
|
||||
}
|
||||
|
||||
if (bytes_expected != bytes_size)
|
||||
{
|
||||
BLT_WARN_STREAM << "Stack state: " << vals.size() << "\n";
|
||||
BLT_WARN("Child tree bytes %ld vs expected %ld, difference: %ld", bytes_size, bytes_expected,
|
||||
static_cast<blt::ptrdiff_t>(bytes_expected) - static_cast<blt::ptrdiff_t>(bytes_size));
|
||||
std::cout << "Parent: " << std::endl;
|
||||
p.print(program, std::cout, false, true);
|
||||
std::cout << "Child:" << std::endl;
|
||||
c.print(program, std::cout, false, true);
|
||||
std::cout << std::endl;
|
||||
c.print(program, std::cout, true, true);
|
||||
std::cout << std::endl;
|
||||
BLT_ABORT("Amount of bytes in stack doesn't match the number of bytes expected for the operations");
|
||||
}
|
||||
auto copy = c;
|
||||
try
|
||||
{
|
||||
auto result = copy.evaluate(nullptr);
|
||||
blt::black_box(result);
|
||||
} catch (const std::exception& e)
|
||||
if (!c.check(program, nullptr))
|
||||
{
|
||||
std::cout << "Parent: " << std::endl;
|
||||
p.print(program, std::cout, false, true);
|
||||
std::cout << "Child:" << std::endl;
|
||||
c.print(program, std::cout, false, true);
|
||||
std::cout << std::endl;
|
||||
std::cout << "Child Values:" << std::endl;
|
||||
c.print(program, std::cout, true, true);
|
||||
std::cout << std::endl;
|
||||
BLT_WARN(e.what());
|
||||
throw e;
|
||||
BLT_ABORT("Tree Check Failed.");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue