FlatZinc is a low-level modelling language for constraint problems. It is designed to be easily interfaceable to constraint solvers (like Gecode). For more information on FlatZinc, please refer to the MiniZinc pages of the G12 project.
We provide a parser that reads a FlatZinc model from a file, and returns a Gecode Space object that represents the model. We also provide a simple front-end, an executable program that reads a FlatZinc model and prints the solution (if any) on the standard output.
FlatZinc for Gecode
Starting with Gecode version 3.2.0, the FlatZinc interpreter for Gecode is part of the standard Gecode distribution. Please check our download pages for more information on how to get a copy of Gecode. Source packages as well as binary packages are available.
The FlatZinc interpreter that ships with Gecode version 6.1.1 supports the FlatZinc language and MiniZinc global constraint definitions of MiniZinc version 1.6.0.
Running the parser
The executable is called fzn-gecode. You can run it with the -help switch to get an overview of how to invoke it:
$ fzn-gecode -help Gecode FlatZinc interpreter - Supported FlatZinc version: 1.6.0 Gecode configuration information: - Version: 6.1.1 - Variable types: BoolVar IntVar SetVar FloatVar - Trigonometric and transcendental float constraints: enabled - Thread support: enabled (8 processing units) - Gist support: enabled Options for Gecode/FlatZinc: -help, --help, -? print this help message -n (unsigned int) default: 1 number of solutions (0 = all) -p (double) default: 1 number of threads (0 = #processing units) -c-d (unsigned int) default: 8 recomputation commit distance -a-d (unsigned int) default: 2 recomputation adaption distance -a (optional: false, 0, true, 1) default: false return all solutions (equal to -solutions 0) --free (optional: false, 0, true, 1) default: false no need to follow search-specification -decay (double) default: 1 decay factor -node (unsigned int) default: 0 node cutoff (0 = none, solution mode) -fail (unsigned int) default: 0 failure cutoff (0 = none, solution mode) -time (unsigned int) default: 0 time (in ms) cutoff (0 = none, solution mode) -interrupt (optional: false, 0, true, 1) default: true whether to catch Ctrl-C (true) or not (false) -r (int) default: 0 random seed -restart (none, constant, linear, luby, geometric) default: none restart sequence type -restart-base (double) default: 1.5 base for geometric restart sequence -restart-scale (unsigned int) default: 250 scale factor for restart sequence -mode (solution, stat, gist) default: solution how to execute script -s (optional: false, 0, true, 1) default: false emit statistics -o (string) default: NONE file to send output to
Global constraint definitions for MiniZinc
The MiniZinc-to-FlatZinc converter provided by the G12 project can produce specialized FlatZinc that is targeted at a certain solver. Gecode/FlatZinc provides suitable definitions of global constraints in the directory mznlib. This directory is located in the Gecode directory installed in your program files folder (if you use the Windows binary package), in /usr/local/share/gecode if you use the Mac OS binary package, or in <prefix>/share/gecode if you installed Gecode from the sources.
In order to make the MiniZinc-to-FlatZinc converter aware of these global constraint definitions, you can either
- copy the mznlib directory into the lib/minizinc directory of your MiniZinc installation, rename it to gecode, and use the -G gecode flag of mzn2fzn;
- or use the -I flag of mzn2fzn with the complete path to the mznlib directory;
- or use the mzn-gecode script, which will invoke mzn2fzn with the correct library paths and directly pass the resulting FlatZinc on to the Gecode FlatZinc interpreter.
FlatZinc parser skeleton
We also provide the source code of the Gecode FlatZinc parser, stripped of all Gecode-specific code. You can use it as a starting point for your own FlatZinc interpreter.
The source code archive (compatible with FlatZinc 1.5) is available here:
The archive contains a README file that explains how to adapt and compile the code. If you have any questions, please contact email@example.com.
MiniZinc with Search Combinators
We have extended the Gecode FlatZinc interpreter with support for Search Combinators, a new, powerful modeling language for search heuristics. Search Combinators are explained in detail in this paper.
You can download an archive with the source code and pre-built binaries for Windows, Mac OS, and Linux. The archive contains a README and some examples to get you started.
If you have any questions, please contact Guido Tack