Git Product home page Git Product logo

polyomino-solver's Introduction

Polyomino Solver

Try it here.

Construct a collection of standard and/or completely custom polyominos, and an arbitrary region to fit them in, and this web app will find and display a valid tiling that places all of the polyominos in the region (if it exists).

Uses web-component-polyomino for building, manipulating, and displaying polyominos.

How it works

Algorithm X

Knuth's "Algorithm X" (implemented with "Dancing Links") is the best algorithm to handle this problem, by reducing it to an Exact Cover Problem. The details are explained by Knuth himself in his paper. I use dlxlib as an implementation of Dancing Links, courtesy of taylorgj.

Converstion to SAT

The other two solving methods are much less efficient, and were the solutions I first discovered.

It's known that for arbitrary grids and arbitrary sets of polyominos, the problem of deciding whether or not the polyominos can fit together on the grid is an NP-Complete problem. Being NP-Complete, we can convert a tiling problem into an instance of a Boolean Satisfiability Problem, for which efficient solvers exist.

Tiling problems can be converted to SAT by introducing a boolean variable for each configuration that each piece could possibly exist in, and then adding clauses that state that a piece must exist in exactly one configuration, and no configurations can overlap.

Javascript SAT Solver

The problem is converted to a CNF file (a common input format for SAT solvers). After that, boolean-sat is applied to solve the problem. This is Javascript SAT solver based on my forked repo of the original code written by Gregory Duck of at University of Singapore. This is probably the least efficient method. Since the SAT problem must be specified in CNF, even the input file can get very large very quickly.

Z3 Webassembly

This was born out of an attempt to make the preceding method faster. Here, we convert the problem to SMT format, and use the Webassembly build of Microsoft Research's Z3 Theorem Prover. Generally speaking, this is a tool that can check the satisfiability of first-order logic statements over arbitrary theories, but we only utilize it for the predicate logic subset.

polyomino-solver's People

Contributors

cemulate avatar dacapoday avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

polyomino-solver's Issues

Non completely fit in area

Can I use the software to find a "any fit" solution somehow? I.e. I'm not looking for exact fit into the canvas, but any fit that will be capable of holding all of given shapes.

For example:

Shapes

TTT
 T

ZZ
 ZZ

Fit into 2x5 canvas:

 TZZ
TTTZZ

Currently, it says that there is no solution :-(

Reflection issue.

Noticed that it doesn't solve some problems because the S pattern is not reflected.
No Solution
Polyomino 21 Feb
Solved

Cells in the preview of the selected polyominos are sized inconsistently

I created custom polyominos as pictured in the screenshot:

image

In the preview, all pieces are shown with a fixed size (50ร—50 pixels).
This causes the cells of the different pieces to have inconsistent size, if the sides of the polyominos are different length.

I'd find it (a) better looking and (b) more helpful for the topic at hand, if the cell size of all polyominos was the same.

That could be achieved in CSS by giving the elements with class cell a fixed size instead of the polyomino-control elements that are currently sized 50ร—50.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.