README

Table of Contents

1 clojure2minizinc

1.1 Summary

clojure2minizinc interfaces state-of-the-art constraint solvers (via MiniZinc) with a very high-level programming language, Clojure.

A Clojure library designed to solve constraint satisfaction problems (CSP). It generates MiniZinc code from Clojure code, that is very similar to the corresponding MiniZinc code. The generated MiniZinc program is then solved by one of the MiniZinc solvers available (e.g., see http://www.minizinc.org/software.html), and the result is read back into Clojure.

1.2 TODO What is MiniZinc and why clojure2minizinc?

More information, in particular many MiniZinc-related links (e.g., to various solvers) can be found at http://www.hakank.org/minizinc/

1.3 TODO Installation

  • Installation of MiniZinc tools
  • Installation of this library TODO: get installation with lein working

1.4 TODO Usage

1.4.1 TODO A Minimal Example

(ns clojure2minizinc.examples
  (:require [clojure2minizinc.core :as mz]))  

(mz/minizinc 
   (mz/clj2mnz
    (let [a (mz/variable (mz/-- -1 1)) 
          b (mz/variable (mz/-- -1 1))]
      (mz/constraint (mz/!= a b))
      (mz/solve :satisfy)
      (mz/output-map {:a a :b b})))
   :num-solutions 3
   ;; :all-solutions? true
   )

Results in ({:a 0, :b -1} {:a 1, :b -1} {:a -1, :b 0}).

Generates in the background this MiniZinc code and calls solver with it

TODO: add code

Note that this library overwrites many standard Clojure functions. You may want to use the library with a namespace prefix as in the example above.

More examples are shown in the tutorial.

1.4.2 Further Reading

1.5 Design

Most Clojure functions simply generate a string with the corresponding MiniZinc code. So, this library is very easy to extend to support not only the full feature set of MiniZinc, but also MiniZinc extensions proposed by various research projects.

The downside is that debugging the Clojure programs is somewhat difficult. For example, error messages by MiniZinc refer to line numbers of the generated MiniZinc code. However, constraint problem debuggers are not too helpful anyway. A useful technique is usually to disable all constraints for testing and then by and by enabling them again.

1.6 Related Work

1.6.1 Clojure: core.logic

In the Clojure community there already exists an interest in Constraint Programming (and the related Logic Programming paradigm), and solvers have been developed for Clojure.

core.logic implements logic and constraint programming facilities from scratch directly in Clojure. More specifically, it implements miniKanren and some of its extensions, e.g., cKanren for Constraint Logic Programming. For example, according to the documentation of core.logic, it currently implements about 10 constraints on integers (arithmetic operations, comparisons, and the global constraint distinct).

By contrast, clojure2minizinc provides an interface to a range of existing state-of-the-art constraint solvers. For example, in addition to constraints over integers (and many more constraints), it supports constraints over floats, sets, and reified constraints (i.e., the truth value of constraints can in turned be constrained, e.g., by logic relations such as implication or equivalence). Also, compared with the classical approach of Constraint Logic Programming implemented by cKanren, over the last twenty years the Constraint Programming community developed many techniques to greatly speed up the search process, which are implemented in state-of-the-art constraint solvers.

However, MiniZinc is not a Logic Programming language. For example, it does not provide unification of arbitrary terms (in contrast to equality constraints).

1.6.2 C++: libmzn

A project with similar goals as clojure2minizinc is libmzn, which provides a C++ interface to MiniZinc. It is planned to be released as part of MiniZinc 2.0.

1.7 License

Copyright © 2014 Torsten Anders

Distributed under the GNU General Public License.

Author: torsten

Created: 2014-08-29 Fri 22:47

Emacs 24.3.50.2 (Org mode 8.2.7b)

Validate