|• 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 can be generated by the
tool with the -c option, for example (
queen4.dzn can be found in
minizinc --solver sicstus -c queen.mzn queen4.dzn
The resulting FlatZinc program
queen4.fzn can then be run as
minizinc without the -c option
first generates a temporary FlatZinc file, then runs it, then deletes it:
minizinc --solver sicstus queen.mzn queen4.dzn
or, simplest of all:
minizinc --solver sicstus -D n=4 queen.mzn
It is also possible to just load a FlatZinc program into
loaded FlatZinc program can then be processed further from
within SICStus, e.g. by retrieving some FlatZinc variables
fzn_identifier/3 and posting additional
library(clpfd) constraints or applying a Prolog labeling
predicate on those variables.
Finally, it is possible to load and run MiniZinc programs directly from within SICStus by using the predicates described in MiniZinc.