PatrickTrentin88 / fzn2omt

Tools/Scripts to convert MiniZinc/FlatZinc to Optimization Modulo Theories (OMT) for BCLT, OptiMathSAT or Z3 and Satisfiability Modulo Theories (SMT) for CVC4.
8 stars 0 forks source link

DESCRIPTION

Python scripts to solve FlatZinc models with Optimization Modulo Theories solvers like, e.g., Barcelogic, OptiMathSAT and z3.

Satisfaction FlatZinc models can also be solved with Satisfiability Modulo Theories solvers like, e.g., CVC4.

The FlatZinc model can be generated using the standard minizinc compiler or the customized emzn2fzn compiler for OptiMathSAT.

Functionality

REQUIREMENTS

The scripts require

INSTALLATION

To install the scripts, add the current directory to the PATH environment variable:

export PATH=$PATH:.../fzn2omt

It is also necessary to add the binaries of Barcelogic, OptiMathSAT, z3 and CVC4 to the PATH environment variable. ) Notice that the conversion from FlatZinc to SMT-LIB (v. 2) uses the fzn2omt interface of OptiMathSAT, so this tool is required even when solving the problems with the other tools.

To make these changes permanent, please consider editing the ~/.bashrc file.

Linux users can also edit and source the contents of the .bashrc file distributed with this project.

Solving with OptiMathSAT: fzn2optimathsat.py

The option to set the desired multi-objective optimization is:

-opt.priority=[box|lex|par]

e.g.

 ~$ fzn2optimathsat.py <model.fzn> -opt.priority=par
 ...

OptiMathSAT may print a sub-optimal model when the objective function is unbounded or, according to its infinite-precision arithmetic engine, equal to K +/- epsilon for some K and some arbitrarily small epsilon. In such cases, OptiMathSAT prints a warning message with the exact optimal value:

~$ fzn2optimathsat.py examples/unit_tests/unbounded.fzn
% objective: x (optimal model)
% warning: x is unbounded: (- oo)
x = -1000000000;
----------
==========

OptiMathSAT examples

Solving with Z3: fzn2z3.py

The option to set the desired multi-objective optimization is:

opt.priority=[box|lex|par]

e.g.

 ~$ fzn2z3.py <model.fzn> opt.priority=par
 ...

z3 may print a sub-optimal model when the objective function is unbounded or, according to its infinite-precision arithmetic engine, equal to K +/- epsilon for some K and some arbitrarily small epsilon.

~$ fzn2z3.py examples/unit_tests/unbounded.fzn
x = 0;
----------
==========

z3 examples

Solving with Barcelogic: fzn2bclt.py

Some FlatZinc problems require an encoding based on OMT(NIRA), which is not supported by Barcelogic. For such problems, Barcelogic may incorrectly return unsat.

Barcelogic requires objective functions to have a known, and finite, domain. When lower/upper bounds are not provided manually (options --bclt-lower and --bclt-upper), the default search interval is [-1000000000,1000000000]. Setting an inappropriate search interval may cause Barcelogic to provide the incorrect answer (e.g. unsat or the wrong optimal value).

Barcelogic examples

Solving with CVC4: fzn2cvc4.py

CVC4 is a SMT solver and does not support optimization.

Normally, attempting to solve an optimization problem with CVC4 results in an error message.

~$ fzn2cvc4.py examples/unit_tests/opt.fzn
error: objectives are not supported

It is possible to force CVC4 to solve the input problem by ignoring the objective function. Naturally, the resulting model is not guaranteed to be optimal.

~$ fzn2cvc4.py examples/unit_tests/opt.fzn --ignore-objs
objective = 0;
----------

CVC4 examples

NOTES

Please contact the author of this repository, or the current maintainer of the OptiMathSAT, in the case that there is still any persisting issue with your MiniZinc models.

Contributors

This project is authored by Patrick Trentin (patrick.trentin.88@gmail.com).