This commit is contained in:
2025-01-05 12:51:17 +00:00
parent 2daee71548
commit 595259b2cc
10 changed files with 106 additions and 105 deletions

View File

@@ -45,9 +45,9 @@ std::vector<uint64> get_reprs_input(int units_required) {
uint64 bit_repr = 0;
int i = 0;
bool good_repr = true;
for (std::reverse_iterator it = input.rbegin(); it < input.rend(); it++, i++) {
for (auto it = input.rbegin(); it < input.rend(); it++, i++) {
if (*it == '1') {
bit_repr |= 1 << i;
bit_repr |= 1ull << i;
total_units++;
} else if (*it != '0' || i >= 64) {
std::cout << "Input invalid. Enter a binary string only with max 64 bits." << '\n';
@@ -73,7 +73,7 @@ struct Solver {
uint64 STD_SOMA[] = { 23ul, 30ul, 15ul, 1043ul, 24594ul, 12306ul, 11ul };
void backtrack_solve_iter(std::vector<uint64> *polycube_input, std::vector<int> *offsets) {
int num_inputs = offsets->size() - 1;
size_t num_inputs = offsets->size() - 1;
std::vector<int> solns = std::vector<int>();
@@ -124,10 +124,10 @@ void backtrack_solve(Solver *solver, uint64 working_solution = 0, size_t curr_pi
list<uint64> *input = solver->input;
list<size_t> *offsets = solver->offsets;
std::vector<SomaSolution> *solutions = solver->solutions;
int start = offsets->data[curr_piece];
int end = offsets->data[curr_piece + 1];
size_t start = offsets->data[curr_piece];
size_t end = offsets->data[curr_piece + 1];
size_t num_pieces = offsets->length - 1;
for (int i = start; i < end; i++) {
for (size_t i = start; i < end; i++) {
bool successful_fuse = !collides(working_solution, input->data[i]);
if (successful_fuse) {
uint64 new_working_solution = working_solution | input->data[i];
@@ -206,25 +206,29 @@ std::vector<SomaSolution> solve(uint64 *reprs_in, uint32 reprs_in_count, int dim
list<uint64> polycubes = PushList(arena, uint64, 0);
Space model_space = {
Space empty_voxel_space = {
{},
dims[0],
dims[1],
dims[2],
};
appendList(&offsets, 0ul);
Space space = model_space;
space.space = reprs_in[0];
cullEmptySpace(&space);
list<uint64> positions = getAllPositionsInPrism(arena, &space, dims);
polycubes.length += positions.length;
polycubes.head += positions.head;
memcpy(polycubes.data, positions.data, positions.length / sizeof(uint64));
appendList(&offsets, (size_t)0);
for (int i = 1; i < reprs_in_count; i++) {
list<uint64> positions = {};
{
Space space = empty_voxel_space;
space.space = reprs_in[0];
cullEmptySpace(&space);
positions = getAllPositionsInPrism(arena, &space, dims);
polycubes.length += positions.length;
polycubes.head += positions.head;
memcpy(polycubes.data, positions.data, positions.length / sizeof(uint64));
};
for (size_t i = 1; i < reprs_in_count; i++) {
appendList(&offsets, polycubes.length);
Space space = model_space;
Space space = empty_voxel_space;
space.space = reprs_in[i];
cullEmptySpace(&space);
list<uint64> perms = getAllPermutationsInPrism(permsArena, &space, dims);