algorithmpuzzleheuristicstiling

Tiling Algorithm


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


Solution

  • 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.