added old backtrack algo
This commit is contained in:
36
main.cpp
36
main.cpp
@@ -1,9 +1,11 @@
|
||||
#include <bitset>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "VoxelSpace.h"
|
||||
|
||||
auto backtrack_solve(std::vector<uint64_t> *polycube_input, std::vector<int> *offsets)-> void {
|
||||
auto backtrack_solve_iter(std::vector<uint64_t> *polycube_input, std::vector<int> *offsets)-> void {
|
||||
auto num_inputs = offsets->size() - 1;
|
||||
|
||||
auto solns = std::vector<int>();
|
||||
@@ -51,6 +53,25 @@ auto backtrack_solve(std::vector<uint64_t> *polycube_input, std::vector<int> *of
|
||||
std::cout << "Done. Found " << solns.size() << " solutions." << std::endl;
|
||||
}
|
||||
|
||||
auto backtrack_solve(std::vector<uint64_t> *polycube_input, std::vector<int> *offsets, uint64_t working_solution = 0ull, int set = 0) -> int {
|
||||
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 = (working_solution | polycube_input->at(i)) == (working_solution ^ polycube_input->at(i));
|
||||
if (successful_fuse) {
|
||||
working_solution = working_solution | polycube_input->at(i);
|
||||
if (set == offsets->size() - 2) {
|
||||
return solns + 1;
|
||||
} else {
|
||||
solns += backtrack_solve(polycube_input, offsets, working_solution, set + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 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;
|
||||
@@ -109,8 +130,8 @@ auto get_reprs_input(int units_required) -> std::vector<uint64_t> {
|
||||
}
|
||||
|
||||
auto main() -> int {
|
||||
int dims[3] = {};
|
||||
get_dims_input(dims);
|
||||
int dims[3] = { 3, 3, 3 };
|
||||
//get_dims_input(dims);
|
||||
std::cout << '\n';
|
||||
//auto reprs = get_reprs_input(dims[0]*dims[1]*dims[2]);
|
||||
auto reprs = std::vector<uint64_t>{
|
||||
@@ -137,7 +158,6 @@ auto main() -> int {
|
||||
auto space = model_space;
|
||||
space.space = reprs[0];
|
||||
Voxel::cullEmptySpace(&space);
|
||||
std::cout << space.dims[0] << space.dims[1] << space.dims[2] << std::endl;
|
||||
auto positions = Voxel::getUniqueRotations(&space);
|
||||
polycubes.insert(polycubes.end(), positions.begin(), positions.end());
|
||||
|
||||
@@ -146,13 +166,17 @@ auto main() -> int {
|
||||
auto space = model_space;
|
||||
space.space = reprs[i];
|
||||
Voxel::cullEmptySpace(&space);
|
||||
std::cout << space.dims[0] << space.dims[1] << space.dims[2] << std::endl;
|
||||
auto perms = Voxel::getUniqueRotations(&space);
|
||||
polycubes.insert(polycubes.end(), perms.begin(), perms.end());
|
||||
}
|
||||
|
||||
offsets.push_back(polycubes.size());
|
||||
|
||||
//backtrack_solve(&polycubes, &offsets);
|
||||
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);
|
||||
|
||||
std::cout << solns << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user