MiniZinc Crossword generation (solver)

Here are some MiniZinc models, problem instances, and word files for solving crosswords.

These models, general approach and benchmarking is described in the blog post Crossword construction in MiniZinc using table constraints - a small benchmark on "72 Gecode problems" .

Basic approach

The solver model (crossword3.mzn) contains This general model is included in each of the problem instances crossword3_*.mzn, see below. The problem instances then contains the specific constraints for the problem instance:

Example

Let's take the following grid (Gecode problem instance #3, gecode_grid3.txt) and see how it is represented in the MiniZinc file crossword3_3.mzn.

First the grid:
% 
% Gecode problem #3: 05.04, 5 x 5
%
_ _ _ * *
_ _ _ _ *
_ _ _ _ _
* _ _ _ _
* * _ _ _
"_" means that we want a letter in this position, "*" means that this cell is blocked. Thus, we have the requirements that the first row contains one word (segment) of three letters, the first column (down) a three letter word, etc. (A line like _ _ _ * * _ _ would mean two words, one of three letters, and one of two letters.)

During a preprocessing phase (via a Perl program, much like make_crossword3.pl) this grid is then converted to:

Solver, general model

The solver model is crossword3.mzn. See above for a description.

Dictionary files

Here are some word list files, as MiniZinc data files (.dzn). They are to be included in crossword3.mzn:

Problem instances

Below are the 72 problem instances from Gecode's crossword model ( crossword.cpp). They include the general model (crossword3.mzn) and can be run something like this:
  # Using G12/MiniZinc default solver
  $ minizinc -v --no-optimize -s  crossword3_0.mzn

  # Using Gecode/fz
  $ minizinc -v --no-optimize  -G gecode -s  crossword3_0.mzn -f "fz   -mode stat  -n 1    "
For larger problems, the parameter --no-optimize might be a good choice, otherwise mzn2fzn can take very long time.

Gecode 72 problems as grids in text file

Here are the 72 Gecode problem instances as grids, i.e. textfiles. E.g. gecode_grid2.txt contains the following:
% 
% Gecode problem #2: 05.03, 5 x 5
%
_ _ _ _ *
_ _ _ _ *
_ _ _ _ _
* _ _ _ _
* _ _ _ _
make_crossword3.pl is a simple Perl program for creating a MiniZinc file from this grid file. Run it like this:
  $ perl make_crossword3.pl gecode_grid2.txt > tmp.mzn && minizinc -v --no-optimize -G gecode -s tmp.mzn -f "fz -mode stat -n 1" 

Random grids

Here are some random grids that I've been playing with:
Back to my MiniZinc page