Gecode: FlatZinc
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.
The FlatZinc interpreter that ships with Gecode version 6.4.0 supports the FlatZinc language and the MiniZinc global constraint definitions included in the source release.
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
Gecode configuration information:
- Version: 6.4.0
- 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 under <prefix>/share/gecode.
In order to make the MiniZinc-to-FlatZinc converter aware of these global constraint definitions, you can either
-
Copy the
mznlibdirectory into thelib/minizincdirectory of your MiniZinc installation, rename it togecode, and use the-G gecodeflag ofmzn2fzn; -
Use the
-Iflag ofmzn2fznwith the complete path to themznlibdirectory; -
Use the
mzn-gecodescript, which will invokemzn2fznwith 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 tack@gecode.dev.