|• FlatZinc Exported Predicates:||Exported Predicates|
The FlatZinc interpreter described here is based on “Specification of FlatZinc, version 1.6”, available at http://www.minizinc.org/specifications.html.
A FlatZinc program can be run directly using
fzn_run_stream/[1,2], as well as
spfz, a simple command-line tool interface to
fzn_run_file/[1,2] (for details, see too-spfz). For
example, a program for solving the 4 Queens problem, located in
library('zinc/examples/queen4.fzn'), can be run by the following
| ?- fzn_run_file(library('zinc/examples/queen4')).
% spfz $SP_LIBRARY_DIR/zinc/examples/queen4
The following solution is then written on the current output stream:
q = array1d(1..4, [2, 4, 1, 3]); ----------
Note the ten consecutive dashes after the solution.
The following goal can be used to find all solutions:
| ?- fzn_run_file(library('zinc/examples/queen4'), [solutions(all)]).
% spfz $SP_LIBRARY_DIR/zinc/examples/queen4 -a
The following solutions are then written on the current output stream:
q = array1d(1..4, [2, 4, 1, 3]); ---------- q = array1d(1..4, [3, 1, 4, 2]); ---------- ==========
Note the ten consecutive equal signs after all solutions have been found.
FlatZinc programs are not intended to be written (or read) by humans,
but rather to be automatically generated. One way to generate a FlatZinc
program is by using a MiniZinc-to-FlatZinc translator, such as
mzn2fzn, bundles with the MiniZinc distribution. One use of this
translator is to first generate a FlatZinc program from a MiniZinc
program, e.g. by the following command line (
queen4.dzn can be found in
mzn2fzn -G sicstus --data queen4.dzn --output-fzn-to-file queen4.fzn queen.mzn
The resulting FlatZinc program
queen4.fzn can then be run as
described above. If a generated FlatZinc program is not desired, then another
mzn2fzn is to pipe its result directly to a SICStus
process, e.g. by the following command:
mzn2fzn -G sicstus --data queen4.dzn --output-fzn-to-stdout queen.mzn | sicstus --goal 'use_module(library(zinc)), fzn_run_stream(user_input), halt.'
minizinc --solver sicstus --data queen4.dzn queen.mzn
or, even simpler:
minizinc --solver sicstus -D n=4 queen.mzn
or, simpler still:
mzn-sicstus -D n=4 queen.mzn
It is also possible to just load a FlatZinc program into SICStus by
fzn_load_stream/2. The loaded FlatZinc
program can then be processed further from within SICStus, e.g. by
retrieving some FlatZinc variables using
library(clpfd) constraints or applying a
Prolog labeling predicate on those variables.
Finally, it is also possible to load and run MiniZinc programs directly
from within SICStus by using the predicates described in
MiniZinc. These predicates all rely on the availability of an
external MiniZinc-to-FlatZinc translator such as
as well as an external solution printer such as