Quantcast
Viewing all articles
Browse latest Browse all 4

Answer by hakank for How to select a Constraint Programming Solver

@Rob wrote a great and extensive answer, but I would like to add two systems.

  • MiniZinc is a high level CP system that is great for learning CP, prototyping problems as well as testing different solvers. MiniZinc first flatten a MiniZinc (.mzn) model to FlagZinc format (.fzn) and there are quite a few CP solvers that supports the FlatZinc format, e.g. Gecode, Chuffed, OR-tools, SICStus Prolog, JaCoP, Picat (CP/SAT), etc (they are listed in the MiniZinc main page). There is also an MiniZinc IDE where some of these solvers are included.

    An example of the high level syntax of MiniZinc is the element constraint x[y] = z where x in an array of decision variables, y and z are decision variables. The constraint constrain z to be the yth value in x. Most other CP languages write this constraint as something like element(x,y,z). Thus this syntax in MiniZinc makes it a little easier to write and understand the constraint.

    MiniZinc support quite a few global constraints, though if a FlatZinc solver supports a specific global constraint, it will use its own instead.

    There is also an yearly MiniZinc Challenge where FlatZinc solvers are solving a number of different MiniZinc models. Last year, OR-Tools dominated the challenge completely. Most MiniZinc models and instances of former challenges are collected at GitHub,

    One drawback of MiniZinc is that it is not a - Turing compatible - programming language, but it is quite easy to spawn a MiniZinc process to solve a problem, and some systems have this integrated (e.g. SICStus Prolog, ECLiPse CLP). And if you are into C++ it is not that complicated to integrate it even more.

    And here's my MiniZinc page with a couple of examples, small and large.

    To summarize, MiniZinc is great for learning the concept of Constraint Programming and for prototyping. If one need to use another programming language, it's often quite easy to port the MiniZinc model to another CP system.

  • PicatWell, I have to add it to the list since I am in the Picat team and I really like Picat as a CP system. :-)

    Picat is a logic-based multi-paradigm programming language inspired by Prolog. The creator of Picat - Neng-Fa Zhou - is also the creator of B-Prolog (which is used in Picat's engine). This Prolog inspiration is seen for example with the support of non-determinism, but Picat also supports for loops, while loops, re-assignments, indexing of lists/arrays etc.

    Picat supports a couple of constraint solving modules: MIP (GLPK and Gurobi), SAT, and SMT (z3 and cvc4); all these solvers has support for the same syntax/constraints (with exception of MIP solver which only supports linear constraints). The PicatSAT FlatZinc solver has done quite well the last MiniZinc Challenges.

    One feature of Picat that I - mostly - like is that the order of the constraints are important when using the CP module. In most CP systems the order of the constraints does not matter, but in Picat (for the CP module) the order might make a difference and this is one other way to make a model more efficient.

    (Picat also has a planner module for traditional planning problems, but this is a bit out of scope of the question.)

    We wrote a book Constraint Solving and Planning with Picat about how to use Picat for Constraint Programming problems (as well as planning problems). The freely available PDF. I hope that the two chapters about CP might be useful as an introduction to CP in general.

    Also, My Picat page has quite a few examples of Picat models.

  • For harder CP problems, it's no uncommon have one have to tweak the model to make it fast enough. Most CP systems has a different ways of doing that:

    • selecting the order of variables to test (variable selection)
    • when testing a specific variable, selecting the order of the values to test (value selecting).

    Unfortunately, selecting these is - as of now - and art and one have to test different variants.

    Also, there are some "tricks" that often speed things up, apart from finding the best variable/value strategies, e.g. symmetry breaking and adding redundant constraints to prune the search tree.

A side note: @Rob mentioned that I don't blog anymore which is correct. Instead I write - occasionally - at - Facebook - Twitter - StackOverflow, mostly answering questions about MiniZinc and Constraint Programming - And publish stuff on GitHub


Viewing all articles
Browse latest Browse all 4

Trending Articles