189 printf(
"\nCreating SAT encoding..\n");
192 std::vector<int> block_positions_124;
198 std::vector<int> block_positions_223;
204 for (
int ix = 0; ix <
DIM_X; ix++)
205 for (
int iy = 0; iy <
DIM_Y; iy++)
206 for (
int iz = 0; iz <
DIM_Z; iz++) {
207 assert(
grid[ix][iy][iz].size() > 0);
211 printf(
"Found %d possible block positions.\n",
int(
blockgeom.size()));
214 std::set<std::set<blockgeom_t>> symmetries;
216 bool keep_running =
true;
217 while (keep_running) {
218 keep_running =
false;
219 std::set<std::set<blockgeom_t>> old_sym;
220 old_sym.swap(symmetries);
221 for (
auto &old_sym_set : old_sym)
223 std::set<blockgeom_t> mx, my, mz;
224 std::set<blockgeom_t> rx, ry, rz;
225 for (
auto &bg : old_sym_set) {
228 bg_mx.
mirror_x(), bg_my.mirror_y(), bg_mz.mirror_z();
229 bg_rx.
rotate_x(), bg_ry.rotate_y(), bg_rz.rotate_z();
230 mx.insert(bg_mx), my.insert(bg_my), mz.insert(bg_mz);
231 rx.insert(bg_rx), ry.insert(bg_ry), rz.insert(bg_rz);
233 if (!old_sym.count(mx) || !old_sym.count(my) || !old_sym.count(mz) ||
234 !old_sym.count(rx) || !old_sym.count(ry) || !old_sym.count(rz))
236 symmetries.insert(old_sym_set);
237 symmetries.insert(mx);
238 symmetries.insert(my);
239 symmetries.insert(mz);
240 symmetries.insert(rx);
241 symmetries.insert(ry);
242 symmetries.insert(rz);
247 std::vector<std::vector<int>> vecvec;
248 for (
auto &sym : symmetries) {
249 std::vector<int> vec;
251 vec.push_back(bg.var);
252 vecvec.push_back(vec);
254 for (
size_t i = 1; i < vecvec.size(); i++)
257 printf(
"Found and eliminated %d spatial symmetries.\n",
int(symmetries.size()));
260 std::vector<int> modelExpressions;
261 std::vector<bool> modelValues;
265 modelExpressions.push_back(it.first);
268 int solution_counter = 0;
271 printf(
"\nSolving puzzle..\n");
272 bool ok =
ez.
solve(modelExpressions, modelValues);
275 printf(
"No more solutions found!\n");
279 printf(
"Puzzle solution:\n");
280 std::vector<int> constraint;
281 for (
size_t i = 0; i < modelExpressions.size(); i++)
282 if (modelValues[i]) {
283 constraint.push_back(
ez.
NOT(modelExpressions[i]));
284 printf(
"%s\n", blockinfo.at(modelExpressions[i]).c_str());
290 printf(
"\nFound %d distinct solutions.\n", solution_counter);
291 printf(
"Have a nice day.\n\n");
void condense_exclusives(std::vector< int > &vars)
int numCnfClauses() const
int onehot(const std::vector< int > &vec, bool max_only=false)
int numCnfVariables() const
bool solve(const std::vector< int > &modelExpressions, std::vector< bool > &modelValues, const std::vector< int > &assumptions)
std::set< blockgeom_t > blockgeom
int ordered(const std::vector< int > &vec1, const std::vector< int > &vec2, bool allow_equal=true)
std::vector< int > grid[DIM_X][DIM_Y][DIM_Z]
void add_block_positions_223(std::vector< int > &block_positions_223)
int manyhot(const std::vector< int > &vec, int min_hot, int max_hot=-1)
std::map< int, std::string > blockinfo
int expression(OpId op, int a=0, int b=0, int c=0, int d=0, int e=0, int f=0)
virtual void freeze(int id)
void add_block_positions_124(std::vector< int > &block_positions_124)