2

I'm faced with a problem where I have to solve puzzles.

E.g. I have an (variable) area of 20x20 (meters for example). There are a number of given set pieces having variable sizes. Such as 4x3, 4x2, 1x5 pieces etc. These pieces can also be turned to add more pain to my problem. The point of the puzzle is to fill the entire area of 20x20 with the given pieces.

What would be a good starting algorithm to achieve such a feat? I'm thinking of using a heuristic that calculates the open space (for efficiency purposes).

Thanks in advance

Shine
  • 676
  • 6
  • 12

1 Answers1

5

That's an Exact Cover problem, with a nice structure too, usually, depending on the pieces. I don't know about any heuristic algorithms, but there are several exact options that should work well.

As usual with Exact Covers, you can use Dancing Links, a way to implement Algorithm X efficiently.

Less generally, you can probably solve this with zero-suppressed decision diagrams. It depends on the tiles though. As a bonus, you can represent all possible solutions and count them or generate one with some properties, all without ever explicitly storing the entire (usually far too large) set of solutions.

BDDs would work about as well, using more nodes to accomplish the same thing (because the solutions are very sparse, as in, using few of the possible tile-placements - ZDDs like that but BDDs like symmetry better than sparseness).

Or you could turn it into a SAT problem, then you get less information (no solution count for example), but faster if there are easy solutions.

harold
  • 61,398
  • 6
  • 86
  • 164
  • So I see how tiling is an exact cover problem: represent all possible board positions as columns, with rows for each possible piece position, plus maybe some control columns if there are restrictions on how many of each piece should be used. However, how would you formulate tiling as a ZDD? – Quantum7 May 27 '15 at 08:20
  • @Quantum7 you can formulate any exact cover problem as a ZDD (not necessarily a small ZDD though); for every element in the universe, make the family of sets in which that element is picked exactly once, then intersect all of them to get the family of sets in which every element is picked exactly once. – harold May 27 '15 at 08:42