added tests, expanding solution algorithm
This commit is contained in:
43
main.cpp
43
main.cpp
@@ -1,4 +1,5 @@
|
||||
#include <bitset>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
@@ -57,7 +58,6 @@ auto backtrack_solve(std::vector<uint64_t> *polycube_input, std::vector<int> *of
|
||||
auto solns = 0;
|
||||
auto start = offsets->at(set);
|
||||
auto end = offsets->at(set + 1);
|
||||
std::cout << start << " " << end << "\n";
|
||||
for (int i = start; i < end; i++) {
|
||||
auto successful_fuse = !Voxel::collides(working_solution, polycube_input->at(i));
|
||||
if (successful_fuse) {
|
||||
@@ -72,6 +72,34 @@ auto backtrack_solve(std::vector<uint64_t> *polycube_input, std::vector<int> *of
|
||||
return solns;
|
||||
}
|
||||
|
||||
auto filter_unique(std::vector<std::vector<uint64_t>> *solutions, int dims[3]) -> std::vector<std::vector<uint64_t>> {
|
||||
if (solutions->size() == 0) {
|
||||
return std::vector<std::vector<uint64_t>>();
|
||||
}
|
||||
auto unique_solns = std::vector<std::vector<uint64_t>>();
|
||||
for (auto &solution : unique_solns) {
|
||||
auto foundMatch = false;
|
||||
auto soln_rotations = std::vector<std::vector<uint64_t>>();
|
||||
for (auto &piece : solution) {
|
||||
auto space = Voxel::Space{ .space=solution.at(0), .dims={ dims[0], dims[1], dims[2] } };
|
||||
auto unique_rots = Voxel::getUniqueRotations(&space);
|
||||
soln_rotations.insert(soln_rotations.end(), unique_rots.begin(), unique_rots.end());
|
||||
}
|
||||
for (auto &rotation : soln_rotations) {
|
||||
auto end = unique_solns.size();
|
||||
for (int i = 0; i < end; i++) {
|
||||
if (rotation == unique_solns[i]) {
|
||||
foundMatch = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!foundMatch) {
|
||||
unique_solns.push_back(solution);
|
||||
}
|
||||
}
|
||||
return unique_solns;
|
||||
}
|
||||
|
||||
auto get_dims_input(int dims[3]) -> void {
|
||||
std::cout << "Enter dimensions separated by newlines. (x*y*z must not exceed 64)\n";
|
||||
auto success = false;
|
||||
@@ -146,19 +174,19 @@ auto main() -> int {
|
||||
std::cout << "Great. Calculating solutions...\n";
|
||||
|
||||
auto offsets = std::vector<int>();
|
||||
auto polycubes = std::vector<Voxel::Space>();
|
||||
auto polycubes = std::vector<uint64_t>();
|
||||
polycubes.reserve(reprs.size() * 10);
|
||||
|
||||
auto model_space = Voxel::Space{
|
||||
.space={},
|
||||
.dims={dims[0], dims[1], dims[2]},
|
||||
};
|
||||
|
||||
|
||||
offsets.push_back(polycubes.size());
|
||||
auto space = model_space;
|
||||
space.space = reprs[0];
|
||||
Voxel::cullEmptySpace(&space);
|
||||
auto positions = Voxel::getUniqueRotations(&space);
|
||||
auto positions = Voxel::getAllPositionsInPrism(space.space, space.dims, dims);
|
||||
polycubes.insert(polycubes.end(), positions.begin(), positions.end());
|
||||
|
||||
for (int i = 1; i < reprs.size(); i++) {
|
||||
@@ -166,16 +194,13 @@ auto main() -> int {
|
||||
auto space = model_space;
|
||||
space.space = reprs[i];
|
||||
Voxel::cullEmptySpace(&space);
|
||||
auto perms = Voxel::getUniqueRotations(&space);
|
||||
auto perms = Voxel::getAllPermutationsInPrism(&space, dims);
|
||||
polycubes.insert(polycubes.end(), perms.begin(), perms.end());
|
||||
}
|
||||
|
||||
offsets.push_back(polycubes.size());
|
||||
|
||||
auto spaces = std::vector<uint64_t>(polycubes.size());
|
||||
std::transform(polycubes.begin(), polycubes.end(), spaces.begin(), [](auto i) { return i.space; });
|
||||
|
||||
auto solns = backtrack_solve(&spaces, &offsets);
|
||||
auto solns = backtrack_solve(&polycubes, &offsets);
|
||||
|
||||
std::cout << solns << std::endl;
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user